scan.c 18 KB

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