main.c 34 KB

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