core.c 31 KB

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