htcleo: add Cotulla's fixes for non-android touchscreen!
[htc-linux.git] / net / mac80211 / scan.c
blob1a4190947970b45f3f945ce7ddafceeb91f3fad9
1 /*
2 * Scanning implementation
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>
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.
15 /* TODO: figure out how to avoid that the "current BSS" expires */
17 #include <linux/wireless.h>
18 #include <linux/if_arp.h>
19 #include <linux/rtnetlink.h>
20 #include <net/mac80211.h>
22 #include "ieee80211_i.h"
23 #include "driver-ops.h"
24 #include "mesh.h"
26 #define IEEE80211_PROBE_DELAY (HZ / 33)
27 #define IEEE80211_CHANNEL_TIME (HZ / 33)
28 #define IEEE80211_PASSIVE_CHANNEL_TIME (HZ / 8)
30 struct ieee80211_bss *
31 ieee80211_rx_bss_get(struct ieee80211_local *local, u8 *bssid, int freq,
32 u8 *ssid, u8 ssid_len)
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);
41 static void ieee80211_rx_bss_free(struct cfg80211_bss *cbss)
43 struct ieee80211_bss *bss = (void *)cbss;
45 kfree(bss_mesh_id(bss));
46 kfree(bss_mesh_cfg(bss));
49 void ieee80211_rx_bss_put(struct ieee80211_local *local,
50 struct ieee80211_bss *bss)
52 cfg80211_put_bss((struct cfg80211_bss *)bss);
55 struct ieee80211_bss *
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,
61 struct ieee80211_channel *channel,
62 bool beacon)
64 struct ieee80211_bss *bss;
65 int clen;
66 s32 signal = 0;
68 if (local->hw.flags & IEEE80211_HW_SIGNAL_DBM)
69 signal = rx_status->signal * 100;
70 else if (local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC)
71 signal = (rx_status->signal * 100) / local->hw.max_signal;
73 bss = (void *)cfg80211_inform_bss_frame(local->hw.wiphy, channel,
74 mgmt, len, signal, GFP_ATOMIC);
76 if (!bss)
77 return NULL;
79 bss->cbss.free_priv = ieee80211_rx_bss_free;
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;
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;
93 /* set default value for buggy AP/no TIM element */
94 if (bss->dtim_period == 0)
95 bss->dtim_period = 1;
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;
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;
115 bss->wmm_used = elems->wmm_param || elems->wmm_info;
117 if (!beacon)
118 bss->last_probe_resp = jiffies;
120 return bss;
123 ieee80211_rx_result
124 ieee80211_scan_rx(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb)
126 struct ieee80211_rx_status *rx_status = IEEE80211_SKB_RXCB(skb);
127 struct ieee80211_mgmt *mgmt;
128 struct ieee80211_bss *bss;
129 u8 *elements;
130 struct ieee80211_channel *channel;
131 size_t baselen;
132 int freq;
133 __le16 fc;
134 bool presp, beacon = false;
135 struct ieee802_11_elems elems;
137 if (skb->len < 2)
138 return RX_DROP_UNUSABLE;
140 mgmt = (struct ieee80211_mgmt *) skb->data;
141 fc = mgmt->frame_control;
143 if (ieee80211_is_ctl(fc))
144 return RX_CONTINUE;
146 if (skb->len < 24)
147 return RX_DROP_MONITOR;
149 presp = ieee80211_is_probe_resp(fc);
150 if (presp) {
151 /* ignore ProbeResp to foreign address */
152 if (memcmp(mgmt->da, sdata->dev->dev_addr, ETH_ALEN))
153 return RX_DROP_MONITOR;
155 presp = true;
156 elements = mgmt->u.probe_resp.variable;
157 baselen = offsetof(struct ieee80211_mgmt, u.probe_resp.variable);
158 } else {
159 beacon = ieee80211_is_beacon(fc);
160 baselen = offsetof(struct ieee80211_mgmt, u.beacon.variable);
161 elements = mgmt->u.beacon.variable;
164 if (!presp && !beacon)
165 return RX_CONTINUE;
167 if (baselen > skb->len)
168 return RX_DROP_MONITOR;
170 ieee802_11_parse_elems(elements, skb->len - baselen, &elems);
172 if (elems.ds_params && elems.ds_params_len == 1)
173 freq = ieee80211_channel_to_frequency(elems.ds_params[0]);
174 else
175 freq = rx_status->freq;
177 channel = ieee80211_get_channel(sdata->local->hw.wiphy, freq);
179 if (!channel || channel->flags & IEEE80211_CHAN_DISABLED)
180 return RX_DROP_MONITOR;
182 bss = ieee80211_bss_info_update(sdata->local, rx_status,
183 mgmt, skb->len, &elems,
184 channel, beacon);
185 if (bss)
186 ieee80211_rx_bss_put(sdata->local, bss);
188 dev_kfree_skb(skb);
189 return RX_QUEUED;
193 * inform AP that we will go to sleep so that it will buffer the frames
194 * while we scan
196 static void ieee80211_scan_ps_enable(struct ieee80211_sub_if_data *sdata)
198 struct ieee80211_local *local = sdata->local;
200 local->scan_ps_enabled = false;
202 /* FIXME: what to do when local->pspolling is true? */
204 del_timer_sync(&local->dynamic_ps_timer);
205 cancel_work_sync(&local->dynamic_ps_enable_work);
207 if (local->hw.conf.flags & IEEE80211_CONF_PS) {
208 local->scan_ps_enabled = true;
209 local->hw.conf.flags &= ~IEEE80211_CONF_PS;
210 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
213 if (!(local->scan_ps_enabled) ||
214 !(local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK))
216 * If power save was enabled, no need to send a nullfunc
217 * frame because AP knows that we are sleeping. But if the
218 * hardware is creating the nullfunc frame for power save
219 * status (ie. IEEE80211_HW_PS_NULLFUNC_STACK is not
220 * enabled) and power save was enabled, the firmware just
221 * sent a null frame with power save disabled. So we need
222 * to send a new nullfunc frame to inform the AP that we
223 * are again sleeping.
225 ieee80211_send_nullfunc(local, sdata, 1);
228 /* inform AP that we are awake again, unless power save is enabled */
229 static void ieee80211_scan_ps_disable(struct ieee80211_sub_if_data *sdata)
231 struct ieee80211_local *local = sdata->local;
233 if (!local->ps_sdata)
234 ieee80211_send_nullfunc(local, sdata, 0);
235 else if (local->scan_ps_enabled) {
237 * In !IEEE80211_HW_PS_NULLFUNC_STACK case the hardware
238 * will send a nullfunc frame with the powersave bit set
239 * even though the AP already knows that we are sleeping.
240 * This could be avoided by sending a null frame with power
241 * save bit disabled before enabling the power save, but
242 * this doesn't gain anything.
244 * When IEEE80211_HW_PS_NULLFUNC_STACK is enabled, no need
245 * to send a nullfunc frame because AP already knows that
246 * we are sleeping, let's just enable power save mode in
247 * hardware.
249 local->hw.conf.flags |= IEEE80211_CONF_PS;
250 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
251 } else if (local->hw.conf.dynamic_ps_timeout > 0) {
253 * If IEEE80211_CONF_PS was not set and the dynamic_ps_timer
254 * had been running before leaving the operating channel,
255 * restart the timer now and send a nullfunc frame to inform
256 * the AP that we are awake.
258 ieee80211_send_nullfunc(local, sdata, 0);
259 mod_timer(&local->dynamic_ps_timer, jiffies +
260 msecs_to_jiffies(local->hw.conf.dynamic_ps_timeout));
264 static void ieee80211_restore_scan_ies(struct ieee80211_local *local)
266 kfree(local->scan_req->ie);
267 local->scan_req->ie = local->orig_ies;
268 local->scan_req->ie_len = local->orig_ies_len;
271 void ieee80211_scan_completed(struct ieee80211_hw *hw, bool aborted)
273 struct ieee80211_local *local = hw_to_local(hw);
274 struct ieee80211_sub_if_data *sdata;
275 bool was_hw_scan;
277 mutex_lock(&local->scan_mtx);
280 * It's ok to abort a not-yet-running scan (that
281 * we have one at all will be verified by checking
282 * local->scan_req next), but not to complete it
283 * successfully.
285 if (WARN_ON(!local->scanning && !aborted))
286 aborted = true;
288 if (WARN_ON(!local->scan_req)) {
289 mutex_unlock(&local->scan_mtx);
290 return;
293 if (test_bit(SCAN_HW_SCANNING, &local->scanning))
294 ieee80211_restore_scan_ies(local);
296 if (local->scan_req != local->int_scan_req)
297 cfg80211_scan_done(local->scan_req, aborted);
298 local->scan_req = NULL;
299 local->scan_sdata = NULL;
301 was_hw_scan = test_bit(SCAN_HW_SCANNING, &local->scanning);
302 local->scanning = 0;
303 local->scan_channel = NULL;
305 /* we only have to protect scan_req and hw/sw scan */
306 mutex_unlock(&local->scan_mtx);
308 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_CHANNEL);
309 if (was_hw_scan)
310 goto done;
312 ieee80211_configure_filter(local);
314 drv_sw_scan_complete(local);
316 mutex_lock(&local->iflist_mtx);
317 list_for_each_entry(sdata, &local->interfaces, list) {
318 if (!netif_running(sdata->dev))
319 continue;
321 /* Tell AP we're back */
322 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
323 if (sdata->u.mgd.associated) {
324 ieee80211_scan_ps_disable(sdata);
325 netif_tx_wake_all_queues(sdata->dev);
327 } else
328 netif_tx_wake_all_queues(sdata->dev);
330 /* re-enable beaconing */
331 if (sdata->vif.type == NL80211_IFTYPE_AP ||
332 sdata->vif.type == NL80211_IFTYPE_ADHOC ||
333 sdata->vif.type == NL80211_IFTYPE_MESH_POINT)
334 ieee80211_bss_info_change_notify(
335 sdata, BSS_CHANGED_BEACON_ENABLED);
337 mutex_unlock(&local->iflist_mtx);
339 done:
340 ieee80211_recalc_idle(local);
341 ieee80211_mlme_notify_scan_completed(local);
342 ieee80211_ibss_notify_scan_completed(local);
343 ieee80211_mesh_notify_scan_completed(local);
345 EXPORT_SYMBOL(ieee80211_scan_completed);
347 static int ieee80211_start_sw_scan(struct ieee80211_local *local)
349 struct ieee80211_sub_if_data *sdata;
352 * Hardware/driver doesn't support hw_scan, so use software
353 * scanning instead. First send a nullfunc frame with power save
354 * bit on so that AP will buffer the frames for us while we are not
355 * listening, then send probe requests to each channel and wait for
356 * the responses. After all channels are scanned, tune back to the
357 * original channel and send a nullfunc frame with power save bit
358 * off to trigger the AP to send us all the buffered frames.
360 * Note that while local->sw_scanning is true everything else but
361 * nullfunc frames and probe requests will be dropped in
362 * ieee80211_tx_h_check_assoc().
364 drv_sw_scan_start(local);
366 mutex_lock(&local->iflist_mtx);
367 list_for_each_entry(sdata, &local->interfaces, list) {
368 if (!netif_running(sdata->dev))
369 continue;
371 /* disable beaconing */
372 if (sdata->vif.type == NL80211_IFTYPE_AP ||
373 sdata->vif.type == NL80211_IFTYPE_ADHOC ||
374 sdata->vif.type == NL80211_IFTYPE_MESH_POINT)
375 ieee80211_bss_info_change_notify(
376 sdata, BSS_CHANGED_BEACON_ENABLED);
379 * only handle non-STA interfaces here, STA interfaces
380 * are handled in the scan state machine
382 if (sdata->vif.type != NL80211_IFTYPE_STATION)
383 netif_tx_stop_all_queues(sdata->dev);
385 mutex_unlock(&local->iflist_mtx);
387 local->next_scan_state = SCAN_DECISION;
388 local->scan_channel_idx = 0;
390 ieee80211_configure_filter(local);
392 /* TODO: start scan as soon as all nullfunc frames are ACKed */
393 ieee80211_queue_delayed_work(&local->hw,
394 &local->scan_work,
395 IEEE80211_CHANNEL_TIME);
397 return 0;
401 static int __ieee80211_start_scan(struct ieee80211_sub_if_data *sdata,
402 struct cfg80211_scan_request *req)
404 struct ieee80211_local *local = sdata->local;
405 struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
406 int rc;
408 if (local->scan_req)
409 return -EBUSY;
411 if (local->ops->hw_scan) {
412 u8 *ies;
413 int ielen;
415 ies = kmalloc(2 + IEEE80211_MAX_SSID_LEN +
416 local->scan_ies_len + req->ie_len, GFP_KERNEL);
417 if (!ies)
418 return -ENOMEM;
420 ielen = ieee80211_build_preq_ies(local, ies,
421 req->ie, req->ie_len);
422 local->orig_ies = req->ie;
423 local->orig_ies_len = req->ie_len;
424 req->ie = ies;
425 req->ie_len = ielen;
428 local->scan_req = req;
429 local->scan_sdata = sdata;
431 if (req != local->int_scan_req &&
432 sdata->vif.type == NL80211_IFTYPE_STATION &&
433 !list_empty(&ifmgd->work_list)) {
434 /* actually wait for the work it's doing to finish/time out */
435 set_bit(IEEE80211_STA_REQ_SCAN, &ifmgd->request);
436 return 0;
439 if (local->ops->hw_scan)
440 __set_bit(SCAN_HW_SCANNING, &local->scanning);
441 else
442 __set_bit(SCAN_SW_SCANNING, &local->scanning);
444 * Kicking off the scan need not be protected,
445 * only the scan variable stuff, since now
446 * local->scan_req is assigned and other callers
447 * will abort their scan attempts.
449 * This avoids getting a scan_mtx -> iflist_mtx
450 * dependency, so that the scan completed calls
451 * have more locking freedom.
454 ieee80211_recalc_idle(local);
455 mutex_unlock(&local->scan_mtx);
457 if (local->ops->hw_scan)
458 rc = drv_hw_scan(local, local->scan_req);
459 else
460 rc = ieee80211_start_sw_scan(local);
462 mutex_lock(&local->scan_mtx);
464 if (rc) {
465 if (local->ops->hw_scan)
466 ieee80211_restore_scan_ies(local);
467 local->scanning = 0;
469 ieee80211_recalc_idle(local);
471 local->scan_req = NULL;
472 local->scan_sdata = NULL;
475 return rc;
478 static int ieee80211_scan_state_decision(struct ieee80211_local *local,
479 unsigned long *next_delay)
481 bool associated = false;
482 struct ieee80211_sub_if_data *sdata;
484 /* if no more bands/channels left, complete scan and advance to the idle state */
485 if (local->scan_channel_idx >= local->scan_req->n_channels) {
486 ieee80211_scan_completed(&local->hw, false);
487 return 1;
490 /* check if at least one STA interface is associated */
491 mutex_lock(&local->iflist_mtx);
492 list_for_each_entry(sdata, &local->interfaces, list) {
493 if (!netif_running(sdata->dev))
494 continue;
496 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
497 if (sdata->u.mgd.associated) {
498 associated = true;
499 break;
503 mutex_unlock(&local->iflist_mtx);
505 if (local->scan_channel) {
507 * we're currently scanning a different channel, let's
508 * switch back to the operating channel now if at least
509 * one interface is associated. Otherwise just scan the
510 * next channel
512 if (associated)
513 local->next_scan_state = SCAN_ENTER_OPER_CHANNEL;
514 else
515 local->next_scan_state = SCAN_SET_CHANNEL;
516 } else {
518 * we're on the operating channel currently, let's
519 * leave that channel now to scan another one
521 local->next_scan_state = SCAN_LEAVE_OPER_CHANNEL;
524 *next_delay = 0;
525 return 0;
528 static void ieee80211_scan_state_leave_oper_channel(struct ieee80211_local *local,
529 unsigned long *next_delay)
531 struct ieee80211_sub_if_data *sdata;
534 * notify the AP about us leaving the channel and stop all STA interfaces
536 mutex_lock(&local->iflist_mtx);
537 list_for_each_entry(sdata, &local->interfaces, list) {
538 if (!netif_running(sdata->dev))
539 continue;
541 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
542 netif_tx_stop_all_queues(sdata->dev);
543 if (sdata->u.mgd.associated)
544 ieee80211_scan_ps_enable(sdata);
547 mutex_unlock(&local->iflist_mtx);
549 __set_bit(SCAN_OFF_CHANNEL, &local->scanning);
551 /* advance to the next channel to be scanned */
552 *next_delay = HZ / 10;
553 local->next_scan_state = SCAN_SET_CHANNEL;
556 static void ieee80211_scan_state_enter_oper_channel(struct ieee80211_local *local,
557 unsigned long *next_delay)
559 struct ieee80211_sub_if_data *sdata = local->scan_sdata;
561 /* switch back to the operating channel */
562 local->scan_channel = NULL;
563 ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_CHANNEL);
566 * notify the AP about us being back and restart all STA interfaces
568 mutex_lock(&local->iflist_mtx);
569 list_for_each_entry(sdata, &local->interfaces, list) {
570 if (!netif_running(sdata->dev))
571 continue;
573 /* Tell AP we're back */
574 if (sdata->vif.type == NL80211_IFTYPE_STATION) {
575 if (sdata->u.mgd.associated)
576 ieee80211_scan_ps_disable(sdata);
577 netif_tx_wake_all_queues(sdata->dev);
580 mutex_unlock(&local->iflist_mtx);
582 __clear_bit(SCAN_OFF_CHANNEL, &local->scanning);
584 *next_delay = HZ / 5;
585 local->next_scan_state = SCAN_DECISION;
588 static void ieee80211_scan_state_set_channel(struct ieee80211_local *local,
589 unsigned long *next_delay)
591 int skip;
592 struct ieee80211_channel *chan;
593 struct ieee80211_sub_if_data *sdata = local->scan_sdata;
595 skip = 0;
596 chan = local->scan_req->channels[local->scan_channel_idx];
598 if (chan->flags & IEEE80211_CHAN_DISABLED ||
599 (sdata->vif.type == NL80211_IFTYPE_ADHOC &&
600 chan->flags & IEEE80211_CHAN_NO_IBSS))
601 skip = 1;
603 if (!skip) {
604 local->scan_channel = chan;
605 if (ieee80211_hw_config(local,
606 IEEE80211_CONF_CHANGE_CHANNEL))
607 skip = 1;
610 /* advance state machine to next channel/band */
611 local->scan_channel_idx++;
613 if (skip) {
614 /* if we skip this channel return to the decision state */
615 local->next_scan_state = SCAN_DECISION;
616 return;
620 * Probe delay is used to update the NAV, cf. 11.1.3.2.2
621 * (which unfortunately doesn't say _why_ step a) is done,
622 * but it waits for the probe delay or until a frame is
623 * received - and the received frame would update the NAV).
624 * For now, we do not support waiting until a frame is
625 * received.
627 * In any case, it is not necessary for a passive scan.
629 if (chan->flags & IEEE80211_CHAN_PASSIVE_SCAN ||
630 !local->scan_req->n_ssids) {
631 *next_delay = IEEE80211_PASSIVE_CHANNEL_TIME;
632 local->next_scan_state = SCAN_DECISION;
633 return;
636 /* active scan, send probes */
637 *next_delay = IEEE80211_PROBE_DELAY;
638 local->next_scan_state = SCAN_SEND_PROBE;
641 static void ieee80211_scan_state_send_probe(struct ieee80211_local *local,
642 unsigned long *next_delay)
644 int i;
645 struct ieee80211_sub_if_data *sdata = local->scan_sdata;
647 for (i = 0; i < local->scan_req->n_ssids; i++)
648 ieee80211_send_probe_req(
649 sdata, NULL,
650 local->scan_req->ssids[i].ssid,
651 local->scan_req->ssids[i].ssid_len,
652 local->scan_req->ie, local->scan_req->ie_len);
655 * After sending probe requests, wait for probe responses
656 * on the channel.
658 *next_delay = IEEE80211_CHANNEL_TIME;
659 local->next_scan_state = SCAN_DECISION;
662 void ieee80211_scan_work(struct work_struct *work)
664 struct ieee80211_local *local =
665 container_of(work, struct ieee80211_local, scan_work.work);
666 struct ieee80211_sub_if_data *sdata = local->scan_sdata;
667 unsigned long next_delay = 0;
669 mutex_lock(&local->scan_mtx);
670 if (!sdata || !local->scan_req) {
671 mutex_unlock(&local->scan_mtx);
672 return;
675 if (local->scan_req && !local->scanning) {
676 struct cfg80211_scan_request *req = local->scan_req;
677 int rc;
679 local->scan_req = NULL;
680 local->scan_sdata = NULL;
682 rc = __ieee80211_start_scan(sdata, req);
683 mutex_unlock(&local->scan_mtx);
685 if (rc)
686 ieee80211_scan_completed(&local->hw, true);
687 return;
690 mutex_unlock(&local->scan_mtx);
693 * Avoid re-scheduling when the sdata is going away.
695 if (!netif_running(sdata->dev)) {
696 ieee80211_scan_completed(&local->hw, true);
697 return;
701 * as long as no delay is required advance immediately
702 * without scheduling a new work
704 do {
705 switch (local->next_scan_state) {
706 case SCAN_DECISION:
707 if (ieee80211_scan_state_decision(local, &next_delay))
708 return;
709 break;
710 case SCAN_SET_CHANNEL:
711 ieee80211_scan_state_set_channel(local, &next_delay);
712 break;
713 case SCAN_SEND_PROBE:
714 ieee80211_scan_state_send_probe(local, &next_delay);
715 break;
716 case SCAN_LEAVE_OPER_CHANNEL:
717 ieee80211_scan_state_leave_oper_channel(local, &next_delay);
718 break;
719 case SCAN_ENTER_OPER_CHANNEL:
720 ieee80211_scan_state_enter_oper_channel(local, &next_delay);
721 break;
723 } while (next_delay == 0);
725 ieee80211_queue_delayed_work(&local->hw, &local->scan_work, next_delay);
728 int ieee80211_request_scan(struct ieee80211_sub_if_data *sdata,
729 struct cfg80211_scan_request *req)
731 int res;
733 mutex_lock(&sdata->local->scan_mtx);
734 res = __ieee80211_start_scan(sdata, req);
735 mutex_unlock(&sdata->local->scan_mtx);
737 return res;
740 int ieee80211_request_internal_scan(struct ieee80211_sub_if_data *sdata,
741 const u8 *ssid, u8 ssid_len)
743 struct ieee80211_local *local = sdata->local;
744 int ret = -EBUSY;
746 mutex_lock(&local->scan_mtx);
748 /* busy scanning */
749 if (local->scan_req)
750 goto unlock;
752 memcpy(local->int_scan_req->ssids[0].ssid, ssid, IEEE80211_MAX_SSID_LEN);
753 local->int_scan_req->ssids[0].ssid_len = ssid_len;
755 ret = __ieee80211_start_scan(sdata, sdata->local->int_scan_req);
756 unlock:
757 mutex_unlock(&local->scan_mtx);
758 return ret;
761 void ieee80211_scan_cancel(struct ieee80211_local *local)
763 bool abortscan;
765 cancel_delayed_work_sync(&local->scan_work);
768 * Only call this function when a scan can't be
769 * queued -- mostly at suspend under RTNL.
771 mutex_lock(&local->scan_mtx);
772 abortscan = test_bit(SCAN_SW_SCANNING, &local->scanning) ||
773 (!local->scanning && local->scan_req);
774 mutex_unlock(&local->scan_mtx);
776 if (abortscan)
777 ieee80211_scan_completed(&local->hw, true);