main.c 37 KB

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