Luciano Coelho | 34dd2aa | 2010-07-08 17:50:06 +0300 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of wl1271 |
| 3 | * |
| 4 | * Copyright (C) 2009-2010 Nokia Corporation |
| 5 | * |
| 6 | * Contact: Luciano Coelho <luciano.coelho@nokia.com> |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or |
| 9 | * modify it under the terms of the GNU General Public License |
| 10 | * version 2 as published by the Free Software Foundation. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, but |
| 13 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | * General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with this program; if not, write to the Free Software |
| 19 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA |
| 20 | * 02110-1301 USA |
| 21 | * |
| 22 | */ |
| 23 | |
| 24 | #include <linux/ieee80211.h> |
| 25 | |
Shahar Levi | 00d2010 | 2010-11-08 11:20:10 +0000 | [diff] [blame] | 26 | #include "wl12xx.h" |
| 27 | #include "cmd.h" |
| 28 | #include "scan.h" |
| 29 | #include "acx.h" |
Arik Nemtsov | 24225b3 | 2011-03-01 12:27:26 +0200 | [diff] [blame] | 30 | #include "ps.h" |
Eliad Peller | af7fbb2 | 2011-09-19 13:51:42 +0300 | [diff] [blame] | 31 | #include "tx.h" |
Luciano Coelho | 34dd2aa | 2010-07-08 17:50:06 +0300 | [diff] [blame] | 32 | |
Juuso Oikarinen | c454f1d | 2010-08-24 06:28:03 +0300 | [diff] [blame] | 33 | void wl1271_scan_complete_work(struct work_struct *work) |
| 34 | { |
Juuso Oikarinen | 78abd32 | 2010-09-21 06:23:32 +0200 | [diff] [blame] | 35 | struct delayed_work *dwork; |
| 36 | struct wl1271 *wl; |
Eliad Peller | 251c177 | 2011-08-14 13:17:17 +0300 | [diff] [blame] | 37 | int ret; |
Eliad Peller | 227e81e | 2011-08-14 13:17:26 +0300 | [diff] [blame] | 38 | bool is_sta, is_ibss; |
Juuso Oikarinen | 78abd32 | 2010-09-21 06:23:32 +0200 | [diff] [blame] | 39 | |
| 40 | dwork = container_of(work, struct delayed_work, work); |
| 41 | wl = container_of(dwork, struct wl1271, scan_complete_work); |
Juuso Oikarinen | c454f1d | 2010-08-24 06:28:03 +0300 | [diff] [blame] | 42 | |
| 43 | wl1271_debug(DEBUG_SCAN, "Scanning complete"); |
| 44 | |
| 45 | mutex_lock(&wl->mutex); |
Juuso Oikarinen | 52a2a37 | 2010-09-21 06:23:30 +0200 | [diff] [blame] | 46 | |
Arik Nemtsov | 24225b3 | 2011-03-01 12:27:26 +0200 | [diff] [blame] | 47 | if (wl->state == WL1271_STATE_OFF) |
| 48 | goto out; |
| 49 | |
| 50 | if (wl->scan.state == WL1271_SCAN_STATE_IDLE) |
| 51 | goto out; |
Juuso Oikarinen | 52a2a37 | 2010-09-21 06:23:30 +0200 | [diff] [blame] | 52 | |
Juuso Oikarinen | c454f1d | 2010-08-24 06:28:03 +0300 | [diff] [blame] | 53 | wl->scan.state = WL1271_SCAN_STATE_IDLE; |
Luciano Coelho | 4a31c11 | 2011-03-21 23:16:14 +0200 | [diff] [blame] | 54 | memset(wl->scan.scanned_ch, 0, sizeof(wl->scan.scanned_ch)); |
Juuso Oikarinen | b739a42 | 2010-10-26 13:24:38 +0200 | [diff] [blame] | 55 | wl->scan.req = NULL; |
Juuso Oikarinen | 78abd32 | 2010-09-21 06:23:32 +0200 | [diff] [blame] | 56 | |
Eliad Peller | 251c177 | 2011-08-14 13:17:17 +0300 | [diff] [blame] | 57 | ret = wl1271_ps_elp_wakeup(wl); |
| 58 | if (ret < 0) |
| 59 | goto out; |
| 60 | |
Arik Nemtsov | 24225b3 | 2011-03-01 12:27:26 +0200 | [diff] [blame] | 61 | if (test_bit(WL1271_FLAG_STA_ASSOCIATED, &wl->flags)) { |
Eliad Peller | 251c177 | 2011-08-14 13:17:17 +0300 | [diff] [blame] | 62 | /* restore hardware connection monitoring template */ |
| 63 | wl1271_cmd_build_ap_probe_req(wl, wl->probereq); |
Eliad Peller | 227e81e | 2011-08-14 13:17:26 +0300 | [diff] [blame] | 64 | } |
| 65 | |
| 66 | /* return to ROC if needed */ |
| 67 | is_sta = (wl->bss_type == BSS_TYPE_STA_BSS); |
| 68 | is_ibss = (wl->bss_type == BSS_TYPE_IBSS); |
Eliad Peller | e0b3826 | 2011-08-28 15:11:55 +0300 | [diff] [blame] | 69 | if (((is_sta && !test_bit(WL1271_FLAG_STA_ASSOCIATED, &wl->flags)) || |
| 70 | (is_ibss && !test_bit(WL1271_FLAG_IBSS_JOINED, &wl->flags))) && |
| 71 | !test_bit(wl->dev_role_id, wl->roc_map)) { |
Eliad Peller | 251c177 | 2011-08-14 13:17:17 +0300 | [diff] [blame] | 72 | /* restore remain on channel */ |
| 73 | wl12xx_cmd_role_start_dev(wl); |
| 74 | wl12xx_roc(wl, wl->dev_role_id); |
Arik Nemtsov | 24225b3 | 2011-03-01 12:27:26 +0200 | [diff] [blame] | 75 | } |
Eliad Peller | 251c177 | 2011-08-14 13:17:17 +0300 | [diff] [blame] | 76 | wl1271_ps_elp_sleep(wl); |
Juuso Oikarinen | 2f6724b | 2010-11-24 08:16:57 +0200 | [diff] [blame] | 77 | |
Juuso Oikarinen | 78abd32 | 2010-09-21 06:23:32 +0200 | [diff] [blame] | 78 | if (wl->scan.failed) { |
| 79 | wl1271_info("Scan completed due to error."); |
Ido Yariv | baacb9ae | 2011-06-06 14:57:05 +0300 | [diff] [blame] | 80 | wl12xx_queue_recovery_work(wl); |
Juuso Oikarinen | 78abd32 | 2010-09-21 06:23:32 +0200 | [diff] [blame] | 81 | } |
Arik Nemtsov | 24225b3 | 2011-03-01 12:27:26 +0200 | [diff] [blame] | 82 | |
Eliad Peller | 251c177 | 2011-08-14 13:17:17 +0300 | [diff] [blame] | 83 | ieee80211_scan_completed(wl->hw, false); |
| 84 | |
Arik Nemtsov | 24225b3 | 2011-03-01 12:27:26 +0200 | [diff] [blame] | 85 | out: |
Juuso Oikarinen | b739a42 | 2010-10-26 13:24:38 +0200 | [diff] [blame] | 86 | mutex_unlock(&wl->mutex); |
| 87 | |
Juuso Oikarinen | c454f1d | 2010-08-24 06:28:03 +0300 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | |
Luciano Coelho | 08688d6 | 2010-07-08 17:50:07 +0300 | [diff] [blame] | 91 | static int wl1271_get_scan_channels(struct wl1271 *wl, |
| 92 | struct cfg80211_scan_request *req, |
| 93 | struct basic_scan_channel_params *channels, |
| 94 | enum ieee80211_band band, bool passive) |
Luciano Coelho | 34dd2aa | 2010-07-08 17:50:06 +0300 | [diff] [blame] | 95 | { |
Juuso Oikarinen | bea39d6 | 2010-09-21 08:14:31 +0200 | [diff] [blame] | 96 | struct conf_scan_settings *c = &wl->conf.scan; |
Luciano Coelho | 08688d6 | 2010-07-08 17:50:07 +0300 | [diff] [blame] | 97 | int i, j; |
| 98 | u32 flags; |
Luciano Coelho | 34dd2aa | 2010-07-08 17:50:06 +0300 | [diff] [blame] | 99 | |
Luciano Coelho | 08688d6 | 2010-07-08 17:50:07 +0300 | [diff] [blame] | 100 | for (i = 0, j = 0; |
| 101 | i < req->n_channels && j < WL1271_SCAN_MAX_CHANNELS; |
| 102 | i++) { |
Luciano Coelho | 08688d6 | 2010-07-08 17:50:07 +0300 | [diff] [blame] | 103 | flags = req->channels[i]->flags; |
Luciano Coelho | 34dd2aa | 2010-07-08 17:50:06 +0300 | [diff] [blame] | 104 | |
Luciano Coelho | 4a31c11 | 2011-03-21 23:16:14 +0200 | [diff] [blame] | 105 | if (!test_bit(i, wl->scan.scanned_ch) && |
Luciano Coelho | 08688d6 | 2010-07-08 17:50:07 +0300 | [diff] [blame] | 106 | !(flags & IEEE80211_CHAN_DISABLED) && |
Luciano Coelho | 6cd9d21 | 2011-09-22 10:06:10 +0300 | [diff] [blame] | 107 | (req->channels[i]->band == band) && |
| 108 | /* |
| 109 | * In passive scans, we scan all remaining |
| 110 | * channels, even if not marked as such. |
| 111 | * In active scans, we only scan channels not |
| 112 | * marked as passive. |
| 113 | */ |
| 114 | (passive || !(flags & IEEE80211_CHAN_PASSIVE_SCAN))) { |
Luciano Coelho | 08688d6 | 2010-07-08 17:50:07 +0300 | [diff] [blame] | 115 | wl1271_debug(DEBUG_SCAN, "band %d, center_freq %d ", |
| 116 | req->channels[i]->band, |
| 117 | req->channels[i]->center_freq); |
| 118 | wl1271_debug(DEBUG_SCAN, "hw_value %d, flags %X", |
| 119 | req->channels[i]->hw_value, |
| 120 | req->channels[i]->flags); |
| 121 | wl1271_debug(DEBUG_SCAN, |
| 122 | "max_antenna_gain %d, max_power %d", |
| 123 | req->channels[i]->max_antenna_gain, |
| 124 | req->channels[i]->max_power); |
| 125 | wl1271_debug(DEBUG_SCAN, "beacon_found %d", |
| 126 | req->channels[i]->beacon_found); |
Luciano Coelho | 34dd2aa | 2010-07-08 17:50:06 +0300 | [diff] [blame] | 127 | |
Juuso Oikarinen | bea39d6 | 2010-09-21 08:14:31 +0200 | [diff] [blame] | 128 | if (!passive) { |
| 129 | channels[j].min_duration = |
| 130 | cpu_to_le32(c->min_dwell_time_active); |
| 131 | channels[j].max_duration = |
| 132 | cpu_to_le32(c->max_dwell_time_active); |
| 133 | } else { |
| 134 | channels[j].min_duration = |
| 135 | cpu_to_le32(c->min_dwell_time_passive); |
| 136 | channels[j].max_duration = |
| 137 | cpu_to_le32(c->max_dwell_time_passive); |
| 138 | } |
Luciano Coelho | 08688d6 | 2010-07-08 17:50:07 +0300 | [diff] [blame] | 139 | channels[j].early_termination = 0; |
Luciano Coelho | 3cc7b54 | 2010-07-08 17:50:08 +0300 | [diff] [blame] | 140 | channels[j].tx_power_att = req->channels[i]->max_power; |
Luciano Coelho | 08688d6 | 2010-07-08 17:50:07 +0300 | [diff] [blame] | 141 | channels[j].channel = req->channels[i]->hw_value; |
| 142 | |
| 143 | memset(&channels[j].bssid_lsb, 0xff, 4); |
| 144 | memset(&channels[j].bssid_msb, 0xff, 2); |
| 145 | |
| 146 | /* Mark the channels we already used */ |
Luciano Coelho | 4a31c11 | 2011-03-21 23:16:14 +0200 | [diff] [blame] | 147 | set_bit(i, wl->scan.scanned_ch); |
Luciano Coelho | 08688d6 | 2010-07-08 17:50:07 +0300 | [diff] [blame] | 148 | |
Luciano Coelho | 34dd2aa | 2010-07-08 17:50:06 +0300 | [diff] [blame] | 149 | j++; |
| 150 | } |
| 151 | } |
| 152 | |
Luciano Coelho | 08688d6 | 2010-07-08 17:50:07 +0300 | [diff] [blame] | 153 | return j; |
| 154 | } |
Luciano Coelho | 34dd2aa | 2010-07-08 17:50:06 +0300 | [diff] [blame] | 155 | |
Luciano Coelho | 08688d6 | 2010-07-08 17:50:07 +0300 | [diff] [blame] | 156 | #define WL1271_NOTHING_TO_SCAN 1 |
| 157 | |
| 158 | static int wl1271_scan_send(struct wl1271 *wl, enum ieee80211_band band, |
| 159 | bool passive, u32 basic_rate) |
| 160 | { |
| 161 | struct wl1271_cmd_scan *cmd; |
| 162 | struct wl1271_cmd_trigger_scan_to *trigger; |
| 163 | int ret; |
| 164 | u16 scan_options = 0; |
| 165 | |
Luciano Coelho | 6cd9d21 | 2011-09-22 10:06:10 +0300 | [diff] [blame] | 166 | /* skip active scans if we don't have SSIDs */ |
| 167 | if (!passive && wl->scan.req->n_ssids == 0) |
| 168 | return WL1271_NOTHING_TO_SCAN; |
| 169 | |
Luciano Coelho | 08688d6 | 2010-07-08 17:50:07 +0300 | [diff] [blame] | 170 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 171 | trigger = kzalloc(sizeof(*trigger), GFP_KERNEL); |
| 172 | if (!cmd || !trigger) { |
| 173 | ret = -ENOMEM; |
| 174 | goto out; |
Luciano Coelho | 34dd2aa | 2010-07-08 17:50:06 +0300 | [diff] [blame] | 175 | } |
| 176 | |
Luciano Coelho | 6cd9d21 | 2011-09-22 10:06:10 +0300 | [diff] [blame] | 177 | if (passive) |
Luciano Coelho | 08688d6 | 2010-07-08 17:50:07 +0300 | [diff] [blame] | 178 | scan_options |= WL1271_SCAN_OPT_PASSIVE; |
Luciano Coelho | 4f35c02 | 2010-08-04 04:36:32 +0300 | [diff] [blame] | 179 | |
Eliad Peller | a4e02f3 | 2011-08-14 13:17:10 +0300 | [diff] [blame] | 180 | if (WARN_ON(wl->role_id == WL12XX_INVALID_ROLE_ID)) { |
| 181 | ret = -EINVAL; |
| 182 | goto out; |
| 183 | } |
| 184 | cmd->params.role_id = wl->role_id; |
Luciano Coelho | 08688d6 | 2010-07-08 17:50:07 +0300 | [diff] [blame] | 185 | cmd->params.scan_options = cpu_to_le16(scan_options); |
| 186 | |
| 187 | cmd->params.n_ch = wl1271_get_scan_channels(wl, wl->scan.req, |
| 188 | cmd->channels, |
| 189 | band, passive); |
| 190 | if (cmd->params.n_ch == 0) { |
| 191 | ret = WL1271_NOTHING_TO_SCAN; |
| 192 | goto out; |
| 193 | } |
| 194 | |
| 195 | cmd->params.tx_rate = cpu_to_le32(basic_rate); |
Juuso Oikarinen | bea39d6 | 2010-09-21 08:14:31 +0200 | [diff] [blame] | 196 | cmd->params.n_probe_reqs = wl->conf.scan.num_probe_reqs; |
Luciano Coelho | 08688d6 | 2010-07-08 17:50:07 +0300 | [diff] [blame] | 197 | cmd->params.tx_rate = cpu_to_le32(basic_rate); |
| 198 | cmd->params.tid_trigger = 0; |
| 199 | cmd->params.scan_tag = WL1271_SCAN_DEFAULT_TAG; |
| 200 | |
| 201 | if (band == IEEE80211_BAND_2GHZ) |
| 202 | cmd->params.band = WL1271_SCAN_BAND_2_4_GHZ; |
| 203 | else |
| 204 | cmd->params.band = WL1271_SCAN_BAND_5_GHZ; |
| 205 | |
| 206 | if (wl->scan.ssid_len && wl->scan.ssid) { |
| 207 | cmd->params.ssid_len = wl->scan.ssid_len; |
| 208 | memcpy(cmd->params.ssid, wl->scan.ssid, wl->scan.ssid_len); |
| 209 | } |
| 210 | |
Eliad Peller | a4e02f3 | 2011-08-14 13:17:10 +0300 | [diff] [blame] | 211 | memcpy(cmd->addr, wl->mac_addr, ETH_ALEN); |
| 212 | |
Luciano Coelho | 08688d6 | 2010-07-08 17:50:07 +0300 | [diff] [blame] | 213 | ret = wl1271_cmd_build_probe_req(wl, wl->scan.ssid, wl->scan.ssid_len, |
| 214 | wl->scan.req->ie, wl->scan.req->ie_len, |
| 215 | band); |
Luciano Coelho | 34dd2aa | 2010-07-08 17:50:06 +0300 | [diff] [blame] | 216 | if (ret < 0) { |
| 217 | wl1271_error("PROBE request template failed"); |
| 218 | goto out; |
| 219 | } |
| 220 | |
Luciano Coelho | 34dd2aa | 2010-07-08 17:50:06 +0300 | [diff] [blame] | 221 | /* disable the timeout */ |
| 222 | trigger->timeout = 0; |
Luciano Coelho | 34dd2aa | 2010-07-08 17:50:06 +0300 | [diff] [blame] | 223 | ret = wl1271_cmd_send(wl, CMD_TRIGGER_SCAN_TO, trigger, |
| 224 | sizeof(*trigger), 0); |
| 225 | if (ret < 0) { |
| 226 | wl1271_error("trigger scan to failed for hw scan"); |
| 227 | goto out; |
| 228 | } |
| 229 | |
Luciano Coelho | 08688d6 | 2010-07-08 17:50:07 +0300 | [diff] [blame] | 230 | wl1271_dump(DEBUG_SCAN, "SCAN: ", cmd, sizeof(*cmd)); |
Luciano Coelho | 34dd2aa | 2010-07-08 17:50:06 +0300 | [diff] [blame] | 231 | |
Luciano Coelho | 08688d6 | 2010-07-08 17:50:07 +0300 | [diff] [blame] | 232 | ret = wl1271_cmd_send(wl, CMD_SCAN, cmd, sizeof(*cmd), 0); |
Luciano Coelho | 34dd2aa | 2010-07-08 17:50:06 +0300 | [diff] [blame] | 233 | if (ret < 0) { |
| 234 | wl1271_error("SCAN failed"); |
Luciano Coelho | 34dd2aa | 2010-07-08 17:50:06 +0300 | [diff] [blame] | 235 | goto out; |
| 236 | } |
| 237 | |
| 238 | out: |
Luciano Coelho | 08688d6 | 2010-07-08 17:50:07 +0300 | [diff] [blame] | 239 | kfree(cmd); |
Luciano Coelho | 34dd2aa | 2010-07-08 17:50:06 +0300 | [diff] [blame] | 240 | kfree(trigger); |
| 241 | return ret; |
| 242 | } |
| 243 | |
Luciano Coelho | 08688d6 | 2010-07-08 17:50:07 +0300 | [diff] [blame] | 244 | void wl1271_scan_stm(struct wl1271 *wl) |
Luciano Coelho | 34dd2aa | 2010-07-08 17:50:06 +0300 | [diff] [blame] | 245 | { |
Juuso Oikarinen | 78abd32 | 2010-09-21 06:23:32 +0200 | [diff] [blame] | 246 | int ret = 0; |
Eliad Peller | af7fbb2 | 2011-09-19 13:51:42 +0300 | [diff] [blame] | 247 | enum ieee80211_band band; |
| 248 | u32 rate; |
Luciano Coelho | 08688d6 | 2010-07-08 17:50:07 +0300 | [diff] [blame] | 249 | |
| 250 | switch (wl->scan.state) { |
| 251 | case WL1271_SCAN_STATE_IDLE: |
| 252 | break; |
| 253 | |
| 254 | case WL1271_SCAN_STATE_2GHZ_ACTIVE: |
Eliad Peller | af7fbb2 | 2011-09-19 13:51:42 +0300 | [diff] [blame] | 255 | band = IEEE80211_BAND_2GHZ; |
| 256 | rate = wl1271_tx_min_rate_get(wl, wl->bitrate_masks[band]); |
| 257 | ret = wl1271_scan_send(wl, band, false, rate); |
Luciano Coelho | 08688d6 | 2010-07-08 17:50:07 +0300 | [diff] [blame] | 258 | if (ret == WL1271_NOTHING_TO_SCAN) { |
| 259 | wl->scan.state = WL1271_SCAN_STATE_2GHZ_PASSIVE; |
| 260 | wl1271_scan_stm(wl); |
Luciano Coelho | 34dd2aa | 2010-07-08 17:50:06 +0300 | [diff] [blame] | 261 | } |
Luciano Coelho | 08688d6 | 2010-07-08 17:50:07 +0300 | [diff] [blame] | 262 | |
| 263 | break; |
| 264 | |
| 265 | case WL1271_SCAN_STATE_2GHZ_PASSIVE: |
Eliad Peller | af7fbb2 | 2011-09-19 13:51:42 +0300 | [diff] [blame] | 266 | band = IEEE80211_BAND_2GHZ; |
| 267 | rate = wl1271_tx_min_rate_get(wl, wl->bitrate_masks[band]); |
| 268 | ret = wl1271_scan_send(wl, band, true, rate); |
Luciano Coelho | 08688d6 | 2010-07-08 17:50:07 +0300 | [diff] [blame] | 269 | if (ret == WL1271_NOTHING_TO_SCAN) { |
Juuso Oikarinen | 02fabb0 | 2010-08-19 04:41:15 +0200 | [diff] [blame] | 270 | if (wl->enable_11a) |
Luciano Coelho | 08688d6 | 2010-07-08 17:50:07 +0300 | [diff] [blame] | 271 | wl->scan.state = WL1271_SCAN_STATE_5GHZ_ACTIVE; |
| 272 | else |
| 273 | wl->scan.state = WL1271_SCAN_STATE_DONE; |
| 274 | wl1271_scan_stm(wl); |
| 275 | } |
| 276 | |
| 277 | break; |
| 278 | |
| 279 | case WL1271_SCAN_STATE_5GHZ_ACTIVE: |
Eliad Peller | af7fbb2 | 2011-09-19 13:51:42 +0300 | [diff] [blame] | 280 | band = IEEE80211_BAND_5GHZ; |
| 281 | rate = wl1271_tx_min_rate_get(wl, wl->bitrate_masks[band]); |
| 282 | ret = wl1271_scan_send(wl, band, false, rate); |
Luciano Coelho | 08688d6 | 2010-07-08 17:50:07 +0300 | [diff] [blame] | 283 | if (ret == WL1271_NOTHING_TO_SCAN) { |
| 284 | wl->scan.state = WL1271_SCAN_STATE_5GHZ_PASSIVE; |
| 285 | wl1271_scan_stm(wl); |
| 286 | } |
| 287 | |
| 288 | break; |
| 289 | |
| 290 | case WL1271_SCAN_STATE_5GHZ_PASSIVE: |
Eliad Peller | af7fbb2 | 2011-09-19 13:51:42 +0300 | [diff] [blame] | 291 | band = IEEE80211_BAND_5GHZ; |
| 292 | rate = wl1271_tx_min_rate_get(wl, wl->bitrate_masks[band]); |
| 293 | ret = wl1271_scan_send(wl, band, true, rate); |
Luciano Coelho | 08688d6 | 2010-07-08 17:50:07 +0300 | [diff] [blame] | 294 | if (ret == WL1271_NOTHING_TO_SCAN) { |
| 295 | wl->scan.state = WL1271_SCAN_STATE_DONE; |
| 296 | wl1271_scan_stm(wl); |
| 297 | } |
| 298 | |
| 299 | break; |
| 300 | |
| 301 | case WL1271_SCAN_STATE_DONE: |
Juuso Oikarinen | 78abd32 | 2010-09-21 06:23:32 +0200 | [diff] [blame] | 302 | wl->scan.failed = false; |
| 303 | cancel_delayed_work(&wl->scan_complete_work); |
| 304 | ieee80211_queue_delayed_work(wl->hw, &wl->scan_complete_work, |
| 305 | msecs_to_jiffies(0)); |
Luciano Coelho | 08688d6 | 2010-07-08 17:50:07 +0300 | [diff] [blame] | 306 | break; |
| 307 | |
| 308 | default: |
| 309 | wl1271_error("invalid scan state"); |
| 310 | break; |
Luciano Coelho | 34dd2aa | 2010-07-08 17:50:06 +0300 | [diff] [blame] | 311 | } |
Juuso Oikarinen | 78abd32 | 2010-09-21 06:23:32 +0200 | [diff] [blame] | 312 | |
| 313 | if (ret < 0) { |
| 314 | cancel_delayed_work(&wl->scan_complete_work); |
| 315 | ieee80211_queue_delayed_work(wl->hw, &wl->scan_complete_work, |
| 316 | msecs_to_jiffies(0)); |
| 317 | } |
Luciano Coelho | 08688d6 | 2010-07-08 17:50:07 +0300 | [diff] [blame] | 318 | } |
| 319 | |
| 320 | int wl1271_scan(struct wl1271 *wl, const u8 *ssid, size_t ssid_len, |
| 321 | struct cfg80211_scan_request *req) |
| 322 | { |
Luciano Coelho | 4a31c11 | 2011-03-21 23:16:14 +0200 | [diff] [blame] | 323 | /* |
| 324 | * cfg80211 should guarantee that we don't get more channels |
| 325 | * than what we have registered. |
| 326 | */ |
| 327 | BUG_ON(req->n_channels > WL1271_MAX_CHANNELS); |
| 328 | |
Luciano Coelho | 08688d6 | 2010-07-08 17:50:07 +0300 | [diff] [blame] | 329 | if (wl->scan.state != WL1271_SCAN_STATE_IDLE) |
| 330 | return -EBUSY; |
| 331 | |
| 332 | wl->scan.state = WL1271_SCAN_STATE_2GHZ_ACTIVE; |
| 333 | |
| 334 | if (ssid_len && ssid) { |
| 335 | wl->scan.ssid_len = ssid_len; |
| 336 | memcpy(wl->scan.ssid, ssid, ssid_len); |
| 337 | } else { |
| 338 | wl->scan.ssid_len = 0; |
| 339 | } |
| 340 | |
| 341 | wl->scan.req = req; |
Luciano Coelho | 4a31c11 | 2011-03-21 23:16:14 +0200 | [diff] [blame] | 342 | memset(wl->scan.scanned_ch, 0, sizeof(wl->scan.scanned_ch)); |
Luciano Coelho | 08688d6 | 2010-07-08 17:50:07 +0300 | [diff] [blame] | 343 | |
Juuso Oikarinen | 78abd32 | 2010-09-21 06:23:32 +0200 | [diff] [blame] | 344 | /* we assume failure so that timeout scenarios are handled correctly */ |
| 345 | wl->scan.failed = true; |
| 346 | ieee80211_queue_delayed_work(wl->hw, &wl->scan_complete_work, |
| 347 | msecs_to_jiffies(WL1271_SCAN_TIMEOUT)); |
| 348 | |
Luciano Coelho | 08688d6 | 2010-07-08 17:50:07 +0300 | [diff] [blame] | 349 | wl1271_scan_stm(wl); |
| 350 | |
Luciano Coelho | 34dd2aa | 2010-07-08 17:50:06 +0300 | [diff] [blame] | 351 | return 0; |
| 352 | } |
Luciano Coelho | 95feadc | 2011-05-10 14:38:59 +0300 | [diff] [blame] | 353 | |
Eliad Peller | 2aa0159 | 2011-06-27 13:06:44 +0300 | [diff] [blame] | 354 | int wl1271_scan_stop(struct wl1271 *wl) |
| 355 | { |
| 356 | struct wl1271_cmd_header *cmd = NULL; |
| 357 | int ret = 0; |
| 358 | |
| 359 | if (WARN_ON(wl->scan.state == WL1271_SCAN_STATE_IDLE)) |
| 360 | return -EINVAL; |
| 361 | |
| 362 | wl1271_debug(DEBUG_CMD, "cmd scan stop"); |
| 363 | |
| 364 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 365 | if (!cmd) { |
| 366 | ret = -ENOMEM; |
| 367 | goto out; |
| 368 | } |
| 369 | |
| 370 | ret = wl1271_cmd_send(wl, CMD_STOP_SCAN, cmd, |
| 371 | sizeof(*cmd), 0); |
| 372 | if (ret < 0) { |
| 373 | wl1271_error("cmd stop_scan failed"); |
| 374 | goto out; |
| 375 | } |
| 376 | out: |
| 377 | kfree(cmd); |
| 378 | return ret; |
| 379 | } |
| 380 | |
Luciano Coelho | 95feadc | 2011-05-10 14:38:59 +0300 | [diff] [blame] | 381 | static int |
| 382 | wl1271_scan_get_sched_scan_channels(struct wl1271 *wl, |
| 383 | struct cfg80211_sched_scan_request *req, |
| 384 | struct conn_scan_ch_params *channels, |
| 385 | u32 band, bool radar, bool passive, |
Luciano Coelho | d2c2bb9 | 2011-05-31 16:38:56 +0300 | [diff] [blame] | 386 | int start, int max_channels) |
Luciano Coelho | 95feadc | 2011-05-10 14:38:59 +0300 | [diff] [blame] | 387 | { |
| 388 | struct conf_sched_scan_settings *c = &wl->conf.sched_scan; |
| 389 | int i, j; |
| 390 | u32 flags; |
Luciano Coelho | 66870b1 | 2011-05-27 15:34:48 +0300 | [diff] [blame] | 391 | bool force_passive = !req->n_ssids; |
Luciano Coelho | 95feadc | 2011-05-10 14:38:59 +0300 | [diff] [blame] | 392 | |
| 393 | for (i = 0, j = start; |
Luciano Coelho | d2c2bb9 | 2011-05-31 16:38:56 +0300 | [diff] [blame] | 394 | i < req->n_channels && j < max_channels; |
Luciano Coelho | 95feadc | 2011-05-10 14:38:59 +0300 | [diff] [blame] | 395 | i++) { |
| 396 | flags = req->channels[i]->flags; |
| 397 | |
Luciano Coelho | 66870b1 | 2011-05-27 15:34:48 +0300 | [diff] [blame] | 398 | if (force_passive) |
| 399 | flags |= IEEE80211_CHAN_PASSIVE_SCAN; |
| 400 | |
Luciano Coelho | 2497a24 | 2011-05-27 15:34:46 +0300 | [diff] [blame] | 401 | if ((req->channels[i]->band == band) && |
| 402 | !(flags & IEEE80211_CHAN_DISABLED) && |
Luciano Coelho | dd08682 | 2011-05-27 15:34:45 +0300 | [diff] [blame] | 403 | (!!(flags & IEEE80211_CHAN_RADAR) == radar) && |
Luciano Coelho | 2497a24 | 2011-05-27 15:34:46 +0300 | [diff] [blame] | 404 | /* if radar is set, we ignore the passive flag */ |
| 405 | (radar || |
| 406 | !!(flags & IEEE80211_CHAN_PASSIVE_SCAN) == passive)) { |
Luciano Coelho | 95feadc | 2011-05-10 14:38:59 +0300 | [diff] [blame] | 407 | wl1271_debug(DEBUG_SCAN, "band %d, center_freq %d ", |
| 408 | req->channels[i]->band, |
| 409 | req->channels[i]->center_freq); |
| 410 | wl1271_debug(DEBUG_SCAN, "hw_value %d, flags %X", |
| 411 | req->channels[i]->hw_value, |
| 412 | req->channels[i]->flags); |
| 413 | wl1271_debug(DEBUG_SCAN, "max_power %d", |
| 414 | req->channels[i]->max_power); |
| 415 | |
Luciano Coelho | 50a66d7 | 2011-05-27 15:34:47 +0300 | [diff] [blame] | 416 | if (flags & IEEE80211_CHAN_RADAR) { |
Luciano Coelho | 2497a24 | 2011-05-27 15:34:46 +0300 | [diff] [blame] | 417 | channels[j].flags |= SCAN_CHANNEL_FLAGS_DFS; |
Luciano Coelho | 50a66d7 | 2011-05-27 15:34:47 +0300 | [diff] [blame] | 418 | channels[j].passive_duration = |
| 419 | cpu_to_le16(c->dwell_time_dfs); |
| 420 | } |
| 421 | else if (flags & IEEE80211_CHAN_PASSIVE_SCAN) { |
Luciano Coelho | 95feadc | 2011-05-10 14:38:59 +0300 | [diff] [blame] | 422 | channels[j].passive_duration = |
| 423 | cpu_to_le16(c->dwell_time_passive); |
| 424 | } else { |
| 425 | channels[j].min_duration = |
| 426 | cpu_to_le16(c->min_dwell_time_active); |
| 427 | channels[j].max_duration = |
| 428 | cpu_to_le16(c->max_dwell_time_active); |
| 429 | } |
Luciano Coelho | 2497a24 | 2011-05-27 15:34:46 +0300 | [diff] [blame] | 430 | channels[j].tx_power_att = req->channels[i]->max_power; |
Luciano Coelho | 95feadc | 2011-05-10 14:38:59 +0300 | [diff] [blame] | 431 | channels[j].channel = req->channels[i]->hw_value; |
| 432 | |
| 433 | j++; |
| 434 | } |
| 435 | } |
| 436 | |
| 437 | return j - start; |
| 438 | } |
| 439 | |
Luciano Coelho | d2c2bb9 | 2011-05-31 16:38:56 +0300 | [diff] [blame] | 440 | static bool |
Luciano Coelho | 95feadc | 2011-05-10 14:38:59 +0300 | [diff] [blame] | 441 | wl1271_scan_sched_scan_channels(struct wl1271 *wl, |
| 442 | struct cfg80211_sched_scan_request *req, |
| 443 | struct wl1271_cmd_sched_scan_config *cfg) |
| 444 | { |
Luciano Coelho | 95feadc | 2011-05-10 14:38:59 +0300 | [diff] [blame] | 445 | cfg->passive[0] = |
Luciano Coelho | d2c2bb9 | 2011-05-31 16:38:56 +0300 | [diff] [blame] | 446 | wl1271_scan_get_sched_scan_channels(wl, req, cfg->channels_2, |
Luciano Coelho | 95feadc | 2011-05-10 14:38:59 +0300 | [diff] [blame] | 447 | IEEE80211_BAND_2GHZ, |
Luciano Coelho | d2c2bb9 | 2011-05-31 16:38:56 +0300 | [diff] [blame] | 448 | false, true, 0, |
| 449 | MAX_CHANNELS_2GHZ); |
Luciano Coelho | 95feadc | 2011-05-10 14:38:59 +0300 | [diff] [blame] | 450 | cfg->active[0] = |
Luciano Coelho | d2c2bb9 | 2011-05-31 16:38:56 +0300 | [diff] [blame] | 451 | wl1271_scan_get_sched_scan_channels(wl, req, cfg->channels_2, |
Luciano Coelho | 95feadc | 2011-05-10 14:38:59 +0300 | [diff] [blame] | 452 | IEEE80211_BAND_2GHZ, |
Luciano Coelho | d2c2bb9 | 2011-05-31 16:38:56 +0300 | [diff] [blame] | 453 | false, false, |
| 454 | cfg->passive[0], |
| 455 | MAX_CHANNELS_2GHZ); |
Luciano Coelho | 95feadc | 2011-05-10 14:38:59 +0300 | [diff] [blame] | 456 | cfg->passive[1] = |
Luciano Coelho | d2c2bb9 | 2011-05-31 16:38:56 +0300 | [diff] [blame] | 457 | wl1271_scan_get_sched_scan_channels(wl, req, cfg->channels_5, |
Luciano Coelho | 95feadc | 2011-05-10 14:38:59 +0300 | [diff] [blame] | 458 | IEEE80211_BAND_5GHZ, |
Luciano Coelho | d2c2bb9 | 2011-05-31 16:38:56 +0300 | [diff] [blame] | 459 | false, true, 0, |
| 460 | MAX_CHANNELS_5GHZ); |
Luciano Coelho | 95feadc | 2011-05-10 14:38:59 +0300 | [diff] [blame] | 461 | cfg->dfs = |
Luciano Coelho | d2c2bb9 | 2011-05-31 16:38:56 +0300 | [diff] [blame] | 462 | wl1271_scan_get_sched_scan_channels(wl, req, cfg->channels_5, |
Luciano Coelho | 95feadc | 2011-05-10 14:38:59 +0300 | [diff] [blame] | 463 | IEEE80211_BAND_5GHZ, |
Luciano Coelho | d2c2bb9 | 2011-05-31 16:38:56 +0300 | [diff] [blame] | 464 | true, true, |
| 465 | cfg->passive[1], |
| 466 | MAX_CHANNELS_5GHZ); |
Luciano Coelho | 2497a24 | 2011-05-27 15:34:46 +0300 | [diff] [blame] | 467 | cfg->active[1] = |
Luciano Coelho | d2c2bb9 | 2011-05-31 16:38:56 +0300 | [diff] [blame] | 468 | wl1271_scan_get_sched_scan_channels(wl, req, cfg->channels_5, |
Luciano Coelho | 2497a24 | 2011-05-27 15:34:46 +0300 | [diff] [blame] | 469 | IEEE80211_BAND_5GHZ, |
Luciano Coelho | d2c2bb9 | 2011-05-31 16:38:56 +0300 | [diff] [blame] | 470 | false, false, |
| 471 | cfg->passive[1] + cfg->dfs, |
| 472 | MAX_CHANNELS_5GHZ); |
| 473 | /* 802.11j channels are not supported yet */ |
| 474 | cfg->passive[2] = 0; |
| 475 | cfg->active[2] = 0; |
Luciano Coelho | 2497a24 | 2011-05-27 15:34:46 +0300 | [diff] [blame] | 476 | |
Luciano Coelho | 95feadc | 2011-05-10 14:38:59 +0300 | [diff] [blame] | 477 | wl1271_debug(DEBUG_SCAN, " 2.4GHz: active %d passive %d", |
| 478 | cfg->active[0], cfg->passive[0]); |
| 479 | wl1271_debug(DEBUG_SCAN, " 5GHz: active %d passive %d", |
| 480 | cfg->active[1], cfg->passive[1]); |
Luciano Coelho | 2497a24 | 2011-05-27 15:34:46 +0300 | [diff] [blame] | 481 | wl1271_debug(DEBUG_SCAN, " DFS: %d", cfg->dfs); |
Luciano Coelho | 95feadc | 2011-05-10 14:38:59 +0300 | [diff] [blame] | 482 | |
Luciano Coelho | d2c2bb9 | 2011-05-31 16:38:56 +0300 | [diff] [blame] | 483 | return cfg->passive[0] || cfg->active[0] || |
| 484 | cfg->passive[1] || cfg->active[1] || cfg->dfs || |
| 485 | cfg->passive[2] || cfg->active[2]; |
Luciano Coelho | 95feadc | 2011-05-10 14:38:59 +0300 | [diff] [blame] | 486 | } |
| 487 | |
Luciano Coelho | fb55377 | 2011-09-02 14:28:21 +0300 | [diff] [blame] | 488 | /* Returns the scan type to be used or a negative value on error */ |
Luciano Coelho | f952079 | 2011-08-23 18:34:44 +0300 | [diff] [blame] | 489 | static int |
| 490 | wl12xx_scan_sched_scan_ssid_list(struct wl1271 *wl, |
| 491 | struct cfg80211_sched_scan_request *req) |
| 492 | { |
| 493 | struct wl1271_cmd_sched_scan_ssid_list *cmd = NULL; |
Luciano Coelho | fb55377 | 2011-09-02 14:28:21 +0300 | [diff] [blame] | 494 | struct cfg80211_match_set *sets = req->match_sets; |
| 495 | struct cfg80211_ssid *ssids = req->ssids; |
Luciano Coelho | 20a33e5 | 2011-09-02 14:28:23 +0300 | [diff] [blame] | 496 | int ret = 0, type, i, j, n_match_ssids = 0; |
Luciano Coelho | f952079 | 2011-08-23 18:34:44 +0300 | [diff] [blame] | 497 | |
| 498 | wl1271_debug(DEBUG_CMD, "cmd sched scan ssid list"); |
| 499 | |
Luciano Coelho | 20a33e5 | 2011-09-02 14:28:23 +0300 | [diff] [blame] | 500 | /* count the match sets that contain SSIDs */ |
| 501 | for (i = 0; i < req->n_match_sets; i++) |
| 502 | if (sets[i].ssid.ssid_len > 0) |
| 503 | n_match_ssids++; |
| 504 | |
Luciano Coelho | fb55377 | 2011-09-02 14:28:21 +0300 | [diff] [blame] | 505 | /* No filter, no ssids or only bcast ssid */ |
Luciano Coelho | 20a33e5 | 2011-09-02 14:28:23 +0300 | [diff] [blame] | 506 | if (!n_match_ssids && |
Luciano Coelho | fb55377 | 2011-09-02 14:28:21 +0300 | [diff] [blame] | 507 | (!req->n_ssids || |
| 508 | (req->n_ssids == 1 && req->ssids[0].ssid_len == 0))) { |
| 509 | type = SCAN_SSID_FILTER_ANY; |
| 510 | goto out; |
| 511 | } |
Luciano Coelho | f952079 | 2011-08-23 18:34:44 +0300 | [diff] [blame] | 512 | |
Luciano Coelho | fb55377 | 2011-09-02 14:28:21 +0300 | [diff] [blame] | 513 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); |
| 514 | if (!cmd) { |
| 515 | ret = -ENOMEM; |
| 516 | goto out; |
| 517 | } |
| 518 | |
Luciano Coelho | 20a33e5 | 2011-09-02 14:28:23 +0300 | [diff] [blame] | 519 | if (!n_match_ssids) { |
Luciano Coelho | fb55377 | 2011-09-02 14:28:21 +0300 | [diff] [blame] | 520 | /* No filter, with ssids */ |
| 521 | type = SCAN_SSID_FILTER_DISABLED; |
| 522 | |
| 523 | for (i = 0; i < req->n_ssids; i++) { |
| 524 | cmd->ssids[cmd->n_ssids].type = (ssids[i].ssid_len) ? |
| 525 | SCAN_SSID_TYPE_HIDDEN : SCAN_SSID_TYPE_PUBLIC; |
| 526 | cmd->ssids[cmd->n_ssids].len = ssids[i].ssid_len; |
| 527 | memcpy(cmd->ssids[cmd->n_ssids].ssid, ssids[i].ssid, |
| 528 | ssids[i].ssid_len); |
| 529 | cmd->n_ssids++; |
Luciano Coelho | bd4932b | 2011-08-23 18:34:45 +0300 | [diff] [blame] | 530 | } |
Luciano Coelho | fb55377 | 2011-09-02 14:28:21 +0300 | [diff] [blame] | 531 | } else { |
| 532 | type = SCAN_SSID_FILTER_LIST; |
| 533 | |
| 534 | /* Add all SSIDs from the filters */ |
| 535 | for (i = 0; i < req->n_match_sets; i++) { |
Luciano Coelho | 20a33e5 | 2011-09-02 14:28:23 +0300 | [diff] [blame] | 536 | /* ignore sets without SSIDs */ |
| 537 | if (!sets[i].ssid.ssid_len) |
| 538 | continue; |
| 539 | |
Luciano Coelho | fb55377 | 2011-09-02 14:28:21 +0300 | [diff] [blame] | 540 | cmd->ssids[cmd->n_ssids].type = SCAN_SSID_TYPE_PUBLIC; |
| 541 | cmd->ssids[cmd->n_ssids].len = sets[i].ssid.ssid_len; |
| 542 | memcpy(cmd->ssids[cmd->n_ssids].ssid, |
| 543 | sets[i].ssid.ssid, sets[i].ssid.ssid_len); |
| 544 | cmd->n_ssids++; |
| 545 | } |
| 546 | if ((req->n_ssids > 1) || |
| 547 | (req->n_ssids == 1 && req->ssids[0].ssid_len > 0)) { |
| 548 | /* |
| 549 | * Mark all the SSIDs passed in the SSID list as HIDDEN, |
| 550 | * so they're used in probe requests. |
| 551 | */ |
| 552 | for (i = 0; i < req->n_ssids; i++) { |
| 553 | for (j = 0; j < cmd->n_ssids; j++) |
| 554 | if (!memcmp(req->ssids[i].ssid, |
| 555 | cmd->ssids[j].ssid, |
| 556 | req->ssids[i].ssid_len)) { |
| 557 | cmd->ssids[j].type = |
| 558 | SCAN_SSID_TYPE_HIDDEN; |
| 559 | break; |
| 560 | } |
| 561 | /* Fail if SSID isn't present in the filters */ |
Eyal Shapira | cc438fc | 2011-11-08 15:54:46 +0200 | [diff] [blame] | 562 | if (j == cmd->n_ssids) { |
Luciano Coelho | fb55377 | 2011-09-02 14:28:21 +0300 | [diff] [blame] | 563 | ret = -EINVAL; |
| 564 | goto out_free; |
| 565 | } |
| 566 | } |
| 567 | } |
Luciano Coelho | f952079 | 2011-08-23 18:34:44 +0300 | [diff] [blame] | 568 | } |
| 569 | |
| 570 | wl1271_dump(DEBUG_SCAN, "SSID_LIST: ", cmd, sizeof(*cmd)); |
| 571 | |
| 572 | ret = wl1271_cmd_send(wl, CMD_CONNECTION_SCAN_SSID_CFG, cmd, |
| 573 | sizeof(*cmd), 0); |
| 574 | if (ret < 0) { |
| 575 | wl1271_error("cmd sched scan ssid list failed"); |
Luciano Coelho | fb55377 | 2011-09-02 14:28:21 +0300 | [diff] [blame] | 576 | goto out_free; |
Luciano Coelho | f952079 | 2011-08-23 18:34:44 +0300 | [diff] [blame] | 577 | } |
| 578 | |
Luciano Coelho | fb55377 | 2011-09-02 14:28:21 +0300 | [diff] [blame] | 579 | out_free: |
Luciano Coelho | f952079 | 2011-08-23 18:34:44 +0300 | [diff] [blame] | 580 | kfree(cmd); |
Luciano Coelho | fb55377 | 2011-09-02 14:28:21 +0300 | [diff] [blame] | 581 | out: |
| 582 | if (ret < 0) |
| 583 | return ret; |
| 584 | return type; |
Luciano Coelho | f952079 | 2011-08-23 18:34:44 +0300 | [diff] [blame] | 585 | } |
| 586 | |
Luciano Coelho | 95feadc | 2011-05-10 14:38:59 +0300 | [diff] [blame] | 587 | int wl1271_scan_sched_scan_config(struct wl1271 *wl, |
| 588 | struct cfg80211_sched_scan_request *req, |
| 589 | struct ieee80211_sched_scan_ies *ies) |
| 590 | { |
| 591 | struct wl1271_cmd_sched_scan_config *cfg = NULL; |
| 592 | struct conf_sched_scan_settings *c = &wl->conf.sched_scan; |
Luciano Coelho | d2c2bb9 | 2011-05-31 16:38:56 +0300 | [diff] [blame] | 593 | int i, ret; |
Luciano Coelho | 66870b1 | 2011-05-27 15:34:48 +0300 | [diff] [blame] | 594 | bool force_passive = !req->n_ssids; |
Luciano Coelho | 95feadc | 2011-05-10 14:38:59 +0300 | [diff] [blame] | 595 | |
| 596 | wl1271_debug(DEBUG_CMD, "cmd sched_scan scan config"); |
| 597 | |
| 598 | cfg = kzalloc(sizeof(*cfg), GFP_KERNEL); |
| 599 | if (!cfg) |
| 600 | return -ENOMEM; |
| 601 | |
| 602 | cfg->rssi_threshold = c->rssi_threshold; |
| 603 | cfg->snr_threshold = c->snr_threshold; |
| 604 | cfg->n_probe_reqs = c->num_probe_reqs; |
| 605 | /* cycles set to 0 it means infinite (until manually stopped) */ |
| 606 | cfg->cycles = 0; |
| 607 | /* report APs when at least 1 is found */ |
| 608 | cfg->report_after = 1; |
| 609 | /* don't stop scanning automatically when something is found */ |
| 610 | cfg->terminate = 0; |
| 611 | cfg->tag = WL1271_SCAN_DEFAULT_TAG; |
| 612 | /* don't filter on BSS type */ |
| 613 | cfg->bss_type = SCAN_BSS_TYPE_ANY; |
| 614 | /* currently NL80211 supports only a single interval */ |
| 615 | for (i = 0; i < SCAN_MAX_CYCLE_INTERVALS; i++) |
| 616 | cfg->intervals[i] = cpu_to_le32(req->interval); |
| 617 | |
Luciano Coelho | f952079 | 2011-08-23 18:34:44 +0300 | [diff] [blame] | 618 | cfg->ssid_len = 0; |
Luciano Coelho | fb55377 | 2011-09-02 14:28:21 +0300 | [diff] [blame] | 619 | ret = wl12xx_scan_sched_scan_ssid_list(wl, req); |
| 620 | if (ret < 0) |
| 621 | goto out; |
| 622 | |
| 623 | cfg->filter_type = ret; |
| 624 | |
| 625 | wl1271_debug(DEBUG_SCAN, "filter_type = %d", cfg->filter_type); |
Luciano Coelho | 95feadc | 2011-05-10 14:38:59 +0300 | [diff] [blame] | 626 | |
Luciano Coelho | d2c2bb9 | 2011-05-31 16:38:56 +0300 | [diff] [blame] | 627 | if (!wl1271_scan_sched_scan_channels(wl, req, cfg)) { |
Luciano Coelho | 95feadc | 2011-05-10 14:38:59 +0300 | [diff] [blame] | 628 | wl1271_error("scan channel list is empty"); |
| 629 | ret = -EINVAL; |
| 630 | goto out; |
| 631 | } |
| 632 | |
Luciano Coelho | 66870b1 | 2011-05-27 15:34:48 +0300 | [diff] [blame] | 633 | if (!force_passive && cfg->active[0]) { |
Luciano Coelho | 95feadc | 2011-05-10 14:38:59 +0300 | [diff] [blame] | 634 | ret = wl1271_cmd_build_probe_req(wl, req->ssids[0].ssid, |
| 635 | req->ssids[0].ssid_len, |
| 636 | ies->ie[IEEE80211_BAND_2GHZ], |
| 637 | ies->len[IEEE80211_BAND_2GHZ], |
| 638 | IEEE80211_BAND_2GHZ); |
| 639 | if (ret < 0) { |
| 640 | wl1271_error("2.4GHz PROBE request template failed"); |
| 641 | goto out; |
| 642 | } |
| 643 | } |
| 644 | |
Luciano Coelho | 66870b1 | 2011-05-27 15:34:48 +0300 | [diff] [blame] | 645 | if (!force_passive && cfg->active[1]) { |
Luciano Coelho | 95feadc | 2011-05-10 14:38:59 +0300 | [diff] [blame] | 646 | ret = wl1271_cmd_build_probe_req(wl, req->ssids[0].ssid, |
| 647 | req->ssids[0].ssid_len, |
| 648 | ies->ie[IEEE80211_BAND_5GHZ], |
| 649 | ies->len[IEEE80211_BAND_5GHZ], |
| 650 | IEEE80211_BAND_5GHZ); |
| 651 | if (ret < 0) { |
| 652 | wl1271_error("5GHz PROBE request template failed"); |
| 653 | goto out; |
| 654 | } |
| 655 | } |
| 656 | |
| 657 | wl1271_dump(DEBUG_SCAN, "SCAN_CFG: ", cfg, sizeof(*cfg)); |
| 658 | |
| 659 | ret = wl1271_cmd_send(wl, CMD_CONNECTION_SCAN_CFG, cfg, |
| 660 | sizeof(*cfg), 0); |
| 661 | if (ret < 0) { |
| 662 | wl1271_error("SCAN configuration failed"); |
| 663 | goto out; |
| 664 | } |
| 665 | out: |
| 666 | kfree(cfg); |
| 667 | return ret; |
| 668 | } |
| 669 | |
| 670 | int wl1271_scan_sched_scan_start(struct wl1271 *wl) |
| 671 | { |
| 672 | struct wl1271_cmd_sched_scan_start *start; |
| 673 | int ret = 0; |
| 674 | |
| 675 | wl1271_debug(DEBUG_CMD, "cmd periodic scan start"); |
| 676 | |
Luciano Coelho | 683c002 | 2011-05-12 17:07:55 +0300 | [diff] [blame] | 677 | if (wl->bss_type != BSS_TYPE_STA_BSS) |
| 678 | return -EOPNOTSUPP; |
| 679 | |
| 680 | if (!test_bit(WL1271_FLAG_IDLE, &wl->flags)) |
| 681 | return -EBUSY; |
| 682 | |
Luciano Coelho | 95feadc | 2011-05-10 14:38:59 +0300 | [diff] [blame] | 683 | start = kzalloc(sizeof(*start), GFP_KERNEL); |
| 684 | if (!start) |
| 685 | return -ENOMEM; |
| 686 | |
| 687 | start->tag = WL1271_SCAN_DEFAULT_TAG; |
| 688 | |
| 689 | ret = wl1271_cmd_send(wl, CMD_START_PERIODIC_SCAN, start, |
| 690 | sizeof(*start), 0); |
| 691 | if (ret < 0) { |
| 692 | wl1271_error("failed to send scan start command"); |
| 693 | goto out_free; |
| 694 | } |
| 695 | |
| 696 | out_free: |
| 697 | kfree(start); |
| 698 | return ret; |
| 699 | } |
| 700 | |
| 701 | void wl1271_scan_sched_scan_results(struct wl1271 *wl) |
| 702 | { |
| 703 | wl1271_debug(DEBUG_SCAN, "got periodic scan results"); |
| 704 | |
| 705 | ieee80211_sched_scan_results(wl->hw); |
| 706 | } |
| 707 | |
| 708 | void wl1271_scan_sched_scan_stop(struct wl1271 *wl) |
| 709 | { |
| 710 | struct wl1271_cmd_sched_scan_stop *stop; |
| 711 | int ret = 0; |
| 712 | |
| 713 | wl1271_debug(DEBUG_CMD, "cmd periodic scan stop"); |
| 714 | |
| 715 | /* FIXME: what to do if alloc'ing to stop fails? */ |
| 716 | stop = kzalloc(sizeof(*stop), GFP_KERNEL); |
| 717 | if (!stop) { |
| 718 | wl1271_error("failed to alloc memory to send sched scan stop"); |
| 719 | return; |
| 720 | } |
| 721 | |
| 722 | stop->tag = WL1271_SCAN_DEFAULT_TAG; |
| 723 | |
| 724 | ret = wl1271_cmd_send(wl, CMD_STOP_PERIODIC_SCAN, stop, |
| 725 | sizeof(*stop), 0); |
Luciano Coelho | 33c2c06 | 2011-05-10 14:46:02 +0300 | [diff] [blame] | 726 | if (ret < 0) { |
Luciano Coelho | 95feadc | 2011-05-10 14:38:59 +0300 | [diff] [blame] | 727 | wl1271_error("failed to send sched scan stop command"); |
Luciano Coelho | 33c2c06 | 2011-05-10 14:46:02 +0300 | [diff] [blame] | 728 | goto out_free; |
| 729 | } |
| 730 | wl->sched_scanning = false; |
Luciano Coelho | 95feadc | 2011-05-10 14:38:59 +0300 | [diff] [blame] | 731 | |
Luciano Coelho | 33c2c06 | 2011-05-10 14:46:02 +0300 | [diff] [blame] | 732 | out_free: |
Luciano Coelho | 95feadc | 2011-05-10 14:38:59 +0300 | [diff] [blame] | 733 | kfree(stop); |
| 734 | } |