main.c 32 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208
  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. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. */
  10. #include <net/mac80211.h>
  11. #include <linux/module.h>
  12. #include <linux/init.h>
  13. #include <linux/netdevice.h>
  14. #include <linux/types.h>
  15. #include <linux/slab.h>
  16. #include <linux/skbuff.h>
  17. #include <linux/etherdevice.h>
  18. #include <linux/if_arp.h>
  19. #include <linux/rtnetlink.h>
  20. #include <linux/bitmap.h>
  21. #include <linux/pm_qos.h>
  22. #include <linux/inetdevice.h>
  23. #include <net/net_namespace.h>
  24. #include <net/cfg80211.h>
  25. #include <net/addrconf.h>
  26. #include "ieee80211_i.h"
  27. #include "driver-ops.h"
  28. #include "rate.h"
  29. #include "mesh.h"
  30. #include "wep.h"
  31. #include "led.h"
  32. #include "cfg.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_promiscs))
  40. new_flags |= FIF_PROMISC_IN_BSS;
  41. if (atomic_read(&local->iff_allmultis))
  42. new_flags |= FIF_ALLMULTI;
  43. if (local->monitors || test_bit(SCAN_SW_SCANNING, &local->scanning) ||
  44. test_bit(SCAN_ONCHANNEL_SCANNING, &local->scanning))
  45. new_flags |= FIF_BCN_PRBRESP_PROMISC;
  46. if (local->fif_probe_req || local->probe_req_reg)
  47. new_flags |= FIF_PROBE_REQ;
  48. if (local->fif_fcsfail)
  49. new_flags |= FIF_FCSFAIL;
  50. if (local->fif_plcpfail)
  51. new_flags |= FIF_PLCPFAIL;
  52. if (local->fif_control)
  53. new_flags |= FIF_CONTROL;
  54. if (local->fif_other_bss)
  55. new_flags |= FIF_OTHER_BSS;
  56. if (local->fif_pspoll)
  57. new_flags |= FIF_PSPOLL;
  58. spin_lock_bh(&local->filter_lock);
  59. changed_flags = local->filter_flags ^ new_flags;
  60. mc = drv_prepare_multicast(local, &local->mc_list);
  61. spin_unlock_bh(&local->filter_lock);
  62. /* be a bit nasty */
  63. new_flags |= (1<<31);
  64. drv_configure_filter(local, changed_flags, &new_flags, mc);
  65. WARN_ON(new_flags & (1<<31));
  66. local->filter_flags = new_flags & ~(1<<31);
  67. }
  68. static void ieee80211_reconfig_filter(struct work_struct *work)
  69. {
  70. struct ieee80211_local *local =
  71. container_of(work, struct ieee80211_local, reconfig_filter);
  72. ieee80211_configure_filter(local);
  73. }
  74. static u32 ieee80211_hw_conf_chan(struct ieee80211_local *local)
  75. {
  76. struct ieee80211_sub_if_data *sdata;
  77. struct cfg80211_chan_def chandef = {};
  78. u32 changed = 0;
  79. int power;
  80. u32 offchannel_flag;
  81. offchannel_flag = local->hw.conf.flags & IEEE80211_CONF_OFFCHANNEL;
  82. if (local->scan_chandef.chan) {
  83. chandef = local->scan_chandef;
  84. } else if (local->tmp_channel) {
  85. chandef.chan = local->tmp_channel;
  86. chandef.width = NL80211_CHAN_WIDTH_20_NOHT;
  87. chandef.center_freq1 = chandef.chan->center_freq;
  88. } else
  89. chandef = local->_oper_chandef;
  90. WARN(!cfg80211_chandef_valid(&chandef),
  91. "control:%d MHz width:%d center: %d/%d MHz",
  92. chandef.chan->center_freq, chandef.width,
  93. chandef.center_freq1, chandef.center_freq2);
  94. if (!cfg80211_chandef_identical(&chandef, &local->_oper_chandef))
  95. local->hw.conf.flags |= IEEE80211_CONF_OFFCHANNEL;
  96. else
  97. local->hw.conf.flags &= ~IEEE80211_CONF_OFFCHANNEL;
  98. offchannel_flag ^= local->hw.conf.flags & IEEE80211_CONF_OFFCHANNEL;
  99. if (offchannel_flag ||
  100. !cfg80211_chandef_identical(&local->hw.conf.chandef,
  101. &local->_oper_chandef)) {
  102. local->hw.conf.chandef = chandef;
  103. changed |= IEEE80211_CONF_CHANGE_CHANNEL;
  104. }
  105. if (!conf_is_ht(&local->hw.conf)) {
  106. /*
  107. * mac80211.h documents that this is only valid
  108. * when the channel is set to an HT type, and
  109. * that otherwise STATIC is used.
  110. */
  111. local->hw.conf.smps_mode = IEEE80211_SMPS_STATIC;
  112. } else if (local->hw.conf.smps_mode != local->smps_mode) {
  113. local->hw.conf.smps_mode = local->smps_mode;
  114. changed |= IEEE80211_CONF_CHANGE_SMPS;
  115. }
  116. power = ieee80211_chandef_max_power(&chandef);
  117. rcu_read_lock();
  118. list_for_each_entry_rcu(sdata, &local->interfaces, list) {
  119. if (!rcu_access_pointer(sdata->vif.chanctx_conf))
  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)
  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. /* wait for scan work complete */
  206. flush_workqueue(local->workqueue);
  207. mutex_lock(&local->mtx);
  208. WARN(test_bit(SCAN_HW_SCANNING, &local->scanning) ||
  209. rcu_dereference_protected(local->sched_scan_sdata,
  210. lockdep_is_held(&local->mtx)),
  211. "%s called with hardware scan in progress\n", __func__);
  212. mutex_unlock(&local->mtx);
  213. rtnl_lock();
  214. ieee80211_scan_cancel(local);
  215. ieee80211_reconfig(local);
  216. rtnl_unlock();
  217. }
  218. void ieee80211_restart_hw(struct ieee80211_hw *hw)
  219. {
  220. struct ieee80211_local *local = hw_to_local(hw);
  221. trace_api_restart_hw(local);
  222. wiphy_info(hw->wiphy,
  223. "Hardware restart was requested\n");
  224. /* use this reason, ieee80211_reconfig will unblock it */
  225. ieee80211_stop_queues_by_reason(hw, IEEE80211_MAX_QUEUE_MAP,
  226. IEEE80211_QUEUE_STOP_REASON_SUSPEND);
  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_DONE;
  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_DONE;
  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. .mcs = {
  379. .rx_mask = { 0xff, 0xff, 0xff, 0xff, 0xff,
  380. 0xff, 0xff, 0xff, 0xff, 0xff, },
  381. },
  382. };
  383. static const struct ieee80211_vht_cap mac80211_vht_capa_mod_mask = {
  384. .vht_cap_info =
  385. cpu_to_le32(IEEE80211_VHT_CAP_RXLDPC |
  386. IEEE80211_VHT_CAP_SHORT_GI_80 |
  387. IEEE80211_VHT_CAP_SHORT_GI_160 |
  388. IEEE80211_VHT_CAP_RXSTBC_1 |
  389. IEEE80211_VHT_CAP_RXSTBC_2 |
  390. IEEE80211_VHT_CAP_RXSTBC_3 |
  391. IEEE80211_VHT_CAP_RXSTBC_4 |
  392. IEEE80211_VHT_CAP_TXSTBC |
  393. IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
  394. IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
  395. IEEE80211_VHT_CAP_TX_ANTENNA_PATTERN |
  396. IEEE80211_VHT_CAP_RX_ANTENNA_PATTERN |
  397. IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK),
  398. .supp_mcs = {
  399. .rx_mcs_map = cpu_to_le16(~0),
  400. .tx_mcs_map = cpu_to_le16(~0),
  401. },
  402. };
  403. static const u8 extended_capabilities[] = {
  404. 0, 0, 0, 0, 0, 0, 0,
  405. WLAN_EXT_CAPA8_OPMODE_NOTIF,
  406. };
  407. struct ieee80211_hw *ieee80211_alloc_hw(size_t priv_data_len,
  408. const struct ieee80211_ops *ops)
  409. {
  410. struct ieee80211_local *local;
  411. int priv_size, i;
  412. struct wiphy *wiphy;
  413. bool use_chanctx;
  414. if (WARN_ON(!ops->tx || !ops->start || !ops->stop || !ops->config ||
  415. !ops->add_interface || !ops->remove_interface ||
  416. !ops->configure_filter))
  417. return NULL;
  418. if (WARN_ON(ops->sta_state && (ops->sta_add || ops->sta_remove)))
  419. return NULL;
  420. /* check all or no channel context operations exist */
  421. i = !!ops->add_chanctx + !!ops->remove_chanctx +
  422. !!ops->change_chanctx + !!ops->assign_vif_chanctx +
  423. !!ops->unassign_vif_chanctx;
  424. if (WARN_ON(i != 0 && i != 5))
  425. return NULL;
  426. use_chanctx = i == 5;
  427. /* Ensure 32-byte alignment of our private data and hw private data.
  428. * We use the wiphy priv data for both our ieee80211_local and for
  429. * the driver's private data
  430. *
  431. * In memory it'll be like this:
  432. *
  433. * +-------------------------+
  434. * | struct wiphy |
  435. * +-------------------------+
  436. * | struct ieee80211_local |
  437. * +-------------------------+
  438. * | driver's private data |
  439. * +-------------------------+
  440. *
  441. */
  442. priv_size = ALIGN(sizeof(*local), NETDEV_ALIGN) + priv_data_len;
  443. wiphy = wiphy_new(&mac80211_config_ops, priv_size);
  444. if (!wiphy)
  445. return NULL;
  446. wiphy->mgmt_stypes = ieee80211_default_mgmt_stypes;
  447. wiphy->privid = mac80211_wiphy_privid;
  448. wiphy->flags |= WIPHY_FLAG_NETNS_OK |
  449. WIPHY_FLAG_4ADDR_AP |
  450. WIPHY_FLAG_4ADDR_STATION |
  451. WIPHY_FLAG_REPORTS_OBSS |
  452. WIPHY_FLAG_OFFCHAN_TX;
  453. wiphy->extended_capabilities = extended_capabilities;
  454. wiphy->extended_capabilities_mask = extended_capabilities;
  455. wiphy->extended_capabilities_len = ARRAY_SIZE(extended_capabilities);
  456. if (ops->remain_on_channel)
  457. wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
  458. wiphy->features |= NL80211_FEATURE_SK_TX_STATUS |
  459. NL80211_FEATURE_SAE |
  460. NL80211_FEATURE_HT_IBSS |
  461. NL80211_FEATURE_VIF_TXPOWER |
  462. NL80211_FEATURE_USERSPACE_MPM;
  463. if (!ops->hw_scan)
  464. wiphy->features |= NL80211_FEATURE_LOW_PRIORITY_SCAN |
  465. NL80211_FEATURE_AP_SCAN;
  466. if (!ops->set_key)
  467. wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
  468. wiphy->bss_priv_size = sizeof(struct ieee80211_bss);
  469. local = wiphy_priv(wiphy);
  470. local->hw.wiphy = wiphy;
  471. local->hw.priv = (char *)local + ALIGN(sizeof(*local), NETDEV_ALIGN);
  472. local->ops = ops;
  473. local->use_chanctx = use_chanctx;
  474. /* set up some defaults */
  475. local->hw.queues = 1;
  476. local->hw.max_rates = 1;
  477. local->hw.max_report_rates = 0;
  478. local->hw.max_rx_aggregation_subframes = IEEE80211_MAX_AMPDU_BUF;
  479. local->hw.max_tx_aggregation_subframes = IEEE80211_MAX_AMPDU_BUF;
  480. local->hw.offchannel_tx_hw_queue = IEEE80211_INVAL_HW_QUEUE;
  481. local->hw.conf.long_frame_max_tx_count = wiphy->retry_long;
  482. local->hw.conf.short_frame_max_tx_count = wiphy->retry_short;
  483. local->hw.radiotap_mcs_details = IEEE80211_RADIOTAP_MCS_HAVE_MCS |
  484. IEEE80211_RADIOTAP_MCS_HAVE_GI |
  485. IEEE80211_RADIOTAP_MCS_HAVE_BW;
  486. local->hw.radiotap_vht_details = IEEE80211_RADIOTAP_VHT_KNOWN_GI |
  487. IEEE80211_RADIOTAP_VHT_KNOWN_BANDWIDTH;
  488. local->hw.uapsd_queues = IEEE80211_DEFAULT_UAPSD_QUEUES;
  489. local->hw.uapsd_max_sp_len = IEEE80211_DEFAULT_MAX_SP_LEN;
  490. local->user_power_level = IEEE80211_UNSET_POWER_LEVEL;
  491. wiphy->ht_capa_mod_mask = &mac80211_ht_capa_mod_mask;
  492. wiphy->vht_capa_mod_mask = &mac80211_vht_capa_mod_mask;
  493. INIT_LIST_HEAD(&local->interfaces);
  494. __hw_addr_init(&local->mc_list);
  495. mutex_init(&local->iflist_mtx);
  496. mutex_init(&local->mtx);
  497. mutex_init(&local->key_mtx);
  498. spin_lock_init(&local->filter_lock);
  499. spin_lock_init(&local->rx_path_lock);
  500. spin_lock_init(&local->queue_stop_reason_lock);
  501. INIT_LIST_HEAD(&local->chanctx_list);
  502. mutex_init(&local->chanctx_mtx);
  503. INIT_DELAYED_WORK(&local->scan_work, ieee80211_scan_work);
  504. INIT_WORK(&local->restart_work, ieee80211_restart_work);
  505. INIT_WORK(&local->radar_detected_work,
  506. ieee80211_dfs_radar_detected_work);
  507. INIT_WORK(&local->reconfig_filter, ieee80211_reconfig_filter);
  508. local->smps_mode = IEEE80211_SMPS_OFF;
  509. INIT_WORK(&local->dynamic_ps_enable_work,
  510. ieee80211_dynamic_ps_enable_work);
  511. INIT_WORK(&local->dynamic_ps_disable_work,
  512. ieee80211_dynamic_ps_disable_work);
  513. setup_timer(&local->dynamic_ps_timer,
  514. ieee80211_dynamic_ps_timer, (unsigned long) local);
  515. INIT_WORK(&local->sched_scan_stopped_work,
  516. ieee80211_sched_scan_stopped_work);
  517. spin_lock_init(&local->ack_status_lock);
  518. idr_init(&local->ack_status_frames);
  519. sta_info_init(local);
  520. for (i = 0; i < IEEE80211_MAX_QUEUES; i++) {
  521. skb_queue_head_init(&local->pending[i]);
  522. atomic_set(&local->agg_queue_stop[i], 0);
  523. }
  524. tasklet_init(&local->tx_pending_tasklet, ieee80211_tx_pending,
  525. (unsigned long)local);
  526. tasklet_init(&local->tasklet,
  527. ieee80211_tasklet_handler,
  528. (unsigned long) local);
  529. skb_queue_head_init(&local->skb_queue);
  530. skb_queue_head_init(&local->skb_queue_unreliable);
  531. ieee80211_led_names(local);
  532. ieee80211_roc_setup(local);
  533. return &local->hw;
  534. }
  535. EXPORT_SYMBOL(ieee80211_alloc_hw);
  536. static int ieee80211_init_cipher_suites(struct ieee80211_local *local)
  537. {
  538. bool have_wep = !(IS_ERR(local->wep_tx_tfm) ||
  539. IS_ERR(local->wep_rx_tfm));
  540. bool have_mfp = local->hw.flags & IEEE80211_HW_MFP_CAPABLE;
  541. const struct ieee80211_cipher_scheme *cs = local->hw.cipher_schemes;
  542. int n_suites = 0, r = 0, w = 0;
  543. u32 *suites;
  544. static const u32 cipher_suites[] = {
  545. /* keep WEP first, it may be removed below */
  546. WLAN_CIPHER_SUITE_WEP40,
  547. WLAN_CIPHER_SUITE_WEP104,
  548. WLAN_CIPHER_SUITE_TKIP,
  549. WLAN_CIPHER_SUITE_CCMP,
  550. /* keep last -- depends on hw flags! */
  551. WLAN_CIPHER_SUITE_AES_CMAC
  552. };
  553. /* Driver specifies the ciphers, we have nothing to do... */
  554. if (local->hw.wiphy->cipher_suites && have_wep)
  555. return 0;
  556. /* Set up cipher suites if driver relies on mac80211 cipher defs */
  557. if (!local->hw.wiphy->cipher_suites && !cs) {
  558. local->hw.wiphy->cipher_suites = cipher_suites;
  559. local->hw.wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
  560. if (!have_mfp)
  561. local->hw.wiphy->n_cipher_suites--;
  562. if (!have_wep) {
  563. local->hw.wiphy->cipher_suites += 2;
  564. local->hw.wiphy->n_cipher_suites -= 2;
  565. }
  566. return 0;
  567. }
  568. if (!local->hw.wiphy->cipher_suites) {
  569. /*
  570. * Driver specifies cipher schemes only
  571. * We start counting ciphers defined by schemes, TKIP and CCMP
  572. */
  573. n_suites = local->hw.n_cipher_schemes + 2;
  574. /* check if we have WEP40 and WEP104 */
  575. if (have_wep)
  576. n_suites += 2;
  577. /* check if we have AES_CMAC */
  578. if (have_mfp)
  579. n_suites++;
  580. suites = kmalloc(sizeof(u32) * n_suites, GFP_KERNEL);
  581. if (!suites)
  582. return -ENOMEM;
  583. suites[w++] = WLAN_CIPHER_SUITE_CCMP;
  584. suites[w++] = WLAN_CIPHER_SUITE_TKIP;
  585. if (have_wep) {
  586. suites[w++] = WLAN_CIPHER_SUITE_WEP40;
  587. suites[w++] = WLAN_CIPHER_SUITE_WEP104;
  588. }
  589. if (have_mfp)
  590. suites[w++] = WLAN_CIPHER_SUITE_AES_CMAC;
  591. for (r = 0; r < local->hw.n_cipher_schemes; r++)
  592. suites[w++] = cs[r].cipher;
  593. } else {
  594. /* Driver provides cipher suites, but we need to exclude WEP */
  595. suites = kmemdup(local->hw.wiphy->cipher_suites,
  596. sizeof(u32) * local->hw.wiphy->n_cipher_suites,
  597. GFP_KERNEL);
  598. if (!suites)
  599. return -ENOMEM;
  600. for (r = 0; r < local->hw.wiphy->n_cipher_suites; r++) {
  601. u32 suite = local->hw.wiphy->cipher_suites[r];
  602. if (suite == WLAN_CIPHER_SUITE_WEP40 ||
  603. suite == WLAN_CIPHER_SUITE_WEP104)
  604. continue;
  605. suites[w++] = suite;
  606. }
  607. }
  608. local->hw.wiphy->cipher_suites = suites;
  609. local->hw.wiphy->n_cipher_suites = w;
  610. local->wiphy_ciphers_allocated = true;
  611. return 0;
  612. }
  613. int ieee80211_register_hw(struct ieee80211_hw *hw)
  614. {
  615. struct ieee80211_local *local = hw_to_local(hw);
  616. int result, i;
  617. enum ieee80211_band band;
  618. int channels, max_bitrates;
  619. bool supp_ht, supp_vht;
  620. netdev_features_t feature_whitelist;
  621. struct cfg80211_chan_def dflt_chandef = {};
  622. if (hw->flags & IEEE80211_HW_QUEUE_CONTROL &&
  623. (local->hw.offchannel_tx_hw_queue == IEEE80211_INVAL_HW_QUEUE ||
  624. local->hw.offchannel_tx_hw_queue >= local->hw.queues))
  625. return -EINVAL;
  626. #ifdef CONFIG_PM
  627. if (hw->wiphy->wowlan && (!local->ops->suspend || !local->ops->resume))
  628. return -EINVAL;
  629. #endif
  630. if (!local->use_chanctx) {
  631. for (i = 0; i < local->hw.wiphy->n_iface_combinations; i++) {
  632. const struct ieee80211_iface_combination *comb;
  633. comb = &local->hw.wiphy->iface_combinations[i];
  634. if (comb->num_different_channels > 1)
  635. return -EINVAL;
  636. }
  637. } else {
  638. /*
  639. * WDS is currently prohibited when channel contexts are used
  640. * because there's no clear definition of which channel WDS
  641. * type interfaces use
  642. */
  643. if (local->hw.wiphy->interface_modes & BIT(NL80211_IFTYPE_WDS))
  644. return -EINVAL;
  645. /* DFS currently not supported with channel context drivers */
  646. for (i = 0; i < local->hw.wiphy->n_iface_combinations; i++) {
  647. const struct ieee80211_iface_combination *comb;
  648. comb = &local->hw.wiphy->iface_combinations[i];
  649. if (comb->radar_detect_widths)
  650. return -EINVAL;
  651. }
  652. }
  653. /* Only HW csum features are currently compatible with mac80211 */
  654. feature_whitelist = NETIF_F_IP_CSUM | NETIF_F_IPV6_CSUM |
  655. NETIF_F_HW_CSUM;
  656. if (WARN_ON(hw->netdev_features & ~feature_whitelist))
  657. return -EINVAL;
  658. if (hw->max_report_rates == 0)
  659. hw->max_report_rates = hw->max_rates;
  660. local->rx_chains = 1;
  661. /*
  662. * generic code guarantees at least one band,
  663. * set this very early because much code assumes
  664. * that hw.conf.channel is assigned
  665. */
  666. channels = 0;
  667. max_bitrates = 0;
  668. supp_ht = false;
  669. supp_vht = false;
  670. for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
  671. struct ieee80211_supported_band *sband;
  672. sband = local->hw.wiphy->bands[band];
  673. if (!sband)
  674. continue;
  675. if (!dflt_chandef.chan) {
  676. cfg80211_chandef_create(&dflt_chandef,
  677. &sband->channels[0],
  678. NL80211_CHAN_NO_HT);
  679. /* init channel we're on */
  680. if (!local->use_chanctx && !local->_oper_chandef.chan) {
  681. local->hw.conf.chandef = dflt_chandef;
  682. local->_oper_chandef = dflt_chandef;
  683. }
  684. local->monitor_chandef = dflt_chandef;
  685. }
  686. channels += sband->n_channels;
  687. if (max_bitrates < sband->n_bitrates)
  688. max_bitrates = sband->n_bitrates;
  689. supp_ht = supp_ht || sband->ht_cap.ht_supported;
  690. supp_vht = supp_vht || sband->vht_cap.vht_supported;
  691. if (sband->ht_cap.ht_supported)
  692. local->rx_chains =
  693. max(ieee80211_mcs_to_chains(&sband->ht_cap.mcs),
  694. local->rx_chains);
  695. /* TODO: consider VHT for RX chains, hopefully it's the same */
  696. }
  697. local->int_scan_req = kzalloc(sizeof(*local->int_scan_req) +
  698. sizeof(void *) * channels, GFP_KERNEL);
  699. if (!local->int_scan_req)
  700. return -ENOMEM;
  701. for (band = 0; band < IEEE80211_NUM_BANDS; band++) {
  702. if (!local->hw.wiphy->bands[band])
  703. continue;
  704. local->int_scan_req->rates[band] = (u32) -1;
  705. }
  706. /* if low-level driver supports AP, we also support VLAN */
  707. if (local->hw.wiphy->interface_modes & BIT(NL80211_IFTYPE_AP)) {
  708. hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_AP_VLAN);
  709. hw->wiphy->software_iftypes |= BIT(NL80211_IFTYPE_AP_VLAN);
  710. }
  711. /* mac80211 always supports monitor */
  712. hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_MONITOR);
  713. hw->wiphy->software_iftypes |= BIT(NL80211_IFTYPE_MONITOR);
  714. /* mac80211 doesn't support more than one IBSS interface right now */
  715. for (i = 0; i < hw->wiphy->n_iface_combinations; i++) {
  716. const struct ieee80211_iface_combination *c;
  717. int j;
  718. c = &hw->wiphy->iface_combinations[i];
  719. for (j = 0; j < c->n_limits; j++)
  720. if ((c->limits[j].types & BIT(NL80211_IFTYPE_ADHOC)) &&
  721. c->limits[j].max > 1)
  722. return -EINVAL;
  723. }
  724. #ifndef CONFIG_MAC80211_MESH
  725. /* mesh depends on Kconfig, but drivers should set it if they want */
  726. local->hw.wiphy->interface_modes &= ~BIT(NL80211_IFTYPE_MESH_POINT);
  727. #endif
  728. /* if the underlying driver supports mesh, mac80211 will (at least)
  729. * provide routing of mesh authentication frames to userspace */
  730. if (local->hw.wiphy->interface_modes & BIT(NL80211_IFTYPE_MESH_POINT))
  731. local->hw.wiphy->flags |= WIPHY_FLAG_MESH_AUTH;
  732. /* mac80211 supports control port protocol changing */
  733. local->hw.wiphy->flags |= WIPHY_FLAG_CONTROL_PORT_PROTOCOL;
  734. if (local->hw.flags & IEEE80211_HW_SIGNAL_DBM)
  735. local->hw.wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
  736. else if (local->hw.flags & IEEE80211_HW_SIGNAL_UNSPEC)
  737. local->hw.wiphy->signal_type = CFG80211_SIGNAL_TYPE_UNSPEC;
  738. WARN((local->hw.flags & IEEE80211_HW_SUPPORTS_UAPSD)
  739. && (local->hw.flags & IEEE80211_HW_PS_NULLFUNC_STACK),
  740. "U-APSD not supported with HW_PS_NULLFUNC_STACK\n");
  741. /*
  742. * Calculate scan IE length -- we need this to alloc
  743. * memory and to subtract from the driver limit. It
  744. * includes the DS Params, (extended) supported rates, and HT
  745. * information -- SSID is the driver's responsibility.
  746. */
  747. local->scan_ies_len = 4 + max_bitrates /* (ext) supp rates */ +
  748. 3 /* DS Params */;
  749. if (supp_ht)
  750. local->scan_ies_len += 2 + sizeof(struct ieee80211_ht_cap);
  751. if (supp_vht)
  752. local->scan_ies_len +=
  753. 2 + sizeof(struct ieee80211_vht_cap);
  754. if (!local->ops->hw_scan) {
  755. /* For hw_scan, driver needs to set these up. */
  756. local->hw.wiphy->max_scan_ssids = 4;
  757. local->hw.wiphy->max_scan_ie_len = IEEE80211_MAX_DATA_LEN;
  758. }
  759. /*
  760. * If the driver supports any scan IEs, then assume the
  761. * limit includes the IEs mac80211 will add, otherwise
  762. * leave it at zero and let the driver sort it out; we
  763. * still pass our IEs to the driver but userspace will
  764. * not be allowed to in that case.
  765. */
  766. if (local->hw.wiphy->max_scan_ie_len)
  767. local->hw.wiphy->max_scan_ie_len -= local->scan_ies_len;
  768. WARN_ON(!ieee80211_cs_list_valid(local->hw.cipher_schemes,
  769. local->hw.n_cipher_schemes));
  770. result = ieee80211_init_cipher_suites(local);
  771. if (result < 0)
  772. goto fail_wiphy_register;
  773. if (!local->ops->remain_on_channel)
  774. local->hw.wiphy->max_remain_on_channel_duration = 5000;
  775. /* mac80211 based drivers don't support internal TDLS setup */
  776. if (local->hw.wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS)
  777. local->hw.wiphy->flags |= WIPHY_FLAG_TDLS_EXTERNAL_SETUP;
  778. result = wiphy_register(local->hw.wiphy);
  779. if (result < 0)
  780. goto fail_wiphy_register;
  781. /*
  782. * We use the number of queues for feature tests (QoS, HT) internally
  783. * so restrict them appropriately.
  784. */
  785. if (hw->queues > IEEE80211_MAX_QUEUES)
  786. hw->queues = IEEE80211_MAX_QUEUES;
  787. local->workqueue =
  788. alloc_ordered_workqueue("%s", 0, wiphy_name(local->hw.wiphy));
  789. if (!local->workqueue) {
  790. result = -ENOMEM;
  791. goto fail_workqueue;
  792. }
  793. /*
  794. * The hardware needs headroom for sending the frame,
  795. * and we need some headroom for passing the frame to monitor
  796. * interfaces, but never both at the same time.
  797. */
  798. local->tx_headroom = max_t(unsigned int , local->hw.extra_tx_headroom,
  799. IEEE80211_TX_STATUS_HEADROOM);
  800. debugfs_hw_add(local);
  801. /*
  802. * if the driver doesn't specify a max listen interval we
  803. * use 5 which should be a safe default
  804. */
  805. if (local->hw.max_listen_interval == 0)
  806. local->hw.max_listen_interval = 5;
  807. local->hw.conf.listen_interval = local->hw.max_listen_interval;
  808. local->dynamic_ps_forced_timeout = -1;
  809. result = ieee80211_wep_init(local);
  810. if (result < 0)
  811. wiphy_debug(local->hw.wiphy, "Failed to initialize wep: %d\n",
  812. result);
  813. local->hw.conf.flags = IEEE80211_CONF_IDLE;
  814. ieee80211_led_init(local);
  815. rtnl_lock();
  816. result = ieee80211_init_rate_ctrl_alg(local,
  817. hw->rate_control_algorithm);
  818. if (result < 0) {
  819. wiphy_debug(local->hw.wiphy,
  820. "Failed to initialize rate control algorithm\n");
  821. goto fail_rate;
  822. }
  823. /* add one default STA interface if supported */
  824. if (local->hw.wiphy->interface_modes & BIT(NL80211_IFTYPE_STATION)) {
  825. result = ieee80211_if_add(local, "wlan%d", NULL,
  826. NL80211_IFTYPE_STATION, NULL);
  827. if (result)
  828. wiphy_warn(local->hw.wiphy,
  829. "Failed to add default virtual iface\n");
  830. }
  831. rtnl_unlock();
  832. local->network_latency_notifier.notifier_call =
  833. ieee80211_max_network_latency;
  834. result = pm_qos_add_notifier(PM_QOS_NETWORK_LATENCY,
  835. &local->network_latency_notifier);
  836. if (result) {
  837. rtnl_lock();
  838. goto fail_pm_qos;
  839. }
  840. #ifdef CONFIG_INET
  841. local->ifa_notifier.notifier_call = ieee80211_ifa_changed;
  842. result = register_inetaddr_notifier(&local->ifa_notifier);
  843. if (result)
  844. goto fail_ifa;
  845. #endif
  846. #if IS_ENABLED(CONFIG_IPV6)
  847. local->ifa6_notifier.notifier_call = ieee80211_ifa6_changed;
  848. result = register_inet6addr_notifier(&local->ifa6_notifier);
  849. if (result)
  850. goto fail_ifa6;
  851. #endif
  852. return 0;
  853. #if IS_ENABLED(CONFIG_IPV6)
  854. fail_ifa6:
  855. #ifdef CONFIG_INET
  856. unregister_inetaddr_notifier(&local->ifa_notifier);
  857. #endif
  858. #endif
  859. #if defined(CONFIG_INET) || defined(CONFIG_IPV6)
  860. fail_ifa:
  861. pm_qos_remove_notifier(PM_QOS_NETWORK_LATENCY,
  862. &local->network_latency_notifier);
  863. rtnl_lock();
  864. #endif
  865. fail_pm_qos:
  866. ieee80211_led_exit(local);
  867. ieee80211_remove_interfaces(local);
  868. fail_rate:
  869. rtnl_unlock();
  870. ieee80211_wep_free(local);
  871. sta_info_stop(local);
  872. destroy_workqueue(local->workqueue);
  873. fail_workqueue:
  874. wiphy_unregister(local->hw.wiphy);
  875. fail_wiphy_register:
  876. if (local->wiphy_ciphers_allocated)
  877. kfree(local->hw.wiphy->cipher_suites);
  878. kfree(local->int_scan_req);
  879. return result;
  880. }
  881. EXPORT_SYMBOL(ieee80211_register_hw);
  882. void ieee80211_unregister_hw(struct ieee80211_hw *hw)
  883. {
  884. struct ieee80211_local *local = hw_to_local(hw);
  885. tasklet_kill(&local->tx_pending_tasklet);
  886. tasklet_kill(&local->tasklet);
  887. pm_qos_remove_notifier(PM_QOS_NETWORK_LATENCY,
  888. &local->network_latency_notifier);
  889. #ifdef CONFIG_INET
  890. unregister_inetaddr_notifier(&local->ifa_notifier);
  891. #endif
  892. #if IS_ENABLED(CONFIG_IPV6)
  893. unregister_inet6addr_notifier(&local->ifa6_notifier);
  894. #endif
  895. rtnl_lock();
  896. /*
  897. * At this point, interface list manipulations are fine
  898. * because the driver cannot be handing us frames any
  899. * more and the tasklet is killed.
  900. */
  901. ieee80211_remove_interfaces(local);
  902. rtnl_unlock();
  903. cancel_work_sync(&local->restart_work);
  904. cancel_work_sync(&local->reconfig_filter);
  905. flush_work(&local->sched_scan_stopped_work);
  906. ieee80211_clear_tx_pending(local);
  907. rate_control_deinitialize(local);
  908. if (skb_queue_len(&local->skb_queue) ||
  909. skb_queue_len(&local->skb_queue_unreliable))
  910. wiphy_warn(local->hw.wiphy, "skb_queue not empty\n");
  911. skb_queue_purge(&local->skb_queue);
  912. skb_queue_purge(&local->skb_queue_unreliable);
  913. destroy_workqueue(local->workqueue);
  914. wiphy_unregister(local->hw.wiphy);
  915. sta_info_stop(local);
  916. ieee80211_wep_free(local);
  917. ieee80211_led_exit(local);
  918. kfree(local->int_scan_req);
  919. }
  920. EXPORT_SYMBOL(ieee80211_unregister_hw);
  921. static int ieee80211_free_ack_frame(int id, void *p, void *data)
  922. {
  923. WARN_ONCE(1, "Have pending ack frames!\n");
  924. kfree_skb(p);
  925. return 0;
  926. }
  927. void ieee80211_free_hw(struct ieee80211_hw *hw)
  928. {
  929. struct ieee80211_local *local = hw_to_local(hw);
  930. mutex_destroy(&local->iflist_mtx);
  931. mutex_destroy(&local->mtx);
  932. if (local->wiphy_ciphers_allocated)
  933. kfree(local->hw.wiphy->cipher_suites);
  934. idr_for_each(&local->ack_status_frames,
  935. ieee80211_free_ack_frame, NULL);
  936. idr_destroy(&local->ack_status_frames);
  937. kfree(rcu_access_pointer(local->tx_latency));
  938. wiphy_free(local->hw.wiphy);
  939. }
  940. EXPORT_SYMBOL(ieee80211_free_hw);
  941. static int __init ieee80211_init(void)
  942. {
  943. struct sk_buff *skb;
  944. int ret;
  945. BUILD_BUG_ON(sizeof(struct ieee80211_tx_info) > sizeof(skb->cb));
  946. BUILD_BUG_ON(offsetof(struct ieee80211_tx_info, driver_data) +
  947. IEEE80211_TX_INFO_DRIVER_DATA_SIZE > sizeof(skb->cb));
  948. ret = rc80211_minstrel_init();
  949. if (ret)
  950. return ret;
  951. ret = rc80211_minstrel_ht_init();
  952. if (ret)
  953. goto err_minstrel;
  954. ret = rc80211_pid_init();
  955. if (ret)
  956. goto err_pid;
  957. ret = ieee80211_iface_init();
  958. if (ret)
  959. goto err_netdev;
  960. return 0;
  961. err_netdev:
  962. rc80211_pid_exit();
  963. err_pid:
  964. rc80211_minstrel_ht_exit();
  965. err_minstrel:
  966. rc80211_minstrel_exit();
  967. return ret;
  968. }
  969. static void __exit ieee80211_exit(void)
  970. {
  971. rc80211_pid_exit();
  972. rc80211_minstrel_ht_exit();
  973. rc80211_minstrel_exit();
  974. ieee80211s_stop();
  975. ieee80211_iface_exit();
  976. rcu_barrier();
  977. }
  978. subsys_initcall(ieee80211_init);
  979. module_exit(ieee80211_exit);
  980. MODULE_DESCRIPTION("IEEE 802.11 subsystem");
  981. MODULE_LICENSE("GPL");