main.c 51 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright 2002-2005, Instant802 Networks, Inc.
  4. * Copyright 2005-2006, Devicescape Software, Inc.
  5. * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz>
  6. * Copyright 2013-2014 Intel Mobile Communications GmbH
  7. * Copyright (C) 2017 Intel Deutschland GmbH
  8. * Copyright (C) 2018-2023 Intel Corporation
  9. */
  10. #include <net/mac80211.h>
  11. #include <linux/module.h>
  12. #include <linux/fips.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/dropreason.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. if (local->rx_mcast_action_reg)
  57. new_flags |= FIF_MCAST_ACTION;
  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 wiphy *wiphy,
  69. struct wiphy_work *work)
  70. {
  71. struct ieee80211_local *local =
  72. container_of(work, struct ieee80211_local, reconfig_filter);
  73. ieee80211_configure_filter(local);
  74. }
  75. static u32 ieee80211_calc_hw_conf_chan(struct ieee80211_local *local,
  76. struct ieee80211_chanctx_conf *ctx)
  77. {
  78. struct ieee80211_sub_if_data *sdata;
  79. struct cfg80211_chan_def chandef = {};
  80. struct cfg80211_chan_def *oper = NULL;
  81. enum ieee80211_smps_mode smps_mode = IEEE80211_SMPS_STATIC;
  82. u32 changed = 0;
  83. int power;
  84. u32 offchannel_flag;
  85. if (!local->emulate_chanctx)
  86. return 0;
  87. offchannel_flag = local->hw.conf.flags & IEEE80211_CONF_OFFCHANNEL;
  88. if (ctx && !WARN_ON(!ctx->def.chan)) {
  89. oper = &ctx->def;
  90. if (ctx->rx_chains_static > 1)
  91. smps_mode = IEEE80211_SMPS_OFF;
  92. else if (ctx->rx_chains_dynamic > 1)
  93. smps_mode = IEEE80211_SMPS_DYNAMIC;
  94. else
  95. smps_mode = IEEE80211_SMPS_STATIC;
  96. }
  97. if (local->scan_chandef.chan) {
  98. chandef = local->scan_chandef;
  99. } else if (local->tmp_channel) {
  100. chandef.chan = local->tmp_channel;
  101. chandef.width = NL80211_CHAN_WIDTH_20_NOHT;
  102. chandef.center_freq1 = chandef.chan->center_freq;
  103. chandef.freq1_offset = chandef.chan->freq_offset;
  104. } else if (oper) {
  105. chandef = *oper;
  106. } else {
  107. chandef = local->dflt_chandef;
  108. }
  109. if (WARN(!cfg80211_chandef_valid(&chandef),
  110. "control:%d.%03d MHz width:%d center: %d.%03d/%d MHz",
  111. chandef.chan ? chandef.chan->center_freq : -1,
  112. chandef.chan ? chandef.chan->freq_offset : 0,
  113. chandef.width, chandef.center_freq1, chandef.freq1_offset,
  114. chandef.center_freq2))
  115. return 0;
  116. if (!oper || !cfg80211_chandef_identical(&chandef, oper))
  117. local->hw.conf.flags |= IEEE80211_CONF_OFFCHANNEL;
  118. else
  119. local->hw.conf.flags &= ~IEEE80211_CONF_OFFCHANNEL;
  120. offchannel_flag ^= local->hw.conf.flags & IEEE80211_CONF_OFFCHANNEL;
  121. /* force it also for scanning, since drivers might config differently */
  122. if (offchannel_flag || local->scanning || local->in_reconfig ||
  123. !cfg80211_chandef_identical(&local->hw.conf.chandef, &chandef)) {
  124. local->hw.conf.chandef = chandef;
  125. changed |= IEEE80211_CONF_CHANGE_CHANNEL;
  126. }
  127. if (!conf_is_ht(&local->hw.conf)) {
  128. /*
  129. * mac80211.h documents that this is only valid
  130. * when the channel is set to an HT type, and
  131. * that otherwise STATIC is used.
  132. */
  133. local->hw.conf.smps_mode = IEEE80211_SMPS_STATIC;
  134. } else if (local->hw.conf.smps_mode != smps_mode) {
  135. local->hw.conf.smps_mode = smps_mode;
  136. changed |= IEEE80211_CONF_CHANGE_SMPS;
  137. }
  138. power = ieee80211_chandef_max_power(&chandef);
  139. if (local->user_power_level != IEEE80211_UNSET_POWER_LEVEL)
  140. power = min(local->user_power_level, power);
  141. rcu_read_lock();
  142. list_for_each_entry_rcu(sdata, &local->interfaces, list) {
  143. if (!rcu_access_pointer(sdata->vif.bss_conf.chanctx_conf))
  144. continue;
  145. if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
  146. continue;
  147. if (sdata->vif.bss_conf.txpower == INT_MIN)
  148. continue;
  149. power = min(power, sdata->vif.bss_conf.txpower);
  150. }
  151. rcu_read_unlock();
  152. if (local->hw.conf.power_level != power) {
  153. changed |= IEEE80211_CONF_CHANGE_POWER;
  154. local->hw.conf.power_level = power;
  155. }
  156. return changed;
  157. }
  158. int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
  159. {
  160. int ret = 0;
  161. might_sleep();
  162. WARN_ON(changed & (IEEE80211_CONF_CHANGE_CHANNEL |
  163. IEEE80211_CONF_CHANGE_POWER |
  164. IEEE80211_CONF_CHANGE_SMPS));
  165. if (changed && local->open_count) {
  166. ret = drv_config(local, changed);
  167. /*
  168. * Goal:
  169. * HW reconfiguration should never fail, the driver has told
  170. * us what it can support so it should live up to that promise.
  171. *
  172. * Current status:
  173. * rfkill is not integrated with mac80211 and a
  174. * configuration command can thus fail if hardware rfkill
  175. * is enabled
  176. *
  177. * FIXME: integrate rfkill with mac80211 and then add this
  178. * WARN_ON() back
  179. *
  180. */
  181. /* WARN_ON(ret); */
  182. }
  183. return ret;
  184. }
  185. /* for scanning, offchannel and chanctx emulation only */
  186. static int _ieee80211_hw_conf_chan(struct ieee80211_local *local,
  187. struct ieee80211_chanctx_conf *ctx)
  188. {
  189. u32 changed;
  190. if (!local->open_count)
  191. return 0;
  192. changed = ieee80211_calc_hw_conf_chan(local, ctx);
  193. if (!changed)
  194. return 0;
  195. return drv_config(local, changed);
  196. }
  197. int ieee80211_hw_conf_chan(struct ieee80211_local *local)
  198. {
  199. struct ieee80211_chanctx *ctx;
  200. ctx = list_first_entry_or_null(&local->chanctx_list,
  201. struct ieee80211_chanctx,
  202. list);
  203. return _ieee80211_hw_conf_chan(local, ctx ? &ctx->conf : NULL);
  204. }
  205. void ieee80211_hw_conf_init(struct ieee80211_local *local)
  206. {
  207. u32 changed = ~(IEEE80211_CONF_CHANGE_CHANNEL |
  208. IEEE80211_CONF_CHANGE_POWER |
  209. IEEE80211_CONF_CHANGE_SMPS);
  210. if (WARN_ON(!local->open_count))
  211. return;
  212. if (local->emulate_chanctx) {
  213. struct ieee80211_chanctx *ctx;
  214. ctx = list_first_entry_or_null(&local->chanctx_list,
  215. struct ieee80211_chanctx,
  216. list);
  217. changed |= ieee80211_calc_hw_conf_chan(local,
  218. ctx ? &ctx->conf : NULL);
  219. }
  220. WARN_ON(drv_config(local, changed));
  221. }
  222. int ieee80211_emulate_add_chanctx(struct ieee80211_hw *hw,
  223. struct ieee80211_chanctx_conf *ctx)
  224. {
  225. struct ieee80211_local *local = hw_to_local(hw);
  226. local->hw.conf.radar_enabled = ctx->radar_enabled;
  227. return _ieee80211_hw_conf_chan(local, ctx);
  228. }
  229. EXPORT_SYMBOL(ieee80211_emulate_add_chanctx);
  230. void ieee80211_emulate_remove_chanctx(struct ieee80211_hw *hw,
  231. struct ieee80211_chanctx_conf *ctx)
  232. {
  233. struct ieee80211_local *local = hw_to_local(hw);
  234. local->hw.conf.radar_enabled = false;
  235. _ieee80211_hw_conf_chan(local, NULL);
  236. }
  237. EXPORT_SYMBOL(ieee80211_emulate_remove_chanctx);
  238. void ieee80211_emulate_change_chanctx(struct ieee80211_hw *hw,
  239. struct ieee80211_chanctx_conf *ctx,
  240. u32 changed)
  241. {
  242. struct ieee80211_local *local = hw_to_local(hw);
  243. local->hw.conf.radar_enabled = ctx->radar_enabled;
  244. _ieee80211_hw_conf_chan(local, ctx);
  245. }
  246. EXPORT_SYMBOL(ieee80211_emulate_change_chanctx);
  247. int ieee80211_emulate_switch_vif_chanctx(struct ieee80211_hw *hw,
  248. struct ieee80211_vif_chanctx_switch *vifs,
  249. int n_vifs,
  250. enum ieee80211_chanctx_switch_mode mode)
  251. {
  252. struct ieee80211_local *local = hw_to_local(hw);
  253. if (n_vifs <= 0)
  254. return -EINVAL;
  255. local->hw.conf.radar_enabled = vifs[0].new_ctx->radar_enabled;
  256. _ieee80211_hw_conf_chan(local, vifs[0].new_ctx);
  257. return 0;
  258. }
  259. EXPORT_SYMBOL(ieee80211_emulate_switch_vif_chanctx);
  260. #define BSS_CHANGED_VIF_CFG_FLAGS (BSS_CHANGED_ASSOC |\
  261. BSS_CHANGED_IDLE |\
  262. BSS_CHANGED_PS |\
  263. BSS_CHANGED_IBSS |\
  264. BSS_CHANGED_ARP_FILTER |\
  265. BSS_CHANGED_SSID |\
  266. BSS_CHANGED_MLD_VALID_LINKS |\
  267. BSS_CHANGED_MLD_TTLM)
  268. void ieee80211_bss_info_change_notify(struct ieee80211_sub_if_data *sdata,
  269. u64 changed)
  270. {
  271. struct ieee80211_local *local = sdata->local;
  272. might_sleep();
  273. WARN_ON_ONCE(ieee80211_vif_is_mld(&sdata->vif));
  274. if (!changed || sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
  275. return;
  276. if (WARN_ON_ONCE(changed & (BSS_CHANGED_BEACON |
  277. BSS_CHANGED_BEACON_ENABLED) &&
  278. sdata->vif.type != NL80211_IFTYPE_AP &&
  279. sdata->vif.type != NL80211_IFTYPE_ADHOC &&
  280. sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
  281. sdata->vif.type != NL80211_IFTYPE_OCB))
  282. return;
  283. if (WARN_ON_ONCE(sdata->vif.type == NL80211_IFTYPE_P2P_DEVICE ||
  284. sdata->vif.type == NL80211_IFTYPE_NAN ||
  285. (sdata->vif.type == NL80211_IFTYPE_MONITOR &&
  286. !sdata->vif.bss_conf.mu_mimo_owner &&
  287. !(changed & BSS_CHANGED_TXPOWER))))
  288. return;
  289. if (!check_sdata_in_driver(sdata))
  290. return;
  291. if (changed & BSS_CHANGED_VIF_CFG_FLAGS) {
  292. u64 ch = changed & BSS_CHANGED_VIF_CFG_FLAGS;
  293. trace_drv_vif_cfg_changed(local, sdata, changed);
  294. if (local->ops->vif_cfg_changed)
  295. local->ops->vif_cfg_changed(&local->hw, &sdata->vif, ch);
  296. }
  297. if (changed & ~BSS_CHANGED_VIF_CFG_FLAGS) {
  298. u64 ch = changed & ~BSS_CHANGED_VIF_CFG_FLAGS;
  299. trace_drv_link_info_changed(local, sdata, &sdata->vif.bss_conf,
  300. changed);
  301. if (local->ops->link_info_changed)
  302. local->ops->link_info_changed(&local->hw, &sdata->vif,
  303. &sdata->vif.bss_conf, ch);
  304. }
  305. if (local->ops->bss_info_changed)
  306. local->ops->bss_info_changed(&local->hw, &sdata->vif,
  307. &sdata->vif.bss_conf, changed);
  308. trace_drv_return_void(local);
  309. }
  310. void ieee80211_vif_cfg_change_notify(struct ieee80211_sub_if_data *sdata,
  311. u64 changed)
  312. {
  313. struct ieee80211_local *local = sdata->local;
  314. WARN_ON_ONCE(changed & ~BSS_CHANGED_VIF_CFG_FLAGS);
  315. if (!changed || sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
  316. return;
  317. drv_vif_cfg_changed(local, sdata, changed);
  318. }
  319. void ieee80211_link_info_change_notify(struct ieee80211_sub_if_data *sdata,
  320. struct ieee80211_link_data *link,
  321. u64 changed)
  322. {
  323. struct ieee80211_local *local = sdata->local;
  324. WARN_ON_ONCE(changed & BSS_CHANGED_VIF_CFG_FLAGS);
  325. if (!changed || sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
  326. return;
  327. if (!check_sdata_in_driver(sdata))
  328. return;
  329. drv_link_info_changed(local, sdata, link->conf, link->link_id, changed);
  330. }
  331. u64 ieee80211_reset_erp_info(struct ieee80211_sub_if_data *sdata)
  332. {
  333. sdata->vif.bss_conf.use_cts_prot = false;
  334. sdata->vif.bss_conf.use_short_preamble = false;
  335. sdata->vif.bss_conf.use_short_slot = false;
  336. return BSS_CHANGED_ERP_CTS_PROT |
  337. BSS_CHANGED_ERP_PREAMBLE |
  338. BSS_CHANGED_ERP_SLOT;
  339. }
  340. /* context: requires softirqs disabled */
  341. void ieee80211_handle_queued_frames(struct ieee80211_local *local)
  342. {
  343. struct sk_buff *skb;
  344. while ((skb = skb_dequeue(&local->skb_queue)) ||
  345. (skb = skb_dequeue(&local->skb_queue_unreliable))) {
  346. switch (skb->pkt_type) {
  347. case IEEE80211_RX_MSG:
  348. /* Clear skb->pkt_type in order to not confuse kernel
  349. * netstack. */
  350. skb->pkt_type = 0;
  351. ieee80211_rx(&local->hw, skb);
  352. break;
  353. case IEEE80211_TX_STATUS_MSG:
  354. skb->pkt_type = 0;
  355. ieee80211_tx_status_skb(&local->hw, skb);
  356. break;
  357. default:
  358. WARN(1, "mac80211: Packet is of unknown type %d\n",
  359. skb->pkt_type);
  360. dev_kfree_skb(skb);
  361. break;
  362. }
  363. }
  364. }
  365. static void ieee80211_tasklet_handler(struct tasklet_struct *t)
  366. {
  367. struct ieee80211_local *local = from_tasklet(local, t, tasklet);
  368. ieee80211_handle_queued_frames(local);
  369. }
  370. static void ieee80211_restart_work(struct work_struct *work)
  371. {
  372. struct ieee80211_local *local =
  373. container_of(work, struct ieee80211_local, restart_work);
  374. struct ieee80211_sub_if_data *sdata;
  375. int ret;
  376. flush_workqueue(local->workqueue);
  377. rtnl_lock();
  378. /* we might do interface manipulations, so need both */
  379. wiphy_lock(local->hw.wiphy);
  380. wiphy_work_flush(local->hw.wiphy, NULL);
  381. WARN(test_bit(SCAN_HW_SCANNING, &local->scanning),
  382. "%s called with hardware scan in progress\n", __func__);
  383. list_for_each_entry(sdata, &local->interfaces, list) {
  384. /*
  385. * XXX: there may be more work for other vif types and even
  386. * for station mode: a good thing would be to run most of
  387. * the iface type's dependent _stop (ieee80211_mg_stop,
  388. * ieee80211_ibss_stop) etc...
  389. * For now, fix only the specific bug that was seen: race
  390. * between csa_connection_drop_work and us.
  391. */
  392. if (sdata->vif.type == NL80211_IFTYPE_STATION) {
  393. /*
  394. * This worker is scheduled from the iface worker that
  395. * runs on mac80211's workqueue, so we can't be
  396. * scheduling this worker after the cancel right here.
  397. * The exception is ieee80211_chswitch_done.
  398. * Then we can have a race...
  399. */
  400. wiphy_work_cancel(local->hw.wiphy,
  401. &sdata->u.mgd.csa_connection_drop_work);
  402. if (sdata->vif.bss_conf.csa_active)
  403. ieee80211_sta_connection_lost(sdata,
  404. WLAN_REASON_UNSPECIFIED,
  405. false);
  406. }
  407. wiphy_delayed_work_flush(local->hw.wiphy,
  408. &sdata->dec_tailroom_needed_wk);
  409. }
  410. ieee80211_scan_cancel(local);
  411. /* make sure any new ROC will consider local->in_reconfig */
  412. wiphy_delayed_work_flush(local->hw.wiphy, &local->roc_work);
  413. wiphy_work_flush(local->hw.wiphy, &local->hw_roc_done);
  414. /* wait for all packet processing to be done */
  415. synchronize_net();
  416. ret = ieee80211_reconfig(local);
  417. wiphy_unlock(local->hw.wiphy);
  418. if (ret)
  419. cfg80211_shutdown_all_interfaces(local->hw.wiphy);
  420. rtnl_unlock();
  421. }
  422. void ieee80211_restart_hw(struct ieee80211_hw *hw)
  423. {
  424. struct ieee80211_local *local = hw_to_local(hw);
  425. trace_api_restart_hw(local);
  426. wiphy_info(hw->wiphy,
  427. "Hardware restart was requested\n");
  428. /* use this reason, ieee80211_reconfig will unblock it */
  429. ieee80211_stop_queues_by_reason(hw, IEEE80211_MAX_QUEUE_MAP,
  430. IEEE80211_QUEUE_STOP_REASON_SUSPEND,
  431. false);
  432. /*
  433. * Stop all Rx during the reconfig. We don't want state changes
  434. * or driver callbacks while this is in progress.
  435. */
  436. local->in_reconfig = true;
  437. barrier();
  438. queue_work(system_freezable_wq, &local->restart_work);
  439. }
  440. EXPORT_SYMBOL(ieee80211_restart_hw);
  441. #ifdef CONFIG_INET
  442. static int ieee80211_ifa_changed(struct notifier_block *nb,
  443. unsigned long data, void *arg)
  444. {
  445. struct in_ifaddr *ifa = arg;
  446. struct ieee80211_local *local =
  447. container_of(nb, struct ieee80211_local,
  448. ifa_notifier);
  449. struct net_device *ndev = ifa->ifa_dev->dev;
  450. struct wireless_dev *wdev = ndev->ieee80211_ptr;
  451. struct in_device *idev;
  452. struct ieee80211_sub_if_data *sdata;
  453. struct ieee80211_vif_cfg *vif_cfg;
  454. struct ieee80211_if_managed *ifmgd;
  455. int c = 0;
  456. /* Make sure it's our interface that got changed */
  457. if (!wdev)
  458. return NOTIFY_DONE;
  459. if (wdev->wiphy != local->hw.wiphy || !wdev->registered)
  460. return NOTIFY_DONE;
  461. sdata = IEEE80211_DEV_TO_SUB_IF(ndev);
  462. vif_cfg = &sdata->vif.cfg;
  463. /* ARP filtering is only supported in managed mode */
  464. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  465. return NOTIFY_DONE;
  466. idev = __in_dev_get_rtnl(sdata->dev);
  467. if (!idev)
  468. return NOTIFY_DONE;
  469. ifmgd = &sdata->u.mgd;
  470. /*
  471. * The nested here is needed to convince lockdep that this is
  472. * all OK. Yes, we lock the wiphy mutex here while we already
  473. * hold the notifier rwsem, that's the normal case. And yes,
  474. * we also acquire the notifier rwsem again when unregistering
  475. * a netdev while we already hold the wiphy mutex, so it does
  476. * look like a typical ABBA deadlock.
  477. *
  478. * However, both of these things happen with the RTNL held
  479. * already. Therefore, they can't actually happen, since the
  480. * lock orders really are ABC and ACB, which is fine due to
  481. * the RTNL (A).
  482. *
  483. * We still need to prevent recursion, which is accomplished
  484. * by the !wdev->registered check above.
  485. */
  486. mutex_lock_nested(&local->hw.wiphy->mtx, 1);
  487. __acquire(&local->hw.wiphy->mtx);
  488. /* Copy the addresses to the vif config list */
  489. ifa = rtnl_dereference(idev->ifa_list);
  490. while (ifa) {
  491. if (c < IEEE80211_BSS_ARP_ADDR_LIST_LEN)
  492. vif_cfg->arp_addr_list[c] = ifa->ifa_address;
  493. ifa = rtnl_dereference(ifa->ifa_next);
  494. c++;
  495. }
  496. vif_cfg->arp_addr_cnt = c;
  497. /* Configure driver only if associated (which also implies it is up) */
  498. if (ifmgd->associated)
  499. ieee80211_vif_cfg_change_notify(sdata, BSS_CHANGED_ARP_FILTER);
  500. wiphy_unlock(local->hw.wiphy);
  501. return NOTIFY_OK;
  502. }
  503. #endif
  504. #if IS_ENABLED(CONFIG_IPV6)
  505. static int ieee80211_ifa6_changed(struct notifier_block *nb,
  506. unsigned long data, void *arg)
  507. {
  508. struct inet6_ifaddr *ifa = (struct inet6_ifaddr *)arg;
  509. struct inet6_dev *idev = ifa->idev;
  510. struct net_device *ndev = ifa->idev->dev;
  511. struct ieee80211_local *local =
  512. container_of(nb, struct ieee80211_local, ifa6_notifier);
  513. struct wireless_dev *wdev = ndev->ieee80211_ptr;
  514. struct ieee80211_sub_if_data *sdata;
  515. /* Make sure it's our interface that got changed */
  516. if (!wdev || wdev->wiphy != local->hw.wiphy)
  517. return NOTIFY_DONE;
  518. sdata = IEEE80211_DEV_TO_SUB_IF(ndev);
  519. /*
  520. * For now only support station mode. This is mostly because
  521. * doing AP would have to handle AP_VLAN in some way ...
  522. */
  523. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  524. return NOTIFY_DONE;
  525. drv_ipv6_addr_change(local, sdata, idev);
  526. return NOTIFY_OK;
  527. }
  528. #endif
  529. /* There isn't a lot of sense in it, but you can transmit anything you like */
  530. static const struct ieee80211_txrx_stypes
  531. ieee80211_default_mgmt_stypes[NUM_NL80211_IFTYPES] = {
  532. [NL80211_IFTYPE_ADHOC] = {
  533. .tx = 0xffff,
  534. .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  535. BIT(IEEE80211_STYPE_AUTH >> 4) |
  536. BIT(IEEE80211_STYPE_DEAUTH >> 4) |
  537. BIT(IEEE80211_STYPE_PROBE_REQ >> 4),
  538. },
  539. [NL80211_IFTYPE_STATION] = {
  540. .tx = 0xffff,
  541. /*
  542. * To support Pre Association Security Negotiation (PASN) while
  543. * already associated to one AP, allow user space to register to
  544. * Rx authentication frames, so that the user space logic would
  545. * be able to receive/handle authentication frames from a
  546. * different AP as part of PASN.
  547. * It is expected that user space would intelligently register
  548. * for Rx authentication frames, i.e., only when PASN is used
  549. * and configure a match filter only for PASN authentication
  550. * algorithm, as otherwise the MLME functionality of mac80211
  551. * would be broken.
  552. */
  553. .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  554. BIT(IEEE80211_STYPE_AUTH >> 4) |
  555. BIT(IEEE80211_STYPE_PROBE_REQ >> 4),
  556. },
  557. [NL80211_IFTYPE_AP] = {
  558. .tx = 0xffff,
  559. .rx = BIT(IEEE80211_STYPE_ASSOC_REQ >> 4) |
  560. BIT(IEEE80211_STYPE_REASSOC_REQ >> 4) |
  561. BIT(IEEE80211_STYPE_PROBE_REQ >> 4) |
  562. BIT(IEEE80211_STYPE_DISASSOC >> 4) |
  563. BIT(IEEE80211_STYPE_AUTH >> 4) |
  564. BIT(IEEE80211_STYPE_DEAUTH >> 4) |
  565. BIT(IEEE80211_STYPE_ACTION >> 4),
  566. },
  567. [NL80211_IFTYPE_AP_VLAN] = {
  568. /* copy AP */
  569. .tx = 0xffff,
  570. .rx = BIT(IEEE80211_STYPE_ASSOC_REQ >> 4) |
  571. BIT(IEEE80211_STYPE_REASSOC_REQ >> 4) |
  572. BIT(IEEE80211_STYPE_PROBE_REQ >> 4) |
  573. BIT(IEEE80211_STYPE_DISASSOC >> 4) |
  574. BIT(IEEE80211_STYPE_AUTH >> 4) |
  575. BIT(IEEE80211_STYPE_DEAUTH >> 4) |
  576. BIT(IEEE80211_STYPE_ACTION >> 4),
  577. },
  578. [NL80211_IFTYPE_P2P_CLIENT] = {
  579. .tx = 0xffff,
  580. .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  581. BIT(IEEE80211_STYPE_PROBE_REQ >> 4),
  582. },
  583. [NL80211_IFTYPE_P2P_GO] = {
  584. .tx = 0xffff,
  585. .rx = BIT(IEEE80211_STYPE_ASSOC_REQ >> 4) |
  586. BIT(IEEE80211_STYPE_REASSOC_REQ >> 4) |
  587. BIT(IEEE80211_STYPE_PROBE_REQ >> 4) |
  588. BIT(IEEE80211_STYPE_DISASSOC >> 4) |
  589. BIT(IEEE80211_STYPE_AUTH >> 4) |
  590. BIT(IEEE80211_STYPE_DEAUTH >> 4) |
  591. BIT(IEEE80211_STYPE_ACTION >> 4),
  592. },
  593. [NL80211_IFTYPE_MESH_POINT] = {
  594. .tx = 0xffff,
  595. .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  596. BIT(IEEE80211_STYPE_AUTH >> 4) |
  597. BIT(IEEE80211_STYPE_DEAUTH >> 4),
  598. },
  599. [NL80211_IFTYPE_P2P_DEVICE] = {
  600. .tx = 0xffff,
  601. .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  602. BIT(IEEE80211_STYPE_PROBE_REQ >> 4),
  603. },
  604. };
  605. static const struct ieee80211_ht_cap mac80211_ht_capa_mod_mask = {
  606. .ampdu_params_info = IEEE80211_HT_AMPDU_PARM_FACTOR |
  607. IEEE80211_HT_AMPDU_PARM_DENSITY,
  608. .cap_info = cpu_to_le16(IEEE80211_HT_CAP_SUP_WIDTH_20_40 |
  609. IEEE80211_HT_CAP_MAX_AMSDU |
  610. IEEE80211_HT_CAP_SGI_20 |
  611. IEEE80211_HT_CAP_SGI_40 |
  612. IEEE80211_HT_CAP_TX_STBC |
  613. IEEE80211_HT_CAP_RX_STBC |
  614. IEEE80211_HT_CAP_LDPC_CODING |
  615. IEEE80211_HT_CAP_40MHZ_INTOLERANT),
  616. .mcs = {
  617. .rx_mask = { 0xff, 0xff, 0xff, 0xff, 0xff,
  618. 0xff, 0xff, 0xff, 0xff, 0xff, },
  619. },
  620. };
  621. static const struct ieee80211_vht_cap mac80211_vht_capa_mod_mask = {
  622. .vht_cap_info =
  623. cpu_to_le32(IEEE80211_VHT_CAP_RXLDPC |
  624. IEEE80211_VHT_CAP_SHORT_GI_80 |
  625. IEEE80211_VHT_CAP_SHORT_GI_160 |
  626. IEEE80211_VHT_CAP_RXSTBC_MASK |
  627. IEEE80211_VHT_CAP_TXSTBC |
  628. IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE |
  629. IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
  630. IEEE80211_VHT_CAP_TX_ANTENNA_PATTERN |
  631. IEEE80211_VHT_CAP_RX_ANTENNA_PATTERN |
  632. IEEE80211_VHT_CAP_MAX_A_MPDU_LENGTH_EXPONENT_MASK),
  633. .supp_mcs = {
  634. .rx_mcs_map = cpu_to_le16(~0),
  635. .tx_mcs_map = cpu_to_le16(~0),
  636. },
  637. };
  638. struct ieee80211_hw *ieee80211_alloc_hw_nm(size_t priv_data_len,
  639. const struct ieee80211_ops *ops,
  640. const char *requested_name)
  641. {
  642. struct ieee80211_local *local;
  643. int priv_size, i;
  644. struct wiphy *wiphy;
  645. bool emulate_chanctx;
  646. if (WARN_ON(!ops->tx || !ops->start || !ops->stop || !ops->config ||
  647. !ops->add_interface || !ops->remove_interface ||
  648. !ops->configure_filter || !ops->wake_tx_queue))
  649. return NULL;
  650. if (WARN_ON(ops->sta_state && (ops->sta_add || ops->sta_remove)))
  651. return NULL;
  652. if (WARN_ON(!!ops->link_info_changed != !!ops->vif_cfg_changed ||
  653. (ops->link_info_changed && ops->bss_info_changed)))
  654. return NULL;
  655. /* check all or no channel context operations exist */
  656. if (ops->add_chanctx == ieee80211_emulate_add_chanctx &&
  657. ops->remove_chanctx == ieee80211_emulate_remove_chanctx &&
  658. ops->change_chanctx == ieee80211_emulate_change_chanctx) {
  659. if (WARN_ON(ops->assign_vif_chanctx ||
  660. ops->unassign_vif_chanctx))
  661. return NULL;
  662. emulate_chanctx = true;
  663. } else {
  664. if (WARN_ON(ops->add_chanctx == ieee80211_emulate_add_chanctx ||
  665. ops->remove_chanctx == ieee80211_emulate_remove_chanctx ||
  666. ops->change_chanctx == ieee80211_emulate_change_chanctx))
  667. return NULL;
  668. if (WARN_ON(!ops->add_chanctx ||
  669. !ops->remove_chanctx ||
  670. !ops->change_chanctx ||
  671. !ops->assign_vif_chanctx ||
  672. !ops->unassign_vif_chanctx))
  673. return NULL;
  674. emulate_chanctx = false;
  675. }
  676. /* Ensure 32-byte alignment of our private data and hw private data.
  677. * We use the wiphy priv data for both our ieee80211_local and for
  678. * the driver's private data
  679. *
  680. * In memory it'll be like this:
  681. *
  682. * +-------------------------+
  683. * | struct wiphy |
  684. * +-------------------------+
  685. * | struct ieee80211_local |
  686. * +-------------------------+
  687. * | driver's private data |
  688. * +-------------------------+
  689. *
  690. */
  691. priv_size = ALIGN(sizeof(*local), NETDEV_ALIGN) + priv_data_len;
  692. wiphy = wiphy_new_nm(&mac80211_config_ops, priv_size, requested_name);
  693. if (!wiphy)
  694. return NULL;
  695. wiphy->mgmt_stypes = ieee80211_default_mgmt_stypes;
  696. wiphy->privid = mac80211_wiphy_privid;
  697. wiphy->flags |= WIPHY_FLAG_NETNS_OK |
  698. WIPHY_FLAG_4ADDR_AP |
  699. WIPHY_FLAG_4ADDR_STATION |
  700. WIPHY_FLAG_REPORTS_OBSS |
  701. WIPHY_FLAG_OFFCHAN_TX;
  702. if (emulate_chanctx || ops->remain_on_channel)
  703. wiphy->flags |= WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL;
  704. wiphy->features |= NL80211_FEATURE_SK_TX_STATUS |
  705. NL80211_FEATURE_SAE |
  706. NL80211_FEATURE_HT_IBSS |
  707. NL80211_FEATURE_VIF_TXPOWER |
  708. NL80211_FEATURE_MAC_ON_CREATE |
  709. NL80211_FEATURE_USERSPACE_MPM |
  710. NL80211_FEATURE_FULL_AP_CLIENT_STATE;
  711. wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_FILS_STA);
  712. wiphy_ext_feature_set(wiphy,
  713. NL80211_EXT_FEATURE_CONTROL_PORT_OVER_NL80211);
  714. wiphy_ext_feature_set(wiphy,
  715. NL80211_EXT_FEATURE_CONTROL_PORT_NO_PREAUTH);
  716. wiphy_ext_feature_set(wiphy,
  717. NL80211_EXT_FEATURE_CONTROL_PORT_OVER_NL80211_TX_STATUS);
  718. wiphy_ext_feature_set(wiphy,
  719. NL80211_EXT_FEATURE_SCAN_FREQ_KHZ);
  720. wiphy_ext_feature_set(wiphy,
  721. NL80211_EXT_FEATURE_POWERED_ADDR_CHANGE);
  722. if (!ops->hw_scan) {
  723. wiphy->features |= NL80211_FEATURE_LOW_PRIORITY_SCAN |
  724. NL80211_FEATURE_AP_SCAN;
  725. /*
  726. * if the driver behaves correctly using the probe request
  727. * (template) from mac80211, then both of these should be
  728. * supported even with hw scan - but let drivers opt in.
  729. */
  730. wiphy_ext_feature_set(wiphy,
  731. NL80211_EXT_FEATURE_SCAN_RANDOM_SN);
  732. wiphy_ext_feature_set(wiphy,
  733. NL80211_EXT_FEATURE_SCAN_MIN_PREQ_CONTENT);
  734. }
  735. if (!ops->set_key) {
  736. wiphy->flags |= WIPHY_FLAG_IBSS_RSN;
  737. wiphy_ext_feature_set(wiphy,
  738. NL80211_EXT_FEATURE_SPP_AMSDU_SUPPORT);
  739. }
  740. wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_TXQS);
  741. wiphy_ext_feature_set(wiphy, NL80211_EXT_FEATURE_RRM);
  742. wiphy->bss_priv_size = sizeof(struct ieee80211_bss);
  743. local = wiphy_priv(wiphy);
  744. if (sta_info_init(local))
  745. goto err_free;
  746. local->hw.wiphy = wiphy;
  747. local->hw.priv = (char *)local + ALIGN(sizeof(*local), NETDEV_ALIGN);
  748. local->ops = ops;
  749. local->emulate_chanctx = emulate_chanctx;
  750. if (emulate_chanctx)
  751. ieee80211_hw_set(&local->hw, CHANCTX_STA_CSA);
  752. /*
  753. * We need a bit of data queued to build aggregates properly, so
  754. * instruct the TCP stack to allow more than a single ms of data
  755. * to be queued in the stack. The value is a bit-shift of 1
  756. * second, so 7 is ~8ms of queued data. Only affects local TCP
  757. * sockets.
  758. * This is the default, anyhow - drivers may need to override it
  759. * for local reasons (longer buffers, longer completion time, or
  760. * similar).
  761. */
  762. local->hw.tx_sk_pacing_shift = 7;
  763. /* set up some defaults */
  764. local->hw.queues = 1;
  765. local->hw.max_rates = 1;
  766. local->hw.max_report_rates = 0;
  767. local->hw.max_rx_aggregation_subframes = IEEE80211_MAX_AMPDU_BUF_HT;
  768. local->hw.max_tx_aggregation_subframes = IEEE80211_MAX_AMPDU_BUF_HT;
  769. local->hw.offchannel_tx_hw_queue = IEEE80211_INVAL_HW_QUEUE;
  770. local->hw.conf.long_frame_max_tx_count = wiphy->retry_long;
  771. local->hw.conf.short_frame_max_tx_count = wiphy->retry_short;
  772. local->hw.radiotap_mcs_details = IEEE80211_RADIOTAP_MCS_HAVE_MCS |
  773. IEEE80211_RADIOTAP_MCS_HAVE_GI |
  774. IEEE80211_RADIOTAP_MCS_HAVE_BW;
  775. local->hw.radiotap_vht_details = IEEE80211_RADIOTAP_VHT_KNOWN_GI |
  776. IEEE80211_RADIOTAP_VHT_KNOWN_BANDWIDTH;
  777. local->hw.uapsd_queues = IEEE80211_DEFAULT_UAPSD_QUEUES;
  778. local->hw.uapsd_max_sp_len = IEEE80211_DEFAULT_MAX_SP_LEN;
  779. local->hw.max_mtu = IEEE80211_MAX_DATA_LEN;
  780. local->user_power_level = IEEE80211_UNSET_POWER_LEVEL;
  781. wiphy->ht_capa_mod_mask = &mac80211_ht_capa_mod_mask;
  782. wiphy->vht_capa_mod_mask = &mac80211_vht_capa_mod_mask;
  783. local->ext_capa[7] = WLAN_EXT_CAPA8_OPMODE_NOTIF;
  784. wiphy->extended_capabilities = local->ext_capa;
  785. wiphy->extended_capabilities_mask = local->ext_capa;
  786. wiphy->extended_capabilities_len =
  787. ARRAY_SIZE(local->ext_capa);
  788. INIT_LIST_HEAD(&local->interfaces);
  789. INIT_LIST_HEAD(&local->mon_list);
  790. __hw_addr_init(&local->mc_list);
  791. mutex_init(&local->iflist_mtx);
  792. spin_lock_init(&local->filter_lock);
  793. spin_lock_init(&local->rx_path_lock);
  794. spin_lock_init(&local->queue_stop_reason_lock);
  795. for (i = 0; i < IEEE80211_NUM_ACS; i++) {
  796. INIT_LIST_HEAD(&local->active_txqs[i]);
  797. spin_lock_init(&local->active_txq_lock[i]);
  798. local->aql_txq_limit_low[i] = IEEE80211_DEFAULT_AQL_TXQ_LIMIT_L;
  799. local->aql_txq_limit_high[i] =
  800. IEEE80211_DEFAULT_AQL_TXQ_LIMIT_H;
  801. atomic_set(&local->aql_ac_pending_airtime[i], 0);
  802. }
  803. local->airtime_flags = AIRTIME_USE_TX | AIRTIME_USE_RX;
  804. local->aql_threshold = IEEE80211_AQL_THRESHOLD;
  805. atomic_set(&local->aql_total_pending_airtime, 0);
  806. spin_lock_init(&local->handle_wake_tx_queue_lock);
  807. INIT_LIST_HEAD(&local->chanctx_list);
  808. wiphy_delayed_work_init(&local->scan_work, ieee80211_scan_work);
  809. INIT_WORK(&local->restart_work, ieee80211_restart_work);
  810. wiphy_work_init(&local->radar_detected_work,
  811. ieee80211_dfs_radar_detected_work);
  812. wiphy_work_init(&local->reconfig_filter, ieee80211_reconfig_filter);
  813. wiphy_work_init(&local->dynamic_ps_enable_work,
  814. ieee80211_dynamic_ps_enable_work);
  815. wiphy_work_init(&local->dynamic_ps_disable_work,
  816. ieee80211_dynamic_ps_disable_work);
  817. timer_setup(&local->dynamic_ps_timer, ieee80211_dynamic_ps_timer, 0);
  818. wiphy_work_init(&local->sched_scan_stopped_work,
  819. ieee80211_sched_scan_stopped_work);
  820. spin_lock_init(&local->ack_status_lock);
  821. idr_init(&local->ack_status_frames);
  822. for (i = 0; i < IEEE80211_MAX_QUEUES; i++) {
  823. skb_queue_head_init(&local->pending[i]);
  824. atomic_set(&local->agg_queue_stop[i], 0);
  825. }
  826. tasklet_setup(&local->tx_pending_tasklet, ieee80211_tx_pending);
  827. tasklet_setup(&local->wake_txqs_tasklet, ieee80211_wake_txqs);
  828. tasklet_setup(&local->tasklet, ieee80211_tasklet_handler);
  829. skb_queue_head_init(&local->skb_queue);
  830. skb_queue_head_init(&local->skb_queue_unreliable);
  831. ieee80211_alloc_led_names(local);
  832. ieee80211_roc_setup(local);
  833. local->hw.radiotap_timestamp.units_pos = -1;
  834. local->hw.radiotap_timestamp.accuracy = -1;
  835. return &local->hw;
  836. err_free:
  837. wiphy_free(wiphy);
  838. return NULL;
  839. }
  840. EXPORT_SYMBOL(ieee80211_alloc_hw_nm);
  841. static int ieee80211_init_cipher_suites(struct ieee80211_local *local)
  842. {
  843. bool have_wep = !fips_enabled; /* FIPS does not permit the use of RC4 */
  844. bool have_mfp = ieee80211_hw_check(&local->hw, MFP_CAPABLE);
  845. int r = 0, w = 0;
  846. u32 *suites;
  847. static const u32 cipher_suites[] = {
  848. /* keep WEP first, it may be removed below */
  849. WLAN_CIPHER_SUITE_WEP40,
  850. WLAN_CIPHER_SUITE_WEP104,
  851. WLAN_CIPHER_SUITE_TKIP,
  852. WLAN_CIPHER_SUITE_CCMP,
  853. WLAN_CIPHER_SUITE_CCMP_256,
  854. WLAN_CIPHER_SUITE_GCMP,
  855. WLAN_CIPHER_SUITE_GCMP_256,
  856. /* keep last -- depends on hw flags! */
  857. WLAN_CIPHER_SUITE_AES_CMAC,
  858. WLAN_CIPHER_SUITE_BIP_CMAC_256,
  859. WLAN_CIPHER_SUITE_BIP_GMAC_128,
  860. WLAN_CIPHER_SUITE_BIP_GMAC_256,
  861. };
  862. if (ieee80211_hw_check(&local->hw, SW_CRYPTO_CONTROL) ||
  863. local->hw.wiphy->cipher_suites) {
  864. /* If the driver advertises, or doesn't support SW crypto,
  865. * we only need to remove WEP if necessary.
  866. */
  867. if (have_wep)
  868. return 0;
  869. /* well if it has _no_ ciphers ... fine */
  870. if (!local->hw.wiphy->n_cipher_suites)
  871. return 0;
  872. /* Driver provides cipher suites, but we need to exclude WEP */
  873. suites = kmemdup_array(local->hw.wiphy->cipher_suites,
  874. local->hw.wiphy->n_cipher_suites,
  875. sizeof(u32), GFP_KERNEL);
  876. if (!suites)
  877. return -ENOMEM;
  878. for (r = 0; r < local->hw.wiphy->n_cipher_suites; r++) {
  879. u32 suite = local->hw.wiphy->cipher_suites[r];
  880. if (suite == WLAN_CIPHER_SUITE_WEP40 ||
  881. suite == WLAN_CIPHER_SUITE_WEP104)
  882. continue;
  883. suites[w++] = suite;
  884. }
  885. } else {
  886. /* assign the (software supported and perhaps offloaded)
  887. * cipher suites
  888. */
  889. local->hw.wiphy->cipher_suites = cipher_suites;
  890. local->hw.wiphy->n_cipher_suites = ARRAY_SIZE(cipher_suites);
  891. if (!have_mfp)
  892. local->hw.wiphy->n_cipher_suites -= 4;
  893. if (!have_wep) {
  894. local->hw.wiphy->cipher_suites += 2;
  895. local->hw.wiphy->n_cipher_suites -= 2;
  896. }
  897. /* not dynamically allocated, so just return */
  898. return 0;
  899. }
  900. local->hw.wiphy->cipher_suites = suites;
  901. local->hw.wiphy->n_cipher_suites = w;
  902. local->wiphy_ciphers_allocated = true;
  903. return 0;
  904. }
  905. static bool
  906. ieee80211_ifcomb_check(const struct ieee80211_iface_combination *c, int n_comb)
  907. {
  908. int i, j;
  909. for (i = 0; i < n_comb; i++, c++) {
  910. /* DFS is not supported with multi-channel combinations yet */
  911. if (c->radar_detect_widths &&
  912. c->num_different_channels > 1)
  913. return false;
  914. /* mac80211 doesn't support more than one IBSS interface */
  915. for (j = 0; j < c->n_limits; j++)
  916. if ((c->limits[j].types & BIT(NL80211_IFTYPE_ADHOC)) &&
  917. c->limits[j].max > 1)
  918. return false;
  919. }
  920. return true;
  921. }
  922. int ieee80211_register_hw(struct ieee80211_hw *hw)
  923. {
  924. struct ieee80211_local *local = hw_to_local(hw);
  925. int result, i;
  926. enum nl80211_band band;
  927. int channels, max_bitrates;
  928. bool supp_ht, supp_vht, supp_he, supp_eht;
  929. struct cfg80211_chan_def dflt_chandef = {};
  930. if (ieee80211_hw_check(hw, QUEUE_CONTROL) &&
  931. (local->hw.offchannel_tx_hw_queue == IEEE80211_INVAL_HW_QUEUE ||
  932. local->hw.offchannel_tx_hw_queue >= local->hw.queues))
  933. return -EINVAL;
  934. if ((hw->wiphy->features & NL80211_FEATURE_TDLS_CHANNEL_SWITCH) &&
  935. (!local->ops->tdls_channel_switch ||
  936. !local->ops->tdls_cancel_channel_switch ||
  937. !local->ops->tdls_recv_channel_switch))
  938. return -EOPNOTSUPP;
  939. if (WARN_ON(ieee80211_hw_check(hw, SUPPORTS_TX_FRAG) &&
  940. !local->ops->set_frag_threshold))
  941. return -EINVAL;
  942. if (WARN_ON(local->hw.wiphy->interface_modes &
  943. BIT(NL80211_IFTYPE_NAN) &&
  944. (!local->ops->start_nan || !local->ops->stop_nan)))
  945. return -EINVAL;
  946. if (hw->wiphy->flags & WIPHY_FLAG_SUPPORTS_MLO) {
  947. /*
  948. * For drivers capable of doing MLO, assume modern driver
  949. * or firmware facilities, so software doesn't have to do
  950. * as much, e.g. monitoring beacons would be hard if we
  951. * might not even know which link is active at which time.
  952. */
  953. if (WARN_ON(local->emulate_chanctx))
  954. return -EINVAL;
  955. if (WARN_ON(!local->ops->link_info_changed))
  956. return -EINVAL;
  957. if (WARN_ON(!ieee80211_hw_check(hw, HAS_RATE_CONTROL)))
  958. return -EINVAL;
  959. if (WARN_ON(!ieee80211_hw_check(hw, AMPDU_AGGREGATION)))
  960. return -EINVAL;
  961. if (WARN_ON(ieee80211_hw_check(hw, HOST_BROADCAST_PS_BUFFERING)))
  962. return -EINVAL;
  963. if (WARN_ON(ieee80211_hw_check(hw, SUPPORTS_PS) &&
  964. (!ieee80211_hw_check(hw, SUPPORTS_DYNAMIC_PS) ||
  965. ieee80211_hw_check(hw, PS_NULLFUNC_STACK))))
  966. return -EINVAL;
  967. if (WARN_ON(!ieee80211_hw_check(hw, MFP_CAPABLE)))
  968. return -EINVAL;
  969. if (WARN_ON(!ieee80211_hw_check(hw, CONNECTION_MONITOR)))
  970. return -EINVAL;
  971. if (WARN_ON(ieee80211_hw_check(hw, NEED_DTIM_BEFORE_ASSOC)))
  972. return -EINVAL;
  973. if (WARN_ON(ieee80211_hw_check(hw, TIMING_BEACON_ONLY)))
  974. return -EINVAL;
  975. if (WARN_ON(!ieee80211_hw_check(hw, AP_LINK_PS)))
  976. return -EINVAL;
  977. }
  978. #ifdef CONFIG_PM
  979. if (hw->wiphy->wowlan && (!local->ops->suspend || !local->ops->resume))
  980. return -EINVAL;
  981. #endif
  982. if (local->emulate_chanctx) {
  983. for (i = 0; i < local->hw.wiphy->n_iface_combinations; i++) {
  984. const struct ieee80211_iface_combination *comb;
  985. comb = &local->hw.wiphy->iface_combinations[i];
  986. if (comb->num_different_channels > 1)
  987. return -EINVAL;
  988. }
  989. }
  990. if (hw->wiphy->n_radio) {
  991. for (i = 0; i < hw->wiphy->n_radio; i++) {
  992. const struct wiphy_radio *radio = &hw->wiphy->radio[i];
  993. if (!ieee80211_ifcomb_check(radio->iface_combinations,
  994. radio->n_iface_combinations))
  995. return -EINVAL;
  996. }
  997. } else {
  998. if (!ieee80211_ifcomb_check(hw->wiphy->iface_combinations,
  999. hw->wiphy->n_iface_combinations))
  1000. return -EINVAL;
  1001. }
  1002. /* Only HW csum features are currently compatible with mac80211 */
  1003. if (WARN_ON(hw->netdev_features & ~MAC80211_SUPPORTED_FEATURES))
  1004. return -EINVAL;
  1005. if (hw->max_report_rates == 0)
  1006. hw->max_report_rates = hw->max_rates;
  1007. local->rx_chains = 1;
  1008. /*
  1009. * generic code guarantees at least one band,
  1010. * set this very early because much code assumes
  1011. * that hw.conf.channel is assigned
  1012. */
  1013. channels = 0;
  1014. max_bitrates = 0;
  1015. supp_ht = false;
  1016. supp_vht = false;
  1017. supp_he = false;
  1018. supp_eht = false;
  1019. for (band = 0; band < NUM_NL80211_BANDS; band++) {
  1020. const struct ieee80211_sband_iftype_data *iftd;
  1021. struct ieee80211_supported_band *sband;
  1022. sband = local->hw.wiphy->bands[band];
  1023. if (!sband)
  1024. continue;
  1025. if (!dflt_chandef.chan) {
  1026. /*
  1027. * Assign the first enabled channel to dflt_chandef
  1028. * from the list of channels
  1029. */
  1030. for (i = 0; i < sband->n_channels; i++)
  1031. if (!(sband->channels[i].flags &
  1032. IEEE80211_CHAN_DISABLED))
  1033. break;
  1034. /* if none found then use the first anyway */
  1035. if (i == sband->n_channels)
  1036. i = 0;
  1037. cfg80211_chandef_create(&dflt_chandef,
  1038. &sband->channels[i],
  1039. NL80211_CHAN_NO_HT);
  1040. /* init channel we're on */
  1041. local->monitor_chanreq.oper = dflt_chandef;
  1042. if (local->emulate_chanctx) {
  1043. local->dflt_chandef = dflt_chandef;
  1044. local->hw.conf.chandef = dflt_chandef;
  1045. }
  1046. }
  1047. channels += sband->n_channels;
  1048. /*
  1049. * Due to the way the aggregation code handles this and it
  1050. * being an HT capability, we can't really support delayed
  1051. * BA in MLO (yet).
  1052. */
  1053. if (WARN_ON(sband->ht_cap.ht_supported &&
  1054. (sband->ht_cap.cap & IEEE80211_HT_CAP_DELAY_BA) &&
  1055. hw->wiphy->flags & WIPHY_FLAG_SUPPORTS_MLO))
  1056. return -EINVAL;
  1057. if (max_bitrates < sband->n_bitrates)
  1058. max_bitrates = sband->n_bitrates;
  1059. supp_ht = supp_ht || sband->ht_cap.ht_supported;
  1060. supp_vht = supp_vht || sband->vht_cap.vht_supported;
  1061. for_each_sband_iftype_data(sband, i, iftd) {
  1062. u8 he_40_mhz_cap;
  1063. supp_he = supp_he || iftd->he_cap.has_he;
  1064. supp_eht = supp_eht || iftd->eht_cap.has_eht;
  1065. if (band == NL80211_BAND_2GHZ)
  1066. he_40_mhz_cap =
  1067. IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_IN_2G;
  1068. else
  1069. he_40_mhz_cap =
  1070. IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_80MHZ_IN_5G;
  1071. /* currently no support for HE client where HT has 40 MHz but not HT */
  1072. if (iftd->he_cap.has_he &&
  1073. iftd->types_mask & (BIT(NL80211_IFTYPE_STATION) |
  1074. BIT(NL80211_IFTYPE_P2P_CLIENT)) &&
  1075. sband->ht_cap.ht_supported &&
  1076. sband->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40 &&
  1077. !(iftd->he_cap.he_cap_elem.phy_cap_info[0] & he_40_mhz_cap))
  1078. return -EINVAL;
  1079. }
  1080. /* HT, VHT, HE require QoS, thus >= 4 queues */
  1081. if (WARN_ON(local->hw.queues < IEEE80211_NUM_ACS &&
  1082. (supp_ht || supp_vht || supp_he)))
  1083. return -EINVAL;
  1084. /* EHT requires HE support */
  1085. if (WARN_ON(supp_eht && !supp_he))
  1086. return -EINVAL;
  1087. if (!sband->ht_cap.ht_supported)
  1088. continue;
  1089. /* TODO: consider VHT for RX chains, hopefully it's the same */
  1090. local->rx_chains =
  1091. max(ieee80211_mcs_to_chains(&sband->ht_cap.mcs),
  1092. local->rx_chains);
  1093. /* no need to mask, SM_PS_DISABLED has all bits set */
  1094. sband->ht_cap.cap |= WLAN_HT_CAP_SM_PS_DISABLED <<
  1095. IEEE80211_HT_CAP_SM_PS_SHIFT;
  1096. }
  1097. /* if low-level driver supports AP, we also support VLAN.
  1098. * drivers advertising SW_CRYPTO_CONTROL should enable AP_VLAN
  1099. * based on their support to transmit SW encrypted packets.
  1100. */
  1101. if (local->hw.wiphy->interface_modes & BIT(NL80211_IFTYPE_AP) &&
  1102. !ieee80211_hw_check(&local->hw, SW_CRYPTO_CONTROL)) {
  1103. hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_AP_VLAN);
  1104. hw->wiphy->software_iftypes |= BIT(NL80211_IFTYPE_AP_VLAN);
  1105. }
  1106. /* mac80211 always supports monitor */
  1107. hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_MONITOR);
  1108. hw->wiphy->software_iftypes |= BIT(NL80211_IFTYPE_MONITOR);
  1109. local->int_scan_req = kzalloc(sizeof(*local->int_scan_req) +
  1110. sizeof(void *) * channels, GFP_KERNEL);
  1111. if (!local->int_scan_req)
  1112. return -ENOMEM;
  1113. eth_broadcast_addr(local->int_scan_req->bssid);
  1114. for (band = 0; band < NUM_NL80211_BANDS; band++) {
  1115. if (!local->hw.wiphy->bands[band])
  1116. continue;
  1117. local->int_scan_req->rates[band] = (u32) -1;
  1118. }
  1119. #ifndef CONFIG_MAC80211_MESH
  1120. /* mesh depends on Kconfig, but drivers should set it if they want */
  1121. local->hw.wiphy->interface_modes &= ~BIT(NL80211_IFTYPE_MESH_POINT);
  1122. #endif
  1123. /* if the underlying driver supports mesh, mac80211 will (at least)
  1124. * provide routing of mesh authentication frames to userspace */
  1125. if (local->hw.wiphy->interface_modes & BIT(NL80211_IFTYPE_MESH_POINT))
  1126. local->hw.wiphy->flags |= WIPHY_FLAG_MESH_AUTH;
  1127. /* mac80211 supports control port protocol changing */
  1128. local->hw.wiphy->flags |= WIPHY_FLAG_CONTROL_PORT_PROTOCOL;
  1129. if (ieee80211_hw_check(&local->hw, SIGNAL_DBM)) {
  1130. local->hw.wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
  1131. } else if (ieee80211_hw_check(&local->hw, SIGNAL_UNSPEC)) {
  1132. local->hw.wiphy->signal_type = CFG80211_SIGNAL_TYPE_UNSPEC;
  1133. if (hw->max_signal <= 0) {
  1134. result = -EINVAL;
  1135. goto fail_workqueue;
  1136. }
  1137. }
  1138. /* Mac80211 and therefore all drivers using SW crypto only
  1139. * are able to handle PTK rekeys and Extended Key ID.
  1140. */
  1141. if (!local->ops->set_key) {
  1142. wiphy_ext_feature_set(local->hw.wiphy,
  1143. NL80211_EXT_FEATURE_CAN_REPLACE_PTK0);
  1144. wiphy_ext_feature_set(local->hw.wiphy,
  1145. NL80211_EXT_FEATURE_EXT_KEY_ID);
  1146. }
  1147. if (local->hw.wiphy->interface_modes & BIT(NL80211_IFTYPE_ADHOC))
  1148. wiphy_ext_feature_set(local->hw.wiphy,
  1149. NL80211_EXT_FEATURE_DEL_IBSS_STA);
  1150. /*
  1151. * Calculate scan IE length -- we need this to alloc
  1152. * memory and to subtract from the driver limit. It
  1153. * includes the DS Params, (extended) supported rates, and HT
  1154. * information -- SSID is the driver's responsibility.
  1155. */
  1156. local->scan_ies_len = 4 + max_bitrates /* (ext) supp rates */ +
  1157. 3 /* DS Params */;
  1158. if (supp_ht)
  1159. local->scan_ies_len += 2 + sizeof(struct ieee80211_ht_cap);
  1160. if (supp_vht)
  1161. local->scan_ies_len +=
  1162. 2 + sizeof(struct ieee80211_vht_cap);
  1163. /*
  1164. * HE cap element is variable in size - set len to allow max size */
  1165. if (supp_he) {
  1166. local->scan_ies_len +=
  1167. 3 + sizeof(struct ieee80211_he_cap_elem) +
  1168. sizeof(struct ieee80211_he_mcs_nss_supp) +
  1169. IEEE80211_HE_PPE_THRES_MAX_LEN;
  1170. if (supp_eht)
  1171. local->scan_ies_len +=
  1172. 3 + sizeof(struct ieee80211_eht_cap_elem) +
  1173. sizeof(struct ieee80211_eht_mcs_nss_supp) +
  1174. IEEE80211_EHT_PPE_THRES_MAX_LEN;
  1175. }
  1176. if (!local->ops->hw_scan) {
  1177. /* For hw_scan, driver needs to set these up. */
  1178. local->hw.wiphy->max_scan_ssids = 4;
  1179. local->hw.wiphy->max_scan_ie_len = IEEE80211_MAX_DATA_LEN;
  1180. }
  1181. /*
  1182. * If the driver supports any scan IEs, then assume the
  1183. * limit includes the IEs mac80211 will add, otherwise
  1184. * leave it at zero and let the driver sort it out; we
  1185. * still pass our IEs to the driver but userspace will
  1186. * not be allowed to in that case.
  1187. */
  1188. if (local->hw.wiphy->max_scan_ie_len)
  1189. local->hw.wiphy->max_scan_ie_len -= local->scan_ies_len;
  1190. result = ieee80211_init_cipher_suites(local);
  1191. if (result < 0)
  1192. goto fail_workqueue;
  1193. if (!local->ops->remain_on_channel)
  1194. local->hw.wiphy->max_remain_on_channel_duration = 5000;
  1195. /* mac80211 based drivers don't support internal TDLS setup */
  1196. if (local->hw.wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS)
  1197. local->hw.wiphy->flags |= WIPHY_FLAG_TDLS_EXTERNAL_SETUP;
  1198. /* mac80211 supports eCSA, if the driver supports STA CSA at all */
  1199. if (ieee80211_hw_check(&local->hw, CHANCTX_STA_CSA))
  1200. local->ext_capa[0] |= WLAN_EXT_CAPA1_EXT_CHANNEL_SWITCHING;
  1201. /* mac80211 supports multi BSSID, if the driver supports it */
  1202. if (ieee80211_hw_check(&local->hw, SUPPORTS_MULTI_BSSID)) {
  1203. local->hw.wiphy->support_mbssid = true;
  1204. if (ieee80211_hw_check(&local->hw,
  1205. SUPPORTS_ONLY_HE_MULTI_BSSID))
  1206. local->hw.wiphy->support_only_he_mbssid = true;
  1207. else
  1208. local->ext_capa[2] |=
  1209. WLAN_EXT_CAPA3_MULTI_BSSID_SUPPORT;
  1210. }
  1211. local->hw.wiphy->max_num_csa_counters = IEEE80211_MAX_CNTDWN_COUNTERS_NUM;
  1212. /*
  1213. * We use the number of queues for feature tests (QoS, HT) internally
  1214. * so restrict them appropriately.
  1215. */
  1216. if (hw->queues > IEEE80211_MAX_QUEUES)
  1217. hw->queues = IEEE80211_MAX_QUEUES;
  1218. local->workqueue =
  1219. alloc_ordered_workqueue("%s", 0, wiphy_name(local->hw.wiphy));
  1220. if (!local->workqueue) {
  1221. result = -ENOMEM;
  1222. goto fail_workqueue;
  1223. }
  1224. /*
  1225. * The hardware needs headroom for sending the frame,
  1226. * and we need some headroom for passing the frame to monitor
  1227. * interfaces, but never both at the same time.
  1228. */
  1229. local->tx_headroom = max_t(unsigned int , local->hw.extra_tx_headroom,
  1230. IEEE80211_TX_STATUS_HEADROOM);
  1231. /*
  1232. * if the driver doesn't specify a max listen interval we
  1233. * use 5 which should be a safe default
  1234. */
  1235. if (local->hw.max_listen_interval == 0)
  1236. local->hw.max_listen_interval = 5;
  1237. local->hw.conf.listen_interval = local->hw.max_listen_interval;
  1238. local->dynamic_ps_forced_timeout = -1;
  1239. if (!local->hw.max_nan_de_entries)
  1240. local->hw.max_nan_de_entries = IEEE80211_MAX_NAN_INSTANCE_ID;
  1241. if (!local->hw.weight_multiplier)
  1242. local->hw.weight_multiplier = 1;
  1243. ieee80211_wep_init(local);
  1244. local->hw.conf.flags = IEEE80211_CONF_IDLE;
  1245. ieee80211_led_init(local);
  1246. result = ieee80211_txq_setup_flows(local);
  1247. if (result)
  1248. goto fail_flows;
  1249. rtnl_lock();
  1250. result = ieee80211_init_rate_ctrl_alg(local,
  1251. hw->rate_control_algorithm);
  1252. rtnl_unlock();
  1253. if (result < 0) {
  1254. wiphy_debug(local->hw.wiphy,
  1255. "Failed to initialize rate control algorithm\n");
  1256. goto fail_rate;
  1257. }
  1258. if (local->rate_ctrl) {
  1259. clear_bit(IEEE80211_HW_SUPPORTS_VHT_EXT_NSS_BW, hw->flags);
  1260. if (local->rate_ctrl->ops->capa & RATE_CTRL_CAPA_VHT_EXT_NSS_BW)
  1261. ieee80211_hw_set(hw, SUPPORTS_VHT_EXT_NSS_BW);
  1262. }
  1263. /*
  1264. * If the VHT capabilities don't have IEEE80211_VHT_EXT_NSS_BW_CAPABLE,
  1265. * or have it when we don't, copy the sband structure and set/clear it.
  1266. * This is necessary because rate scaling algorithms could be switched
  1267. * and have different support values.
  1268. * Print a message so that in the common case the reallocation can be
  1269. * avoided.
  1270. */
  1271. BUILD_BUG_ON(NUM_NL80211_BANDS > 8 * sizeof(local->sband_allocated));
  1272. for (band = 0; band < NUM_NL80211_BANDS; band++) {
  1273. struct ieee80211_supported_band *sband;
  1274. bool local_cap, ie_cap;
  1275. local_cap = ieee80211_hw_check(hw, SUPPORTS_VHT_EXT_NSS_BW);
  1276. sband = local->hw.wiphy->bands[band];
  1277. if (!sband || !sband->vht_cap.vht_supported)
  1278. continue;
  1279. ie_cap = !!(sband->vht_cap.vht_mcs.tx_highest &
  1280. cpu_to_le16(IEEE80211_VHT_EXT_NSS_BW_CAPABLE));
  1281. if (local_cap == ie_cap)
  1282. continue;
  1283. sband = kmemdup(sband, sizeof(*sband), GFP_KERNEL);
  1284. if (!sband) {
  1285. result = -ENOMEM;
  1286. goto fail_rate;
  1287. }
  1288. wiphy_dbg(hw->wiphy, "copying sband (band %d) due to VHT EXT NSS BW flag\n",
  1289. band);
  1290. sband->vht_cap.vht_mcs.tx_highest ^=
  1291. cpu_to_le16(IEEE80211_VHT_EXT_NSS_BW_CAPABLE);
  1292. local->hw.wiphy->bands[band] = sband;
  1293. local->sband_allocated |= BIT(band);
  1294. }
  1295. result = wiphy_register(local->hw.wiphy);
  1296. if (result < 0)
  1297. goto fail_wiphy_register;
  1298. debugfs_hw_add(local);
  1299. rate_control_add_debugfs(local);
  1300. ieee80211_check_wbrf_support(local);
  1301. rtnl_lock();
  1302. wiphy_lock(hw->wiphy);
  1303. /* add one default STA interface if supported */
  1304. if (local->hw.wiphy->interface_modes & BIT(NL80211_IFTYPE_STATION) &&
  1305. !ieee80211_hw_check(hw, NO_AUTO_VIF)) {
  1306. struct vif_params params = {0};
  1307. result = ieee80211_if_add(local, "wlan%d", NET_NAME_ENUM, NULL,
  1308. NL80211_IFTYPE_STATION, &params);
  1309. if (result)
  1310. wiphy_warn(local->hw.wiphy,
  1311. "Failed to add default virtual iface\n");
  1312. }
  1313. wiphy_unlock(hw->wiphy);
  1314. rtnl_unlock();
  1315. #ifdef CONFIG_INET
  1316. local->ifa_notifier.notifier_call = ieee80211_ifa_changed;
  1317. result = register_inetaddr_notifier(&local->ifa_notifier);
  1318. if (result)
  1319. goto fail_ifa;
  1320. #endif
  1321. #if IS_ENABLED(CONFIG_IPV6)
  1322. local->ifa6_notifier.notifier_call = ieee80211_ifa6_changed;
  1323. result = register_inet6addr_notifier(&local->ifa6_notifier);
  1324. if (result)
  1325. goto fail_ifa6;
  1326. #endif
  1327. return 0;
  1328. #if IS_ENABLED(CONFIG_IPV6)
  1329. fail_ifa6:
  1330. #ifdef CONFIG_INET
  1331. unregister_inetaddr_notifier(&local->ifa_notifier);
  1332. #endif
  1333. #endif
  1334. #if defined(CONFIG_INET) || defined(CONFIG_IPV6)
  1335. fail_ifa:
  1336. #endif
  1337. wiphy_unregister(local->hw.wiphy);
  1338. fail_wiphy_register:
  1339. rtnl_lock();
  1340. rate_control_deinitialize(local);
  1341. ieee80211_remove_interfaces(local);
  1342. rtnl_unlock();
  1343. fail_rate:
  1344. ieee80211_txq_teardown_flows(local);
  1345. fail_flows:
  1346. ieee80211_led_exit(local);
  1347. destroy_workqueue(local->workqueue);
  1348. fail_workqueue:
  1349. if (local->wiphy_ciphers_allocated) {
  1350. kfree(local->hw.wiphy->cipher_suites);
  1351. local->wiphy_ciphers_allocated = false;
  1352. }
  1353. kfree(local->int_scan_req);
  1354. return result;
  1355. }
  1356. EXPORT_SYMBOL(ieee80211_register_hw);
  1357. void ieee80211_unregister_hw(struct ieee80211_hw *hw)
  1358. {
  1359. struct ieee80211_local *local = hw_to_local(hw);
  1360. tasklet_kill(&local->tx_pending_tasklet);
  1361. tasklet_kill(&local->tasklet);
  1362. #ifdef CONFIG_INET
  1363. unregister_inetaddr_notifier(&local->ifa_notifier);
  1364. #endif
  1365. #if IS_ENABLED(CONFIG_IPV6)
  1366. unregister_inet6addr_notifier(&local->ifa6_notifier);
  1367. #endif
  1368. rtnl_lock();
  1369. /*
  1370. * At this point, interface list manipulations are fine
  1371. * because the driver cannot be handing us frames any
  1372. * more and the tasklet is killed.
  1373. */
  1374. ieee80211_remove_interfaces(local);
  1375. ieee80211_txq_teardown_flows(local);
  1376. wiphy_lock(local->hw.wiphy);
  1377. wiphy_delayed_work_cancel(local->hw.wiphy, &local->roc_work);
  1378. wiphy_work_cancel(local->hw.wiphy, &local->reconfig_filter);
  1379. wiphy_work_cancel(local->hw.wiphy, &local->sched_scan_stopped_work);
  1380. wiphy_work_cancel(local->hw.wiphy, &local->radar_detected_work);
  1381. wiphy_unlock(local->hw.wiphy);
  1382. rtnl_unlock();
  1383. cancel_work_sync(&local->restart_work);
  1384. ieee80211_clear_tx_pending(local);
  1385. rate_control_deinitialize(local);
  1386. if (skb_queue_len(&local->skb_queue) ||
  1387. skb_queue_len(&local->skb_queue_unreliable))
  1388. wiphy_warn(local->hw.wiphy, "skb_queue not empty\n");
  1389. skb_queue_purge(&local->skb_queue);
  1390. skb_queue_purge(&local->skb_queue_unreliable);
  1391. wiphy_unregister(local->hw.wiphy);
  1392. destroy_workqueue(local->workqueue);
  1393. ieee80211_led_exit(local);
  1394. kfree(local->int_scan_req);
  1395. }
  1396. EXPORT_SYMBOL(ieee80211_unregister_hw);
  1397. static int ieee80211_free_ack_frame(int id, void *p, void *data)
  1398. {
  1399. WARN_ONCE(1, "Have pending ack frames!\n");
  1400. kfree_skb(p);
  1401. return 0;
  1402. }
  1403. void ieee80211_free_hw(struct ieee80211_hw *hw)
  1404. {
  1405. struct ieee80211_local *local = hw_to_local(hw);
  1406. enum nl80211_band band;
  1407. mutex_destroy(&local->iflist_mtx);
  1408. if (local->wiphy_ciphers_allocated) {
  1409. kfree(local->hw.wiphy->cipher_suites);
  1410. local->wiphy_ciphers_allocated = false;
  1411. }
  1412. idr_for_each(&local->ack_status_frames,
  1413. ieee80211_free_ack_frame, NULL);
  1414. idr_destroy(&local->ack_status_frames);
  1415. sta_info_stop(local);
  1416. ieee80211_free_led_names(local);
  1417. for (band = 0; band < NUM_NL80211_BANDS; band++) {
  1418. if (!(local->sband_allocated & BIT(band)))
  1419. continue;
  1420. kfree(local->hw.wiphy->bands[band]);
  1421. }
  1422. wiphy_free(local->hw.wiphy);
  1423. }
  1424. EXPORT_SYMBOL(ieee80211_free_hw);
  1425. static const char * const drop_reasons_monitor[] = {
  1426. #define V(x) #x,
  1427. [0] = "RX_DROP_MONITOR",
  1428. MAC80211_DROP_REASONS_MONITOR(V)
  1429. };
  1430. static struct drop_reason_list drop_reason_list_monitor = {
  1431. .reasons = drop_reasons_monitor,
  1432. .n_reasons = ARRAY_SIZE(drop_reasons_monitor),
  1433. };
  1434. static const char * const drop_reasons_unusable[] = {
  1435. [0] = "RX_DROP_UNUSABLE",
  1436. MAC80211_DROP_REASONS_UNUSABLE(V)
  1437. #undef V
  1438. };
  1439. static struct drop_reason_list drop_reason_list_unusable = {
  1440. .reasons = drop_reasons_unusable,
  1441. .n_reasons = ARRAY_SIZE(drop_reasons_unusable),
  1442. };
  1443. static int __init ieee80211_init(void)
  1444. {
  1445. struct sk_buff *skb;
  1446. int ret;
  1447. BUILD_BUG_ON(sizeof(struct ieee80211_tx_info) > sizeof(skb->cb));
  1448. BUILD_BUG_ON(offsetof(struct ieee80211_tx_info, driver_data) +
  1449. IEEE80211_TX_INFO_DRIVER_DATA_SIZE > sizeof(skb->cb));
  1450. ret = rc80211_minstrel_init();
  1451. if (ret)
  1452. return ret;
  1453. ret = ieee80211_iface_init();
  1454. if (ret)
  1455. goto err_netdev;
  1456. drop_reasons_register_subsys(SKB_DROP_REASON_SUBSYS_MAC80211_MONITOR,
  1457. &drop_reason_list_monitor);
  1458. drop_reasons_register_subsys(SKB_DROP_REASON_SUBSYS_MAC80211_UNUSABLE,
  1459. &drop_reason_list_unusable);
  1460. return 0;
  1461. err_netdev:
  1462. rc80211_minstrel_exit();
  1463. return ret;
  1464. }
  1465. static void __exit ieee80211_exit(void)
  1466. {
  1467. rc80211_minstrel_exit();
  1468. ieee80211s_stop();
  1469. ieee80211_iface_exit();
  1470. drop_reasons_unregister_subsys(SKB_DROP_REASON_SUBSYS_MAC80211_MONITOR);
  1471. drop_reasons_unregister_subsys(SKB_DROP_REASON_SUBSYS_MAC80211_UNUSABLE);
  1472. rcu_barrier();
  1473. }
  1474. subsys_initcall(ieee80211_init);
  1475. module_exit(ieee80211_exit);
  1476. MODULE_DESCRIPTION("IEEE 802.11 subsystem");
  1477. MODULE_LICENSE("GPL");