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 | 5484e23 | 2008-09-08 17:44:27 +0200 | [diff] [blame] | 15 | /* TODO: |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame^] | 16 | * figure out how to avoid that the "current BSS" expires |
| 17 | * clean up IBSS code (in MLME), see why it adds a BSS to the list |
| 18 | * use cfg80211's BSS handling (depends on IBSS TODO above) |
Johannes Berg | 5484e23 | 2008-09-08 17:44:27 +0200 | [diff] [blame] | 19 | * order BSS list by RSSI(?) ("quality of AP") |
| 20 | * scan result table filtering (by capability (privacy, IBSS/BSS, WPA/RSN IE, |
| 21 | * SSID) |
| 22 | */ |
| 23 | |
Johannes Berg | 0a51b27 | 2008-09-08 17:44:25 +0200 | [diff] [blame] | 24 | #include <linux/wireless.h> |
| 25 | #include <linux/if_arp.h> |
Johannes Berg | 078e1e6 | 2009-01-22 18:07:31 +0100 | [diff] [blame] | 26 | #include <linux/rtnetlink.h> |
Johannes Berg | 0a51b27 | 2008-09-08 17:44:25 +0200 | [diff] [blame] | 27 | #include <net/mac80211.h> |
| 28 | #include <net/iw_handler.h> |
| 29 | |
| 30 | #include "ieee80211_i.h" |
Johannes Berg | 5484e23 | 2008-09-08 17:44:27 +0200 | [diff] [blame] | 31 | #include "mesh.h" |
Johannes Berg | 0a51b27 | 2008-09-08 17:44:25 +0200 | [diff] [blame] | 32 | |
| 33 | #define IEEE80211_PROBE_DELAY (HZ / 33) |
| 34 | #define IEEE80211_CHANNEL_TIME (HZ / 33) |
| 35 | #define IEEE80211_PASSIVE_CHANNEL_TIME (HZ / 5) |
| 36 | |
Johannes Berg | 5484e23 | 2008-09-08 17:44:27 +0200 | [diff] [blame] | 37 | void ieee80211_rx_bss_list_init(struct ieee80211_local *local) |
| 38 | { |
Johannes Berg | c2b1345 | 2008-09-11 00:01:55 +0200 | [diff] [blame] | 39 | spin_lock_init(&local->bss_lock); |
| 40 | INIT_LIST_HEAD(&local->bss_list); |
Johannes Berg | 5484e23 | 2008-09-08 17:44:27 +0200 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | void ieee80211_rx_bss_list_deinit(struct ieee80211_local *local) |
| 44 | { |
Johannes Berg | c2b1345 | 2008-09-11 00:01:55 +0200 | [diff] [blame] | 45 | struct ieee80211_bss *bss, *tmp; |
Johannes Berg | 5484e23 | 2008-09-08 17:44:27 +0200 | [diff] [blame] | 46 | |
Johannes Berg | c2b1345 | 2008-09-11 00:01:55 +0200 | [diff] [blame] | 47 | list_for_each_entry_safe(bss, tmp, &local->bss_list, list) |
Johannes Berg | 5484e23 | 2008-09-08 17:44:27 +0200 | [diff] [blame] | 48 | ieee80211_rx_bss_put(local, bss); |
| 49 | } |
| 50 | |
Johannes Berg | c2b1345 | 2008-09-11 00:01:55 +0200 | [diff] [blame] | 51 | struct ieee80211_bss * |
Johannes Berg | 5484e23 | 2008-09-08 17:44:27 +0200 | [diff] [blame] | 52 | ieee80211_rx_bss_get(struct ieee80211_local *local, u8 *bssid, int freq, |
| 53 | u8 *ssid, u8 ssid_len) |
| 54 | { |
Johannes Berg | c2b1345 | 2008-09-11 00:01:55 +0200 | [diff] [blame] | 55 | struct ieee80211_bss *bss; |
Johannes Berg | 5484e23 | 2008-09-08 17:44:27 +0200 | [diff] [blame] | 56 | |
Johannes Berg | c2b1345 | 2008-09-11 00:01:55 +0200 | [diff] [blame] | 57 | spin_lock_bh(&local->bss_lock); |
| 58 | bss = local->bss_hash[STA_HASH(bssid)]; |
Johannes Berg | 5484e23 | 2008-09-08 17:44:27 +0200 | [diff] [blame] | 59 | while (bss) { |
| 60 | if (!bss_mesh_cfg(bss) && |
| 61 | !memcmp(bss->bssid, bssid, ETH_ALEN) && |
| 62 | bss->freq == freq && |
| 63 | bss->ssid_len == ssid_len && |
| 64 | (ssid_len == 0 || !memcmp(bss->ssid, ssid, ssid_len))) { |
| 65 | atomic_inc(&bss->users); |
| 66 | break; |
| 67 | } |
| 68 | bss = bss->hnext; |
| 69 | } |
Johannes Berg | c2b1345 | 2008-09-11 00:01:55 +0200 | [diff] [blame] | 70 | spin_unlock_bh(&local->bss_lock); |
Johannes Berg | 5484e23 | 2008-09-08 17:44:27 +0200 | [diff] [blame] | 71 | return bss; |
| 72 | } |
| 73 | |
Johannes Berg | c2b1345 | 2008-09-11 00:01:55 +0200 | [diff] [blame] | 74 | /* Caller must hold local->bss_lock */ |
Johannes Berg | 5484e23 | 2008-09-08 17:44:27 +0200 | [diff] [blame] | 75 | static void __ieee80211_rx_bss_hash_add(struct ieee80211_local *local, |
Johannes Berg | c2b1345 | 2008-09-11 00:01:55 +0200 | [diff] [blame] | 76 | struct ieee80211_bss *bss) |
Johannes Berg | 5484e23 | 2008-09-08 17:44:27 +0200 | [diff] [blame] | 77 | { |
| 78 | u8 hash_idx; |
| 79 | |
| 80 | if (bss_mesh_cfg(bss)) |
| 81 | hash_idx = mesh_id_hash(bss_mesh_id(bss), |
| 82 | bss_mesh_id_len(bss)); |
| 83 | else |
| 84 | hash_idx = STA_HASH(bss->bssid); |
| 85 | |
Johannes Berg | c2b1345 | 2008-09-11 00:01:55 +0200 | [diff] [blame] | 86 | bss->hnext = local->bss_hash[hash_idx]; |
| 87 | local->bss_hash[hash_idx] = bss; |
Johannes Berg | 5484e23 | 2008-09-08 17:44:27 +0200 | [diff] [blame] | 88 | } |
| 89 | |
Johannes Berg | c2b1345 | 2008-09-11 00:01:55 +0200 | [diff] [blame] | 90 | /* Caller must hold local->bss_lock */ |
Johannes Berg | 5484e23 | 2008-09-08 17:44:27 +0200 | [diff] [blame] | 91 | static void __ieee80211_rx_bss_hash_del(struct ieee80211_local *local, |
Johannes Berg | c2b1345 | 2008-09-11 00:01:55 +0200 | [diff] [blame] | 92 | struct ieee80211_bss *bss) |
Johannes Berg | 5484e23 | 2008-09-08 17:44:27 +0200 | [diff] [blame] | 93 | { |
Johannes Berg | c2b1345 | 2008-09-11 00:01:55 +0200 | [diff] [blame] | 94 | struct ieee80211_bss *b, *prev = NULL; |
| 95 | b = local->bss_hash[STA_HASH(bss->bssid)]; |
Johannes Berg | 5484e23 | 2008-09-08 17:44:27 +0200 | [diff] [blame] | 96 | while (b) { |
| 97 | if (b == bss) { |
| 98 | if (!prev) |
Johannes Berg | c2b1345 | 2008-09-11 00:01:55 +0200 | [diff] [blame] | 99 | local->bss_hash[STA_HASH(bss->bssid)] = |
Johannes Berg | 5484e23 | 2008-09-08 17:44:27 +0200 | [diff] [blame] | 100 | bss->hnext; |
| 101 | else |
| 102 | prev->hnext = bss->hnext; |
| 103 | break; |
| 104 | } |
| 105 | prev = b; |
| 106 | b = b->hnext; |
| 107 | } |
| 108 | } |
| 109 | |
Johannes Berg | c2b1345 | 2008-09-11 00:01:55 +0200 | [diff] [blame] | 110 | struct ieee80211_bss * |
Johannes Berg | 5484e23 | 2008-09-08 17:44:27 +0200 | [diff] [blame] | 111 | ieee80211_rx_bss_add(struct ieee80211_local *local, u8 *bssid, int freq, |
| 112 | u8 *ssid, u8 ssid_len) |
| 113 | { |
Johannes Berg | c2b1345 | 2008-09-11 00:01:55 +0200 | [diff] [blame] | 114 | struct ieee80211_bss *bss; |
Johannes Berg | 5484e23 | 2008-09-08 17:44:27 +0200 | [diff] [blame] | 115 | |
| 116 | bss = kzalloc(sizeof(*bss), GFP_ATOMIC); |
| 117 | if (!bss) |
| 118 | return NULL; |
| 119 | atomic_set(&bss->users, 2); |
| 120 | memcpy(bss->bssid, bssid, ETH_ALEN); |
| 121 | bss->freq = freq; |
| 122 | if (ssid && ssid_len <= IEEE80211_MAX_SSID_LEN) { |
| 123 | memcpy(bss->ssid, ssid, ssid_len); |
| 124 | bss->ssid_len = ssid_len; |
| 125 | } |
| 126 | |
Johannes Berg | c2b1345 | 2008-09-11 00:01:55 +0200 | [diff] [blame] | 127 | spin_lock_bh(&local->bss_lock); |
Johannes Berg | 5484e23 | 2008-09-08 17:44:27 +0200 | [diff] [blame] | 128 | /* TODO: order by RSSI? */ |
Johannes Berg | c2b1345 | 2008-09-11 00:01:55 +0200 | [diff] [blame] | 129 | list_add_tail(&bss->list, &local->bss_list); |
Johannes Berg | 5484e23 | 2008-09-08 17:44:27 +0200 | [diff] [blame] | 130 | __ieee80211_rx_bss_hash_add(local, bss); |
Johannes Berg | c2b1345 | 2008-09-11 00:01:55 +0200 | [diff] [blame] | 131 | spin_unlock_bh(&local->bss_lock); |
Johannes Berg | 5484e23 | 2008-09-08 17:44:27 +0200 | [diff] [blame] | 132 | return bss; |
| 133 | } |
| 134 | |
| 135 | #ifdef CONFIG_MAC80211_MESH |
Johannes Berg | c2b1345 | 2008-09-11 00:01:55 +0200 | [diff] [blame] | 136 | static struct ieee80211_bss * |
Johannes Berg | 5484e23 | 2008-09-08 17:44:27 +0200 | [diff] [blame] | 137 | ieee80211_rx_mesh_bss_get(struct ieee80211_local *local, u8 *mesh_id, int mesh_id_len, |
| 138 | u8 *mesh_cfg, int freq) |
| 139 | { |
Johannes Berg | c2b1345 | 2008-09-11 00:01:55 +0200 | [diff] [blame] | 140 | struct ieee80211_bss *bss; |
Johannes Berg | 5484e23 | 2008-09-08 17:44:27 +0200 | [diff] [blame] | 141 | |
Johannes Berg | c2b1345 | 2008-09-11 00:01:55 +0200 | [diff] [blame] | 142 | spin_lock_bh(&local->bss_lock); |
| 143 | bss = local->bss_hash[mesh_id_hash(mesh_id, mesh_id_len)]; |
Johannes Berg | 5484e23 | 2008-09-08 17:44:27 +0200 | [diff] [blame] | 144 | while (bss) { |
| 145 | if (bss_mesh_cfg(bss) && |
| 146 | !memcmp(bss_mesh_cfg(bss), mesh_cfg, MESH_CFG_CMP_LEN) && |
| 147 | bss->freq == freq && |
| 148 | mesh_id_len == bss->mesh_id_len && |
| 149 | (mesh_id_len == 0 || !memcmp(bss->mesh_id, mesh_id, |
| 150 | mesh_id_len))) { |
| 151 | atomic_inc(&bss->users); |
| 152 | break; |
| 153 | } |
| 154 | bss = bss->hnext; |
| 155 | } |
Johannes Berg | c2b1345 | 2008-09-11 00:01:55 +0200 | [diff] [blame] | 156 | spin_unlock_bh(&local->bss_lock); |
Johannes Berg | 5484e23 | 2008-09-08 17:44:27 +0200 | [diff] [blame] | 157 | return bss; |
| 158 | } |
| 159 | |
Johannes Berg | c2b1345 | 2008-09-11 00:01:55 +0200 | [diff] [blame] | 160 | static struct ieee80211_bss * |
Johannes Berg | 5484e23 | 2008-09-08 17:44:27 +0200 | [diff] [blame] | 161 | ieee80211_rx_mesh_bss_add(struct ieee80211_local *local, u8 *mesh_id, int mesh_id_len, |
| 162 | u8 *mesh_cfg, int mesh_config_len, int freq) |
| 163 | { |
Johannes Berg | c2b1345 | 2008-09-11 00:01:55 +0200 | [diff] [blame] | 164 | struct ieee80211_bss *bss; |
Johannes Berg | 5484e23 | 2008-09-08 17:44:27 +0200 | [diff] [blame] | 165 | |
Johannes Berg | 1239cd5 | 2008-10-28 11:12:57 +0100 | [diff] [blame] | 166 | if (mesh_config_len != IEEE80211_MESH_CONFIG_LEN) |
Johannes Berg | 5484e23 | 2008-09-08 17:44:27 +0200 | [diff] [blame] | 167 | return NULL; |
| 168 | |
| 169 | bss = kzalloc(sizeof(*bss), GFP_ATOMIC); |
| 170 | if (!bss) |
| 171 | return NULL; |
| 172 | |
| 173 | bss->mesh_cfg = kmalloc(MESH_CFG_CMP_LEN, GFP_ATOMIC); |
| 174 | if (!bss->mesh_cfg) { |
| 175 | kfree(bss); |
| 176 | return NULL; |
| 177 | } |
| 178 | |
| 179 | if (mesh_id_len && mesh_id_len <= IEEE80211_MAX_MESH_ID_LEN) { |
| 180 | bss->mesh_id = kmalloc(mesh_id_len, GFP_ATOMIC); |
| 181 | if (!bss->mesh_id) { |
| 182 | kfree(bss->mesh_cfg); |
| 183 | kfree(bss); |
| 184 | return NULL; |
| 185 | } |
| 186 | memcpy(bss->mesh_id, mesh_id, mesh_id_len); |
| 187 | } |
| 188 | |
| 189 | atomic_set(&bss->users, 2); |
| 190 | memcpy(bss->mesh_cfg, mesh_cfg, MESH_CFG_CMP_LEN); |
| 191 | bss->mesh_id_len = mesh_id_len; |
| 192 | bss->freq = freq; |
Johannes Berg | c2b1345 | 2008-09-11 00:01:55 +0200 | [diff] [blame] | 193 | spin_lock_bh(&local->bss_lock); |
Johannes Berg | 5484e23 | 2008-09-08 17:44:27 +0200 | [diff] [blame] | 194 | /* TODO: order by RSSI? */ |
Johannes Berg | c2b1345 | 2008-09-11 00:01:55 +0200 | [diff] [blame] | 195 | list_add_tail(&bss->list, &local->bss_list); |
Johannes Berg | 5484e23 | 2008-09-08 17:44:27 +0200 | [diff] [blame] | 196 | __ieee80211_rx_bss_hash_add(local, bss); |
Johannes Berg | c2b1345 | 2008-09-11 00:01:55 +0200 | [diff] [blame] | 197 | spin_unlock_bh(&local->bss_lock); |
Johannes Berg | 5484e23 | 2008-09-08 17:44:27 +0200 | [diff] [blame] | 198 | return bss; |
| 199 | } |
| 200 | #endif |
| 201 | |
Johannes Berg | c2b1345 | 2008-09-11 00:01:55 +0200 | [diff] [blame] | 202 | static void ieee80211_rx_bss_free(struct ieee80211_bss *bss) |
Johannes Berg | 5484e23 | 2008-09-08 17:44:27 +0200 | [diff] [blame] | 203 | { |
| 204 | kfree(bss->ies); |
| 205 | kfree(bss_mesh_id(bss)); |
| 206 | kfree(bss_mesh_cfg(bss)); |
| 207 | kfree(bss); |
| 208 | } |
| 209 | |
| 210 | void ieee80211_rx_bss_put(struct ieee80211_local *local, |
Johannes Berg | c2b1345 | 2008-09-11 00:01:55 +0200 | [diff] [blame] | 211 | struct ieee80211_bss *bss) |
Johannes Berg | 5484e23 | 2008-09-08 17:44:27 +0200 | [diff] [blame] | 212 | { |
| 213 | local_bh_disable(); |
Johannes Berg | c2b1345 | 2008-09-11 00:01:55 +0200 | [diff] [blame] | 214 | if (!atomic_dec_and_lock(&bss->users, &local->bss_lock)) { |
Johannes Berg | 5484e23 | 2008-09-08 17:44:27 +0200 | [diff] [blame] | 215 | local_bh_enable(); |
| 216 | return; |
| 217 | } |
| 218 | |
| 219 | __ieee80211_rx_bss_hash_del(local, bss); |
| 220 | list_del(&bss->list); |
Johannes Berg | c2b1345 | 2008-09-11 00:01:55 +0200 | [diff] [blame] | 221 | spin_unlock_bh(&local->bss_lock); |
Johannes Berg | 5484e23 | 2008-09-08 17:44:27 +0200 | [diff] [blame] | 222 | ieee80211_rx_bss_free(bss); |
| 223 | } |
| 224 | |
Johannes Berg | c2b1345 | 2008-09-11 00:01:55 +0200 | [diff] [blame] | 225 | struct ieee80211_bss * |
Johannes Berg | 5484e23 | 2008-09-08 17:44:27 +0200 | [diff] [blame] | 226 | ieee80211_bss_info_update(struct ieee80211_local *local, |
| 227 | struct ieee80211_rx_status *rx_status, |
| 228 | struct ieee80211_mgmt *mgmt, |
| 229 | size_t len, |
| 230 | struct ieee802_11_elems *elems, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame^] | 231 | struct ieee80211_channel *channel, |
| 232 | bool beacon) |
Johannes Berg | 5484e23 | 2008-09-08 17:44:27 +0200 | [diff] [blame] | 233 | { |
Johannes Berg | c2b1345 | 2008-09-11 00:01:55 +0200 | [diff] [blame] | 234 | struct ieee80211_bss *bss; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame^] | 235 | int clen, freq = channel->center_freq; |
| 236 | enum cfg80211_signal_type sigtype = CFG80211_SIGNAL_TYPE_NONE; |
| 237 | s32 signal = 0; |
| 238 | |
| 239 | if (local->hw.flags & IEEE80211_HW_SIGNAL_DBM) { |
| 240 | sigtype = CFG80211_SIGNAL_TYPE_MBM; |
| 241 | signal = rx_status->signal * 100; |
| 242 | } else if (local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC) { |
| 243 | sigtype = CFG80211_SIGNAL_TYPE_UNSPEC; |
| 244 | signal = (rx_status->signal * 100) / local->hw.max_signal; |
| 245 | } |
| 246 | |
| 247 | cfg80211_put_bss( |
| 248 | cfg80211_inform_bss_frame(local->hw.wiphy, channel, |
| 249 | mgmt, len, signal, sigtype, |
| 250 | GFP_ATOMIC)); |
Johannes Berg | 5484e23 | 2008-09-08 17:44:27 +0200 | [diff] [blame] | 251 | |
| 252 | #ifdef CONFIG_MAC80211_MESH |
| 253 | if (elems->mesh_config) |
| 254 | bss = ieee80211_rx_mesh_bss_get(local, elems->mesh_id, |
| 255 | elems->mesh_id_len, elems->mesh_config, freq); |
| 256 | else |
| 257 | #endif |
| 258 | bss = ieee80211_rx_bss_get(local, mgmt->bssid, freq, |
| 259 | elems->ssid, elems->ssid_len); |
| 260 | if (!bss) { |
| 261 | #ifdef CONFIG_MAC80211_MESH |
| 262 | if (elems->mesh_config) |
| 263 | bss = ieee80211_rx_mesh_bss_add(local, elems->mesh_id, |
| 264 | elems->mesh_id_len, elems->mesh_config, |
| 265 | elems->mesh_config_len, freq); |
| 266 | else |
| 267 | #endif |
| 268 | bss = ieee80211_rx_bss_add(local, mgmt->bssid, freq, |
| 269 | elems->ssid, elems->ssid_len); |
| 270 | if (!bss) |
| 271 | return NULL; |
| 272 | } else { |
| 273 | #if 0 |
| 274 | /* TODO: order by RSSI? */ |
Johannes Berg | c2b1345 | 2008-09-11 00:01:55 +0200 | [diff] [blame] | 275 | spin_lock_bh(&local->bss_lock); |
| 276 | list_move_tail(&bss->list, &local->bss_list); |
| 277 | spin_unlock_bh(&local->bss_lock); |
Johannes Berg | 5484e23 | 2008-09-08 17:44:27 +0200 | [diff] [blame] | 278 | #endif |
| 279 | } |
| 280 | |
| 281 | /* save the ERP value so that it is available at association time */ |
| 282 | if (elems->erp_info && elems->erp_info_len >= 1) { |
| 283 | bss->erp_value = elems->erp_info[0]; |
| 284 | bss->has_erp_value = 1; |
| 285 | } |
| 286 | |
| 287 | bss->beacon_int = le16_to_cpu(mgmt->u.beacon.beacon_int); |
| 288 | bss->capability = le16_to_cpu(mgmt->u.beacon.capab_info); |
| 289 | |
| 290 | if (elems->tim) { |
| 291 | struct ieee80211_tim_ie *tim_ie = |
| 292 | (struct ieee80211_tim_ie *)elems->tim; |
| 293 | bss->dtim_period = tim_ie->dtim_period; |
| 294 | } |
| 295 | |
| 296 | /* set default value for buggy APs */ |
| 297 | if (!elems->tim || bss->dtim_period == 0) |
| 298 | bss->dtim_period = 1; |
| 299 | |
| 300 | bss->supp_rates_len = 0; |
| 301 | if (elems->supp_rates) { |
| 302 | clen = IEEE80211_MAX_SUPP_RATES - bss->supp_rates_len; |
| 303 | if (clen > elems->supp_rates_len) |
| 304 | clen = elems->supp_rates_len; |
| 305 | memcpy(&bss->supp_rates[bss->supp_rates_len], elems->supp_rates, |
| 306 | clen); |
| 307 | bss->supp_rates_len += clen; |
| 308 | } |
| 309 | if (elems->ext_supp_rates) { |
| 310 | clen = IEEE80211_MAX_SUPP_RATES - bss->supp_rates_len; |
| 311 | if (clen > elems->ext_supp_rates_len) |
| 312 | clen = elems->ext_supp_rates_len; |
| 313 | memcpy(&bss->supp_rates[bss->supp_rates_len], |
| 314 | elems->ext_supp_rates, clen); |
| 315 | bss->supp_rates_len += clen; |
| 316 | } |
| 317 | |
| 318 | bss->band = rx_status->band; |
| 319 | |
| 320 | bss->timestamp = le64_to_cpu(mgmt->u.beacon.timestamp); |
| 321 | bss->last_update = jiffies; |
| 322 | bss->signal = rx_status->signal; |
| 323 | bss->noise = rx_status->noise; |
| 324 | bss->qual = rx_status->qual; |
| 325 | bss->wmm_used = elems->wmm_param || elems->wmm_info; |
| 326 | |
| 327 | if (!beacon) |
| 328 | bss->last_probe_resp = jiffies; |
| 329 | |
| 330 | /* |
| 331 | * For probe responses, or if we don't have any information yet, |
| 332 | * use the IEs from the beacon. |
| 333 | */ |
| 334 | if (!bss->ies || !beacon) { |
| 335 | if (bss->ies == NULL || bss->ies_len < elems->total_len) { |
| 336 | kfree(bss->ies); |
| 337 | bss->ies = kmalloc(elems->total_len, GFP_ATOMIC); |
| 338 | } |
| 339 | if (bss->ies) { |
| 340 | memcpy(bss->ies, elems->ie_start, elems->total_len); |
| 341 | bss->ies_len = elems->total_len; |
| 342 | } else |
| 343 | bss->ies_len = 0; |
| 344 | } |
| 345 | |
| 346 | return bss; |
| 347 | } |
Johannes Berg | 0a51b27 | 2008-09-08 17:44:25 +0200 | [diff] [blame] | 348 | |
Vasanthakumar Thiagarajan | 7a94708 | 2009-02-04 18:28:48 +0530 | [diff] [blame] | 349 | void ieee80211_rx_bss_remove(struct ieee80211_sub_if_data *sdata, u8 *bssid, |
| 350 | int freq, u8 *ssid, u8 ssid_len) |
| 351 | { |
| 352 | struct ieee80211_bss *bss; |
| 353 | struct ieee80211_local *local = sdata->local; |
| 354 | |
| 355 | bss = ieee80211_rx_bss_get(local, bssid, freq, ssid, ssid_len); |
| 356 | if (bss) { |
| 357 | atomic_dec(&bss->users); |
| 358 | ieee80211_rx_bss_put(local, bss); |
| 359 | } |
| 360 | } |
| 361 | |
Johannes Berg | 98c8fcc | 2008-09-08 17:44:26 +0200 | [diff] [blame] | 362 | ieee80211_rx_result |
Johannes Berg | c2b1345 | 2008-09-11 00:01:55 +0200 | [diff] [blame] | 363 | ieee80211_scan_rx(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb, |
| 364 | struct ieee80211_rx_status *rx_status) |
Johannes Berg | 98c8fcc | 2008-09-08 17:44:26 +0200 | [diff] [blame] | 365 | { |
| 366 | struct ieee80211_mgmt *mgmt; |
Johannes Berg | c2b1345 | 2008-09-11 00:01:55 +0200 | [diff] [blame] | 367 | struct ieee80211_bss *bss; |
Johannes Berg | 98c8fcc | 2008-09-08 17:44:26 +0200 | [diff] [blame] | 368 | u8 *elements; |
| 369 | struct ieee80211_channel *channel; |
| 370 | size_t baselen; |
| 371 | int freq; |
| 372 | __le16 fc; |
| 373 | bool presp, beacon = false; |
| 374 | struct ieee802_11_elems elems; |
| 375 | |
| 376 | if (skb->len < 2) |
| 377 | return RX_DROP_UNUSABLE; |
| 378 | |
| 379 | mgmt = (struct ieee80211_mgmt *) skb->data; |
| 380 | fc = mgmt->frame_control; |
| 381 | |
| 382 | if (ieee80211_is_ctl(fc)) |
| 383 | return RX_CONTINUE; |
| 384 | |
| 385 | if (skb->len < 24) |
| 386 | return RX_DROP_MONITOR; |
| 387 | |
| 388 | presp = ieee80211_is_probe_resp(fc); |
| 389 | if (presp) { |
| 390 | /* ignore ProbeResp to foreign address */ |
| 391 | if (memcmp(mgmt->da, sdata->dev->dev_addr, ETH_ALEN)) |
| 392 | return RX_DROP_MONITOR; |
| 393 | |
| 394 | presp = true; |
| 395 | elements = mgmt->u.probe_resp.variable; |
| 396 | baselen = offsetof(struct ieee80211_mgmt, u.probe_resp.variable); |
| 397 | } else { |
| 398 | beacon = ieee80211_is_beacon(fc); |
| 399 | baselen = offsetof(struct ieee80211_mgmt, u.beacon.variable); |
| 400 | elements = mgmt->u.beacon.variable; |
| 401 | } |
| 402 | |
| 403 | if (!presp && !beacon) |
| 404 | return RX_CONTINUE; |
| 405 | |
| 406 | if (baselen > skb->len) |
| 407 | return RX_DROP_MONITOR; |
| 408 | |
| 409 | ieee802_11_parse_elems(elements, skb->len - baselen, &elems); |
| 410 | |
| 411 | if (elems.ds_params && elems.ds_params_len == 1) |
| 412 | freq = ieee80211_channel_to_frequency(elems.ds_params[0]); |
| 413 | else |
| 414 | freq = rx_status->freq; |
| 415 | |
| 416 | channel = ieee80211_get_channel(sdata->local->hw.wiphy, freq); |
| 417 | |
| 418 | if (!channel || channel->flags & IEEE80211_CHAN_DISABLED) |
| 419 | return RX_DROP_MONITOR; |
| 420 | |
| 421 | bss = ieee80211_bss_info_update(sdata->local, rx_status, |
| 422 | mgmt, skb->len, &elems, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame^] | 423 | channel, beacon); |
Jouni Malinen | d048e50 | 2008-10-11 03:29:55 +0300 | [diff] [blame] | 424 | if (bss) |
| 425 | ieee80211_rx_bss_put(sdata->local, bss); |
Johannes Berg | 98c8fcc | 2008-09-08 17:44:26 +0200 | [diff] [blame] | 426 | |
| 427 | dev_kfree_skb(skb); |
| 428 | return RX_QUEUED; |
| 429 | } |
| 430 | |
Vivek Natarajan | a97b77b | 2008-12-23 18:39:02 -0800 | [diff] [blame] | 431 | void ieee80211_send_nullfunc(struct ieee80211_local *local, |
Johannes Berg | 0a51b27 | 2008-09-08 17:44:25 +0200 | [diff] [blame] | 432 | struct ieee80211_sub_if_data *sdata, |
| 433 | int powersave) |
| 434 | { |
| 435 | struct sk_buff *skb; |
| 436 | struct ieee80211_hdr *nullfunc; |
| 437 | __le16 fc; |
| 438 | |
| 439 | skb = dev_alloc_skb(local->hw.extra_tx_headroom + 24); |
| 440 | if (!skb) { |
| 441 | printk(KERN_DEBUG "%s: failed to allocate buffer for nullfunc " |
| 442 | "frame\n", sdata->dev->name); |
| 443 | return; |
| 444 | } |
| 445 | skb_reserve(skb, local->hw.extra_tx_headroom); |
| 446 | |
| 447 | nullfunc = (struct ieee80211_hdr *) skb_put(skb, 24); |
| 448 | memset(nullfunc, 0, 24); |
| 449 | fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_NULLFUNC | |
| 450 | IEEE80211_FCTL_TODS); |
| 451 | if (powersave) |
| 452 | fc |= cpu_to_le16(IEEE80211_FCTL_PM); |
| 453 | nullfunc->frame_control = fc; |
| 454 | memcpy(nullfunc->addr1, sdata->u.sta.bssid, ETH_ALEN); |
| 455 | memcpy(nullfunc->addr2, sdata->dev->dev_addr, ETH_ALEN); |
| 456 | memcpy(nullfunc->addr3, sdata->u.sta.bssid, ETH_ALEN); |
| 457 | |
Johannes Berg | e50db65 | 2008-09-09 15:07:09 +0200 | [diff] [blame] | 458 | ieee80211_tx_skb(sdata, skb, 0); |
Johannes Berg | 0a51b27 | 2008-09-08 17:44:25 +0200 | [diff] [blame] | 459 | } |
| 460 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame^] | 461 | void ieee80211_scan_completed(struct ieee80211_hw *hw, bool aborted) |
Johannes Berg | 0a51b27 | 2008-09-08 17:44:25 +0200 | [diff] [blame] | 462 | { |
| 463 | struct ieee80211_local *local = hw_to_local(hw); |
| 464 | struct ieee80211_sub_if_data *sdata; |
Johannes Berg | 0a51b27 | 2008-09-08 17:44:25 +0200 | [diff] [blame] | 465 | |
Johannes Berg | c2b1345 | 2008-09-11 00:01:55 +0200 | [diff] [blame] | 466 | if (WARN_ON(!local->hw_scanning && !local->sw_scanning)) |
Johannes Berg | 5bc7572 | 2008-09-11 00:01:51 +0200 | [diff] [blame] | 467 | return; |
| 468 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame^] | 469 | if (WARN_ON(!local->scan_req)) |
| 470 | return; |
Johannes Berg | 5bc7572 | 2008-09-11 00:01:51 +0200 | [diff] [blame] | 471 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame^] | 472 | if (local->scan_req != &local->int_scan_req) |
| 473 | cfg80211_scan_done(local->scan_req, aborted); |
| 474 | local->scan_req = NULL; |
| 475 | |
| 476 | local->last_scan_completed = jiffies; |
Johannes Berg | 0a51b27 | 2008-09-08 17:44:25 +0200 | [diff] [blame] | 477 | |
Johannes Berg | c2b1345 | 2008-09-11 00:01:55 +0200 | [diff] [blame] | 478 | if (local->hw_scanning) { |
| 479 | local->hw_scanning = false; |
Johannes Berg | e897558 | 2008-10-09 12:18:51 +0200 | [diff] [blame] | 480 | /* |
| 481 | * Somebody might have requested channel change during scan |
| 482 | * that we won't have acted upon, try now. ieee80211_hw_config |
| 483 | * will set the flag based on actual changes. |
| 484 | */ |
| 485 | ieee80211_hw_config(local, 0); |
Johannes Berg | 0a51b27 | 2008-09-08 17:44:25 +0200 | [diff] [blame] | 486 | goto done; |
| 487 | } |
| 488 | |
Johannes Berg | c2b1345 | 2008-09-11 00:01:55 +0200 | [diff] [blame] | 489 | local->sw_scanning = false; |
Johannes Berg | e897558 | 2008-10-09 12:18:51 +0200 | [diff] [blame] | 490 | ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_CHANNEL); |
Johannes Berg | 0a51b27 | 2008-09-08 17:44:25 +0200 | [diff] [blame] | 491 | |
| 492 | netif_tx_lock_bh(local->mdev); |
| 493 | netif_addr_lock(local->mdev); |
| 494 | local->filter_flags &= ~FIF_BCN_PRBRESP_PROMISC; |
| 495 | local->ops->configure_filter(local_to_hw(local), |
| 496 | FIF_BCN_PRBRESP_PROMISC, |
| 497 | &local->filter_flags, |
| 498 | local->mdev->mc_count, |
| 499 | local->mdev->mc_list); |
| 500 | |
| 501 | netif_addr_unlock(local->mdev); |
| 502 | netif_tx_unlock_bh(local->mdev); |
| 503 | |
Johannes Berg | 078e1e6 | 2009-01-22 18:07:31 +0100 | [diff] [blame] | 504 | mutex_lock(&local->iflist_mtx); |
| 505 | list_for_each_entry(sdata, &local->interfaces, list) { |
Johannes Berg | fb9ddbf | 2009-01-26 19:11:57 +0100 | [diff] [blame] | 506 | if (!netif_running(sdata->dev)) |
| 507 | continue; |
| 508 | |
Johannes Berg | 0a51b27 | 2008-09-08 17:44:25 +0200 | [diff] [blame] | 509 | /* Tell AP we're back */ |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 510 | if (sdata->vif.type == NL80211_IFTYPE_STATION) { |
Johannes Berg | 0a51b27 | 2008-09-08 17:44:25 +0200 | [diff] [blame] | 511 | if (sdata->u.sta.flags & IEEE80211_STA_ASSOCIATED) { |
| 512 | ieee80211_send_nullfunc(local, sdata, 0); |
| 513 | netif_tx_wake_all_queues(sdata->dev); |
| 514 | } |
| 515 | } else |
| 516 | netif_tx_wake_all_queues(sdata->dev); |
Johannes Berg | 078e1e6 | 2009-01-22 18:07:31 +0100 | [diff] [blame] | 517 | |
Johannes Berg | 14b8072 | 2009-02-10 21:25:42 +0100 | [diff] [blame] | 518 | /* re-enable beaconing */ |
| 519 | if (sdata->vif.type == NL80211_IFTYPE_AP || |
| 520 | sdata->vif.type == NL80211_IFTYPE_ADHOC || |
| 521 | sdata->vif.type == NL80211_IFTYPE_MESH_POINT) |
| 522 | ieee80211_if_config(sdata, |
| 523 | IEEE80211_IFCC_BEACON_ENABLED); |
Johannes Berg | 0a51b27 | 2008-09-08 17:44:25 +0200 | [diff] [blame] | 524 | } |
Johannes Berg | 078e1e6 | 2009-01-22 18:07:31 +0100 | [diff] [blame] | 525 | mutex_unlock(&local->iflist_mtx); |
Johannes Berg | 0a51b27 | 2008-09-08 17:44:25 +0200 | [diff] [blame] | 526 | |
| 527 | done: |
| 528 | ieee80211_mlme_notify_scan_completed(local); |
Johannes Berg | 472dbc4 | 2008-09-11 00:01:49 +0200 | [diff] [blame] | 529 | ieee80211_mesh_notify_scan_completed(local); |
Johannes Berg | 0a51b27 | 2008-09-08 17:44:25 +0200 | [diff] [blame] | 530 | } |
| 531 | EXPORT_SYMBOL(ieee80211_scan_completed); |
| 532 | |
Johannes Berg | c2b1345 | 2008-09-11 00:01:55 +0200 | [diff] [blame] | 533 | void ieee80211_scan_work(struct work_struct *work) |
Johannes Berg | 0a51b27 | 2008-09-08 17:44:25 +0200 | [diff] [blame] | 534 | { |
| 535 | struct ieee80211_local *local = |
| 536 | container_of(work, struct ieee80211_local, scan_work.work); |
| 537 | struct ieee80211_sub_if_data *sdata = local->scan_sdata; |
Johannes Berg | 0a51b27 | 2008-09-08 17:44:25 +0200 | [diff] [blame] | 538 | struct ieee80211_channel *chan; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame^] | 539 | int skip, i; |
Johannes Berg | 0a51b27 | 2008-09-08 17:44:25 +0200 | [diff] [blame] | 540 | unsigned long next_delay = 0; |
| 541 | |
Johannes Berg | 5bc7572 | 2008-09-11 00:01:51 +0200 | [diff] [blame] | 542 | /* |
| 543 | * Avoid re-scheduling when the sdata is going away. |
| 544 | */ |
| 545 | if (!netif_running(sdata->dev)) |
Johannes Berg | 0a51b27 | 2008-09-08 17:44:25 +0200 | [diff] [blame] | 546 | return; |
| 547 | |
| 548 | switch (local->scan_state) { |
| 549 | case SCAN_SET_CHANNEL: |
Johannes Berg | 0a51b27 | 2008-09-08 17:44:25 +0200 | [diff] [blame] | 550 | /* if no more bands/channels left, complete scan */ |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame^] | 551 | if (local->scan_channel_idx >= local->scan_req->n_channels) { |
| 552 | ieee80211_scan_completed(local_to_hw(local), false); |
Johannes Berg | 0a51b27 | 2008-09-08 17:44:25 +0200 | [diff] [blame] | 553 | return; |
| 554 | } |
| 555 | skip = 0; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame^] | 556 | chan = local->scan_req->channels[local->scan_channel_idx]; |
Johannes Berg | 0a51b27 | 2008-09-08 17:44:25 +0200 | [diff] [blame] | 557 | |
| 558 | if (chan->flags & IEEE80211_CHAN_DISABLED || |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 559 | (sdata->vif.type == NL80211_IFTYPE_ADHOC && |
Johannes Berg | 0a51b27 | 2008-09-08 17:44:25 +0200 | [diff] [blame] | 560 | chan->flags & IEEE80211_CHAN_NO_IBSS)) |
| 561 | skip = 1; |
| 562 | |
| 563 | if (!skip) { |
| 564 | local->scan_channel = chan; |
Johannes Berg | e897558 | 2008-10-09 12:18:51 +0200 | [diff] [blame] | 565 | if (ieee80211_hw_config(local, |
| 566 | IEEE80211_CONF_CHANGE_CHANNEL)) |
Johannes Berg | 0a51b27 | 2008-09-08 17:44:25 +0200 | [diff] [blame] | 567 | skip = 1; |
Johannes Berg | 0a51b27 | 2008-09-08 17:44:25 +0200 | [diff] [blame] | 568 | } |
| 569 | |
| 570 | /* advance state machine to next channel/band */ |
| 571 | local->scan_channel_idx++; |
Johannes Berg | 0a51b27 | 2008-09-08 17:44:25 +0200 | [diff] [blame] | 572 | |
| 573 | if (skip) |
| 574 | break; |
| 575 | |
| 576 | next_delay = IEEE80211_PROBE_DELAY + |
| 577 | usecs_to_jiffies(local->hw.channel_change_time); |
| 578 | local->scan_state = SCAN_SEND_PROBE; |
| 579 | break; |
| 580 | case SCAN_SEND_PROBE: |
| 581 | next_delay = IEEE80211_PASSIVE_CHANNEL_TIME; |
| 582 | local->scan_state = SCAN_SET_CHANNEL; |
| 583 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame^] | 584 | if (local->scan_channel->flags & IEEE80211_CHAN_PASSIVE_SCAN || |
| 585 | !local->scan_req->n_ssids) |
Johannes Berg | 0a51b27 | 2008-09-08 17:44:25 +0200 | [diff] [blame] | 586 | break; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame^] | 587 | for (i = 0; i < local->scan_req->n_ssids; i++) |
| 588 | ieee80211_send_probe_req( |
| 589 | sdata, NULL, |
| 590 | local->scan_req->ssids[i].ssid, |
| 591 | local->scan_req->ssids[i].ssid_len); |
Johannes Berg | 0a51b27 | 2008-09-08 17:44:25 +0200 | [diff] [blame] | 592 | next_delay = IEEE80211_CHANNEL_TIME; |
| 593 | break; |
| 594 | } |
| 595 | |
Johannes Berg | 5bc7572 | 2008-09-11 00:01:51 +0200 | [diff] [blame] | 596 | queue_delayed_work(local->hw.workqueue, &local->scan_work, |
| 597 | next_delay); |
Johannes Berg | 0a51b27 | 2008-09-08 17:44:25 +0200 | [diff] [blame] | 598 | } |
| 599 | |
| 600 | |
Johannes Berg | c2b1345 | 2008-09-11 00:01:55 +0200 | [diff] [blame] | 601 | int ieee80211_start_scan(struct ieee80211_sub_if_data *scan_sdata, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame^] | 602 | struct cfg80211_scan_request *req) |
Johannes Berg | 0a51b27 | 2008-09-08 17:44:25 +0200 | [diff] [blame] | 603 | { |
| 604 | struct ieee80211_local *local = scan_sdata->local; |
| 605 | struct ieee80211_sub_if_data *sdata; |
| 606 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame^] | 607 | if (!req) |
Johannes Berg | 0a51b27 | 2008-09-08 17:44:25 +0200 | [diff] [blame] | 608 | return -EINVAL; |
| 609 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame^] | 610 | if (local->scan_req && local->scan_req != req) |
| 611 | return -EBUSY; |
| 612 | |
| 613 | local->scan_req = req; |
| 614 | |
Johannes Berg | 0a51b27 | 2008-09-08 17:44:25 +0200 | [diff] [blame] | 615 | /* MLME-SCAN.request (page 118) page 144 (11.1.3.1) |
| 616 | * BSSType: INFRASTRUCTURE, INDEPENDENT, ANY_BSS |
| 617 | * BSSID: MACAddress |
| 618 | * SSID |
| 619 | * ScanType: ACTIVE, PASSIVE |
| 620 | * ProbeDelay: delay (in microseconds) to be used prior to transmitting |
| 621 | * a Probe frame during active scanning |
| 622 | * ChannelList |
| 623 | * MinChannelTime (>= ProbeDelay), in TU |
| 624 | * MaxChannelTime: (>= MinChannelTime), in TU |
| 625 | */ |
| 626 | |
| 627 | /* MLME-SCAN.confirm |
| 628 | * BSSDescriptionSet |
| 629 | * ResultCode: SUCCESS, INVALID_PARAMETERS |
| 630 | */ |
| 631 | |
Johannes Berg | c2b1345 | 2008-09-11 00:01:55 +0200 | [diff] [blame] | 632 | if (local->sw_scanning || local->hw_scanning) { |
Johannes Berg | 0a51b27 | 2008-09-08 17:44:25 +0200 | [diff] [blame] | 633 | if (local->scan_sdata == scan_sdata) |
| 634 | return 0; |
| 635 | return -EBUSY; |
| 636 | } |
| 637 | |
| 638 | if (local->ops->hw_scan) { |
Johannes Berg | 5bc7572 | 2008-09-11 00:01:51 +0200 | [diff] [blame] | 639 | int rc; |
| 640 | |
Johannes Berg | c2b1345 | 2008-09-11 00:01:55 +0200 | [diff] [blame] | 641 | local->hw_scanning = true; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame^] | 642 | rc = local->ops->hw_scan(local_to_hw(local), req); |
Johannes Berg | 5bc7572 | 2008-09-11 00:01:51 +0200 | [diff] [blame] | 643 | if (rc) { |
Johannes Berg | c2b1345 | 2008-09-11 00:01:55 +0200 | [diff] [blame] | 644 | local->hw_scanning = false; |
Johannes Berg | 5bc7572 | 2008-09-11 00:01:51 +0200 | [diff] [blame] | 645 | return rc; |
Johannes Berg | 0a51b27 | 2008-09-08 17:44:25 +0200 | [diff] [blame] | 646 | } |
Johannes Berg | 5bc7572 | 2008-09-11 00:01:51 +0200 | [diff] [blame] | 647 | local->scan_sdata = scan_sdata; |
| 648 | return 0; |
Johannes Berg | 0a51b27 | 2008-09-08 17:44:25 +0200 | [diff] [blame] | 649 | } |
| 650 | |
Johannes Berg | c2b1345 | 2008-09-11 00:01:55 +0200 | [diff] [blame] | 651 | local->sw_scanning = true; |
Johannes Berg | 0a51b27 | 2008-09-08 17:44:25 +0200 | [diff] [blame] | 652 | |
Johannes Berg | 078e1e6 | 2009-01-22 18:07:31 +0100 | [diff] [blame] | 653 | mutex_lock(&local->iflist_mtx); |
| 654 | list_for_each_entry(sdata, &local->interfaces, list) { |
Johannes Berg | fb9ddbf | 2009-01-26 19:11:57 +0100 | [diff] [blame] | 655 | if (!netif_running(sdata->dev)) |
| 656 | continue; |
| 657 | |
Johannes Berg | 14b8072 | 2009-02-10 21:25:42 +0100 | [diff] [blame] | 658 | /* disable beaconing */ |
| 659 | if (sdata->vif.type == NL80211_IFTYPE_AP || |
| 660 | sdata->vif.type == NL80211_IFTYPE_ADHOC || |
| 661 | sdata->vif.type == NL80211_IFTYPE_MESH_POINT) |
| 662 | ieee80211_if_config(sdata, |
| 663 | IEEE80211_IFCC_BEACON_ENABLED); |
Johannes Berg | 078e1e6 | 2009-01-22 18:07:31 +0100 | [diff] [blame] | 664 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 665 | if (sdata->vif.type == NL80211_IFTYPE_STATION) { |
Johannes Berg | 0a51b27 | 2008-09-08 17:44:25 +0200 | [diff] [blame] | 666 | if (sdata->u.sta.flags & IEEE80211_STA_ASSOCIATED) { |
| 667 | netif_tx_stop_all_queues(sdata->dev); |
| 668 | ieee80211_send_nullfunc(local, sdata, 1); |
| 669 | } |
| 670 | } else |
| 671 | netif_tx_stop_all_queues(sdata->dev); |
| 672 | } |
Johannes Berg | 078e1e6 | 2009-01-22 18:07:31 +0100 | [diff] [blame] | 673 | mutex_unlock(&local->iflist_mtx); |
Johannes Berg | 0a51b27 | 2008-09-08 17:44:25 +0200 | [diff] [blame] | 674 | |
Johannes Berg | 0a51b27 | 2008-09-08 17:44:25 +0200 | [diff] [blame] | 675 | local->scan_state = SCAN_SET_CHANNEL; |
| 676 | local->scan_channel_idx = 0; |
Johannes Berg | 0a51b27 | 2008-09-08 17:44:25 +0200 | [diff] [blame] | 677 | local->scan_sdata = scan_sdata; |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame^] | 678 | local->scan_req = req; |
Johannes Berg | 0a51b27 | 2008-09-08 17:44:25 +0200 | [diff] [blame] | 679 | |
| 680 | netif_addr_lock_bh(local->mdev); |
| 681 | local->filter_flags |= FIF_BCN_PRBRESP_PROMISC; |
| 682 | local->ops->configure_filter(local_to_hw(local), |
| 683 | FIF_BCN_PRBRESP_PROMISC, |
| 684 | &local->filter_flags, |
| 685 | local->mdev->mc_count, |
| 686 | local->mdev->mc_list); |
| 687 | netif_addr_unlock_bh(local->mdev); |
| 688 | |
| 689 | /* TODO: start scan as soon as all nullfunc frames are ACKed */ |
| 690 | queue_delayed_work(local->hw.workqueue, &local->scan_work, |
| 691 | IEEE80211_CHANNEL_TIME); |
| 692 | |
| 693 | return 0; |
| 694 | } |
| 695 | |
| 696 | |
Johannes Berg | c2b1345 | 2008-09-11 00:01:55 +0200 | [diff] [blame] | 697 | int ieee80211_request_scan(struct ieee80211_sub_if_data *sdata, |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame^] | 698 | struct cfg80211_scan_request *req) |
Johannes Berg | 0a51b27 | 2008-09-08 17:44:25 +0200 | [diff] [blame] | 699 | { |
Johannes Berg | 0a51b27 | 2008-09-08 17:44:25 +0200 | [diff] [blame] | 700 | struct ieee80211_local *local = sdata->local; |
Johannes Berg | 9116dd0 | 2008-09-08 17:47:23 +0200 | [diff] [blame] | 701 | struct ieee80211_if_sta *ifsta; |
Johannes Berg | 0a51b27 | 2008-09-08 17:44:25 +0200 | [diff] [blame] | 702 | |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame^] | 703 | if (!req) |
| 704 | return -EINVAL; |
| 705 | |
| 706 | if (local->scan_req && local->scan_req != req) |
| 707 | return -EBUSY; |
| 708 | |
| 709 | local->scan_req = req; |
| 710 | |
Johannes Berg | 05c914f | 2008-09-11 00:01:58 +0200 | [diff] [blame] | 711 | if (sdata->vif.type != NL80211_IFTYPE_STATION) |
Johannes Berg | 2a51931 | 2009-02-10 21:25:55 +0100 | [diff] [blame^] | 712 | return ieee80211_start_scan(sdata, req); |
Johannes Berg | 0a51b27 | 2008-09-08 17:44:25 +0200 | [diff] [blame] | 713 | |
Johannes Berg | 9116dd0 | 2008-09-08 17:47:23 +0200 | [diff] [blame] | 714 | /* |
| 715 | * STA has a state machine that might need to defer scanning |
| 716 | * while it's trying to associate/authenticate, therefore we |
| 717 | * queue it up to the state machine in that case. |
| 718 | */ |
| 719 | |
Johannes Berg | c2b1345 | 2008-09-11 00:01:55 +0200 | [diff] [blame] | 720 | if (local->sw_scanning || local->hw_scanning) { |
Johannes Berg | 0a51b27 | 2008-09-08 17:44:25 +0200 | [diff] [blame] | 721 | if (local->scan_sdata == sdata) |
| 722 | return 0; |
| 723 | return -EBUSY; |
| 724 | } |
| 725 | |
Johannes Berg | 9116dd0 | 2008-09-08 17:47:23 +0200 | [diff] [blame] | 726 | ifsta = &sdata->u.sta; |
Johannes Berg | 0a51b27 | 2008-09-08 17:44:25 +0200 | [diff] [blame] | 727 | set_bit(IEEE80211_STA_REQ_SCAN, &ifsta->request); |
| 728 | queue_work(local->hw.workqueue, &ifsta->work); |
Johannes Berg | 9116dd0 | 2008-09-08 17:47:23 +0200 | [diff] [blame] | 729 | |
Johannes Berg | 0a51b27 | 2008-09-08 17:44:25 +0200 | [diff] [blame] | 730 | return 0; |
| 731 | } |