scan.c 18 KB

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