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