main.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222
  1. /*
  2. * Copyright 2002-2005, Instant802 Networks, Inc.
  3. * Copyright 2005-2006, Devicescape Software, Inc.
  4. * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz>
  5. * Copyright 2013-2014 Intel Mobile Communications GmbH
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. */
  11. #include <net/mac80211.h>
  12. #include <linux/module.h>
  13. #include <linux/init.h>
  14. #include <linux/netdevice.h>
  15. #include <linux/types.h>
  16. #include <linux/slab.h>
  17. #include <linux/skbuff.h>
  18. #include <linux/etherdevice.h>
  19. #include <linux/if_arp.h>
  20. #include <linux/rtnetlink.h>
  21. #include <linux/bitmap.h>
  22. #include <linux/pm_qos.h>
  23. #include <linux/inetdevice.h>
  24. #include <net/net_namespace.h>
  25. #include <net/cfg80211.h>
  26. #include <net/addrconf.h>
  27. #include "ieee80211_i.h"
  28. #include "driver-ops.h"
  29. #include "rate.h"
  30. #include "mesh.h"
  31. #include "wep.h"
  32. #include "led.h"
  33. #include "cfg.h"
  34. #include "debugfs.h"
  35. void ieee80211_configure_filter(struct ieee80211_local *local)
  36. {
  37. u64 mc;
  38. unsigned int changed_flags;
  39. unsigned int new_flags = 0;
  40. if (atomic_read(&local->iff_promiscs))
  41. new_flags |= FIF_PROMISC_IN_BSS;
  42. if (atomic_read(&local->iff_allmultis))
  43. new_flags |= FIF_ALLMULTI;
  44. if (local->monitors || test_bit(SCAN_SW_SCANNING, &local->scanning) ||
  45. test_bit(SCAN_ONCHANNEL_SCANNING, &local->scanning))
  46. new_flags |= FIF_BCN_PRBRESP_PROMISC;
  47. if (local->fif_probe_req || local->probe_req_reg)
  48. new_flags |= FIF_PROBE_REQ;
  49. if (local->fif_fcsfail)
  50. new_flags |= FIF_FCSFAIL;
  51. if (local->fif_plcpfail)
  52. new_flags |= FIF_PLCPFAIL;
  53. if (local->fif_control)
  54. new_flags |= FIF_CONTROL;
  55. if (local->fif_other_bss)
  56. new_flags |= FIF_OTHER_BSS;
  57. if (local->fif_pspoll)
  58. new_flags |= FIF_PSPOLL;
  59. spin_lock_bh(&local->filter_lock);
  60. changed_flags = local->filter_flags ^ new_flags;
  61. mc = drv_prepare_multicast(local, &local->mc_list);
  62. spin_unlock_bh(&local->filter_lock);
  63. /* be a bit nasty */
  64. new_flags |= (1<<31);
  65. drv_configure_filter(local, changed_flags, &new_flags, mc);
  66. WARN_ON(new_flags & (1<<31));
  67. local->filter_flags = new_flags & ~(1<<31);
  68. }
  69. static void ieee80211_reconfig_filter(struct work_struct *work)
  70. {
  71. struct ieee80211_local *local =
  72. container_of(work, struct ieee80211_local, reconfig_filter);
  73. ieee80211_configure_filter(local);
  74. }
  75. static u32 ieee80211_hw_conf_chan(struct ieee80211_local *local)
  76. {
  77. struct ieee80211_sub_if_data *sdata;
  78. struct cfg80211_chan_def chandef = {};
  79. u32 changed = 0;
  80. int power;
  81. u32 offchannel_flag;
  82. offchannel_flag = local->hw.conf.flags & IEEE80211_CONF_OFFCHANNEL;
  83. if (local->scan_chandef.chan) {
  84. chandef = local->scan_chandef;
  85. } else if (local->tmp_channel) {
  86. chandef.chan = local->tmp_channel;
  87. chandef.width = NL80211_CHAN_WIDTH_20_NOHT;
  88. chandef.center_freq1 = chandef.chan->center_freq;
  89. } else
  90. chandef = local->_oper_chandef;
  91. WARN(!cfg80211_chandef_valid(&chandef),
  92. "control:%d MHz width:%d center: %d/%d MHz",
  93. chandef.chan->center_freq, chandef.width,
  94. chandef.center_freq1, chandef.center_freq2);
  95. if (!cfg80211_chandef_identical(&chandef, &local->_oper_chandef))
  96. local->hw.conf.flags |= IEEE80211_CONF_OFFCHANNEL;
  97. else
  98. local->hw.conf.flags &= ~IEEE80211_CONF_OFFCHANNEL;
  99. offchannel_flag ^= local->hw.conf.flags & IEEE80211_CONF_OFFCHANNEL;
  100. if (offchannel_flag ||
  101. !cfg80211_chandef_identical(&local->hw.conf.chandef,
  102. &local->_oper_chandef)) {
  103. local->hw.conf.chandef = chandef;
  104. changed |= IEEE80211_CONF_CHANGE_CHANNEL;
  105. }
  106. if (!conf_is_ht(&local->hw.conf)) {
  107. /*
  108. * mac80211.h documents that this is only valid
  109. * when the channel is set to an HT type, and
  110. * that otherwise STATIC is used.
  111. */
  112. local->hw.conf.smps_mode = IEEE80211_SMPS_STATIC;
  113. } else if (local->hw.conf.smps_mode != local->smps_mode) {
  114. local->hw.conf.smps_mode = local->smps_mode;
  115. changed |= IEEE80211_CONF_CHANGE_SMPS;
  116. }
  117. power = ieee80211_chandef_max_power(&chandef);
  118. rcu_read_lock();
  119. list_for_each_entry_rcu(sdata, &local->interfaces, list) {
  120. if (!rcu_access_pointer(sdata->vif.chanctx_conf))
  121. continue;
  122. if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
  123. continue;
  124. power = min(power, sdata->vif.bss_conf.txpower);
  125. }
  126. rcu_read_unlock();
  127. if (local->hw.conf.power_level != power) {
  128. changed |= IEEE80211_CONF_CHANGE_POWER;
  129. local->hw.conf.power_level = power;
  130. }
  131. return changed;
  132. }
  133. int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
  134. {
  135. int ret = 0;
  136. might_sleep();
  137. if (!local->use_chanctx)
  138. changed |= ieee80211_hw_conf_chan(local);
  139. else
  140. changed &= ~(IEEE80211_CONF_CHANGE_CHANNEL |
  141. IEEE80211_CONF_CHANGE_POWER);
  142. if (changed && local->open_count) {
  143. ret = drv_config(local, changed);
  144. /*
  145. * Goal:
  146. * HW reconfiguration should never fail, the driver has told
  147. * us what it can support so it should live up to that promise.
  148. *
  149. * Current status:
  150. * rfkill is not integrated with mac80211 and a
  151. * configuration command can thus fail if hardware rfkill
  152. * is enabled
  153. *
  154. * FIXME: integrate rfkill with mac80211 and then add this
  155. * WARN_ON() back
  156. *
  157. */
  158. /* WARN_ON(ret); */
  159. }
  160. return ret;
  161. }
  162. void ieee80211_bss_info_change_notify(struct ieee80211_sub_if_data *sdata,
  163. u32 changed)
  164. {
  165. struct ieee80211_local *local = sdata->local;
  166. if (!changed || sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
  167. return;
  168. drv_bss_info_changed(local, sdata, &sdata->vif.bss_conf, changed);
  169. }
  170. u32 ieee80211_reset_erp_info(struct ieee80211_sub_if_data *sdata)
  171. {
  172. sdata->vif.bss_conf.use_cts_prot = false;
  173. sdata->vif.bss_conf.use_short_preamble = false;
  174. sdata->vif.bss_conf.use_short_slot = false;
  175. return BSS_CHANGED_ERP_CTS_PROT |
  176. BSS_CHANGED_ERP_PREAMBLE |
  177. BSS_CHANGED_ERP_SLOT;
  178. }
  179. static void ieee80211_tasklet_handler(unsigned long data)
  180. {
  181. struct ieee80211_local *local = (struct ieee80211_local *) data;
  182. struct sk_buff *skb;
  183. while ((skb = skb_dequeue(&local->skb_queue)) ||
  184. (skb = skb_dequeue(&local->skb_queue_unreliable))) {
  185. switch (skb->pkt_type) {
  186. case IEEE80211_RX_MSG:
  187. /* Clear skb->pkt_type in order to not confuse kernel
  188. * netstack. */
  189. skb->pkt_type = 0;
  190. ieee80211_rx(&local->hw, skb);
  191. break;
  192. case IEEE80211_TX_STATUS_MSG:
  193. skb->pkt_type = 0;
  194. ieee80211_tx_status(&local->hw, skb);
  195. break;
  196. default:
  197. WARN(1, "mac80211: Packet is of unknown type %d\n",
  198. skb->pkt_type);
  199. dev_kfree_skb(skb);
  200. break;
  201. }
  202. }
  203. }
  204. static void ieee80211_restart_work(struct work_struct *work)
  205. {
  206. struct ieee80211_local *local =
  207. container_of(work, struct ieee80211_local, restart_work);
  208. /* wait for scan work complete */
  209. flush_workqueue(local->workqueue);
  210. WARN(test_bit(SCAN_HW_SCANNING, &local->scanning),
  211. "%s called with hardware scan in progress\n", __func__);
  212. rtnl_lock();
  213. ieee80211_scan_cancel(local);
  214. ieee80211_reconfig(local);
  215. rtnl_unlock();
  216. }
  217. void ieee80211_restart_hw(struct ieee80211_hw *hw)
  218. {
  219. struct ieee80211_local *local = hw_to_local(hw);
  220. trace_api_restart_hw(local);
  221. wiphy_info(hw->wiphy,
  222. "Hardware restart was requested\n");
  223. /* use this reason, ieee80211_reconfig will unblock it */
  224. ieee80211_stop_queues_by_reason(hw, IEEE80211_MAX_QUEUE_MAP,
  225. IEEE80211_QUEUE_STOP_REASON_SUSPEND,
  226. false);
  227. /*
  228. * Stop all Rx during the reconfig. We don't want state changes
  229. * or driver callbacks while this is in progress.
  230. */
  231. local->in_reconfig = true;
  232. barrier();
  233. schedule_work(&local->restart_work);
  234. }
  235. EXPORT_SYMBOL(ieee80211_restart_hw);
  236. #ifdef CONFIG_INET
  237. static int ieee80211_ifa_changed(struct notifier_block *nb,
  238. unsigned long data, void *arg)
  239. {
  240. struct in_ifaddr *ifa = arg;
  241. struct ieee80211_local *local =
  242. container_of(nb, struct ieee80211_local,
  243. ifa_notifier);
  244. struct net_device *ndev = ifa->ifa_dev->dev;
  245. struct wireless_dev *wdev = ndev->ieee80211_ptr;
  246. struct in_device *idev;
  247. struct ieee80211_sub_if_data *sdata;
  248. struct ieee80211_bss_conf *bss_conf;
  249. struct ieee80211_if_managed *ifmgd;
  250. int c = 0;
  251. /* Make sure it's our interface that got changed */
  252. if (!wdev)
  253. return NOTIFY_DONE;
  254. if (wdev->wiphy != local->hw.wiphy)
  255. return NOTIFY_DONE;
  256. sdata = IEEE80211_DEV_TO_SUB_IF(ndev);
  257. bss_conf = &sdata->vif.bss_conf;
  258. /* ARP filtering is only supported in managed mode */
  259. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  260. return NOTIFY_DONE;
  261. idev = __in_dev_get_rtnl(sdata->dev);
  262. if (!idev)
  263. return NOTIFY_DONE;
  264. ifmgd = &sdata->u.mgd;
  265. sdata_lock(sdata);
  266. /* Copy the addresses to the bss_conf list */
  267. ifa = idev->ifa_list;
  268. while (ifa) {
  269. if (c < IEEE80211_BSS_ARP_ADDR_LIST_LEN)
  270. bss_conf->arp_addr_list[c] = ifa->ifa_address;
  271. ifa = ifa->ifa_next;
  272. c++;
  273. }
  274. bss_conf->arp_addr_cnt = c;
  275. /* Configure driver only if associated (which also implies it is up) */
  276. if (ifmgd->associated)
  277. ieee80211_bss_info_change_notify(sdata,
  278. BSS_CHANGED_ARP_FILTER);
  279. sdata_unlock(sdata);
  280. return NOTIFY_OK;
  281. }
  282. #endif
  283. #if IS_ENABLED(CONFIG_IPV6)
  284. static int ieee80211_ifa6_changed(struct notifier_block *nb,
  285. unsigned long data, void *arg)
  286. {
  287. struct inet6_ifaddr *ifa = (struct inet6_ifaddr *)arg;
  288. struct inet6_dev *idev = ifa->idev;
  289. struct net_device *ndev = ifa->idev->dev;
  290. struct ieee80211_local *local =
  291. container_of(nb, struct ieee80211_local, ifa6_notifier);
  292. struct wireless_dev *wdev = ndev->ieee80211_ptr;
  293. struct ieee80211_sub_if_data *sdata;
  294. /* Make sure it's our interface that got changed */
  295. if (!wdev || wdev->wiphy != local->hw.wiphy)
  296. return NOTIFY_DONE;
  297. sdata = IEEE80211_DEV_TO_SUB_IF(ndev);
  298. /*
  299. * For now only support station mode. This is mostly because
  300. * doing AP would have to handle AP_VLAN in some way ...
  301. */
  302. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  303. return NOTIFY_DONE;
  304. drv_ipv6_addr_change(local, sdata, idev);
  305. return NOTIFY_OK;
  306. }
  307. #endif
  308. /* There isn't a lot of sense in it, but you can transmit anything you like */
  309. static const struct ieee80211_txrx_stypes
  310. ieee80211_default_mgmt_stypes[NUM_NL80211_IFTYPES] = {
  311. [NL80211_IFTYPE_ADHOC] = {
  312. .tx = 0xffff,
  313. .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  314. BIT(IEEE80211_STYPE_AUTH >> 4) |
  315. BIT(IEEE80211_STYPE_DEAUTH >> 4) |
  316. BIT(IEEE80211_STYPE_PROBE_REQ >> 4),
  317. },
  318. [NL80211_IFTYPE_STATION] = {
  319. .tx = 0xffff,
  320. .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  321. BIT(IEEE80211_STYPE_PROBE_REQ >> 4),
  322. },
  323. [NL80211_IFTYPE_AP] = {
  324. .tx = 0xffff,
  325. .rx = BIT(IEEE80211_STYPE_ASSOC_REQ >> 4) |
  326. BIT(IEEE80211_STYPE_REASSOC_REQ >> 4) |
  327. BIT(IEEE80211_STYPE_PROBE_REQ >> 4) |
  328. BIT(IEEE80211_STYPE_DISASSOC >> 4) |
  329. BIT(IEEE80211_STYPE_AUTH >> 4) |
  330. BIT(IEEE80211_STYPE_DEAUTH >> 4) |
  331. BIT(IEEE80211_STYPE_ACTION >> 4),
  332. },
  333. [NL80211_IFTYPE_AP_VLAN] = {
  334. /* copy AP */
  335. .tx = 0xffff,
  336. .rx = BIT(IEEE80211_STYPE_ASSOC_REQ >> 4) |
  337. BIT(IEEE80211_STYPE_REASSOC_REQ >> 4) |
  338. BIT(IEEE80211_STYPE_PROBE_REQ >> 4) |
  339. BIT(IEEE80211_STYPE_DISASSOC >> 4) |
  340. BIT(IEEE80211_STYPE_AUTH >> 4) |
  341. BIT(IEEE80211_STYPE_DEAUTH >> 4) |
  342. BIT(IEEE80211_STYPE_ACTION >> 4),
  343. },
  344. [NL80211_IFTYPE_P2P_CLIENT] = {
  345. .tx = 0xffff,
  346. .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  347. BIT(IEEE80211_STYPE_PROBE_REQ >> 4),
  348. },
  349. [NL80211_IFTYPE_P2P_GO] = {
  350. .tx = 0xffff,
  351. .rx = BIT(IEEE80211_STYPE_ASSOC_REQ >> 4) |
  352. BIT(IEEE80211_STYPE_REASSOC_REQ >> 4) |
  353. BIT(IEEE80211_STYPE_PROBE_REQ >> 4) |
  354. BIT(IEEE80211_STYPE_DISASSOC >> 4) |
  355. BIT(IEEE80211_STYPE_AUTH >> 4) |
  356. BIT(IEEE80211_STYPE_DEAUTH >> 4) |
  357. BIT(IEEE80211_STYPE_ACTION >> 4),
  358. },
  359. [NL80211_IFTYPE_MESH_POINT] = {
  360. .tx = 0xffff,
  361. .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  362. BIT(IEEE80211_STYPE_AUTH >> 4) |
  363. BIT(IEEE80211_STYPE_DEAUTH >> 4),
  364. },
  365. [NL80211_IFTYPE_P2P_DEVICE] = {
  366. .tx = 0xffff,
  367. .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  368. BIT(IEEE80211_STYPE_PROBE_REQ >> 4),
  369. },
  370. };
  371. static const struct ieee80211_ht_cap mac80211_ht_capa_mod_mask = {
  372. .ampdu_params_info = IEEE80211_HT_AMPDU_PARM_FACTOR |
  373. IEEE80211_HT_AMPDU_PARM_DENSITY,
  374. .cap_info = cpu_to_le16(IEEE80211_HT_CAP_SUP_WIDTH_20_40 |
  375. IEEE80211_HT_CAP_MAX_AMSDU |
  376. IEEE80211_HT_CAP_SGI_20 |
  377. IEEE80211_HT_CAP_SGI_40 |
  378. IEEE80211_HT_CAP_LDPC_CODING |
  379. IEEE80211_HT_CAP_40MHZ_INTOLERANT),
  380. .mcs = {
  381. .rx_mask = { 0xff, 0xff, 0xff, 0xff, 0xff,
  382. 0xff, 0xff, 0xff, 0xff, 0xff, },
  383. },
  384. };
  385. static const struct ieee80211_vht_cap mac80211_vht_capa_mod_mask = {
  386. .vht_cap_info =
  387. cpu_to_le32(IEEE80211_VHT_CAP_RXLDPC |
  388. IEEE80211_VHT_CAP_SHORT_GI_80 |
  389. IEEE80211_VHT_CAP_SHORT_GI_160 |
  390. IEEE80211_VHT_CAP_RXSTBC_1 |
  391. IEEE80211_VHT_CAP_RXSTBC_2 |
  392. IEEE80211_VHT_CAP_RXSTBC_3 |
  393. IEEE80211_VHT_CAP_RXSTBC_4 |
  394. IEEE80211_VHT_CAP_TXSTBC |
  395. IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
  396. IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
  397. IEEE80211_VHT_CAP_TX_ANTENNA_PATTERN |
  398. IEEE80211_VHT_CAP_RX_ANTENNA_PATTERN |
  399. IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK),
  400. .supp_mcs = {
  401. .rx_mcs_map = cpu_to_le16(~0),
  402. .tx_mcs_map = cpu_to_le16(~0),
  403. },
  404. };
  405. static const u8 extended_capabilities[] = {
  406. 0, 0, 0, 0, 0, 0, 0,
  407. WLAN_EXT_CAPA8_OPMODE_NOTIF,
  408. };
  409. struct ieee80211_hw *ieee80211_alloc_hw(size_t priv_data_len,
  410. const struct ieee80211_ops *ops)
  411. {
  412. struct ieee80211_local *local;
  413. int priv_size, i;
  414. struct wiphy *wiphy;
  415. bool use_chanctx;
  416. if (WARN_ON(!ops->tx || !ops->start || !ops->stop || !ops->config ||
  417. !ops->add_interface || !ops->remove_interface ||
  418. !ops->configure_filter))
  419. return NULL;
  420. if (WARN_ON(ops->sta_state && (ops->sta_add || ops->sta_remove)))
  421. return NULL;
  422. /* check all or no channel context operations exist */
  423. i = !!ops->add_chanctx + !!ops->remove_chanctx +
  424. !!ops->change_chanctx + !!ops->assign_vif_chanctx +
  425. !!ops->unassign_vif_chanctx;
  426. if (WARN_ON(i != 0 && i != 5))
  427. return NULL;
  428. use_chanctx = i == 5;
  429. /* Ensure 32-byte alignment of our private data and hw private data.
  430. * We use the wiphy priv data for both our ieee80211_local and for
  431. * the driver's private data
  432. *
  433. * In memory it'll be like this:
  434. *
  435. * +-------------------------+
  436. * | struct wiphy |
  437. * +-------------------------+
  438. * | struct ieee80211_local |
  439. * +-------------------------+
  440. * | driver's private data |
  441. * +-------------------------+
  442. *
  443. */
  444. priv_size = ALIGN(sizeof(*local), NETDEV_ALIGN) + priv_data_len;
  445. wiphy = wiphy_new(&mac80211_config_ops, priv_size);
  446. if (!wiphy)
  447. return NULL;
  448. wiphy->mgmt_stypes = ieee80211_default_mgmt_stypes;
  449. wiphy->privid = mac80211_wiphy_privid;
  450. wiphy->flags |= WIPHY_FLAG_NETNS_OK |
  451. WIPHY_FLAG_4ADDR_AP |
  452. WIPHY_FLAG_4ADDR_STATION |
  453. WIPHY_FLAG_REPORTS_OBSS |
  454. WIPHY_FLAG_OFFCHAN_TX;
  455. wiphy->extended_capabilities = extended_capabilities;
  456. wiphy->extended_capabilities_mask = extended_capabilities;
  457. wiphy->extended_capabilities_len = ARRAY_SIZE(extended_capabilities);
  458. if (ops->remain_on_channel)
  459. wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
  460. wiphy->features |= NL80211_FEATURE_SK_TX_STATUS |
  461. NL80211_FEATURE_SAE |
  462. NL80211_FEATURE_HT_IBSS |
  463. NL80211_FEATURE_VIF_TXPOWER |
  464. NL80211_FEATURE_USERSPACE_MPM;
  465. if (!ops->hw_scan)
  466. wiphy->features |= NL80211_FEATURE_LOW_PRIORITY_SCAN |
  467. NL80211_FEATURE_AP_SCAN;
  468. if (!ops->set_key)
  469. wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
  470. wiphy->bss_priv_size = sizeof(struct ieee80211_bss);
  471. local = wiphy_priv(wiphy);
  472. local->hw.wiphy = wiphy;
  473. local->hw.priv = (char *)local + ALIGN(sizeof(*local), NETDEV_ALIGN);
  474. local->ops = ops;
  475. local->use_chanctx = use_chanctx;
  476. /* set up some defaults */
  477. local->hw.queues = 1;
  478. local->hw.max_rates = 1;
  479. local->hw.max_report_rates = 0;
  480. local->hw.max_rx_aggregation_subframes = IEEE80211_MAX_AMPDU_BUF;
  481. local->hw.max_tx_aggregation_subframes = IEEE80211_MAX_AMPDU_BUF;
  482. local->hw.offchannel_tx_hw_queue = IEEE80211_INVAL_HW_QUEUE;
  483. local->hw.conf.long_frame_max_tx_count = wiphy->retry_long;
  484. local->hw.conf.short_frame_max_tx_count = wiphy->retry_short;
  485. local->hw.radiotap_mcs_details = IEEE80211_RADIOTAP_MCS_HAVE_MCS |
  486. IEEE80211_RADIOTAP_MCS_HAVE_GI |
  487. IEEE80211_RADIOTAP_MCS_HAVE_BW;
  488. local->hw.radiotap_vht_details = IEEE80211_RADIOTAP_VHT_KNOWN_GI |
  489. IEEE80211_RADIOTAP_VHT_KNOWN_BANDWIDTH;
  490. local->hw.uapsd_queues = IEEE80211_DEFAULT_UAPSD_QUEUES;
  491. local->hw.uapsd_max_sp_len = IEEE80211_DEFAULT_MAX_SP_LEN;
  492. local->user_power_level = IEEE80211_UNSET_POWER_LEVEL;
  493. wiphy->ht_capa_mod_mask = &mac80211_ht_capa_mod_mask;
  494. wiphy->vht_capa_mod_mask = &mac80211_vht_capa_mod_mask;
  495. INIT_LIST_HEAD(&local->interfaces);
  496. __hw_addr_init(&local->mc_list);
  497. mutex_init(&local->iflist_mtx);
  498. mutex_init(&local->mtx);
  499. mutex_init(&local->key_mtx);
  500. spin_lock_init(&local->filter_lock);
  501. spin_lock_init(&local->rx_path_lock);
  502. spin_lock_init(&local->queue_stop_reason_lock);
  503. INIT_LIST_HEAD(&local->chanctx_list);
  504. mutex_init(&local->chanctx_mtx);
  505. INIT_DELAYED_WORK(&local->scan_work, ieee80211_scan_work);
  506. INIT_WORK(&local->restart_work, ieee80211_restart_work);
  507. INIT_WORK(&local->radar_detected_work,
  508. ieee80211_dfs_radar_detected_work);
  509. INIT_WORK(&local->reconfig_filter, ieee80211_reconfig_filter);
  510. local->smps_mode = IEEE80211_SMPS_OFF;
  511. INIT_WORK(&local->dynamic_ps_enable_work,
  512. ieee80211_dynamic_ps_enable_work);
  513. INIT_WORK(&local->dynamic_ps_disable_work,
  514. ieee80211_dynamic_ps_disable_work);
  515. setup_timer(&local->dynamic_ps_timer,
  516. ieee80211_dynamic_ps_timer, (unsigned long) local);
  517. INIT_WORK(&local->sched_scan_stopped_work,
  518. ieee80211_sched_scan_stopped_work);
  519. spin_lock_init(&local->ack_status_lock);
  520. idr_init(&local->ack_status_frames);
  521. sta_info_init(local);
  522. for (i = 0; i < IEEE80211_MAX_QUEUES; i++) {
  523. skb_queue_head_init(&local->pending[i]);
  524. atomic_set(&local->agg_queue_stop[i], 0);
  525. }
  526. tasklet_init(&local->tx_pending_tasklet, ieee80211_tx_pending,
  527. (unsigned long)local);
  528. tasklet_init(&local->tasklet,
  529. ieee80211_tasklet_handler,
  530. (unsigned long) local);
  531. skb_queue_head_init(&local->skb_queue);
  532. skb_queue_head_init(&local->skb_queue_unreliable);
  533. ieee80211_led_names(local);
  534. ieee80211_roc_setup(local);
  535. return &local->hw;
  536. }
  537. EXPORT_SYMBOL(ieee80211_alloc_hw);
  538. static int ieee80211_init_cipher_suites(struct ieee80211_local *local)
  539. {
  540. bool have_wep = !(IS_ERR(local->wep_tx_tfm) ||
  541. IS_ERR(local->wep_rx_tfm));
  542. bool have_mfp = local->hw.flags & IEEE80211_HW_MFP_CAPABLE;
  543. const struct ieee80211_cipher_scheme *cs = local->hw.cipher_schemes;
  544. int n_suites = 0, r = 0, w = 0;
  545. u32 *suites;
  546. static const u32 cipher_suites[] = {
  547. /* keep WEP first, it may be removed below */
  548. WLAN_CIPHER_SUITE_WEP40,
  549. WLAN_CIPHER_SUITE_WEP104,
  550. WLAN_CIPHER_SUITE_TKIP,
  551. WLAN_CIPHER_SUITE_CCMP,
  552. /* keep last -- depends on hw flags! */
  553. WLAN_CIPHER_SUITE_AES_CMAC
  554. };
  555. /* Driver specifies the ciphers, we have nothing to do... */
  556. if (local->hw.wiphy->cipher_suites && have_wep)
  557. return 0;
  558. /* Set up cipher suites if driver relies on mac80211 cipher defs */
  559. if (!local->hw.wiphy->cipher_suites && !cs) {
  560. local->hw.wiphy->cipher_suites = cipher_suites;
  561. local->hw.wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
  562. if (!have_mfp)
  563. local->hw.wiphy->n_cipher_suites--;
  564. if (!have_wep) {
  565. local->hw.wiphy->cipher_suites += 2;
  566. local->hw.wiphy->n_cipher_suites -= 2;
  567. }
  568. return 0;
  569. }
  570. if (!local->hw.wiphy->cipher_suites) {
  571. /*
  572. * Driver specifies cipher schemes only
  573. * We start counting ciphers defined by schemes, TKIP and CCMP
  574. */
  575. n_suites = local->hw.n_cipher_schemes + 2;
  576. /* check if we have WEP40 and WEP104 */
  577. if (have_wep)
  578. n_suites += 2;
  579. /* check if we have AES_CMAC */
  580. if (have_mfp)
  581. n_suites++;
  582. suites = kmalloc(sizeof(u32) * n_suites, GFP_KERNEL);
  583. if (!suites)
  584. return -ENOMEM;
  585. suites[w++] = WLAN_CIPHER_SUITE_CCMP;
  586. suites[w++] = WLAN_CIPHER_SUITE_TKIP;
  587. if (have_wep) {
  588. suites[w++] = WLAN_CIPHER_SUITE_WEP40;
  589. suites[w++] = WLAN_CIPHER_SUITE_WEP104;
  590. }
  591. if (have_mfp)
  592. suites[w++] = WLAN_CIPHER_SUITE_AES_CMAC;
  593. for (r = 0; r < local->hw.n_cipher_schemes; r++)
  594. suites[w++] = cs[r].cipher;
  595. } else {
  596. /* Driver provides cipher suites, but we need to exclude WEP */
  597. suites = kmemdup(local->hw.wiphy->cipher_suites,
  598. sizeof(u32) * local->hw.wiphy->n_cipher_suites,
  599. GFP_KERNEL);
  600. if (!suites)
  601. return -ENOMEM;
  602. for (r = 0; r < local->hw.wiphy->n_cipher_suites; r++) {
  603. u32 suite = local->hw.wiphy->cipher_suites[r];
  604. if (suite == WLAN_CIPHER_SUITE_WEP40 ||
  605. suite == WLAN_CIPHER_SUITE_WEP104)
  606. continue;
  607. suites[w++] = suite;
  608. }
  609. }
  610. local->hw.wiphy->cipher_suites = suites;
  611. local->hw.wiphy->n_cipher_suites = w;
  612. local->wiphy_ciphers_allocated = true;
  613. return 0;
  614. }
  615. int ieee80211_register_hw(struct ieee80211_hw *hw)
  616. {
  617. struct ieee80211_local *local = hw_to_local(hw);
  618. int result, i;
  619. enum ieee80211_band band;
  620. int channels, max_bitrates;
  621. bool supp_ht, supp_vht;
  622. netdev_features_t feature_whitelist;
  623. struct cfg80211_chan_def dflt_chandef = {};
  624. if (hw->flags & IEEE80211_HW_QUEUE_CONTROL &&
  625. (local->hw.offchannel_tx_hw_queue == IEEE80211_INVAL_HW_QUEUE ||
  626. local->hw.offchannel_tx_hw_queue >= local->hw.queues))
  627. return -EINVAL;
  628. #ifdef CONFIG_PM
  629. if (hw->wiphy->wowlan && (!local->ops->suspend || !local->ops->resume))
  630. return -EINVAL;
  631. #endif
  632. if (!local->use_chanctx) {
  633. for (i = 0; i < local->hw.wiphy->n_iface_combinations; i++) {
  634. const struct ieee80211_iface_combination *comb;
  635. comb = &local->hw.wiphy->iface_combinations[i];
  636. if (comb->num_different_channels > 1)
  637. return -EINVAL;
  638. }
  639. } else {
  640. /*
  641. * WDS is currently prohibited when channel contexts are used
  642. * because there's no clear definition of which channel WDS
  643. * type interfaces use
  644. */
  645. if (local->hw.wiphy->interface_modes & BIT(NL80211_IFTYPE_WDS))
  646. return -EINVAL;
  647. /* DFS currently not supported with channel context drivers */
  648. for (i = 0; i < local->hw.wiphy->n_iface_combinations; i++) {
  649. const struct ieee80211_iface_combination *comb;
  650. comb = &local->hw.wiphy->iface_combinations[i];
  651. if (comb->radar_detect_widths)
  652. return -EINVAL;
  653. }
  654. }
  655. /* Only HW csum features are currently compatible with mac80211 */
  656. feature_whitelist = NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
  657. NETIF_F_HW_CSUM;
  658. if (WARN_ON(hw->netdev_features & ~feature_whitelist))
  659. return -EINVAL;
  660. if (hw->max_report_rates == 0)
  661. hw->max_report_rates = hw->max_rates;
  662. local->rx_chains = 1;
  663. /*
  664. * generic code guarantees at least one band,
  665. * set this very early because much code assumes
  666. * that hw.conf.channel is assigned
  667. */
  668. channels = 0;
  669. max_bitrates = 0;
  670. supp_ht = false;
  671. supp_vht = false;
  672. for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
  673. struct ieee80211_supported_band *sband;
  674. sband = local->hw.wiphy->bands[band];
  675. if (!sband)
  676. continue;
  677. if (!dflt_chandef.chan) {
  678. cfg80211_chandef_create(&dflt_chandef,
  679. &sband->channels[0],
  680. NL80211_CHAN_NO_HT);
  681. /* init channel we're on */
  682. if (!local->use_chanctx && !local->_oper_chandef.chan) {
  683. local->hw.conf.chandef = dflt_chandef;
  684. local->_oper_chandef = dflt_chandef;
  685. }
  686. local->monitor_chandef = dflt_chandef;
  687. }
  688. channels += sband->n_channels;
  689. if (max_bitrates < sband->n_bitrates)
  690. max_bitrates = sband->n_bitrates;
  691. supp_ht = supp_ht || sband->ht_cap.ht_supported;
  692. supp_vht = supp_vht || sband->vht_cap.vht_supported;
  693. if (sband->ht_cap.ht_supported)
  694. local->rx_chains =
  695. max(ieee80211_mcs_to_chains(&sband->ht_cap.mcs),
  696. local->rx_chains);
  697. /* TODO: consider VHT for RX chains, hopefully it's the same */
  698. }
  699. /* if low-level driver supports AP, we also support VLAN */
  700. if (local->hw.wiphy->interface_modes & BIT(NL80211_IFTYPE_AP)) {
  701. hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_AP_VLAN);
  702. hw->wiphy->software_iftypes |= BIT(NL80211_IFTYPE_AP_VLAN);
  703. }
  704. /* mac80211 always supports monitor */
  705. hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_MONITOR);
  706. hw->wiphy->software_iftypes |= BIT(NL80211_IFTYPE_MONITOR);
  707. /* mac80211 doesn't support more than one IBSS interface right now */
  708. for (i = 0; i < hw->wiphy->n_iface_combinations; i++) {
  709. const struct ieee80211_iface_combination *c;
  710. int j;
  711. c = &hw->wiphy->iface_combinations[i];
  712. for (j = 0; j < c->n_limits; j++)
  713. if ((c->limits[j].types & BIT(NL80211_IFTYPE_ADHOC)) &&
  714. c->limits[j].max > 1)
  715. return -EINVAL;
  716. }
  717. local->int_scan_req = kzalloc(sizeof(*local->int_scan_req) +
  718. sizeof(void *) * channels, GFP_KERNEL);
  719. if (!local->int_scan_req)
  720. return -ENOMEM;
  721. for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
  722. if (!local->hw.wiphy->bands[band])
  723. continue;
  724. local->int_scan_req->rates[band] = (u32) -1;
  725. }
  726. #ifndef CONFIG_MAC80211_MESH
  727. /* mesh depends on Kconfig, but drivers should set it if they want */
  728. local->hw.wiphy->interface_modes &= ~BIT(NL80211_IFTYPE_MESH_POINT);
  729. #endif
  730. /* if the underlying driver supports mesh, mac80211 will (at least)
  731. * provide routing of mesh authentication frames to userspace */
  732. if (local->hw.wiphy->interface_modes & BIT(NL80211_IFTYPE_MESH_POINT))
  733. local->hw.wiphy->flags |= WIPHY_FLAG_MESH_AUTH;
  734. /* mac80211 supports control port protocol changing */
  735. local->hw.wiphy->flags |= WIPHY_FLAG_CONTROL_PORT_PROTOCOL;
  736. if (local->hw.flags & IEEE80211_HW_SIGNAL_DBM) {
  737. local->hw.wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
  738. } else if (local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC) {
  739. local->hw.wiphy->signal_type = CFG80211_SIGNAL_TYPE_UNSPEC;
  740. if (hw->max_signal <= 0) {
  741. result = -EINVAL;
  742. goto fail_wiphy_register;
  743. }
  744. }
  745. WARN((local->hw.flags & IEEE80211_HW_SUPPORTS_UAPSD)
  746. && (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK),
  747. "U-APSD not supported with HW_PS_NULLFUNC_STACK\n");
  748. /*
  749. * Calculate scan IE length -- we need this to alloc
  750. * memory and to subtract from the driver limit. It
  751. * includes the DS Params, (extended) supported rates, and HT
  752. * information -- SSID is the driver's responsibility.
  753. */
  754. local->scan_ies_len = 4 + max_bitrates /* (ext) supp rates */ +
  755. 3 /* DS Params */;
  756. if (supp_ht)
  757. local->scan_ies_len += 2 + sizeof(struct ieee80211_ht_cap);
  758. if (supp_vht)
  759. local->scan_ies_len +=
  760. 2 + sizeof(struct ieee80211_vht_cap);
  761. if (!local->ops->hw_scan) {
  762. /* For hw_scan, driver needs to set these up. */
  763. local->hw.wiphy->max_scan_ssids = 4;
  764. local->hw.wiphy->max_scan_ie_len = IEEE80211_MAX_DATA_LEN;
  765. }
  766. /*
  767. * If the driver supports any scan IEs, then assume the
  768. * limit includes the IEs mac80211 will add, otherwise
  769. * leave it at zero and let the driver sort it out; we
  770. * still pass our IEs to the driver but userspace will
  771. * not be allowed to in that case.
  772. */
  773. if (local->hw.wiphy->max_scan_ie_len)
  774. local->hw.wiphy->max_scan_ie_len -= local->scan_ies_len;
  775. WARN_ON(!ieee80211_cs_list_valid(local->hw.cipher_schemes,
  776. local->hw.n_cipher_schemes));
  777. result = ieee80211_init_cipher_suites(local);
  778. if (result < 0)
  779. goto fail_wiphy_register;
  780. if (!local->ops->remain_on_channel)
  781. local->hw.wiphy->max_remain_on_channel_duration = 5000;
  782. /* mac80211 based drivers don't support internal TDLS setup */
  783. if (local->hw.wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS)
  784. local->hw.wiphy->flags |= WIPHY_FLAG_TDLS_EXTERNAL_SETUP;
  785. local->hw.wiphy->max_num_csa_counters = IEEE80211_MAX_CSA_COUNTERS_NUM;
  786. result = wiphy_register(local->hw.wiphy);
  787. if (result < 0)
  788. goto fail_wiphy_register;
  789. /*
  790. * We use the number of queues for feature tests (QoS, HT) internally
  791. * so restrict them appropriately.
  792. */
  793. if (hw->queues > IEEE80211_MAX_QUEUES)
  794. hw->queues = IEEE80211_MAX_QUEUES;
  795. local->workqueue =
  796. alloc_ordered_workqueue("%s", 0, wiphy_name(local->hw.wiphy));
  797. if (!local->workqueue) {
  798. result = -ENOMEM;
  799. goto fail_workqueue;
  800. }
  801. /*
  802. * The hardware needs headroom for sending the frame,
  803. * and we need some headroom for passing the frame to monitor
  804. * interfaces, but never both at the same time.
  805. */
  806. local->tx_headroom = max_t(unsigned int , local->hw.extra_tx_headroom,
  807. IEEE80211_TX_STATUS_HEADROOM);
  808. debugfs_hw_add(local);
  809. /*
  810. * if the driver doesn't specify a max listen interval we
  811. * use 5 which should be a safe default
  812. */
  813. if (local->hw.max_listen_interval == 0)
  814. local->hw.max_listen_interval = 5;
  815. local->hw.conf.listen_interval = local->hw.max_listen_interval;
  816. local->dynamic_ps_forced_timeout = -1;
  817. result = ieee80211_wep_init(local);
  818. if (result < 0)
  819. wiphy_debug(local->hw.wiphy, "Failed to initialize wep: %d\n",
  820. result);
  821. local->hw.conf.flags = IEEE80211_CONF_IDLE;
  822. ieee80211_led_init(local);
  823. rtnl_lock();
  824. result = ieee80211_init_rate_ctrl_alg(local,
  825. hw->rate_control_algorithm);
  826. if (result < 0) {
  827. wiphy_debug(local->hw.wiphy,
  828. "Failed to initialize rate control algorithm\n");
  829. goto fail_rate;
  830. }
  831. /* add one default STA interface if supported */
  832. if (local->hw.wiphy->interface_modes & BIT(NL80211_IFTYPE_STATION)) {
  833. result = ieee80211_if_add(local, "wlan%d", NULL,
  834. NL80211_IFTYPE_STATION, NULL);
  835. if (result)
  836. wiphy_warn(local->hw.wiphy,
  837. "Failed to add default virtual iface\n");
  838. }
  839. rtnl_unlock();
  840. local->network_latency_notifier.notifier_call =
  841. ieee80211_max_network_latency;
  842. result = pm_qos_add_notifier(PM_QOS_NETWORK_LATENCY,
  843. &local->network_latency_notifier);
  844. if (result) {
  845. rtnl_lock();
  846. goto fail_pm_qos;
  847. }
  848. #ifdef CONFIG_INET
  849. local->ifa_notifier.notifier_call = ieee80211_ifa_changed;
  850. result = register_inetaddr_notifier(&local->ifa_notifier);
  851. if (result)
  852. goto fail_ifa;
  853. #endif
  854. #if IS_ENABLED(CONFIG_IPV6)
  855. local->ifa6_notifier.notifier_call = ieee80211_ifa6_changed;
  856. result = register_inet6addr_notifier(&local->ifa6_notifier);
  857. if (result)
  858. goto fail_ifa6;
  859. #endif
  860. return 0;
  861. #if IS_ENABLED(CONFIG_IPV6)
  862. fail_ifa6:
  863. #ifdef CONFIG_INET
  864. unregister_inetaddr_notifier(&local->ifa_notifier);
  865. #endif
  866. #endif
  867. #if defined(CONFIG_INET) || defined(CONFIG_IPV6)
  868. fail_ifa:
  869. pm_qos_remove_notifier(PM_QOS_NETWORK_LATENCY,
  870. &local->network_latency_notifier);
  871. rtnl_lock();
  872. #endif
  873. fail_pm_qos:
  874. ieee80211_led_exit(local);
  875. ieee80211_remove_interfaces(local);
  876. fail_rate:
  877. rtnl_unlock();
  878. ieee80211_wep_free(local);
  879. sta_info_stop(local);
  880. destroy_workqueue(local->workqueue);
  881. fail_workqueue:
  882. wiphy_unregister(local->hw.wiphy);
  883. fail_wiphy_register:
  884. if (local->wiphy_ciphers_allocated)
  885. kfree(local->hw.wiphy->cipher_suites);
  886. kfree(local->int_scan_req);
  887. return result;
  888. }
  889. EXPORT_SYMBOL(ieee80211_register_hw);
  890. void ieee80211_napi_add(struct ieee80211_hw *hw, struct napi_struct *napi,
  891. struct net_device *napi_dev,
  892. int (*poll)(struct napi_struct *, int),
  893. int weight)
  894. {
  895. struct ieee80211_local *local = hw_to_local(hw);
  896. netif_napi_add(napi_dev, napi, poll, weight);
  897. local->napi = napi;
  898. }
  899. EXPORT_SYMBOL_GPL(ieee80211_napi_add);
  900. void ieee80211_unregister_hw(struct ieee80211_hw *hw)
  901. {
  902. struct ieee80211_local *local = hw_to_local(hw);
  903. tasklet_kill(&local->tx_pending_tasklet);
  904. tasklet_kill(&local->tasklet);
  905. pm_qos_remove_notifier(PM_QOS_NETWORK_LATENCY,
  906. &local->network_latency_notifier);
  907. #ifdef CONFIG_INET
  908. unregister_inetaddr_notifier(&local->ifa_notifier);
  909. #endif
  910. #if IS_ENABLED(CONFIG_IPV6)
  911. unregister_inet6addr_notifier(&local->ifa6_notifier);
  912. #endif
  913. rtnl_lock();
  914. /*
  915. * At this point, interface list manipulations are fine
  916. * because the driver cannot be handing us frames any
  917. * more and the tasklet is killed.
  918. */
  919. ieee80211_remove_interfaces(local);
  920. rtnl_unlock();
  921. cancel_work_sync(&local->restart_work);
  922. cancel_work_sync(&local->reconfig_filter);
  923. flush_work(&local->sched_scan_stopped_work);
  924. ieee80211_clear_tx_pending(local);
  925. rate_control_deinitialize(local);
  926. if (skb_queue_len(&local->skb_queue) ||
  927. skb_queue_len(&local->skb_queue_unreliable))
  928. wiphy_warn(local->hw.wiphy, "skb_queue not empty\n");
  929. skb_queue_purge(&local->skb_queue);
  930. skb_queue_purge(&local->skb_queue_unreliable);
  931. destroy_workqueue(local->workqueue);
  932. wiphy_unregister(local->hw.wiphy);
  933. sta_info_stop(local);
  934. ieee80211_wep_free(local);
  935. ieee80211_led_exit(local);
  936. kfree(local->int_scan_req);
  937. }
  938. EXPORT_SYMBOL(ieee80211_unregister_hw);
  939. static int ieee80211_free_ack_frame(int id, void *p, void *data)
  940. {
  941. WARN_ONCE(1, "Have pending ack frames!\n");
  942. kfree_skb(p);
  943. return 0;
  944. }
  945. void ieee80211_free_hw(struct ieee80211_hw *hw)
  946. {
  947. struct ieee80211_local *local = hw_to_local(hw);
  948. mutex_destroy(&local->iflist_mtx);
  949. mutex_destroy(&local->mtx);
  950. if (local->wiphy_ciphers_allocated)
  951. kfree(local->hw.wiphy->cipher_suites);
  952. idr_for_each(&local->ack_status_frames,
  953. ieee80211_free_ack_frame, NULL);
  954. idr_destroy(&local->ack_status_frames);
  955. kfree(rcu_access_pointer(local->tx_latency));
  956. wiphy_free(local->hw.wiphy);
  957. }
  958. EXPORT_SYMBOL(ieee80211_free_hw);
  959. static int __init ieee80211_init(void)
  960. {
  961. struct sk_buff *skb;
  962. int ret;
  963. BUILD_BUG_ON(sizeof(struct ieee80211_tx_info) > sizeof(skb->cb));
  964. BUILD_BUG_ON(offsetof(struct ieee80211_tx_info, driver_data) +
  965. IEEE80211_TX_INFO_DRIVER_DATA_SIZE > sizeof(skb->cb));
  966. ret = rc80211_minstrel_init();
  967. if (ret)
  968. return ret;
  969. ret = rc80211_minstrel_ht_init();
  970. if (ret)
  971. goto err_minstrel;
  972. ret = ieee80211_iface_init();
  973. if (ret)
  974. goto err_netdev;
  975. return 0;
  976. err_netdev:
  977. rc80211_minstrel_ht_exit();
  978. err_minstrel:
  979. rc80211_minstrel_exit();
  980. return ret;
  981. }
  982. static void __exit ieee80211_exit(void)
  983. {
  984. rc80211_minstrel_ht_exit();
  985. rc80211_minstrel_exit();
  986. ieee80211s_stop();
  987. ieee80211_iface_exit();
  988. rcu_barrier();
  989. }
  990. subsys_initcall(ieee80211_init);
  991. module_exit(ieee80211_exit);
  992. MODULE_DESCRIPTION("IEEE 802.11 subsystem");
  993. MODULE_LICENSE("GPL");