scan.c 17 KB

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