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