scan.c 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273
  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. * Copyright 2013-2015 Intel Mobile Communications GmbH
  10. * Copyright 2016 Intel Deutschland GmbH
  11. *
  12. * This program is free software; you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License version 2 as
  14. * published by the Free Software Foundation.
  15. */
  16. #include <linux/if_arp.h>
  17. #include <linux/etherdevice.h>
  18. #include <linux/rtnetlink.h>
  19. #include <net/sch_generic.h>
  20. #include <linux/slab.h>
  21. #include <linux/export.h>
  22. #include <net/mac80211.h>
  23. #include "ieee80211_i.h"
  24. #include "driver-ops.h"
  25. #include "mesh.h"
  26. #define IEEE80211_PROBE_DELAY (HZ / 33)
  27. #define IEEE80211_CHANNEL_TIME (HZ / 33)
  28. #define IEEE80211_PASSIVE_CHANNEL_TIME (HZ / 9)
  29. void ieee80211_rx_bss_put(struct ieee80211_local *local,
  30. struct ieee80211_bss *bss)
  31. {
  32. if (!bss)
  33. return;
  34. cfg80211_put_bss(local->hw.wiphy,
  35. container_of((void *)bss, struct cfg80211_bss, priv));
  36. }
  37. static bool is_uapsd_supported(struct ieee802_11_elems *elems)
  38. {
  39. u8 qos_info;
  40. if (elems->wmm_info && elems->wmm_info_len == 7
  41. && elems->wmm_info[5] == 1)
  42. qos_info = elems->wmm_info[6];
  43. else if (elems->wmm_param && elems->wmm_param_len == 24
  44. && elems->wmm_param[5] == 1)
  45. qos_info = elems->wmm_param[6];
  46. else
  47. /* no valid wmm information or parameter element found */
  48. return false;
  49. return qos_info & IEEE80211_WMM_IE_AP_QOSINFO_UAPSD;
  50. }
  51. struct ieee80211_bss *
  52. ieee80211_bss_info_update(struct ieee80211_local *local,
  53. struct ieee80211_rx_status *rx_status,
  54. struct ieee80211_mgmt *mgmt, size_t len,
  55. struct ieee802_11_elems *elems,
  56. struct ieee80211_channel *channel)
  57. {
  58. bool beacon = ieee80211_is_beacon(mgmt->frame_control);
  59. struct cfg80211_bss *cbss;
  60. struct ieee80211_bss *bss;
  61. int clen, srlen;
  62. struct cfg80211_inform_bss bss_meta = {
  63. .boottime_ns = rx_status->boottime_ns,
  64. };
  65. bool signal_valid;
  66. struct ieee80211_sub_if_data *scan_sdata;
  67. if (ieee80211_hw_check(&local->hw, SIGNAL_DBM))
  68. bss_meta.signal = rx_status->signal * 100;
  69. else if (ieee80211_hw_check(&local->hw, SIGNAL_UNSPEC))
  70. bss_meta.signal = (rx_status->signal * 100) / local->hw.max_signal;
  71. bss_meta.scan_width = NL80211_BSS_CHAN_WIDTH_20;
  72. if (rx_status->flag & RX_FLAG_5MHZ)
  73. bss_meta.scan_width = NL80211_BSS_CHAN_WIDTH_5;
  74. if (rx_status->flag & RX_FLAG_10MHZ)
  75. bss_meta.scan_width = NL80211_BSS_CHAN_WIDTH_10;
  76. bss_meta.chan = channel;
  77. rcu_read_lock();
  78. scan_sdata = rcu_dereference(local->scan_sdata);
  79. if (scan_sdata && scan_sdata->vif.type == NL80211_IFTYPE_STATION &&
  80. scan_sdata->vif.bss_conf.assoc &&
  81. ieee80211_have_rx_timestamp(rx_status)) {
  82. bss_meta.parent_tsf =
  83. ieee80211_calculate_rx_timestamp(local, rx_status,
  84. len + FCS_LEN, 24);
  85. ether_addr_copy(bss_meta.parent_bssid,
  86. scan_sdata->vif.bss_conf.bssid);
  87. }
  88. rcu_read_unlock();
  89. cbss = cfg80211_inform_bss_frame_data(local->hw.wiphy, &bss_meta,
  90. mgmt, len, GFP_ATOMIC);
  91. if (!cbss)
  92. return NULL;
  93. /* In case the signal is invalid update the status */
  94. signal_valid = abs(channel->center_freq - cbss->channel->center_freq)
  95. <= local->hw.wiphy->max_adj_channel_rssi_comp;
  96. if (!signal_valid)
  97. rx_status->flag |= RX_FLAG_NO_SIGNAL_VAL;
  98. bss = (void *)cbss->priv;
  99. if (beacon)
  100. bss->device_ts_beacon = rx_status->device_timestamp;
  101. else
  102. bss->device_ts_presp = rx_status->device_timestamp;
  103. if (elems->parse_error) {
  104. if (beacon)
  105. bss->corrupt_data |= IEEE80211_BSS_CORRUPT_BEACON;
  106. else
  107. bss->corrupt_data |= IEEE80211_BSS_CORRUPT_PROBE_RESP;
  108. } else {
  109. if (beacon)
  110. bss->corrupt_data &= ~IEEE80211_BSS_CORRUPT_BEACON;
  111. else
  112. bss->corrupt_data &= ~IEEE80211_BSS_CORRUPT_PROBE_RESP;
  113. }
  114. /* save the ERP value so that it is available at association time */
  115. if (elems->erp_info && (!elems->parse_error ||
  116. !(bss->valid_data & IEEE80211_BSS_VALID_ERP))) {
  117. bss->erp_value = elems->erp_info[0];
  118. bss->has_erp_value = true;
  119. if (!elems->parse_error)
  120. bss->valid_data |= IEEE80211_BSS_VALID_ERP;
  121. }
  122. /* replace old supported rates if we get new values */
  123. if (!elems->parse_error ||
  124. !(bss->valid_data & IEEE80211_BSS_VALID_RATES)) {
  125. srlen = 0;
  126. if (elems->supp_rates) {
  127. clen = IEEE80211_MAX_SUPP_RATES;
  128. if (clen > elems->supp_rates_len)
  129. clen = elems->supp_rates_len;
  130. memcpy(bss->supp_rates, elems->supp_rates, clen);
  131. srlen += clen;
  132. }
  133. if (elems->ext_supp_rates) {
  134. clen = IEEE80211_MAX_SUPP_RATES - srlen;
  135. if (clen > elems->ext_supp_rates_len)
  136. clen = elems->ext_supp_rates_len;
  137. memcpy(bss->supp_rates + srlen, elems->ext_supp_rates,
  138. clen);
  139. srlen += clen;
  140. }
  141. if (srlen) {
  142. bss->supp_rates_len = srlen;
  143. if (!elems->parse_error)
  144. bss->valid_data |= IEEE80211_BSS_VALID_RATES;
  145. }
  146. }
  147. if (!elems->parse_error ||
  148. !(bss->valid_data & IEEE80211_BSS_VALID_WMM)) {
  149. bss->wmm_used = elems->wmm_param || elems->wmm_info;
  150. bss->uapsd_supported = is_uapsd_supported(elems);
  151. if (!elems->parse_error)
  152. bss->valid_data |= IEEE80211_BSS_VALID_WMM;
  153. }
  154. if (beacon) {
  155. struct ieee80211_supported_band *sband =
  156. local->hw.wiphy->bands[rx_status->band];
  157. if (!(rx_status->flag & RX_FLAG_HT) &&
  158. !(rx_status->flag & RX_FLAG_VHT))
  159. bss->beacon_rate =
  160. &sband->bitrates[rx_status->rate_idx];
  161. }
  162. return bss;
  163. }
  164. void ieee80211_scan_rx(struct ieee80211_local *local, struct sk_buff *skb)
  165. {
  166. struct ieee80211_rx_status *rx_status = IEEE80211_SKB_RXCB(skb);
  167. struct ieee80211_sub_if_data *sdata1, *sdata2;
  168. struct ieee80211_mgmt *mgmt = (void *)skb->data;
  169. struct ieee80211_bss *bss;
  170. u8 *elements;
  171. struct ieee80211_channel *channel;
  172. size_t baselen;
  173. struct ieee802_11_elems elems;
  174. if (skb->len < 24 ||
  175. (!ieee80211_is_probe_resp(mgmt->frame_control) &&
  176. !ieee80211_is_beacon(mgmt->frame_control)))
  177. return;
  178. sdata1 = rcu_dereference(local->scan_sdata);
  179. sdata2 = rcu_dereference(local->sched_scan_sdata);
  180. if (likely(!sdata1 && !sdata2))
  181. return;
  182. if (ieee80211_is_probe_resp(mgmt->frame_control)) {
  183. struct cfg80211_scan_request *scan_req;
  184. struct cfg80211_sched_scan_request *sched_scan_req;
  185. scan_req = rcu_dereference(local->scan_req);
  186. sched_scan_req = rcu_dereference(local->sched_scan_req);
  187. /* ignore ProbeResp to foreign address unless scanning
  188. * with randomised address
  189. */
  190. if (!(sdata1 &&
  191. (ether_addr_equal(mgmt->da, sdata1->vif.addr) ||
  192. scan_req->flags & NL80211_SCAN_FLAG_RANDOM_ADDR)) &&
  193. !(sdata2 &&
  194. (ether_addr_equal(mgmt->da, sdata2->vif.addr) ||
  195. sched_scan_req->flags & NL80211_SCAN_FLAG_RANDOM_ADDR)))
  196. return;
  197. elements = mgmt->u.probe_resp.variable;
  198. baselen = offsetof(struct ieee80211_mgmt, u.probe_resp.variable);
  199. } else {
  200. baselen = offsetof(struct ieee80211_mgmt, u.beacon.variable);
  201. elements = mgmt->u.beacon.variable;
  202. }
  203. if (baselen > skb->len)
  204. return;
  205. ieee802_11_parse_elems(elements, skb->len - baselen, false, &elems);
  206. channel = ieee80211_get_channel(local->hw.wiphy, rx_status->freq);
  207. if (!channel || channel->flags & IEEE80211_CHAN_DISABLED)
  208. return;
  209. bss = ieee80211_bss_info_update(local, rx_status,
  210. mgmt, skb->len, &elems,
  211. channel);
  212. if (bss)
  213. ieee80211_rx_bss_put(local, bss);
  214. }
  215. static void
  216. ieee80211_prepare_scan_chandef(struct cfg80211_chan_def *chandef,
  217. enum nl80211_bss_scan_width scan_width)
  218. {
  219. memset(chandef, 0, sizeof(*chandef));
  220. switch (scan_width) {
  221. case NL80211_BSS_CHAN_WIDTH_5:
  222. chandef->width = NL80211_CHAN_WIDTH_5;
  223. break;
  224. case NL80211_BSS_CHAN_WIDTH_10:
  225. chandef->width = NL80211_CHAN_WIDTH_10;
  226. break;
  227. default:
  228. chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
  229. break;
  230. }
  231. }
  232. /* return false if no more work */
  233. static bool ieee80211_prep_hw_scan(struct ieee80211_local *local)
  234. {
  235. struct cfg80211_scan_request *req;
  236. struct cfg80211_chan_def chandef;
  237. u8 bands_used = 0;
  238. int i, ielen, n_chans;
  239. req = rcu_dereference_protected(local->scan_req,
  240. lockdep_is_held(&local->mtx));
  241. if (test_bit(SCAN_HW_CANCELLED, &local->scanning))
  242. return false;
  243. if (ieee80211_hw_check(&local->hw, SINGLE_SCAN_ON_ALL_BANDS)) {
  244. for (i = 0; i < req->n_channels; i++) {
  245. local->hw_scan_req->req.channels[i] = req->channels[i];
  246. bands_used |= BIT(req->channels[i]->band);
  247. }
  248. n_chans = req->n_channels;
  249. } else {
  250. do {
  251. if (local->hw_scan_band == NUM_NL80211_BANDS)
  252. return false;
  253. n_chans = 0;
  254. for (i = 0; i < req->n_channels; i++) {
  255. if (req->channels[i]->band !=
  256. local->hw_scan_band)
  257. continue;
  258. local->hw_scan_req->req.channels[n_chans] =
  259. req->channels[i];
  260. n_chans++;
  261. bands_used |= BIT(req->channels[i]->band);
  262. }
  263. local->hw_scan_band++;
  264. } while (!n_chans);
  265. }
  266. local->hw_scan_req->req.n_channels = n_chans;
  267. ieee80211_prepare_scan_chandef(&chandef, req->scan_width);
  268. ielen = ieee80211_build_preq_ies(local,
  269. (u8 *)local->hw_scan_req->req.ie,
  270. local->hw_scan_ies_bufsize,
  271. &local->hw_scan_req->ies,
  272. req->ie, req->ie_len,
  273. bands_used, req->rates, &chandef);
  274. local->hw_scan_req->req.ie_len = ielen;
  275. local->hw_scan_req->req.no_cck = req->no_cck;
  276. ether_addr_copy(local->hw_scan_req->req.mac_addr, req->mac_addr);
  277. ether_addr_copy(local->hw_scan_req->req.mac_addr_mask,
  278. req->mac_addr_mask);
  279. ether_addr_copy(local->hw_scan_req->req.bssid, req->bssid);
  280. return true;
  281. }
  282. static void __ieee80211_scan_completed(struct ieee80211_hw *hw, bool aborted)
  283. {
  284. struct ieee80211_local *local = hw_to_local(hw);
  285. bool hw_scan = local->ops->hw_scan;
  286. bool was_scanning = local->scanning;
  287. struct cfg80211_scan_request *scan_req;
  288. struct ieee80211_sub_if_data *scan_sdata;
  289. struct ieee80211_sub_if_data *sdata;
  290. lockdep_assert_held(&local->mtx);
  291. /*
  292. * It's ok to abort a not-yet-running scan (that
  293. * we have one at all will be verified by checking
  294. * local->scan_req next), but not to complete it
  295. * successfully.
  296. */
  297. if (WARN_ON(!local->scanning && !aborted))
  298. aborted = true;
  299. if (WARN_ON(!local->scan_req))
  300. return;
  301. if (hw_scan && !aborted &&
  302. !ieee80211_hw_check(&local->hw, SINGLE_SCAN_ON_ALL_BANDS) &&
  303. ieee80211_prep_hw_scan(local)) {
  304. int rc;
  305. rc = drv_hw_scan(local,
  306. rcu_dereference_protected(local->scan_sdata,
  307. lockdep_is_held(&local->mtx)),
  308. local->hw_scan_req);
  309. if (rc == 0)
  310. return;
  311. /* HW scan failed and is going to be reported as aborted,
  312. * so clear old scan info.
  313. */
  314. memset(&local->scan_info, 0, sizeof(local->scan_info));
  315. aborted = true;
  316. }
  317. kfree(local->hw_scan_req);
  318. local->hw_scan_req = NULL;
  319. scan_req = rcu_dereference_protected(local->scan_req,
  320. lockdep_is_held(&local->mtx));
  321. if (scan_req != local->int_scan_req) {
  322. local->scan_info.aborted = aborted;
  323. cfg80211_scan_done(scan_req, &local->scan_info);
  324. }
  325. RCU_INIT_POINTER(local->scan_req, NULL);
  326. scan_sdata = rcu_dereference_protected(local->scan_sdata,
  327. lockdep_is_held(&local->mtx));
  328. RCU_INIT_POINTER(local->scan_sdata, NULL);
  329. local->scanning = 0;
  330. local->scan_chandef.chan = NULL;
  331. /* Set power back to normal operating levels. */
  332. ieee80211_hw_config(local, 0);
  333. if (!hw_scan) {
  334. ieee80211_configure_filter(local);
  335. drv_sw_scan_complete(local, scan_sdata);
  336. ieee80211_offchannel_return(local);
  337. }
  338. ieee80211_recalc_idle(local);
  339. ieee80211_mlme_notify_scan_completed(local);
  340. ieee80211_ibss_notify_scan_completed(local);
  341. /* Requeue all the work that might have been ignored while
  342. * the scan was in progress; if there was none this will
  343. * just be a no-op for the particular interface.
  344. */
  345. list_for_each_entry_rcu(sdata, &local->interfaces, list) {
  346. if (ieee80211_sdata_running(sdata))
  347. ieee80211_queue_work(&sdata->local->hw, &sdata->work);
  348. }
  349. if (was_scanning)
  350. ieee80211_start_next_roc(local);
  351. }
  352. void ieee80211_scan_completed(struct ieee80211_hw *hw,
  353. struct cfg80211_scan_info *info)
  354. {
  355. struct ieee80211_local *local = hw_to_local(hw);
  356. trace_api_scan_completed(local, info->aborted);
  357. set_bit(SCAN_COMPLETED, &local->scanning);
  358. if (info->aborted)
  359. set_bit(SCAN_ABORTED, &local->scanning);
  360. memcpy(&local->scan_info, info, sizeof(*info));
  361. ieee80211_queue_delayed_work(&local->hw, &local->scan_work, 0);
  362. }
  363. EXPORT_SYMBOL(ieee80211_scan_completed);
  364. static int ieee80211_start_sw_scan(struct ieee80211_local *local,
  365. struct ieee80211_sub_if_data *sdata)
  366. {
  367. /* Software scan is not supported in multi-channel cases */
  368. if (local->use_chanctx)
  369. return -EOPNOTSUPP;
  370. /*
  371. * Hardware/driver doesn't support hw_scan, so use software
  372. * scanning instead. First send a nullfunc frame with power save
  373. * bit on so that AP will buffer the frames for us while we are not
  374. * listening, then send probe requests to each channel and wait for
  375. * the responses. After all channels are scanned, tune back to the
  376. * original channel and send a nullfunc frame with power save bit
  377. * off to trigger the AP to send us all the buffered frames.
  378. *
  379. * Note that while local->sw_scanning is true everything else but
  380. * nullfunc frames and probe requests will be dropped in
  381. * ieee80211_tx_h_check_assoc().
  382. */
  383. drv_sw_scan_start(local, sdata, local->scan_addr);
  384. local->leave_oper_channel_time = jiffies;
  385. local->next_scan_state = SCAN_DECISION;
  386. local->scan_channel_idx = 0;
  387. ieee80211_offchannel_stop_vifs(local);
  388. /* ensure nullfunc is transmitted before leaving operating channel */
  389. ieee80211_flush_queues(local, NULL, false);
  390. ieee80211_configure_filter(local);
  391. /* We need to set power level at maximum rate for scanning. */
  392. ieee80211_hw_config(local, 0);
  393. ieee80211_queue_delayed_work(&local->hw,
  394. &local->scan_work, 0);
  395. return 0;
  396. }
  397. static bool ieee80211_can_scan(struct ieee80211_local *local,
  398. struct ieee80211_sub_if_data *sdata)
  399. {
  400. if (ieee80211_is_radar_required(local))
  401. return false;
  402. if (!list_empty(&local->roc_list))
  403. return false;
  404. if (sdata->vif.type == NL80211_IFTYPE_STATION &&
  405. sdata->u.mgd.flags & IEEE80211_STA_CONNECTION_POLL)
  406. return false;
  407. return true;
  408. }
  409. void ieee80211_run_deferred_scan(struct ieee80211_local *local)
  410. {
  411. lockdep_assert_held(&local->mtx);
  412. if (!local->scan_req || local->scanning)
  413. return;
  414. if (!ieee80211_can_scan(local,
  415. rcu_dereference_protected(
  416. local->scan_sdata,
  417. lockdep_is_held(&local->mtx))))
  418. return;
  419. ieee80211_queue_delayed_work(&local->hw, &local->scan_work,
  420. round_jiffies_relative(0));
  421. }
  422. static void ieee80211_scan_state_send_probe(struct ieee80211_local *local,
  423. unsigned long *next_delay)
  424. {
  425. int i;
  426. struct ieee80211_sub_if_data *sdata;
  427. struct cfg80211_scan_request *scan_req;
  428. enum nl80211_band band = local->hw.conf.chandef.chan->band;
  429. u32 tx_flags;
  430. scan_req = rcu_dereference_protected(local->scan_req,
  431. lockdep_is_held(&local->mtx));
  432. tx_flags = IEEE80211_TX_INTFL_OFFCHAN_TX_OK;
  433. if (scan_req->no_cck)
  434. tx_flags |= IEEE80211_TX_CTL_NO_CCK_RATE;
  435. sdata = rcu_dereference_protected(local->scan_sdata,
  436. lockdep_is_held(&local->mtx));
  437. for (i = 0; i < scan_req->n_ssids; i++)
  438. ieee80211_send_probe_req(
  439. sdata, local->scan_addr, scan_req->bssid,
  440. scan_req->ssids[i].ssid, scan_req->ssids[i].ssid_len,
  441. scan_req->ie, scan_req->ie_len,
  442. scan_req->rates[band], false,
  443. tx_flags, local->hw.conf.chandef.chan, true);
  444. /*
  445. * After sending probe requests, wait for probe responses
  446. * on the channel.
  447. */
  448. *next_delay = IEEE80211_CHANNEL_TIME;
  449. local->next_scan_state = SCAN_DECISION;
  450. }
  451. static int __ieee80211_start_scan(struct ieee80211_sub_if_data *sdata,
  452. struct cfg80211_scan_request *req)
  453. {
  454. struct ieee80211_local *local = sdata->local;
  455. int rc;
  456. lockdep_assert_held(&local->mtx);
  457. if (local->scan_req || ieee80211_is_radar_required(local))
  458. return -EBUSY;
  459. if (!ieee80211_can_scan(local, sdata)) {
  460. /* wait for the work to finish/time out */
  461. rcu_assign_pointer(local->scan_req, req);
  462. rcu_assign_pointer(local->scan_sdata, sdata);
  463. return 0;
  464. }
  465. if (local->ops->hw_scan) {
  466. u8 *ies;
  467. local->hw_scan_ies_bufsize = local->scan_ies_len + req->ie_len;
  468. if (ieee80211_hw_check(&local->hw, SINGLE_SCAN_ON_ALL_BANDS)) {
  469. int i, n_bands = 0;
  470. u8 bands_counted = 0;
  471. for (i = 0; i < req->n_channels; i++) {
  472. if (bands_counted & BIT(req->channels[i]->band))
  473. continue;
  474. bands_counted |= BIT(req->channels[i]->band);
  475. n_bands++;
  476. }
  477. local->hw_scan_ies_bufsize *= n_bands;
  478. }
  479. local->hw_scan_req = kmalloc(
  480. sizeof(*local->hw_scan_req) +
  481. req->n_channels * sizeof(req->channels[0]) +
  482. local->hw_scan_ies_bufsize, GFP_KERNEL);
  483. if (!local->hw_scan_req)
  484. return -ENOMEM;
  485. local->hw_scan_req->req.ssids = req->ssids;
  486. local->hw_scan_req->req.n_ssids = req->n_ssids;
  487. ies = (u8 *)local->hw_scan_req +
  488. sizeof(*local->hw_scan_req) +
  489. req->n_channels * sizeof(req->channels[0]);
  490. local->hw_scan_req->req.ie = ies;
  491. local->hw_scan_req->req.flags = req->flags;
  492. eth_broadcast_addr(local->hw_scan_req->req.bssid);
  493. local->hw_scan_req->req.duration = req->duration;
  494. local->hw_scan_req->req.duration_mandatory =
  495. req->duration_mandatory;
  496. local->hw_scan_band = 0;
  497. /*
  498. * After allocating local->hw_scan_req, we must
  499. * go through until ieee80211_prep_hw_scan(), so
  500. * anything that might be changed here and leave
  501. * this function early must not go after this
  502. * allocation.
  503. */
  504. }
  505. rcu_assign_pointer(local->scan_req, req);
  506. rcu_assign_pointer(local->scan_sdata, sdata);
  507. if (req->flags & NL80211_SCAN_FLAG_RANDOM_ADDR)
  508. get_random_mask_addr(local->scan_addr,
  509. req->mac_addr,
  510. req->mac_addr_mask);
  511. else
  512. memcpy(local->scan_addr, sdata->vif.addr, ETH_ALEN);
  513. if (local->ops->hw_scan) {
  514. __set_bit(SCAN_HW_SCANNING, &local->scanning);
  515. } else if ((req->n_channels == 1) &&
  516. (req->channels[0] == local->_oper_chandef.chan)) {
  517. /*
  518. * If we are scanning only on the operating channel
  519. * then we do not need to stop normal activities
  520. */
  521. unsigned long next_delay;
  522. __set_bit(SCAN_ONCHANNEL_SCANNING, &local->scanning);
  523. ieee80211_recalc_idle(local);
  524. /* Notify driver scan is starting, keep order of operations
  525. * same as normal software scan, in case that matters. */
  526. drv_sw_scan_start(local, sdata, local->scan_addr);
  527. ieee80211_configure_filter(local); /* accept probe-responses */
  528. /* We need to ensure power level is at max for scanning. */
  529. ieee80211_hw_config(local, 0);
  530. if ((req->channels[0]->flags & (IEEE80211_CHAN_NO_IR |
  531. IEEE80211_CHAN_RADAR)) ||
  532. !req->n_ssids) {
  533. next_delay = IEEE80211_PASSIVE_CHANNEL_TIME;
  534. } else {
  535. ieee80211_scan_state_send_probe(local, &next_delay);
  536. next_delay = IEEE80211_CHANNEL_TIME;
  537. }
  538. /* Now, just wait a bit and we are all done! */
  539. ieee80211_queue_delayed_work(&local->hw, &local->scan_work,
  540. next_delay);
  541. return 0;
  542. } else {
  543. /* Do normal software scan */
  544. __set_bit(SCAN_SW_SCANNING, &local->scanning);
  545. }
  546. ieee80211_recalc_idle(local);
  547. if (local->ops->hw_scan) {
  548. WARN_ON(!ieee80211_prep_hw_scan(local));
  549. rc = drv_hw_scan(local, sdata, local->hw_scan_req);
  550. } else {
  551. rc = ieee80211_start_sw_scan(local, sdata);
  552. }
  553. if (rc) {
  554. kfree(local->hw_scan_req);
  555. local->hw_scan_req = NULL;
  556. local->scanning = 0;
  557. ieee80211_recalc_idle(local);
  558. local->scan_req = NULL;
  559. RCU_INIT_POINTER(local->scan_sdata, NULL);
  560. }
  561. return rc;
  562. }
  563. static unsigned long
  564. ieee80211_scan_get_channel_time(struct ieee80211_channel *chan)
  565. {
  566. /*
  567. * TODO: channel switching also consumes quite some time,
  568. * add that delay as well to get a better estimation
  569. */
  570. if (chan->flags & (IEEE80211_CHAN_NO_IR | IEEE80211_CHAN_RADAR))
  571. return IEEE80211_PASSIVE_CHANNEL_TIME;
  572. return IEEE80211_PROBE_DELAY + IEEE80211_CHANNEL_TIME;
  573. }
  574. static void ieee80211_scan_state_decision(struct ieee80211_local *local,
  575. unsigned long *next_delay)
  576. {
  577. bool associated = false;
  578. bool tx_empty = true;
  579. bool bad_latency;
  580. struct ieee80211_sub_if_data *sdata;
  581. struct ieee80211_channel *next_chan;
  582. enum mac80211_scan_state next_scan_state;
  583. struct cfg80211_scan_request *scan_req;
  584. /*
  585. * check if at least one STA interface is associated,
  586. * check if at least one STA interface has pending tx frames
  587. * and grab the lowest used beacon interval
  588. */
  589. mutex_lock(&local->iflist_mtx);
  590. list_for_each_entry(sdata, &local->interfaces, list) {
  591. if (!ieee80211_sdata_running(sdata))
  592. continue;
  593. if (sdata->vif.type == NL80211_IFTYPE_STATION) {
  594. if (sdata->u.mgd.associated) {
  595. associated = true;
  596. if (!qdisc_all_tx_empty(sdata->dev)) {
  597. tx_empty = false;
  598. break;
  599. }
  600. }
  601. }
  602. }
  603. mutex_unlock(&local->iflist_mtx);
  604. scan_req = rcu_dereference_protected(local->scan_req,
  605. lockdep_is_held(&local->mtx));
  606. next_chan = scan_req->channels[local->scan_channel_idx];
  607. /*
  608. * we're currently scanning a different channel, let's
  609. * see if we can scan another channel without interfering
  610. * with the current traffic situation.
  611. *
  612. * Keep good latency, do not stay off-channel more than 125 ms.
  613. */
  614. bad_latency = time_after(jiffies +
  615. ieee80211_scan_get_channel_time(next_chan),
  616. local->leave_oper_channel_time + HZ / 8);
  617. if (associated && !tx_empty) {
  618. if (scan_req->flags & NL80211_SCAN_FLAG_LOW_PRIORITY)
  619. next_scan_state = SCAN_ABORT;
  620. else
  621. next_scan_state = SCAN_SUSPEND;
  622. } else if (associated && bad_latency) {
  623. next_scan_state = SCAN_SUSPEND;
  624. } else {
  625. next_scan_state = SCAN_SET_CHANNEL;
  626. }
  627. local->next_scan_state = next_scan_state;
  628. *next_delay = 0;
  629. }
  630. static void ieee80211_scan_state_set_channel(struct ieee80211_local *local,
  631. unsigned long *next_delay)
  632. {
  633. int skip;
  634. struct ieee80211_channel *chan;
  635. enum nl80211_bss_scan_width oper_scan_width;
  636. struct cfg80211_scan_request *scan_req;
  637. scan_req = rcu_dereference_protected(local->scan_req,
  638. lockdep_is_held(&local->mtx));
  639. skip = 0;
  640. chan = scan_req->channels[local->scan_channel_idx];
  641. local->scan_chandef.chan = chan;
  642. local->scan_chandef.center_freq1 = chan->center_freq;
  643. local->scan_chandef.center_freq2 = 0;
  644. switch (scan_req->scan_width) {
  645. case NL80211_BSS_CHAN_WIDTH_5:
  646. local->scan_chandef.width = NL80211_CHAN_WIDTH_5;
  647. break;
  648. case NL80211_BSS_CHAN_WIDTH_10:
  649. local->scan_chandef.width = NL80211_CHAN_WIDTH_10;
  650. break;
  651. case NL80211_BSS_CHAN_WIDTH_20:
  652. /* If scanning on oper channel, use whatever channel-type
  653. * is currently in use.
  654. */
  655. oper_scan_width = cfg80211_chandef_to_scan_width(
  656. &local->_oper_chandef);
  657. if (chan == local->_oper_chandef.chan &&
  658. oper_scan_width == scan_req->scan_width)
  659. local->scan_chandef = local->_oper_chandef;
  660. else
  661. local->scan_chandef.width = NL80211_CHAN_WIDTH_20_NOHT;
  662. break;
  663. }
  664. if (ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_CHANNEL))
  665. skip = 1;
  666. /* advance state machine to next channel/band */
  667. local->scan_channel_idx++;
  668. if (skip) {
  669. /* if we skip this channel return to the decision state */
  670. local->next_scan_state = SCAN_DECISION;
  671. return;
  672. }
  673. /*
  674. * Probe delay is used to update the NAV, cf. 11.1.3.2.2
  675. * (which unfortunately doesn't say _why_ step a) is done,
  676. * but it waits for the probe delay or until a frame is
  677. * received - and the received frame would update the NAV).
  678. * For now, we do not support waiting until a frame is
  679. * received.
  680. *
  681. * In any case, it is not necessary for a passive scan.
  682. */
  683. if ((chan->flags & (IEEE80211_CHAN_NO_IR | IEEE80211_CHAN_RADAR)) ||
  684. !scan_req->n_ssids) {
  685. *next_delay = IEEE80211_PASSIVE_CHANNEL_TIME;
  686. local->next_scan_state = SCAN_DECISION;
  687. return;
  688. }
  689. /* active scan, send probes */
  690. *next_delay = IEEE80211_PROBE_DELAY;
  691. local->next_scan_state = SCAN_SEND_PROBE;
  692. }
  693. static void ieee80211_scan_state_suspend(struct ieee80211_local *local,
  694. unsigned long *next_delay)
  695. {
  696. /* switch back to the operating channel */
  697. local->scan_chandef.chan = NULL;
  698. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_CHANNEL);
  699. /* disable PS */
  700. ieee80211_offchannel_return(local);
  701. *next_delay = HZ / 5;
  702. /* afterwards, resume scan & go to next channel */
  703. local->next_scan_state = SCAN_RESUME;
  704. }
  705. static void ieee80211_scan_state_resume(struct ieee80211_local *local,
  706. unsigned long *next_delay)
  707. {
  708. ieee80211_offchannel_stop_vifs(local);
  709. if (local->ops->flush) {
  710. ieee80211_flush_queues(local, NULL, false);
  711. *next_delay = 0;
  712. } else
  713. *next_delay = HZ / 10;
  714. /* remember when we left the operating channel */
  715. local->leave_oper_channel_time = jiffies;
  716. /* advance to the next channel to be scanned */
  717. local->next_scan_state = SCAN_SET_CHANNEL;
  718. }
  719. void ieee80211_scan_work(struct work_struct *work)
  720. {
  721. struct ieee80211_local *local =
  722. container_of(work, struct ieee80211_local, scan_work.work);
  723. struct ieee80211_sub_if_data *sdata;
  724. struct cfg80211_scan_request *scan_req;
  725. unsigned long next_delay = 0;
  726. bool aborted;
  727. mutex_lock(&local->mtx);
  728. if (!ieee80211_can_run_worker(local)) {
  729. aborted = true;
  730. goto out_complete;
  731. }
  732. sdata = rcu_dereference_protected(local->scan_sdata,
  733. lockdep_is_held(&local->mtx));
  734. scan_req = rcu_dereference_protected(local->scan_req,
  735. lockdep_is_held(&local->mtx));
  736. /* When scanning on-channel, the first-callback means completed. */
  737. if (test_bit(SCAN_ONCHANNEL_SCANNING, &local->scanning)) {
  738. aborted = test_and_clear_bit(SCAN_ABORTED, &local->scanning);
  739. goto out_complete;
  740. }
  741. if (test_and_clear_bit(SCAN_COMPLETED, &local->scanning)) {
  742. aborted = test_and_clear_bit(SCAN_ABORTED, &local->scanning);
  743. goto out_complete;
  744. }
  745. if (!sdata || !scan_req)
  746. goto out;
  747. if (!local->scanning) {
  748. int rc;
  749. RCU_INIT_POINTER(local->scan_req, NULL);
  750. RCU_INIT_POINTER(local->scan_sdata, NULL);
  751. rc = __ieee80211_start_scan(sdata, scan_req);
  752. if (rc) {
  753. /* need to complete scan in cfg80211 */
  754. rcu_assign_pointer(local->scan_req, scan_req);
  755. aborted = true;
  756. goto out_complete;
  757. } else
  758. goto out;
  759. }
  760. /*
  761. * as long as no delay is required advance immediately
  762. * without scheduling a new work
  763. */
  764. do {
  765. if (!ieee80211_sdata_running(sdata)) {
  766. aborted = true;
  767. goto out_complete;
  768. }
  769. switch (local->next_scan_state) {
  770. case SCAN_DECISION:
  771. /* if no more bands/channels left, complete scan */
  772. if (local->scan_channel_idx >= scan_req->n_channels) {
  773. aborted = false;
  774. goto out_complete;
  775. }
  776. ieee80211_scan_state_decision(local, &next_delay);
  777. break;
  778. case SCAN_SET_CHANNEL:
  779. ieee80211_scan_state_set_channel(local, &next_delay);
  780. break;
  781. case SCAN_SEND_PROBE:
  782. ieee80211_scan_state_send_probe(local, &next_delay);
  783. break;
  784. case SCAN_SUSPEND:
  785. ieee80211_scan_state_suspend(local, &next_delay);
  786. break;
  787. case SCAN_RESUME:
  788. ieee80211_scan_state_resume(local, &next_delay);
  789. break;
  790. case SCAN_ABORT:
  791. aborted = true;
  792. goto out_complete;
  793. }
  794. } while (next_delay == 0);
  795. ieee80211_queue_delayed_work(&local->hw, &local->scan_work, next_delay);
  796. goto out;
  797. out_complete:
  798. __ieee80211_scan_completed(&local->hw, aborted);
  799. out:
  800. mutex_unlock(&local->mtx);
  801. }
  802. int ieee80211_request_scan(struct ieee80211_sub_if_data *sdata,
  803. struct cfg80211_scan_request *req)
  804. {
  805. int res;
  806. mutex_lock(&sdata->local->mtx);
  807. res = __ieee80211_start_scan(sdata, req);
  808. mutex_unlock(&sdata->local->mtx);
  809. return res;
  810. }
  811. int ieee80211_request_ibss_scan(struct ieee80211_sub_if_data *sdata,
  812. const u8 *ssid, u8 ssid_len,
  813. struct ieee80211_channel **channels,
  814. unsigned int n_channels,
  815. enum nl80211_bss_scan_width scan_width)
  816. {
  817. struct ieee80211_local *local = sdata->local;
  818. int ret = -EBUSY, i, n_ch = 0;
  819. enum nl80211_band band;
  820. mutex_lock(&local->mtx);
  821. /* busy scanning */
  822. if (local->scan_req)
  823. goto unlock;
  824. /* fill internal scan request */
  825. if (!channels) {
  826. int max_n;
  827. for (band = 0; band < NUM_NL80211_BANDS; band++) {
  828. if (!local->hw.wiphy->bands[band])
  829. continue;
  830. max_n = local->hw.wiphy->bands[band]->n_channels;
  831. for (i = 0; i < max_n; i++) {
  832. struct ieee80211_channel *tmp_ch =
  833. &local->hw.wiphy->bands[band]->channels[i];
  834. if (tmp_ch->flags & (IEEE80211_CHAN_NO_IR |
  835. IEEE80211_CHAN_DISABLED))
  836. continue;
  837. local->int_scan_req->channels[n_ch] = tmp_ch;
  838. n_ch++;
  839. }
  840. }
  841. if (WARN_ON_ONCE(n_ch == 0))
  842. goto unlock;
  843. local->int_scan_req->n_channels = n_ch;
  844. } else {
  845. for (i = 0; i < n_channels; i++) {
  846. if (channels[i]->flags & (IEEE80211_CHAN_NO_IR |
  847. IEEE80211_CHAN_DISABLED))
  848. continue;
  849. local->int_scan_req->channels[n_ch] = channels[i];
  850. n_ch++;
  851. }
  852. if (WARN_ON_ONCE(n_ch == 0))
  853. goto unlock;
  854. local->int_scan_req->n_channels = n_ch;
  855. }
  856. local->int_scan_req->ssids = &local->scan_ssid;
  857. local->int_scan_req->n_ssids = 1;
  858. local->int_scan_req->scan_width = scan_width;
  859. memcpy(local->int_scan_req->ssids[0].ssid, ssid, IEEE80211_MAX_SSID_LEN);
  860. local->int_scan_req->ssids[0].ssid_len = ssid_len;
  861. ret = __ieee80211_start_scan(sdata, sdata->local->int_scan_req);
  862. unlock:
  863. mutex_unlock(&local->mtx);
  864. return ret;
  865. }
  866. /*
  867. * Only call this function when a scan can't be queued -- under RTNL.
  868. */
  869. void ieee80211_scan_cancel(struct ieee80211_local *local)
  870. {
  871. /*
  872. * We are canceling software scan, or deferred scan that was not
  873. * yet really started (see __ieee80211_start_scan ).
  874. *
  875. * Regarding hardware scan:
  876. * - we can not call __ieee80211_scan_completed() as when
  877. * SCAN_HW_SCANNING bit is set this function change
  878. * local->hw_scan_req to operate on 5G band, what race with
  879. * driver which can use local->hw_scan_req
  880. *
  881. * - we can not cancel scan_work since driver can schedule it
  882. * by ieee80211_scan_completed(..., true) to finish scan
  883. *
  884. * Hence we only call the cancel_hw_scan() callback, but the low-level
  885. * driver is still responsible for calling ieee80211_scan_completed()
  886. * after the scan was completed/aborted.
  887. */
  888. mutex_lock(&local->mtx);
  889. if (!local->scan_req)
  890. goto out;
  891. /*
  892. * We have a scan running and the driver already reported completion,
  893. * but the worker hasn't run yet or is stuck on the mutex - mark it as
  894. * cancelled.
  895. */
  896. if (test_bit(SCAN_HW_SCANNING, &local->scanning) &&
  897. test_bit(SCAN_COMPLETED, &local->scanning)) {
  898. set_bit(SCAN_HW_CANCELLED, &local->scanning);
  899. goto out;
  900. }
  901. if (test_bit(SCAN_HW_SCANNING, &local->scanning)) {
  902. /*
  903. * Make sure that __ieee80211_scan_completed doesn't trigger a
  904. * scan on another band.
  905. */
  906. set_bit(SCAN_HW_CANCELLED, &local->scanning);
  907. if (local->ops->cancel_hw_scan)
  908. drv_cancel_hw_scan(local,
  909. rcu_dereference_protected(local->scan_sdata,
  910. lockdep_is_held(&local->mtx)));
  911. goto out;
  912. }
  913. /*
  914. * If the work is currently running, it must be blocked on
  915. * the mutex, but we'll set scan_sdata = NULL and it'll
  916. * simply exit once it acquires the mutex.
  917. */
  918. cancel_delayed_work(&local->scan_work);
  919. /* and clean up */
  920. memset(&local->scan_info, 0, sizeof(local->scan_info));
  921. __ieee80211_scan_completed(&local->hw, true);
  922. out:
  923. mutex_unlock(&local->mtx);
  924. }
  925. int __ieee80211_request_sched_scan_start(struct ieee80211_sub_if_data *sdata,
  926. struct cfg80211_sched_scan_request *req)
  927. {
  928. struct ieee80211_local *local = sdata->local;
  929. struct ieee80211_scan_ies sched_scan_ies = {};
  930. struct cfg80211_chan_def chandef;
  931. int ret, i, iebufsz, num_bands = 0;
  932. u32 rate_masks[NUM_NL80211_BANDS] = {};
  933. u8 bands_used = 0;
  934. u8 *ie;
  935. size_t len;
  936. iebufsz = local->scan_ies_len + req->ie_len;
  937. lockdep_assert_held(&local->mtx);
  938. if (!local->ops->sched_scan_start)
  939. return -ENOTSUPP;
  940. for (i = 0; i < NUM_NL80211_BANDS; i++) {
  941. if (local->hw.wiphy->bands[i]) {
  942. bands_used |= BIT(i);
  943. rate_masks[i] = (u32) -1;
  944. num_bands++;
  945. }
  946. }
  947. ie = kzalloc(num_bands * iebufsz, GFP_KERNEL);
  948. if (!ie) {
  949. ret = -ENOMEM;
  950. goto out;
  951. }
  952. ieee80211_prepare_scan_chandef(&chandef, req->scan_width);
  953. len = ieee80211_build_preq_ies(local, ie, num_bands * iebufsz,
  954. &sched_scan_ies, req->ie,
  955. req->ie_len, bands_used,
  956. rate_masks, &chandef);
  957. ret = drv_sched_scan_start(local, sdata, req, &sched_scan_ies);
  958. if (ret == 0) {
  959. rcu_assign_pointer(local->sched_scan_sdata, sdata);
  960. rcu_assign_pointer(local->sched_scan_req, req);
  961. }
  962. kfree(ie);
  963. out:
  964. if (ret) {
  965. /* Clean in case of failure after HW restart or upon resume. */
  966. RCU_INIT_POINTER(local->sched_scan_sdata, NULL);
  967. RCU_INIT_POINTER(local->sched_scan_req, NULL);
  968. }
  969. return ret;
  970. }
  971. int ieee80211_request_sched_scan_start(struct ieee80211_sub_if_data *sdata,
  972. struct cfg80211_sched_scan_request *req)
  973. {
  974. struct ieee80211_local *local = sdata->local;
  975. int ret;
  976. mutex_lock(&local->mtx);
  977. if (rcu_access_pointer(local->sched_scan_sdata)) {
  978. mutex_unlock(&local->mtx);
  979. return -EBUSY;
  980. }
  981. ret = __ieee80211_request_sched_scan_start(sdata, req);
  982. mutex_unlock(&local->mtx);
  983. return ret;
  984. }
  985. int ieee80211_request_sched_scan_stop(struct ieee80211_local *local)
  986. {
  987. struct ieee80211_sub_if_data *sched_scan_sdata;
  988. int ret = -ENOENT;
  989. mutex_lock(&local->mtx);
  990. if (!local->ops->sched_scan_stop) {
  991. ret = -ENOTSUPP;
  992. goto out;
  993. }
  994. /* We don't want to restart sched scan anymore. */
  995. RCU_INIT_POINTER(local->sched_scan_req, NULL);
  996. sched_scan_sdata = rcu_dereference_protected(local->sched_scan_sdata,
  997. lockdep_is_held(&local->mtx));
  998. if (sched_scan_sdata) {
  999. ret = drv_sched_scan_stop(local, sched_scan_sdata);
  1000. if (!ret)
  1001. RCU_INIT_POINTER(local->sched_scan_sdata, NULL);
  1002. }
  1003. out:
  1004. mutex_unlock(&local->mtx);
  1005. return ret;
  1006. }
  1007. void ieee80211_sched_scan_results(struct ieee80211_hw *hw)
  1008. {
  1009. struct ieee80211_local *local = hw_to_local(hw);
  1010. trace_api_sched_scan_results(local);
  1011. cfg80211_sched_scan_results(hw->wiphy);
  1012. }
  1013. EXPORT_SYMBOL(ieee80211_sched_scan_results);
  1014. void ieee80211_sched_scan_end(struct ieee80211_local *local)
  1015. {
  1016. mutex_lock(&local->mtx);
  1017. if (!rcu_access_pointer(local->sched_scan_sdata)) {
  1018. mutex_unlock(&local->mtx);
  1019. return;
  1020. }
  1021. RCU_INIT_POINTER(local->sched_scan_sdata, NULL);
  1022. /* If sched scan was aborted by the driver. */
  1023. RCU_INIT_POINTER(local->sched_scan_req, NULL);
  1024. mutex_unlock(&local->mtx);
  1025. cfg80211_sched_scan_stopped(local->hw.wiphy);
  1026. }
  1027. void ieee80211_sched_scan_stopped_work(struct work_struct *work)
  1028. {
  1029. struct ieee80211_local *local =
  1030. container_of(work, struct ieee80211_local,
  1031. sched_scan_stopped_work);
  1032. ieee80211_sched_scan_end(local);
  1033. }
  1034. void ieee80211_sched_scan_stopped(struct ieee80211_hw *hw)
  1035. {
  1036. struct ieee80211_local *local = hw_to_local(hw);
  1037. trace_api_sched_scan_stopped(local);
  1038. /*
  1039. * this shouldn't really happen, so for simplicity
  1040. * simply ignore it, and let mac80211 reconfigure
  1041. * the sched scan later on.
  1042. */
  1043. if (local->in_reconfig)
  1044. return;
  1045. schedule_work(&local->sched_scan_stopped_work);
  1046. }
  1047. EXPORT_SYMBOL(ieee80211_sched_scan_stopped);