Johannes Berg | 0a51b27 | 2008-09-08 17:44:25 +0200 | [diff] [blame] | 1 | /* |
Johannes Berg | 5484e23 | 2008-09-08 17:44:27 +0200 | [diff] [blame] | 2 | * Scanning implementation |
| 3 | * |
Johannes Berg | 0a51b27 | 2008-09-08 17:44:25 +0200 | [diff] [blame] | 4 | * Copyright 2003, Jouni Malinen <jkmaline@cc.hut.fi> |
| 5 | * Copyright 2004, Instant802 Networks, Inc. |
| 6 | * Copyright 2005, Devicescape Software, Inc. |
| 7 | * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz> |
| 8 | * Copyright 2007, Michael Wu <flamingice@sourmilk.net> |
| 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify |
| 11 | * it under the terms of the GNU General Public License version 2 as |
| 12 | * published by the Free Software Foundation. |
| 13 | */ |
| 14 | |
Johannes Berg | 00d3f14 | 2009-02-10 21:26:00 +0100 | [diff] [blame] | 15 | /* TODO: figure out how to avoid that the "current BSS" expires */ |
Johannes Berg | 5484e23 | 2008-09-08 17:44:27 +0200 | [diff] [blame] | 16 | |
Johannes Berg | 0a51b27 | 2008-09-08 17:44:25 +0200 | [diff] [blame] | 17 | #include <linux/wireless.h> |
| 18 | #include <linux/if_arp.h> |
Johannes Berg | 078e1e6 | 2009-01-22 18:07:31 +0100 | [diff] [blame] | 19 | #include <linux/rtnetlink.h> |
Johannes Berg | 0a51b27 | 2008-09-08 17:44:25 +0200 | [diff] [blame] | 20 | #include <net/mac80211.h> |
| 21 | #include <net/iw_handler.h> |
| 22 | |
| 23 | #include "ieee80211_i.h" |
Johannes Berg | 5484e23 | 2008-09-08 17:44:27 +0200 | [diff] [blame] | 24 | #include "mesh.h" |
Johannes Berg | 0a51b27 | 2008-09-08 17:44:25 +0200 | [diff] [blame] | 25 | |
| 26 | #define IEEE80211_PROBE_DELAY (HZ / 33) |
| 27 | #define IEEE80211_CHANNEL_TIME (HZ / 33) |
| 28 | #define IEEE80211_PASSIVE_CHANNEL_TIME (HZ / 5) |
| 29 | |
Johannes Berg | c2b1345 | 2008-09-11 00:01:55 +0200 | [diff] [blame] | 30 | struct ieee80211_bss * |
Johannes Berg | 5484e23 | 2008-09-08 17:44:27 +0200 | [diff] [blame] | 31 | ieee80211_rx_bss_get(struct ieee80211_local *local, u8 *bssid, int freq, |
| 32 | u8 *ssid, u8 ssid_len) |
| 33 | { |
Johannes Berg | 00d3f14 | 2009-02-10 21:26:00 +0100 | [diff] [blame] | 34 | return (void *)cfg80211_get_bss(local->hw.wiphy, |
| 35 | ieee80211_get_channel(local->hw.wiphy, |
| 36 | freq), |
| 37 | bssid, ssid, ssid_len, |
| 38 | 0, 0); |
Johannes Berg | 5484e23 | 2008-09-08 17:44:27 +0200 | [diff] [blame] | 39 | } |
| 40 | |
Johannes Berg | 00d3f14 | 2009-02-10 21:26:00 +0100 | [diff] [blame] | 41 | static void ieee80211_rx_bss_free(struct cfg80211_bss *cbss) |
Johannes Berg | 5484e23 | 2008-09-08 17:44:27 +0200 | [diff] [blame] | 42 | { |
Johannes Berg | 00d3f14 | 2009-02-10 21:26:00 +0100 | [diff] [blame] | 43 | struct ieee80211_bss *bss = (void *)cbss; |
Johannes Berg | 5484e23 | 2008-09-08 17:44:27 +0200 | [diff] [blame] | 44 | |
Johannes Berg | 5484e23 | 2008-09-08 17:44:27 +0200 | [diff] [blame] | 45 | kfree(bss_mesh_id(bss)); |
| 46 | kfree(bss_mesh_cfg(bss)); |
Johannes Berg | 5484e23 | 2008-09-08 17:44:27 +0200 | [diff] [blame] | 47 | } |
| 48 | |
| 49 | void ieee80211_rx_bss_put(struct ieee80211_local *local, |
Johannes Berg | c2b1345 | 2008-09-11 00:01:55 +0200 | [diff] [blame] | 50 | struct ieee80211_bss *bss) |
Johannes Berg | 5484e23 | 2008-09-08 17:44:27 +0200 | [diff] [blame] | 51 | { |
Johannes Berg | 00d3f14 | 2009-02-10 21:26:00 +0100 | [diff] [blame] | 52 | cfg80211_put_bss((struct cfg80211_bss *)bss); |
Johannes Berg | 5484e23 | 2008-09-08 17:44:27 +0200 | [diff] [blame] | 53 | } |
| 54 | |
Johannes Berg | c2b1345 | 2008-09-11 00:01:55 +0200 | [diff] [blame] | 55 | struct ieee80211_bss * |
Johannes Berg | 5484e23 | 2008-09-08 17:44:27 +0200 | [diff] [blame] | 56 | ieee80211_bss_info_update(struct ieee80211_local *local, |
| 57 | struct ieee80211_rx_status *rx_status, |
| 58 | struct ieee80211_mgmt *mgmt, |
| 59 | size_t len, |
| 60 | struct ieee802_11_elems *elems, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 61 | struct ieee80211_channel *channel, |
| 62 | bool beacon) |
Johannes Berg | 5484e23 | 2008-09-08 17:44:27 +0200 | [diff] [blame] | 63 | { |
Johannes Berg | c2b1345 | 2008-09-11 00:01:55 +0200 | [diff] [blame] | 64 | struct ieee80211_bss *bss; |
Johannes Berg | 00d3f14 | 2009-02-10 21:26:00 +0100 | [diff] [blame] | 65 | int clen; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 66 | enum cfg80211_signal_type sigtype = CFG80211_SIGNAL_TYPE_NONE; |
| 67 | s32 signal = 0; |
| 68 | |
| 69 | if (local->hw.flags & IEEE80211_HW_SIGNAL_DBM) { |
| 70 | sigtype = CFG80211_SIGNAL_TYPE_MBM; |
| 71 | signal = rx_status->signal * 100; |
| 72 | } else if (local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC) { |
| 73 | sigtype = CFG80211_SIGNAL_TYPE_UNSPEC; |
| 74 | signal = (rx_status->signal * 100) / local->hw.max_signal; |
| 75 | } |
| 76 | |
Johannes Berg | 00d3f14 | 2009-02-10 21:26:00 +0100 | [diff] [blame] | 77 | bss = (void *)cfg80211_inform_bss_frame(local->hw.wiphy, channel, |
| 78 | mgmt, len, signal, sigtype, |
| 79 | GFP_ATOMIC); |
Johannes Berg | 5484e23 | 2008-09-08 17:44:27 +0200 | [diff] [blame] | 80 | |
Johannes Berg | 00d3f14 | 2009-02-10 21:26:00 +0100 | [diff] [blame] | 81 | if (!bss) |
| 82 | return NULL; |
| 83 | |
| 84 | bss->cbss.free_priv = ieee80211_rx_bss_free; |
Johannes Berg | 5484e23 | 2008-09-08 17:44:27 +0200 | [diff] [blame] | 85 | |
| 86 | /* save the ERP value so that it is available at association time */ |
| 87 | if (elems->erp_info && elems->erp_info_len >= 1) { |
| 88 | bss->erp_value = elems->erp_info[0]; |
| 89 | bss->has_erp_value = 1; |
| 90 | } |
| 91 | |
Johannes Berg | 5484e23 | 2008-09-08 17:44:27 +0200 | [diff] [blame] | 92 | if (elems->tim) { |
| 93 | struct ieee80211_tim_ie *tim_ie = |
| 94 | (struct ieee80211_tim_ie *)elems->tim; |
| 95 | bss->dtim_period = tim_ie->dtim_period; |
| 96 | } |
| 97 | |
| 98 | /* set default value for buggy APs */ |
| 99 | if (!elems->tim || bss->dtim_period == 0) |
| 100 | bss->dtim_period = 1; |
| 101 | |
| 102 | bss->supp_rates_len = 0; |
| 103 | if (elems->supp_rates) { |
| 104 | clen = IEEE80211_MAX_SUPP_RATES - bss->supp_rates_len; |
| 105 | if (clen > elems->supp_rates_len) |
| 106 | clen = elems->supp_rates_len; |
| 107 | memcpy(&bss->supp_rates[bss->supp_rates_len], elems->supp_rates, |
| 108 | clen); |
| 109 | bss->supp_rates_len += clen; |
| 110 | } |
| 111 | if (elems->ext_supp_rates) { |
| 112 | clen = IEEE80211_MAX_SUPP_RATES - bss->supp_rates_len; |
| 113 | if (clen > elems->ext_supp_rates_len) |
| 114 | clen = elems->ext_supp_rates_len; |
| 115 | memcpy(&bss->supp_rates[bss->supp_rates_len], |
| 116 | elems->ext_supp_rates, clen); |
| 117 | bss->supp_rates_len += clen; |
| 118 | } |
| 119 | |
Johannes Berg | 5484e23 | 2008-09-08 17:44:27 +0200 | [diff] [blame] | 120 | bss->wmm_used = elems->wmm_param || elems->wmm_info; |
| 121 | |
| 122 | if (!beacon) |
| 123 | bss->last_probe_resp = jiffies; |
| 124 | |
Johannes Berg | 5484e23 | 2008-09-08 17:44:27 +0200 | [diff] [blame] | 125 | return bss; |
| 126 | } |
Johannes Berg | 0a51b27 | 2008-09-08 17:44:25 +0200 | [diff] [blame] | 127 | |
Vasanthakumar Thiagarajan | 7a94708 | 2009-02-04 18:28:48 +0530 | [diff] [blame] | 128 | void ieee80211_rx_bss_remove(struct ieee80211_sub_if_data *sdata, u8 *bssid, |
| 129 | int freq, u8 *ssid, u8 ssid_len) |
| 130 | { |
| 131 | struct ieee80211_bss *bss; |
| 132 | struct ieee80211_local *local = sdata->local; |
| 133 | |
| 134 | bss = ieee80211_rx_bss_get(local, bssid, freq, ssid, ssid_len); |
| 135 | if (bss) { |
Johannes Berg | 00d3f14 | 2009-02-10 21:26:00 +0100 | [diff] [blame] | 136 | cfg80211_unlink_bss(local->hw.wiphy, (void *)bss); |
Vasanthakumar Thiagarajan | 7a94708 | 2009-02-04 18:28:48 +0530 | [diff] [blame] | 137 | ieee80211_rx_bss_put(local, bss); |
| 138 | } |
| 139 | } |
| 140 | |
Johannes Berg | 98c8fcc | 2008-09-08 17:44:26 +0200 | [diff] [blame] | 141 | ieee80211_rx_result |
Johannes Berg | c2b1345 | 2008-09-11 00:01:55 +0200 | [diff] [blame] | 142 | ieee80211_scan_rx(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb, |
| 143 | struct ieee80211_rx_status *rx_status) |
Johannes Berg | 98c8fcc | 2008-09-08 17:44:26 +0200 | [diff] [blame] | 144 | { |
| 145 | struct ieee80211_mgmt *mgmt; |
Johannes Berg | c2b1345 | 2008-09-11 00:01:55 +0200 | [diff] [blame] | 146 | struct ieee80211_bss *bss; |
Johannes Berg | 98c8fcc | 2008-09-08 17:44:26 +0200 | [diff] [blame] | 147 | u8 *elements; |
| 148 | struct ieee80211_channel *channel; |
| 149 | size_t baselen; |
| 150 | int freq; |
| 151 | __le16 fc; |
| 152 | bool presp, beacon = false; |
| 153 | struct ieee802_11_elems elems; |
| 154 | |
| 155 | if (skb->len < 2) |
| 156 | return RX_DROP_UNUSABLE; |
| 157 | |
| 158 | mgmt = (struct ieee80211_mgmt *) skb->data; |
| 159 | fc = mgmt->frame_control; |
| 160 | |
| 161 | if (ieee80211_is_ctl(fc)) |
| 162 | return RX_CONTINUE; |
| 163 | |
| 164 | if (skb->len < 24) |
| 165 | return RX_DROP_MONITOR; |
| 166 | |
| 167 | presp = ieee80211_is_probe_resp(fc); |
| 168 | if (presp) { |
| 169 | /* ignore ProbeResp to foreign address */ |
| 170 | if (memcmp(mgmt->da, sdata->dev->dev_addr, ETH_ALEN)) |
| 171 | return RX_DROP_MONITOR; |
| 172 | |
| 173 | presp = true; |
| 174 | elements = mgmt->u.probe_resp.variable; |
| 175 | baselen = offsetof(struct ieee80211_mgmt, u.probe_resp.variable); |
| 176 | } else { |
| 177 | beacon = ieee80211_is_beacon(fc); |
| 178 | baselen = offsetof(struct ieee80211_mgmt, u.beacon.variable); |
| 179 | elements = mgmt->u.beacon.variable; |
| 180 | } |
| 181 | |
| 182 | if (!presp && !beacon) |
| 183 | return RX_CONTINUE; |
| 184 | |
| 185 | if (baselen > skb->len) |
| 186 | return RX_DROP_MONITOR; |
| 187 | |
| 188 | ieee802_11_parse_elems(elements, skb->len - baselen, &elems); |
| 189 | |
| 190 | if (elems.ds_params && elems.ds_params_len == 1) |
| 191 | freq = ieee80211_channel_to_frequency(elems.ds_params[0]); |
| 192 | else |
| 193 | freq = rx_status->freq; |
| 194 | |
| 195 | channel = ieee80211_get_channel(sdata->local->hw.wiphy, freq); |
| 196 | |
| 197 | if (!channel || channel->flags & IEEE80211_CHAN_DISABLED) |
| 198 | return RX_DROP_MONITOR; |
| 199 | |
| 200 | bss = ieee80211_bss_info_update(sdata->local, rx_status, |
| 201 | mgmt, skb->len, &elems, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 202 | channel, beacon); |
Jouni Malinen | d048e50 | 2008-10-11 03:29:55 +0300 | [diff] [blame] | 203 | if (bss) |
| 204 | ieee80211_rx_bss_put(sdata->local, bss); |
Johannes Berg | 98c8fcc | 2008-09-08 17:44:26 +0200 | [diff] [blame] | 205 | |
| 206 | dev_kfree_skb(skb); |
| 207 | return RX_QUEUED; |
| 208 | } |
| 209 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 210 | void ieee80211_scan_completed(struct ieee80211_hw *hw, bool aborted) |
Johannes Berg | 0a51b27 | 2008-09-08 17:44:25 +0200 | [diff] [blame] | 211 | { |
| 212 | struct ieee80211_local *local = hw_to_local(hw); |
| 213 | struct ieee80211_sub_if_data *sdata; |
Johannes Berg | 0a51b27 | 2008-09-08 17:44:25 +0200 | [diff] [blame] | 214 | |
Johannes Berg | c2b1345 | 2008-09-11 00:01:55 +0200 | [diff] [blame] | 215 | if (WARN_ON(!local->hw_scanning && !local->sw_scanning)) |
Johannes Berg | 5bc7572 | 2008-09-11 00:01:51 +0200 | [diff] [blame] | 216 | return; |
| 217 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 218 | if (WARN_ON(!local->scan_req)) |
| 219 | return; |
Johannes Berg | 5bc7572 | 2008-09-11 00:01:51 +0200 | [diff] [blame] | 220 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 221 | if (local->scan_req != &local->int_scan_req) |
| 222 | cfg80211_scan_done(local->scan_req, aborted); |
| 223 | local->scan_req = NULL; |
| 224 | |
| 225 | local->last_scan_completed = jiffies; |
Johannes Berg | 0a51b27 | 2008-09-08 17:44:25 +0200 | [diff] [blame] | 226 | |
Johannes Berg | c2b1345 | 2008-09-11 00:01:55 +0200 | [diff] [blame] | 227 | if (local->hw_scanning) { |
| 228 | local->hw_scanning = false; |
Johannes Berg | e897558 | 2008-10-09 12:18:51 +0200 | [diff] [blame] | 229 | /* |
| 230 | * Somebody might have requested channel change during scan |
| 231 | * that we won't have acted upon, try now. ieee80211_hw_config |
| 232 | * will set the flag based on actual changes. |
| 233 | */ |
| 234 | ieee80211_hw_config(local, 0); |
Johannes Berg | 0a51b27 | 2008-09-08 17:44:25 +0200 | [diff] [blame] | 235 | goto done; |
| 236 | } |
| 237 | |
Johannes Berg | c2b1345 | 2008-09-11 00:01:55 +0200 | [diff] [blame] | 238 | local->sw_scanning = false; |
Johannes Berg | e897558 | 2008-10-09 12:18:51 +0200 | [diff] [blame] | 239 | ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_CHANNEL); |
Johannes Berg | 0a51b27 | 2008-09-08 17:44:25 +0200 | [diff] [blame] | 240 | |
| 241 | netif_tx_lock_bh(local->mdev); |
| 242 | netif_addr_lock(local->mdev); |
| 243 | local->filter_flags &= ~FIF_BCN_PRBRESP_PROMISC; |
| 244 | local->ops->configure_filter(local_to_hw(local), |
| 245 | FIF_BCN_PRBRESP_PROMISC, |
| 246 | &local->filter_flags, |
| 247 | local->mdev->mc_count, |
| 248 | local->mdev->mc_list); |
| 249 | |
| 250 | netif_addr_unlock(local->mdev); |
| 251 | netif_tx_unlock_bh(local->mdev); |
| 252 | |
Johannes Berg | 078e1e6 | 2009-01-22 18:07:31 +0100 | [diff] [blame] | 253 | mutex_lock(&local->iflist_mtx); |
| 254 | list_for_each_entry(sdata, &local->interfaces, list) { |
Johannes Berg | fb9ddbf | 2009-01-26 19:11:57 +0100 | [diff] [blame] | 255 | if (!netif_running(sdata->dev)) |
| 256 | continue; |
| 257 | |
Johannes Berg | 0a51b27 | 2008-09-08 17:44:25 +0200 | [diff] [blame] | 258 | /* Tell AP we're back */ |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 259 | if (sdata->vif.type == NL80211_IFTYPE_STATION) { |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 260 | if (sdata->u.mgd.flags & IEEE80211_STA_ASSOCIATED) { |
Johannes Berg | 0a51b27 | 2008-09-08 17:44:25 +0200 | [diff] [blame] | 261 | ieee80211_send_nullfunc(local, sdata, 0); |
| 262 | netif_tx_wake_all_queues(sdata->dev); |
| 263 | } |
| 264 | } else |
| 265 | netif_tx_wake_all_queues(sdata->dev); |
Johannes Berg | 078e1e6 | 2009-01-22 18:07:31 +0100 | [diff] [blame] | 266 | |
Johannes Berg | 14b8072 | 2009-02-10 21:25:42 +0100 | [diff] [blame] | 267 | /* re-enable beaconing */ |
| 268 | if (sdata->vif.type == NL80211_IFTYPE_AP || |
| 269 | sdata->vif.type == NL80211_IFTYPE_ADHOC || |
| 270 | sdata->vif.type == NL80211_IFTYPE_MESH_POINT) |
| 271 | ieee80211_if_config(sdata, |
| 272 | IEEE80211_IFCC_BEACON_ENABLED); |
Johannes Berg | 0a51b27 | 2008-09-08 17:44:25 +0200 | [diff] [blame] | 273 | } |
Johannes Berg | 078e1e6 | 2009-01-22 18:07:31 +0100 | [diff] [blame] | 274 | mutex_unlock(&local->iflist_mtx); |
Johannes Berg | 0a51b27 | 2008-09-08 17:44:25 +0200 | [diff] [blame] | 275 | |
| 276 | done: |
| 277 | ieee80211_mlme_notify_scan_completed(local); |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 278 | ieee80211_ibss_notify_scan_completed(local); |
Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 279 | ieee80211_mesh_notify_scan_completed(local); |
Johannes Berg | 0a51b27 | 2008-09-08 17:44:25 +0200 | [diff] [blame] | 280 | } |
| 281 | EXPORT_SYMBOL(ieee80211_scan_completed); |
| 282 | |
Johannes Berg | c2b1345 | 2008-09-11 00:01:55 +0200 | [diff] [blame] | 283 | void ieee80211_scan_work(struct work_struct *work) |
Johannes Berg | 0a51b27 | 2008-09-08 17:44:25 +0200 | [diff] [blame] | 284 | { |
| 285 | struct ieee80211_local *local = |
| 286 | container_of(work, struct ieee80211_local, scan_work.work); |
| 287 | struct ieee80211_sub_if_data *sdata = local->scan_sdata; |
Johannes Berg | 0a51b27 | 2008-09-08 17:44:25 +0200 | [diff] [blame] | 288 | struct ieee80211_channel *chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 289 | int skip, i; |
Johannes Berg | 0a51b27 | 2008-09-08 17:44:25 +0200 | [diff] [blame] | 290 | unsigned long next_delay = 0; |
| 291 | |
Johannes Berg | 5bc7572 | 2008-09-11 00:01:51 +0200 | [diff] [blame] | 292 | /* |
| 293 | * Avoid re-scheduling when the sdata is going away. |
| 294 | */ |
| 295 | if (!netif_running(sdata->dev)) |
Johannes Berg | 0a51b27 | 2008-09-08 17:44:25 +0200 | [diff] [blame] | 296 | return; |
| 297 | |
| 298 | switch (local->scan_state) { |
| 299 | case SCAN_SET_CHANNEL: |
Johannes Berg | 0a51b27 | 2008-09-08 17:44:25 +0200 | [diff] [blame] | 300 | /* if no more bands/channels left, complete scan */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 301 | if (local->scan_channel_idx >= local->scan_req->n_channels) { |
| 302 | ieee80211_scan_completed(local_to_hw(local), false); |
Johannes Berg | 0a51b27 | 2008-09-08 17:44:25 +0200 | [diff] [blame] | 303 | return; |
| 304 | } |
| 305 | skip = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 306 | chan = local->scan_req->channels[local->scan_channel_idx]; |
Johannes Berg | 0a51b27 | 2008-09-08 17:44:25 +0200 | [diff] [blame] | 307 | |
| 308 | if (chan->flags & IEEE80211_CHAN_DISABLED || |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 309 | (sdata->vif.type == NL80211_IFTYPE_ADHOC && |
Johannes Berg | 0a51b27 | 2008-09-08 17:44:25 +0200 | [diff] [blame] | 310 | chan->flags & IEEE80211_CHAN_NO_IBSS)) |
| 311 | skip = 1; |
| 312 | |
| 313 | if (!skip) { |
| 314 | local->scan_channel = chan; |
Johannes Berg | e897558 | 2008-10-09 12:18:51 +0200 | [diff] [blame] | 315 | if (ieee80211_hw_config(local, |
| 316 | IEEE80211_CONF_CHANGE_CHANNEL)) |
Johannes Berg | 0a51b27 | 2008-09-08 17:44:25 +0200 | [diff] [blame] | 317 | skip = 1; |
Johannes Berg | 0a51b27 | 2008-09-08 17:44:25 +0200 | [diff] [blame] | 318 | } |
| 319 | |
| 320 | /* advance state machine to next channel/band */ |
| 321 | local->scan_channel_idx++; |
Johannes Berg | 0a51b27 | 2008-09-08 17:44:25 +0200 | [diff] [blame] | 322 | |
| 323 | if (skip) |
| 324 | break; |
| 325 | |
| 326 | next_delay = IEEE80211_PROBE_DELAY + |
| 327 | usecs_to_jiffies(local->hw.channel_change_time); |
| 328 | local->scan_state = SCAN_SEND_PROBE; |
| 329 | break; |
| 330 | case SCAN_SEND_PROBE: |
| 331 | next_delay = IEEE80211_PASSIVE_CHANNEL_TIME; |
| 332 | local->scan_state = SCAN_SET_CHANNEL; |
| 333 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 334 | if (local->scan_channel->flags & IEEE80211_CHAN_PASSIVE_SCAN || |
| 335 | !local->scan_req->n_ssids) |
Johannes Berg | 0a51b27 | 2008-09-08 17:44:25 +0200 | [diff] [blame] | 336 | break; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 337 | for (i = 0; i < local->scan_req->n_ssids; i++) |
| 338 | ieee80211_send_probe_req( |
| 339 | sdata, NULL, |
| 340 | local->scan_req->ssids[i].ssid, |
Jouni Malinen | 70692ad | 2009-02-16 19:39:13 +0200 | [diff] [blame^] | 341 | local->scan_req->ssids[i].ssid_len, |
| 342 | local->scan_req->ie, local->scan_req->ie_len); |
Johannes Berg | 0a51b27 | 2008-09-08 17:44:25 +0200 | [diff] [blame] | 343 | next_delay = IEEE80211_CHANNEL_TIME; |
| 344 | break; |
| 345 | } |
| 346 | |
Johannes Berg | 5bc7572 | 2008-09-11 00:01:51 +0200 | [diff] [blame] | 347 | queue_delayed_work(local->hw.workqueue, &local->scan_work, |
| 348 | next_delay); |
Johannes Berg | 0a51b27 | 2008-09-08 17:44:25 +0200 | [diff] [blame] | 349 | } |
| 350 | |
| 351 | |
Johannes Berg | c2b1345 | 2008-09-11 00:01:55 +0200 | [diff] [blame] | 352 | int ieee80211_start_scan(struct ieee80211_sub_if_data *scan_sdata, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 353 | struct cfg80211_scan_request *req) |
Johannes Berg | 0a51b27 | 2008-09-08 17:44:25 +0200 | [diff] [blame] | 354 | { |
| 355 | struct ieee80211_local *local = scan_sdata->local; |
| 356 | struct ieee80211_sub_if_data *sdata; |
| 357 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 358 | if (!req) |
Johannes Berg | 0a51b27 | 2008-09-08 17:44:25 +0200 | [diff] [blame] | 359 | return -EINVAL; |
| 360 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 361 | if (local->scan_req && local->scan_req != req) |
| 362 | return -EBUSY; |
| 363 | |
| 364 | local->scan_req = req; |
| 365 | |
Johannes Berg | 0a51b27 | 2008-09-08 17:44:25 +0200 | [diff] [blame] | 366 | /* MLME-SCAN.request (page 118) page 144 (11.1.3.1) |
| 367 | * BSSType: INFRASTRUCTURE, INDEPENDENT, ANY_BSS |
| 368 | * BSSID: MACAddress |
| 369 | * SSID |
| 370 | * ScanType: ACTIVE, PASSIVE |
| 371 | * ProbeDelay: delay (in microseconds) to be used prior to transmitting |
| 372 | * a Probe frame during active scanning |
| 373 | * ChannelList |
| 374 | * MinChannelTime (>= ProbeDelay), in TU |
| 375 | * MaxChannelTime: (>= MinChannelTime), in TU |
| 376 | */ |
| 377 | |
| 378 | /* MLME-SCAN.confirm |
| 379 | * BSSDescriptionSet |
| 380 | * ResultCode: SUCCESS, INVALID_PARAMETERS |
| 381 | */ |
| 382 | |
Johannes Berg | c2b1345 | 2008-09-11 00:01:55 +0200 | [diff] [blame] | 383 | if (local->sw_scanning || local->hw_scanning) { |
Johannes Berg | 0a51b27 | 2008-09-08 17:44:25 +0200 | [diff] [blame] | 384 | if (local->scan_sdata == scan_sdata) |
| 385 | return 0; |
| 386 | return -EBUSY; |
| 387 | } |
| 388 | |
| 389 | if (local->ops->hw_scan) { |
Johannes Berg | 5bc7572 | 2008-09-11 00:01:51 +0200 | [diff] [blame] | 390 | int rc; |
| 391 | |
Johannes Berg | c2b1345 | 2008-09-11 00:01:55 +0200 | [diff] [blame] | 392 | local->hw_scanning = true; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 393 | rc = local->ops->hw_scan(local_to_hw(local), req); |
Johannes Berg | 5bc7572 | 2008-09-11 00:01:51 +0200 | [diff] [blame] | 394 | if (rc) { |
Johannes Berg | c2b1345 | 2008-09-11 00:01:55 +0200 | [diff] [blame] | 395 | local->hw_scanning = false; |
Johannes Berg | 5bc7572 | 2008-09-11 00:01:51 +0200 | [diff] [blame] | 396 | return rc; |
Johannes Berg | 0a51b27 | 2008-09-08 17:44:25 +0200 | [diff] [blame] | 397 | } |
Johannes Berg | 5bc7572 | 2008-09-11 00:01:51 +0200 | [diff] [blame] | 398 | local->scan_sdata = scan_sdata; |
| 399 | return 0; |
Johannes Berg | 0a51b27 | 2008-09-08 17:44:25 +0200 | [diff] [blame] | 400 | } |
| 401 | |
Johannes Berg | c2b1345 | 2008-09-11 00:01:55 +0200 | [diff] [blame] | 402 | local->sw_scanning = true; |
Johannes Berg | 0a51b27 | 2008-09-08 17:44:25 +0200 | [diff] [blame] | 403 | |
Johannes Berg | 078e1e6 | 2009-01-22 18:07:31 +0100 | [diff] [blame] | 404 | mutex_lock(&local->iflist_mtx); |
| 405 | list_for_each_entry(sdata, &local->interfaces, list) { |
Johannes Berg | fb9ddbf | 2009-01-26 19:11:57 +0100 | [diff] [blame] | 406 | if (!netif_running(sdata->dev)) |
| 407 | continue; |
| 408 | |
Johannes Berg | 14b8072 | 2009-02-10 21:25:42 +0100 | [diff] [blame] | 409 | /* disable beaconing */ |
| 410 | if (sdata->vif.type == NL80211_IFTYPE_AP || |
| 411 | sdata->vif.type == NL80211_IFTYPE_ADHOC || |
| 412 | sdata->vif.type == NL80211_IFTYPE_MESH_POINT) |
| 413 | ieee80211_if_config(sdata, |
| 414 | IEEE80211_IFCC_BEACON_ENABLED); |
Johannes Berg | 078e1e6 | 2009-01-22 18:07:31 +0100 | [diff] [blame] | 415 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 416 | if (sdata->vif.type == NL80211_IFTYPE_STATION) { |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 417 | if (sdata->u.mgd.flags & IEEE80211_STA_ASSOCIATED) { |
Johannes Berg | 0a51b27 | 2008-09-08 17:44:25 +0200 | [diff] [blame] | 418 | netif_tx_stop_all_queues(sdata->dev); |
| 419 | ieee80211_send_nullfunc(local, sdata, 1); |
| 420 | } |
| 421 | } else |
| 422 | netif_tx_stop_all_queues(sdata->dev); |
| 423 | } |
Johannes Berg | 078e1e6 | 2009-01-22 18:07:31 +0100 | [diff] [blame] | 424 | mutex_unlock(&local->iflist_mtx); |
Johannes Berg | 0a51b27 | 2008-09-08 17:44:25 +0200 | [diff] [blame] | 425 | |
Johannes Berg | 0a51b27 | 2008-09-08 17:44:25 +0200 | [diff] [blame] | 426 | local->scan_state = SCAN_SET_CHANNEL; |
| 427 | local->scan_channel_idx = 0; |
Johannes Berg | 0a51b27 | 2008-09-08 17:44:25 +0200 | [diff] [blame] | 428 | local->scan_sdata = scan_sdata; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 429 | local->scan_req = req; |
Johannes Berg | 0a51b27 | 2008-09-08 17:44:25 +0200 | [diff] [blame] | 430 | |
| 431 | netif_addr_lock_bh(local->mdev); |
| 432 | local->filter_flags |= FIF_BCN_PRBRESP_PROMISC; |
| 433 | local->ops->configure_filter(local_to_hw(local), |
| 434 | FIF_BCN_PRBRESP_PROMISC, |
| 435 | &local->filter_flags, |
| 436 | local->mdev->mc_count, |
| 437 | local->mdev->mc_list); |
| 438 | netif_addr_unlock_bh(local->mdev); |
| 439 | |
| 440 | /* TODO: start scan as soon as all nullfunc frames are ACKed */ |
| 441 | queue_delayed_work(local->hw.workqueue, &local->scan_work, |
| 442 | IEEE80211_CHANNEL_TIME); |
| 443 | |
| 444 | return 0; |
| 445 | } |
| 446 | |
| 447 | |
Johannes Berg | c2b1345 | 2008-09-11 00:01:55 +0200 | [diff] [blame] | 448 | int ieee80211_request_scan(struct ieee80211_sub_if_data *sdata, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 449 | struct cfg80211_scan_request *req) |
Johannes Berg | 0a51b27 | 2008-09-08 17:44:25 +0200 | [diff] [blame] | 450 | { |
Johannes Berg | 0a51b27 | 2008-09-08 17:44:25 +0200 | [diff] [blame] | 451 | struct ieee80211_local *local = sdata->local; |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 452 | struct ieee80211_if_managed *ifmgd; |
Johannes Berg | 0a51b27 | 2008-09-08 17:44:25 +0200 | [diff] [blame] | 453 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 454 | if (!req) |
| 455 | return -EINVAL; |
| 456 | |
| 457 | if (local->scan_req && local->scan_req != req) |
| 458 | return -EBUSY; |
| 459 | |
| 460 | local->scan_req = req; |
| 461 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 462 | if (sdata->vif.type != NL80211_IFTYPE_STATION) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame] | 463 | return ieee80211_start_scan(sdata, req); |
Johannes Berg | 0a51b27 | 2008-09-08 17:44:25 +0200 | [diff] [blame] | 464 | |
Johannes Berg | 9116dd0 | 2008-09-08 17:47:23 +0200 | [diff] [blame] | 465 | /* |
| 466 | * STA has a state machine that might need to defer scanning |
| 467 | * while it's trying to associate/authenticate, therefore we |
| 468 | * queue it up to the state machine in that case. |
| 469 | */ |
| 470 | |
Johannes Berg | c2b1345 | 2008-09-11 00:01:55 +0200 | [diff] [blame] | 471 | if (local->sw_scanning || local->hw_scanning) { |
Johannes Berg | 0a51b27 | 2008-09-08 17:44:25 +0200 | [diff] [blame] | 472 | if (local->scan_sdata == sdata) |
| 473 | return 0; |
| 474 | return -EBUSY; |
| 475 | } |
| 476 | |
Johannes Berg | 4690029 | 2009-02-15 12:44:28 +0100 | [diff] [blame] | 477 | ifmgd = &sdata->u.mgd; |
| 478 | set_bit(IEEE80211_STA_REQ_SCAN, &ifmgd->request); |
| 479 | queue_work(local->hw.workqueue, &ifmgd->work); |
Johannes Berg | 9116dd0 | 2008-09-08 17:47:23 +0200 | [diff] [blame] | 480 | |
Johannes Berg | 0a51b27 | 2008-09-08 17:44:25 +0200 | [diff] [blame] | 481 | return 0; |
| 482 | } |