core.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233
  1. /*
  2. * This is the linux wireless configuration interface.
  3. *
  4. * Copyright 2006-2010 Johannes Berg <johannes@sipsolutions.net>
  5. * Copyright 2013-2014 Intel Mobile Communications GmbH
  6. */
  7. #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
  8. #include <linux/if.h>
  9. #include <linux/module.h>
  10. #include <linux/err.h>
  11. #include <linux/list.h>
  12. #include <linux/slab.h>
  13. #include <linux/nl80211.h>
  14. #include <linux/debugfs.h>
  15. #include <linux/notifier.h>
  16. #include <linux/device.h>
  17. #include <linux/etherdevice.h>
  18. #include <linux/rtnetlink.h>
  19. #include <linux/sched.h>
  20. #include <net/genetlink.h>
  21. #include <net/cfg80211.h>
  22. #include "nl80211.h"
  23. #include "core.h"
  24. #include "sysfs.h"
  25. #include "debugfs.h"
  26. #include "wext-compat.h"
  27. #include "rdev-ops.h"
  28. /* name for sysfs, %d is appended */
  29. #define PHY_NAME "phy"
  30. MODULE_AUTHOR("Johannes Berg");
  31. MODULE_LICENSE("GPL");
  32. MODULE_DESCRIPTION("wireless configuration support");
  33. MODULE_ALIAS_GENL_FAMILY(NL80211_GENL_NAME);
  34. /* RCU-protected (and RTNL for writers) */
  35. LIST_HEAD(cfg80211_rdev_list);
  36. int cfg80211_rdev_list_generation;
  37. /* for debugfs */
  38. static struct dentry *ieee80211_debugfs_dir;
  39. /* for the cleanup, scan and event works */
  40. struct workqueue_struct *cfg80211_wq;
  41. static bool cfg80211_disable_40mhz_24ghz;
  42. module_param(cfg80211_disable_40mhz_24ghz, bool, 0644);
  43. MODULE_PARM_DESC(cfg80211_disable_40mhz_24ghz,
  44. "Disable 40MHz support in the 2.4GHz band");
  45. struct cfg80211_registered_device *cfg80211_rdev_by_wiphy_idx(int wiphy_idx)
  46. {
  47. struct cfg80211_registered_device *result = NULL, *rdev;
  48. ASSERT_RTNL();
  49. list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
  50. if (rdev->wiphy_idx == wiphy_idx) {
  51. result = rdev;
  52. break;
  53. }
  54. }
  55. return result;
  56. }
  57. int get_wiphy_idx(struct wiphy *wiphy)
  58. {
  59. struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
  60. return rdev->wiphy_idx;
  61. }
  62. struct wiphy *wiphy_idx_to_wiphy(int wiphy_idx)
  63. {
  64. struct cfg80211_registered_device *rdev;
  65. ASSERT_RTNL();
  66. rdev = cfg80211_rdev_by_wiphy_idx(wiphy_idx);
  67. if (!rdev)
  68. return NULL;
  69. return &rdev->wiphy;
  70. }
  71. static int cfg80211_dev_check_name(struct cfg80211_registered_device *rdev,
  72. const char *newname)
  73. {
  74. struct cfg80211_registered_device *rdev2;
  75. int wiphy_idx, taken = -1, digits;
  76. ASSERT_RTNL();
  77. /* prohibit calling the thing phy%d when %d is not its number */
  78. sscanf(newname, PHY_NAME "%d%n", &wiphy_idx, &taken);
  79. if (taken == strlen(newname) && wiphy_idx != rdev->wiphy_idx) {
  80. /* count number of places needed to print wiphy_idx */
  81. digits = 1;
  82. while (wiphy_idx /= 10)
  83. digits++;
  84. /*
  85. * deny the name if it is phy<idx> where <idx> is printed
  86. * without leading zeroes. taken == strlen(newname) here
  87. */
  88. if (taken == strlen(PHY_NAME) + digits)
  89. return -EINVAL;
  90. }
  91. /* Ensure another device does not already have this name. */
  92. list_for_each_entry(rdev2, &cfg80211_rdev_list, list)
  93. if (strcmp(newname, wiphy_name(&rdev2->wiphy)) == 0)
  94. return -EINVAL;
  95. return 0;
  96. }
  97. int cfg80211_dev_rename(struct cfg80211_registered_device *rdev,
  98. char *newname)
  99. {
  100. int result;
  101. ASSERT_RTNL();
  102. /* Ignore nop renames */
  103. if (strcmp(newname, wiphy_name(&rdev->wiphy)) == 0)
  104. return 0;
  105. result = cfg80211_dev_check_name(rdev, newname);
  106. if (result < 0)
  107. return result;
  108. result = device_rename(&rdev->wiphy.dev, newname);
  109. if (result)
  110. return result;
  111. if (rdev->wiphy.debugfsdir &&
  112. !debugfs_rename(rdev->wiphy.debugfsdir->d_parent,
  113. rdev->wiphy.debugfsdir,
  114. rdev->wiphy.debugfsdir->d_parent,
  115. newname))
  116. pr_err("failed to rename debugfs dir to %s!\n", newname);
  117. nl80211_notify_wiphy(rdev, NL80211_CMD_NEW_WIPHY);
  118. return 0;
  119. }
  120. int cfg80211_switch_netns(struct cfg80211_registered_device *rdev,
  121. struct net *net)
  122. {
  123. struct wireless_dev *wdev;
  124. int err = 0;
  125. if (!(rdev->wiphy.flags & WIPHY_FLAG_NETNS_OK))
  126. return -EOPNOTSUPP;
  127. list_for_each_entry(wdev, &rdev->wdev_list, list) {
  128. if (!wdev->netdev)
  129. continue;
  130. wdev->netdev->features &= ~NETIF_F_NETNS_LOCAL;
  131. err = dev_change_net_namespace(wdev->netdev, net, "wlan%d");
  132. if (err)
  133. break;
  134. wdev->netdev->features |= NETIF_F_NETNS_LOCAL;
  135. }
  136. if (err) {
  137. /* failed -- clean up to old netns */
  138. net = wiphy_net(&rdev->wiphy);
  139. list_for_each_entry_continue_reverse(wdev, &rdev->wdev_list,
  140. list) {
  141. if (!wdev->netdev)
  142. continue;
  143. wdev->netdev->features &= ~NETIF_F_NETNS_LOCAL;
  144. err = dev_change_net_namespace(wdev->netdev, net,
  145. "wlan%d");
  146. WARN_ON(err);
  147. wdev->netdev->features |= NETIF_F_NETNS_LOCAL;
  148. }
  149. return err;
  150. }
  151. wiphy_net_set(&rdev->wiphy, net);
  152. err = device_rename(&rdev->wiphy.dev, dev_name(&rdev->wiphy.dev));
  153. WARN_ON(err);
  154. return 0;
  155. }
  156. static void cfg80211_rfkill_poll(struct rfkill *rfkill, void *data)
  157. {
  158. struct cfg80211_registered_device *rdev = data;
  159. rdev_rfkill_poll(rdev);
  160. }
  161. void cfg80211_stop_p2p_device(struct cfg80211_registered_device *rdev,
  162. struct wireless_dev *wdev)
  163. {
  164. ASSERT_RTNL();
  165. if (WARN_ON(wdev->iftype != NL80211_IFTYPE_P2P_DEVICE))
  166. return;
  167. if (!wdev->p2p_started)
  168. return;
  169. rdev_stop_p2p_device(rdev, wdev);
  170. wdev->p2p_started = false;
  171. rdev->opencount--;
  172. if (rdev->scan_req && rdev->scan_req->wdev == wdev) {
  173. if (WARN_ON(!rdev->scan_req->notified))
  174. rdev->scan_req->aborted = true;
  175. ___cfg80211_scan_done(rdev, false);
  176. }
  177. }
  178. void cfg80211_shutdown_all_interfaces(struct wiphy *wiphy)
  179. {
  180. struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
  181. struct wireless_dev *wdev;
  182. ASSERT_RTNL();
  183. list_for_each_entry(wdev, &rdev->wdev_list, list) {
  184. if (wdev->netdev) {
  185. dev_close(wdev->netdev);
  186. continue;
  187. }
  188. /* otherwise, check iftype */
  189. switch (wdev->iftype) {
  190. case NL80211_IFTYPE_P2P_DEVICE:
  191. cfg80211_stop_p2p_device(rdev, wdev);
  192. break;
  193. default:
  194. break;
  195. }
  196. }
  197. }
  198. EXPORT_SYMBOL_GPL(cfg80211_shutdown_all_interfaces);
  199. static int cfg80211_rfkill_set_block(void *data, bool blocked)
  200. {
  201. struct cfg80211_registered_device *rdev = data;
  202. if (!blocked)
  203. return 0;
  204. rtnl_lock();
  205. cfg80211_shutdown_all_interfaces(&rdev->wiphy);
  206. rtnl_unlock();
  207. return 0;
  208. }
  209. static void cfg80211_rfkill_sync_work(struct work_struct *work)
  210. {
  211. struct cfg80211_registered_device *rdev;
  212. rdev = container_of(work, struct cfg80211_registered_device, rfkill_sync);
  213. cfg80211_rfkill_set_block(rdev, rfkill_blocked(rdev->rfkill));
  214. }
  215. static void cfg80211_event_work(struct work_struct *work)
  216. {
  217. struct cfg80211_registered_device *rdev;
  218. rdev = container_of(work, struct cfg80211_registered_device,
  219. event_work);
  220. rtnl_lock();
  221. cfg80211_process_rdev_events(rdev);
  222. rtnl_unlock();
  223. }
  224. void cfg80211_destroy_ifaces(struct cfg80211_registered_device *rdev)
  225. {
  226. struct cfg80211_iface_destroy *item;
  227. ASSERT_RTNL();
  228. spin_lock_irq(&rdev->destroy_list_lock);
  229. while ((item = list_first_entry_or_null(&rdev->destroy_list,
  230. struct cfg80211_iface_destroy,
  231. list))) {
  232. struct wireless_dev *wdev, *tmp;
  233. u32 nlportid = item->nlportid;
  234. list_del(&item->list);
  235. kfree(item);
  236. spin_unlock_irq(&rdev->destroy_list_lock);
  237. list_for_each_entry_safe(wdev, tmp, &rdev->wdev_list, list) {
  238. if (nlportid == wdev->owner_nlportid)
  239. rdev_del_virtual_intf(rdev, wdev);
  240. }
  241. spin_lock_irq(&rdev->destroy_list_lock);
  242. }
  243. spin_unlock_irq(&rdev->destroy_list_lock);
  244. }
  245. static void cfg80211_destroy_iface_wk(struct work_struct *work)
  246. {
  247. struct cfg80211_registered_device *rdev;
  248. rdev = container_of(work, struct cfg80211_registered_device,
  249. destroy_work);
  250. rtnl_lock();
  251. cfg80211_destroy_ifaces(rdev);
  252. rtnl_unlock();
  253. }
  254. static void cfg80211_sched_scan_stop_wk(struct work_struct *work)
  255. {
  256. struct cfg80211_registered_device *rdev;
  257. rdev = container_of(work, struct cfg80211_registered_device,
  258. sched_scan_stop_wk);
  259. rtnl_lock();
  260. __cfg80211_stop_sched_scan(rdev, false);
  261. rtnl_unlock();
  262. }
  263. /* exported functions */
  264. struct wiphy *wiphy_new_nm(const struct cfg80211_ops *ops, int sizeof_priv,
  265. const char *requested_name)
  266. {
  267. static atomic_t wiphy_counter = ATOMIC_INIT(0);
  268. struct cfg80211_registered_device *rdev;
  269. int alloc_size;
  270. WARN_ON(ops->add_key && (!ops->del_key || !ops->set_default_key));
  271. WARN_ON(ops->auth && (!ops->assoc || !ops->deauth || !ops->disassoc));
  272. WARN_ON(ops->connect && !ops->disconnect);
  273. WARN_ON(ops->join_ibss && !ops->leave_ibss);
  274. WARN_ON(ops->add_virtual_intf && !ops->del_virtual_intf);
  275. WARN_ON(ops->add_station && !ops->del_station);
  276. WARN_ON(ops->add_mpath && !ops->del_mpath);
  277. WARN_ON(ops->join_mesh && !ops->leave_mesh);
  278. alloc_size = sizeof(*rdev) + sizeof_priv;
  279. rdev = kzalloc(alloc_size, GFP_KERNEL);
  280. if (!rdev)
  281. return NULL;
  282. rdev->ops = ops;
  283. rdev->wiphy_idx = atomic_inc_return(&wiphy_counter);
  284. if (unlikely(rdev->wiphy_idx < 0)) {
  285. /* ugh, wrapped! */
  286. atomic_dec(&wiphy_counter);
  287. kfree(rdev);
  288. return NULL;
  289. }
  290. /* atomic_inc_return makes it start at 1, make it start at 0 */
  291. rdev->wiphy_idx--;
  292. /* give it a proper name */
  293. if (requested_name && requested_name[0]) {
  294. int rv;
  295. rtnl_lock();
  296. rv = cfg80211_dev_check_name(rdev, requested_name);
  297. if (rv < 0) {
  298. rtnl_unlock();
  299. goto use_default_name;
  300. }
  301. rv = dev_set_name(&rdev->wiphy.dev, "%s", requested_name);
  302. rtnl_unlock();
  303. if (rv)
  304. goto use_default_name;
  305. } else {
  306. use_default_name:
  307. /* NOTE: This is *probably* safe w/out holding rtnl because of
  308. * the restrictions on phy names. Probably this call could
  309. * fail if some other part of the kernel (re)named a device
  310. * phyX. But, might should add some locking and check return
  311. * value, and use a different name if this one exists?
  312. */
  313. dev_set_name(&rdev->wiphy.dev, PHY_NAME "%d", rdev->wiphy_idx);
  314. }
  315. INIT_LIST_HEAD(&rdev->wdev_list);
  316. INIT_LIST_HEAD(&rdev->beacon_registrations);
  317. spin_lock_init(&rdev->beacon_registrations_lock);
  318. spin_lock_init(&rdev->bss_lock);
  319. INIT_LIST_HEAD(&rdev->bss_list);
  320. INIT_WORK(&rdev->scan_done_wk, __cfg80211_scan_done);
  321. INIT_WORK(&rdev->sched_scan_results_wk, __cfg80211_sched_scan_results);
  322. INIT_LIST_HEAD(&rdev->mlme_unreg);
  323. spin_lock_init(&rdev->mlme_unreg_lock);
  324. INIT_WORK(&rdev->mlme_unreg_wk, cfg80211_mlme_unreg_wk);
  325. INIT_DELAYED_WORK(&rdev->dfs_update_channels_wk,
  326. cfg80211_dfs_channels_update_work);
  327. #ifdef CONFIG_CFG80211_WEXT
  328. rdev->wiphy.wext = &cfg80211_wext_handler;
  329. #endif
  330. device_initialize(&rdev->wiphy.dev);
  331. rdev->wiphy.dev.class = &ieee80211_class;
  332. rdev->wiphy.dev.platform_data = rdev;
  333. device_enable_async_suspend(&rdev->wiphy.dev);
  334. INIT_LIST_HEAD(&rdev->destroy_list);
  335. spin_lock_init(&rdev->destroy_list_lock);
  336. INIT_WORK(&rdev->destroy_work, cfg80211_destroy_iface_wk);
  337. INIT_WORK(&rdev->sched_scan_stop_wk, cfg80211_sched_scan_stop_wk);
  338. #ifdef CONFIG_CFG80211_DEFAULT_PS
  339. rdev->wiphy.flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT;
  340. #endif
  341. wiphy_net_set(&rdev->wiphy, &init_net);
  342. rdev->rfkill_ops.set_block = cfg80211_rfkill_set_block;
  343. rdev->rfkill = rfkill_alloc(dev_name(&rdev->wiphy.dev),
  344. &rdev->wiphy.dev, RFKILL_TYPE_WLAN,
  345. &rdev->rfkill_ops, rdev);
  346. if (!rdev->rfkill) {
  347. kfree(rdev);
  348. return NULL;
  349. }
  350. INIT_WORK(&rdev->rfkill_sync, cfg80211_rfkill_sync_work);
  351. INIT_WORK(&rdev->conn_work, cfg80211_conn_work);
  352. INIT_WORK(&rdev->event_work, cfg80211_event_work);
  353. init_waitqueue_head(&rdev->dev_wait);
  354. /*
  355. * Initialize wiphy parameters to IEEE 802.11 MIB default values.
  356. * Fragmentation and RTS threshold are disabled by default with the
  357. * special -1 value.
  358. */
  359. rdev->wiphy.retry_short = 7;
  360. rdev->wiphy.retry_long = 4;
  361. rdev->wiphy.frag_threshold = (u32) -1;
  362. rdev->wiphy.rts_threshold = (u32) -1;
  363. rdev->wiphy.coverage_class = 0;
  364. rdev->wiphy.max_num_csa_counters = 1;
  365. rdev->wiphy.max_sched_scan_plans = 1;
  366. rdev->wiphy.max_sched_scan_plan_interval = U32_MAX;
  367. return &rdev->wiphy;
  368. }
  369. EXPORT_SYMBOL(wiphy_new_nm);
  370. static int wiphy_verify_combinations(struct wiphy *wiphy)
  371. {
  372. const struct ieee80211_iface_combination *c;
  373. int i, j;
  374. for (i = 0; i < wiphy->n_iface_combinations; i++) {
  375. u32 cnt = 0;
  376. u16 all_iftypes = 0;
  377. c = &wiphy->iface_combinations[i];
  378. /*
  379. * Combinations with just one interface aren't real,
  380. * however we make an exception for DFS.
  381. */
  382. if (WARN_ON((c->max_interfaces < 2) && !c->radar_detect_widths))
  383. return -EINVAL;
  384. /* Need at least one channel */
  385. if (WARN_ON(!c->num_different_channels))
  386. return -EINVAL;
  387. /*
  388. * Put a sane limit on maximum number of different
  389. * channels to simplify channel accounting code.
  390. */
  391. if (WARN_ON(c->num_different_channels >
  392. CFG80211_MAX_NUM_DIFFERENT_CHANNELS))
  393. return -EINVAL;
  394. /* DFS only works on one channel. */
  395. if (WARN_ON(c->radar_detect_widths &&
  396. (c->num_different_channels > 1)))
  397. return -EINVAL;
  398. if (WARN_ON(!c->n_limits))
  399. return -EINVAL;
  400. for (j = 0; j < c->n_limits; j++) {
  401. u16 types = c->limits[j].types;
  402. /* interface types shouldn't overlap */
  403. if (WARN_ON(types & all_iftypes))
  404. return -EINVAL;
  405. all_iftypes |= types;
  406. if (WARN_ON(!c->limits[j].max))
  407. return -EINVAL;
  408. /* Shouldn't list software iftypes in combinations! */
  409. if (WARN_ON(wiphy->software_iftypes & types))
  410. return -EINVAL;
  411. /* Only a single P2P_DEVICE can be allowed */
  412. if (WARN_ON(types & BIT(NL80211_IFTYPE_P2P_DEVICE) &&
  413. c->limits[j].max > 1))
  414. return -EINVAL;
  415. cnt += c->limits[j].max;
  416. /*
  417. * Don't advertise an unsupported type
  418. * in a combination.
  419. */
  420. if (WARN_ON((wiphy->interface_modes & types) != types))
  421. return -EINVAL;
  422. }
  423. /* You can't even choose that many! */
  424. if (WARN_ON(cnt < c->max_interfaces))
  425. return -EINVAL;
  426. }
  427. return 0;
  428. }
  429. int wiphy_register(struct wiphy *wiphy)
  430. {
  431. struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
  432. int res;
  433. enum ieee80211_band band;
  434. struct ieee80211_supported_band *sband;
  435. bool have_band = false;
  436. int i;
  437. u16 ifmodes = wiphy->interface_modes;
  438. #ifdef CONFIG_PM
  439. if (WARN_ON(wiphy->wowlan &&
  440. (wiphy->wowlan->flags & WIPHY_WOWLAN_GTK_REKEY_FAILURE) &&
  441. !(wiphy->wowlan->flags & WIPHY_WOWLAN_SUPPORTS_GTK_REKEY)))
  442. return -EINVAL;
  443. if (WARN_ON(wiphy->wowlan &&
  444. !wiphy->wowlan->flags && !wiphy->wowlan->n_patterns &&
  445. !wiphy->wowlan->tcp))
  446. return -EINVAL;
  447. #endif
  448. if (WARN_ON((wiphy->features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH) &&
  449. (!rdev->ops->tdls_channel_switch ||
  450. !rdev->ops->tdls_cancel_channel_switch)))
  451. return -EINVAL;
  452. /*
  453. * if a wiphy has unsupported modes for regulatory channel enforcement,
  454. * opt-out of enforcement checking
  455. */
  456. if (wiphy->interface_modes & ~(BIT(NL80211_IFTYPE_STATION) |
  457. BIT(NL80211_IFTYPE_P2P_CLIENT) |
  458. BIT(NL80211_IFTYPE_AP) |
  459. BIT(NL80211_IFTYPE_P2P_GO) |
  460. BIT(NL80211_IFTYPE_ADHOC) |
  461. BIT(NL80211_IFTYPE_P2P_DEVICE) |
  462. BIT(NL80211_IFTYPE_AP_VLAN) |
  463. BIT(NL80211_IFTYPE_MONITOR)))
  464. wiphy->regulatory_flags |= REGULATORY_IGNORE_STALE_KICKOFF;
  465. if (WARN_ON((wiphy->regulatory_flags & REGULATORY_WIPHY_SELF_MANAGED) &&
  466. (wiphy->regulatory_flags &
  467. (REGULATORY_CUSTOM_REG |
  468. REGULATORY_STRICT_REG |
  469. REGULATORY_COUNTRY_IE_FOLLOW_POWER |
  470. REGULATORY_COUNTRY_IE_IGNORE))))
  471. return -EINVAL;
  472. if (WARN_ON(wiphy->coalesce &&
  473. (!wiphy->coalesce->n_rules ||
  474. !wiphy->coalesce->n_patterns) &&
  475. (!wiphy->coalesce->pattern_min_len ||
  476. wiphy->coalesce->pattern_min_len >
  477. wiphy->coalesce->pattern_max_len)))
  478. return -EINVAL;
  479. if (WARN_ON(wiphy->ap_sme_capa &&
  480. !(wiphy->flags & WIPHY_FLAG_HAVE_AP_SME)))
  481. return -EINVAL;
  482. if (WARN_ON(wiphy->addresses && !wiphy->n_addresses))
  483. return -EINVAL;
  484. if (WARN_ON(wiphy->addresses &&
  485. !is_zero_ether_addr(wiphy->perm_addr) &&
  486. memcmp(wiphy->perm_addr, wiphy->addresses[0].addr,
  487. ETH_ALEN)))
  488. return -EINVAL;
  489. if (WARN_ON(wiphy->max_acl_mac_addrs &&
  490. (!(wiphy->flags & WIPHY_FLAG_HAVE_AP_SME) ||
  491. !rdev->ops->set_mac_acl)))
  492. return -EINVAL;
  493. if (wiphy->addresses)
  494. memcpy(wiphy->perm_addr, wiphy->addresses[0].addr, ETH_ALEN);
  495. /* sanity check ifmodes */
  496. WARN_ON(!ifmodes);
  497. ifmodes &= ((1 << NUM_NL80211_IFTYPES) - 1) & ~1;
  498. if (WARN_ON(ifmodes != wiphy->interface_modes))
  499. wiphy->interface_modes = ifmodes;
  500. res = wiphy_verify_combinations(wiphy);
  501. if (res)
  502. return res;
  503. /* sanity check supported bands/channels */
  504. for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
  505. sband = wiphy->bands[band];
  506. if (!sband)
  507. continue;
  508. sband->band = band;
  509. if (WARN_ON(!sband->n_channels))
  510. return -EINVAL;
  511. /*
  512. * on 60GHz band, there are no legacy rates, so
  513. * n_bitrates is 0
  514. */
  515. if (WARN_ON(band != IEEE80211_BAND_60GHZ &&
  516. !sband->n_bitrates))
  517. return -EINVAL;
  518. /*
  519. * Since cfg80211_disable_40mhz_24ghz is global, we can
  520. * modify the sband's ht data even if the driver uses a
  521. * global structure for that.
  522. */
  523. if (cfg80211_disable_40mhz_24ghz &&
  524. band == IEEE80211_BAND_2GHZ &&
  525. sband->ht_cap.ht_supported) {
  526. sband->ht_cap.cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
  527. sband->ht_cap.cap &= ~IEEE80211_HT_CAP_SGI_40;
  528. }
  529. /*
  530. * Since we use a u32 for rate bitmaps in
  531. * ieee80211_get_response_rate, we cannot
  532. * have more than 32 legacy rates.
  533. */
  534. if (WARN_ON(sband->n_bitrates > 32))
  535. return -EINVAL;
  536. for (i = 0; i < sband->n_channels; i++) {
  537. sband->channels[i].orig_flags =
  538. sband->channels[i].flags;
  539. sband->channels[i].orig_mag = INT_MAX;
  540. sband->channels[i].orig_mpwr =
  541. sband->channels[i].max_power;
  542. sband->channels[i].band = band;
  543. }
  544. have_band = true;
  545. }
  546. if (!have_band) {
  547. WARN_ON(1);
  548. return -EINVAL;
  549. }
  550. #ifdef CONFIG_PM
  551. if (WARN_ON(rdev->wiphy.wowlan && rdev->wiphy.wowlan->n_patterns &&
  552. (!rdev->wiphy.wowlan->pattern_min_len ||
  553. rdev->wiphy.wowlan->pattern_min_len >
  554. rdev->wiphy.wowlan->pattern_max_len)))
  555. return -EINVAL;
  556. #endif
  557. /* check and set up bitrates */
  558. ieee80211_set_bitrate_flags(wiphy);
  559. rdev->wiphy.features |= NL80211_FEATURE_SCAN_FLUSH;
  560. rtnl_lock();
  561. res = device_add(&rdev->wiphy.dev);
  562. if (res) {
  563. rtnl_unlock();
  564. return res;
  565. }
  566. /* set up regulatory info */
  567. wiphy_regulatory_register(wiphy);
  568. list_add_rcu(&rdev->list, &cfg80211_rdev_list);
  569. cfg80211_rdev_list_generation++;
  570. /* add to debugfs */
  571. rdev->wiphy.debugfsdir =
  572. debugfs_create_dir(wiphy_name(&rdev->wiphy),
  573. ieee80211_debugfs_dir);
  574. if (IS_ERR(rdev->wiphy.debugfsdir))
  575. rdev->wiphy.debugfsdir = NULL;
  576. cfg80211_debugfs_rdev_add(rdev);
  577. nl80211_notify_wiphy(rdev, NL80211_CMD_NEW_WIPHY);
  578. if (wiphy->regulatory_flags & REGULATORY_CUSTOM_REG) {
  579. struct regulatory_request request;
  580. request.wiphy_idx = get_wiphy_idx(wiphy);
  581. request.initiator = NL80211_REGDOM_SET_BY_DRIVER;
  582. request.alpha2[0] = '9';
  583. request.alpha2[1] = '9';
  584. nl80211_send_reg_change_event(&request);
  585. }
  586. rdev->wiphy.registered = true;
  587. rtnl_unlock();
  588. res = rfkill_register(rdev->rfkill);
  589. if (res) {
  590. rfkill_destroy(rdev->rfkill);
  591. rdev->rfkill = NULL;
  592. wiphy_unregister(&rdev->wiphy);
  593. return res;
  594. }
  595. return 0;
  596. }
  597. EXPORT_SYMBOL(wiphy_register);
  598. void wiphy_rfkill_start_polling(struct wiphy *wiphy)
  599. {
  600. struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
  601. if (!rdev->ops->rfkill_poll)
  602. return;
  603. rdev->rfkill_ops.poll = cfg80211_rfkill_poll;
  604. rfkill_resume_polling(rdev->rfkill);
  605. }
  606. EXPORT_SYMBOL(wiphy_rfkill_start_polling);
  607. void wiphy_rfkill_stop_polling(struct wiphy *wiphy)
  608. {
  609. struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
  610. rfkill_pause_polling(rdev->rfkill);
  611. }
  612. EXPORT_SYMBOL(wiphy_rfkill_stop_polling);
  613. void wiphy_unregister(struct wiphy *wiphy)
  614. {
  615. struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
  616. wait_event(rdev->dev_wait, ({
  617. int __count;
  618. rtnl_lock();
  619. __count = rdev->opencount;
  620. rtnl_unlock();
  621. __count == 0; }));
  622. if (rdev->rfkill)
  623. rfkill_unregister(rdev->rfkill);
  624. rtnl_lock();
  625. nl80211_notify_wiphy(rdev, NL80211_CMD_DEL_WIPHY);
  626. rdev->wiphy.registered = false;
  627. WARN_ON(!list_empty(&rdev->wdev_list));
  628. /*
  629. * First remove the hardware from everywhere, this makes
  630. * it impossible to find from userspace.
  631. */
  632. debugfs_remove_recursive(rdev->wiphy.debugfsdir);
  633. list_del_rcu(&rdev->list);
  634. synchronize_rcu();
  635. /*
  636. * If this device got a regulatory hint tell core its
  637. * free to listen now to a new shiny device regulatory hint
  638. */
  639. wiphy_regulatory_deregister(wiphy);
  640. cfg80211_rdev_list_generation++;
  641. device_del(&rdev->wiphy.dev);
  642. rtnl_unlock();
  643. flush_work(&rdev->scan_done_wk);
  644. cancel_work_sync(&rdev->conn_work);
  645. flush_work(&rdev->event_work);
  646. cancel_delayed_work_sync(&rdev->dfs_update_channels_wk);
  647. flush_work(&rdev->destroy_work);
  648. flush_work(&rdev->sched_scan_stop_wk);
  649. flush_work(&rdev->mlme_unreg_wk);
  650. #ifdef CONFIG_PM
  651. if (rdev->wiphy.wowlan_config && rdev->ops->set_wakeup)
  652. rdev_set_wakeup(rdev, false);
  653. #endif
  654. cfg80211_rdev_free_wowlan(rdev);
  655. cfg80211_rdev_free_coalesce(rdev);
  656. }
  657. EXPORT_SYMBOL(wiphy_unregister);
  658. void cfg80211_dev_free(struct cfg80211_registered_device *rdev)
  659. {
  660. struct cfg80211_internal_bss *scan, *tmp;
  661. struct cfg80211_beacon_registration *reg, *treg;
  662. rfkill_destroy(rdev->rfkill);
  663. list_for_each_entry_safe(reg, treg, &rdev->beacon_registrations, list) {
  664. list_del(&reg->list);
  665. kfree(reg);
  666. }
  667. list_for_each_entry_safe(scan, tmp, &rdev->bss_list, list)
  668. cfg80211_put_bss(&rdev->wiphy, &scan->pub);
  669. kfree(rdev);
  670. }
  671. void wiphy_free(struct wiphy *wiphy)
  672. {
  673. put_device(&wiphy->dev);
  674. }
  675. EXPORT_SYMBOL(wiphy_free);
  676. void wiphy_rfkill_set_hw_state(struct wiphy *wiphy, bool blocked)
  677. {
  678. struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
  679. if (rfkill_set_hw_state(rdev->rfkill, blocked))
  680. schedule_work(&rdev->rfkill_sync);
  681. }
  682. EXPORT_SYMBOL(wiphy_rfkill_set_hw_state);
  683. void cfg80211_unregister_wdev(struct wireless_dev *wdev)
  684. {
  685. struct cfg80211_registered_device *rdev = wiphy_to_rdev(wdev->wiphy);
  686. ASSERT_RTNL();
  687. if (WARN_ON(wdev->netdev))
  688. return;
  689. list_del_rcu(&wdev->list);
  690. rdev->devlist_generation++;
  691. switch (wdev->iftype) {
  692. case NL80211_IFTYPE_P2P_DEVICE:
  693. cfg80211_mlme_purge_registrations(wdev);
  694. cfg80211_stop_p2p_device(rdev, wdev);
  695. break;
  696. default:
  697. WARN_ON_ONCE(1);
  698. break;
  699. }
  700. }
  701. EXPORT_SYMBOL(cfg80211_unregister_wdev);
  702. static const struct device_type wiphy_type = {
  703. .name = "wlan",
  704. };
  705. void cfg80211_update_iface_num(struct cfg80211_registered_device *rdev,
  706. enum nl80211_iftype iftype, int num)
  707. {
  708. ASSERT_RTNL();
  709. rdev->num_running_ifaces += num;
  710. if (iftype == NL80211_IFTYPE_MONITOR)
  711. rdev->num_running_monitor_ifaces += num;
  712. }
  713. void __cfg80211_leave(struct cfg80211_registered_device *rdev,
  714. struct wireless_dev *wdev)
  715. {
  716. struct net_device *dev = wdev->netdev;
  717. struct cfg80211_sched_scan_request *sched_scan_req;
  718. ASSERT_RTNL();
  719. ASSERT_WDEV_LOCK(wdev);
  720. switch (wdev->iftype) {
  721. case NL80211_IFTYPE_ADHOC:
  722. __cfg80211_leave_ibss(rdev, dev, true);
  723. break;
  724. case NL80211_IFTYPE_P2P_CLIENT:
  725. case NL80211_IFTYPE_STATION:
  726. sched_scan_req = rtnl_dereference(rdev->sched_scan_req);
  727. if (sched_scan_req && dev == sched_scan_req->dev)
  728. __cfg80211_stop_sched_scan(rdev, false);
  729. #ifdef CONFIG_CFG80211_WEXT
  730. kfree(wdev->wext.ie);
  731. wdev->wext.ie = NULL;
  732. wdev->wext.ie_len = 0;
  733. wdev->wext.connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
  734. #endif
  735. cfg80211_disconnect(rdev, dev,
  736. WLAN_REASON_DEAUTH_LEAVING, true);
  737. break;
  738. case NL80211_IFTYPE_MESH_POINT:
  739. __cfg80211_leave_mesh(rdev, dev);
  740. break;
  741. case NL80211_IFTYPE_AP:
  742. case NL80211_IFTYPE_P2P_GO:
  743. __cfg80211_stop_ap(rdev, dev, true);
  744. break;
  745. case NL80211_IFTYPE_OCB:
  746. __cfg80211_leave_ocb(rdev, dev);
  747. break;
  748. case NL80211_IFTYPE_WDS:
  749. /* must be handled by mac80211/driver, has no APIs */
  750. break;
  751. case NL80211_IFTYPE_P2P_DEVICE:
  752. /* cannot happen, has no netdev */
  753. break;
  754. case NL80211_IFTYPE_AP_VLAN:
  755. case NL80211_IFTYPE_MONITOR:
  756. /* nothing to do */
  757. break;
  758. case NL80211_IFTYPE_UNSPECIFIED:
  759. case NUM_NL80211_IFTYPES:
  760. /* invalid */
  761. break;
  762. }
  763. }
  764. void cfg80211_leave(struct cfg80211_registered_device *rdev,
  765. struct wireless_dev *wdev)
  766. {
  767. wdev_lock(wdev);
  768. __cfg80211_leave(rdev, wdev);
  769. wdev_unlock(wdev);
  770. }
  771. void cfg80211_stop_iface(struct wiphy *wiphy, struct wireless_dev *wdev,
  772. gfp_t gfp)
  773. {
  774. struct cfg80211_registered_device *rdev = wiphy_to_rdev(wiphy);
  775. struct cfg80211_event *ev;
  776. unsigned long flags;
  777. trace_cfg80211_stop_iface(wiphy, wdev);
  778. ev = kzalloc(sizeof(*ev), gfp);
  779. if (!ev)
  780. return;
  781. ev->type = EVENT_STOPPED;
  782. spin_lock_irqsave(&wdev->event_lock, flags);
  783. list_add_tail(&ev->list, &wdev->event_list);
  784. spin_unlock_irqrestore(&wdev->event_lock, flags);
  785. queue_work(cfg80211_wq, &rdev->event_work);
  786. }
  787. EXPORT_SYMBOL(cfg80211_stop_iface);
  788. static int cfg80211_netdev_notifier_call(struct notifier_block *nb,
  789. unsigned long state, void *ptr)
  790. {
  791. struct net_device *dev = netdev_notifier_info_to_dev(ptr);
  792. struct wireless_dev *wdev = dev->ieee80211_ptr;
  793. struct cfg80211_registered_device *rdev;
  794. struct cfg80211_sched_scan_request *sched_scan_req;
  795. if (!wdev)
  796. return NOTIFY_DONE;
  797. rdev = wiphy_to_rdev(wdev->wiphy);
  798. WARN_ON(wdev->iftype == NL80211_IFTYPE_UNSPECIFIED);
  799. switch (state) {
  800. case NETDEV_POST_INIT:
  801. SET_NETDEV_DEVTYPE(dev, &wiphy_type);
  802. break;
  803. case NETDEV_REGISTER:
  804. /*
  805. * NB: cannot take rdev->mtx here because this may be
  806. * called within code protected by it when interfaces
  807. * are added with nl80211.
  808. */
  809. mutex_init(&wdev->mtx);
  810. INIT_LIST_HEAD(&wdev->event_list);
  811. spin_lock_init(&wdev->event_lock);
  812. INIT_LIST_HEAD(&wdev->mgmt_registrations);
  813. spin_lock_init(&wdev->mgmt_registrations_lock);
  814. wdev->identifier = ++rdev->wdev_id;
  815. list_add_rcu(&wdev->list, &rdev->wdev_list);
  816. rdev->devlist_generation++;
  817. /* can only change netns with wiphy */
  818. dev->features |= NETIF_F_NETNS_LOCAL;
  819. if (sysfs_create_link(&dev->dev.kobj, &rdev->wiphy.dev.kobj,
  820. "phy80211")) {
  821. pr_err("failed to add phy80211 symlink to netdev!\n");
  822. }
  823. wdev->netdev = dev;
  824. #ifdef CONFIG_CFG80211_WEXT
  825. wdev->wext.default_key = -1;
  826. wdev->wext.default_mgmt_key = -1;
  827. wdev->wext.connect.auth_type = NL80211_AUTHTYPE_AUTOMATIC;
  828. #endif
  829. if (wdev->wiphy->flags & WIPHY_FLAG_PS_ON_BY_DEFAULT)
  830. wdev->ps = true;
  831. else
  832. wdev->ps = false;
  833. /* allow mac80211 to determine the timeout */
  834. wdev->ps_timeout = -1;
  835. if ((wdev->iftype == NL80211_IFTYPE_STATION ||
  836. wdev->iftype == NL80211_IFTYPE_P2P_CLIENT ||
  837. wdev->iftype == NL80211_IFTYPE_ADHOC) && !wdev->use_4addr)
  838. dev->priv_flags |= IFF_DONT_BRIDGE;
  839. break;
  840. case NETDEV_GOING_DOWN:
  841. cfg80211_leave(rdev, wdev);
  842. break;
  843. case NETDEV_DOWN:
  844. cfg80211_update_iface_num(rdev, wdev->iftype, -1);
  845. if (rdev->scan_req && rdev->scan_req->wdev == wdev) {
  846. if (WARN_ON(!rdev->scan_req->notified))
  847. rdev->scan_req->aborted = true;
  848. ___cfg80211_scan_done(rdev, false);
  849. }
  850. sched_scan_req = rtnl_dereference(rdev->sched_scan_req);
  851. if (WARN_ON(sched_scan_req &&
  852. sched_scan_req->dev == wdev->netdev)) {
  853. __cfg80211_stop_sched_scan(rdev, false);
  854. }
  855. rdev->opencount--;
  856. wake_up(&rdev->dev_wait);
  857. break;
  858. case NETDEV_UP:
  859. cfg80211_update_iface_num(rdev, wdev->iftype, 1);
  860. wdev_lock(wdev);
  861. switch (wdev->iftype) {
  862. #ifdef CONFIG_CFG80211_WEXT
  863. case NL80211_IFTYPE_ADHOC:
  864. cfg80211_ibss_wext_join(rdev, wdev);
  865. break;
  866. case NL80211_IFTYPE_STATION:
  867. cfg80211_mgd_wext_connect(rdev, wdev);
  868. break;
  869. #endif
  870. #ifdef CONFIG_MAC80211_MESH
  871. case NL80211_IFTYPE_MESH_POINT:
  872. {
  873. /* backward compat code... */
  874. struct mesh_setup setup;
  875. memcpy(&setup, &default_mesh_setup,
  876. sizeof(setup));
  877. /* back compat only needed for mesh_id */
  878. setup.mesh_id = wdev->ssid;
  879. setup.mesh_id_len = wdev->mesh_id_up_len;
  880. if (wdev->mesh_id_up_len)
  881. __cfg80211_join_mesh(rdev, dev,
  882. &setup,
  883. &default_mesh_config);
  884. break;
  885. }
  886. #endif
  887. default:
  888. break;
  889. }
  890. wdev_unlock(wdev);
  891. rdev->opencount++;
  892. /*
  893. * Configure power management to the driver here so that its
  894. * correctly set also after interface type changes etc.
  895. */
  896. if ((wdev->iftype == NL80211_IFTYPE_STATION ||
  897. wdev->iftype == NL80211_IFTYPE_P2P_CLIENT) &&
  898. rdev->ops->set_power_mgmt)
  899. if (rdev_set_power_mgmt(rdev, dev, wdev->ps,
  900. wdev->ps_timeout)) {
  901. /* assume this means it's off */
  902. wdev->ps = false;
  903. }
  904. break;
  905. case NETDEV_UNREGISTER:
  906. /*
  907. * It is possible to get NETDEV_UNREGISTER
  908. * multiple times. To detect that, check
  909. * that the interface is still on the list
  910. * of registered interfaces, and only then
  911. * remove and clean it up.
  912. */
  913. if (!list_empty(&wdev->list)) {
  914. sysfs_remove_link(&dev->dev.kobj, "phy80211");
  915. list_del_rcu(&wdev->list);
  916. rdev->devlist_generation++;
  917. cfg80211_mlme_purge_registrations(wdev);
  918. #ifdef CONFIG_CFG80211_WEXT
  919. kzfree(wdev->wext.keys);
  920. #endif
  921. }
  922. /*
  923. * synchronise (so that we won't find this netdev
  924. * from other code any more) and then clear the list
  925. * head so that the above code can safely check for
  926. * !list_empty() to avoid double-cleanup.
  927. */
  928. synchronize_rcu();
  929. INIT_LIST_HEAD(&wdev->list);
  930. /*
  931. * Ensure that all events have been processed and
  932. * freed.
  933. */
  934. cfg80211_process_wdev_events(wdev);
  935. if (WARN_ON(wdev->current_bss)) {
  936. cfg80211_unhold_bss(wdev->current_bss);
  937. cfg80211_put_bss(wdev->wiphy, &wdev->current_bss->pub);
  938. wdev->current_bss = NULL;
  939. }
  940. break;
  941. case NETDEV_PRE_UP:
  942. if (!(wdev->wiphy->interface_modes & BIT(wdev->iftype)))
  943. return notifier_from_errno(-EOPNOTSUPP);
  944. if (rfkill_blocked(rdev->rfkill))
  945. return notifier_from_errno(-ERFKILL);
  946. break;
  947. default:
  948. return NOTIFY_DONE;
  949. }
  950. return NOTIFY_OK;
  951. }
  952. static struct notifier_block cfg80211_netdev_notifier = {
  953. .notifier_call = cfg80211_netdev_notifier_call,
  954. };
  955. static void __net_exit cfg80211_pernet_exit(struct net *net)
  956. {
  957. struct cfg80211_registered_device *rdev;
  958. rtnl_lock();
  959. list_for_each_entry(rdev, &cfg80211_rdev_list, list) {
  960. if (net_eq(wiphy_net(&rdev->wiphy), net))
  961. WARN_ON(cfg80211_switch_netns(rdev, &init_net));
  962. }
  963. rtnl_unlock();
  964. }
  965. static struct pernet_operations cfg80211_pernet_ops = {
  966. .exit = cfg80211_pernet_exit,
  967. };
  968. static int __init cfg80211_init(void)
  969. {
  970. int err;
  971. err = register_pernet_device(&cfg80211_pernet_ops);
  972. if (err)
  973. goto out_fail_pernet;
  974. err = wiphy_sysfs_init();
  975. if (err)
  976. goto out_fail_sysfs;
  977. err = register_netdevice_notifier(&cfg80211_netdev_notifier);
  978. if (err)
  979. goto out_fail_notifier;
  980. err = nl80211_init();
  981. if (err)
  982. goto out_fail_nl80211;
  983. ieee80211_debugfs_dir = debugfs_create_dir("ieee80211", NULL);
  984. err = regulatory_init();
  985. if (err)
  986. goto out_fail_reg;
  987. cfg80211_wq = create_singlethread_workqueue("cfg80211");
  988. if (!cfg80211_wq) {
  989. err = -ENOMEM;
  990. goto out_fail_wq;
  991. }
  992. return 0;
  993. out_fail_wq:
  994. regulatory_exit();
  995. out_fail_reg:
  996. debugfs_remove(ieee80211_debugfs_dir);
  997. nl80211_exit();
  998. out_fail_nl80211:
  999. unregister_netdevice_notifier(&cfg80211_netdev_notifier);
  1000. out_fail_notifier:
  1001. wiphy_sysfs_exit();
  1002. out_fail_sysfs:
  1003. unregister_pernet_device(&cfg80211_pernet_ops);
  1004. out_fail_pernet:
  1005. return err;
  1006. }
  1007. subsys_initcall(cfg80211_init);
  1008. static void __exit cfg80211_exit(void)
  1009. {
  1010. debugfs_remove(ieee80211_debugfs_dir);
  1011. nl80211_exit();
  1012. unregister_netdevice_notifier(&cfg80211_netdev_notifier);
  1013. wiphy_sysfs_exit();
  1014. regulatory_exit();
  1015. unregister_pernet_device(&cfg80211_pernet_ops);
  1016. destroy_workqueue(cfg80211_wq);
  1017. }
  1018. module_exit(cfg80211_exit);