scan.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651
  1. /*
  2. * Scanning implementation
  3. *
  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. /* TODO: figure out how to avoid that the "current BSS" expires */
  15. #include <linux/wireless.h>
  16. #include <linux/if_arp.h>
  17. #include <linux/rtnetlink.h>
  18. #include <net/mac80211.h>
  19. #include <net/iw_handler.h>
  20. #include "ieee80211_i.h"
  21. #include "driver-ops.h"
  22. #include "mesh.h"
  23. #define IEEE80211_PROBE_DELAY (HZ / 33)
  24. #define IEEE80211_CHANNEL_TIME (HZ / 33)
  25. #define IEEE80211_PASSIVE_CHANNEL_TIME (HZ / 5)
  26. struct ieee80211_bss *
  27. ieee80211_rx_bss_get(struct ieee80211_local *local, u8 *bssid, int freq,
  28. u8 *ssid, u8 ssid_len)
  29. {
  30. return (void *)cfg80211_get_bss(local->hw.wiphy,
  31. ieee80211_get_channel(local->hw.wiphy,
  32. freq),
  33. bssid, ssid, ssid_len,
  34. 0, 0);
  35. }
  36. static void ieee80211_rx_bss_free(struct cfg80211_bss *cbss)
  37. {
  38. struct ieee80211_bss *bss = (void *)cbss;
  39. kfree(bss_mesh_id(bss));
  40. kfree(bss_mesh_cfg(bss));
  41. }
  42. void ieee80211_rx_bss_put(struct ieee80211_local *local,
  43. struct ieee80211_bss *bss)
  44. {
  45. cfg80211_put_bss((struct cfg80211_bss *)bss);
  46. }
  47. struct ieee80211_bss *
  48. ieee80211_bss_info_update(struct ieee80211_local *local,
  49. struct ieee80211_rx_status *rx_status,
  50. struct ieee80211_mgmt *mgmt,
  51. size_t len,
  52. struct ieee802_11_elems *elems,
  53. struct ieee80211_channel *channel,
  54. bool beacon)
  55. {
  56. struct ieee80211_bss *bss;
  57. int clen;
  58. s32 signal = 0;
  59. if (local->hw.flags & IEEE80211_HW_SIGNAL_DBM)
  60. signal = rx_status->signal * 100;
  61. else if (local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC)
  62. signal = (rx_status->signal * 100) / local->hw.max_signal;
  63. bss = (void *)cfg80211_inform_bss_frame(local->hw.wiphy, channel,
  64. mgmt, len, signal, GFP_ATOMIC);
  65. if (!bss)
  66. return NULL;
  67. bss->cbss.free_priv = ieee80211_rx_bss_free;
  68. /* save the ERP value so that it is available at association time */
  69. if (elems->erp_info && elems->erp_info_len >= 1) {
  70. bss->erp_value = elems->erp_info[0];
  71. bss->has_erp_value = 1;
  72. }
  73. if (elems->tim) {
  74. struct ieee80211_tim_ie *tim_ie =
  75. (struct ieee80211_tim_ie *)elems->tim;
  76. bss->dtim_period = tim_ie->dtim_period;
  77. }
  78. /* set default value for buggy APs */
  79. if (!elems->tim || bss->dtim_period == 0)
  80. bss->dtim_period = 1;
  81. bss->supp_rates_len = 0;
  82. if (elems->supp_rates) {
  83. clen = IEEE80211_MAX_SUPP_RATES - bss->supp_rates_len;
  84. if (clen > elems->supp_rates_len)
  85. clen = elems->supp_rates_len;
  86. memcpy(&bss->supp_rates[bss->supp_rates_len], elems->supp_rates,
  87. clen);
  88. bss->supp_rates_len += clen;
  89. }
  90. if (elems->ext_supp_rates) {
  91. clen = IEEE80211_MAX_SUPP_RATES - bss->supp_rates_len;
  92. if (clen > elems->ext_supp_rates_len)
  93. clen = elems->ext_supp_rates_len;
  94. memcpy(&bss->supp_rates[bss->supp_rates_len],
  95. elems->ext_supp_rates, clen);
  96. bss->supp_rates_len += clen;
  97. }
  98. bss->wmm_used = elems->wmm_param || elems->wmm_info;
  99. if (!beacon)
  100. bss->last_probe_resp = jiffies;
  101. return bss;
  102. }
  103. void ieee80211_rx_bss_remove(struct ieee80211_sub_if_data *sdata, u8 *bssid,
  104. int freq, u8 *ssid, u8 ssid_len)
  105. {
  106. struct ieee80211_bss *bss;
  107. struct ieee80211_local *local = sdata->local;
  108. bss = ieee80211_rx_bss_get(local, bssid, freq, ssid, ssid_len);
  109. if (bss) {
  110. cfg80211_unlink_bss(local->hw.wiphy, (void *)bss);
  111. ieee80211_rx_bss_put(local, bss);
  112. }
  113. }
  114. ieee80211_rx_result
  115. ieee80211_scan_rx(struct ieee80211_sub_if_data *sdata, struct sk_buff *skb,
  116. struct ieee80211_rx_status *rx_status)
  117. {
  118. struct ieee80211_mgmt *mgmt;
  119. struct ieee80211_bss *bss;
  120. u8 *elements;
  121. struct ieee80211_channel *channel;
  122. size_t baselen;
  123. int freq;
  124. __le16 fc;
  125. bool presp, beacon = false;
  126. struct ieee802_11_elems elems;
  127. if (skb->len < 2)
  128. return RX_DROP_UNUSABLE;
  129. mgmt = (struct ieee80211_mgmt *) skb->data;
  130. fc = mgmt->frame_control;
  131. if (ieee80211_is_ctl(fc))
  132. return RX_CONTINUE;
  133. if (skb->len < 24)
  134. return RX_DROP_MONITOR;
  135. presp = ieee80211_is_probe_resp(fc);
  136. if (presp) {
  137. /* ignore ProbeResp to foreign address */
  138. if (memcmp(mgmt->da, sdata->dev->dev_addr, ETH_ALEN))
  139. return RX_DROP_MONITOR;
  140. presp = true;
  141. elements = mgmt->u.probe_resp.variable;
  142. baselen = offsetof(struct ieee80211_mgmt, u.probe_resp.variable);
  143. } else {
  144. beacon = ieee80211_is_beacon(fc);
  145. baselen = offsetof(struct ieee80211_mgmt, u.beacon.variable);
  146. elements = mgmt->u.beacon.variable;
  147. }
  148. if (!presp && !beacon)
  149. return RX_CONTINUE;
  150. if (baselen > skb->len)
  151. return RX_DROP_MONITOR;
  152. ieee802_11_parse_elems(elements, skb->len - baselen, &elems);
  153. if (elems.ds_params && elems.ds_params_len == 1)
  154. freq = ieee80211_channel_to_frequency(elems.ds_params[0]);
  155. else
  156. freq = rx_status->freq;
  157. channel = ieee80211_get_channel(sdata->local->hw.wiphy, freq);
  158. if (!channel || channel->flags & IEEE80211_CHAN_DISABLED)
  159. return RX_DROP_MONITOR;
  160. bss = ieee80211_bss_info_update(sdata->local, rx_status,
  161. mgmt, skb->len, &elems,
  162. channel, beacon);
  163. if (bss)
  164. ieee80211_rx_bss_put(sdata->local, bss);
  165. dev_kfree_skb(skb);
  166. return RX_QUEUED;
  167. }
  168. /*
  169. * inform AP that we will go to sleep so that it will buffer the frames
  170. * while we scan
  171. */
  172. static void ieee80211_scan_ps_enable(struct ieee80211_sub_if_data *sdata)
  173. {
  174. struct ieee80211_local *local = sdata->local;
  175. bool ps = false;
  176. /* FIXME: what to do when local->pspolling is true? */
  177. del_timer_sync(&local->dynamic_ps_timer);
  178. cancel_work_sync(&local->dynamic_ps_enable_work);
  179. if (local->hw.conf.flags & IEEE80211_CONF_PS) {
  180. ps = true;
  181. local->hw.conf.flags &= ~IEEE80211_CONF_PS;
  182. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
  183. }
  184. if (!ps || !(local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK))
  185. /*
  186. * If power save was enabled, no need to send a nullfunc
  187. * frame because AP knows that we are sleeping. But if the
  188. * hardware is creating the nullfunc frame for power save
  189. * status (ie. IEEE80211_HW_PS_NULLFUNC_STACK is not
  190. * enabled) and power save was enabled, the firmware just
  191. * sent a null frame with power save disabled. So we need
  192. * to send a new nullfunc frame to inform the AP that we
  193. * are again sleeping.
  194. */
  195. ieee80211_send_nullfunc(local, sdata, 1);
  196. }
  197. /* inform AP that we are awake again, unless power save is enabled */
  198. static void ieee80211_scan_ps_disable(struct ieee80211_sub_if_data *sdata)
  199. {
  200. struct ieee80211_local *local = sdata->local;
  201. if (!local->ps_sdata)
  202. ieee80211_send_nullfunc(local, sdata, 0);
  203. else {
  204. /*
  205. * In !IEEE80211_HW_PS_NULLFUNC_STACK case the hardware
  206. * will send a nullfunc frame with the powersave bit set
  207. * even though the AP already knows that we are sleeping.
  208. * This could be avoided by sending a null frame with power
  209. * save bit disabled before enabling the power save, but
  210. * this doesn't gain anything.
  211. *
  212. * When IEEE80211_HW_PS_NULLFUNC_STACK is enabled, no need
  213. * to send a nullfunc frame because AP already knows that
  214. * we are sleeping, let's just enable power save mode in
  215. * hardware.
  216. */
  217. local->hw.conf.flags |= IEEE80211_CONF_PS;
  218. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
  219. }
  220. }
  221. static void ieee80211_restore_scan_ies(struct ieee80211_local *local)
  222. {
  223. kfree(local->scan_req->ie);
  224. local->scan_req->ie = local->orig_ies;
  225. local->scan_req->ie_len = local->orig_ies_len;
  226. }
  227. void ieee80211_scan_completed(struct ieee80211_hw *hw, bool aborted)
  228. {
  229. struct ieee80211_local *local = hw_to_local(hw);
  230. struct ieee80211_sub_if_data *sdata;
  231. bool was_hw_scan;
  232. mutex_lock(&local->scan_mtx);
  233. if (WARN_ON(!local->hw_scanning && !local->sw_scanning)) {
  234. mutex_unlock(&local->scan_mtx);
  235. return;
  236. }
  237. if (WARN_ON(!local->scan_req)) {
  238. mutex_unlock(&local->scan_mtx);
  239. return;
  240. }
  241. if (local->hw_scanning)
  242. ieee80211_restore_scan_ies(local);
  243. if (local->scan_req != &local->int_scan_req)
  244. cfg80211_scan_done(local->scan_req, aborted);
  245. local->scan_req = NULL;
  246. was_hw_scan = local->hw_scanning;
  247. local->hw_scanning = false;
  248. local->sw_scanning = false;
  249. local->scan_channel = NULL;
  250. /* we only have to protect scan_req and hw/sw scan */
  251. mutex_unlock(&local->scan_mtx);
  252. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_CHANNEL);
  253. if (was_hw_scan)
  254. goto done;
  255. netif_tx_lock_bh(local->mdev);
  256. netif_addr_lock(local->mdev);
  257. local->filter_flags &= ~FIF_BCN_PRBRESP_PROMISC;
  258. drv_configure_filter(local, FIF_BCN_PRBRESP_PROMISC,
  259. &local->filter_flags,
  260. local->mdev->mc_count,
  261. local->mdev->mc_list);
  262. netif_addr_unlock(local->mdev);
  263. netif_tx_unlock_bh(local->mdev);
  264. drv_sw_scan_complete(local);
  265. mutex_lock(&local->iflist_mtx);
  266. list_for_each_entry(sdata, &local->interfaces, list) {
  267. if (!netif_running(sdata->dev))
  268. continue;
  269. /* Tell AP we're back */
  270. if (sdata->vif.type == NL80211_IFTYPE_STATION) {
  271. if (sdata->u.mgd.flags & IEEE80211_STA_ASSOCIATED) {
  272. ieee80211_scan_ps_disable(sdata);
  273. netif_tx_wake_all_queues(sdata->dev);
  274. }
  275. } else
  276. netif_tx_wake_all_queues(sdata->dev);
  277. /* re-enable beaconing */
  278. if (sdata->vif.type == NL80211_IFTYPE_AP ||
  279. sdata->vif.type == NL80211_IFTYPE_ADHOC ||
  280. sdata->vif.type == NL80211_IFTYPE_MESH_POINT)
  281. ieee80211_bss_info_change_notify(
  282. sdata, BSS_CHANGED_BEACON_ENABLED);
  283. }
  284. mutex_unlock(&local->iflist_mtx);
  285. done:
  286. ieee80211_recalc_idle(local);
  287. ieee80211_mlme_notify_scan_completed(local);
  288. ieee80211_ibss_notify_scan_completed(local);
  289. ieee80211_mesh_notify_scan_completed(local);
  290. }
  291. EXPORT_SYMBOL(ieee80211_scan_completed);
  292. static int ieee80211_start_sw_scan(struct ieee80211_local *local)
  293. {
  294. struct ieee80211_sub_if_data *sdata;
  295. /*
  296. * Hardware/driver doesn't support hw_scan, so use software
  297. * scanning instead. First send a nullfunc frame with power save
  298. * bit on so that AP will buffer the frames for us while we are not
  299. * listening, then send probe requests to each channel and wait for
  300. * the responses. After all channels are scanned, tune back to the
  301. * original channel and send a nullfunc frame with power save bit
  302. * off to trigger the AP to send us all the buffered frames.
  303. *
  304. * Note that while local->sw_scanning is true everything else but
  305. * nullfunc frames and probe requests will be dropped in
  306. * ieee80211_tx_h_check_assoc().
  307. */
  308. drv_sw_scan_start(local);
  309. mutex_lock(&local->iflist_mtx);
  310. list_for_each_entry(sdata, &local->interfaces, list) {
  311. if (!netif_running(sdata->dev))
  312. continue;
  313. /* disable beaconing */
  314. if (sdata->vif.type == NL80211_IFTYPE_AP ||
  315. sdata->vif.type == NL80211_IFTYPE_ADHOC ||
  316. sdata->vif.type == NL80211_IFTYPE_MESH_POINT)
  317. ieee80211_bss_info_change_notify(
  318. sdata, BSS_CHANGED_BEACON_ENABLED);
  319. if (sdata->vif.type == NL80211_IFTYPE_STATION) {
  320. if (sdata->u.mgd.flags & IEEE80211_STA_ASSOCIATED) {
  321. netif_tx_stop_all_queues(sdata->dev);
  322. ieee80211_scan_ps_enable(sdata);
  323. }
  324. } else
  325. netif_tx_stop_all_queues(sdata->dev);
  326. }
  327. mutex_unlock(&local->iflist_mtx);
  328. local->scan_state = SCAN_SET_CHANNEL;
  329. local->scan_channel_idx = 0;
  330. netif_addr_lock_bh(local->mdev);
  331. local->filter_flags |= FIF_BCN_PRBRESP_PROMISC;
  332. drv_configure_filter(local, FIF_BCN_PRBRESP_PROMISC,
  333. &local->filter_flags,
  334. local->mdev->mc_count,
  335. local->mdev->mc_list);
  336. netif_addr_unlock_bh(local->mdev);
  337. /* TODO: start scan as soon as all nullfunc frames are ACKed */
  338. queue_delayed_work(local->hw.workqueue, &local->scan_work,
  339. IEEE80211_CHANNEL_TIME);
  340. return 0;
  341. }
  342. static int __ieee80211_start_scan(struct ieee80211_sub_if_data *sdata,
  343. struct cfg80211_scan_request *req)
  344. {
  345. struct ieee80211_local *local = sdata->local;
  346. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  347. int rc;
  348. if (local->scan_req)
  349. return -EBUSY;
  350. if (local->ops->hw_scan) {
  351. u8 *ies;
  352. int ielen;
  353. ies = kmalloc(2 + IEEE80211_MAX_SSID_LEN +
  354. local->scan_ies_len + req->ie_len, GFP_KERNEL);
  355. if (!ies)
  356. return -ENOMEM;
  357. ielen = ieee80211_build_preq_ies(local, ies,
  358. req->ie, req->ie_len);
  359. local->orig_ies = req->ie;
  360. local->orig_ies_len = req->ie_len;
  361. req->ie = ies;
  362. req->ie_len = ielen;
  363. }
  364. local->scan_req = req;
  365. local->scan_sdata = sdata;
  366. if (req != &local->int_scan_req &&
  367. sdata->vif.type == NL80211_IFTYPE_STATION &&
  368. (ifmgd->state == IEEE80211_STA_MLME_DIRECT_PROBE ||
  369. ifmgd->state == IEEE80211_STA_MLME_AUTHENTICATE ||
  370. ifmgd->state == IEEE80211_STA_MLME_ASSOCIATE)) {
  371. /* actually wait for the assoc to finish/time out */
  372. set_bit(IEEE80211_STA_REQ_SCAN, &ifmgd->request);
  373. return 0;
  374. }
  375. if (local->ops->hw_scan)
  376. local->hw_scanning = true;
  377. else
  378. local->sw_scanning = true;
  379. /*
  380. * Kicking off the scan need not be protected,
  381. * only the scan variable stuff, since now
  382. * local->scan_req is assigned and other callers
  383. * will abort their scan attempts.
  384. *
  385. * This avoids getting a scan_mtx -> iflist_mtx
  386. * dependency, so that the scan completed calls
  387. * have more locking freedom.
  388. */
  389. ieee80211_recalc_idle(local);
  390. mutex_unlock(&local->scan_mtx);
  391. if (local->ops->hw_scan)
  392. rc = drv_hw_scan(local, local->scan_req);
  393. else
  394. rc = ieee80211_start_sw_scan(local);
  395. mutex_lock(&local->scan_mtx);
  396. if (rc) {
  397. if (local->ops->hw_scan) {
  398. local->hw_scanning = false;
  399. ieee80211_restore_scan_ies(local);
  400. } else
  401. local->sw_scanning = false;
  402. ieee80211_recalc_idle(local);
  403. local->scan_req = NULL;
  404. local->scan_sdata = NULL;
  405. }
  406. return rc;
  407. }
  408. void ieee80211_scan_work(struct work_struct *work)
  409. {
  410. struct ieee80211_local *local =
  411. container_of(work, struct ieee80211_local, scan_work.work);
  412. struct ieee80211_sub_if_data *sdata = local->scan_sdata;
  413. struct ieee80211_channel *chan;
  414. int skip, i;
  415. unsigned long next_delay = 0;
  416. mutex_lock(&local->scan_mtx);
  417. if (!sdata || !local->scan_req) {
  418. mutex_unlock(&local->scan_mtx);
  419. return;
  420. }
  421. if (local->scan_req && !(local->sw_scanning || local->hw_scanning)) {
  422. struct cfg80211_scan_request *req = local->scan_req;
  423. int rc;
  424. local->scan_req = NULL;
  425. rc = __ieee80211_start_scan(sdata, req);
  426. mutex_unlock(&local->scan_mtx);
  427. if (rc)
  428. ieee80211_scan_completed(&local->hw, true);
  429. return;
  430. }
  431. mutex_unlock(&local->scan_mtx);
  432. /*
  433. * Avoid re-scheduling when the sdata is going away.
  434. */
  435. if (!netif_running(sdata->dev)) {
  436. ieee80211_scan_completed(&local->hw, true);
  437. return;
  438. }
  439. switch (local->scan_state) {
  440. case SCAN_SET_CHANNEL:
  441. /* if no more bands/channels left, complete scan */
  442. if (local->scan_channel_idx >= local->scan_req->n_channels) {
  443. ieee80211_scan_completed(&local->hw, false);
  444. return;
  445. }
  446. skip = 0;
  447. chan = local->scan_req->channels[local->scan_channel_idx];
  448. if (chan->flags & IEEE80211_CHAN_DISABLED ||
  449. (sdata->vif.type == NL80211_IFTYPE_ADHOC &&
  450. chan->flags & IEEE80211_CHAN_NO_IBSS))
  451. skip = 1;
  452. if (!skip) {
  453. local->scan_channel = chan;
  454. if (ieee80211_hw_config(local,
  455. IEEE80211_CONF_CHANGE_CHANNEL))
  456. skip = 1;
  457. }
  458. /* advance state machine to next channel/band */
  459. local->scan_channel_idx++;
  460. if (skip)
  461. break;
  462. /*
  463. * Probe delay is used to update the NAV, cf. 11.1.3.2.2
  464. * (which unfortunately doesn't say _why_ step a) is done,
  465. * but it waits for the probe delay or until a frame is
  466. * received - and the received frame would update the NAV).
  467. * For now, we do not support waiting until a frame is
  468. * received.
  469. *
  470. * In any case, it is not necessary for a passive scan.
  471. */
  472. if (chan->flags & IEEE80211_CHAN_PASSIVE_SCAN ||
  473. !local->scan_req->n_ssids) {
  474. next_delay = IEEE80211_PASSIVE_CHANNEL_TIME;
  475. break;
  476. }
  477. next_delay = IEEE80211_PROBE_DELAY;
  478. local->scan_state = SCAN_SEND_PROBE;
  479. break;
  480. case SCAN_SEND_PROBE:
  481. for (i = 0; i < local->scan_req->n_ssids; i++)
  482. ieee80211_send_probe_req(
  483. sdata, NULL,
  484. local->scan_req->ssids[i].ssid,
  485. local->scan_req->ssids[i].ssid_len,
  486. local->scan_req->ie, local->scan_req->ie_len);
  487. /*
  488. * After sending probe requests, wait for probe responses
  489. * on the channel.
  490. */
  491. next_delay = IEEE80211_CHANNEL_TIME;
  492. local->scan_state = SCAN_SET_CHANNEL;
  493. break;
  494. }
  495. queue_delayed_work(local->hw.workqueue, &local->scan_work,
  496. next_delay);
  497. }
  498. int ieee80211_request_scan(struct ieee80211_sub_if_data *sdata,
  499. struct cfg80211_scan_request *req)
  500. {
  501. int res;
  502. mutex_lock(&sdata->local->scan_mtx);
  503. res = __ieee80211_start_scan(sdata, req);
  504. mutex_unlock(&sdata->local->scan_mtx);
  505. return res;
  506. }
  507. int ieee80211_request_internal_scan(struct ieee80211_sub_if_data *sdata,
  508. const u8 *ssid, u8 ssid_len)
  509. {
  510. struct ieee80211_local *local = sdata->local;
  511. int ret = -EBUSY;
  512. mutex_lock(&local->scan_mtx);
  513. /* busy scanning */
  514. if (local->scan_req)
  515. goto unlock;
  516. memcpy(local->int_scan_req.ssids[0].ssid, ssid, IEEE80211_MAX_SSID_LEN);
  517. local->int_scan_req.ssids[0].ssid_len = ssid_len;
  518. ret = __ieee80211_start_scan(sdata, &sdata->local->int_scan_req);
  519. unlock:
  520. mutex_unlock(&local->scan_mtx);
  521. return ret;
  522. }
  523. void ieee80211_scan_cancel(struct ieee80211_local *local)
  524. {
  525. bool swscan;
  526. cancel_delayed_work_sync(&local->scan_work);
  527. /*
  528. * Only call this function when a scan can't be
  529. * queued -- mostly at suspend under RTNL.
  530. */
  531. mutex_lock(&local->scan_mtx);
  532. swscan = local->sw_scanning;
  533. mutex_unlock(&local->scan_mtx);
  534. if (swscan)
  535. ieee80211_scan_completed(&local->hw, true);
  536. }