core.c 32 KB

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