main.c 35 KB

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