main.c 39 KB

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