main.c 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252
  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. WARN(test_bit(SCAN_HW_SCANNING, &local->scanning),
  208. "%s called with hardware scan in progress\n", __func__);
  209. rtnl_lock();
  210. list_for_each_entry(sdata, &local->interfaces, list)
  211. flush_delayed_work(&sdata->dec_tailroom_needed_wk);
  212. ieee80211_scan_cancel(local);
  213. ieee80211_reconfig(local);
  214. rtnl_unlock();
  215. }
  216. void ieee80211_restart_hw(struct ieee80211_hw *hw)
  217. {
  218. struct ieee80211_local *local = hw_to_local(hw);
  219. trace_api_restart_hw(local);
  220. wiphy_info(hw->wiphy,
  221. "Hardware restart was requested\n");
  222. /* use this reason, ieee80211_reconfig will unblock it */
  223. ieee80211_stop_queues_by_reason(hw, IEEE80211_MAX_QUEUE_MAP,
  224. IEEE80211_QUEUE_STOP_REASON_SUSPEND,
  225. false);
  226. /*
  227. * Stop all Rx during the reconfig. We don't want state changes
  228. * or driver callbacks while this is in progress.
  229. */
  230. local->in_reconfig = true;
  231. barrier();
  232. queue_work(system_freezable_wq, &local->restart_work);
  233. }
  234. EXPORT_SYMBOL(ieee80211_restart_hw);
  235. #ifdef CONFIG_INET
  236. static int ieee80211_ifa_changed(struct notifier_block *nb,
  237. unsigned long data, void *arg)
  238. {
  239. struct in_ifaddr *ifa = arg;
  240. struct ieee80211_local *local =
  241. container_of(nb, struct ieee80211_local,
  242. ifa_notifier);
  243. struct net_device *ndev = ifa->ifa_dev->dev;
  244. struct wireless_dev *wdev = ndev->ieee80211_ptr;
  245. struct in_device *idev;
  246. struct ieee80211_sub_if_data *sdata;
  247. struct ieee80211_bss_conf *bss_conf;
  248. struct ieee80211_if_managed *ifmgd;
  249. int c = 0;
  250. /* Make sure it's our interface that got changed */
  251. if (!wdev)
  252. return NOTIFY_DONE;
  253. if (wdev->wiphy != local->hw.wiphy)
  254. return NOTIFY_DONE;
  255. sdata = IEEE80211_DEV_TO_SUB_IF(ndev);
  256. bss_conf = &sdata->vif.bss_conf;
  257. /* ARP filtering is only supported in managed mode */
  258. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  259. return NOTIFY_DONE;
  260. idev = __in_dev_get_rtnl(sdata->dev);
  261. if (!idev)
  262. return NOTIFY_DONE;
  263. ifmgd = &sdata->u.mgd;
  264. sdata_lock(sdata);
  265. /* Copy the addresses to the bss_conf list */
  266. ifa = idev->ifa_list;
  267. while (ifa) {
  268. if (c < IEEE80211_BSS_ARP_ADDR_LIST_LEN)
  269. bss_conf->arp_addr_list[c] = ifa->ifa_address;
  270. ifa = ifa->ifa_next;
  271. c++;
  272. }
  273. bss_conf->arp_addr_cnt = c;
  274. /* Configure driver only if associated (which also implies it is up) */
  275. if (ifmgd->associated)
  276. ieee80211_bss_info_change_notify(sdata,
  277. BSS_CHANGED_ARP_FILTER);
  278. sdata_unlock(sdata);
  279. return NOTIFY_OK;
  280. }
  281. #endif
  282. #if IS_ENABLED(CONFIG_IPV6)
  283. static int ieee80211_ifa6_changed(struct notifier_block *nb,
  284. unsigned long data, void *arg)
  285. {
  286. struct inet6_ifaddr *ifa = (struct inet6_ifaddr *)arg;
  287. struct inet6_dev *idev = ifa->idev;
  288. struct net_device *ndev = ifa->idev->dev;
  289. struct ieee80211_local *local =
  290. container_of(nb, struct ieee80211_local, ifa6_notifier);
  291. struct wireless_dev *wdev = ndev->ieee80211_ptr;
  292. struct ieee80211_sub_if_data *sdata;
  293. /* Make sure it's our interface that got changed */
  294. if (!wdev || wdev->wiphy != local->hw.wiphy)
  295. return NOTIFY_DONE;
  296. sdata = IEEE80211_DEV_TO_SUB_IF(ndev);
  297. /*
  298. * For now only support station mode. This is mostly because
  299. * doing AP would have to handle AP_VLAN in some way ...
  300. */
  301. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  302. return NOTIFY_DONE;
  303. drv_ipv6_addr_change(local, sdata, idev);
  304. return NOTIFY_OK;
  305. }
  306. #endif
  307. /* There isn't a lot of sense in it, but you can transmit anything you like */
  308. static const struct ieee80211_txrx_stypes
  309. ieee80211_default_mgmt_stypes[NUM_NL80211_IFTYPES] = {
  310. [NL80211_IFTYPE_ADHOC] = {
  311. .tx = 0xffff,
  312. .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  313. BIT(IEEE80211_STYPE_AUTH >> 4) |
  314. BIT(IEEE80211_STYPE_DEAUTH >> 4) |
  315. BIT(IEEE80211_STYPE_PROBE_REQ >> 4),
  316. },
  317. [NL80211_IFTYPE_STATION] = {
  318. .tx = 0xffff,
  319. .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  320. BIT(IEEE80211_STYPE_PROBE_REQ >> 4),
  321. },
  322. [NL80211_IFTYPE_AP] = {
  323. .tx = 0xffff,
  324. .rx = BIT(IEEE80211_STYPE_ASSOC_REQ >> 4) |
  325. BIT(IEEE80211_STYPE_REASSOC_REQ >> 4) |
  326. BIT(IEEE80211_STYPE_PROBE_REQ >> 4) |
  327. BIT(IEEE80211_STYPE_DISASSOC >> 4) |
  328. BIT(IEEE80211_STYPE_AUTH >> 4) |
  329. BIT(IEEE80211_STYPE_DEAUTH >> 4) |
  330. BIT(IEEE80211_STYPE_ACTION >> 4),
  331. },
  332. [NL80211_IFTYPE_AP_VLAN] = {
  333. /* copy AP */
  334. .tx = 0xffff,
  335. .rx = BIT(IEEE80211_STYPE_ASSOC_REQ >> 4) |
  336. BIT(IEEE80211_STYPE_REASSOC_REQ >> 4) |
  337. BIT(IEEE80211_STYPE_PROBE_REQ >> 4) |
  338. BIT(IEEE80211_STYPE_DISASSOC >> 4) |
  339. BIT(IEEE80211_STYPE_AUTH >> 4) |
  340. BIT(IEEE80211_STYPE_DEAUTH >> 4) |
  341. BIT(IEEE80211_STYPE_ACTION >> 4),
  342. },
  343. [NL80211_IFTYPE_P2P_CLIENT] = {
  344. .tx = 0xffff,
  345. .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  346. BIT(IEEE80211_STYPE_PROBE_REQ >> 4),
  347. },
  348. [NL80211_IFTYPE_P2P_GO] = {
  349. .tx = 0xffff,
  350. .rx = BIT(IEEE80211_STYPE_ASSOC_REQ >> 4) |
  351. BIT(IEEE80211_STYPE_REASSOC_REQ >> 4) |
  352. BIT(IEEE80211_STYPE_PROBE_REQ >> 4) |
  353. BIT(IEEE80211_STYPE_DISASSOC >> 4) |
  354. BIT(IEEE80211_STYPE_AUTH >> 4) |
  355. BIT(IEEE80211_STYPE_DEAUTH >> 4) |
  356. BIT(IEEE80211_STYPE_ACTION >> 4),
  357. },
  358. [NL80211_IFTYPE_MESH_POINT] = {
  359. .tx = 0xffff,
  360. .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  361. BIT(IEEE80211_STYPE_AUTH >> 4) |
  362. BIT(IEEE80211_STYPE_DEAUTH >> 4),
  363. },
  364. [NL80211_IFTYPE_P2P_DEVICE] = {
  365. .tx = 0xffff,
  366. .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  367. BIT(IEEE80211_STYPE_PROBE_REQ >> 4),
  368. },
  369. };
  370. static const struct ieee80211_ht_cap mac80211_ht_capa_mod_mask = {
  371. .ampdu_params_info = IEEE80211_HT_AMPDU_PARM_FACTOR |
  372. IEEE80211_HT_AMPDU_PARM_DENSITY,
  373. .cap_info = cpu_to_le16(IEEE80211_HT_CAP_SUP_WIDTH_20_40 |
  374. IEEE80211_HT_CAP_MAX_AMSDU |
  375. IEEE80211_HT_CAP_SGI_20 |
  376. IEEE80211_HT_CAP_SGI_40 |
  377. IEEE80211_HT_CAP_LDPC_CODING |
  378. IEEE80211_HT_CAP_40MHZ_INTOLERANT),
  379. .mcs = {
  380. .rx_mask = { 0xff, 0xff, 0xff, 0xff, 0xff,
  381. 0xff, 0xff, 0xff, 0xff, 0xff, },
  382. },
  383. };
  384. static const struct ieee80211_vht_cap mac80211_vht_capa_mod_mask = {
  385. .vht_cap_info =
  386. cpu_to_le32(IEEE80211_VHT_CAP_RXLDPC |
  387. IEEE80211_VHT_CAP_SHORT_GI_80 |
  388. IEEE80211_VHT_CAP_SHORT_GI_160 |
  389. IEEE80211_VHT_CAP_RXSTBC_1 |
  390. IEEE80211_VHT_CAP_RXSTBC_2 |
  391. IEEE80211_VHT_CAP_RXSTBC_3 |
  392. IEEE80211_VHT_CAP_RXSTBC_4 |
  393. IEEE80211_VHT_CAP_TXSTBC |
  394. IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
  395. IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
  396. IEEE80211_VHT_CAP_TX_ANTENNA_PATTERN |
  397. IEEE80211_VHT_CAP_RX_ANTENNA_PATTERN |
  398. IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK),
  399. .supp_mcs = {
  400. .rx_mcs_map = cpu_to_le16(~0),
  401. .tx_mcs_map = cpu_to_le16(~0),
  402. },
  403. };
  404. struct ieee80211_hw *ieee80211_alloc_hw_nm(size_t priv_data_len,
  405. const struct ieee80211_ops *ops,
  406. const char *requested_name)
  407. {
  408. struct ieee80211_local *local;
  409. int priv_size, i;
  410. struct wiphy *wiphy;
  411. bool use_chanctx;
  412. if (WARN_ON(!ops->tx || !ops->start || !ops->stop || !ops->config ||
  413. !ops->add_interface || !ops->remove_interface ||
  414. !ops->configure_filter))
  415. return NULL;
  416. if (WARN_ON(ops->sta_state && (ops->sta_add || ops->sta_remove)))
  417. return NULL;
  418. /* check all or no channel context operations exist */
  419. i = !!ops->add_chanctx + !!ops->remove_chanctx +
  420. !!ops->change_chanctx + !!ops->assign_vif_chanctx +
  421. !!ops->unassign_vif_chanctx;
  422. if (WARN_ON(i != 0 && i != 5))
  423. return NULL;
  424. use_chanctx = i == 5;
  425. /* Ensure 32-byte alignment of our private data and hw private data.
  426. * We use the wiphy priv data for both our ieee80211_local and for
  427. * the driver's private data
  428. *
  429. * In memory it'll be like this:
  430. *
  431. * +-------------------------+
  432. * | struct wiphy |
  433. * +-------------------------+
  434. * | struct ieee80211_local |
  435. * +-------------------------+
  436. * | driver's private data |
  437. * +-------------------------+
  438. *
  439. */
  440. priv_size = ALIGN(sizeof(*local), NETDEV_ALIGN) + priv_data_len;
  441. wiphy = wiphy_new_nm(&mac80211_config_ops, priv_size, requested_name);
  442. if (!wiphy)
  443. return NULL;
  444. wiphy->mgmt_stypes = ieee80211_default_mgmt_stypes;
  445. wiphy->privid = mac80211_wiphy_privid;
  446. wiphy->flags |= WIPHY_FLAG_NETNS_OK |
  447. WIPHY_FLAG_4ADDR_AP |
  448. WIPHY_FLAG_4ADDR_STATION |
  449. WIPHY_FLAG_REPORTS_OBSS |
  450. WIPHY_FLAG_OFFCHAN_TX;
  451. if (ops->remain_on_channel)
  452. wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
  453. wiphy->features |= NL80211_FEATURE_SK_TX_STATUS |
  454. NL80211_FEATURE_SAE |
  455. NL80211_FEATURE_HT_IBSS |
  456. NL80211_FEATURE_VIF_TXPOWER |
  457. NL80211_FEATURE_MAC_ON_CREATE |
  458. NL80211_FEATURE_USERSPACE_MPM |
  459. NL80211_FEATURE_FULL_AP_CLIENT_STATE;
  460. if (!ops->hw_scan)
  461. wiphy->features |= NL80211_FEATURE_LOW_PRIORITY_SCAN |
  462. NL80211_FEATURE_AP_SCAN;
  463. if (!ops->set_key)
  464. wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
  465. wiphy->bss_priv_size = sizeof(struct ieee80211_bss);
  466. local = wiphy_priv(wiphy);
  467. if (sta_info_init(local))
  468. goto err_free;
  469. local->hw.wiphy = wiphy;
  470. local->hw.priv = (char *)local + ALIGN(sizeof(*local), NETDEV_ALIGN);
  471. local->ops = ops;
  472. local->use_chanctx = use_chanctx;
  473. /* set up some defaults */
  474. local->hw.queues = 1;
  475. local->hw.max_rates = 1;
  476. local->hw.max_report_rates = 0;
  477. local->hw.max_rx_aggregation_subframes = IEEE80211_MAX_AMPDU_BUF;
  478. local->hw.max_tx_aggregation_subframes = IEEE80211_MAX_AMPDU_BUF;
  479. local->hw.offchannel_tx_hw_queue = IEEE80211_INVAL_HW_QUEUE;
  480. local->hw.conf.long_frame_max_tx_count = wiphy->retry_long;
  481. local->hw.conf.short_frame_max_tx_count = wiphy->retry_short;
  482. local->hw.radiotap_mcs_details = IEEE80211_RADIOTAP_MCS_HAVE_MCS |
  483. IEEE80211_RADIOTAP_MCS_HAVE_GI |
  484. IEEE80211_RADIOTAP_MCS_HAVE_BW;
  485. local->hw.radiotap_vht_details = IEEE80211_RADIOTAP_VHT_KNOWN_GI |
  486. IEEE80211_RADIOTAP_VHT_KNOWN_BANDWIDTH;
  487. local->hw.uapsd_queues = IEEE80211_DEFAULT_UAPSD_QUEUES;
  488. local->hw.uapsd_max_sp_len = IEEE80211_DEFAULT_MAX_SP_LEN;
  489. local->user_power_level = IEEE80211_UNSET_POWER_LEVEL;
  490. wiphy->ht_capa_mod_mask = &mac80211_ht_capa_mod_mask;
  491. wiphy->vht_capa_mod_mask = &mac80211_vht_capa_mod_mask;
  492. local->ext_capa[7] = WLAN_EXT_CAPA8_OPMODE_NOTIF;
  493. wiphy->extended_capabilities = local->ext_capa;
  494. wiphy->extended_capabilities_mask = local->ext_capa;
  495. wiphy->extended_capabilities_len =
  496. ARRAY_SIZE(local->ext_capa);
  497. INIT_LIST_HEAD(&local->interfaces);
  498. __hw_addr_init(&local->mc_list);
  499. mutex_init(&local->iflist_mtx);
  500. mutex_init(&local->mtx);
  501. mutex_init(&local->key_mtx);
  502. spin_lock_init(&local->filter_lock);
  503. spin_lock_init(&local->rx_path_lock);
  504. spin_lock_init(&local->queue_stop_reason_lock);
  505. INIT_LIST_HEAD(&local->chanctx_list);
  506. mutex_init(&local->chanctx_mtx);
  507. INIT_DELAYED_WORK(&local->scan_work, ieee80211_scan_work);
  508. INIT_WORK(&local->restart_work, ieee80211_restart_work);
  509. INIT_WORK(&local->radar_detected_work,
  510. ieee80211_dfs_radar_detected_work);
  511. INIT_WORK(&local->reconfig_filter, ieee80211_reconfig_filter);
  512. local->smps_mode = IEEE80211_SMPS_OFF;
  513. INIT_WORK(&local->dynamic_ps_enable_work,
  514. ieee80211_dynamic_ps_enable_work);
  515. INIT_WORK(&local->dynamic_ps_disable_work,
  516. ieee80211_dynamic_ps_disable_work);
  517. setup_timer(&local->dynamic_ps_timer,
  518. ieee80211_dynamic_ps_timer, (unsigned long) local);
  519. INIT_WORK(&local->sched_scan_stopped_work,
  520. ieee80211_sched_scan_stopped_work);
  521. INIT_WORK(&local->tdls_chsw_work, ieee80211_tdls_chsw_work);
  522. spin_lock_init(&local->ack_status_lock);
  523. idr_init(&local->ack_status_frames);
  524. for (i = 0; i < IEEE80211_MAX_QUEUES; i++) {
  525. skb_queue_head_init(&local->pending[i]);
  526. atomic_set(&local->agg_queue_stop[i], 0);
  527. }
  528. tasklet_init(&local->tx_pending_tasklet, ieee80211_tx_pending,
  529. (unsigned long)local);
  530. tasklet_init(&local->tasklet,
  531. ieee80211_tasklet_handler,
  532. (unsigned long) local);
  533. skb_queue_head_init(&local->skb_queue);
  534. skb_queue_head_init(&local->skb_queue_unreliable);
  535. skb_queue_head_init(&local->skb_queue_tdls_chsw);
  536. ieee80211_alloc_led_names(local);
  537. ieee80211_roc_setup(local);
  538. return &local->hw;
  539. err_free:
  540. wiphy_free(wiphy);
  541. return NULL;
  542. }
  543. EXPORT_SYMBOL(ieee80211_alloc_hw_nm);
  544. static int ieee80211_init_cipher_suites(struct ieee80211_local *local)
  545. {
  546. bool have_wep = !(IS_ERR(local->wep_tx_tfm) ||
  547. IS_ERR(local->wep_rx_tfm));
  548. bool have_mfp = ieee80211_hw_check(&local->hw, MFP_CAPABLE);
  549. int n_suites = 0, r = 0, w = 0;
  550. u32 *suites;
  551. static const u32 cipher_suites[] = {
  552. /* keep WEP first, it may be removed below */
  553. WLAN_CIPHER_SUITE_WEP40,
  554. WLAN_CIPHER_SUITE_WEP104,
  555. WLAN_CIPHER_SUITE_TKIP,
  556. WLAN_CIPHER_SUITE_CCMP,
  557. WLAN_CIPHER_SUITE_CCMP_256,
  558. WLAN_CIPHER_SUITE_GCMP,
  559. WLAN_CIPHER_SUITE_GCMP_256,
  560. /* keep last -- depends on hw flags! */
  561. WLAN_CIPHER_SUITE_AES_CMAC,
  562. WLAN_CIPHER_SUITE_BIP_CMAC_256,
  563. WLAN_CIPHER_SUITE_BIP_GMAC_128,
  564. WLAN_CIPHER_SUITE_BIP_GMAC_256,
  565. };
  566. if (ieee80211_hw_check(&local->hw, SW_CRYPTO_CONTROL) ||
  567. local->hw.wiphy->cipher_suites) {
  568. /* If the driver advertises, or doesn't support SW crypto,
  569. * we only need to remove WEP if necessary.
  570. */
  571. if (have_wep)
  572. return 0;
  573. /* well if it has _no_ ciphers ... fine */
  574. if (!local->hw.wiphy->n_cipher_suites)
  575. return 0;
  576. /* Driver provides cipher suites, but we need to exclude WEP */
  577. suites = kmemdup(local->hw.wiphy->cipher_suites,
  578. sizeof(u32) * local->hw.wiphy->n_cipher_suites,
  579. GFP_KERNEL);
  580. if (!suites)
  581. return -ENOMEM;
  582. for (r = 0; r < local->hw.wiphy->n_cipher_suites; r++) {
  583. u32 suite = local->hw.wiphy->cipher_suites[r];
  584. if (suite == WLAN_CIPHER_SUITE_WEP40 ||
  585. suite == WLAN_CIPHER_SUITE_WEP104)
  586. continue;
  587. suites[w++] = suite;
  588. }
  589. } else if (!local->hw.cipher_schemes) {
  590. /* If the driver doesn't have cipher schemes, there's nothing
  591. * else to do other than assign the (software supported and
  592. * perhaps offloaded) cipher suites.
  593. */
  594. local->hw.wiphy->cipher_suites = cipher_suites;
  595. local->hw.wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
  596. if (!have_mfp)
  597. local->hw.wiphy->n_cipher_suites -= 4;
  598. if (!have_wep) {
  599. local->hw.wiphy->cipher_suites += 2;
  600. local->hw.wiphy->n_cipher_suites -= 2;
  601. }
  602. /* not dynamically allocated, so just return */
  603. return 0;
  604. } else {
  605. const struct ieee80211_cipher_scheme *cs;
  606. cs = local->hw.cipher_schemes;
  607. /* Driver specifies cipher schemes only (but not cipher suites
  608. * including the schemes)
  609. *
  610. * We start counting ciphers defined by schemes, TKIP, CCMP,
  611. * CCMP-256, GCMP, and GCMP-256
  612. */
  613. n_suites = local->hw.n_cipher_schemes + 5;
  614. /* check if we have WEP40 and WEP104 */
  615. if (have_wep)
  616. n_suites += 2;
  617. /* check if we have AES_CMAC, BIP-CMAC-256, BIP-GMAC-128,
  618. * BIP-GMAC-256
  619. */
  620. if (have_mfp)
  621. n_suites += 4;
  622. suites = kmalloc(sizeof(u32) * n_suites, GFP_KERNEL);
  623. if (!suites)
  624. return -ENOMEM;
  625. suites[w++] = WLAN_CIPHER_SUITE_CCMP;
  626. suites[w++] = WLAN_CIPHER_SUITE_CCMP_256;
  627. suites[w++] = WLAN_CIPHER_SUITE_TKIP;
  628. suites[w++] = WLAN_CIPHER_SUITE_GCMP;
  629. suites[w++] = WLAN_CIPHER_SUITE_GCMP_256;
  630. if (have_wep) {
  631. suites[w++] = WLAN_CIPHER_SUITE_WEP40;
  632. suites[w++] = WLAN_CIPHER_SUITE_WEP104;
  633. }
  634. if (have_mfp) {
  635. suites[w++] = WLAN_CIPHER_SUITE_AES_CMAC;
  636. suites[w++] = WLAN_CIPHER_SUITE_BIP_CMAC_256;
  637. suites[w++] = WLAN_CIPHER_SUITE_BIP_GMAC_128;
  638. suites[w++] = WLAN_CIPHER_SUITE_BIP_GMAC_256;
  639. }
  640. for (r = 0; r < local->hw.n_cipher_schemes; r++) {
  641. suites[w++] = cs[r].cipher;
  642. if (WARN_ON(cs[r].pn_len > IEEE80211_MAX_PN_LEN)) {
  643. kfree(suites);
  644. return -EINVAL;
  645. }
  646. }
  647. }
  648. local->hw.wiphy->cipher_suites = suites;
  649. local->hw.wiphy->n_cipher_suites = w;
  650. local->wiphy_ciphers_allocated = true;
  651. return 0;
  652. }
  653. int ieee80211_register_hw(struct ieee80211_hw *hw)
  654. {
  655. struct ieee80211_local *local = hw_to_local(hw);
  656. int result, i;
  657. enum ieee80211_band band;
  658. int channels, max_bitrates;
  659. bool supp_ht, supp_vht;
  660. netdev_features_t feature_whitelist;
  661. struct cfg80211_chan_def dflt_chandef = {};
  662. if (ieee80211_hw_check(hw, QUEUE_CONTROL) &&
  663. (local->hw.offchannel_tx_hw_queue == IEEE80211_INVAL_HW_QUEUE ||
  664. local->hw.offchannel_tx_hw_queue >= local->hw.queues))
  665. return -EINVAL;
  666. if ((hw->wiphy->features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH) &&
  667. (!local->ops->tdls_channel_switch ||
  668. !local->ops->tdls_cancel_channel_switch ||
  669. !local->ops->tdls_recv_channel_switch))
  670. return -EOPNOTSUPP;
  671. #ifdef CONFIG_PM
  672. if (hw->wiphy->wowlan && (!local->ops->suspend || !local->ops->resume))
  673. return -EINVAL;
  674. #endif
  675. if (!local->use_chanctx) {
  676. for (i = 0; i < local->hw.wiphy->n_iface_combinations; i++) {
  677. const struct ieee80211_iface_combination *comb;
  678. comb = &local->hw.wiphy->iface_combinations[i];
  679. if (comb->num_different_channels > 1)
  680. return -EINVAL;
  681. }
  682. } else {
  683. /*
  684. * WDS is currently prohibited when channel contexts are used
  685. * because there's no clear definition of which channel WDS
  686. * type interfaces use
  687. */
  688. if (local->hw.wiphy->interface_modes & BIT(NL80211_IFTYPE_WDS))
  689. return -EINVAL;
  690. /* DFS is not supported with multi-channel combinations yet */
  691. for (i = 0; i < local->hw.wiphy->n_iface_combinations; i++) {
  692. const struct ieee80211_iface_combination *comb;
  693. comb = &local->hw.wiphy->iface_combinations[i];
  694. if (comb->radar_detect_widths &&
  695. comb->num_different_channels > 1)
  696. return -EINVAL;
  697. }
  698. }
  699. /* Only HW csum features are currently compatible with mac80211 */
  700. feature_whitelist = NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
  701. NETIF_F_HW_CSUM | NETIF_F_SG | NETIF_F_HIGHDMA |
  702. NETIF_F_GSO_SOFTWARE;
  703. if (WARN_ON(hw->netdev_features & ~feature_whitelist))
  704. return -EINVAL;
  705. if (hw->max_report_rates == 0)
  706. hw->max_report_rates = hw->max_rates;
  707. local->rx_chains = 1;
  708. /*
  709. * generic code guarantees at least one band,
  710. * set this very early because much code assumes
  711. * that hw.conf.channel is assigned
  712. */
  713. channels = 0;
  714. max_bitrates = 0;
  715. supp_ht = false;
  716. supp_vht = false;
  717. for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
  718. struct ieee80211_supported_band *sband;
  719. sband = local->hw.wiphy->bands[band];
  720. if (!sband)
  721. continue;
  722. if (!dflt_chandef.chan) {
  723. cfg80211_chandef_create(&dflt_chandef,
  724. &sband->channels[0],
  725. NL80211_CHAN_NO_HT);
  726. /* init channel we're on */
  727. if (!local->use_chanctx && !local->_oper_chandef.chan) {
  728. local->hw.conf.chandef = dflt_chandef;
  729. local->_oper_chandef = dflt_chandef;
  730. }
  731. local->monitor_chandef = dflt_chandef;
  732. }
  733. channels += sband->n_channels;
  734. if (max_bitrates < sband->n_bitrates)
  735. max_bitrates = sband->n_bitrates;
  736. supp_ht = supp_ht || sband->ht_cap.ht_supported;
  737. supp_vht = supp_vht || sband->vht_cap.vht_supported;
  738. if (sband->ht_cap.ht_supported)
  739. local->rx_chains =
  740. max(ieee80211_mcs_to_chains(&sband->ht_cap.mcs),
  741. local->rx_chains);
  742. /* TODO: consider VHT for RX chains, hopefully it's the same */
  743. }
  744. /* if low-level driver supports AP, we also support VLAN */
  745. if (local->hw.wiphy->interface_modes & BIT(NL80211_IFTYPE_AP)) {
  746. hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_AP_VLAN);
  747. hw->wiphy->software_iftypes |= BIT(NL80211_IFTYPE_AP_VLAN);
  748. }
  749. /* mac80211 always supports monitor */
  750. hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_MONITOR);
  751. hw->wiphy->software_iftypes |= BIT(NL80211_IFTYPE_MONITOR);
  752. /* mac80211 doesn't support more than one IBSS interface right now */
  753. for (i = 0; i < hw->wiphy->n_iface_combinations; i++) {
  754. const struct ieee80211_iface_combination *c;
  755. int j;
  756. c = &hw->wiphy->iface_combinations[i];
  757. for (j = 0; j < c->n_limits; j++)
  758. if ((c->limits[j].types & BIT(NL80211_IFTYPE_ADHOC)) &&
  759. c->limits[j].max > 1)
  760. return -EINVAL;
  761. }
  762. local->int_scan_req = kzalloc(sizeof(*local->int_scan_req) +
  763. sizeof(void *) * channels, GFP_KERNEL);
  764. if (!local->int_scan_req)
  765. return -ENOMEM;
  766. for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
  767. if (!local->hw.wiphy->bands[band])
  768. continue;
  769. local->int_scan_req->rates[band] = (u32) -1;
  770. }
  771. #ifndef CONFIG_MAC80211_MESH
  772. /* mesh depends on Kconfig, but drivers should set it if they want */
  773. local->hw.wiphy->interface_modes &= ~BIT(NL80211_IFTYPE_MESH_POINT);
  774. #endif
  775. /* if the underlying driver supports mesh, mac80211 will (at least)
  776. * provide routing of mesh authentication frames to userspace */
  777. if (local->hw.wiphy->interface_modes & BIT(NL80211_IFTYPE_MESH_POINT))
  778. local->hw.wiphy->flags |= WIPHY_FLAG_MESH_AUTH;
  779. /* mac80211 supports control port protocol changing */
  780. local->hw.wiphy->flags |= WIPHY_FLAG_CONTROL_PORT_PROTOCOL;
  781. if (ieee80211_hw_check(&local->hw, SIGNAL_DBM)) {
  782. local->hw.wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
  783. } else if (ieee80211_hw_check(&local->hw, SIGNAL_UNSPEC)) {
  784. local->hw.wiphy->signal_type = CFG80211_SIGNAL_TYPE_UNSPEC;
  785. if (hw->max_signal <= 0) {
  786. result = -EINVAL;
  787. goto fail_wiphy_register;
  788. }
  789. }
  790. /*
  791. * Calculate scan IE length -- we need this to alloc
  792. * memory and to subtract from the driver limit. It
  793. * includes the DS Params, (extended) supported rates, and HT
  794. * information -- SSID is the driver's responsibility.
  795. */
  796. local->scan_ies_len = 4 + max_bitrates /* (ext) supp rates */ +
  797. 3 /* DS Params */;
  798. if (supp_ht)
  799. local->scan_ies_len += 2 + sizeof(struct ieee80211_ht_cap);
  800. if (supp_vht)
  801. local->scan_ies_len +=
  802. 2 + sizeof(struct ieee80211_vht_cap);
  803. if (!local->ops->hw_scan) {
  804. /* For hw_scan, driver needs to set these up. */
  805. local->hw.wiphy->max_scan_ssids = 4;
  806. local->hw.wiphy->max_scan_ie_len = IEEE80211_MAX_DATA_LEN;
  807. }
  808. /*
  809. * If the driver supports any scan IEs, then assume the
  810. * limit includes the IEs mac80211 will add, otherwise
  811. * leave it at zero and let the driver sort it out; we
  812. * still pass our IEs to the driver but userspace will
  813. * not be allowed to in that case.
  814. */
  815. if (local->hw.wiphy->max_scan_ie_len)
  816. local->hw.wiphy->max_scan_ie_len -= local->scan_ies_len;
  817. WARN_ON(!ieee80211_cs_list_valid(local->hw.cipher_schemes,
  818. local->hw.n_cipher_schemes));
  819. result = ieee80211_init_cipher_suites(local);
  820. if (result < 0)
  821. goto fail_wiphy_register;
  822. if (!local->ops->remain_on_channel)
  823. local->hw.wiphy->max_remain_on_channel_duration = 5000;
  824. /* mac80211 based drivers don't support internal TDLS setup */
  825. if (local->hw.wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS)
  826. local->hw.wiphy->flags |= WIPHY_FLAG_TDLS_EXTERNAL_SETUP;
  827. /* mac80211 supports eCSA, if the driver supports STA CSA at all */
  828. if (ieee80211_hw_check(&local->hw, CHANCTX_STA_CSA))
  829. local->ext_capa[0] |= WLAN_EXT_CAPA1_EXT_CHANNEL_SWITCHING;
  830. local->hw.wiphy->max_num_csa_counters = IEEE80211_MAX_CSA_COUNTERS_NUM;
  831. result = wiphy_register(local->hw.wiphy);
  832. if (result < 0)
  833. goto fail_wiphy_register;
  834. /*
  835. * We use the number of queues for feature tests (QoS, HT) internally
  836. * so restrict them appropriately.
  837. */
  838. if (hw->queues > IEEE80211_MAX_QUEUES)
  839. hw->queues = IEEE80211_MAX_QUEUES;
  840. local->workqueue =
  841. alloc_ordered_workqueue("%s", 0, wiphy_name(local->hw.wiphy));
  842. if (!local->workqueue) {
  843. result = -ENOMEM;
  844. goto fail_workqueue;
  845. }
  846. /*
  847. * The hardware needs headroom for sending the frame,
  848. * and we need some headroom for passing the frame to monitor
  849. * interfaces, but never both at the same time.
  850. */
  851. local->tx_headroom = max_t(unsigned int , local->hw.extra_tx_headroom,
  852. IEEE80211_TX_STATUS_HEADROOM);
  853. debugfs_hw_add(local);
  854. /*
  855. * if the driver doesn't specify a max listen interval we
  856. * use 5 which should be a safe default
  857. */
  858. if (local->hw.max_listen_interval == 0)
  859. local->hw.max_listen_interval = 5;
  860. local->hw.conf.listen_interval = local->hw.max_listen_interval;
  861. local->dynamic_ps_forced_timeout = -1;
  862. if (!local->hw.txq_ac_max_pending)
  863. local->hw.txq_ac_max_pending = 64;
  864. result = ieee80211_wep_init(local);
  865. if (result < 0)
  866. wiphy_debug(local->hw.wiphy, "Failed to initialize wep: %d\n",
  867. result);
  868. local->hw.conf.flags = IEEE80211_CONF_IDLE;
  869. ieee80211_led_init(local);
  870. rtnl_lock();
  871. result = ieee80211_init_rate_ctrl_alg(local,
  872. hw->rate_control_algorithm);
  873. if (result < 0) {
  874. wiphy_debug(local->hw.wiphy,
  875. "Failed to initialize rate control algorithm\n");
  876. goto fail_rate;
  877. }
  878. /* add one default STA interface if supported */
  879. if (local->hw.wiphy->interface_modes & BIT(NL80211_IFTYPE_STATION) &&
  880. !ieee80211_hw_check(hw, NO_AUTO_VIF)) {
  881. result = ieee80211_if_add(local, "wlan%d", NET_NAME_ENUM, NULL,
  882. NL80211_IFTYPE_STATION, NULL);
  883. if (result)
  884. wiphy_warn(local->hw.wiphy,
  885. "Failed to add default virtual iface\n");
  886. }
  887. rtnl_unlock();
  888. #ifdef CONFIG_INET
  889. local->ifa_notifier.notifier_call = ieee80211_ifa_changed;
  890. result = register_inetaddr_notifier(&local->ifa_notifier);
  891. if (result)
  892. goto fail_ifa;
  893. #endif
  894. #if IS_ENABLED(CONFIG_IPV6)
  895. local->ifa6_notifier.notifier_call = ieee80211_ifa6_changed;
  896. result = register_inet6addr_notifier(&local->ifa6_notifier);
  897. if (result)
  898. goto fail_ifa6;
  899. #endif
  900. return 0;
  901. #if IS_ENABLED(CONFIG_IPV6)
  902. fail_ifa6:
  903. #ifdef CONFIG_INET
  904. unregister_inetaddr_notifier(&local->ifa_notifier);
  905. #endif
  906. #endif
  907. #if defined(CONFIG_INET) || defined(CONFIG_IPV6)
  908. fail_ifa:
  909. #endif
  910. rtnl_lock();
  911. rate_control_deinitialize(local);
  912. ieee80211_remove_interfaces(local);
  913. fail_rate:
  914. rtnl_unlock();
  915. ieee80211_led_exit(local);
  916. ieee80211_wep_free(local);
  917. destroy_workqueue(local->workqueue);
  918. fail_workqueue:
  919. wiphy_unregister(local->hw.wiphy);
  920. fail_wiphy_register:
  921. if (local->wiphy_ciphers_allocated)
  922. kfree(local->hw.wiphy->cipher_suites);
  923. kfree(local->int_scan_req);
  924. return result;
  925. }
  926. EXPORT_SYMBOL(ieee80211_register_hw);
  927. void ieee80211_unregister_hw(struct ieee80211_hw *hw)
  928. {
  929. struct ieee80211_local *local = hw_to_local(hw);
  930. tasklet_kill(&local->tx_pending_tasklet);
  931. tasklet_kill(&local->tasklet);
  932. #ifdef CONFIG_INET
  933. unregister_inetaddr_notifier(&local->ifa_notifier);
  934. #endif
  935. #if IS_ENABLED(CONFIG_IPV6)
  936. unregister_inet6addr_notifier(&local->ifa6_notifier);
  937. #endif
  938. rtnl_lock();
  939. /*
  940. * At this point, interface list manipulations are fine
  941. * because the driver cannot be handing us frames any
  942. * more and the tasklet is killed.
  943. */
  944. ieee80211_remove_interfaces(local);
  945. rtnl_unlock();
  946. cancel_delayed_work_sync(&local->roc_work);
  947. cancel_work_sync(&local->restart_work);
  948. cancel_work_sync(&local->reconfig_filter);
  949. cancel_work_sync(&local->tdls_chsw_work);
  950. flush_work(&local->sched_scan_stopped_work);
  951. ieee80211_clear_tx_pending(local);
  952. rate_control_deinitialize(local);
  953. if (skb_queue_len(&local->skb_queue) ||
  954. skb_queue_len(&local->skb_queue_unreliable))
  955. wiphy_warn(local->hw.wiphy, "skb_queue not empty\n");
  956. skb_queue_purge(&local->skb_queue);
  957. skb_queue_purge(&local->skb_queue_unreliable);
  958. skb_queue_purge(&local->skb_queue_tdls_chsw);
  959. destroy_workqueue(local->workqueue);
  960. wiphy_unregister(local->hw.wiphy);
  961. ieee80211_wep_free(local);
  962. ieee80211_led_exit(local);
  963. kfree(local->int_scan_req);
  964. }
  965. EXPORT_SYMBOL(ieee80211_unregister_hw);
  966. static int ieee80211_free_ack_frame(int id, void *p, void *data)
  967. {
  968. WARN_ONCE(1, "Have pending ack frames!\n");
  969. kfree_skb(p);
  970. return 0;
  971. }
  972. void ieee80211_free_hw(struct ieee80211_hw *hw)
  973. {
  974. struct ieee80211_local *local = hw_to_local(hw);
  975. mutex_destroy(&local->iflist_mtx);
  976. mutex_destroy(&local->mtx);
  977. if (local->wiphy_ciphers_allocated)
  978. kfree(local->hw.wiphy->cipher_suites);
  979. idr_for_each(&local->ack_status_frames,
  980. ieee80211_free_ack_frame, NULL);
  981. idr_destroy(&local->ack_status_frames);
  982. sta_info_stop(local);
  983. ieee80211_free_led_names(local);
  984. wiphy_free(local->hw.wiphy);
  985. }
  986. EXPORT_SYMBOL(ieee80211_free_hw);
  987. static int __init ieee80211_init(void)
  988. {
  989. struct sk_buff *skb;
  990. int ret;
  991. BUILD_BUG_ON(sizeof(struct ieee80211_tx_info) > sizeof(skb->cb));
  992. BUILD_BUG_ON(offsetof(struct ieee80211_tx_info, driver_data) +
  993. IEEE80211_TX_INFO_DRIVER_DATA_SIZE > sizeof(skb->cb));
  994. ret = rc80211_minstrel_init();
  995. if (ret)
  996. return ret;
  997. ret = rc80211_minstrel_ht_init();
  998. if (ret)
  999. goto err_minstrel;
  1000. ret = ieee80211_iface_init();
  1001. if (ret)
  1002. goto err_netdev;
  1003. return 0;
  1004. err_netdev:
  1005. rc80211_minstrel_ht_exit();
  1006. err_minstrel:
  1007. rc80211_minstrel_exit();
  1008. return ret;
  1009. }
  1010. static void __exit ieee80211_exit(void)
  1011. {
  1012. rc80211_minstrel_ht_exit();
  1013. rc80211_minstrel_exit();
  1014. ieee80211s_stop();
  1015. ieee80211_iface_exit();
  1016. rcu_barrier();
  1017. }
  1018. subsys_initcall(ieee80211_init);
  1019. module_exit(ieee80211_exit);
  1020. MODULE_DESCRIPTION("IEEE 802.11 subsystem");
  1021. MODULE_LICENSE("GPL");