main.c 36 KB

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