Tomas Winkler | 2a421b9 | 2008-06-12 09:47:10 +0800 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
| 3 | * GPL LICENSE SUMMARY |
| 4 | * |
Wey-Yi Guy | fb4961d | 2012-01-06 13:16:33 -0800 | [diff] [blame] | 5 | * Copyright(c) 2008 - 2012 Intel Corporation. All rights reserved. |
Tomas Winkler | 2a421b9 | 2008-06-12 09:47:10 +0800 | [diff] [blame] | 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of version 2 of the GNU General Public License as |
| 9 | * published by the Free Software Foundation. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, but |
| 12 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 14 | * General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, |
| 19 | * USA |
| 20 | * |
| 21 | * The full GNU General Public License is included in this distribution |
| 22 | * in the file called LICENSE.GPL. |
| 23 | * |
| 24 | * Contact Information: |
Winkler, Tomas | 759ef89 | 2008-12-09 11:28:58 -0800 | [diff] [blame] | 25 | * Intel Linux Wireless <ilw@linux.intel.com> |
Tomas Winkler | 2a421b9 | 2008-06-12 09:47:10 +0800 | [diff] [blame] | 26 | * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497 |
| 27 | *****************************************************************************/ |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 28 | #include <linux/slab.h> |
John W. Linville | 7e272fc | 2008-09-24 18:13:14 -0400 | [diff] [blame] | 29 | #include <linux/types.h> |
Tomas Winkler | 2a421b9 | 2008-06-12 09:47:10 +0800 | [diff] [blame] | 30 | #include <linux/etherdevice.h> |
John W. Linville | 7e272fc | 2008-09-24 18:13:14 -0400 | [diff] [blame] | 31 | #include <net/mac80211.h> |
Tomas Winkler | 2a421b9 | 2008-06-12 09:47:10 +0800 | [diff] [blame] | 32 | |
| 33 | #include "iwl-eeprom.h" |
| 34 | #include "iwl-dev.h" |
| 35 | #include "iwl-core.h" |
Tomas Winkler | 2a421b9 | 2008-06-12 09:47:10 +0800 | [diff] [blame] | 36 | #include "iwl-io.h" |
Wey-Yi Guy | e80d70e | 2011-06-03 07:54:15 -0700 | [diff] [blame] | 37 | #include "iwl-agn.h" |
Emmanuel Grumbach | bdfbf09 | 2011-07-08 08:46:16 -0700 | [diff] [blame] | 38 | #include "iwl-trans.h" |
Tomas Winkler | 2a421b9 | 2008-06-12 09:47:10 +0800 | [diff] [blame] | 39 | |
| 40 | /* For active scan, listen ACTIVE_DWELL_TIME (msec) on each channel after |
| 41 | * sending probe req. This should be set long enough to hear probe responses |
| 42 | * from more than one AP. */ |
Tomas Winkler | fe905f1 | 2008-07-11 11:53:39 +0800 | [diff] [blame] | 43 | #define IWL_ACTIVE_DWELL_TIME_24 (30) /* all times in msec */ |
| 44 | #define IWL_ACTIVE_DWELL_TIME_52 (20) |
| 45 | |
| 46 | #define IWL_ACTIVE_DWELL_FACTOR_24GHZ (3) |
| 47 | #define IWL_ACTIVE_DWELL_FACTOR_52GHZ (2) |
Tomas Winkler | 2a421b9 | 2008-06-12 09:47:10 +0800 | [diff] [blame] | 48 | |
Tomas Winkler | 2a421b9 | 2008-06-12 09:47:10 +0800 | [diff] [blame] | 49 | /* For passive scan, listen PASSIVE_DWELL_TIME (msec) on each channel. |
| 50 | * Must be set longer than active dwell time. |
| 51 | * For the most reliable scan, set > AP beacon interval (typically 100msec). */ |
| 52 | #define IWL_PASSIVE_DWELL_TIME_24 (20) /* all times in msec */ |
| 53 | #define IWL_PASSIVE_DWELL_TIME_52 (10) |
| 54 | #define IWL_PASSIVE_DWELL_BASE (100) |
| 55 | #define IWL_CHANNEL_TUNE_TIME 5 |
| 56 | |
Stanislaw Gruszka | cd44600 | 2010-09-13 14:46:36 +0200 | [diff] [blame] | 57 | static int iwl_send_scan_abort(struct iwl_priv *priv) |
| 58 | { |
| 59 | int ret; |
| 60 | struct iwl_rx_packet *pkt; |
| 61 | struct iwl_host_cmd cmd = { |
| 62 | .id = REPLY_SCAN_ABORT_CMD, |
Emmanuel Grumbach | e419d62 | 2011-07-08 08:46:14 -0700 | [diff] [blame] | 63 | .flags = CMD_SYNC | CMD_WANT_SKB, |
Stanislaw Gruszka | cd44600 | 2010-09-13 14:46:36 +0200 | [diff] [blame] | 64 | }; |
Tomas Winkler | fe905f1 | 2008-07-11 11:53:39 +0800 | [diff] [blame] | 65 | |
Stanislaw Gruszka | cd44600 | 2010-09-13 14:46:36 +0200 | [diff] [blame] | 66 | /* Exit instantly with error when device is not ready |
| 67 | * to receive scan abort command or it does not perform |
| 68 | * hardware scan currently */ |
Emmanuel Grumbach | 63013ae | 2011-08-25 23:10:42 -0700 | [diff] [blame] | 69 | if (!test_bit(STATUS_READY, &priv->shrd->status) || |
| 70 | !test_bit(STATUS_GEO_CONFIGURED, &priv->shrd->status) || |
| 71 | !test_bit(STATUS_SCAN_HW, &priv->shrd->status) || |
Johannes Berg | 5c40d86 | 2012-03-05 11:24:28 -0800 | [diff] [blame] | 72 | test_bit(STATUS_FW_ERROR, &priv->shrd->status)) |
Stanislaw Gruszka | cd44600 | 2010-09-13 14:46:36 +0200 | [diff] [blame] | 73 | return -EIO; |
| 74 | |
Johannes Berg | e10a053 | 2012-03-06 13:30:39 -0800 | [diff] [blame] | 75 | ret = iwl_dvm_send_cmd(priv, &cmd); |
Stanislaw Gruszka | cd44600 | 2010-09-13 14:46:36 +0200 | [diff] [blame] | 76 | if (ret) |
| 77 | return ret; |
| 78 | |
Johannes Berg | 65b94a4 | 2012-03-05 11:24:38 -0800 | [diff] [blame] | 79 | pkt = cmd.resp_pkt; |
Stanislaw Gruszka | cd44600 | 2010-09-13 14:46:36 +0200 | [diff] [blame] | 80 | if (pkt->u.status != CAN_ABORT_STATUS) { |
| 81 | /* The scan abort will return 1 for success or |
| 82 | * 2 for "failure". A failure condition can be |
| 83 | * due to simply not being in an active scan which |
| 84 | * can occur if we send the scan abort before we |
| 85 | * the microcode has notified us that a scan is |
| 86 | * completed. */ |
Stanislaw Gruszka | 7cf2442 | 2010-09-13 14:46:44 +0200 | [diff] [blame] | 87 | IWL_DEBUG_SCAN(priv, "SCAN_ABORT ret %d.\n", pkt->u.status); |
Stanislaw Gruszka | cd44600 | 2010-09-13 14:46:36 +0200 | [diff] [blame] | 88 | ret = -EIO; |
| 89 | } |
| 90 | |
Johannes Berg | 65b94a4 | 2012-03-05 11:24:38 -0800 | [diff] [blame] | 91 | iwl_free_resp(&cmd); |
Stanislaw Gruszka | cd44600 | 2010-09-13 14:46:36 +0200 | [diff] [blame] | 92 | return ret; |
| 93 | } |
| 94 | |
Stanislaw Gruszka | 02d8c14 | 2010-09-13 14:46:38 +0200 | [diff] [blame] | 95 | static void iwl_complete_scan(struct iwl_priv *priv, bool aborted) |
| 96 | { |
| 97 | /* check if scan was requested from mac80211 */ |
| 98 | if (priv->scan_request) { |
| 99 | IWL_DEBUG_SCAN(priv, "Complete scan in mac80211\n"); |
| 100 | ieee80211_scan_completed(priv->hw, aborted); |
| 101 | } |
| 102 | |
Johannes Berg | c6baf7f | 2011-07-23 10:24:47 -0700 | [diff] [blame] | 103 | if (priv->scan_type == IWL_SCAN_ROC) { |
| 104 | ieee80211_remain_on_channel_expired(priv->hw); |
| 105 | priv->hw_roc_channel = NULL; |
| 106 | schedule_delayed_work(&priv->hw_roc_disable_work, 10 * HZ); |
| 107 | } |
| 108 | |
Johannes Berg | 266af4c7 | 2011-03-10 20:13:26 -0800 | [diff] [blame] | 109 | priv->scan_type = IWL_SCAN_NORMAL; |
Stanislaw Gruszka | 02d8c14 | 2010-09-13 14:46:38 +0200 | [diff] [blame] | 110 | priv->scan_vif = NULL; |
| 111 | priv->scan_request = NULL; |
| 112 | } |
| 113 | |
Johannes Berg | a2fa246 | 2011-09-22 15:14:59 -0700 | [diff] [blame] | 114 | static void iwl_process_scan_complete(struct iwl_priv *priv) |
| 115 | { |
| 116 | bool aborted; |
| 117 | |
Johannes Berg | b1eea29 | 2012-03-06 13:30:42 -0800 | [diff] [blame^] | 118 | lockdep_assert_held(&priv->mutex); |
Johannes Berg | 84b1bec | 2011-09-22 15:15:00 -0700 | [diff] [blame] | 119 | |
| 120 | if (!test_and_clear_bit(STATUS_SCAN_COMPLETE, &priv->shrd->status)) |
| 121 | return; |
| 122 | |
Johannes Berg | a2fa246 | 2011-09-22 15:14:59 -0700 | [diff] [blame] | 123 | IWL_DEBUG_SCAN(priv, "Completed scan.\n"); |
| 124 | |
| 125 | cancel_delayed_work(&priv->scan_check); |
| 126 | |
| 127 | aborted = test_and_clear_bit(STATUS_SCAN_ABORTING, &priv->shrd->status); |
| 128 | if (aborted) |
| 129 | IWL_DEBUG_SCAN(priv, "Aborted scan completed.\n"); |
| 130 | |
| 131 | if (!test_and_clear_bit(STATUS_SCANNING, &priv->shrd->status)) { |
| 132 | IWL_DEBUG_SCAN(priv, "Scan already completed.\n"); |
| 133 | goto out_settings; |
| 134 | } |
| 135 | |
| 136 | if (priv->scan_type == IWL_SCAN_ROC) { |
| 137 | ieee80211_remain_on_channel_expired(priv->hw); |
| 138 | priv->hw_roc_channel = NULL; |
| 139 | schedule_delayed_work(&priv->hw_roc_disable_work, 10 * HZ); |
| 140 | } |
| 141 | |
| 142 | if (priv->scan_type != IWL_SCAN_NORMAL && !aborted) { |
| 143 | int err; |
| 144 | |
| 145 | /* Check if mac80211 requested scan during our internal scan */ |
| 146 | if (priv->scan_request == NULL) |
| 147 | goto out_complete; |
| 148 | |
| 149 | /* If so request a new scan */ |
| 150 | err = iwl_scan_initiate(priv, priv->scan_vif, IWL_SCAN_NORMAL, |
| 151 | priv->scan_request->channels[0]->band); |
| 152 | if (err) { |
| 153 | IWL_DEBUG_SCAN(priv, |
| 154 | "failed to initiate pending scan: %d\n", err); |
| 155 | aborted = true; |
| 156 | goto out_complete; |
| 157 | } |
| 158 | |
| 159 | return; |
| 160 | } |
| 161 | |
| 162 | out_complete: |
| 163 | iwl_complete_scan(priv, aborted); |
| 164 | |
| 165 | out_settings: |
| 166 | /* Can we still talk to firmware ? */ |
| 167 | if (!iwl_is_ready_rf(priv->shrd)) |
| 168 | return; |
| 169 | |
| 170 | iwlagn_post_scan(priv); |
| 171 | } |
| 172 | |
Stanislaw Gruszka | e7e16b9 | 2010-09-13 14:46:41 +0200 | [diff] [blame] | 173 | void iwl_force_scan_end(struct iwl_priv *priv) |
Stanislaw Gruszka | f5354c1 | 2010-09-13 14:46:39 +0200 | [diff] [blame] | 174 | { |
Johannes Berg | b1eea29 | 2012-03-06 13:30:42 -0800 | [diff] [blame^] | 175 | lockdep_assert_held(&priv->mutex); |
Stanislaw Gruszka | e7e16b9 | 2010-09-13 14:46:41 +0200 | [diff] [blame] | 176 | |
Emmanuel Grumbach | 63013ae | 2011-08-25 23:10:42 -0700 | [diff] [blame] | 177 | if (!test_bit(STATUS_SCANNING, &priv->shrd->status)) { |
Stanislaw Gruszka | e7e16b9 | 2010-09-13 14:46:41 +0200 | [diff] [blame] | 178 | IWL_DEBUG_SCAN(priv, "Forcing scan end while not scanning\n"); |
| 179 | return; |
| 180 | } |
| 181 | |
Stanislaw Gruszka | f5354c1 | 2010-09-13 14:46:39 +0200 | [diff] [blame] | 182 | IWL_DEBUG_SCAN(priv, "Forcing scan end\n"); |
Emmanuel Grumbach | 63013ae | 2011-08-25 23:10:42 -0700 | [diff] [blame] | 183 | clear_bit(STATUS_SCANNING, &priv->shrd->status); |
| 184 | clear_bit(STATUS_SCAN_HW, &priv->shrd->status); |
| 185 | clear_bit(STATUS_SCAN_ABORTING, &priv->shrd->status); |
Johannes Berg | 84b1bec | 2011-09-22 15:15:00 -0700 | [diff] [blame] | 186 | clear_bit(STATUS_SCAN_COMPLETE, &priv->shrd->status); |
Stanislaw Gruszka | f5354c1 | 2010-09-13 14:46:39 +0200 | [diff] [blame] | 187 | iwl_complete_scan(priv, true); |
| 188 | } |
| 189 | |
Stanislaw Gruszka | cd44600 | 2010-09-13 14:46:36 +0200 | [diff] [blame] | 190 | static void iwl_do_scan_abort(struct iwl_priv *priv) |
| 191 | { |
| 192 | int ret; |
| 193 | |
Johannes Berg | b1eea29 | 2012-03-06 13:30:42 -0800 | [diff] [blame^] | 194 | lockdep_assert_held(&priv->mutex); |
Stanislaw Gruszka | cd44600 | 2010-09-13 14:46:36 +0200 | [diff] [blame] | 195 | |
Emmanuel Grumbach | 63013ae | 2011-08-25 23:10:42 -0700 | [diff] [blame] | 196 | if (!test_bit(STATUS_SCANNING, &priv->shrd->status)) { |
Stanislaw Gruszka | cd44600 | 2010-09-13 14:46:36 +0200 | [diff] [blame] | 197 | IWL_DEBUG_SCAN(priv, "Not performing scan to abort\n"); |
| 198 | return; |
| 199 | } |
| 200 | |
Emmanuel Grumbach | 63013ae | 2011-08-25 23:10:42 -0700 | [diff] [blame] | 201 | if (test_and_set_bit(STATUS_SCAN_ABORTING, &priv->shrd->status)) { |
Stanislaw Gruszka | cd44600 | 2010-09-13 14:46:36 +0200 | [diff] [blame] | 202 | IWL_DEBUG_SCAN(priv, "Scan abort in progress\n"); |
| 203 | return; |
| 204 | } |
| 205 | |
| 206 | ret = iwl_send_scan_abort(priv); |
| 207 | if (ret) { |
| 208 | IWL_DEBUG_SCAN(priv, "Send scan abort failed %d\n", ret); |
Stanislaw Gruszka | f5354c1 | 2010-09-13 14:46:39 +0200 | [diff] [blame] | 209 | iwl_force_scan_end(priv); |
Stanislaw Gruszka | cd44600 | 2010-09-13 14:46:36 +0200 | [diff] [blame] | 210 | } else |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 211 | IWL_DEBUG_SCAN(priv, "Successfully send scan abort\n"); |
Stanislaw Gruszka | cd44600 | 2010-09-13 14:46:36 +0200 | [diff] [blame] | 212 | } |
Tomas Winkler | fe905f1 | 2008-07-11 11:53:39 +0800 | [diff] [blame] | 213 | |
Tomas Winkler | 2a421b9 | 2008-06-12 09:47:10 +0800 | [diff] [blame] | 214 | /** |
| 215 | * iwl_scan_cancel - Cancel any currently executing HW scan |
Tomas Winkler | 2a421b9 | 2008-06-12 09:47:10 +0800 | [diff] [blame] | 216 | */ |
| 217 | int iwl_scan_cancel(struct iwl_priv *priv) |
| 218 | { |
Stanislaw Gruszka | cd44600 | 2010-09-13 14:46:36 +0200 | [diff] [blame] | 219 | IWL_DEBUG_SCAN(priv, "Queuing abort scan\n"); |
Johannes Berg | 1ee158d | 2012-02-17 10:07:44 -0800 | [diff] [blame] | 220 | queue_work(priv->workqueue, &priv->abort_scan); |
Tomas Winkler | 2a421b9 | 2008-06-12 09:47:10 +0800 | [diff] [blame] | 221 | return 0; |
| 222 | } |
Stanislaw Gruszka | cd44600 | 2010-09-13 14:46:36 +0200 | [diff] [blame] | 223 | |
Tomas Winkler | 2a421b9 | 2008-06-12 09:47:10 +0800 | [diff] [blame] | 224 | /** |
| 225 | * iwl_scan_cancel_timeout - Cancel any currently executing HW scan |
| 226 | * @ms: amount of time to wait (in milliseconds) for scan to abort |
| 227 | * |
Tomas Winkler | 2a421b9 | 2008-06-12 09:47:10 +0800 | [diff] [blame] | 228 | */ |
Johannes Berg | 98efb4a | 2011-09-22 15:14:57 -0700 | [diff] [blame] | 229 | void iwl_scan_cancel_timeout(struct iwl_priv *priv, unsigned long ms) |
Tomas Winkler | 2a421b9 | 2008-06-12 09:47:10 +0800 | [diff] [blame] | 230 | { |
Stanislaw Gruszka | e693a80 | 2010-09-13 14:46:37 +0200 | [diff] [blame] | 231 | unsigned long timeout = jiffies + msecs_to_jiffies(ms); |
Tomas Winkler | 2a421b9 | 2008-06-12 09:47:10 +0800 | [diff] [blame] | 232 | |
Johannes Berg | b1eea29 | 2012-03-06 13:30:42 -0800 | [diff] [blame^] | 233 | lockdep_assert_held(&priv->mutex); |
Tomas Winkler | 2a421b9 | 2008-06-12 09:47:10 +0800 | [diff] [blame] | 234 | |
Stanislaw Gruszka | e693a80 | 2010-09-13 14:46:37 +0200 | [diff] [blame] | 235 | IWL_DEBUG_SCAN(priv, "Scan cancel timeout\n"); |
| 236 | |
| 237 | iwl_do_scan_abort(priv); |
| 238 | |
| 239 | while (time_before_eq(jiffies, timeout)) { |
Emmanuel Grumbach | 63013ae | 2011-08-25 23:10:42 -0700 | [diff] [blame] | 240 | if (!test_bit(STATUS_SCAN_HW, &priv->shrd->status)) |
Johannes Berg | 84b1bec | 2011-09-22 15:15:00 -0700 | [diff] [blame] | 241 | goto finished; |
Stanislaw Gruszka | e693a80 | 2010-09-13 14:46:37 +0200 | [diff] [blame] | 242 | msleep(20); |
Tomas Winkler | 2a421b9 | 2008-06-12 09:47:10 +0800 | [diff] [blame] | 243 | } |
Johannes Berg | 84b1bec | 2011-09-22 15:15:00 -0700 | [diff] [blame] | 244 | |
| 245 | return; |
| 246 | |
| 247 | finished: |
| 248 | /* |
| 249 | * Now STATUS_SCAN_HW is clear. This means that the |
| 250 | * device finished, but the background work is going |
| 251 | * to execute at best as soon as we release the mutex. |
| 252 | * Since we need to be able to issue a new scan right |
| 253 | * after this function returns, run the complete here. |
| 254 | * The STATUS_SCAN_COMPLETE bit will then be cleared |
| 255 | * and prevent the background work from "completing" |
| 256 | * a possible new scan. |
| 257 | */ |
| 258 | iwl_process_scan_complete(priv); |
Tomas Winkler | 2a421b9 | 2008-06-12 09:47:10 +0800 | [diff] [blame] | 259 | } |
Tomas Winkler | 2a421b9 | 2008-06-12 09:47:10 +0800 | [diff] [blame] | 260 | |
Tomas Winkler | 2a421b9 | 2008-06-12 09:47:10 +0800 | [diff] [blame] | 261 | /* Service response to REPLY_SCAN_CMD (0x80) */ |
Emmanuel Grumbach | 247c61d | 2011-09-20 15:37:23 -0700 | [diff] [blame] | 262 | static int iwl_rx_reply_scan(struct iwl_priv *priv, |
Johannes Berg | 48a2d66 | 2012-03-05 11:24:39 -0800 | [diff] [blame] | 263 | struct iwl_rx_cmd_buffer *rxb, |
Emmanuel Grumbach | 247c61d | 2011-09-20 15:37:23 -0700 | [diff] [blame] | 264 | struct iwl_device_cmd *cmd) |
Tomas Winkler | 2a421b9 | 2008-06-12 09:47:10 +0800 | [diff] [blame] | 265 | { |
| 266 | #ifdef CONFIG_IWLWIFI_DEBUG |
Zhu Yi | 2f30122 | 2009-10-09 17:19:45 +0800 | [diff] [blame] | 267 | struct iwl_rx_packet *pkt = rxb_addr(rxb); |
Tomas Winkler | 2a421b9 | 2008-06-12 09:47:10 +0800 | [diff] [blame] | 268 | struct iwl_scanreq_notification *notif = |
| 269 | (struct iwl_scanreq_notification *)pkt->u.raw; |
| 270 | |
Stanislaw Gruszka | 7cf2442 | 2010-09-13 14:46:44 +0200 | [diff] [blame] | 271 | IWL_DEBUG_SCAN(priv, "Scan request status = 0x%x\n", notif->status); |
Tomas Winkler | 2a421b9 | 2008-06-12 09:47:10 +0800 | [diff] [blame] | 272 | #endif |
Emmanuel Grumbach | 247c61d | 2011-09-20 15:37:23 -0700 | [diff] [blame] | 273 | return 0; |
Tomas Winkler | 2a421b9 | 2008-06-12 09:47:10 +0800 | [diff] [blame] | 274 | } |
| 275 | |
| 276 | /* Service SCAN_START_NOTIFICATION (0x82) */ |
Emmanuel Grumbach | 247c61d | 2011-09-20 15:37:23 -0700 | [diff] [blame] | 277 | static int iwl_rx_scan_start_notif(struct iwl_priv *priv, |
Johannes Berg | 48a2d66 | 2012-03-05 11:24:39 -0800 | [diff] [blame] | 278 | struct iwl_rx_cmd_buffer *rxb, |
Emmanuel Grumbach | 247c61d | 2011-09-20 15:37:23 -0700 | [diff] [blame] | 279 | struct iwl_device_cmd *cmd) |
Tomas Winkler | 2a421b9 | 2008-06-12 09:47:10 +0800 | [diff] [blame] | 280 | { |
Zhu Yi | 2f30122 | 2009-10-09 17:19:45 +0800 | [diff] [blame] | 281 | struct iwl_rx_packet *pkt = rxb_addr(rxb); |
Tomas Winkler | 2a421b9 | 2008-06-12 09:47:10 +0800 | [diff] [blame] | 282 | struct iwl_scanstart_notification *notif = |
| 283 | (struct iwl_scanstart_notification *)pkt->u.raw; |
| 284 | priv->scan_start_tsf = le32_to_cpu(notif->tsf_low); |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 285 | IWL_DEBUG_SCAN(priv, "Scan start: " |
Tomas Winkler | 2a421b9 | 2008-06-12 09:47:10 +0800 | [diff] [blame] | 286 | "%d [802.11%s] " |
| 287 | "(TSF: 0x%08X:%08X) - %d (beacon timer %u)\n", |
| 288 | notif->channel, |
| 289 | notif->band ? "bg" : "a", |
Tomas Winkler | fe905f1 | 2008-07-11 11:53:39 +0800 | [diff] [blame] | 290 | le32_to_cpu(notif->tsf_high), |
| 291 | le32_to_cpu(notif->tsf_low), |
| 292 | notif->status, notif->beacon_timer); |
Johannes Berg | c6baf7f | 2011-07-23 10:24:47 -0700 | [diff] [blame] | 293 | |
Johannes Berg | 390808d | 2011-09-20 15:37:22 -0700 | [diff] [blame] | 294 | if (priv->scan_type == IWL_SCAN_ROC && |
| 295 | !priv->hw_roc_start_notified) { |
Johannes Berg | c6baf7f | 2011-07-23 10:24:47 -0700 | [diff] [blame] | 296 | ieee80211_ready_on_channel(priv->hw); |
Johannes Berg | 390808d | 2011-09-20 15:37:22 -0700 | [diff] [blame] | 297 | priv->hw_roc_start_notified = true; |
| 298 | } |
Emmanuel Grumbach | 247c61d | 2011-09-20 15:37:23 -0700 | [diff] [blame] | 299 | |
| 300 | return 0; |
Tomas Winkler | 2a421b9 | 2008-06-12 09:47:10 +0800 | [diff] [blame] | 301 | } |
| 302 | |
| 303 | /* Service SCAN_RESULTS_NOTIFICATION (0x83) */ |
Emmanuel Grumbach | 247c61d | 2011-09-20 15:37:23 -0700 | [diff] [blame] | 304 | static int iwl_rx_scan_results_notif(struct iwl_priv *priv, |
Johannes Berg | 48a2d66 | 2012-03-05 11:24:39 -0800 | [diff] [blame] | 305 | struct iwl_rx_cmd_buffer *rxb, |
Emmanuel Grumbach | 247c61d | 2011-09-20 15:37:23 -0700 | [diff] [blame] | 306 | struct iwl_device_cmd *cmd) |
Tomas Winkler | 2a421b9 | 2008-06-12 09:47:10 +0800 | [diff] [blame] | 307 | { |
| 308 | #ifdef CONFIG_IWLWIFI_DEBUG |
Zhu Yi | 2f30122 | 2009-10-09 17:19:45 +0800 | [diff] [blame] | 309 | struct iwl_rx_packet *pkt = rxb_addr(rxb); |
Tomas Winkler | 2a421b9 | 2008-06-12 09:47:10 +0800 | [diff] [blame] | 310 | struct iwl_scanresults_notification *notif = |
| 311 | (struct iwl_scanresults_notification *)pkt->u.raw; |
| 312 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 313 | IWL_DEBUG_SCAN(priv, "Scan ch.res: " |
Tomas Winkler | 2a421b9 | 2008-06-12 09:47:10 +0800 | [diff] [blame] | 314 | "%d [802.11%s] " |
Wey-Yi Guy | 1895b36 | 2011-09-22 15:14:51 -0700 | [diff] [blame] | 315 | "probe status: %u:%u " |
Tomas Winkler | 2a421b9 | 2008-06-12 09:47:10 +0800 | [diff] [blame] | 316 | "(TSF: 0x%08X:%08X) - %d " |
Henry Zhangh | 220575f | 2010-01-22 14:22:44 -0800 | [diff] [blame] | 317 | "elapsed=%lu usec\n", |
Tomas Winkler | 2a421b9 | 2008-06-12 09:47:10 +0800 | [diff] [blame] | 318 | notif->channel, |
| 319 | notif->band ? "bg" : "a", |
Wey-Yi Guy | 1895b36 | 2011-09-22 15:14:51 -0700 | [diff] [blame] | 320 | notif->probe_status, notif->num_probe_not_sent, |
Tomas Winkler | 2a421b9 | 2008-06-12 09:47:10 +0800 | [diff] [blame] | 321 | le32_to_cpu(notif->tsf_high), |
| 322 | le32_to_cpu(notif->tsf_low), |
| 323 | le32_to_cpu(notif->statistics[0]), |
Henry Zhangh | 220575f | 2010-01-22 14:22:44 -0800 | [diff] [blame] | 324 | le32_to_cpu(notif->tsf_low) - priv->scan_start_tsf); |
Tomas Winkler | 2a421b9 | 2008-06-12 09:47:10 +0800 | [diff] [blame] | 325 | #endif |
Emmanuel Grumbach | 247c61d | 2011-09-20 15:37:23 -0700 | [diff] [blame] | 326 | return 0; |
Tomas Winkler | 2a421b9 | 2008-06-12 09:47:10 +0800 | [diff] [blame] | 327 | } |
| 328 | |
| 329 | /* Service SCAN_COMPLETE_NOTIFICATION (0x84) */ |
Emmanuel Grumbach | 247c61d | 2011-09-20 15:37:23 -0700 | [diff] [blame] | 330 | static int iwl_rx_scan_complete_notif(struct iwl_priv *priv, |
Johannes Berg | 48a2d66 | 2012-03-05 11:24:39 -0800 | [diff] [blame] | 331 | struct iwl_rx_cmd_buffer *rxb, |
Emmanuel Grumbach | 247c61d | 2011-09-20 15:37:23 -0700 | [diff] [blame] | 332 | struct iwl_device_cmd *cmd) |
Tomas Winkler | 2a421b9 | 2008-06-12 09:47:10 +0800 | [diff] [blame] | 333 | { |
Zhu Yi | 2f30122 | 2009-10-09 17:19:45 +0800 | [diff] [blame] | 334 | struct iwl_rx_packet *pkt = rxb_addr(rxb); |
Tomas Winkler | 2a421b9 | 2008-06-12 09:47:10 +0800 | [diff] [blame] | 335 | struct iwl_scancomplete_notification *scan_notif = (void *)pkt->u.raw; |
| 336 | |
Tomas Winkler | e162344 | 2009-01-27 14:27:56 -0800 | [diff] [blame] | 337 | IWL_DEBUG_SCAN(priv, "Scan complete: %d channels (TSF 0x%08X:%08X) - %d\n", |
Tomas Winkler | 2a421b9 | 2008-06-12 09:47:10 +0800 | [diff] [blame] | 338 | scan_notif->scanned_channels, |
| 339 | scan_notif->tsf_low, |
| 340 | scan_notif->tsf_high, scan_notif->status); |
| 341 | |
Stanislaw Gruszka | 7cf2442 | 2010-09-13 14:46:44 +0200 | [diff] [blame] | 342 | IWL_DEBUG_SCAN(priv, "Scan on %sGHz took %dms\n", |
Johannes Berg | 00700ee | 2010-04-06 04:12:37 -0700 | [diff] [blame] | 343 | (priv->scan_band == IEEE80211_BAND_2GHZ) ? "2.4" : "5.2", |
Stanislaw Gruszka | ef1b21f | 2010-11-12 08:47:07 +0100 | [diff] [blame] | 344 | jiffies_to_msecs(jiffies - priv->scan_start)); |
Tomas Winkler | 2a421b9 | 2008-06-12 09:47:10 +0800 | [diff] [blame] | 345 | |
Johannes Berg | 84b1bec | 2011-09-22 15:15:00 -0700 | [diff] [blame] | 346 | /* |
| 347 | * When aborting, we run the scan completed background work inline |
| 348 | * and the background work must then do nothing. The SCAN_COMPLETE |
| 349 | * bit helps implement that logic and thus needs to be set before |
| 350 | * queueing the work. Also, since the scan abort waits for SCAN_HW |
| 351 | * to clear, we need to set SCAN_COMPLETE before clearing SCAN_HW |
| 352 | * to avoid a race there. |
| 353 | */ |
| 354 | set_bit(STATUS_SCAN_COMPLETE, &priv->shrd->status); |
| 355 | clear_bit(STATUS_SCAN_HW, &priv->shrd->status); |
Johannes Berg | 1ee158d | 2012-02-17 10:07:44 -0800 | [diff] [blame] | 356 | queue_work(priv->workqueue, &priv->scan_completed); |
Tomas Winkler | 2a421b9 | 2008-06-12 09:47:10 +0800 | [diff] [blame] | 357 | |
Wey-Yi Guy | f78e545 | 2010-08-23 07:57:15 -0700 | [diff] [blame] | 358 | if (priv->iw_mode != NL80211_IFTYPE_ADHOC && |
Stanislaw Gruszka | 88e58fc | 2011-01-28 16:47:47 +0100 | [diff] [blame] | 359 | iwl_advanced_bt_coexist(priv) && |
Johannes Berg | d5926d9 | 2010-09-13 14:46:34 +0200 | [diff] [blame] | 360 | priv->bt_status != scan_notif->bt_status) { |
Wey-Yi Guy | f78e545 | 2010-08-23 07:57:15 -0700 | [diff] [blame] | 361 | if (scan_notif->bt_status) { |
| 362 | /* BT on */ |
| 363 | if (!priv->bt_ch_announce) |
| 364 | priv->bt_traffic_load = |
| 365 | IWL_BT_COEX_TRAFFIC_LOAD_HIGH; |
| 366 | /* |
| 367 | * otherwise, no traffic load information provided |
| 368 | * no changes made |
| 369 | */ |
| 370 | } else { |
| 371 | /* BT off */ |
| 372 | priv->bt_traffic_load = |
| 373 | IWL_BT_COEX_TRAFFIC_LOAD_NONE; |
| 374 | } |
| 375 | priv->bt_status = scan_notif->bt_status; |
Johannes Berg | 1ee158d | 2012-02-17 10:07:44 -0800 | [diff] [blame] | 376 | queue_work(priv->workqueue, |
Emmanuel Grumbach | 74e28e4 | 2011-08-25 23:10:41 -0700 | [diff] [blame] | 377 | &priv->bt_traffic_change_work); |
Wey-Yi Guy | f78e545 | 2010-08-23 07:57:15 -0700 | [diff] [blame] | 378 | } |
Emmanuel Grumbach | 247c61d | 2011-09-20 15:37:23 -0700 | [diff] [blame] | 379 | return 0; |
Tomas Winkler | 2a421b9 | 2008-06-12 09:47:10 +0800 | [diff] [blame] | 380 | } |
| 381 | |
| 382 | void iwl_setup_rx_scan_handlers(struct iwl_priv *priv) |
| 383 | { |
| 384 | /* scan handlers */ |
| 385 | priv->rx_handlers[REPLY_SCAN_CMD] = iwl_rx_reply_scan; |
| 386 | priv->rx_handlers[SCAN_START_NOTIFICATION] = iwl_rx_scan_start_notif; |
| 387 | priv->rx_handlers[SCAN_RESULTS_NOTIFICATION] = |
| 388 | iwl_rx_scan_results_notif; |
| 389 | priv->rx_handlers[SCAN_COMPLETE_NOTIFICATION] = |
| 390 | iwl_rx_scan_complete_notif; |
| 391 | } |
Tomas Winkler | 2a421b9 | 2008-06-12 09:47:10 +0800 | [diff] [blame] | 392 | |
Johannes Berg | 6e809a1 | 2011-09-20 15:37:20 -0700 | [diff] [blame] | 393 | static u16 iwl_get_active_dwell_time(struct iwl_priv *priv, |
| 394 | enum ieee80211_band band, u8 n_probes) |
Tomas Winkler | 2a421b9 | 2008-06-12 09:47:10 +0800 | [diff] [blame] | 395 | { |
| 396 | if (band == IEEE80211_BAND_5GHZ) |
Tomas Winkler | fe905f1 | 2008-07-11 11:53:39 +0800 | [diff] [blame] | 397 | return IWL_ACTIVE_DWELL_TIME_52 + |
| 398 | IWL_ACTIVE_DWELL_FACTOR_52GHZ * (n_probes + 1); |
Tomas Winkler | 2a421b9 | 2008-06-12 09:47:10 +0800 | [diff] [blame] | 399 | else |
Tomas Winkler | fe905f1 | 2008-07-11 11:53:39 +0800 | [diff] [blame] | 400 | return IWL_ACTIVE_DWELL_TIME_24 + |
| 401 | IWL_ACTIVE_DWELL_FACTOR_24GHZ * (n_probes + 1); |
Tomas Winkler | 2a421b9 | 2008-06-12 09:47:10 +0800 | [diff] [blame] | 402 | } |
| 403 | |
Johannes Berg | 390808d | 2011-09-20 15:37:22 -0700 | [diff] [blame] | 404 | static u16 iwl_limit_dwell(struct iwl_priv *priv, u16 dwell_time) |
| 405 | { |
| 406 | struct iwl_rxon_context *ctx; |
| 407 | |
| 408 | /* |
| 409 | * If we're associated, we clamp the dwell time 98% |
| 410 | * of the smallest beacon interval (minus 2 * channel |
| 411 | * tune time) |
| 412 | */ |
| 413 | for_each_context(priv, ctx) { |
| 414 | u16 value; |
| 415 | |
Johannes Berg | 2ed8171 | 2012-01-28 08:30:52 -0800 | [diff] [blame] | 416 | switch (ctx->staging.dev_type) { |
| 417 | case RXON_DEV_TYPE_P2P: |
| 418 | /* no timing constraints */ |
Johannes Berg | 390808d | 2011-09-20 15:37:22 -0700 | [diff] [blame] | 419 | continue; |
Johannes Berg | 2ed8171 | 2012-01-28 08:30:52 -0800 | [diff] [blame] | 420 | case RXON_DEV_TYPE_ESS: |
| 421 | default: |
| 422 | /* timing constraints if associated */ |
| 423 | if (!iwl_is_associated_ctx(ctx)) |
| 424 | continue; |
| 425 | break; |
| 426 | case RXON_DEV_TYPE_CP: |
| 427 | case RXON_DEV_TYPE_2STA: |
| 428 | /* |
| 429 | * These seem to always have timers for TBTT |
| 430 | * active in uCode even when not associated yet. |
| 431 | */ |
| 432 | break; |
| 433 | } |
| 434 | |
Johannes Berg | 390808d | 2011-09-20 15:37:22 -0700 | [diff] [blame] | 435 | value = ctx->beacon_int; |
| 436 | if (!value) |
| 437 | value = IWL_PASSIVE_DWELL_BASE; |
| 438 | value = (value * 98) / 100 - IWL_CHANNEL_TUNE_TIME * 2; |
| 439 | dwell_time = min(value, dwell_time); |
| 440 | } |
| 441 | |
| 442 | return dwell_time; |
| 443 | } |
| 444 | |
Johannes Berg | 6e809a1 | 2011-09-20 15:37:20 -0700 | [diff] [blame] | 445 | static u16 iwl_get_passive_dwell_time(struct iwl_priv *priv, |
| 446 | enum ieee80211_band band) |
Tomas Winkler | 2a421b9 | 2008-06-12 09:47:10 +0800 | [diff] [blame] | 447 | { |
Tomas Winkler | fe905f1 | 2008-07-11 11:53:39 +0800 | [diff] [blame] | 448 | u16 passive = (band == IEEE80211_BAND_2GHZ) ? |
Tomas Winkler | 2a421b9 | 2008-06-12 09:47:10 +0800 | [diff] [blame] | 449 | IWL_PASSIVE_DWELL_BASE + IWL_PASSIVE_DWELL_TIME_24 : |
| 450 | IWL_PASSIVE_DWELL_BASE + IWL_PASSIVE_DWELL_TIME_52; |
| 451 | |
Johannes Berg | 390808d | 2011-09-20 15:37:22 -0700 | [diff] [blame] | 452 | return iwl_limit_dwell(priv, passive); |
Tomas Winkler | 2a421b9 | 2008-06-12 09:47:10 +0800 | [diff] [blame] | 453 | } |
| 454 | |
Johannes Berg | 6e809a1 | 2011-09-20 15:37:20 -0700 | [diff] [blame] | 455 | static int iwl_get_single_channel_for_scan(struct iwl_priv *priv, |
| 456 | struct ieee80211_vif *vif, |
| 457 | enum ieee80211_band band, |
| 458 | struct iwl_scan_channel *scan_ch) |
| 459 | { |
| 460 | const struct ieee80211_supported_band *sband; |
| 461 | u16 passive_dwell = 0; |
| 462 | u16 active_dwell = 0; |
| 463 | int added = 0; |
| 464 | u16 channel = 0; |
| 465 | |
| 466 | sband = iwl_get_hw_mode(priv, band); |
| 467 | if (!sband) { |
| 468 | IWL_ERR(priv, "invalid band\n"); |
| 469 | return added; |
| 470 | } |
| 471 | |
| 472 | active_dwell = iwl_get_active_dwell_time(priv, band, 0); |
| 473 | passive_dwell = iwl_get_passive_dwell_time(priv, band); |
| 474 | |
| 475 | if (passive_dwell <= active_dwell) |
| 476 | passive_dwell = active_dwell + 1; |
| 477 | |
| 478 | channel = iwl_get_single_channel_number(priv, band); |
| 479 | if (channel) { |
| 480 | scan_ch->channel = cpu_to_le16(channel); |
| 481 | scan_ch->type = SCAN_CHANNEL_TYPE_PASSIVE; |
| 482 | scan_ch->active_dwell = cpu_to_le16(active_dwell); |
| 483 | scan_ch->passive_dwell = cpu_to_le16(passive_dwell); |
| 484 | /* Set txpower levels to defaults */ |
| 485 | scan_ch->dsp_atten = 110; |
| 486 | if (band == IEEE80211_BAND_5GHZ) |
| 487 | scan_ch->tx_gain = ((1 << 5) | (3 << 3)) | 3; |
| 488 | else |
| 489 | scan_ch->tx_gain = ((1 << 5) | (5 << 3)); |
| 490 | added++; |
| 491 | } else |
| 492 | IWL_ERR(priv, "no valid channel found\n"); |
| 493 | return added; |
| 494 | } |
| 495 | |
| 496 | static int iwl_get_channels_for_scan(struct iwl_priv *priv, |
| 497 | struct ieee80211_vif *vif, |
| 498 | enum ieee80211_band band, |
| 499 | u8 is_active, u8 n_probes, |
| 500 | struct iwl_scan_channel *scan_ch) |
| 501 | { |
| 502 | struct ieee80211_channel *chan; |
| 503 | const struct ieee80211_supported_band *sband; |
| 504 | const struct iwl_channel_info *ch_info; |
| 505 | u16 passive_dwell = 0; |
| 506 | u16 active_dwell = 0; |
| 507 | int added, i; |
| 508 | u16 channel; |
| 509 | |
| 510 | sband = iwl_get_hw_mode(priv, band); |
| 511 | if (!sband) |
| 512 | return 0; |
| 513 | |
| 514 | active_dwell = iwl_get_active_dwell_time(priv, band, n_probes); |
| 515 | passive_dwell = iwl_get_passive_dwell_time(priv, band); |
| 516 | |
| 517 | if (passive_dwell <= active_dwell) |
| 518 | passive_dwell = active_dwell + 1; |
| 519 | |
| 520 | for (i = 0, added = 0; i < priv->scan_request->n_channels; i++) { |
| 521 | chan = priv->scan_request->channels[i]; |
| 522 | |
| 523 | if (chan->band != band) |
| 524 | continue; |
| 525 | |
| 526 | channel = chan->hw_value; |
| 527 | scan_ch->channel = cpu_to_le16(channel); |
| 528 | |
| 529 | ch_info = iwl_get_channel_info(priv, band, channel); |
| 530 | if (!is_channel_valid(ch_info)) { |
| 531 | IWL_DEBUG_SCAN(priv, |
| 532 | "Channel %d is INVALID for this band.\n", |
| 533 | channel); |
| 534 | continue; |
| 535 | } |
| 536 | |
| 537 | if (!is_active || is_channel_passive(ch_info) || |
| 538 | (chan->flags & IEEE80211_CHAN_PASSIVE_SCAN)) |
| 539 | scan_ch->type = SCAN_CHANNEL_TYPE_PASSIVE; |
| 540 | else |
| 541 | scan_ch->type = SCAN_CHANNEL_TYPE_ACTIVE; |
| 542 | |
| 543 | if (n_probes) |
| 544 | scan_ch->type |= IWL_SCAN_PROBE_MASK(n_probes); |
| 545 | |
| 546 | scan_ch->active_dwell = cpu_to_le16(active_dwell); |
| 547 | scan_ch->passive_dwell = cpu_to_le16(passive_dwell); |
| 548 | |
| 549 | /* Set txpower levels to defaults */ |
| 550 | scan_ch->dsp_atten = 110; |
| 551 | |
| 552 | /* NOTE: if we were doing 6Mb OFDM for scans we'd use |
| 553 | * power level: |
| 554 | * scan_ch->tx_gain = ((1 << 5) | (2 << 3)) | 3; |
| 555 | */ |
| 556 | if (band == IEEE80211_BAND_5GHZ) |
| 557 | scan_ch->tx_gain = ((1 << 5) | (3 << 3)) | 3; |
| 558 | else |
| 559 | scan_ch->tx_gain = ((1 << 5) | (5 << 3)); |
| 560 | |
| 561 | IWL_DEBUG_SCAN(priv, "Scanning ch=%d prob=0x%X [%s %d]\n", |
| 562 | channel, le32_to_cpu(scan_ch->type), |
| 563 | (scan_ch->type & SCAN_CHANNEL_TYPE_ACTIVE) ? |
| 564 | "ACTIVE" : "PASSIVE", |
| 565 | (scan_ch->type & SCAN_CHANNEL_TYPE_ACTIVE) ? |
| 566 | active_dwell : passive_dwell); |
| 567 | |
| 568 | scan_ch++; |
| 569 | added++; |
| 570 | } |
| 571 | |
| 572 | IWL_DEBUG_SCAN(priv, "total channels to scan %d\n", added); |
| 573 | return added; |
| 574 | } |
| 575 | |
| 576 | static int iwlagn_request_scan(struct iwl_priv *priv, struct ieee80211_vif *vif) |
| 577 | { |
| 578 | struct iwl_host_cmd cmd = { |
| 579 | .id = REPLY_SCAN_CMD, |
| 580 | .len = { sizeof(struct iwl_scan_cmd), }, |
| 581 | .flags = CMD_SYNC, |
| 582 | }; |
| 583 | struct iwl_scan_cmd *scan; |
| 584 | struct iwl_rxon_context *ctx = &priv->contexts[IWL_RXON_CTX_BSS]; |
| 585 | u32 rate_flags = 0; |
Fabio Estevam | 331d930 | 2012-01-16 00:47:12 -0200 | [diff] [blame] | 586 | u16 cmd_len = 0; |
Johannes Berg | 6e809a1 | 2011-09-20 15:37:20 -0700 | [diff] [blame] | 587 | u16 rx_chain = 0; |
| 588 | enum ieee80211_band band; |
| 589 | u8 n_probes = 0; |
| 590 | u8 rx_ant = hw_params(priv).valid_rx_ant; |
| 591 | u8 rate; |
| 592 | bool is_active = false; |
| 593 | int chan_mod; |
| 594 | u8 active_chains; |
| 595 | u8 scan_tx_antennas = hw_params(priv).valid_tx_ant; |
| 596 | int ret; |
| 597 | |
Johannes Berg | b1eea29 | 2012-03-06 13:30:42 -0800 | [diff] [blame^] | 598 | lockdep_assert_held(&priv->mutex); |
Johannes Berg | 6e809a1 | 2011-09-20 15:37:20 -0700 | [diff] [blame] | 599 | |
| 600 | if (vif) |
| 601 | ctx = iwl_rxon_ctx_from_vif(vif); |
| 602 | |
| 603 | if (!priv->scan_cmd) { |
| 604 | priv->scan_cmd = kmalloc(sizeof(struct iwl_scan_cmd) + |
| 605 | IWL_MAX_SCAN_SIZE, GFP_KERNEL); |
| 606 | if (!priv->scan_cmd) { |
| 607 | IWL_DEBUG_SCAN(priv, |
| 608 | "fail to allocate memory for scan\n"); |
| 609 | return -ENOMEM; |
| 610 | } |
| 611 | } |
| 612 | scan = priv->scan_cmd; |
| 613 | memset(scan, 0, sizeof(struct iwl_scan_cmd) + IWL_MAX_SCAN_SIZE); |
| 614 | |
| 615 | scan->quiet_plcp_th = IWL_PLCP_QUIET_THRESH; |
| 616 | scan->quiet_time = IWL_ACTIVE_QUIET_TIME; |
| 617 | |
| 618 | if (priv->scan_type != IWL_SCAN_ROC && |
| 619 | iwl_is_any_associated(priv)) { |
| 620 | u16 interval = 0; |
| 621 | u32 extra; |
| 622 | u32 suspend_time = 100; |
| 623 | u32 scan_suspend_time = 100; |
| 624 | |
| 625 | IWL_DEBUG_INFO(priv, "Scanning while associated...\n"); |
| 626 | switch (priv->scan_type) { |
| 627 | case IWL_SCAN_ROC: |
| 628 | WARN_ON(1); |
| 629 | break; |
| 630 | case IWL_SCAN_RADIO_RESET: |
| 631 | interval = 0; |
| 632 | break; |
| 633 | case IWL_SCAN_NORMAL: |
| 634 | interval = vif->bss_conf.beacon_int; |
| 635 | break; |
| 636 | } |
| 637 | |
| 638 | scan->suspend_time = 0; |
| 639 | scan->max_out_time = cpu_to_le32(200 * 1024); |
| 640 | if (!interval) |
| 641 | interval = suspend_time; |
| 642 | |
| 643 | extra = (suspend_time / interval) << 22; |
| 644 | scan_suspend_time = (extra | |
| 645 | ((suspend_time % interval) * 1024)); |
| 646 | scan->suspend_time = cpu_to_le32(scan_suspend_time); |
| 647 | IWL_DEBUG_SCAN(priv, "suspend_time 0x%X beacon interval %d\n", |
| 648 | scan_suspend_time, interval); |
| 649 | } else if (priv->scan_type == IWL_SCAN_ROC) { |
| 650 | scan->suspend_time = 0; |
| 651 | scan->max_out_time = 0; |
| 652 | scan->quiet_time = 0; |
| 653 | scan->quiet_plcp_th = 0; |
| 654 | } |
| 655 | |
| 656 | switch (priv->scan_type) { |
| 657 | case IWL_SCAN_RADIO_RESET: |
| 658 | IWL_DEBUG_SCAN(priv, "Start internal passive scan.\n"); |
| 659 | break; |
| 660 | case IWL_SCAN_NORMAL: |
| 661 | if (priv->scan_request->n_ssids) { |
| 662 | int i, p = 0; |
| 663 | IWL_DEBUG_SCAN(priv, "Kicking off active scan\n"); |
| 664 | for (i = 0; i < priv->scan_request->n_ssids; i++) { |
| 665 | /* always does wildcard anyway */ |
| 666 | if (!priv->scan_request->ssids[i].ssid_len) |
| 667 | continue; |
| 668 | scan->direct_scan[p].id = WLAN_EID_SSID; |
| 669 | scan->direct_scan[p].len = |
| 670 | priv->scan_request->ssids[i].ssid_len; |
| 671 | memcpy(scan->direct_scan[p].ssid, |
| 672 | priv->scan_request->ssids[i].ssid, |
| 673 | priv->scan_request->ssids[i].ssid_len); |
| 674 | n_probes++; |
| 675 | p++; |
| 676 | } |
| 677 | is_active = true; |
| 678 | } else |
| 679 | IWL_DEBUG_SCAN(priv, "Start passive scan.\n"); |
| 680 | break; |
| 681 | case IWL_SCAN_ROC: |
| 682 | IWL_DEBUG_SCAN(priv, "Start ROC scan.\n"); |
| 683 | break; |
| 684 | } |
| 685 | |
| 686 | scan->tx_cmd.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK; |
| 687 | scan->tx_cmd.sta_id = ctx->bcast_sta_id; |
| 688 | scan->tx_cmd.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE; |
| 689 | |
| 690 | switch (priv->scan_band) { |
| 691 | case IEEE80211_BAND_2GHZ: |
| 692 | scan->flags = RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK; |
| 693 | chan_mod = le32_to_cpu( |
| 694 | priv->contexts[IWL_RXON_CTX_BSS].active.flags & |
| 695 | RXON_FLG_CHANNEL_MODE_MSK) |
| 696 | >> RXON_FLG_CHANNEL_MODE_POS; |
Johannes Berg | 3a8aea0 | 2011-10-14 12:54:48 -0700 | [diff] [blame] | 697 | if ((priv->scan_request && priv->scan_request->no_cck) || |
| 698 | chan_mod == CHANNEL_MODE_PURE_40) { |
Johannes Berg | 6e809a1 | 2011-09-20 15:37:20 -0700 | [diff] [blame] | 699 | rate = IWL_RATE_6M_PLCP; |
| 700 | } else { |
| 701 | rate = IWL_RATE_1M_PLCP; |
| 702 | rate_flags = RATE_MCS_CCK_MSK; |
| 703 | } |
| 704 | /* |
| 705 | * Internal scans are passive, so we can indiscriminately set |
| 706 | * the BT ignore flag on 2.4 GHz since it applies to TX only. |
| 707 | */ |
Don Fry | 3862241 | 2011-12-16 07:07:36 -0800 | [diff] [blame] | 708 | if (cfg(priv)->bt_params && |
| 709 | cfg(priv)->bt_params->advanced_bt_coexist) |
Johannes Berg | 6e809a1 | 2011-09-20 15:37:20 -0700 | [diff] [blame] | 710 | scan->tx_cmd.tx_flags |= TX_CMD_FLG_IGNORE_BT; |
| 711 | break; |
| 712 | case IEEE80211_BAND_5GHZ: |
| 713 | rate = IWL_RATE_6M_PLCP; |
| 714 | break; |
| 715 | default: |
| 716 | IWL_WARN(priv, "Invalid scan band\n"); |
| 717 | return -EIO; |
| 718 | } |
| 719 | |
| 720 | /* |
| 721 | * If active scanning is requested but a certain channel is |
| 722 | * marked passive, we can do active scanning if we detect |
| 723 | * transmissions. |
| 724 | * |
| 725 | * There is an issue with some firmware versions that triggers |
| 726 | * a sysassert on a "good CRC threshold" of zero (== disabled), |
| 727 | * on a radar channel even though this means that we should NOT |
| 728 | * send probes. |
| 729 | * |
| 730 | * The "good CRC threshold" is the number of frames that we |
| 731 | * need to receive during our dwell time on a channel before |
| 732 | * sending out probes -- setting this to a huge value will |
| 733 | * mean we never reach it, but at the same time work around |
| 734 | * the aforementioned issue. Thus use IWL_GOOD_CRC_TH_NEVER |
| 735 | * here instead of IWL_GOOD_CRC_TH_DISABLED. |
| 736 | * |
| 737 | * This was fixed in later versions along with some other |
| 738 | * scan changes, and the threshold behaves as a flag in those |
| 739 | * versions. |
| 740 | */ |
| 741 | if (priv->new_scan_threshold_behaviour) |
| 742 | scan->good_CRC_th = is_active ? IWL_GOOD_CRC_TH_DEFAULT : |
| 743 | IWL_GOOD_CRC_TH_DISABLED; |
| 744 | else |
| 745 | scan->good_CRC_th = is_active ? IWL_GOOD_CRC_TH_DEFAULT : |
| 746 | IWL_GOOD_CRC_TH_NEVER; |
| 747 | |
| 748 | band = priv->scan_band; |
| 749 | |
Don Fry | 3862241 | 2011-12-16 07:07:36 -0800 | [diff] [blame] | 750 | if (cfg(priv)->scan_rx_antennas[band]) |
| 751 | rx_ant = cfg(priv)->scan_rx_antennas[band]; |
Johannes Berg | 6e809a1 | 2011-09-20 15:37:20 -0700 | [diff] [blame] | 752 | |
| 753 | if (band == IEEE80211_BAND_2GHZ && |
Don Fry | 3862241 | 2011-12-16 07:07:36 -0800 | [diff] [blame] | 754 | cfg(priv)->bt_params && |
| 755 | cfg(priv)->bt_params->advanced_bt_coexist) { |
Johannes Berg | 6e809a1 | 2011-09-20 15:37:20 -0700 | [diff] [blame] | 756 | /* transmit 2.4 GHz probes only on first antenna */ |
| 757 | scan_tx_antennas = first_antenna(scan_tx_antennas); |
| 758 | } |
| 759 | |
| 760 | priv->scan_tx_ant[band] = iwl_toggle_tx_ant(priv, |
| 761 | priv->scan_tx_ant[band], |
| 762 | scan_tx_antennas); |
| 763 | rate_flags |= iwl_ant_idx_to_flags(priv->scan_tx_ant[band]); |
| 764 | scan->tx_cmd.rate_n_flags = iwl_hw_set_rate_n_flags(rate, rate_flags); |
| 765 | |
| 766 | /* In power save mode use one chain, otherwise use all chains */ |
| 767 | if (test_bit(STATUS_POWER_PMI, &priv->shrd->status)) { |
| 768 | /* rx_ant has been set to all valid chains previously */ |
| 769 | active_chains = rx_ant & |
| 770 | ((u8)(priv->chain_noise_data.active_chains)); |
| 771 | if (!active_chains) |
| 772 | active_chains = rx_ant; |
| 773 | |
| 774 | IWL_DEBUG_SCAN(priv, "chain_noise_data.active_chains: %u\n", |
| 775 | priv->chain_noise_data.active_chains); |
| 776 | |
| 777 | rx_ant = first_antenna(active_chains); |
| 778 | } |
Don Fry | 3862241 | 2011-12-16 07:07:36 -0800 | [diff] [blame] | 779 | if (cfg(priv)->bt_params && |
| 780 | cfg(priv)->bt_params->advanced_bt_coexist && |
Johannes Berg | 6e809a1 | 2011-09-20 15:37:20 -0700 | [diff] [blame] | 781 | priv->bt_full_concurrent) { |
| 782 | /* operated as 1x1 in full concurrency mode */ |
| 783 | rx_ant = first_antenna(rx_ant); |
| 784 | } |
| 785 | |
| 786 | /* MIMO is not used here, but value is required */ |
| 787 | rx_chain |= |
| 788 | hw_params(priv).valid_rx_ant << RXON_RX_CHAIN_VALID_POS; |
| 789 | rx_chain |= rx_ant << RXON_RX_CHAIN_FORCE_MIMO_SEL_POS; |
| 790 | rx_chain |= rx_ant << RXON_RX_CHAIN_FORCE_SEL_POS; |
| 791 | rx_chain |= 0x1 << RXON_RX_CHAIN_DRIVER_FORCE_POS; |
| 792 | scan->rx_chain = cpu_to_le16(rx_chain); |
| 793 | switch (priv->scan_type) { |
| 794 | case IWL_SCAN_NORMAL: |
| 795 | cmd_len = iwl_fill_probe_req(priv, |
| 796 | (struct ieee80211_mgmt *)scan->data, |
| 797 | vif->addr, |
| 798 | priv->scan_request->ie, |
| 799 | priv->scan_request->ie_len, |
| 800 | IWL_MAX_SCAN_SIZE - sizeof(*scan)); |
| 801 | break; |
| 802 | case IWL_SCAN_RADIO_RESET: |
| 803 | case IWL_SCAN_ROC: |
| 804 | /* use bcast addr, will not be transmitted but must be valid */ |
| 805 | cmd_len = iwl_fill_probe_req(priv, |
| 806 | (struct ieee80211_mgmt *)scan->data, |
| 807 | iwl_bcast_addr, NULL, 0, |
| 808 | IWL_MAX_SCAN_SIZE - sizeof(*scan)); |
| 809 | break; |
| 810 | default: |
| 811 | BUG(); |
| 812 | } |
| 813 | scan->tx_cmd.len = cpu_to_le16(cmd_len); |
| 814 | |
| 815 | scan->filter_flags |= (RXON_FILTER_ACCEPT_GRP_MSK | |
| 816 | RXON_FILTER_BCON_AWARE_MSK); |
| 817 | |
| 818 | switch (priv->scan_type) { |
| 819 | case IWL_SCAN_RADIO_RESET: |
| 820 | scan->channel_count = |
| 821 | iwl_get_single_channel_for_scan(priv, vif, band, |
| 822 | (void *)&scan->data[cmd_len]); |
| 823 | break; |
| 824 | case IWL_SCAN_NORMAL: |
| 825 | scan->channel_count = |
| 826 | iwl_get_channels_for_scan(priv, vif, band, |
| 827 | is_active, n_probes, |
| 828 | (void *)&scan->data[cmd_len]); |
| 829 | break; |
| 830 | case IWL_SCAN_ROC: { |
| 831 | struct iwl_scan_channel *scan_ch; |
Johannes Berg | 390808d | 2011-09-20 15:37:22 -0700 | [diff] [blame] | 832 | int n_chan, i; |
| 833 | u16 dwell; |
Johannes Berg | 6e809a1 | 2011-09-20 15:37:20 -0700 | [diff] [blame] | 834 | |
Johannes Berg | 390808d | 2011-09-20 15:37:22 -0700 | [diff] [blame] | 835 | dwell = iwl_limit_dwell(priv, priv->hw_roc_duration); |
| 836 | n_chan = DIV_ROUND_UP(priv->hw_roc_duration, dwell); |
| 837 | |
| 838 | scan->channel_count = n_chan; |
Johannes Berg | 6e809a1 | 2011-09-20 15:37:20 -0700 | [diff] [blame] | 839 | |
| 840 | scan_ch = (void *)&scan->data[cmd_len]; |
Johannes Berg | 6e809a1 | 2011-09-20 15:37:20 -0700 | [diff] [blame] | 841 | |
Johannes Berg | 390808d | 2011-09-20 15:37:22 -0700 | [diff] [blame] | 842 | for (i = 0; i < n_chan; i++) { |
| 843 | scan_ch->type = SCAN_CHANNEL_TYPE_PASSIVE; |
| 844 | scan_ch->channel = |
| 845 | cpu_to_le16(priv->hw_roc_channel->hw_value); |
Johannes Berg | 6e809a1 | 2011-09-20 15:37:20 -0700 | [diff] [blame] | 846 | |
Johannes Berg | 390808d | 2011-09-20 15:37:22 -0700 | [diff] [blame] | 847 | if (i == n_chan - 1) |
| 848 | dwell = priv->hw_roc_duration - i * dwell; |
| 849 | |
| 850 | scan_ch->active_dwell = |
| 851 | scan_ch->passive_dwell = cpu_to_le16(dwell); |
| 852 | |
| 853 | /* Set txpower levels to defaults */ |
| 854 | scan_ch->dsp_atten = 110; |
| 855 | |
| 856 | /* NOTE: if we were doing 6Mb OFDM for scans we'd use |
| 857 | * power level: |
| 858 | * scan_ch->tx_gain = ((1 << 5) | (2 << 3)) | 3; |
| 859 | */ |
| 860 | if (priv->hw_roc_channel->band == IEEE80211_BAND_5GHZ) |
| 861 | scan_ch->tx_gain = ((1 << 5) | (3 << 3)) | 3; |
| 862 | else |
| 863 | scan_ch->tx_gain = ((1 << 5) | (5 << 3)); |
| 864 | |
| 865 | scan_ch++; |
Johannes Berg | 6e809a1 | 2011-09-20 15:37:20 -0700 | [diff] [blame] | 866 | } |
Johannes Berg | 390808d | 2011-09-20 15:37:22 -0700 | [diff] [blame] | 867 | } |
| 868 | |
Johannes Berg | 6e809a1 | 2011-09-20 15:37:20 -0700 | [diff] [blame] | 869 | break; |
| 870 | } |
| 871 | |
| 872 | if (scan->channel_count == 0) { |
| 873 | IWL_DEBUG_SCAN(priv, "channel count %d\n", scan->channel_count); |
| 874 | return -EIO; |
| 875 | } |
| 876 | |
| 877 | cmd.len[0] += le16_to_cpu(scan->tx_cmd.len) + |
| 878 | scan->channel_count * sizeof(struct iwl_scan_channel); |
| 879 | cmd.data[0] = scan; |
| 880 | cmd.dataflags[0] = IWL_HCMD_DFL_NOCOPY; |
| 881 | scan->len = cpu_to_le16(cmd.len[0]); |
| 882 | |
| 883 | /* set scan bit here for PAN params */ |
| 884 | set_bit(STATUS_SCAN_HW, &priv->shrd->status); |
| 885 | |
| 886 | ret = iwlagn_set_pan_params(priv); |
| 887 | if (ret) |
| 888 | return ret; |
| 889 | |
Johannes Berg | e10a053 | 2012-03-06 13:30:39 -0800 | [diff] [blame] | 890 | ret = iwl_dvm_send_cmd(priv, &cmd); |
Johannes Berg | 6e809a1 | 2011-09-20 15:37:20 -0700 | [diff] [blame] | 891 | if (ret) { |
| 892 | clear_bit(STATUS_SCAN_HW, &priv->shrd->status); |
| 893 | iwlagn_set_pan_params(priv); |
| 894 | } |
| 895 | |
| 896 | return ret; |
| 897 | } |
| 898 | |
Tomas Winkler | f53696d | 2008-06-12 09:47:12 +0800 | [diff] [blame] | 899 | void iwl_init_scan_params(struct iwl_priv *priv) |
| 900 | { |
Emmanuel Grumbach | d618912 | 2011-08-25 23:10:39 -0700 | [diff] [blame] | 901 | u8 ant_idx = fls(hw_params(priv).valid_tx_ant) - 1; |
Tomas Winkler | f53696d | 2008-06-12 09:47:12 +0800 | [diff] [blame] | 902 | if (!priv->scan_tx_ant[IEEE80211_BAND_5GHZ]) |
Tomas Winkler | 76eff18 | 2008-10-14 12:32:45 -0700 | [diff] [blame] | 903 | priv->scan_tx_ant[IEEE80211_BAND_5GHZ] = ant_idx; |
Tomas Winkler | f53696d | 2008-06-12 09:47:12 +0800 | [diff] [blame] | 904 | if (!priv->scan_tx_ant[IEEE80211_BAND_2GHZ]) |
Tomas Winkler | 76eff18 | 2008-10-14 12:32:45 -0700 | [diff] [blame] | 905 | priv->scan_tx_ant[IEEE80211_BAND_2GHZ] = ant_idx; |
Tomas Winkler | f53696d | 2008-06-12 09:47:12 +0800 | [diff] [blame] | 906 | } |
| 907 | |
Johannes Berg | 266af4c7 | 2011-03-10 20:13:26 -0800 | [diff] [blame] | 908 | int __must_check iwl_scan_initiate(struct iwl_priv *priv, |
| 909 | struct ieee80211_vif *vif, |
| 910 | enum iwl_scan_type scan_type, |
| 911 | enum ieee80211_band band) |
Tomas Winkler | 2a421b9 | 2008-06-12 09:47:10 +0800 | [diff] [blame] | 912 | { |
Johannes Berg | 3eecce5 | 2010-09-13 14:46:33 +0200 | [diff] [blame] | 913 | int ret; |
Johannes Berg | 88be026 | 2010-04-07 00:21:36 -0700 | [diff] [blame] | 914 | |
Johannes Berg | b1eea29 | 2012-03-06 13:30:42 -0800 | [diff] [blame^] | 915 | lockdep_assert_held(&priv->mutex); |
Tomas Winkler | 2a421b9 | 2008-06-12 09:47:10 +0800 | [diff] [blame] | 916 | |
Johannes Berg | 3eecce5 | 2010-09-13 14:46:33 +0200 | [diff] [blame] | 917 | cancel_delayed_work(&priv->scan_check); |
| 918 | |
Emmanuel Grumbach | 845a9c0 | 2011-08-25 23:11:04 -0700 | [diff] [blame] | 919 | if (!iwl_is_ready_rf(priv->shrd)) { |
Stanislaw Gruszka | 7cf2442 | 2010-09-13 14:46:44 +0200 | [diff] [blame] | 920 | IWL_WARN(priv, "Request scan called when driver not ready.\n"); |
Johannes Berg | 3eecce5 | 2010-09-13 14:46:33 +0200 | [diff] [blame] | 921 | return -EIO; |
| 922 | } |
| 923 | |
Emmanuel Grumbach | 63013ae | 2011-08-25 23:10:42 -0700 | [diff] [blame] | 924 | if (test_bit(STATUS_SCAN_HW, &priv->shrd->status)) { |
Stanislaw Gruszka | 7cf2442 | 2010-09-13 14:46:44 +0200 | [diff] [blame] | 925 | IWL_DEBUG_SCAN(priv, |
Johannes Berg | 3eecce5 | 2010-09-13 14:46:33 +0200 | [diff] [blame] | 926 | "Multiple concurrent scan requests in parallel.\n"); |
| 927 | return -EBUSY; |
| 928 | } |
| 929 | |
Emmanuel Grumbach | 63013ae | 2011-08-25 23:10:42 -0700 | [diff] [blame] | 930 | if (test_bit(STATUS_SCAN_ABORTING, &priv->shrd->status)) { |
Stanislaw Gruszka | 7cf2442 | 2010-09-13 14:46:44 +0200 | [diff] [blame] | 931 | IWL_DEBUG_SCAN(priv, "Scan request while abort pending.\n"); |
Johannes Berg | 3eecce5 | 2010-09-13 14:46:33 +0200 | [diff] [blame] | 932 | return -EBUSY; |
| 933 | } |
| 934 | |
Stanislaw Gruszka | 7cf2442 | 2010-09-13 14:46:44 +0200 | [diff] [blame] | 935 | IWL_DEBUG_SCAN(priv, "Starting %sscan...\n", |
Johannes Berg | 266af4c7 | 2011-03-10 20:13:26 -0800 | [diff] [blame] | 936 | scan_type == IWL_SCAN_NORMAL ? "" : |
Johannes Berg | c6baf7f | 2011-07-23 10:24:47 -0700 | [diff] [blame] | 937 | scan_type == IWL_SCAN_ROC ? "remain-on-channel " : |
Johannes Berg | 266af4c7 | 2011-03-10 20:13:26 -0800 | [diff] [blame] | 938 | "internal short "); |
Johannes Berg | 3eecce5 | 2010-09-13 14:46:33 +0200 | [diff] [blame] | 939 | |
Emmanuel Grumbach | 63013ae | 2011-08-25 23:10:42 -0700 | [diff] [blame] | 940 | set_bit(STATUS_SCANNING, &priv->shrd->status); |
Johannes Berg | 266af4c7 | 2011-03-10 20:13:26 -0800 | [diff] [blame] | 941 | priv->scan_type = scan_type; |
Johannes Berg | 3eecce5 | 2010-09-13 14:46:33 +0200 | [diff] [blame] | 942 | priv->scan_start = jiffies; |
| 943 | priv->scan_band = band; |
| 944 | |
Don Fry | 5c3d29f | 2011-07-08 08:46:29 -0700 | [diff] [blame] | 945 | ret = iwlagn_request_scan(priv, vif); |
Johannes Berg | 3eecce5 | 2010-09-13 14:46:33 +0200 | [diff] [blame] | 946 | if (ret) { |
Emmanuel Grumbach | 63013ae | 2011-08-25 23:10:42 -0700 | [diff] [blame] | 947 | clear_bit(STATUS_SCANNING, &priv->shrd->status); |
Johannes Berg | 266af4c7 | 2011-03-10 20:13:26 -0800 | [diff] [blame] | 948 | priv->scan_type = IWL_SCAN_NORMAL; |
Johannes Berg | 3eecce5 | 2010-09-13 14:46:33 +0200 | [diff] [blame] | 949 | return ret; |
| 950 | } |
| 951 | |
Johannes Berg | 1ee158d | 2012-02-17 10:07:44 -0800 | [diff] [blame] | 952 | queue_delayed_work(priv->workqueue, &priv->scan_check, |
Johannes Berg | 3eecce5 | 2010-09-13 14:46:33 +0200 | [diff] [blame] | 953 | IWL_SCAN_CHECK_WATCHDOG); |
Tomas Winkler | 2a421b9 | 2008-06-12 09:47:10 +0800 | [diff] [blame] | 954 | |
| 955 | return 0; |
| 956 | } |
Tomas Winkler | 2a421b9 | 2008-06-12 09:47:10 +0800 | [diff] [blame] | 957 | |
Abhijeet Kolekar | e9dde6f6 | 2009-02-18 15:54:27 -0800 | [diff] [blame] | 958 | |
Wey-Yi Guy | afbdd69 | 2010-01-22 14:22:43 -0800 | [diff] [blame] | 959 | /* |
| 960 | * internal short scan, this function should only been called while associated. |
| 961 | * It will reset and tune the radio to prevent possible RF related problem |
| 962 | */ |
Johannes Berg | 88be026 | 2010-04-07 00:21:36 -0700 | [diff] [blame] | 963 | void iwl_internal_short_hw_scan(struct iwl_priv *priv) |
Wey-Yi Guy | afbdd69 | 2010-01-22 14:22:43 -0800 | [diff] [blame] | 964 | { |
Johannes Berg | 1ee158d | 2012-02-17 10:07:44 -0800 | [diff] [blame] | 965 | queue_work(priv->workqueue, &priv->start_internal_scan); |
Johannes Berg | 88be026 | 2010-04-07 00:21:36 -0700 | [diff] [blame] | 966 | } |
| 967 | |
Stanislaw Gruszka | c240879 | 2010-07-30 16:41:08 +0200 | [diff] [blame] | 968 | static void iwl_bg_start_internal_scan(struct work_struct *work) |
Johannes Berg | 88be026 | 2010-04-07 00:21:36 -0700 | [diff] [blame] | 969 | { |
| 970 | struct iwl_priv *priv = |
| 971 | container_of(work, struct iwl_priv, start_internal_scan); |
| 972 | |
Stanislaw Gruszka | 7cf2442 | 2010-09-13 14:46:44 +0200 | [diff] [blame] | 973 | IWL_DEBUG_SCAN(priv, "Start internal scan\n"); |
| 974 | |
Johannes Berg | b1eea29 | 2012-03-06 13:30:42 -0800 | [diff] [blame^] | 975 | mutex_lock(&priv->mutex); |
Wey-Yi Guy | afbdd69 | 2010-01-22 14:22:43 -0800 | [diff] [blame] | 976 | |
Johannes Berg | 266af4c7 | 2011-03-10 20:13:26 -0800 | [diff] [blame] | 977 | if (priv->scan_type == IWL_SCAN_RADIO_RESET) { |
Reinette Chatre | 073d5ea | 2010-05-13 14:49:44 -0700 | [diff] [blame] | 978 | IWL_DEBUG_SCAN(priv, "Internal scan already in progress\n"); |
| 979 | goto unlock; |
| 980 | } |
| 981 | |
Emmanuel Grumbach | 63013ae | 2011-08-25 23:10:42 -0700 | [diff] [blame] | 982 | if (test_bit(STATUS_SCANNING, &priv->shrd->status)) { |
Wey-Yi Guy | afbdd69 | 2010-01-22 14:22:43 -0800 | [diff] [blame] | 983 | IWL_DEBUG_SCAN(priv, "Scan already in progress.\n"); |
Johannes Berg | 88be026 | 2010-04-07 00:21:36 -0700 | [diff] [blame] | 984 | goto unlock; |
Wey-Yi Guy | afbdd69 | 2010-01-22 14:22:43 -0800 | [diff] [blame] | 985 | } |
Johannes Berg | 88be026 | 2010-04-07 00:21:36 -0700 | [diff] [blame] | 986 | |
Johannes Berg | 266af4c7 | 2011-03-10 20:13:26 -0800 | [diff] [blame] | 987 | if (iwl_scan_initiate(priv, NULL, IWL_SCAN_RADIO_RESET, priv->band)) |
Johannes Berg | 3eecce5 | 2010-09-13 14:46:33 +0200 | [diff] [blame] | 988 | IWL_DEBUG_SCAN(priv, "failed to start internal short scan\n"); |
Johannes Berg | 88be026 | 2010-04-07 00:21:36 -0700 | [diff] [blame] | 989 | unlock: |
Johannes Berg | b1eea29 | 2012-03-06 13:30:42 -0800 | [diff] [blame^] | 990 | mutex_unlock(&priv->mutex); |
Wey-Yi Guy | afbdd69 | 2010-01-22 14:22:43 -0800 | [diff] [blame] | 991 | } |
Wey-Yi Guy | afbdd69 | 2010-01-22 14:22:43 -0800 | [diff] [blame] | 992 | |
Stanislaw Gruszka | c240879 | 2010-07-30 16:41:08 +0200 | [diff] [blame] | 993 | static void iwl_bg_scan_check(struct work_struct *data) |
Tomas Winkler | 2a421b9 | 2008-06-12 09:47:10 +0800 | [diff] [blame] | 994 | { |
| 995 | struct iwl_priv *priv = |
| 996 | container_of(data, struct iwl_priv, scan_check.work); |
| 997 | |
Stanislaw Gruszka | 7cf2442 | 2010-09-13 14:46:44 +0200 | [diff] [blame] | 998 | IWL_DEBUG_SCAN(priv, "Scan check work\n"); |
| 999 | |
Stanislaw Gruszka | e7e16b9 | 2010-09-13 14:46:41 +0200 | [diff] [blame] | 1000 | /* Since we are here firmware does not finish scan and |
| 1001 | * most likely is in bad shape, so we don't bother to |
| 1002 | * send abort command, just force scan complete to mac80211 */ |
Johannes Berg | b1eea29 | 2012-03-06 13:30:42 -0800 | [diff] [blame^] | 1003 | mutex_lock(&priv->mutex); |
Stanislaw Gruszka | e7e16b9 | 2010-09-13 14:46:41 +0200 | [diff] [blame] | 1004 | iwl_force_scan_end(priv); |
Johannes Berg | b1eea29 | 2012-03-06 13:30:42 -0800 | [diff] [blame^] | 1005 | mutex_unlock(&priv->mutex); |
Tomas Winkler | 2a421b9 | 2008-06-12 09:47:10 +0800 | [diff] [blame] | 1006 | } |
Samuel Ortiz | 77fecfb8 | 2009-01-23 13:45:12 -0800 | [diff] [blame] | 1007 | |
Tomas Winkler | 2a421b9 | 2008-06-12 09:47:10 +0800 | [diff] [blame] | 1008 | /** |
Tomas Winkler | 2a421b9 | 2008-06-12 09:47:10 +0800 | [diff] [blame] | 1009 | * iwl_fill_probe_req - fill in all required fields and IE for probe request |
| 1010 | */ |
Tomas Winkler | f53696d | 2008-06-12 09:47:12 +0800 | [diff] [blame] | 1011 | |
Johannes Berg | 1ecf9fc | 2009-04-20 14:36:56 -0700 | [diff] [blame] | 1012 | u16 iwl_fill_probe_req(struct iwl_priv *priv, struct ieee80211_mgmt *frame, |
Johannes Berg | 3a0b9aa | 2010-05-12 03:33:12 -0700 | [diff] [blame] | 1013 | const u8 *ta, const u8 *ies, int ie_len, int left) |
Tomas Winkler | 2a421b9 | 2008-06-12 09:47:10 +0800 | [diff] [blame] | 1014 | { |
| 1015 | int len = 0; |
| 1016 | u8 *pos = NULL; |
Tomas Winkler | f53696d | 2008-06-12 09:47:12 +0800 | [diff] [blame] | 1017 | |
Tomas Winkler | 2a421b9 | 2008-06-12 09:47:10 +0800 | [diff] [blame] | 1018 | /* Make sure there is enough space for the probe request, |
| 1019 | * two mandatory IEs and the data */ |
| 1020 | left -= 24; |
| 1021 | if (left < 0) |
| 1022 | return 0; |
Tomas Winkler | 2a421b9 | 2008-06-12 09:47:10 +0800 | [diff] [blame] | 1023 | |
| 1024 | frame->frame_control = cpu_to_le16(IEEE80211_STYPE_PROBE_REQ); |
| 1025 | memcpy(frame->da, iwl_bcast_addr, ETH_ALEN); |
Johannes Berg | 3a0b9aa | 2010-05-12 03:33:12 -0700 | [diff] [blame] | 1026 | memcpy(frame->sa, ta, ETH_ALEN); |
Tomas Winkler | 2a421b9 | 2008-06-12 09:47:10 +0800 | [diff] [blame] | 1027 | memcpy(frame->bssid, iwl_bcast_addr, ETH_ALEN); |
| 1028 | frame->seq_ctrl = 0; |
| 1029 | |
Tomas Winkler | f53696d | 2008-06-12 09:47:12 +0800 | [diff] [blame] | 1030 | len += 24; |
Tomas Winkler | 2a421b9 | 2008-06-12 09:47:10 +0800 | [diff] [blame] | 1031 | |
Tomas Winkler | f53696d | 2008-06-12 09:47:12 +0800 | [diff] [blame] | 1032 | /* ...next IE... */ |
| 1033 | pos = &frame->u.probe_req.variable[0]; |
| 1034 | |
| 1035 | /* fill in our indirect SSID IE */ |
Tomas Winkler | 2a421b9 | 2008-06-12 09:47:10 +0800 | [diff] [blame] | 1036 | left -= 2; |
| 1037 | if (left < 0) |
| 1038 | return 0; |
Tomas Winkler | 2a421b9 | 2008-06-12 09:47:10 +0800 | [diff] [blame] | 1039 | *pos++ = WLAN_EID_SSID; |
Reinette Chatre | 1382c71 | 2010-02-25 10:02:19 -0800 | [diff] [blame] | 1040 | *pos++ = 0; |
Tomas Winkler | 2a421b9 | 2008-06-12 09:47:10 +0800 | [diff] [blame] | 1041 | |
Reinette Chatre | 1382c71 | 2010-02-25 10:02:19 -0800 | [diff] [blame] | 1042 | len += 2; |
Tomas Winkler | 2a421b9 | 2008-06-12 09:47:10 +0800 | [diff] [blame] | 1043 | |
Johannes Berg | 1ecf9fc | 2009-04-20 14:36:56 -0700 | [diff] [blame] | 1044 | if (WARN_ON(left < ie_len)) |
| 1045 | return len; |
Tomas Winkler | 2a421b9 | 2008-06-12 09:47:10 +0800 | [diff] [blame] | 1046 | |
Stanislaw Gruszka | eb2ec0f | 2010-04-16 15:46:41 +0200 | [diff] [blame] | 1047 | if (ies && ie_len) { |
Wey-Yi Guy | afbdd69 | 2010-01-22 14:22:43 -0800 | [diff] [blame] | 1048 | memcpy(pos, ies, ie_len); |
Stanislaw Gruszka | eb2ec0f | 2010-04-16 15:46:41 +0200 | [diff] [blame] | 1049 | len += ie_len; |
| 1050 | } |
Tomas Winkler | f53696d | 2008-06-12 09:47:12 +0800 | [diff] [blame] | 1051 | |
Tomas Winkler | 2a421b9 | 2008-06-12 09:47:10 +0800 | [diff] [blame] | 1052 | return (u16)len; |
| 1053 | } |
| 1054 | |
Stanislaw Gruszka | c240879 | 2010-07-30 16:41:08 +0200 | [diff] [blame] | 1055 | static void iwl_bg_abort_scan(struct work_struct *work) |
Tomas Winkler | 2a421b9 | 2008-06-12 09:47:10 +0800 | [diff] [blame] | 1056 | { |
| 1057 | struct iwl_priv *priv = container_of(work, struct iwl_priv, abort_scan); |
| 1058 | |
Stanislaw Gruszka | 7cf2442 | 2010-09-13 14:46:44 +0200 | [diff] [blame] | 1059 | IWL_DEBUG_SCAN(priv, "Abort scan work\n"); |
| 1060 | |
Stanislaw Gruszka | e7e16b9 | 2010-09-13 14:46:41 +0200 | [diff] [blame] | 1061 | /* We keep scan_check work queued in case when firmware will not |
| 1062 | * report back scan completed notification */ |
Johannes Berg | b1eea29 | 2012-03-06 13:30:42 -0800 | [diff] [blame^] | 1063 | mutex_lock(&priv->mutex); |
Stanislaw Gruszka | 6bd1758 | 2010-09-13 14:46:40 +0200 | [diff] [blame] | 1064 | iwl_scan_cancel_timeout(priv, 200); |
Johannes Berg | b1eea29 | 2012-03-06 13:30:42 -0800 | [diff] [blame^] | 1065 | mutex_unlock(&priv->mutex); |
Tomas Winkler | 2a421b9 | 2008-06-12 09:47:10 +0800 | [diff] [blame] | 1066 | } |
| 1067 | |
Johannes Berg | f253247 | 2011-09-22 15:14:58 -0700 | [diff] [blame] | 1068 | static void iwl_bg_scan_completed(struct work_struct *work) |
| 1069 | { |
| 1070 | struct iwl_priv *priv = |
| 1071 | container_of(work, struct iwl_priv, scan_completed); |
| 1072 | |
Johannes Berg | b1eea29 | 2012-03-06 13:30:42 -0800 | [diff] [blame^] | 1073 | mutex_lock(&priv->mutex); |
Johannes Berg | f253247 | 2011-09-22 15:14:58 -0700 | [diff] [blame] | 1074 | iwl_process_scan_complete(priv); |
Johannes Berg | b1eea29 | 2012-03-06 13:30:42 -0800 | [diff] [blame^] | 1075 | mutex_unlock(&priv->mutex); |
Tomas Winkler | eedda36 | 2008-10-06 16:05:32 +0800 | [diff] [blame] | 1076 | } |
Tomas Winkler | eedda36 | 2008-10-06 16:05:32 +0800 | [diff] [blame] | 1077 | |
Tomas Winkler | 2a421b9 | 2008-06-12 09:47:10 +0800 | [diff] [blame] | 1078 | void iwl_setup_scan_deferred_work(struct iwl_priv *priv) |
| 1079 | { |
Tomas Winkler | eedda36 | 2008-10-06 16:05:32 +0800 | [diff] [blame] | 1080 | INIT_WORK(&priv->scan_completed, iwl_bg_scan_completed); |
Tomas Winkler | 2a421b9 | 2008-06-12 09:47:10 +0800 | [diff] [blame] | 1081 | INIT_WORK(&priv->abort_scan, iwl_bg_abort_scan); |
Johannes Berg | 88be026 | 2010-04-07 00:21:36 -0700 | [diff] [blame] | 1082 | INIT_WORK(&priv->start_internal_scan, iwl_bg_start_internal_scan); |
Tomas Winkler | 2a421b9 | 2008-06-12 09:47:10 +0800 | [diff] [blame] | 1083 | INIT_DELAYED_WORK(&priv->scan_check, iwl_bg_scan_check); |
| 1084 | } |
Tomas Winkler | 2a421b9 | 2008-06-12 09:47:10 +0800 | [diff] [blame] | 1085 | |
Stanislaw Gruszka | e7e16b9 | 2010-09-13 14:46:41 +0200 | [diff] [blame] | 1086 | void iwl_cancel_scan_deferred_work(struct iwl_priv *priv) |
| 1087 | { |
| 1088 | cancel_work_sync(&priv->start_internal_scan); |
| 1089 | cancel_work_sync(&priv->abort_scan); |
| 1090 | cancel_work_sync(&priv->scan_completed); |
| 1091 | |
| 1092 | if (cancel_delayed_work_sync(&priv->scan_check)) { |
Johannes Berg | b1eea29 | 2012-03-06 13:30:42 -0800 | [diff] [blame^] | 1093 | mutex_lock(&priv->mutex); |
Stanislaw Gruszka | e7e16b9 | 2010-09-13 14:46:41 +0200 | [diff] [blame] | 1094 | iwl_force_scan_end(priv); |
Johannes Berg | b1eea29 | 2012-03-06 13:30:42 -0800 | [diff] [blame^] | 1095 | mutex_unlock(&priv->mutex); |
Stanislaw Gruszka | e7e16b9 | 2010-09-13 14:46:41 +0200 | [diff] [blame] | 1096 | } |
| 1097 | } |