main.c 34 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258
  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->bss_priv_size = sizeof(struct ieee80211_bss);
  470. local = wiphy_priv(wiphy);
  471. if (sta_info_init(local))
  472. goto err_free;
  473. local->hw.wiphy = wiphy;
  474. local->hw.priv = (char *)local + ALIGN(sizeof(*local), NETDEV_ALIGN);
  475. local->ops = ops;
  476. local->use_chanctx = use_chanctx;
  477. /* set up some defaults */
  478. local->hw.queues = 1;
  479. local->hw.max_rates = 1;
  480. local->hw.max_report_rates = 0;
  481. local->hw.max_rx_aggregation_subframes = IEEE80211_MAX_AMPDU_BUF;
  482. local->hw.max_tx_aggregation_subframes = IEEE80211_MAX_AMPDU_BUF;
  483. local->hw.offchannel_tx_hw_queue = IEEE80211_INVAL_HW_QUEUE;
  484. local->hw.conf.long_frame_max_tx_count = wiphy->retry_long;
  485. local->hw.conf.short_frame_max_tx_count = wiphy->retry_short;
  486. local->hw.radiotap_mcs_details = IEEE80211_RADIOTAP_MCS_HAVE_MCS |
  487. IEEE80211_RADIOTAP_MCS_HAVE_GI |
  488. IEEE80211_RADIOTAP_MCS_HAVE_BW;
  489. local->hw.radiotap_vht_details = IEEE80211_RADIOTAP_VHT_KNOWN_GI |
  490. IEEE80211_RADIOTAP_VHT_KNOWN_BANDWIDTH;
  491. local->hw.uapsd_queues = IEEE80211_DEFAULT_UAPSD_QUEUES;
  492. local->hw.uapsd_max_sp_len = IEEE80211_DEFAULT_MAX_SP_LEN;
  493. local->user_power_level = IEEE80211_UNSET_POWER_LEVEL;
  494. wiphy->ht_capa_mod_mask = &mac80211_ht_capa_mod_mask;
  495. wiphy->vht_capa_mod_mask = &mac80211_vht_capa_mod_mask;
  496. local->ext_capa[7] = WLAN_EXT_CAPA8_OPMODE_NOTIF;
  497. wiphy->extended_capabilities = local->ext_capa;
  498. wiphy->extended_capabilities_mask = local->ext_capa;
  499. wiphy->extended_capabilities_len =
  500. ARRAY_SIZE(local->ext_capa);
  501. INIT_LIST_HEAD(&local->interfaces);
  502. __hw_addr_init(&local->mc_list);
  503. mutex_init(&local->iflist_mtx);
  504. mutex_init(&local->mtx);
  505. mutex_init(&local->key_mtx);
  506. spin_lock_init(&local->filter_lock);
  507. spin_lock_init(&local->rx_path_lock);
  508. spin_lock_init(&local->queue_stop_reason_lock);
  509. INIT_LIST_HEAD(&local->chanctx_list);
  510. mutex_init(&local->chanctx_mtx);
  511. INIT_DELAYED_WORK(&local->scan_work, ieee80211_scan_work);
  512. INIT_WORK(&local->restart_work, ieee80211_restart_work);
  513. INIT_WORK(&local->radar_detected_work,
  514. ieee80211_dfs_radar_detected_work);
  515. INIT_WORK(&local->reconfig_filter, ieee80211_reconfig_filter);
  516. local->smps_mode = IEEE80211_SMPS_OFF;
  517. INIT_WORK(&local->dynamic_ps_enable_work,
  518. ieee80211_dynamic_ps_enable_work);
  519. INIT_WORK(&local->dynamic_ps_disable_work,
  520. ieee80211_dynamic_ps_disable_work);
  521. setup_timer(&local->dynamic_ps_timer,
  522. ieee80211_dynamic_ps_timer, (unsigned long) local);
  523. INIT_WORK(&local->sched_scan_stopped_work,
  524. ieee80211_sched_scan_stopped_work);
  525. INIT_WORK(&local->tdls_chsw_work, ieee80211_tdls_chsw_work);
  526. spin_lock_init(&local->ack_status_lock);
  527. idr_init(&local->ack_status_frames);
  528. for (i = 0; i < IEEE80211_MAX_QUEUES; i++) {
  529. skb_queue_head_init(&local->pending[i]);
  530. atomic_set(&local->agg_queue_stop[i], 0);
  531. }
  532. tasklet_init(&local->tx_pending_tasklet, ieee80211_tx_pending,
  533. (unsigned long)local);
  534. tasklet_init(&local->tasklet,
  535. ieee80211_tasklet_handler,
  536. (unsigned long) local);
  537. skb_queue_head_init(&local->skb_queue);
  538. skb_queue_head_init(&local->skb_queue_unreliable);
  539. skb_queue_head_init(&local->skb_queue_tdls_chsw);
  540. ieee80211_alloc_led_names(local);
  541. ieee80211_roc_setup(local);
  542. return &local->hw;
  543. err_free:
  544. wiphy_free(wiphy);
  545. return NULL;
  546. }
  547. EXPORT_SYMBOL(ieee80211_alloc_hw_nm);
  548. static int ieee80211_init_cipher_suites(struct ieee80211_local *local)
  549. {
  550. bool have_wep = !(IS_ERR(local->wep_tx_tfm) ||
  551. IS_ERR(local->wep_rx_tfm));
  552. bool have_mfp = ieee80211_hw_check(&local->hw, MFP_CAPABLE);
  553. int n_suites = 0, r = 0, w = 0;
  554. u32 *suites;
  555. static const u32 cipher_suites[] = {
  556. /* keep WEP first, it may be removed below */
  557. WLAN_CIPHER_SUITE_WEP40,
  558. WLAN_CIPHER_SUITE_WEP104,
  559. WLAN_CIPHER_SUITE_TKIP,
  560. WLAN_CIPHER_SUITE_CCMP,
  561. WLAN_CIPHER_SUITE_CCMP_256,
  562. WLAN_CIPHER_SUITE_GCMP,
  563. WLAN_CIPHER_SUITE_GCMP_256,
  564. /* keep last -- depends on hw flags! */
  565. WLAN_CIPHER_SUITE_AES_CMAC,
  566. WLAN_CIPHER_SUITE_BIP_CMAC_256,
  567. WLAN_CIPHER_SUITE_BIP_GMAC_128,
  568. WLAN_CIPHER_SUITE_BIP_GMAC_256,
  569. };
  570. if (ieee80211_hw_check(&local->hw, SW_CRYPTO_CONTROL) ||
  571. local->hw.wiphy->cipher_suites) {
  572. /* If the driver advertises, or doesn't support SW crypto,
  573. * we only need to remove WEP if necessary.
  574. */
  575. if (have_wep)
  576. return 0;
  577. /* well if it has _no_ ciphers ... fine */
  578. if (!local->hw.wiphy->n_cipher_suites)
  579. return 0;
  580. /* Driver provides cipher suites, but we need to exclude WEP */
  581. suites = kmemdup(local->hw.wiphy->cipher_suites,
  582. sizeof(u32) * local->hw.wiphy->n_cipher_suites,
  583. GFP_KERNEL);
  584. if (!suites)
  585. return -ENOMEM;
  586. for (r = 0; r < local->hw.wiphy->n_cipher_suites; r++) {
  587. u32 suite = local->hw.wiphy->cipher_suites[r];
  588. if (suite == WLAN_CIPHER_SUITE_WEP40 ||
  589. suite == WLAN_CIPHER_SUITE_WEP104)
  590. continue;
  591. suites[w++] = suite;
  592. }
  593. } else if (!local->hw.cipher_schemes) {
  594. /* If the driver doesn't have cipher schemes, there's nothing
  595. * else to do other than assign the (software supported and
  596. * perhaps offloaded) cipher suites.
  597. */
  598. local->hw.wiphy->cipher_suites = cipher_suites;
  599. local->hw.wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
  600. if (!have_mfp)
  601. local->hw.wiphy->n_cipher_suites -= 4;
  602. if (!have_wep) {
  603. local->hw.wiphy->cipher_suites += 2;
  604. local->hw.wiphy->n_cipher_suites -= 2;
  605. }
  606. /* not dynamically allocated, so just return */
  607. return 0;
  608. } else {
  609. const struct ieee80211_cipher_scheme *cs;
  610. cs = local->hw.cipher_schemes;
  611. /* Driver specifies cipher schemes only (but not cipher suites
  612. * including the schemes)
  613. *
  614. * We start counting ciphers defined by schemes, TKIP, CCMP,
  615. * CCMP-256, GCMP, and GCMP-256
  616. */
  617. n_suites = local->hw.n_cipher_schemes + 5;
  618. /* check if we have WEP40 and WEP104 */
  619. if (have_wep)
  620. n_suites += 2;
  621. /* check if we have AES_CMAC, BIP-CMAC-256, BIP-GMAC-128,
  622. * BIP-GMAC-256
  623. */
  624. if (have_mfp)
  625. n_suites += 4;
  626. suites = kmalloc(sizeof(u32) * n_suites, GFP_KERNEL);
  627. if (!suites)
  628. return -ENOMEM;
  629. suites[w++] = WLAN_CIPHER_SUITE_CCMP;
  630. suites[w++] = WLAN_CIPHER_SUITE_CCMP_256;
  631. suites[w++] = WLAN_CIPHER_SUITE_TKIP;
  632. suites[w++] = WLAN_CIPHER_SUITE_GCMP;
  633. suites[w++] = WLAN_CIPHER_SUITE_GCMP_256;
  634. if (have_wep) {
  635. suites[w++] = WLAN_CIPHER_SUITE_WEP40;
  636. suites[w++] = WLAN_CIPHER_SUITE_WEP104;
  637. }
  638. if (have_mfp) {
  639. suites[w++] = WLAN_CIPHER_SUITE_AES_CMAC;
  640. suites[w++] = WLAN_CIPHER_SUITE_BIP_CMAC_256;
  641. suites[w++] = WLAN_CIPHER_SUITE_BIP_GMAC_128;
  642. suites[w++] = WLAN_CIPHER_SUITE_BIP_GMAC_256;
  643. }
  644. for (r = 0; r < local->hw.n_cipher_schemes; r++) {
  645. suites[w++] = cs[r].cipher;
  646. if (WARN_ON(cs[r].pn_len > IEEE80211_MAX_PN_LEN)) {
  647. kfree(suites);
  648. return -EINVAL;
  649. }
  650. }
  651. }
  652. local->hw.wiphy->cipher_suites = suites;
  653. local->hw.wiphy->n_cipher_suites = w;
  654. local->wiphy_ciphers_allocated = true;
  655. return 0;
  656. }
  657. int ieee80211_register_hw(struct ieee80211_hw *hw)
  658. {
  659. struct ieee80211_local *local = hw_to_local(hw);
  660. int result, i;
  661. enum ieee80211_band band;
  662. int channels, max_bitrates;
  663. bool supp_ht, supp_vht;
  664. netdev_features_t feature_whitelist;
  665. struct cfg80211_chan_def dflt_chandef = {};
  666. if (ieee80211_hw_check(hw, QUEUE_CONTROL) &&
  667. (local->hw.offchannel_tx_hw_queue == IEEE80211_INVAL_HW_QUEUE ||
  668. local->hw.offchannel_tx_hw_queue >= local->hw.queues))
  669. return -EINVAL;
  670. if ((hw->wiphy->features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH) &&
  671. (!local->ops->tdls_channel_switch ||
  672. !local->ops->tdls_cancel_channel_switch ||
  673. !local->ops->tdls_recv_channel_switch))
  674. return -EOPNOTSUPP;
  675. #ifdef CONFIG_PM
  676. if (hw->wiphy->wowlan && (!local->ops->suspend || !local->ops->resume))
  677. return -EINVAL;
  678. #endif
  679. if (!local->use_chanctx) {
  680. for (i = 0; i < local->hw.wiphy->n_iface_combinations; i++) {
  681. const struct ieee80211_iface_combination *comb;
  682. comb = &local->hw.wiphy->iface_combinations[i];
  683. if (comb->num_different_channels > 1)
  684. return -EINVAL;
  685. }
  686. } else {
  687. /*
  688. * WDS is currently prohibited when channel contexts are used
  689. * because there's no clear definition of which channel WDS
  690. * type interfaces use
  691. */
  692. if (local->hw.wiphy->interface_modes & BIT(NL80211_IFTYPE_WDS))
  693. return -EINVAL;
  694. /* DFS is not supported with multi-channel combinations yet */
  695. for (i = 0; i < local->hw.wiphy->n_iface_combinations; i++) {
  696. const struct ieee80211_iface_combination *comb;
  697. comb = &local->hw.wiphy->iface_combinations[i];
  698. if (comb->radar_detect_widths &&
  699. comb->num_different_channels > 1)
  700. return -EINVAL;
  701. }
  702. }
  703. /* Only HW csum features are currently compatible with mac80211 */
  704. feature_whitelist = NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
  705. NETIF_F_HW_CSUM | NETIF_F_SG | NETIF_F_HIGHDMA |
  706. NETIF_F_GSO_SOFTWARE;
  707. if (WARN_ON(hw->netdev_features & ~feature_whitelist))
  708. return -EINVAL;
  709. if (hw->max_report_rates == 0)
  710. hw->max_report_rates = hw->max_rates;
  711. local->rx_chains = 1;
  712. /*
  713. * generic code guarantees at least one band,
  714. * set this very early because much code assumes
  715. * that hw.conf.channel is assigned
  716. */
  717. channels = 0;
  718. max_bitrates = 0;
  719. supp_ht = false;
  720. supp_vht = false;
  721. for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
  722. struct ieee80211_supported_band *sband;
  723. sband = local->hw.wiphy->bands[band];
  724. if (!sband)
  725. continue;
  726. if (!dflt_chandef.chan) {
  727. cfg80211_chandef_create(&dflt_chandef,
  728. &sband->channels[0],
  729. NL80211_CHAN_NO_HT);
  730. /* init channel we're on */
  731. if (!local->use_chanctx && !local->_oper_chandef.chan) {
  732. local->hw.conf.chandef = dflt_chandef;
  733. local->_oper_chandef = dflt_chandef;
  734. }
  735. local->monitor_chandef = dflt_chandef;
  736. }
  737. channels += sband->n_channels;
  738. if (max_bitrates < sband->n_bitrates)
  739. max_bitrates = sband->n_bitrates;
  740. supp_ht = supp_ht || sband->ht_cap.ht_supported;
  741. supp_vht = supp_vht || sband->vht_cap.vht_supported;
  742. if (sband->ht_cap.ht_supported)
  743. local->rx_chains =
  744. max(ieee80211_mcs_to_chains(&sband->ht_cap.mcs),
  745. local->rx_chains);
  746. /* TODO: consider VHT for RX chains, hopefully it's the same */
  747. }
  748. /* if low-level driver supports AP, we also support VLAN */
  749. if (local->hw.wiphy->interface_modes & BIT(NL80211_IFTYPE_AP)) {
  750. hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_AP_VLAN);
  751. hw->wiphy->software_iftypes |= BIT(NL80211_IFTYPE_AP_VLAN);
  752. }
  753. /* mac80211 always supports monitor */
  754. hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_MONITOR);
  755. hw->wiphy->software_iftypes |= BIT(NL80211_IFTYPE_MONITOR);
  756. /* mac80211 doesn't support more than one IBSS interface right now */
  757. for (i = 0; i < hw->wiphy->n_iface_combinations; i++) {
  758. const struct ieee80211_iface_combination *c;
  759. int j;
  760. c = &hw->wiphy->iface_combinations[i];
  761. for (j = 0; j < c->n_limits; j++)
  762. if ((c->limits[j].types & BIT(NL80211_IFTYPE_ADHOC)) &&
  763. c->limits[j].max > 1)
  764. return -EINVAL;
  765. }
  766. local->int_scan_req = kzalloc(sizeof(*local->int_scan_req) +
  767. sizeof(void *) * channels, GFP_KERNEL);
  768. if (!local->int_scan_req)
  769. return -ENOMEM;
  770. for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
  771. if (!local->hw.wiphy->bands[band])
  772. continue;
  773. local->int_scan_req->rates[band] = (u32) -1;
  774. }
  775. #ifndef CONFIG_MAC80211_MESH
  776. /* mesh depends on Kconfig, but drivers should set it if they want */
  777. local->hw.wiphy->interface_modes &= ~BIT(NL80211_IFTYPE_MESH_POINT);
  778. #endif
  779. /* if the underlying driver supports mesh, mac80211 will (at least)
  780. * provide routing of mesh authentication frames to userspace */
  781. if (local->hw.wiphy->interface_modes & BIT(NL80211_IFTYPE_MESH_POINT))
  782. local->hw.wiphy->flags |= WIPHY_FLAG_MESH_AUTH;
  783. /* mac80211 supports control port protocol changing */
  784. local->hw.wiphy->flags |= WIPHY_FLAG_CONTROL_PORT_PROTOCOL;
  785. if (ieee80211_hw_check(&local->hw, SIGNAL_DBM)) {
  786. local->hw.wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
  787. } else if (ieee80211_hw_check(&local->hw, SIGNAL_UNSPEC)) {
  788. local->hw.wiphy->signal_type = CFG80211_SIGNAL_TYPE_UNSPEC;
  789. if (hw->max_signal <= 0) {
  790. result = -EINVAL;
  791. goto fail_wiphy_register;
  792. }
  793. }
  794. /*
  795. * Calculate scan IE length -- we need this to alloc
  796. * memory and to subtract from the driver limit. It
  797. * includes the DS Params, (extended) supported rates, and HT
  798. * information -- SSID is the driver's responsibility.
  799. */
  800. local->scan_ies_len = 4 + max_bitrates /* (ext) supp rates */ +
  801. 3 /* DS Params */;
  802. if (supp_ht)
  803. local->scan_ies_len += 2 + sizeof(struct ieee80211_ht_cap);
  804. if (supp_vht)
  805. local->scan_ies_len +=
  806. 2 + sizeof(struct ieee80211_vht_cap);
  807. if (!local->ops->hw_scan) {
  808. /* For hw_scan, driver needs to set these up. */
  809. local->hw.wiphy->max_scan_ssids = 4;
  810. local->hw.wiphy->max_scan_ie_len = IEEE80211_MAX_DATA_LEN;
  811. }
  812. /*
  813. * If the driver supports any scan IEs, then assume the
  814. * limit includes the IEs mac80211 will add, otherwise
  815. * leave it at zero and let the driver sort it out; we
  816. * still pass our IEs to the driver but userspace will
  817. * not be allowed to in that case.
  818. */
  819. if (local->hw.wiphy->max_scan_ie_len)
  820. local->hw.wiphy->max_scan_ie_len -= local->scan_ies_len;
  821. WARN_ON(!ieee80211_cs_list_valid(local->hw.cipher_schemes,
  822. local->hw.n_cipher_schemes));
  823. result = ieee80211_init_cipher_suites(local);
  824. if (result < 0)
  825. goto fail_wiphy_register;
  826. if (!local->ops->remain_on_channel)
  827. local->hw.wiphy->max_remain_on_channel_duration = 5000;
  828. /* mac80211 based drivers don't support internal TDLS setup */
  829. if (local->hw.wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS)
  830. local->hw.wiphy->flags |= WIPHY_FLAG_TDLS_EXTERNAL_SETUP;
  831. /* mac80211 supports eCSA, if the driver supports STA CSA at all */
  832. if (ieee80211_hw_check(&local->hw, CHANCTX_STA_CSA))
  833. local->ext_capa[0] |= WLAN_EXT_CAPA1_EXT_CHANNEL_SWITCHING;
  834. local->hw.wiphy->max_num_csa_counters = IEEE80211_MAX_CSA_COUNTERS_NUM;
  835. result = wiphy_register(local->hw.wiphy);
  836. if (result < 0)
  837. goto fail_wiphy_register;
  838. /*
  839. * We use the number of queues for feature tests (QoS, HT) internally
  840. * so restrict them appropriately.
  841. */
  842. if (hw->queues > IEEE80211_MAX_QUEUES)
  843. hw->queues = IEEE80211_MAX_QUEUES;
  844. local->workqueue =
  845. alloc_ordered_workqueue("%s", 0, wiphy_name(local->hw.wiphy));
  846. if (!local->workqueue) {
  847. result = -ENOMEM;
  848. goto fail_workqueue;
  849. }
  850. /*
  851. * The hardware needs headroom for sending the frame,
  852. * and we need some headroom for passing the frame to monitor
  853. * interfaces, but never both at the same time.
  854. */
  855. local->tx_headroom = max_t(unsigned int , local->hw.extra_tx_headroom,
  856. IEEE80211_TX_STATUS_HEADROOM);
  857. debugfs_hw_add(local);
  858. /*
  859. * if the driver doesn't specify a max listen interval we
  860. * use 5 which should be a safe default
  861. */
  862. if (local->hw.max_listen_interval == 0)
  863. local->hw.max_listen_interval = 5;
  864. local->hw.conf.listen_interval = local->hw.max_listen_interval;
  865. local->dynamic_ps_forced_timeout = -1;
  866. if (!local->hw.txq_ac_max_pending)
  867. local->hw.txq_ac_max_pending = 64;
  868. result = ieee80211_wep_init(local);
  869. if (result < 0)
  870. wiphy_debug(local->hw.wiphy, "Failed to initialize wep: %d\n",
  871. result);
  872. local->hw.conf.flags = IEEE80211_CONF_IDLE;
  873. ieee80211_led_init(local);
  874. rtnl_lock();
  875. result = ieee80211_init_rate_ctrl_alg(local,
  876. hw->rate_control_algorithm);
  877. if (result < 0) {
  878. wiphy_debug(local->hw.wiphy,
  879. "Failed to initialize rate control algorithm\n");
  880. goto fail_rate;
  881. }
  882. /* add one default STA interface if supported */
  883. if (local->hw.wiphy->interface_modes & BIT(NL80211_IFTYPE_STATION) &&
  884. !ieee80211_hw_check(hw, NO_AUTO_VIF)) {
  885. result = ieee80211_if_add(local, "wlan%d", NET_NAME_ENUM, NULL,
  886. NL80211_IFTYPE_STATION, NULL);
  887. if (result)
  888. wiphy_warn(local->hw.wiphy,
  889. "Failed to add default virtual iface\n");
  890. }
  891. rtnl_unlock();
  892. #ifdef CONFIG_INET
  893. local->ifa_notifier.notifier_call = ieee80211_ifa_changed;
  894. result = register_inetaddr_notifier(&local->ifa_notifier);
  895. if (result)
  896. goto fail_ifa;
  897. #endif
  898. #if IS_ENABLED(CONFIG_IPV6)
  899. local->ifa6_notifier.notifier_call = ieee80211_ifa6_changed;
  900. result = register_inet6addr_notifier(&local->ifa6_notifier);
  901. if (result)
  902. goto fail_ifa6;
  903. #endif
  904. return 0;
  905. #if IS_ENABLED(CONFIG_IPV6)
  906. fail_ifa6:
  907. #ifdef CONFIG_INET
  908. unregister_inetaddr_notifier(&local->ifa_notifier);
  909. #endif
  910. #endif
  911. #if defined(CONFIG_INET) || defined(CONFIG_IPV6)
  912. fail_ifa:
  913. #endif
  914. rtnl_lock();
  915. rate_control_deinitialize(local);
  916. ieee80211_remove_interfaces(local);
  917. fail_rate:
  918. rtnl_unlock();
  919. ieee80211_led_exit(local);
  920. ieee80211_wep_free(local);
  921. destroy_workqueue(local->workqueue);
  922. fail_workqueue:
  923. wiphy_unregister(local->hw.wiphy);
  924. fail_wiphy_register:
  925. if (local->wiphy_ciphers_allocated)
  926. kfree(local->hw.wiphy->cipher_suites);
  927. kfree(local->int_scan_req);
  928. return result;
  929. }
  930. EXPORT_SYMBOL(ieee80211_register_hw);
  931. void ieee80211_unregister_hw(struct ieee80211_hw *hw)
  932. {
  933. struct ieee80211_local *local = hw_to_local(hw);
  934. tasklet_kill(&local->tx_pending_tasklet);
  935. tasklet_kill(&local->tasklet);
  936. #ifdef CONFIG_INET
  937. unregister_inetaddr_notifier(&local->ifa_notifier);
  938. #endif
  939. #if IS_ENABLED(CONFIG_IPV6)
  940. unregister_inet6addr_notifier(&local->ifa6_notifier);
  941. #endif
  942. rtnl_lock();
  943. /*
  944. * At this point, interface list manipulations are fine
  945. * because the driver cannot be handing us frames any
  946. * more and the tasklet is killed.
  947. */
  948. ieee80211_remove_interfaces(local);
  949. rtnl_unlock();
  950. cancel_delayed_work_sync(&local->roc_work);
  951. cancel_work_sync(&local->restart_work);
  952. cancel_work_sync(&local->reconfig_filter);
  953. cancel_work_sync(&local->tdls_chsw_work);
  954. flush_work(&local->sched_scan_stopped_work);
  955. ieee80211_clear_tx_pending(local);
  956. rate_control_deinitialize(local);
  957. if (skb_queue_len(&local->skb_queue) ||
  958. skb_queue_len(&local->skb_queue_unreliable))
  959. wiphy_warn(local->hw.wiphy, "skb_queue not empty\n");
  960. skb_queue_purge(&local->skb_queue);
  961. skb_queue_purge(&local->skb_queue_unreliable);
  962. skb_queue_purge(&local->skb_queue_tdls_chsw);
  963. destroy_workqueue(local->workqueue);
  964. wiphy_unregister(local->hw.wiphy);
  965. ieee80211_wep_free(local);
  966. ieee80211_led_exit(local);
  967. kfree(local->int_scan_req);
  968. }
  969. EXPORT_SYMBOL(ieee80211_unregister_hw);
  970. static int ieee80211_free_ack_frame(int id, void *p, void *data)
  971. {
  972. WARN_ONCE(1, "Have pending ack frames!\n");
  973. kfree_skb(p);
  974. return 0;
  975. }
  976. void ieee80211_free_hw(struct ieee80211_hw *hw)
  977. {
  978. struct ieee80211_local *local = hw_to_local(hw);
  979. mutex_destroy(&local->iflist_mtx);
  980. mutex_destroy(&local->mtx);
  981. if (local->wiphy_ciphers_allocated)
  982. kfree(local->hw.wiphy->cipher_suites);
  983. idr_for_each(&local->ack_status_frames,
  984. ieee80211_free_ack_frame, NULL);
  985. idr_destroy(&local->ack_status_frames);
  986. sta_info_stop(local);
  987. ieee80211_free_led_names(local);
  988. wiphy_free(local->hw.wiphy);
  989. }
  990. EXPORT_SYMBOL(ieee80211_free_hw);
  991. static int __init ieee80211_init(void)
  992. {
  993. struct sk_buff *skb;
  994. int ret;
  995. BUILD_BUG_ON(sizeof(struct ieee80211_tx_info) > sizeof(skb->cb));
  996. BUILD_BUG_ON(offsetof(struct ieee80211_tx_info, driver_data) +
  997. IEEE80211_TX_INFO_DRIVER_DATA_SIZE > sizeof(skb->cb));
  998. ret = rc80211_minstrel_init();
  999. if (ret)
  1000. return ret;
  1001. ret = rc80211_minstrel_ht_init();
  1002. if (ret)
  1003. goto err_minstrel;
  1004. ret = ieee80211_iface_init();
  1005. if (ret)
  1006. goto err_netdev;
  1007. return 0;
  1008. err_netdev:
  1009. rc80211_minstrel_ht_exit();
  1010. err_minstrel:
  1011. rc80211_minstrel_exit();
  1012. return ret;
  1013. }
  1014. static void __exit ieee80211_exit(void)
  1015. {
  1016. rc80211_minstrel_ht_exit();
  1017. rc80211_minstrel_exit();
  1018. ieee80211s_stop();
  1019. ieee80211_iface_exit();
  1020. rcu_barrier();
  1021. }
  1022. subsys_initcall(ieee80211_init);
  1023. module_exit(ieee80211_exit);
  1024. MODULE_DESCRIPTION("IEEE 802.11 subsystem");
  1025. MODULE_LICENSE("GPL");