scan.c 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798
  1. /*
  2. * cfg80211 scan result handling
  3. *
  4. * Copyright 2008 Johannes Berg <johannes@sipsolutions.net>
  5. * Copyright 2013-2014 Intel Mobile Communications GmbH
  6. * Copyright 2016 Intel Deutschland GmbH
  7. */
  8. #include <linux/kernel.h>
  9. #include <linux/slab.h>
  10. #include <linux/module.h>
  11. #include <linux/netdevice.h>
  12. #include <linux/wireless.h>
  13. #include <linux/nl80211.h>
  14. #include <linux/etherdevice.h>
  15. #include <net/arp.h>
  16. #include <net/cfg80211.h>
  17. #include <net/cfg80211-wext.h>
  18. #include <net/iw_handler.h>
  19. #include "core.h"
  20. #include "nl80211.h"
  21. #include "wext-compat.h"
  22. #include "rdev-ops.h"
  23. /**
  24. * DOC: BSS tree/list structure
  25. *
  26. * At the top level, the BSS list is kept in both a list in each
  27. * registered device (@bss_list) as well as an RB-tree for faster
  28. * lookup. In the RB-tree, entries can be looked up using their
  29. * channel, MESHID, MESHCONF (for MBSSes) or channel, BSSID, SSID
  30. * for other BSSes.
  31. *
  32. * Due to the possibility of hidden SSIDs, there's a second level
  33. * structure, the "hidden_list" and "hidden_beacon_bss" pointer.
  34. * The hidden_list connects all BSSes belonging to a single AP
  35. * that has a hidden SSID, and connects beacon and probe response
  36. * entries. For a probe response entry for a hidden SSID, the
  37. * hidden_beacon_bss pointer points to the BSS struct holding the
  38. * beacon's information.
  39. *
  40. * Reference counting is done for all these references except for
  41. * the hidden_list, so that a beacon BSS struct that is otherwise
  42. * not referenced has one reference for being on the bss_list and
  43. * one for each probe response entry that points to it using the
  44. * hidden_beacon_bss pointer. When a BSS struct that has such a
  45. * pointer is get/put, the refcount update is also propagated to
  46. * the referenced struct, this ensure that it cannot get removed
  47. * while somebody is using the probe response version.
  48. *
  49. * Note that the hidden_beacon_bss pointer never changes, due to
  50. * the reference counting. Therefore, no locking is needed for
  51. * it.
  52. *
  53. * Also note that the hidden_beacon_bss pointer is only relevant
  54. * if the driver uses something other than the IEs, e.g. private
  55. * data stored stored in the BSS struct, since the beacon IEs are
  56. * also linked into the probe response struct.
  57. */
  58. /*
  59. * Limit the number of BSS entries stored in mac80211. Each one is
  60. * a bit over 4k at most, so this limits to roughly 4-5M of memory.
  61. * If somebody wants to really attack this though, they'd likely
  62. * use small beacons, and only one type of frame, limiting each of
  63. * the entries to a much smaller size (in order to generate more
  64. * entries in total, so overhead is bigger.)
  65. */
  66. static int bss_entries_limit = 1000;
  67. module_param(bss_entries_limit, int, 0644);
  68. MODULE_PARM_DESC(bss_entries_limit,
  69. "limit to number of scan BSS entries (per wiphy, default 1000)");
  70. #define IEEE80211_SCAN_RESULT_EXPIRE (30 * HZ)
  71. static void bss_free(struct cfg80211_internal_bss *bss)
  72. {
  73. struct cfg80211_bss_ies *ies;
  74. if (WARN_ON(atomic_read(&bss->hold)))
  75. return;
  76. ies = (void *)rcu_access_pointer(bss->pub.beacon_ies);
  77. if (ies && !bss->pub.hidden_beacon_bss)
  78. kfree_rcu(ies, rcu_head);
  79. ies = (void *)rcu_access_pointer(bss->pub.proberesp_ies);
  80. if (ies)
  81. kfree_rcu(ies, rcu_head);
  82. /*
  83. * This happens when the module is removed, it doesn't
  84. * really matter any more save for completeness
  85. */
  86. if (!list_empty(&bss->hidden_list))
  87. list_del(&bss->hidden_list);
  88. kfree(bss);
  89. }
  90. static inline void bss_ref_get(struct cfg80211_registered_device *rdev,
  91. struct cfg80211_internal_bss *bss)
  92. {
  93. lockdep_assert_held(&rdev->bss_lock);
  94. bss->refcount++;
  95. if (bss->pub.hidden_beacon_bss) {
  96. bss = container_of(bss->pub.hidden_beacon_bss,
  97. struct cfg80211_internal_bss,
  98. pub);
  99. bss->refcount++;
  100. }
  101. }
  102. static inline void bss_ref_put(struct cfg80211_registered_device *rdev,
  103. struct cfg80211_internal_bss *bss)
  104. {
  105. lockdep_assert_held(&rdev->bss_lock);
  106. if (bss->pub.hidden_beacon_bss) {
  107. struct cfg80211_internal_bss *hbss;
  108. hbss = container_of(bss->pub.hidden_beacon_bss,
  109. struct cfg80211_internal_bss,
  110. pub);
  111. hbss->refcount--;
  112. if (hbss->refcount == 0)
  113. bss_free(hbss);
  114. }
  115. bss->refcount--;
  116. if (bss->refcount == 0)
  117. bss_free(bss);
  118. }
  119. static bool __cfg80211_unlink_bss(struct cfg80211_registered_device *rdev,
  120. struct cfg80211_internal_bss *bss)
  121. {
  122. lockdep_assert_held(&rdev->bss_lock);
  123. if (!list_empty(&bss->hidden_list)) {
  124. /*
  125. * don't remove the beacon entry if it has
  126. * probe responses associated with it
  127. */
  128. if (!bss->pub.hidden_beacon_bss)
  129. return false;
  130. /*
  131. * if it's a probe response entry break its
  132. * link to the other entries in the group
  133. */
  134. list_del_init(&bss->hidden_list);
  135. }
  136. list_del_init(&bss->list);
  137. rb_erase(&bss->rbn, &rdev->bss_tree);
  138. rdev->bss_entries--;
  139. WARN_ONCE((rdev->bss_entries == 0) ^ list_empty(&rdev->bss_list),
  140. "rdev bss entries[%d]/list[empty:%d] corruption\n",
  141. rdev->bss_entries, list_empty(&rdev->bss_list));
  142. bss_ref_put(rdev, bss);
  143. return true;
  144. }
  145. static void __cfg80211_bss_expire(struct cfg80211_registered_device *rdev,
  146. unsigned long expire_time)
  147. {
  148. struct cfg80211_internal_bss *bss, *tmp;
  149. bool expired = false;
  150. lockdep_assert_held(&rdev->bss_lock);
  151. list_for_each_entry_safe(bss, tmp, &rdev->bss_list, list) {
  152. if (atomic_read(&bss->hold))
  153. continue;
  154. if (!time_after(expire_time, bss->ts))
  155. continue;
  156. if (__cfg80211_unlink_bss(rdev, bss))
  157. expired = true;
  158. }
  159. if (expired)
  160. rdev->bss_generation++;
  161. }
  162. static bool cfg80211_bss_expire_oldest(struct cfg80211_registered_device *rdev)
  163. {
  164. struct cfg80211_internal_bss *bss, *oldest = NULL;
  165. bool ret;
  166. lockdep_assert_held(&rdev->bss_lock);
  167. list_for_each_entry(bss, &rdev->bss_list, list) {
  168. if (atomic_read(&bss->hold))
  169. continue;
  170. if (!list_empty(&bss->hidden_list) &&
  171. !bss->pub.hidden_beacon_bss)
  172. continue;
  173. if (oldest && time_before(oldest->ts, bss->ts))
  174. continue;
  175. oldest = bss;
  176. }
  177. if (WARN_ON(!oldest))
  178. return false;
  179. /*
  180. * The callers make sure to increase rdev->bss_generation if anything
  181. * gets removed (and a new entry added), so there's no need to also do
  182. * it here.
  183. */
  184. ret = __cfg80211_unlink_bss(rdev, oldest);
  185. WARN_ON(!ret);
  186. return ret;
  187. }
  188. void ___cfg80211_scan_done(struct cfg80211_registered_device *rdev,
  189. bool send_message)
  190. {
  191. struct cfg80211_scan_request *request;
  192. struct wireless_dev *wdev;
  193. struct sk_buff *msg;
  194. #ifdef CONFIG_CFG80211_WEXT
  195. union iwreq_data wrqu;
  196. #endif
  197. ASSERT_RTNL();
  198. if (rdev->scan_msg) {
  199. nl80211_send_scan_result(rdev, rdev->scan_msg);
  200. rdev->scan_msg = NULL;
  201. return;
  202. }
  203. request = rdev->scan_req;
  204. if (!request)
  205. return;
  206. wdev = request->wdev;
  207. /*
  208. * This must be before sending the other events!
  209. * Otherwise, wpa_supplicant gets completely confused with
  210. * wext events.
  211. */
  212. if (wdev->netdev)
  213. cfg80211_sme_scan_done(wdev->netdev);
  214. if (!request->info.aborted &&
  215. request->flags & NL80211_SCAN_FLAG_FLUSH) {
  216. /* flush entries from previous scans */
  217. spin_lock_bh(&rdev->bss_lock);
  218. __cfg80211_bss_expire(rdev, request->scan_start);
  219. spin_unlock_bh(&rdev->bss_lock);
  220. }
  221. msg = nl80211_build_scan_msg(rdev, wdev, request->info.aborted);
  222. #ifdef CONFIG_CFG80211_WEXT
  223. if (wdev->netdev && !request->info.aborted) {
  224. memset(&wrqu, 0, sizeof(wrqu));
  225. wireless_send_event(wdev->netdev, SIOCGIWSCAN, &wrqu, NULL);
  226. }
  227. #endif
  228. if (wdev->netdev)
  229. dev_put(wdev->netdev);
  230. rdev->scan_req = NULL;
  231. kfree(request);
  232. if (!send_message)
  233. rdev->scan_msg = msg;
  234. else
  235. nl80211_send_scan_result(rdev, msg);
  236. }
  237. void __cfg80211_scan_done(struct work_struct *wk)
  238. {
  239. struct cfg80211_registered_device *rdev;
  240. rdev = container_of(wk, struct cfg80211_registered_device,
  241. scan_done_wk);
  242. rtnl_lock();
  243. ___cfg80211_scan_done(rdev, true);
  244. rtnl_unlock();
  245. }
  246. void cfg80211_scan_done(struct cfg80211_scan_request *request,
  247. struct cfg80211_scan_info *info)
  248. {
  249. trace_cfg80211_scan_done(request, info);
  250. WARN_ON(request != wiphy_to_rdev(request->wiphy)->scan_req);
  251. request->info = *info;
  252. request->notified = true;
  253. queue_work(cfg80211_wq, &wiphy_to_rdev(request->wiphy)->scan_done_wk);
  254. }
  255. EXPORT_SYMBOL(cfg80211_scan_done);
  256. void __cfg80211_sched_scan_results(struct work_struct *wk)
  257. {
  258. struct cfg80211_registered_device *rdev;
  259. struct cfg80211_sched_scan_request *request;
  260. rdev = container_of(wk, struct cfg80211_registered_device,
  261. sched_scan_results_wk);
  262. rtnl_lock();
  263. request = rtnl_dereference(rdev->sched_scan_req);
  264. /* we don't have sched_scan_req anymore if the scan is stopping */
  265. if (request) {
  266. if (request->flags & NL80211_SCAN_FLAG_FLUSH) {
  267. /* flush entries from previous scans */
  268. spin_lock_bh(&rdev->bss_lock);
  269. __cfg80211_bss_expire(rdev, request->scan_start);
  270. spin_unlock_bh(&rdev->bss_lock);
  271. request->scan_start = jiffies;
  272. }
  273. nl80211_send_sched_scan_results(rdev, request->dev);
  274. }
  275. rtnl_unlock();
  276. }
  277. void cfg80211_sched_scan_results(struct wiphy *wiphy)
  278. {
  279. trace_cfg80211_sched_scan_results(wiphy);
  280. /* ignore if we're not scanning */
  281. if (rcu_access_pointer(wiphy_to_rdev(wiphy)->sched_scan_req))
  282. queue_work(cfg80211_wq,
  283. &wiphy_to_rdev(wiphy)->sched_scan_results_wk);
  284. }
  285. EXPORT_SYMBOL(cfg80211_sched_scan_results);
  286. void cfg80211_sched_scan_stopped_rtnl(struct wiphy *wiphy)
  287. {
  288. struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
  289. ASSERT_RTNL();
  290. trace_cfg80211_sched_scan_stopped(wiphy);
  291. __cfg80211_stop_sched_scan(rdev, true);
  292. }
  293. EXPORT_SYMBOL(cfg80211_sched_scan_stopped_rtnl);
  294. void cfg80211_sched_scan_stopped(struct wiphy *wiphy)
  295. {
  296. rtnl_lock();
  297. cfg80211_sched_scan_stopped_rtnl(wiphy);
  298. rtnl_unlock();
  299. }
  300. EXPORT_SYMBOL(cfg80211_sched_scan_stopped);
  301. int __cfg80211_stop_sched_scan(struct cfg80211_registered_device *rdev,
  302. bool driver_initiated)
  303. {
  304. struct cfg80211_sched_scan_request *sched_scan_req;
  305. struct net_device *dev;
  306. ASSERT_RTNL();
  307. if (!rdev->sched_scan_req)
  308. return -ENOENT;
  309. sched_scan_req = rtnl_dereference(rdev->sched_scan_req);
  310. dev = sched_scan_req->dev;
  311. if (!driver_initiated) {
  312. int err = rdev_sched_scan_stop(rdev, dev);
  313. if (err)
  314. return err;
  315. }
  316. nl80211_send_sched_scan(rdev, dev, NL80211_CMD_SCHED_SCAN_STOPPED);
  317. RCU_INIT_POINTER(rdev->sched_scan_req, NULL);
  318. kfree_rcu(sched_scan_req, rcu_head);
  319. return 0;
  320. }
  321. void cfg80211_bss_age(struct cfg80211_registered_device *rdev,
  322. unsigned long age_secs)
  323. {
  324. struct cfg80211_internal_bss *bss;
  325. unsigned long age_jiffies = msecs_to_jiffies(age_secs * MSEC_PER_SEC);
  326. spin_lock_bh(&rdev->bss_lock);
  327. list_for_each_entry(bss, &rdev->bss_list, list)
  328. bss->ts -= age_jiffies;
  329. spin_unlock_bh(&rdev->bss_lock);
  330. }
  331. void cfg80211_bss_expire(struct cfg80211_registered_device *rdev)
  332. {
  333. __cfg80211_bss_expire(rdev, jiffies - IEEE80211_SCAN_RESULT_EXPIRE);
  334. }
  335. const u8 *cfg80211_find_ie_match(u8 eid, const u8 *ies, int len,
  336. const u8 *match, int match_len,
  337. int match_offset)
  338. {
  339. /* match_offset can't be smaller than 2, unless match_len is
  340. * zero, in which case match_offset must be zero as well.
  341. */
  342. if (WARN_ON((match_len && match_offset < 2) ||
  343. (!match_len && match_offset)))
  344. return NULL;
  345. while (len >= 2 && len >= ies[1] + 2) {
  346. if ((ies[0] == eid) &&
  347. (ies[1] + 2 >= match_offset + match_len) &&
  348. !memcmp(ies + match_offset, match, match_len))
  349. return ies;
  350. len -= ies[1] + 2;
  351. ies += ies[1] + 2;
  352. }
  353. return NULL;
  354. }
  355. EXPORT_SYMBOL(cfg80211_find_ie_match);
  356. const u8 *cfg80211_find_vendor_ie(unsigned int oui, int oui_type,
  357. const u8 *ies, int len)
  358. {
  359. const u8 *ie;
  360. u8 match[] = { oui >> 16, oui >> 8, oui, oui_type };
  361. int match_len = (oui_type < 0) ? 3 : sizeof(match);
  362. if (WARN_ON(oui_type > 0xff))
  363. return NULL;
  364. ie = cfg80211_find_ie_match(WLAN_EID_VENDOR_SPECIFIC, ies, len,
  365. match, match_len, 2);
  366. if (ie && (ie[1] < 4))
  367. return NULL;
  368. return ie;
  369. }
  370. EXPORT_SYMBOL(cfg80211_find_vendor_ie);
  371. static bool is_bss(struct cfg80211_bss *a, const u8 *bssid,
  372. const u8 *ssid, size_t ssid_len)
  373. {
  374. const struct cfg80211_bss_ies *ies;
  375. const u8 *ssidie;
  376. if (bssid && !ether_addr_equal(a->bssid, bssid))
  377. return false;
  378. if (!ssid)
  379. return true;
  380. ies = rcu_access_pointer(a->ies);
  381. if (!ies)
  382. return false;
  383. ssidie = cfg80211_find_ie(WLAN_EID_SSID, ies->data, ies->len);
  384. if (!ssidie)
  385. return false;
  386. if (ssidie[1] != ssid_len)
  387. return false;
  388. return memcmp(ssidie + 2, ssid, ssid_len) == 0;
  389. }
  390. /**
  391. * enum bss_compare_mode - BSS compare mode
  392. * @BSS_CMP_REGULAR: regular compare mode (for insertion and normal find)
  393. * @BSS_CMP_HIDE_ZLEN: find hidden SSID with zero-length mode
  394. * @BSS_CMP_HIDE_NUL: find hidden SSID with NUL-ed out mode
  395. */
  396. enum bss_compare_mode {
  397. BSS_CMP_REGULAR,
  398. BSS_CMP_HIDE_ZLEN,
  399. BSS_CMP_HIDE_NUL,
  400. };
  401. static int cmp_bss(struct cfg80211_bss *a,
  402. struct cfg80211_bss *b,
  403. enum bss_compare_mode mode)
  404. {
  405. const struct cfg80211_bss_ies *a_ies, *b_ies;
  406. const u8 *ie1 = NULL;
  407. const u8 *ie2 = NULL;
  408. int i, r;
  409. if (a->channel != b->channel)
  410. return b->channel->center_freq - a->channel->center_freq;
  411. a_ies = rcu_access_pointer(a->ies);
  412. if (!a_ies)
  413. return -1;
  414. b_ies = rcu_access_pointer(b->ies);
  415. if (!b_ies)
  416. return 1;
  417. if (WLAN_CAPABILITY_IS_STA_BSS(a->capability))
  418. ie1 = cfg80211_find_ie(WLAN_EID_MESH_ID,
  419. a_ies->data, a_ies->len);
  420. if (WLAN_CAPABILITY_IS_STA_BSS(b->capability))
  421. ie2 = cfg80211_find_ie(WLAN_EID_MESH_ID,
  422. b_ies->data, b_ies->len);
  423. if (ie1 && ie2) {
  424. int mesh_id_cmp;
  425. if (ie1[1] == ie2[1])
  426. mesh_id_cmp = memcmp(ie1 + 2, ie2 + 2, ie1[1]);
  427. else
  428. mesh_id_cmp = ie2[1] - ie1[1];
  429. ie1 = cfg80211_find_ie(WLAN_EID_MESH_CONFIG,
  430. a_ies->data, a_ies->len);
  431. ie2 = cfg80211_find_ie(WLAN_EID_MESH_CONFIG,
  432. b_ies->data, b_ies->len);
  433. if (ie1 && ie2) {
  434. if (mesh_id_cmp)
  435. return mesh_id_cmp;
  436. if (ie1[1] != ie2[1])
  437. return ie2[1] - ie1[1];
  438. return memcmp(ie1 + 2, ie2 + 2, ie1[1]);
  439. }
  440. }
  441. r = memcmp(a->bssid, b->bssid, sizeof(a->bssid));
  442. if (r)
  443. return r;
  444. ie1 = cfg80211_find_ie(WLAN_EID_SSID, a_ies->data, a_ies->len);
  445. ie2 = cfg80211_find_ie(WLAN_EID_SSID, b_ies->data, b_ies->len);
  446. if (!ie1 && !ie2)
  447. return 0;
  448. /*
  449. * Note that with "hide_ssid", the function returns a match if
  450. * the already-present BSS ("b") is a hidden SSID beacon for
  451. * the new BSS ("a").
  452. */
  453. /* sort missing IE before (left of) present IE */
  454. if (!ie1)
  455. return -1;
  456. if (!ie2)
  457. return 1;
  458. switch (mode) {
  459. case BSS_CMP_HIDE_ZLEN:
  460. /*
  461. * In ZLEN mode we assume the BSS entry we're
  462. * looking for has a zero-length SSID. So if
  463. * the one we're looking at right now has that,
  464. * return 0. Otherwise, return the difference
  465. * in length, but since we're looking for the
  466. * 0-length it's really equivalent to returning
  467. * the length of the one we're looking at.
  468. *
  469. * No content comparison is needed as we assume
  470. * the content length is zero.
  471. */
  472. return ie2[1];
  473. case BSS_CMP_REGULAR:
  474. default:
  475. /* sort by length first, then by contents */
  476. if (ie1[1] != ie2[1])
  477. return ie2[1] - ie1[1];
  478. return memcmp(ie1 + 2, ie2 + 2, ie1[1]);
  479. case BSS_CMP_HIDE_NUL:
  480. if (ie1[1] != ie2[1])
  481. return ie2[1] - ie1[1];
  482. /* this is equivalent to memcmp(zeroes, ie2 + 2, len) */
  483. for (i = 0; i < ie2[1]; i++)
  484. if (ie2[i + 2])
  485. return -1;
  486. return 0;
  487. }
  488. }
  489. static bool cfg80211_bss_type_match(u16 capability,
  490. enum nl80211_band band,
  491. enum ieee80211_bss_type bss_type)
  492. {
  493. bool ret = true;
  494. u16 mask, val;
  495. if (bss_type == IEEE80211_BSS_TYPE_ANY)
  496. return ret;
  497. if (band == NL80211_BAND_60GHZ) {
  498. mask = WLAN_CAPABILITY_DMG_TYPE_MASK;
  499. switch (bss_type) {
  500. case IEEE80211_BSS_TYPE_ESS:
  501. val = WLAN_CAPABILITY_DMG_TYPE_AP;
  502. break;
  503. case IEEE80211_BSS_TYPE_PBSS:
  504. val = WLAN_CAPABILITY_DMG_TYPE_PBSS;
  505. break;
  506. case IEEE80211_BSS_TYPE_IBSS:
  507. val = WLAN_CAPABILITY_DMG_TYPE_IBSS;
  508. break;
  509. default:
  510. return false;
  511. }
  512. } else {
  513. mask = WLAN_CAPABILITY_ESS | WLAN_CAPABILITY_IBSS;
  514. switch (bss_type) {
  515. case IEEE80211_BSS_TYPE_ESS:
  516. val = WLAN_CAPABILITY_ESS;
  517. break;
  518. case IEEE80211_BSS_TYPE_IBSS:
  519. val = WLAN_CAPABILITY_IBSS;
  520. break;
  521. case IEEE80211_BSS_TYPE_MBSS:
  522. val = 0;
  523. break;
  524. default:
  525. return false;
  526. }
  527. }
  528. ret = ((capability & mask) == val);
  529. return ret;
  530. }
  531. /* Returned bss is reference counted and must be cleaned up appropriately. */
  532. struct cfg80211_bss *cfg80211_get_bss(struct wiphy *wiphy,
  533. struct ieee80211_channel *channel,
  534. const u8 *bssid,
  535. const u8 *ssid, size_t ssid_len,
  536. enum ieee80211_bss_type bss_type,
  537. enum ieee80211_privacy privacy)
  538. {
  539. struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
  540. struct cfg80211_internal_bss *bss, *res = NULL;
  541. unsigned long now = jiffies;
  542. int bss_privacy;
  543. trace_cfg80211_get_bss(wiphy, channel, bssid, ssid, ssid_len, bss_type,
  544. privacy);
  545. spin_lock_bh(&rdev->bss_lock);
  546. list_for_each_entry(bss, &rdev->bss_list, list) {
  547. if (!cfg80211_bss_type_match(bss->pub.capability,
  548. bss->pub.channel->band, bss_type))
  549. continue;
  550. bss_privacy = (bss->pub.capability & WLAN_CAPABILITY_PRIVACY);
  551. if ((privacy == IEEE80211_PRIVACY_ON && !bss_privacy) ||
  552. (privacy == IEEE80211_PRIVACY_OFF && bss_privacy))
  553. continue;
  554. if (channel && bss->pub.channel != channel)
  555. continue;
  556. if (!is_valid_ether_addr(bss->pub.bssid))
  557. continue;
  558. /* Don't get expired BSS structs */
  559. if (time_after(now, bss->ts + IEEE80211_SCAN_RESULT_EXPIRE) &&
  560. !atomic_read(&bss->hold))
  561. continue;
  562. if (is_bss(&bss->pub, bssid, ssid, ssid_len)) {
  563. res = bss;
  564. bss_ref_get(rdev, res);
  565. break;
  566. }
  567. }
  568. spin_unlock_bh(&rdev->bss_lock);
  569. if (!res)
  570. return NULL;
  571. trace_cfg80211_return_bss(&res->pub);
  572. return &res->pub;
  573. }
  574. EXPORT_SYMBOL(cfg80211_get_bss);
  575. static void rb_insert_bss(struct cfg80211_registered_device *rdev,
  576. struct cfg80211_internal_bss *bss)
  577. {
  578. struct rb_node **p = &rdev->bss_tree.rb_node;
  579. struct rb_node *parent = NULL;
  580. struct cfg80211_internal_bss *tbss;
  581. int cmp;
  582. while (*p) {
  583. parent = *p;
  584. tbss = rb_entry(parent, struct cfg80211_internal_bss, rbn);
  585. cmp = cmp_bss(&bss->pub, &tbss->pub, BSS_CMP_REGULAR);
  586. if (WARN_ON(!cmp)) {
  587. /* will sort of leak this BSS */
  588. return;
  589. }
  590. if (cmp < 0)
  591. p = &(*p)->rb_left;
  592. else
  593. p = &(*p)->rb_right;
  594. }
  595. rb_link_node(&bss->rbn, parent, p);
  596. rb_insert_color(&bss->rbn, &rdev->bss_tree);
  597. }
  598. static struct cfg80211_internal_bss *
  599. rb_find_bss(struct cfg80211_registered_device *rdev,
  600. struct cfg80211_internal_bss *res,
  601. enum bss_compare_mode mode)
  602. {
  603. struct rb_node *n = rdev->bss_tree.rb_node;
  604. struct cfg80211_internal_bss *bss;
  605. int r;
  606. while (n) {
  607. bss = rb_entry(n, struct cfg80211_internal_bss, rbn);
  608. r = cmp_bss(&res->pub, &bss->pub, mode);
  609. if (r == 0)
  610. return bss;
  611. else if (r < 0)
  612. n = n->rb_left;
  613. else
  614. n = n->rb_right;
  615. }
  616. return NULL;
  617. }
  618. static bool cfg80211_combine_bsses(struct cfg80211_registered_device *rdev,
  619. struct cfg80211_internal_bss *new)
  620. {
  621. const struct cfg80211_bss_ies *ies;
  622. struct cfg80211_internal_bss *bss;
  623. const u8 *ie;
  624. int i, ssidlen;
  625. u8 fold = 0;
  626. u32 n_entries = 0;
  627. ies = rcu_access_pointer(new->pub.beacon_ies);
  628. if (WARN_ON(!ies))
  629. return false;
  630. ie = cfg80211_find_ie(WLAN_EID_SSID, ies->data, ies->len);
  631. if (!ie) {
  632. /* nothing to do */
  633. return true;
  634. }
  635. ssidlen = ie[1];
  636. for (i = 0; i < ssidlen; i++)
  637. fold |= ie[2 + i];
  638. if (fold) {
  639. /* not a hidden SSID */
  640. return true;
  641. }
  642. /* This is the bad part ... */
  643. list_for_each_entry(bss, &rdev->bss_list, list) {
  644. /*
  645. * we're iterating all the entries anyway, so take the
  646. * opportunity to validate the list length accounting
  647. */
  648. n_entries++;
  649. if (!ether_addr_equal(bss->pub.bssid, new->pub.bssid))
  650. continue;
  651. if (bss->pub.channel != new->pub.channel)
  652. continue;
  653. if (bss->pub.scan_width != new->pub.scan_width)
  654. continue;
  655. if (rcu_access_pointer(bss->pub.beacon_ies))
  656. continue;
  657. ies = rcu_access_pointer(bss->pub.ies);
  658. if (!ies)
  659. continue;
  660. ie = cfg80211_find_ie(WLAN_EID_SSID, ies->data, ies->len);
  661. if (!ie)
  662. continue;
  663. if (ssidlen && ie[1] != ssidlen)
  664. continue;
  665. if (WARN_ON_ONCE(bss->pub.hidden_beacon_bss))
  666. continue;
  667. if (WARN_ON_ONCE(!list_empty(&bss->hidden_list)))
  668. list_del(&bss->hidden_list);
  669. /* combine them */
  670. list_add(&bss->hidden_list, &new->hidden_list);
  671. bss->pub.hidden_beacon_bss = &new->pub;
  672. new->refcount += bss->refcount;
  673. rcu_assign_pointer(bss->pub.beacon_ies,
  674. new->pub.beacon_ies);
  675. }
  676. WARN_ONCE(n_entries != rdev->bss_entries,
  677. "rdev bss entries[%d]/list[len:%d] corruption\n",
  678. rdev->bss_entries, n_entries);
  679. return true;
  680. }
  681. /* Returned bss is reference counted and must be cleaned up appropriately. */
  682. static struct cfg80211_internal_bss *
  683. cfg80211_bss_update(struct cfg80211_registered_device *rdev,
  684. struct cfg80211_internal_bss *tmp,
  685. bool signal_valid)
  686. {
  687. struct cfg80211_internal_bss *found = NULL;
  688. if (WARN_ON(!tmp->pub.channel))
  689. return NULL;
  690. tmp->ts = jiffies;
  691. spin_lock_bh(&rdev->bss_lock);
  692. if (WARN_ON(!rcu_access_pointer(tmp->pub.ies))) {
  693. spin_unlock_bh(&rdev->bss_lock);
  694. return NULL;
  695. }
  696. found = rb_find_bss(rdev, tmp, BSS_CMP_REGULAR);
  697. if (found) {
  698. /* Update IEs */
  699. if (rcu_access_pointer(tmp->pub.proberesp_ies)) {
  700. const struct cfg80211_bss_ies *old;
  701. old = rcu_access_pointer(found->pub.proberesp_ies);
  702. rcu_assign_pointer(found->pub.proberesp_ies,
  703. tmp->pub.proberesp_ies);
  704. /* Override possible earlier Beacon frame IEs */
  705. rcu_assign_pointer(found->pub.ies,
  706. tmp->pub.proberesp_ies);
  707. if (old)
  708. kfree_rcu((struct cfg80211_bss_ies *)old,
  709. rcu_head);
  710. } else if (rcu_access_pointer(tmp->pub.beacon_ies)) {
  711. const struct cfg80211_bss_ies *old;
  712. struct cfg80211_internal_bss *bss;
  713. if (found->pub.hidden_beacon_bss &&
  714. !list_empty(&found->hidden_list)) {
  715. const struct cfg80211_bss_ies *f;
  716. /*
  717. * The found BSS struct is one of the probe
  718. * response members of a group, but we're
  719. * receiving a beacon (beacon_ies in the tmp
  720. * bss is used). This can only mean that the
  721. * AP changed its beacon from not having an
  722. * SSID to showing it, which is confusing so
  723. * drop this information.
  724. */
  725. f = rcu_access_pointer(tmp->pub.beacon_ies);
  726. kfree_rcu((struct cfg80211_bss_ies *)f,
  727. rcu_head);
  728. goto drop;
  729. }
  730. old = rcu_access_pointer(found->pub.beacon_ies);
  731. rcu_assign_pointer(found->pub.beacon_ies,
  732. tmp->pub.beacon_ies);
  733. /* Override IEs if they were from a beacon before */
  734. if (old == rcu_access_pointer(found->pub.ies))
  735. rcu_assign_pointer(found->pub.ies,
  736. tmp->pub.beacon_ies);
  737. /* Assign beacon IEs to all sub entries */
  738. list_for_each_entry(bss, &found->hidden_list,
  739. hidden_list) {
  740. const struct cfg80211_bss_ies *ies;
  741. ies = rcu_access_pointer(bss->pub.beacon_ies);
  742. WARN_ON(ies != old);
  743. rcu_assign_pointer(bss->pub.beacon_ies,
  744. tmp->pub.beacon_ies);
  745. }
  746. if (old)
  747. kfree_rcu((struct cfg80211_bss_ies *)old,
  748. rcu_head);
  749. }
  750. found->pub.beacon_interval = tmp->pub.beacon_interval;
  751. /*
  752. * don't update the signal if beacon was heard on
  753. * adjacent channel.
  754. */
  755. if (signal_valid)
  756. found->pub.signal = tmp->pub.signal;
  757. found->pub.capability = tmp->pub.capability;
  758. found->ts = tmp->ts;
  759. found->ts_boottime = tmp->ts_boottime;
  760. found->parent_tsf = tmp->parent_tsf;
  761. ether_addr_copy(found->parent_bssid, tmp->parent_bssid);
  762. } else {
  763. struct cfg80211_internal_bss *new;
  764. struct cfg80211_internal_bss *hidden;
  765. struct cfg80211_bss_ies *ies;
  766. /*
  767. * create a copy -- the "res" variable that is passed in
  768. * is allocated on the stack since it's not needed in the
  769. * more common case of an update
  770. */
  771. new = kzalloc(sizeof(*new) + rdev->wiphy.bss_priv_size,
  772. GFP_ATOMIC);
  773. if (!new) {
  774. ies = (void *)rcu_dereference(tmp->pub.beacon_ies);
  775. if (ies)
  776. kfree_rcu(ies, rcu_head);
  777. ies = (void *)rcu_dereference(tmp->pub.proberesp_ies);
  778. if (ies)
  779. kfree_rcu(ies, rcu_head);
  780. goto drop;
  781. }
  782. memcpy(new, tmp, sizeof(*new));
  783. new->refcount = 1;
  784. INIT_LIST_HEAD(&new->hidden_list);
  785. if (rcu_access_pointer(tmp->pub.proberesp_ies)) {
  786. hidden = rb_find_bss(rdev, tmp, BSS_CMP_HIDE_ZLEN);
  787. if (!hidden)
  788. hidden = rb_find_bss(rdev, tmp,
  789. BSS_CMP_HIDE_NUL);
  790. if (hidden) {
  791. new->pub.hidden_beacon_bss = &hidden->pub;
  792. list_add(&new->hidden_list,
  793. &hidden->hidden_list);
  794. hidden->refcount++;
  795. rcu_assign_pointer(new->pub.beacon_ies,
  796. hidden->pub.beacon_ies);
  797. }
  798. } else {
  799. /*
  800. * Ok so we found a beacon, and don't have an entry. If
  801. * it's a beacon with hidden SSID, we might be in for an
  802. * expensive search for any probe responses that should
  803. * be grouped with this beacon for updates ...
  804. */
  805. if (!cfg80211_combine_bsses(rdev, new)) {
  806. kfree(new);
  807. goto drop;
  808. }
  809. }
  810. if (rdev->bss_entries >= bss_entries_limit &&
  811. !cfg80211_bss_expire_oldest(rdev)) {
  812. kfree(new);
  813. goto drop;
  814. }
  815. list_add_tail(&new->list, &rdev->bss_list);
  816. rdev->bss_entries++;
  817. rb_insert_bss(rdev, new);
  818. found = new;
  819. }
  820. rdev->bss_generation++;
  821. bss_ref_get(rdev, found);
  822. spin_unlock_bh(&rdev->bss_lock);
  823. return found;
  824. drop:
  825. spin_unlock_bh(&rdev->bss_lock);
  826. return NULL;
  827. }
  828. /*
  829. * Update RX channel information based on the available frame payload
  830. * information. This is mainly for the 2.4 GHz band where frames can be received
  831. * from neighboring channels and the Beacon frames use the DSSS Parameter Set
  832. * element to indicate the current (transmitting) channel, but this might also
  833. * be needed on other bands if RX frequency does not match with the actual
  834. * operating channel of a BSS.
  835. */
  836. static struct ieee80211_channel *
  837. cfg80211_get_bss_channel(struct wiphy *wiphy, const u8 *ie, size_t ielen,
  838. struct ieee80211_channel *channel,
  839. enum nl80211_bss_scan_width scan_width)
  840. {
  841. const u8 *tmp;
  842. u32 freq;
  843. int channel_number = -1;
  844. struct ieee80211_channel *alt_channel;
  845. tmp = cfg80211_find_ie(WLAN_EID_DS_PARAMS, ie, ielen);
  846. if (tmp && tmp[1] == 1) {
  847. channel_number = tmp[2];
  848. } else {
  849. tmp = cfg80211_find_ie(WLAN_EID_HT_OPERATION, ie, ielen);
  850. if (tmp && tmp[1] >= sizeof(struct ieee80211_ht_operation)) {
  851. struct ieee80211_ht_operation *htop = (void *)(tmp + 2);
  852. channel_number = htop->primary_chan;
  853. }
  854. }
  855. if (channel_number < 0) {
  856. /* No channel information in frame payload */
  857. return channel;
  858. }
  859. freq = ieee80211_channel_to_frequency(channel_number, channel->band);
  860. alt_channel = ieee80211_get_channel(wiphy, freq);
  861. if (!alt_channel) {
  862. if (channel->band == NL80211_BAND_2GHZ) {
  863. /*
  864. * Better not allow unexpected channels when that could
  865. * be going beyond the 1-11 range (e.g., discovering
  866. * BSS on channel 12 when radio is configured for
  867. * channel 11.
  868. */
  869. return NULL;
  870. }
  871. /* No match for the payload channel number - ignore it */
  872. return channel;
  873. }
  874. if (scan_width == NL80211_BSS_CHAN_WIDTH_10 ||
  875. scan_width == NL80211_BSS_CHAN_WIDTH_5) {
  876. /*
  877. * Ignore channel number in 5 and 10 MHz channels where there
  878. * may not be an n:1 or 1:n mapping between frequencies and
  879. * channel numbers.
  880. */
  881. return channel;
  882. }
  883. /*
  884. * Use the channel determined through the payload channel number
  885. * instead of the RX channel reported by the driver.
  886. */
  887. if (alt_channel->flags & IEEE80211_CHAN_DISABLED)
  888. return NULL;
  889. return alt_channel;
  890. }
  891. /* Returned bss is reference counted and must be cleaned up appropriately. */
  892. struct cfg80211_bss *
  893. cfg80211_inform_bss_data(struct wiphy *wiphy,
  894. struct cfg80211_inform_bss *data,
  895. enum cfg80211_bss_frame_type ftype,
  896. const u8 *bssid, u64 tsf, u16 capability,
  897. u16 beacon_interval, const u8 *ie, size_t ielen,
  898. gfp_t gfp)
  899. {
  900. struct cfg80211_bss_ies *ies;
  901. struct ieee80211_channel *channel;
  902. struct cfg80211_internal_bss tmp = {}, *res;
  903. int bss_type;
  904. bool signal_valid;
  905. if (WARN_ON(!wiphy))
  906. return NULL;
  907. if (WARN_ON(wiphy->signal_type == CFG80211_SIGNAL_TYPE_UNSPEC &&
  908. (data->signal < 0 || data->signal > 100)))
  909. return NULL;
  910. channel = cfg80211_get_bss_channel(wiphy, ie, ielen, data->chan,
  911. data->scan_width);
  912. if (!channel)
  913. return NULL;
  914. memcpy(tmp.pub.bssid, bssid, ETH_ALEN);
  915. tmp.pub.channel = channel;
  916. tmp.pub.scan_width = data->scan_width;
  917. tmp.pub.signal = data->signal;
  918. tmp.pub.beacon_interval = beacon_interval;
  919. tmp.pub.capability = capability;
  920. tmp.ts_boottime = data->boottime_ns;
  921. /*
  922. * If we do not know here whether the IEs are from a Beacon or Probe
  923. * Response frame, we need to pick one of the options and only use it
  924. * with the driver that does not provide the full Beacon/Probe Response
  925. * frame. Use Beacon frame pointer to avoid indicating that this should
  926. * override the IEs pointer should we have received an earlier
  927. * indication of Probe Response data.
  928. */
  929. ies = kzalloc(sizeof(*ies) + ielen, gfp);
  930. if (!ies)
  931. return NULL;
  932. ies->len = ielen;
  933. ies->tsf = tsf;
  934. ies->from_beacon = false;
  935. memcpy(ies->data, ie, ielen);
  936. switch (ftype) {
  937. case CFG80211_BSS_FTYPE_BEACON:
  938. ies->from_beacon = true;
  939. /* fall through to assign */
  940. case CFG80211_BSS_FTYPE_UNKNOWN:
  941. rcu_assign_pointer(tmp.pub.beacon_ies, ies);
  942. break;
  943. case CFG80211_BSS_FTYPE_PRESP:
  944. rcu_assign_pointer(tmp.pub.proberesp_ies, ies);
  945. break;
  946. }
  947. rcu_assign_pointer(tmp.pub.ies, ies);
  948. signal_valid = abs(data->chan->center_freq - channel->center_freq) <=
  949. wiphy->max_adj_channel_rssi_comp;
  950. res = cfg80211_bss_update(wiphy_to_rdev(wiphy), &tmp, signal_valid);
  951. if (!res)
  952. return NULL;
  953. if (channel->band == NL80211_BAND_60GHZ) {
  954. bss_type = res->pub.capability & WLAN_CAPABILITY_DMG_TYPE_MASK;
  955. if (bss_type == WLAN_CAPABILITY_DMG_TYPE_AP ||
  956. bss_type == WLAN_CAPABILITY_DMG_TYPE_PBSS)
  957. regulatory_hint_found_beacon(wiphy, channel, gfp);
  958. } else {
  959. if (res->pub.capability & WLAN_CAPABILITY_ESS)
  960. regulatory_hint_found_beacon(wiphy, channel, gfp);
  961. }
  962. trace_cfg80211_return_bss(&res->pub);
  963. /* cfg80211_bss_update gives us a referenced result */
  964. return &res->pub;
  965. }
  966. EXPORT_SYMBOL(cfg80211_inform_bss_data);
  967. /* cfg80211_inform_bss_width_frame helper */
  968. struct cfg80211_bss *
  969. cfg80211_inform_bss_frame_data(struct wiphy *wiphy,
  970. struct cfg80211_inform_bss *data,
  971. struct ieee80211_mgmt *mgmt, size_t len,
  972. gfp_t gfp)
  973. {
  974. struct cfg80211_internal_bss tmp = {}, *res;
  975. struct cfg80211_bss_ies *ies;
  976. struct ieee80211_channel *channel;
  977. bool signal_valid;
  978. size_t ielen = len - offsetof(struct ieee80211_mgmt,
  979. u.probe_resp.variable);
  980. int bss_type;
  981. BUILD_BUG_ON(offsetof(struct ieee80211_mgmt, u.probe_resp.variable) !=
  982. offsetof(struct ieee80211_mgmt, u.beacon.variable));
  983. trace_cfg80211_inform_bss_frame(wiphy, data, mgmt, len);
  984. if (WARN_ON(!mgmt))
  985. return NULL;
  986. if (WARN_ON(!wiphy))
  987. return NULL;
  988. if (WARN_ON(wiphy->signal_type == CFG80211_SIGNAL_TYPE_UNSPEC &&
  989. (data->signal < 0 || data->signal > 100)))
  990. return NULL;
  991. if (WARN_ON(len < offsetof(struct ieee80211_mgmt, u.probe_resp.variable)))
  992. return NULL;
  993. channel = cfg80211_get_bss_channel(wiphy, mgmt->u.beacon.variable,
  994. ielen, data->chan, data->scan_width);
  995. if (!channel)
  996. return NULL;
  997. ies = kzalloc(sizeof(*ies) + ielen, gfp);
  998. if (!ies)
  999. return NULL;
  1000. ies->len = ielen;
  1001. ies->tsf = le64_to_cpu(mgmt->u.probe_resp.timestamp);
  1002. ies->from_beacon = ieee80211_is_beacon(mgmt->frame_control);
  1003. memcpy(ies->data, mgmt->u.probe_resp.variable, ielen);
  1004. if (ieee80211_is_probe_resp(mgmt->frame_control))
  1005. rcu_assign_pointer(tmp.pub.proberesp_ies, ies);
  1006. else
  1007. rcu_assign_pointer(tmp.pub.beacon_ies, ies);
  1008. rcu_assign_pointer(tmp.pub.ies, ies);
  1009. memcpy(tmp.pub.bssid, mgmt->bssid, ETH_ALEN);
  1010. tmp.pub.channel = channel;
  1011. tmp.pub.scan_width = data->scan_width;
  1012. tmp.pub.signal = data->signal;
  1013. tmp.pub.beacon_interval = le16_to_cpu(mgmt->u.probe_resp.beacon_int);
  1014. tmp.pub.capability = le16_to_cpu(mgmt->u.probe_resp.capab_info);
  1015. tmp.ts_boottime = data->boottime_ns;
  1016. tmp.parent_tsf = data->parent_tsf;
  1017. ether_addr_copy(tmp.parent_bssid, data->parent_bssid);
  1018. signal_valid = abs(data->chan->center_freq - channel->center_freq) <=
  1019. wiphy->max_adj_channel_rssi_comp;
  1020. res = cfg80211_bss_update(wiphy_to_rdev(wiphy), &tmp, signal_valid);
  1021. if (!res)
  1022. return NULL;
  1023. if (channel->band == NL80211_BAND_60GHZ) {
  1024. bss_type = res->pub.capability & WLAN_CAPABILITY_DMG_TYPE_MASK;
  1025. if (bss_type == WLAN_CAPABILITY_DMG_TYPE_AP ||
  1026. bss_type == WLAN_CAPABILITY_DMG_TYPE_PBSS)
  1027. regulatory_hint_found_beacon(wiphy, channel, gfp);
  1028. } else {
  1029. if (res->pub.capability & WLAN_CAPABILITY_ESS)
  1030. regulatory_hint_found_beacon(wiphy, channel, gfp);
  1031. }
  1032. trace_cfg80211_return_bss(&res->pub);
  1033. /* cfg80211_bss_update gives us a referenced result */
  1034. return &res->pub;
  1035. }
  1036. EXPORT_SYMBOL(cfg80211_inform_bss_frame_data);
  1037. void cfg80211_ref_bss(struct wiphy *wiphy, struct cfg80211_bss *pub)
  1038. {
  1039. struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
  1040. struct cfg80211_internal_bss *bss;
  1041. if (!pub)
  1042. return;
  1043. bss = container_of(pub, struct cfg80211_internal_bss, pub);
  1044. spin_lock_bh(&rdev->bss_lock);
  1045. bss_ref_get(rdev, bss);
  1046. spin_unlock_bh(&rdev->bss_lock);
  1047. }
  1048. EXPORT_SYMBOL(cfg80211_ref_bss);
  1049. void cfg80211_put_bss(struct wiphy *wiphy, struct cfg80211_bss *pub)
  1050. {
  1051. struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
  1052. struct cfg80211_internal_bss *bss;
  1053. if (!pub)
  1054. return;
  1055. bss = container_of(pub, struct cfg80211_internal_bss, pub);
  1056. spin_lock_bh(&rdev->bss_lock);
  1057. bss_ref_put(rdev, bss);
  1058. spin_unlock_bh(&rdev->bss_lock);
  1059. }
  1060. EXPORT_SYMBOL(cfg80211_put_bss);
  1061. void cfg80211_unlink_bss(struct wiphy *wiphy, struct cfg80211_bss *pub)
  1062. {
  1063. struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
  1064. struct cfg80211_internal_bss *bss;
  1065. if (WARN_ON(!pub))
  1066. return;
  1067. bss = container_of(pub, struct cfg80211_internal_bss, pub);
  1068. spin_lock_bh(&rdev->bss_lock);
  1069. if (!list_empty(&bss->list)) {
  1070. if (__cfg80211_unlink_bss(rdev, bss))
  1071. rdev->bss_generation++;
  1072. }
  1073. spin_unlock_bh(&rdev->bss_lock);
  1074. }
  1075. EXPORT_SYMBOL(cfg80211_unlink_bss);
  1076. #ifdef CONFIG_CFG80211_WEXT
  1077. static struct cfg80211_registered_device *
  1078. cfg80211_get_dev_from_ifindex(struct net *net, int ifindex)
  1079. {
  1080. struct cfg80211_registered_device *rdev;
  1081. struct net_device *dev;
  1082. ASSERT_RTNL();
  1083. dev = dev_get_by_index(net, ifindex);
  1084. if (!dev)
  1085. return ERR_PTR(-ENODEV);
  1086. if (dev->ieee80211_ptr)
  1087. rdev = wiphy_to_rdev(dev->ieee80211_ptr->wiphy);
  1088. else
  1089. rdev = ERR_PTR(-ENODEV);
  1090. dev_put(dev);
  1091. return rdev;
  1092. }
  1093. int cfg80211_wext_siwscan(struct net_device *dev,
  1094. struct iw_request_info *info,
  1095. union iwreq_data *wrqu, char *extra)
  1096. {
  1097. struct cfg80211_registered_device *rdev;
  1098. struct wiphy *wiphy;
  1099. struct iw_scan_req *wreq = NULL;
  1100. struct cfg80211_scan_request *creq = NULL;
  1101. int i, err, n_channels = 0;
  1102. enum nl80211_band band;
  1103. if (!netif_running(dev))
  1104. return -ENETDOWN;
  1105. if (wrqu->data.length == sizeof(struct iw_scan_req))
  1106. wreq = (struct iw_scan_req *)extra;
  1107. rdev = cfg80211_get_dev_from_ifindex(dev_net(dev), dev->ifindex);
  1108. if (IS_ERR(rdev))
  1109. return PTR_ERR(rdev);
  1110. if (rdev->scan_req || rdev->scan_msg) {
  1111. err = -EBUSY;
  1112. goto out;
  1113. }
  1114. wiphy = &rdev->wiphy;
  1115. /* Determine number of channels, needed to allocate creq */
  1116. if (wreq && wreq->num_channels)
  1117. n_channels = wreq->num_channels;
  1118. else
  1119. n_channels = ieee80211_get_num_supported_channels(wiphy);
  1120. creq = kzalloc(sizeof(*creq) + sizeof(struct cfg80211_ssid) +
  1121. n_channels * sizeof(void *),
  1122. GFP_ATOMIC);
  1123. if (!creq) {
  1124. err = -ENOMEM;
  1125. goto out;
  1126. }
  1127. creq->wiphy = wiphy;
  1128. creq->wdev = dev->ieee80211_ptr;
  1129. /* SSIDs come after channels */
  1130. creq->ssids = (void *)&creq->channels[n_channels];
  1131. creq->n_channels = n_channels;
  1132. creq->n_ssids = 1;
  1133. creq->scan_start = jiffies;
  1134. /* translate "Scan on frequencies" request */
  1135. i = 0;
  1136. for (band = 0; band < NUM_NL80211_BANDS; band++) {
  1137. int j;
  1138. if (!wiphy->bands[band])
  1139. continue;
  1140. for (j = 0; j < wiphy->bands[band]->n_channels; j++) {
  1141. /* ignore disabled channels */
  1142. if (wiphy->bands[band]->channels[j].flags &
  1143. IEEE80211_CHAN_DISABLED)
  1144. continue;
  1145. /* If we have a wireless request structure and the
  1146. * wireless request specifies frequencies, then search
  1147. * for the matching hardware channel.
  1148. */
  1149. if (wreq && wreq->num_channels) {
  1150. int k;
  1151. int wiphy_freq = wiphy->bands[band]->channels[j].center_freq;
  1152. for (k = 0; k < wreq->num_channels; k++) {
  1153. struct iw_freq *freq =
  1154. &wreq->channel_list[k];
  1155. int wext_freq =
  1156. cfg80211_wext_freq(freq);
  1157. if (wext_freq == wiphy_freq)
  1158. goto wext_freq_found;
  1159. }
  1160. goto wext_freq_not_found;
  1161. }
  1162. wext_freq_found:
  1163. creq->channels[i] = &wiphy->bands[band]->channels[j];
  1164. i++;
  1165. wext_freq_not_found: ;
  1166. }
  1167. }
  1168. /* No channels found? */
  1169. if (!i) {
  1170. err = -EINVAL;
  1171. goto out;
  1172. }
  1173. /* Set real number of channels specified in creq->channels[] */
  1174. creq->n_channels = i;
  1175. /* translate "Scan for SSID" request */
  1176. if (wreq) {
  1177. if (wrqu->data.flags & IW_SCAN_THIS_ESSID) {
  1178. if (wreq->essid_len > IEEE80211_MAX_SSID_LEN) {
  1179. err = -EINVAL;
  1180. goto out;
  1181. }
  1182. memcpy(creq->ssids[0].ssid, wreq->essid, wreq->essid_len);
  1183. creq->ssids[0].ssid_len = wreq->essid_len;
  1184. }
  1185. if (wreq->scan_type == IW_SCAN_TYPE_PASSIVE)
  1186. creq->n_ssids = 0;
  1187. }
  1188. for (i = 0; i < NUM_NL80211_BANDS; i++)
  1189. if (wiphy->bands[i])
  1190. creq->rates[i] = (1 << wiphy->bands[i]->n_bitrates) - 1;
  1191. eth_broadcast_addr(creq->bssid);
  1192. rdev->scan_req = creq;
  1193. err = rdev_scan(rdev, creq);
  1194. if (err) {
  1195. rdev->scan_req = NULL;
  1196. /* creq will be freed below */
  1197. } else {
  1198. nl80211_send_scan_start(rdev, dev->ieee80211_ptr);
  1199. /* creq now owned by driver */
  1200. creq = NULL;
  1201. dev_hold(dev);
  1202. }
  1203. out:
  1204. kfree(creq);
  1205. return err;
  1206. }
  1207. EXPORT_WEXT_HANDLER(cfg80211_wext_siwscan);
  1208. static char *ieee80211_scan_add_ies(struct iw_request_info *info,
  1209. const struct cfg80211_bss_ies *ies,
  1210. char *current_ev, char *end_buf)
  1211. {
  1212. const u8 *pos, *end, *next;
  1213. struct iw_event iwe;
  1214. if (!ies)
  1215. return current_ev;
  1216. /*
  1217. * If needed, fragment the IEs buffer (at IE boundaries) into short
  1218. * enough fragments to fit into IW_GENERIC_IE_MAX octet messages.
  1219. */
  1220. pos = ies->data;
  1221. end = pos + ies->len;
  1222. while (end - pos > IW_GENERIC_IE_MAX) {
  1223. next = pos + 2 + pos[1];
  1224. while (next + 2 + next[1] - pos < IW_GENERIC_IE_MAX)
  1225. next = next + 2 + next[1];
  1226. memset(&iwe, 0, sizeof(iwe));
  1227. iwe.cmd = IWEVGENIE;
  1228. iwe.u.data.length = next - pos;
  1229. current_ev = iwe_stream_add_point_check(info, current_ev,
  1230. end_buf, &iwe,
  1231. (void *)pos);
  1232. if (IS_ERR(current_ev))
  1233. return current_ev;
  1234. pos = next;
  1235. }
  1236. if (end > pos) {
  1237. memset(&iwe, 0, sizeof(iwe));
  1238. iwe.cmd = IWEVGENIE;
  1239. iwe.u.data.length = end - pos;
  1240. current_ev = iwe_stream_add_point_check(info, current_ev,
  1241. end_buf, &iwe,
  1242. (void *)pos);
  1243. if (IS_ERR(current_ev))
  1244. return current_ev;
  1245. }
  1246. return current_ev;
  1247. }
  1248. static char *
  1249. ieee80211_bss(struct wiphy *wiphy, struct iw_request_info *info,
  1250. struct cfg80211_internal_bss *bss, char *current_ev,
  1251. char *end_buf)
  1252. {
  1253. const struct cfg80211_bss_ies *ies;
  1254. struct iw_event iwe;
  1255. const u8 *ie;
  1256. u8 buf[50];
  1257. u8 *cfg, *p, *tmp;
  1258. int rem, i, sig;
  1259. bool ismesh = false;
  1260. memset(&iwe, 0, sizeof(iwe));
  1261. iwe.cmd = SIOCGIWAP;
  1262. iwe.u.ap_addr.sa_family = ARPHRD_ETHER;
  1263. memcpy(iwe.u.ap_addr.sa_data, bss->pub.bssid, ETH_ALEN);
  1264. current_ev = iwe_stream_add_event_check(info, current_ev, end_buf, &iwe,
  1265. IW_EV_ADDR_LEN);
  1266. if (IS_ERR(current_ev))
  1267. return current_ev;
  1268. memset(&iwe, 0, sizeof(iwe));
  1269. iwe.cmd = SIOCGIWFREQ;
  1270. iwe.u.freq.m = ieee80211_frequency_to_channel(bss->pub.channel->center_freq);
  1271. iwe.u.freq.e = 0;
  1272. current_ev = iwe_stream_add_event_check(info, current_ev, end_buf, &iwe,
  1273. IW_EV_FREQ_LEN);
  1274. if (IS_ERR(current_ev))
  1275. return current_ev;
  1276. memset(&iwe, 0, sizeof(iwe));
  1277. iwe.cmd = SIOCGIWFREQ;
  1278. iwe.u.freq.m = bss->pub.channel->center_freq;
  1279. iwe.u.freq.e = 6;
  1280. current_ev = iwe_stream_add_event_check(info, current_ev, end_buf, &iwe,
  1281. IW_EV_FREQ_LEN);
  1282. if (IS_ERR(current_ev))
  1283. return current_ev;
  1284. if (wiphy->signal_type != CFG80211_SIGNAL_TYPE_NONE) {
  1285. memset(&iwe, 0, sizeof(iwe));
  1286. iwe.cmd = IWEVQUAL;
  1287. iwe.u.qual.updated = IW_QUAL_LEVEL_UPDATED |
  1288. IW_QUAL_NOISE_INVALID |
  1289. IW_QUAL_QUAL_UPDATED;
  1290. switch (wiphy->signal_type) {
  1291. case CFG80211_SIGNAL_TYPE_MBM:
  1292. sig = bss->pub.signal / 100;
  1293. iwe.u.qual.level = sig;
  1294. iwe.u.qual.updated |= IW_QUAL_DBM;
  1295. if (sig < -110) /* rather bad */
  1296. sig = -110;
  1297. else if (sig > -40) /* perfect */
  1298. sig = -40;
  1299. /* will give a range of 0 .. 70 */
  1300. iwe.u.qual.qual = sig + 110;
  1301. break;
  1302. case CFG80211_SIGNAL_TYPE_UNSPEC:
  1303. iwe.u.qual.level = bss->pub.signal;
  1304. /* will give range 0 .. 100 */
  1305. iwe.u.qual.qual = bss->pub.signal;
  1306. break;
  1307. default:
  1308. /* not reached */
  1309. break;
  1310. }
  1311. current_ev = iwe_stream_add_event_check(info, current_ev,
  1312. end_buf, &iwe,
  1313. IW_EV_QUAL_LEN);
  1314. if (IS_ERR(current_ev))
  1315. return current_ev;
  1316. }
  1317. memset(&iwe, 0, sizeof(iwe));
  1318. iwe.cmd = SIOCGIWENCODE;
  1319. if (bss->pub.capability & WLAN_CAPABILITY_PRIVACY)
  1320. iwe.u.data.flags = IW_ENCODE_ENABLED | IW_ENCODE_NOKEY;
  1321. else
  1322. iwe.u.data.flags = IW_ENCODE_DISABLED;
  1323. iwe.u.data.length = 0;
  1324. current_ev = iwe_stream_add_point_check(info, current_ev, end_buf,
  1325. &iwe, "");
  1326. if (IS_ERR(current_ev))
  1327. return current_ev;
  1328. rcu_read_lock();
  1329. ies = rcu_dereference(bss->pub.ies);
  1330. rem = ies->len;
  1331. ie = ies->data;
  1332. while (rem >= 2) {
  1333. /* invalid data */
  1334. if (ie[1] > rem - 2)
  1335. break;
  1336. switch (ie[0]) {
  1337. case WLAN_EID_SSID:
  1338. memset(&iwe, 0, sizeof(iwe));
  1339. iwe.cmd = SIOCGIWESSID;
  1340. iwe.u.data.length = ie[1];
  1341. iwe.u.data.flags = 1;
  1342. current_ev = iwe_stream_add_point_check(info,
  1343. current_ev,
  1344. end_buf, &iwe,
  1345. (u8 *)ie + 2);
  1346. if (IS_ERR(current_ev))
  1347. goto unlock;
  1348. break;
  1349. case WLAN_EID_MESH_ID:
  1350. memset(&iwe, 0, sizeof(iwe));
  1351. iwe.cmd = SIOCGIWESSID;
  1352. iwe.u.data.length = ie[1];
  1353. iwe.u.data.flags = 1;
  1354. current_ev = iwe_stream_add_point_check(info,
  1355. current_ev,
  1356. end_buf, &iwe,
  1357. (u8 *)ie + 2);
  1358. if (IS_ERR(current_ev))
  1359. goto unlock;
  1360. break;
  1361. case WLAN_EID_MESH_CONFIG:
  1362. ismesh = true;
  1363. if (ie[1] != sizeof(struct ieee80211_meshconf_ie))
  1364. break;
  1365. cfg = (u8 *)ie + 2;
  1366. memset(&iwe, 0, sizeof(iwe));
  1367. iwe.cmd = IWEVCUSTOM;
  1368. sprintf(buf, "Mesh Network Path Selection Protocol ID: "
  1369. "0x%02X", cfg[0]);
  1370. iwe.u.data.length = strlen(buf);
  1371. current_ev = iwe_stream_add_point_check(info,
  1372. current_ev,
  1373. end_buf,
  1374. &iwe, buf);
  1375. if (IS_ERR(current_ev))
  1376. goto unlock;
  1377. sprintf(buf, "Path Selection Metric ID: 0x%02X",
  1378. cfg[1]);
  1379. iwe.u.data.length = strlen(buf);
  1380. current_ev = iwe_stream_add_point_check(info,
  1381. current_ev,
  1382. end_buf,
  1383. &iwe, buf);
  1384. if (IS_ERR(current_ev))
  1385. goto unlock;
  1386. sprintf(buf, "Congestion Control Mode ID: 0x%02X",
  1387. cfg[2]);
  1388. iwe.u.data.length = strlen(buf);
  1389. current_ev = iwe_stream_add_point_check(info,
  1390. current_ev,
  1391. end_buf,
  1392. &iwe, buf);
  1393. if (IS_ERR(current_ev))
  1394. goto unlock;
  1395. sprintf(buf, "Synchronization ID: 0x%02X", cfg[3]);
  1396. iwe.u.data.length = strlen(buf);
  1397. current_ev = iwe_stream_add_point_check(info,
  1398. current_ev,
  1399. end_buf,
  1400. &iwe, buf);
  1401. if (IS_ERR(current_ev))
  1402. goto unlock;
  1403. sprintf(buf, "Authentication ID: 0x%02X", cfg[4]);
  1404. iwe.u.data.length = strlen(buf);
  1405. current_ev = iwe_stream_add_point_check(info,
  1406. current_ev,
  1407. end_buf,
  1408. &iwe, buf);
  1409. if (IS_ERR(current_ev))
  1410. goto unlock;
  1411. sprintf(buf, "Formation Info: 0x%02X", cfg[5]);
  1412. iwe.u.data.length = strlen(buf);
  1413. current_ev = iwe_stream_add_point_check(info,
  1414. current_ev,
  1415. end_buf,
  1416. &iwe, buf);
  1417. if (IS_ERR(current_ev))
  1418. goto unlock;
  1419. sprintf(buf, "Capabilities: 0x%02X", cfg[6]);
  1420. iwe.u.data.length = strlen(buf);
  1421. current_ev = iwe_stream_add_point_check(info,
  1422. current_ev,
  1423. end_buf,
  1424. &iwe, buf);
  1425. if (IS_ERR(current_ev))
  1426. goto unlock;
  1427. break;
  1428. case WLAN_EID_SUPP_RATES:
  1429. case WLAN_EID_EXT_SUPP_RATES:
  1430. /* display all supported rates in readable format */
  1431. p = current_ev + iwe_stream_lcp_len(info);
  1432. memset(&iwe, 0, sizeof(iwe));
  1433. iwe.cmd = SIOCGIWRATE;
  1434. /* Those two flags are ignored... */
  1435. iwe.u.bitrate.fixed = iwe.u.bitrate.disabled = 0;
  1436. for (i = 0; i < ie[1]; i++) {
  1437. iwe.u.bitrate.value =
  1438. ((ie[i + 2] & 0x7f) * 500000);
  1439. tmp = p;
  1440. p = iwe_stream_add_value(info, current_ev, p,
  1441. end_buf, &iwe,
  1442. IW_EV_PARAM_LEN);
  1443. if (p == tmp) {
  1444. current_ev = ERR_PTR(-E2BIG);
  1445. goto unlock;
  1446. }
  1447. }
  1448. current_ev = p;
  1449. break;
  1450. }
  1451. rem -= ie[1] + 2;
  1452. ie += ie[1] + 2;
  1453. }
  1454. if (bss->pub.capability & (WLAN_CAPABILITY_ESS | WLAN_CAPABILITY_IBSS) ||
  1455. ismesh) {
  1456. memset(&iwe, 0, sizeof(iwe));
  1457. iwe.cmd = SIOCGIWMODE;
  1458. if (ismesh)
  1459. iwe.u.mode = IW_MODE_MESH;
  1460. else if (bss->pub.capability & WLAN_CAPABILITY_ESS)
  1461. iwe.u.mode = IW_MODE_MASTER;
  1462. else
  1463. iwe.u.mode = IW_MODE_ADHOC;
  1464. current_ev = iwe_stream_add_event_check(info, current_ev,
  1465. end_buf, &iwe,
  1466. IW_EV_UINT_LEN);
  1467. if (IS_ERR(current_ev))
  1468. goto unlock;
  1469. }
  1470. memset(&iwe, 0, sizeof(iwe));
  1471. iwe.cmd = IWEVCUSTOM;
  1472. sprintf(buf, "tsf=%016llx", (unsigned long long)(ies->tsf));
  1473. iwe.u.data.length = strlen(buf);
  1474. current_ev = iwe_stream_add_point_check(info, current_ev, end_buf,
  1475. &iwe, buf);
  1476. if (IS_ERR(current_ev))
  1477. goto unlock;
  1478. memset(&iwe, 0, sizeof(iwe));
  1479. iwe.cmd = IWEVCUSTOM;
  1480. sprintf(buf, " Last beacon: %ums ago",
  1481. elapsed_jiffies_msecs(bss->ts));
  1482. iwe.u.data.length = strlen(buf);
  1483. current_ev = iwe_stream_add_point_check(info, current_ev,
  1484. end_buf, &iwe, buf);
  1485. if (IS_ERR(current_ev))
  1486. goto unlock;
  1487. current_ev = ieee80211_scan_add_ies(info, ies, current_ev, end_buf);
  1488. unlock:
  1489. rcu_read_unlock();
  1490. return current_ev;
  1491. }
  1492. static int ieee80211_scan_results(struct cfg80211_registered_device *rdev,
  1493. struct iw_request_info *info,
  1494. char *buf, size_t len)
  1495. {
  1496. char *current_ev = buf;
  1497. char *end_buf = buf + len;
  1498. struct cfg80211_internal_bss *bss;
  1499. int err = 0;
  1500. spin_lock_bh(&rdev->bss_lock);
  1501. cfg80211_bss_expire(rdev);
  1502. list_for_each_entry(bss, &rdev->bss_list, list) {
  1503. if (buf + len - current_ev <= IW_EV_ADDR_LEN) {
  1504. err = -E2BIG;
  1505. break;
  1506. }
  1507. current_ev = ieee80211_bss(&rdev->wiphy, info, bss,
  1508. current_ev, end_buf);
  1509. if (IS_ERR(current_ev)) {
  1510. err = PTR_ERR(current_ev);
  1511. break;
  1512. }
  1513. }
  1514. spin_unlock_bh(&rdev->bss_lock);
  1515. if (err)
  1516. return err;
  1517. return current_ev - buf;
  1518. }
  1519. int cfg80211_wext_giwscan(struct net_device *dev,
  1520. struct iw_request_info *info,
  1521. struct iw_point *data, char *extra)
  1522. {
  1523. struct cfg80211_registered_device *rdev;
  1524. int res;
  1525. if (!netif_running(dev))
  1526. return -ENETDOWN;
  1527. rdev = cfg80211_get_dev_from_ifindex(dev_net(dev), dev->ifindex);
  1528. if (IS_ERR(rdev))
  1529. return PTR_ERR(rdev);
  1530. if (rdev->scan_req || rdev->scan_msg)
  1531. return -EAGAIN;
  1532. res = ieee80211_scan_results(rdev, info, extra, data->length);
  1533. data->length = 0;
  1534. if (res >= 0) {
  1535. data->length = res;
  1536. res = 0;
  1537. }
  1538. return res;
  1539. }
  1540. EXPORT_WEXT_HANDLER(cfg80211_wext_giwscan);
  1541. #endif