| 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" | 
| Luciano Coelho | 34dd2aa | 2010-07-08 17:50:06 +0300 | [diff] [blame] | 31 |  | 
| Juuso Oikarinen | c454f1d | 2010-08-24 06:28:03 +0300 | [diff] [blame] | 32 | void wl1271_scan_complete_work(struct work_struct *work) | 
|  | 33 | { | 
| Juuso Oikarinen | 78abd32 | 2010-09-21 06:23:32 +0200 | [diff] [blame] | 34 | struct delayed_work *dwork; | 
|  | 35 | struct wl1271 *wl; | 
|  | 36 |  | 
|  | 37 | dwork = container_of(work, struct delayed_work, work); | 
|  | 38 | wl = container_of(dwork, struct wl1271, scan_complete_work); | 
| Juuso Oikarinen | c454f1d | 2010-08-24 06:28:03 +0300 | [diff] [blame] | 39 |  | 
|  | 40 | wl1271_debug(DEBUG_SCAN, "Scanning complete"); | 
|  | 41 |  | 
|  | 42 | mutex_lock(&wl->mutex); | 
| Juuso Oikarinen | 52a2a37 | 2010-09-21 06:23:30 +0200 | [diff] [blame] | 43 |  | 
| Arik Nemtsov | 24225b3 | 2011-03-01 12:27:26 +0200 | [diff] [blame] | 44 | if (wl->state == WL1271_STATE_OFF) | 
|  | 45 | goto out; | 
|  | 46 |  | 
|  | 47 | if (wl->scan.state == WL1271_SCAN_STATE_IDLE) | 
|  | 48 | goto out; | 
| Juuso Oikarinen | 52a2a37 | 2010-09-21 06:23:30 +0200 | [diff] [blame] | 49 |  | 
| Juuso Oikarinen | c454f1d | 2010-08-24 06:28:03 +0300 | [diff] [blame] | 50 | wl->scan.state = WL1271_SCAN_STATE_IDLE; | 
| Luciano Coelho | 4a31c11 | 2011-03-21 23:16:14 +0200 | [diff] [blame] | 51 | memset(wl->scan.scanned_ch, 0, sizeof(wl->scan.scanned_ch)); | 
| Juuso Oikarinen | b739a42 | 2010-10-26 13:24:38 +0200 | [diff] [blame] | 52 | wl->scan.req = NULL; | 
| Juuso Oikarinen | c454f1d | 2010-08-24 06:28:03 +0300 | [diff] [blame] | 53 | ieee80211_scan_completed(wl->hw, false); | 
| Juuso Oikarinen | 78abd32 | 2010-09-21 06:23:32 +0200 | [diff] [blame] | 54 |  | 
| Juuso Oikarinen | 2f6724b | 2010-11-24 08:16:57 +0200 | [diff] [blame] | 55 | /* restore hardware connection monitoring template */ | 
| Arik Nemtsov | 24225b3 | 2011-03-01 12:27:26 +0200 | [diff] [blame] | 56 | if (test_bit(WL1271_FLAG_STA_ASSOCIATED, &wl->flags)) { | 
|  | 57 | if (wl1271_ps_elp_wakeup(wl) == 0) { | 
|  | 58 | wl1271_cmd_build_ap_probe_req(wl, wl->probereq); | 
|  | 59 | wl1271_ps_elp_sleep(wl); | 
|  | 60 | } | 
|  | 61 | } | 
| Juuso Oikarinen | 2f6724b | 2010-11-24 08:16:57 +0200 | [diff] [blame] | 62 |  | 
| Juuso Oikarinen | 78abd32 | 2010-09-21 06:23:32 +0200 | [diff] [blame] | 63 | if (wl->scan.failed) { | 
|  | 64 | wl1271_info("Scan completed due to error."); | 
|  | 65 | ieee80211_queue_work(wl->hw, &wl->recovery_work); | 
|  | 66 | } | 
| Arik Nemtsov | 24225b3 | 2011-03-01 12:27:26 +0200 | [diff] [blame] | 67 |  | 
|  | 68 | out: | 
| Juuso Oikarinen | b739a42 | 2010-10-26 13:24:38 +0200 | [diff] [blame] | 69 | mutex_unlock(&wl->mutex); | 
|  | 70 |  | 
| Juuso Oikarinen | c454f1d | 2010-08-24 06:28:03 +0300 | [diff] [blame] | 71 | } | 
|  | 72 |  | 
|  | 73 |  | 
| Luciano Coelho | 08688d6 | 2010-07-08 17:50:07 +0300 | [diff] [blame] | 74 | static int wl1271_get_scan_channels(struct wl1271 *wl, | 
|  | 75 | struct cfg80211_scan_request *req, | 
|  | 76 | struct basic_scan_channel_params *channels, | 
|  | 77 | enum ieee80211_band band, bool passive) | 
| Luciano Coelho | 34dd2aa | 2010-07-08 17:50:06 +0300 | [diff] [blame] | 78 | { | 
| Juuso Oikarinen | bea39d6 | 2010-09-21 08:14:31 +0200 | [diff] [blame] | 79 | struct conf_scan_settings *c = &wl->conf.scan; | 
| Luciano Coelho | 08688d6 | 2010-07-08 17:50:07 +0300 | [diff] [blame] | 80 | int i, j; | 
|  | 81 | u32 flags; | 
| Luciano Coelho | 34dd2aa | 2010-07-08 17:50:06 +0300 | [diff] [blame] | 82 |  | 
| Luciano Coelho | 08688d6 | 2010-07-08 17:50:07 +0300 | [diff] [blame] | 83 | for (i = 0, j = 0; | 
|  | 84 | i < req->n_channels && j < WL1271_SCAN_MAX_CHANNELS; | 
|  | 85 | i++) { | 
| Luciano Coelho | 34dd2aa | 2010-07-08 17:50:06 +0300 | [diff] [blame] | 86 |  | 
| Luciano Coelho | 08688d6 | 2010-07-08 17:50:07 +0300 | [diff] [blame] | 87 | flags = req->channels[i]->flags; | 
| Luciano Coelho | 34dd2aa | 2010-07-08 17:50:06 +0300 | [diff] [blame] | 88 |  | 
| Luciano Coelho | 4a31c11 | 2011-03-21 23:16:14 +0200 | [diff] [blame] | 89 | if (!test_bit(i, wl->scan.scanned_ch) && | 
| Luciano Coelho | 08688d6 | 2010-07-08 17:50:07 +0300 | [diff] [blame] | 90 | !(flags & IEEE80211_CHAN_DISABLED) && | 
|  | 91 | ((!!(flags & IEEE80211_CHAN_PASSIVE_SCAN)) == passive) && | 
|  | 92 | (req->channels[i]->band == band)) { | 
| Luciano Coelho | 34dd2aa | 2010-07-08 17:50:06 +0300 | [diff] [blame] | 93 |  | 
| Luciano Coelho | 08688d6 | 2010-07-08 17:50:07 +0300 | [diff] [blame] | 94 | wl1271_debug(DEBUG_SCAN, "band %d, center_freq %d ", | 
|  | 95 | req->channels[i]->band, | 
|  | 96 | req->channels[i]->center_freq); | 
|  | 97 | wl1271_debug(DEBUG_SCAN, "hw_value %d, flags %X", | 
|  | 98 | req->channels[i]->hw_value, | 
|  | 99 | req->channels[i]->flags); | 
|  | 100 | wl1271_debug(DEBUG_SCAN, | 
|  | 101 | "max_antenna_gain %d, max_power %d", | 
|  | 102 | req->channels[i]->max_antenna_gain, | 
|  | 103 | req->channels[i]->max_power); | 
|  | 104 | wl1271_debug(DEBUG_SCAN, "beacon_found %d", | 
|  | 105 | req->channels[i]->beacon_found); | 
| Luciano Coelho | 34dd2aa | 2010-07-08 17:50:06 +0300 | [diff] [blame] | 106 |  | 
| Juuso Oikarinen | bea39d6 | 2010-09-21 08:14:31 +0200 | [diff] [blame] | 107 | if (!passive) { | 
|  | 108 | channels[j].min_duration = | 
|  | 109 | cpu_to_le32(c->min_dwell_time_active); | 
|  | 110 | channels[j].max_duration = | 
|  | 111 | cpu_to_le32(c->max_dwell_time_active); | 
|  | 112 | } else { | 
|  | 113 | channels[j].min_duration = | 
|  | 114 | cpu_to_le32(c->min_dwell_time_passive); | 
|  | 115 | channels[j].max_duration = | 
|  | 116 | cpu_to_le32(c->max_dwell_time_passive); | 
|  | 117 | } | 
| Luciano Coelho | 08688d6 | 2010-07-08 17:50:07 +0300 | [diff] [blame] | 118 | channels[j].early_termination = 0; | 
| Luciano Coelho | 3cc7b54 | 2010-07-08 17:50:08 +0300 | [diff] [blame] | 119 | channels[j].tx_power_att = req->channels[i]->max_power; | 
| Luciano Coelho | 08688d6 | 2010-07-08 17:50:07 +0300 | [diff] [blame] | 120 | channels[j].channel = req->channels[i]->hw_value; | 
|  | 121 |  | 
|  | 122 | memset(&channels[j].bssid_lsb, 0xff, 4); | 
|  | 123 | memset(&channels[j].bssid_msb, 0xff, 2); | 
|  | 124 |  | 
|  | 125 | /* Mark the channels we already used */ | 
| Luciano Coelho | 4a31c11 | 2011-03-21 23:16:14 +0200 | [diff] [blame] | 126 | set_bit(i, wl->scan.scanned_ch); | 
| Luciano Coelho | 08688d6 | 2010-07-08 17:50:07 +0300 | [diff] [blame] | 127 |  | 
| Luciano Coelho | 34dd2aa | 2010-07-08 17:50:06 +0300 | [diff] [blame] | 128 | j++; | 
|  | 129 | } | 
|  | 130 | } | 
|  | 131 |  | 
| Luciano Coelho | 08688d6 | 2010-07-08 17:50:07 +0300 | [diff] [blame] | 132 | return j; | 
|  | 133 | } | 
| Luciano Coelho | 34dd2aa | 2010-07-08 17:50:06 +0300 | [diff] [blame] | 134 |  | 
| Luciano Coelho | 08688d6 | 2010-07-08 17:50:07 +0300 | [diff] [blame] | 135 | #define WL1271_NOTHING_TO_SCAN 1 | 
|  | 136 |  | 
|  | 137 | static int wl1271_scan_send(struct wl1271 *wl, enum ieee80211_band band, | 
|  | 138 | bool passive, u32 basic_rate) | 
|  | 139 | { | 
|  | 140 | struct wl1271_cmd_scan *cmd; | 
|  | 141 | struct wl1271_cmd_trigger_scan_to *trigger; | 
|  | 142 | int ret; | 
|  | 143 | u16 scan_options = 0; | 
|  | 144 |  | 
|  | 145 | cmd = kzalloc(sizeof(*cmd), GFP_KERNEL); | 
|  | 146 | trigger = kzalloc(sizeof(*trigger), GFP_KERNEL); | 
|  | 147 | if (!cmd || !trigger) { | 
|  | 148 | ret = -ENOMEM; | 
|  | 149 | goto out; | 
| Luciano Coelho | 34dd2aa | 2010-07-08 17:50:06 +0300 | [diff] [blame] | 150 | } | 
|  | 151 |  | 
| Luciano Coelho | 08688d6 | 2010-07-08 17:50:07 +0300 | [diff] [blame] | 152 | /* We always use high priority scans */ | 
|  | 153 | scan_options = WL1271_SCAN_OPT_PRIORITY_HIGH; | 
| Luciano Coelho | 4f35c02 | 2010-08-04 04:36:32 +0300 | [diff] [blame] | 154 |  | 
|  | 155 | /* No SSIDs means that we have a forced passive scan */ | 
|  | 156 | if (passive || wl->scan.req->n_ssids == 0) | 
| Luciano Coelho | 08688d6 | 2010-07-08 17:50:07 +0300 | [diff] [blame] | 157 | scan_options |= WL1271_SCAN_OPT_PASSIVE; | 
| Luciano Coelho | 4f35c02 | 2010-08-04 04:36:32 +0300 | [diff] [blame] | 158 |  | 
| Luciano Coelho | 08688d6 | 2010-07-08 17:50:07 +0300 | [diff] [blame] | 159 | cmd->params.scan_options = cpu_to_le16(scan_options); | 
|  | 160 |  | 
|  | 161 | cmd->params.n_ch = wl1271_get_scan_channels(wl, wl->scan.req, | 
|  | 162 | cmd->channels, | 
|  | 163 | band, passive); | 
|  | 164 | if (cmd->params.n_ch == 0) { | 
|  | 165 | ret = WL1271_NOTHING_TO_SCAN; | 
|  | 166 | goto out; | 
|  | 167 | } | 
|  | 168 |  | 
|  | 169 | cmd->params.tx_rate = cpu_to_le32(basic_rate); | 
|  | 170 | cmd->params.rx_config_options = cpu_to_le32(CFG_RX_ALL_GOOD); | 
|  | 171 | cmd->params.rx_filter_options = | 
|  | 172 | cpu_to_le32(CFG_RX_PRSP_EN | CFG_RX_MGMT_EN | CFG_RX_BCN_EN); | 
|  | 173 |  | 
| Juuso Oikarinen | bea39d6 | 2010-09-21 08:14:31 +0200 | [diff] [blame] | 174 | cmd->params.n_probe_reqs = wl->conf.scan.num_probe_reqs; | 
| Luciano Coelho | 08688d6 | 2010-07-08 17:50:07 +0300 | [diff] [blame] | 175 | cmd->params.tx_rate = cpu_to_le32(basic_rate); | 
|  | 176 | cmd->params.tid_trigger = 0; | 
|  | 177 | cmd->params.scan_tag = WL1271_SCAN_DEFAULT_TAG; | 
|  | 178 |  | 
|  | 179 | if (band == IEEE80211_BAND_2GHZ) | 
|  | 180 | cmd->params.band = WL1271_SCAN_BAND_2_4_GHZ; | 
|  | 181 | else | 
|  | 182 | cmd->params.band = WL1271_SCAN_BAND_5_GHZ; | 
|  | 183 |  | 
|  | 184 | if (wl->scan.ssid_len && wl->scan.ssid) { | 
|  | 185 | cmd->params.ssid_len = wl->scan.ssid_len; | 
|  | 186 | memcpy(cmd->params.ssid, wl->scan.ssid, wl->scan.ssid_len); | 
|  | 187 | } | 
|  | 188 |  | 
|  | 189 | ret = wl1271_cmd_build_probe_req(wl, wl->scan.ssid, wl->scan.ssid_len, | 
|  | 190 | wl->scan.req->ie, wl->scan.req->ie_len, | 
|  | 191 | band); | 
| Luciano Coelho | 34dd2aa | 2010-07-08 17:50:06 +0300 | [diff] [blame] | 192 | if (ret < 0) { | 
|  | 193 | wl1271_error("PROBE request template failed"); | 
|  | 194 | goto out; | 
|  | 195 | } | 
|  | 196 |  | 
| Luciano Coelho | 34dd2aa | 2010-07-08 17:50:06 +0300 | [diff] [blame] | 197 | /* disable the timeout */ | 
|  | 198 | trigger->timeout = 0; | 
| Luciano Coelho | 34dd2aa | 2010-07-08 17:50:06 +0300 | [diff] [blame] | 199 | ret = wl1271_cmd_send(wl, CMD_TRIGGER_SCAN_TO, trigger, | 
|  | 200 | sizeof(*trigger), 0); | 
|  | 201 | if (ret < 0) { | 
|  | 202 | wl1271_error("trigger scan to failed for hw scan"); | 
|  | 203 | goto out; | 
|  | 204 | } | 
|  | 205 |  | 
| Luciano Coelho | 08688d6 | 2010-07-08 17:50:07 +0300 | [diff] [blame] | 206 | wl1271_dump(DEBUG_SCAN, "SCAN: ", cmd, sizeof(*cmd)); | 
| Luciano Coelho | 34dd2aa | 2010-07-08 17:50:06 +0300 | [diff] [blame] | 207 |  | 
| Luciano Coelho | 08688d6 | 2010-07-08 17:50:07 +0300 | [diff] [blame] | 208 | ret = wl1271_cmd_send(wl, CMD_SCAN, cmd, sizeof(*cmd), 0); | 
| Luciano Coelho | 34dd2aa | 2010-07-08 17:50:06 +0300 | [diff] [blame] | 209 | if (ret < 0) { | 
|  | 210 | wl1271_error("SCAN failed"); | 
| Luciano Coelho | 34dd2aa | 2010-07-08 17:50:06 +0300 | [diff] [blame] | 211 | goto out; | 
|  | 212 | } | 
|  | 213 |  | 
|  | 214 | out: | 
| Luciano Coelho | 08688d6 | 2010-07-08 17:50:07 +0300 | [diff] [blame] | 215 | kfree(cmd); | 
| Luciano Coelho | 34dd2aa | 2010-07-08 17:50:06 +0300 | [diff] [blame] | 216 | kfree(trigger); | 
|  | 217 | return ret; | 
|  | 218 | } | 
|  | 219 |  | 
| Luciano Coelho | 08688d6 | 2010-07-08 17:50:07 +0300 | [diff] [blame] | 220 | void wl1271_scan_stm(struct wl1271 *wl) | 
| Luciano Coelho | 34dd2aa | 2010-07-08 17:50:06 +0300 | [diff] [blame] | 221 | { | 
| Juuso Oikarinen | 78abd32 | 2010-09-21 06:23:32 +0200 | [diff] [blame] | 222 | int ret = 0; | 
| Luciano Coelho | 08688d6 | 2010-07-08 17:50:07 +0300 | [diff] [blame] | 223 |  | 
|  | 224 | switch (wl->scan.state) { | 
|  | 225 | case WL1271_SCAN_STATE_IDLE: | 
|  | 226 | break; | 
|  | 227 |  | 
|  | 228 | case WL1271_SCAN_STATE_2GHZ_ACTIVE: | 
|  | 229 | ret = wl1271_scan_send(wl, IEEE80211_BAND_2GHZ, false, | 
|  | 230 | wl->conf.tx.basic_rate); | 
|  | 231 | if (ret == WL1271_NOTHING_TO_SCAN) { | 
|  | 232 | wl->scan.state = WL1271_SCAN_STATE_2GHZ_PASSIVE; | 
|  | 233 | wl1271_scan_stm(wl); | 
| Luciano Coelho | 34dd2aa | 2010-07-08 17:50:06 +0300 | [diff] [blame] | 234 | } | 
| Luciano Coelho | 08688d6 | 2010-07-08 17:50:07 +0300 | [diff] [blame] | 235 |  | 
|  | 236 | break; | 
|  | 237 |  | 
|  | 238 | case WL1271_SCAN_STATE_2GHZ_PASSIVE: | 
|  | 239 | ret = wl1271_scan_send(wl, IEEE80211_BAND_2GHZ, true, | 
|  | 240 | wl->conf.tx.basic_rate); | 
|  | 241 | if (ret == WL1271_NOTHING_TO_SCAN) { | 
| Juuso Oikarinen | 02fabb0 | 2010-08-19 04:41:15 +0200 | [diff] [blame] | 242 | if (wl->enable_11a) | 
| Luciano Coelho | 08688d6 | 2010-07-08 17:50:07 +0300 | [diff] [blame] | 243 | wl->scan.state = WL1271_SCAN_STATE_5GHZ_ACTIVE; | 
|  | 244 | else | 
|  | 245 | wl->scan.state = WL1271_SCAN_STATE_DONE; | 
|  | 246 | wl1271_scan_stm(wl); | 
|  | 247 | } | 
|  | 248 |  | 
|  | 249 | break; | 
|  | 250 |  | 
|  | 251 | case WL1271_SCAN_STATE_5GHZ_ACTIVE: | 
|  | 252 | ret = wl1271_scan_send(wl, IEEE80211_BAND_5GHZ, false, | 
|  | 253 | wl->conf.tx.basic_rate_5); | 
|  | 254 | if (ret == WL1271_NOTHING_TO_SCAN) { | 
|  | 255 | wl->scan.state = WL1271_SCAN_STATE_5GHZ_PASSIVE; | 
|  | 256 | wl1271_scan_stm(wl); | 
|  | 257 | } | 
|  | 258 |  | 
|  | 259 | break; | 
|  | 260 |  | 
|  | 261 | case WL1271_SCAN_STATE_5GHZ_PASSIVE: | 
|  | 262 | ret = wl1271_scan_send(wl, IEEE80211_BAND_5GHZ, true, | 
|  | 263 | wl->conf.tx.basic_rate_5); | 
|  | 264 | if (ret == WL1271_NOTHING_TO_SCAN) { | 
|  | 265 | wl->scan.state = WL1271_SCAN_STATE_DONE; | 
|  | 266 | wl1271_scan_stm(wl); | 
|  | 267 | } | 
|  | 268 |  | 
|  | 269 | break; | 
|  | 270 |  | 
|  | 271 | case WL1271_SCAN_STATE_DONE: | 
| Juuso Oikarinen | 78abd32 | 2010-09-21 06:23:32 +0200 | [diff] [blame] | 272 | wl->scan.failed = false; | 
|  | 273 | cancel_delayed_work(&wl->scan_complete_work); | 
|  | 274 | ieee80211_queue_delayed_work(wl->hw, &wl->scan_complete_work, | 
|  | 275 | msecs_to_jiffies(0)); | 
| Luciano Coelho | 08688d6 | 2010-07-08 17:50:07 +0300 | [diff] [blame] | 276 | break; | 
|  | 277 |  | 
|  | 278 | default: | 
|  | 279 | wl1271_error("invalid scan state"); | 
|  | 280 | break; | 
| Luciano Coelho | 34dd2aa | 2010-07-08 17:50:06 +0300 | [diff] [blame] | 281 | } | 
| Juuso Oikarinen | 78abd32 | 2010-09-21 06:23:32 +0200 | [diff] [blame] | 282 |  | 
|  | 283 | if (ret < 0) { | 
|  | 284 | cancel_delayed_work(&wl->scan_complete_work); | 
|  | 285 | ieee80211_queue_delayed_work(wl->hw, &wl->scan_complete_work, | 
|  | 286 | msecs_to_jiffies(0)); | 
|  | 287 | } | 
| Luciano Coelho | 08688d6 | 2010-07-08 17:50:07 +0300 | [diff] [blame] | 288 | } | 
|  | 289 |  | 
|  | 290 | int wl1271_scan(struct wl1271 *wl, const u8 *ssid, size_t ssid_len, | 
|  | 291 | struct cfg80211_scan_request *req) | 
|  | 292 | { | 
| Luciano Coelho | 4a31c11 | 2011-03-21 23:16:14 +0200 | [diff] [blame] | 293 | /* | 
|  | 294 | * cfg80211 should guarantee that we don't get more channels | 
|  | 295 | * than what we have registered. | 
|  | 296 | */ | 
|  | 297 | BUG_ON(req->n_channels > WL1271_MAX_CHANNELS); | 
|  | 298 |  | 
| Luciano Coelho | 08688d6 | 2010-07-08 17:50:07 +0300 | [diff] [blame] | 299 | if (wl->scan.state != WL1271_SCAN_STATE_IDLE) | 
|  | 300 | return -EBUSY; | 
|  | 301 |  | 
|  | 302 | wl->scan.state = WL1271_SCAN_STATE_2GHZ_ACTIVE; | 
|  | 303 |  | 
|  | 304 | if (ssid_len && ssid) { | 
|  | 305 | wl->scan.ssid_len = ssid_len; | 
|  | 306 | memcpy(wl->scan.ssid, ssid, ssid_len); | 
|  | 307 | } else { | 
|  | 308 | wl->scan.ssid_len = 0; | 
|  | 309 | } | 
|  | 310 |  | 
|  | 311 | wl->scan.req = req; | 
| Luciano Coelho | 4a31c11 | 2011-03-21 23:16:14 +0200 | [diff] [blame] | 312 | memset(wl->scan.scanned_ch, 0, sizeof(wl->scan.scanned_ch)); | 
| Luciano Coelho | 08688d6 | 2010-07-08 17:50:07 +0300 | [diff] [blame] | 313 |  | 
| Juuso Oikarinen | 78abd32 | 2010-09-21 06:23:32 +0200 | [diff] [blame] | 314 | /* we assume failure so that timeout scenarios are handled correctly */ | 
|  | 315 | wl->scan.failed = true; | 
|  | 316 | ieee80211_queue_delayed_work(wl->hw, &wl->scan_complete_work, | 
|  | 317 | msecs_to_jiffies(WL1271_SCAN_TIMEOUT)); | 
|  | 318 |  | 
| Luciano Coelho | 08688d6 | 2010-07-08 17:50:07 +0300 | [diff] [blame] | 319 | wl1271_scan_stm(wl); | 
|  | 320 |  | 
| Luciano Coelho | 34dd2aa | 2010-07-08 17:50:06 +0300 | [diff] [blame] | 321 | return 0; | 
|  | 322 | } | 
| Luciano Coelho | 95feadc | 2011-05-10 14:38:59 +0300 | [diff] [blame] | 323 |  | 
|  | 324 | static int | 
|  | 325 | wl1271_scan_get_sched_scan_channels(struct wl1271 *wl, | 
|  | 326 | struct cfg80211_sched_scan_request *req, | 
|  | 327 | struct conn_scan_ch_params *channels, | 
|  | 328 | u32 band, bool radar, bool passive, | 
|  | 329 | int start) | 
|  | 330 | { | 
|  | 331 | struct conf_sched_scan_settings *c = &wl->conf.sched_scan; | 
|  | 332 | int i, j; | 
|  | 333 | u32 flags; | 
| Luciano Coelho | 66870b1 | 2011-05-27 15:34:48 +0300 | [diff] [blame] | 334 | bool force_passive = !req->n_ssids; | 
| Luciano Coelho | 95feadc | 2011-05-10 14:38:59 +0300 | [diff] [blame] | 335 |  | 
|  | 336 | for (i = 0, j = start; | 
|  | 337 | i < req->n_channels && j < MAX_CHANNELS_ALL_BANDS; | 
|  | 338 | i++) { | 
|  | 339 | flags = req->channels[i]->flags; | 
|  | 340 |  | 
| Luciano Coelho | 66870b1 | 2011-05-27 15:34:48 +0300 | [diff] [blame] | 341 | if (force_passive) | 
|  | 342 | flags |= IEEE80211_CHAN_PASSIVE_SCAN; | 
|  | 343 |  | 
| Luciano Coelho | 2497a24 | 2011-05-27 15:34:46 +0300 | [diff] [blame] | 344 | if ((req->channels[i]->band == band) && | 
|  | 345 | !(flags & IEEE80211_CHAN_DISABLED) && | 
| Luciano Coelho | dd08682 | 2011-05-27 15:34:45 +0300 | [diff] [blame] | 346 | (!!(flags & IEEE80211_CHAN_RADAR) == radar) && | 
| Luciano Coelho | 2497a24 | 2011-05-27 15:34:46 +0300 | [diff] [blame] | 347 | /* if radar is set, we ignore the passive flag */ | 
|  | 348 | (radar || | 
|  | 349 | !!(flags & IEEE80211_CHAN_PASSIVE_SCAN) == passive)) { | 
| Luciano Coelho | 95feadc | 2011-05-10 14:38:59 +0300 | [diff] [blame] | 350 | wl1271_debug(DEBUG_SCAN, "band %d, center_freq %d ", | 
|  | 351 | req->channels[i]->band, | 
|  | 352 | req->channels[i]->center_freq); | 
|  | 353 | wl1271_debug(DEBUG_SCAN, "hw_value %d, flags %X", | 
|  | 354 | req->channels[i]->hw_value, | 
|  | 355 | req->channels[i]->flags); | 
|  | 356 | wl1271_debug(DEBUG_SCAN, "max_power %d", | 
|  | 357 | req->channels[i]->max_power); | 
|  | 358 |  | 
| Luciano Coelho | 50a66d7 | 2011-05-27 15:34:47 +0300 | [diff] [blame] | 359 | if (flags & IEEE80211_CHAN_RADAR) { | 
| Luciano Coelho | 2497a24 | 2011-05-27 15:34:46 +0300 | [diff] [blame] | 360 | channels[j].flags |= SCAN_CHANNEL_FLAGS_DFS; | 
| Luciano Coelho | 50a66d7 | 2011-05-27 15:34:47 +0300 | [diff] [blame] | 361 | channels[j].passive_duration = | 
|  | 362 | cpu_to_le16(c->dwell_time_dfs); | 
|  | 363 | } | 
|  | 364 | else if (flags & IEEE80211_CHAN_PASSIVE_SCAN) { | 
| Luciano Coelho | 95feadc | 2011-05-10 14:38:59 +0300 | [diff] [blame] | 365 | channels[j].passive_duration = | 
|  | 366 | cpu_to_le16(c->dwell_time_passive); | 
|  | 367 | } else { | 
|  | 368 | channels[j].min_duration = | 
|  | 369 | cpu_to_le16(c->min_dwell_time_active); | 
|  | 370 | channels[j].max_duration = | 
|  | 371 | cpu_to_le16(c->max_dwell_time_active); | 
|  | 372 | } | 
| Luciano Coelho | 2497a24 | 2011-05-27 15:34:46 +0300 | [diff] [blame] | 373 | channels[j].tx_power_att = req->channels[i]->max_power; | 
| Luciano Coelho | 95feadc | 2011-05-10 14:38:59 +0300 | [diff] [blame] | 374 | channels[j].channel = req->channels[i]->hw_value; | 
|  | 375 |  | 
|  | 376 | j++; | 
|  | 377 | } | 
|  | 378 | } | 
|  | 379 |  | 
|  | 380 | return j - start; | 
|  | 381 | } | 
|  | 382 |  | 
|  | 383 | static int | 
|  | 384 | wl1271_scan_sched_scan_channels(struct wl1271 *wl, | 
|  | 385 | struct cfg80211_sched_scan_request *req, | 
|  | 386 | struct wl1271_cmd_sched_scan_config *cfg) | 
|  | 387 | { | 
|  | 388 | int idx = 0; | 
|  | 389 |  | 
|  | 390 | cfg->passive[0] = | 
|  | 391 | wl1271_scan_get_sched_scan_channels(wl, req, cfg->channels, | 
|  | 392 | IEEE80211_BAND_2GHZ, | 
|  | 393 | false, true, idx); | 
|  | 394 | idx += cfg->passive[0]; | 
|  | 395 |  | 
|  | 396 | cfg->active[0] = | 
|  | 397 | wl1271_scan_get_sched_scan_channels(wl, req, cfg->channels, | 
|  | 398 | IEEE80211_BAND_2GHZ, | 
|  | 399 | false, false, idx); | 
| Luciano Coelho | 2497a24 | 2011-05-27 15:34:46 +0300 | [diff] [blame] | 400 | /* | 
|  | 401 | * 5GHz channels always start at position 14, not immediately | 
|  | 402 | * after the last 2.4GHz channel | 
|  | 403 | */ | 
|  | 404 | idx = 14; | 
| Luciano Coelho | 95feadc | 2011-05-10 14:38:59 +0300 | [diff] [blame] | 405 |  | 
|  | 406 | cfg->passive[1] = | 
|  | 407 | wl1271_scan_get_sched_scan_channels(wl, req, cfg->channels, | 
|  | 408 | IEEE80211_BAND_5GHZ, | 
|  | 409 | false, true, idx); | 
|  | 410 | idx += cfg->passive[1]; | 
|  | 411 |  | 
| Luciano Coelho | 95feadc | 2011-05-10 14:38:59 +0300 | [diff] [blame] | 412 | cfg->dfs = | 
|  | 413 | wl1271_scan_get_sched_scan_channels(wl, req, cfg->channels, | 
|  | 414 | IEEE80211_BAND_5GHZ, | 
| Luciano Coelho | 2497a24 | 2011-05-27 15:34:46 +0300 | [diff] [blame] | 415 | true, true, idx); | 
| Luciano Coelho | 95feadc | 2011-05-10 14:38:59 +0300 | [diff] [blame] | 416 | idx += cfg->dfs; | 
|  | 417 |  | 
| Luciano Coelho | 2497a24 | 2011-05-27 15:34:46 +0300 | [diff] [blame] | 418 | cfg->active[1] = | 
|  | 419 | wl1271_scan_get_sched_scan_channels(wl, req, cfg->channels, | 
|  | 420 | IEEE80211_BAND_5GHZ, | 
|  | 421 | false, false, idx); | 
|  | 422 | idx += cfg->active[1]; | 
|  | 423 |  | 
| Luciano Coelho | 95feadc | 2011-05-10 14:38:59 +0300 | [diff] [blame] | 424 | wl1271_debug(DEBUG_SCAN, "    2.4GHz: active %d passive %d", | 
|  | 425 | cfg->active[0], cfg->passive[0]); | 
|  | 426 | wl1271_debug(DEBUG_SCAN, "    5GHz: active %d passive %d", | 
|  | 427 | cfg->active[1], cfg->passive[1]); | 
| Luciano Coelho | 2497a24 | 2011-05-27 15:34:46 +0300 | [diff] [blame] | 428 | wl1271_debug(DEBUG_SCAN, "    DFS: %d", cfg->dfs); | 
| Luciano Coelho | 95feadc | 2011-05-10 14:38:59 +0300 | [diff] [blame] | 429 |  | 
|  | 430 | return idx; | 
|  | 431 | } | 
|  | 432 |  | 
|  | 433 | int wl1271_scan_sched_scan_config(struct wl1271 *wl, | 
|  | 434 | struct cfg80211_sched_scan_request *req, | 
|  | 435 | struct ieee80211_sched_scan_ies *ies) | 
|  | 436 | { | 
|  | 437 | struct wl1271_cmd_sched_scan_config *cfg = NULL; | 
|  | 438 | struct conf_sched_scan_settings *c = &wl->conf.sched_scan; | 
|  | 439 | int i, total_channels, ret; | 
| Luciano Coelho | 66870b1 | 2011-05-27 15:34:48 +0300 | [diff] [blame] | 440 | bool force_passive = !req->n_ssids; | 
| Luciano Coelho | 95feadc | 2011-05-10 14:38:59 +0300 | [diff] [blame] | 441 |  | 
|  | 442 | wl1271_debug(DEBUG_CMD, "cmd sched_scan scan config"); | 
|  | 443 |  | 
|  | 444 | cfg = kzalloc(sizeof(*cfg), GFP_KERNEL); | 
|  | 445 | if (!cfg) | 
|  | 446 | return -ENOMEM; | 
|  | 447 |  | 
|  | 448 | cfg->rssi_threshold = c->rssi_threshold; | 
|  | 449 | cfg->snr_threshold  = c->snr_threshold; | 
|  | 450 | cfg->n_probe_reqs = c->num_probe_reqs; | 
|  | 451 | /* cycles set to 0 it means infinite (until manually stopped) */ | 
|  | 452 | cfg->cycles = 0; | 
|  | 453 | /* report APs when at least 1 is found */ | 
|  | 454 | cfg->report_after = 1; | 
|  | 455 | /* don't stop scanning automatically when something is found */ | 
|  | 456 | cfg->terminate = 0; | 
|  | 457 | cfg->tag = WL1271_SCAN_DEFAULT_TAG; | 
|  | 458 | /* don't filter on BSS type */ | 
|  | 459 | cfg->bss_type = SCAN_BSS_TYPE_ANY; | 
|  | 460 | /* currently NL80211 supports only a single interval */ | 
|  | 461 | for (i = 0; i < SCAN_MAX_CYCLE_INTERVALS; i++) | 
|  | 462 | cfg->intervals[i] = cpu_to_le32(req->interval); | 
|  | 463 |  | 
| Luciano Coelho | 66870b1 | 2011-05-27 15:34:48 +0300 | [diff] [blame] | 464 | if (!force_passive && req->ssids[0].ssid_len && req->ssids[0].ssid) { | 
| Luciano Coelho | 95feadc | 2011-05-10 14:38:59 +0300 | [diff] [blame] | 465 | cfg->filter_type = SCAN_SSID_FILTER_SPECIFIC; | 
|  | 466 | cfg->ssid_len = req->ssids[0].ssid_len; | 
|  | 467 | memcpy(cfg->ssid, req->ssids[0].ssid, | 
|  | 468 | req->ssids[0].ssid_len); | 
|  | 469 | } else { | 
|  | 470 | cfg->filter_type = SCAN_SSID_FILTER_ANY; | 
|  | 471 | cfg->ssid_len = 0; | 
|  | 472 | } | 
|  | 473 |  | 
|  | 474 | total_channels = wl1271_scan_sched_scan_channels(wl, req, cfg); | 
|  | 475 | if (total_channels == 0) { | 
|  | 476 | wl1271_error("scan channel list is empty"); | 
|  | 477 | ret = -EINVAL; | 
|  | 478 | goto out; | 
|  | 479 | } | 
|  | 480 |  | 
| Luciano Coelho | 66870b1 | 2011-05-27 15:34:48 +0300 | [diff] [blame] | 481 | if (!force_passive && cfg->active[0]) { | 
| Luciano Coelho | 95feadc | 2011-05-10 14:38:59 +0300 | [diff] [blame] | 482 | ret = wl1271_cmd_build_probe_req(wl, req->ssids[0].ssid, | 
|  | 483 | req->ssids[0].ssid_len, | 
|  | 484 | ies->ie[IEEE80211_BAND_2GHZ], | 
|  | 485 | ies->len[IEEE80211_BAND_2GHZ], | 
|  | 486 | IEEE80211_BAND_2GHZ); | 
|  | 487 | if (ret < 0) { | 
|  | 488 | wl1271_error("2.4GHz PROBE request template failed"); | 
|  | 489 | goto out; | 
|  | 490 | } | 
|  | 491 | } | 
|  | 492 |  | 
| Luciano Coelho | 66870b1 | 2011-05-27 15:34:48 +0300 | [diff] [blame] | 493 | if (!force_passive && cfg->active[1]) { | 
| Luciano Coelho | 95feadc | 2011-05-10 14:38:59 +0300 | [diff] [blame] | 494 | ret = wl1271_cmd_build_probe_req(wl,  req->ssids[0].ssid, | 
|  | 495 | req->ssids[0].ssid_len, | 
|  | 496 | ies->ie[IEEE80211_BAND_5GHZ], | 
|  | 497 | ies->len[IEEE80211_BAND_5GHZ], | 
|  | 498 | IEEE80211_BAND_5GHZ); | 
|  | 499 | if (ret < 0) { | 
|  | 500 | wl1271_error("5GHz PROBE request template failed"); | 
|  | 501 | goto out; | 
|  | 502 | } | 
|  | 503 | } | 
|  | 504 |  | 
|  | 505 | wl1271_dump(DEBUG_SCAN, "SCAN_CFG: ", cfg, sizeof(*cfg)); | 
|  | 506 |  | 
|  | 507 | ret = wl1271_cmd_send(wl, CMD_CONNECTION_SCAN_CFG, cfg, | 
|  | 508 | sizeof(*cfg), 0); | 
|  | 509 | if (ret < 0) { | 
|  | 510 | wl1271_error("SCAN configuration failed"); | 
|  | 511 | goto out; | 
|  | 512 | } | 
|  | 513 | out: | 
|  | 514 | kfree(cfg); | 
|  | 515 | return ret; | 
|  | 516 | } | 
|  | 517 |  | 
|  | 518 | int wl1271_scan_sched_scan_start(struct wl1271 *wl) | 
|  | 519 | { | 
|  | 520 | struct wl1271_cmd_sched_scan_start *start; | 
|  | 521 | int ret = 0; | 
|  | 522 |  | 
|  | 523 | wl1271_debug(DEBUG_CMD, "cmd periodic scan start"); | 
|  | 524 |  | 
| Luciano Coelho | 683c002 | 2011-05-12 17:07:55 +0300 | [diff] [blame] | 525 | if (wl->bss_type != BSS_TYPE_STA_BSS) | 
|  | 526 | return -EOPNOTSUPP; | 
|  | 527 |  | 
|  | 528 | if (!test_bit(WL1271_FLAG_IDLE, &wl->flags)) | 
|  | 529 | return -EBUSY; | 
|  | 530 |  | 
| Luciano Coelho | 95feadc | 2011-05-10 14:38:59 +0300 | [diff] [blame] | 531 | start = kzalloc(sizeof(*start), GFP_KERNEL); | 
|  | 532 | if (!start) | 
|  | 533 | return -ENOMEM; | 
|  | 534 |  | 
|  | 535 | start->tag = WL1271_SCAN_DEFAULT_TAG; | 
|  | 536 |  | 
|  | 537 | ret = wl1271_cmd_send(wl, CMD_START_PERIODIC_SCAN, start, | 
|  | 538 | sizeof(*start), 0); | 
|  | 539 | if (ret < 0) { | 
|  | 540 | wl1271_error("failed to send scan start command"); | 
|  | 541 | goto out_free; | 
|  | 542 | } | 
|  | 543 |  | 
|  | 544 | out_free: | 
|  | 545 | kfree(start); | 
|  | 546 | return ret; | 
|  | 547 | } | 
|  | 548 |  | 
|  | 549 | void wl1271_scan_sched_scan_results(struct wl1271 *wl) | 
|  | 550 | { | 
|  | 551 | wl1271_debug(DEBUG_SCAN, "got periodic scan results"); | 
|  | 552 |  | 
|  | 553 | ieee80211_sched_scan_results(wl->hw); | 
|  | 554 | } | 
|  | 555 |  | 
|  | 556 | void wl1271_scan_sched_scan_stop(struct wl1271 *wl) | 
|  | 557 | { | 
|  | 558 | struct wl1271_cmd_sched_scan_stop *stop; | 
|  | 559 | int ret = 0; | 
|  | 560 |  | 
|  | 561 | wl1271_debug(DEBUG_CMD, "cmd periodic scan stop"); | 
|  | 562 |  | 
|  | 563 | /* FIXME: what to do if alloc'ing to stop fails? */ | 
|  | 564 | stop = kzalloc(sizeof(*stop), GFP_KERNEL); | 
|  | 565 | if (!stop) { | 
|  | 566 | wl1271_error("failed to alloc memory to send sched scan stop"); | 
|  | 567 | return; | 
|  | 568 | } | 
|  | 569 |  | 
|  | 570 | stop->tag = WL1271_SCAN_DEFAULT_TAG; | 
|  | 571 |  | 
|  | 572 | ret = wl1271_cmd_send(wl, CMD_STOP_PERIODIC_SCAN, stop, | 
|  | 573 | sizeof(*stop), 0); | 
| Luciano Coelho | 33c2c06 | 2011-05-10 14:46:02 +0300 | [diff] [blame] | 574 | if (ret < 0) { | 
| Luciano Coelho | 95feadc | 2011-05-10 14:38:59 +0300 | [diff] [blame] | 575 | wl1271_error("failed to send sched scan stop command"); | 
| Luciano Coelho | 33c2c06 | 2011-05-10 14:46:02 +0300 | [diff] [blame] | 576 | goto out_free; | 
|  | 577 | } | 
|  | 578 | wl->sched_scanning = false; | 
| Luciano Coelho | 95feadc | 2011-05-10 14:38:59 +0300 | [diff] [blame] | 579 |  | 
| Luciano Coelho | 33c2c06 | 2011-05-10 14:46:02 +0300 | [diff] [blame] | 580 | out_free: | 
| Luciano Coelho | 95feadc | 2011-05-10 14:38:59 +0300 | [diff] [blame] | 581 | kfree(stop); | 
|  | 582 | } |