main.c 35 KB

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