Commit | Line | Data |
---|---|---|
0a51b27e | 1 | /* |
5484e237 JB |
2 | * Scanning implementation |
3 | * | |
0a51b27e JB |
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 | ||
00d3f14c | 15 | /* TODO: figure out how to avoid that the "current BSS" expires */ |
5484e237 | 16 | |
0a51b27e JB |
17 | #include <linux/wireless.h> |
18 | #include <linux/if_arp.h> | |
078e1e60 | 19 | #include <linux/rtnetlink.h> |
0a51b27e JB |
20 | #include <net/mac80211.h> |
21 | #include <net/iw_handler.h> | |
22 | ||
23 | #include "ieee80211_i.h" | |
5484e237 | 24 | #include "mesh.h" |
0a51b27e JB |
25 | |
26 | #define IEEE80211_PROBE_DELAY (HZ / 33) | |
27 | #define IEEE80211_CHANNEL_TIME (HZ / 33) | |
28 | #define IEEE80211_PASSIVE_CHANNEL_TIME (HZ / 5) | |
29 | ||
c2b13452 | 30 | struct ieee80211_bss * |
5484e237 JB |
31 | ieee80211_rx_bss_get(struct ieee80211_local *local, u8 *bssid, int freq, |
32 | u8 *ssid, u8 ssid_len) | |
33 | { | |
00d3f14c JB |
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); | |
5484e237 JB |
39 | } |
40 | ||
00d3f14c | 41 | static void ieee80211_rx_bss_free(struct cfg80211_bss *cbss) |
5484e237 | 42 | { |
00d3f14c | 43 | struct ieee80211_bss *bss = (void *)cbss; |
5484e237 | 44 | |
5484e237 JB |
45 | kfree(bss_mesh_id(bss)); |
46 | kfree(bss_mesh_cfg(bss)); | |
5484e237 JB |
47 | } |
48 | ||
49 | void ieee80211_rx_bss_put(struct ieee80211_local *local, | |
c2b13452 | 50 | struct ieee80211_bss *bss) |
5484e237 | 51 | { |
00d3f14c | 52 | cfg80211_put_bss((struct cfg80211_bss *)bss); |
5484e237 JB |
53 | } |
54 | ||
c2b13452 | 55 | struct ieee80211_bss * |
5484e237 JB |
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, | |
2a519311 JB |
61 | struct ieee80211_channel *channel, |
62 | bool beacon) | |
5484e237 | 63 | { |
c2b13452 | 64 | struct ieee80211_bss *bss; |
00d3f14c | 65 | int clen; |
2a519311 JB |
66 | s32 signal = 0; |
67 | ||
77965c97 | 68 | if (local->hw.flags & IEEE80211_HW_SIGNAL_DBM) |
2a519311 | 69 | signal = rx_status->signal * 100; |
77965c97 | 70 | else if (local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC) |
2a519311 | 71 | signal = (rx_status->signal * 100) / local->hw.max_signal; |
2a519311 | 72 | |
00d3f14c | 73 | bss = (void *)cfg80211_inform_bss_frame(local->hw.wiphy, channel, |
77965c97 | 74 | mgmt, len, signal, GFP_ATOMIC); |
5484e237 | 75 | |
00d3f14c JB |
76 | if (!bss) |
77 | return NULL; | |
78 | ||
79 | bss->cbss.free_priv = ieee80211_rx_bss_free; | |
5484e237 JB |
80 | |
81 | /* save the ERP value so that it is available at association time */ | |
82 | if (elems->erp_info && elems->erp_info_len >= 1) { | |
83 | bss->erp_value = elems->erp_info[0]; | |
84 | bss->has_erp_value = 1; | |
85 | } | |
86 | ||
5484e237 JB |
87 | if (elems->tim) { |
88 | struct ieee80211_tim_ie *tim_ie = | |
89 | (struct ieee80211_tim_ie *)elems->tim; | |
90 | bss->dtim_period = tim_ie->dtim_period; | |
91 | } | |
92 | ||
93 | /* set default value for buggy APs */ | |
94 | if (!elems->tim || bss->dtim_period == 0) | |
95 | bss->dtim_period = 1; | |
96 | ||
97 | bss->supp_rates_len = 0; | |
98 | if (elems->supp_rates) { | |
99 | clen = IEEE80211_MAX_SUPP_RATES - bss->supp_rates_len; | |
100 | if (clen > elems->supp_rates_len) | |
101 | clen = elems->supp_rates_len; | |
102 | memcpy(&bss->supp_rates[bss->supp_rates_len], elems->supp_rates, | |
103 | clen); | |
104 | bss->supp_rates_len += clen; | |
105 | } | |
106 | if (elems->ext_supp_rates) { | |
107 | clen = IEEE80211_MAX_SUPP_RATES - bss->supp_rates_len; | |
108 | if (clen > elems->ext_supp_rates_len) | |
109 | clen = elems->ext_supp_rates_len; | |
110 | memcpy(&bss->supp_rates[bss->supp_rates_len], | |
111 | elems->ext_supp_rates, clen); | |
112 | bss->supp_rates_len += clen; | |
113 | } | |
114 | ||
5484e237 JB |
115 | bss->wmm_used = elems->wmm_param || elems->wmm_info; |
116 | ||
117 | if (!beacon) | |
118 | bss->last_probe_resp = jiffies; | |
119 | ||
5484e237 JB |
120 | return bss; |
121 | } | |
0a51b27e | 122 | |
7a947080 VT |
123 | void ieee80211_rx_bss_remove(struct ieee80211_sub_if_data *sdata, u8 *bssid, |
124 | int freq, u8 *ssid, u8 ssid_len) | |
125 | { | |
126 | struct ieee80211_bss *bss; | |
127 | struct ieee80211_local *local = sdata->local; | |
128 | ||
129 | bss = ieee80211_rx_bss_get(local, bssid, freq, ssid, ssid_len); | |
130 | if (bss) { | |
00d3f14c | 131 | cfg80211_unlink_bss(local->hw.wiphy, (void *)bss); |
7a947080 VT |
132 | ieee80211_rx_bss_put(local, bss); |
133 | } | |
134 | } | |
135 | ||
98c8fccf | 136 | ieee80211_rx_result |
c2b13452 JB |
137 | ieee80211_scan_rx(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb, |
138 | struct ieee80211_rx_status *rx_status) | |
98c8fccf JB |
139 | { |
140 | struct ieee80211_mgmt *mgmt; | |
c2b13452 | 141 | struct ieee80211_bss *bss; |
98c8fccf JB |
142 | u8 *elements; |
143 | struct ieee80211_channel *channel; | |
144 | size_t baselen; | |
145 | int freq; | |
146 | __le16 fc; | |
147 | bool presp, beacon = false; | |
148 | struct ieee802_11_elems elems; | |
149 | ||
150 | if (skb->len < 2) | |
151 | return RX_DROP_UNUSABLE; | |
152 | ||
153 | mgmt = (struct ieee80211_mgmt *) skb->data; | |
154 | fc = mgmt->frame_control; | |
155 | ||
156 | if (ieee80211_is_ctl(fc)) | |
157 | return RX_CONTINUE; | |
158 | ||
159 | if (skb->len < 24) | |
160 | return RX_DROP_MONITOR; | |
161 | ||
162 | presp = ieee80211_is_probe_resp(fc); | |
163 | if (presp) { | |
164 | /* ignore ProbeResp to foreign address */ | |
165 | if (memcmp(mgmt->da, sdata->dev->dev_addr, ETH_ALEN)) | |
166 | return RX_DROP_MONITOR; | |
167 | ||
168 | presp = true; | |
169 | elements = mgmt->u.probe_resp.variable; | |
170 | baselen = offsetof(struct ieee80211_mgmt, u.probe_resp.variable); | |
171 | } else { | |
172 | beacon = ieee80211_is_beacon(fc); | |
173 | baselen = offsetof(struct ieee80211_mgmt, u.beacon.variable); | |
174 | elements = mgmt->u.beacon.variable; | |
175 | } | |
176 | ||
177 | if (!presp && !beacon) | |
178 | return RX_CONTINUE; | |
179 | ||
180 | if (baselen > skb->len) | |
181 | return RX_DROP_MONITOR; | |
182 | ||
183 | ieee802_11_parse_elems(elements, skb->len - baselen, &elems); | |
184 | ||
185 | if (elems.ds_params && elems.ds_params_len == 1) | |
186 | freq = ieee80211_channel_to_frequency(elems.ds_params[0]); | |
187 | else | |
188 | freq = rx_status->freq; | |
189 | ||
190 | channel = ieee80211_get_channel(sdata->local->hw.wiphy, freq); | |
191 | ||
192 | if (!channel || channel->flags & IEEE80211_CHAN_DISABLED) | |
193 | return RX_DROP_MONITOR; | |
194 | ||
195 | bss = ieee80211_bss_info_update(sdata->local, rx_status, | |
196 | mgmt, skb->len, &elems, | |
2a519311 | 197 | channel, beacon); |
d048e503 JM |
198 | if (bss) |
199 | ieee80211_rx_bss_put(sdata->local, bss); | |
98c8fccf JB |
200 | |
201 | dev_kfree_skb(skb); | |
202 | return RX_QUEUED; | |
203 | } | |
204 | ||
af88b907 HS |
205 | void ieee80211_scan_failed(struct ieee80211_local *local) |
206 | { | |
207 | if (WARN_ON(!local->scan_req)) | |
208 | return; | |
209 | ||
210 | /* notify cfg80211 about the failed scan */ | |
211 | if (local->scan_req != &local->int_scan_req) | |
212 | cfg80211_scan_done(local->scan_req, true); | |
213 | ||
214 | local->scan_req = NULL; | |
215 | } | |
216 | ||
9050bdd8 KV |
217 | /* |
218 | * inform AP that we will go to sleep so that it will buffer the frames | |
219 | * while we scan | |
220 | */ | |
221 | static void ieee80211_scan_ps_enable(struct ieee80211_sub_if_data *sdata) | |
222 | { | |
223 | struct ieee80211_local *local = sdata->local; | |
224 | bool ps = false; | |
225 | ||
226 | /* FIXME: what to do when local->pspolling is true? */ | |
227 | ||
228 | del_timer_sync(&local->dynamic_ps_timer); | |
229 | cancel_work_sync(&local->dynamic_ps_enable_work); | |
230 | ||
231 | if (local->hw.conf.flags & IEEE80211_CONF_PS) { | |
232 | ps = true; | |
233 | local->hw.conf.flags &= ~IEEE80211_CONF_PS; | |
234 | ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS); | |
235 | } | |
236 | ||
237 | if (!ps || !(local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK)) | |
238 | /* | |
239 | * If power save was enabled, no need to send a nullfunc | |
240 | * frame because AP knows that we are sleeping. But if the | |
241 | * hardware is creating the nullfunc frame for power save | |
242 | * status (ie. IEEE80211_HW_PS_NULLFUNC_STACK is not | |
243 | * enabled) and power save was enabled, the firmware just | |
244 | * sent a null frame with power save disabled. So we need | |
245 | * to send a new nullfunc frame to inform the AP that we | |
246 | * are again sleeping. | |
247 | */ | |
248 | ieee80211_send_nullfunc(local, sdata, 1); | |
249 | } | |
250 | ||
251 | /* inform AP that we are awake again, unless power save is enabled */ | |
252 | static void ieee80211_scan_ps_disable(struct ieee80211_sub_if_data *sdata) | |
253 | { | |
254 | struct ieee80211_local *local = sdata->local; | |
255 | ||
256 | if (!local->powersave) | |
257 | ieee80211_send_nullfunc(local, sdata, 0); | |
258 | else { | |
259 | /* | |
260 | * In !IEEE80211_HW_PS_NULLFUNC_STACK case the hardware | |
261 | * will send a nullfunc frame with the powersave bit set | |
262 | * even though the AP already knows that we are sleeping. | |
263 | * This could be avoided by sending a null frame with power | |
264 | * save bit disabled before enabling the power save, but | |
265 | * this doesn't gain anything. | |
266 | * | |
267 | * When IEEE80211_HW_PS_NULLFUNC_STACK is enabled, no need | |
268 | * to send a nullfunc frame because AP already knows that | |
269 | * we are sleeping, let's just enable power save mode in | |
270 | * hardware. | |
271 | */ | |
272 | local->hw.conf.flags |= IEEE80211_CONF_PS; | |
273 | ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS); | |
274 | } | |
275 | } | |
276 | ||
2a519311 | 277 | void ieee80211_scan_completed(struct ieee80211_hw *hw, bool aborted) |
0a51b27e JB |
278 | { |
279 | struct ieee80211_local *local = hw_to_local(hw); | |
280 | struct ieee80211_sub_if_data *sdata; | |
0a51b27e | 281 | |
c2b13452 | 282 | if (WARN_ON(!local->hw_scanning && !local->sw_scanning)) |
5bc75728 JB |
283 | return; |
284 | ||
2a519311 JB |
285 | if (WARN_ON(!local->scan_req)) |
286 | return; | |
5bc75728 | 287 | |
2a519311 JB |
288 | if (local->scan_req != &local->int_scan_req) |
289 | cfg80211_scan_done(local->scan_req, aborted); | |
290 | local->scan_req = NULL; | |
291 | ||
292 | local->last_scan_completed = jiffies; | |
0a51b27e | 293 | |
c2b13452 JB |
294 | if (local->hw_scanning) { |
295 | local->hw_scanning = false; | |
e8975581 JB |
296 | /* |
297 | * Somebody might have requested channel change during scan | |
298 | * that we won't have acted upon, try now. ieee80211_hw_config | |
299 | * will set the flag based on actual changes. | |
300 | */ | |
301 | ieee80211_hw_config(local, 0); | |
0a51b27e JB |
302 | goto done; |
303 | } | |
304 | ||
c2b13452 | 305 | local->sw_scanning = false; |
e8975581 | 306 | ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_CHANNEL); |
0a51b27e JB |
307 | |
308 | netif_tx_lock_bh(local->mdev); | |
309 | netif_addr_lock(local->mdev); | |
310 | local->filter_flags &= ~FIF_BCN_PRBRESP_PROMISC; | |
311 | local->ops->configure_filter(local_to_hw(local), | |
312 | FIF_BCN_PRBRESP_PROMISC, | |
313 | &local->filter_flags, | |
314 | local->mdev->mc_count, | |
315 | local->mdev->mc_list); | |
316 | ||
317 | netif_addr_unlock(local->mdev); | |
318 | netif_tx_unlock_bh(local->mdev); | |
319 | ||
80e775bf MB |
320 | if (local->ops->sw_scan_complete) |
321 | local->ops->sw_scan_complete(local_to_hw(local)); | |
322 | ||
078e1e60 JB |
323 | mutex_lock(&local->iflist_mtx); |
324 | list_for_each_entry(sdata, &local->interfaces, list) { | |
fb9ddbf0 JB |
325 | if (!netif_running(sdata->dev)) |
326 | continue; | |
327 | ||
0a51b27e | 328 | /* Tell AP we're back */ |
05c914fe | 329 | if (sdata->vif.type == NL80211_IFTYPE_STATION) { |
46900298 | 330 | if (sdata->u.mgd.flags & IEEE80211_STA_ASSOCIATED) { |
9050bdd8 | 331 | ieee80211_scan_ps_disable(sdata); |
0a51b27e JB |
332 | netif_tx_wake_all_queues(sdata->dev); |
333 | } | |
334 | } else | |
335 | netif_tx_wake_all_queues(sdata->dev); | |
078e1e60 | 336 | |
14b80724 JB |
337 | /* re-enable beaconing */ |
338 | if (sdata->vif.type == NL80211_IFTYPE_AP || | |
339 | sdata->vif.type == NL80211_IFTYPE_ADHOC || | |
340 | sdata->vif.type == NL80211_IFTYPE_MESH_POINT) | |
341 | ieee80211_if_config(sdata, | |
342 | IEEE80211_IFCC_BEACON_ENABLED); | |
0a51b27e | 343 | } |
078e1e60 | 344 | mutex_unlock(&local->iflist_mtx); |
0a51b27e JB |
345 | |
346 | done: | |
347 | ieee80211_mlme_notify_scan_completed(local); | |
46900298 | 348 | ieee80211_ibss_notify_scan_completed(local); |
472dbc45 | 349 | ieee80211_mesh_notify_scan_completed(local); |
0a51b27e JB |
350 | } |
351 | EXPORT_SYMBOL(ieee80211_scan_completed); | |
352 | ||
c2b13452 | 353 | void ieee80211_scan_work(struct work_struct *work) |
0a51b27e JB |
354 | { |
355 | struct ieee80211_local *local = | |
356 | container_of(work, struct ieee80211_local, scan_work.work); | |
357 | struct ieee80211_sub_if_data *sdata = local->scan_sdata; | |
0a51b27e | 358 | struct ieee80211_channel *chan; |
2a519311 | 359 | int skip, i; |
0a51b27e JB |
360 | unsigned long next_delay = 0; |
361 | ||
5bc75728 JB |
362 | /* |
363 | * Avoid re-scheduling when the sdata is going away. | |
364 | */ | |
365 | if (!netif_running(sdata->dev)) | |
0a51b27e JB |
366 | return; |
367 | ||
368 | switch (local->scan_state) { | |
369 | case SCAN_SET_CHANNEL: | |
0a51b27e | 370 | /* if no more bands/channels left, complete scan */ |
2a519311 JB |
371 | if (local->scan_channel_idx >= local->scan_req->n_channels) { |
372 | ieee80211_scan_completed(local_to_hw(local), false); | |
0a51b27e JB |
373 | return; |
374 | } | |
375 | skip = 0; | |
2a519311 | 376 | chan = local->scan_req->channels[local->scan_channel_idx]; |
0a51b27e JB |
377 | |
378 | if (chan->flags & IEEE80211_CHAN_DISABLED || | |
05c914fe | 379 | (sdata->vif.type == NL80211_IFTYPE_ADHOC && |
0a51b27e JB |
380 | chan->flags & IEEE80211_CHAN_NO_IBSS)) |
381 | skip = 1; | |
382 | ||
383 | if (!skip) { | |
384 | local->scan_channel = chan; | |
e8975581 JB |
385 | if (ieee80211_hw_config(local, |
386 | IEEE80211_CONF_CHANGE_CHANNEL)) | |
0a51b27e | 387 | skip = 1; |
0a51b27e JB |
388 | } |
389 | ||
390 | /* advance state machine to next channel/band */ | |
391 | local->scan_channel_idx++; | |
0a51b27e JB |
392 | |
393 | if (skip) | |
394 | break; | |
395 | ||
396 | next_delay = IEEE80211_PROBE_DELAY + | |
397 | usecs_to_jiffies(local->hw.channel_change_time); | |
398 | local->scan_state = SCAN_SEND_PROBE; | |
399 | break; | |
400 | case SCAN_SEND_PROBE: | |
401 | next_delay = IEEE80211_PASSIVE_CHANNEL_TIME; | |
402 | local->scan_state = SCAN_SET_CHANNEL; | |
403 | ||
2a519311 JB |
404 | if (local->scan_channel->flags & IEEE80211_CHAN_PASSIVE_SCAN || |
405 | !local->scan_req->n_ssids) | |
0a51b27e | 406 | break; |
2a519311 JB |
407 | for (i = 0; i < local->scan_req->n_ssids; i++) |
408 | ieee80211_send_probe_req( | |
409 | sdata, NULL, | |
410 | local->scan_req->ssids[i].ssid, | |
70692ad2 JM |
411 | local->scan_req->ssids[i].ssid_len, |
412 | local->scan_req->ie, local->scan_req->ie_len); | |
0a51b27e JB |
413 | next_delay = IEEE80211_CHANNEL_TIME; |
414 | break; | |
415 | } | |
416 | ||
5bc75728 JB |
417 | queue_delayed_work(local->hw.workqueue, &local->scan_work, |
418 | next_delay); | |
0a51b27e JB |
419 | } |
420 | ||
421 | ||
c2b13452 | 422 | int ieee80211_start_scan(struct ieee80211_sub_if_data *scan_sdata, |
2a519311 | 423 | struct cfg80211_scan_request *req) |
0a51b27e JB |
424 | { |
425 | struct ieee80211_local *local = scan_sdata->local; | |
426 | struct ieee80211_sub_if_data *sdata; | |
427 | ||
2a519311 | 428 | if (!req) |
0a51b27e JB |
429 | return -EINVAL; |
430 | ||
2a519311 JB |
431 | if (local->scan_req && local->scan_req != req) |
432 | return -EBUSY; | |
433 | ||
434 | local->scan_req = req; | |
435 | ||
0a51b27e JB |
436 | /* MLME-SCAN.request (page 118) page 144 (11.1.3.1) |
437 | * BSSType: INFRASTRUCTURE, INDEPENDENT, ANY_BSS | |
438 | * BSSID: MACAddress | |
439 | * SSID | |
440 | * ScanType: ACTIVE, PASSIVE | |
441 | * ProbeDelay: delay (in microseconds) to be used prior to transmitting | |
442 | * a Probe frame during active scanning | |
443 | * ChannelList | |
444 | * MinChannelTime (>= ProbeDelay), in TU | |
445 | * MaxChannelTime: (>= MinChannelTime), in TU | |
446 | */ | |
447 | ||
448 | /* MLME-SCAN.confirm | |
449 | * BSSDescriptionSet | |
450 | * ResultCode: SUCCESS, INVALID_PARAMETERS | |
451 | */ | |
452 | ||
c2b13452 | 453 | if (local->sw_scanning || local->hw_scanning) { |
0a51b27e JB |
454 | if (local->scan_sdata == scan_sdata) |
455 | return 0; | |
456 | return -EBUSY; | |
457 | } | |
458 | ||
459 | if (local->ops->hw_scan) { | |
5bc75728 JB |
460 | int rc; |
461 | ||
c2b13452 | 462 | local->hw_scanning = true; |
2a519311 | 463 | rc = local->ops->hw_scan(local_to_hw(local), req); |
5bc75728 | 464 | if (rc) { |
c2b13452 | 465 | local->hw_scanning = false; |
5bc75728 | 466 | return rc; |
0a51b27e | 467 | } |
5bc75728 JB |
468 | local->scan_sdata = scan_sdata; |
469 | return 0; | |
0a51b27e JB |
470 | } |
471 | ||
a9a6ffff KV |
472 | /* |
473 | * Hardware/driver doesn't support hw_scan, so use software | |
474 | * scanning instead. First send a nullfunc frame with power save | |
475 | * bit on so that AP will buffer the frames for us while we are not | |
476 | * listening, then send probe requests to each channel and wait for | |
477 | * the responses. After all channels are scanned, tune back to the | |
478 | * original channel and send a nullfunc frame with power save bit | |
479 | * off to trigger the AP to send us all the buffered frames. | |
480 | * | |
481 | * Note that while local->sw_scanning is true everything else but | |
482 | * nullfunc frames and probe requests will be dropped in | |
483 | * ieee80211_tx_h_check_assoc(). | |
484 | */ | |
c2b13452 | 485 | local->sw_scanning = true; |
80e775bf MB |
486 | if (local->ops->sw_scan_start) |
487 | local->ops->sw_scan_start(local_to_hw(local)); | |
0a51b27e | 488 | |
078e1e60 JB |
489 | mutex_lock(&local->iflist_mtx); |
490 | list_for_each_entry(sdata, &local->interfaces, list) { | |
fb9ddbf0 JB |
491 | if (!netif_running(sdata->dev)) |
492 | continue; | |
493 | ||
14b80724 JB |
494 | /* disable beaconing */ |
495 | if (sdata->vif.type == NL80211_IFTYPE_AP || | |
496 | sdata->vif.type == NL80211_IFTYPE_ADHOC || | |
497 | sdata->vif.type == NL80211_IFTYPE_MESH_POINT) | |
498 | ieee80211_if_config(sdata, | |
499 | IEEE80211_IFCC_BEACON_ENABLED); | |
078e1e60 | 500 | |
05c914fe | 501 | if (sdata->vif.type == NL80211_IFTYPE_STATION) { |
46900298 | 502 | if (sdata->u.mgd.flags & IEEE80211_STA_ASSOCIATED) { |
0a51b27e | 503 | netif_tx_stop_all_queues(sdata->dev); |
9050bdd8 | 504 | ieee80211_scan_ps_enable(sdata); |
0a51b27e JB |
505 | } |
506 | } else | |
507 | netif_tx_stop_all_queues(sdata->dev); | |
508 | } | |
078e1e60 | 509 | mutex_unlock(&local->iflist_mtx); |
0a51b27e | 510 | |
0a51b27e JB |
511 | local->scan_state = SCAN_SET_CHANNEL; |
512 | local->scan_channel_idx = 0; | |
0a51b27e | 513 | local->scan_sdata = scan_sdata; |
2a519311 | 514 | local->scan_req = req; |
0a51b27e JB |
515 | |
516 | netif_addr_lock_bh(local->mdev); | |
517 | local->filter_flags |= FIF_BCN_PRBRESP_PROMISC; | |
518 | local->ops->configure_filter(local_to_hw(local), | |
519 | FIF_BCN_PRBRESP_PROMISC, | |
520 | &local->filter_flags, | |
521 | local->mdev->mc_count, | |
522 | local->mdev->mc_list); | |
523 | netif_addr_unlock_bh(local->mdev); | |
524 | ||
525 | /* TODO: start scan as soon as all nullfunc frames are ACKed */ | |
526 | queue_delayed_work(local->hw.workqueue, &local->scan_work, | |
527 | IEEE80211_CHANNEL_TIME); | |
528 | ||
529 | return 0; | |
530 | } | |
531 | ||
532 | ||
c2b13452 | 533 | int ieee80211_request_scan(struct ieee80211_sub_if_data *sdata, |
2a519311 | 534 | struct cfg80211_scan_request *req) |
0a51b27e | 535 | { |
0a51b27e | 536 | struct ieee80211_local *local = sdata->local; |
46900298 | 537 | struct ieee80211_if_managed *ifmgd; |
0a51b27e | 538 | |
2a519311 JB |
539 | if (!req) |
540 | return -EINVAL; | |
541 | ||
542 | if (local->scan_req && local->scan_req != req) | |
543 | return -EBUSY; | |
544 | ||
545 | local->scan_req = req; | |
546 | ||
05c914fe | 547 | if (sdata->vif.type != NL80211_IFTYPE_STATION) |
2a519311 | 548 | return ieee80211_start_scan(sdata, req); |
0a51b27e | 549 | |
9116dd01 JB |
550 | /* |
551 | * STA has a state machine that might need to defer scanning | |
552 | * while it's trying to associate/authenticate, therefore we | |
553 | * queue it up to the state machine in that case. | |
554 | */ | |
555 | ||
c2b13452 | 556 | if (local->sw_scanning || local->hw_scanning) { |
0a51b27e JB |
557 | if (local->scan_sdata == sdata) |
558 | return 0; | |
559 | return -EBUSY; | |
560 | } | |
561 | ||
46900298 JB |
562 | ifmgd = &sdata->u.mgd; |
563 | set_bit(IEEE80211_STA_REQ_SCAN, &ifmgd->request); | |
564 | queue_work(local->hw.workqueue, &ifmgd->work); | |
9116dd01 | 565 | |
0a51b27e JB |
566 | return 0; |
567 | } |