main.c 34 KB

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