main.c 37 KB

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