main.c 51 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815
  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, supp_s1g;
  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. supp_s1g = false;
  1020. for (band = 0; band < NUM_NL80211_BANDS; band++) {
  1021. const struct ieee80211_sband_iftype_data *iftd;
  1022. struct ieee80211_supported_band *sband;
  1023. sband = local->hw.wiphy->bands[band];
  1024. if (!sband)
  1025. continue;
  1026. if (!dflt_chandef.chan) {
  1027. /*
  1028. * Assign the first enabled channel to dflt_chandef
  1029. * from the list of channels
  1030. */
  1031. for (i = 0; i < sband->n_channels; i++)
  1032. if (!(sband->channels[i].flags &
  1033. IEEE80211_CHAN_DISABLED))
  1034. break;
  1035. /* if none found then use the first anyway */
  1036. if (i == sband->n_channels)
  1037. i = 0;
  1038. cfg80211_chandef_create(&dflt_chandef,
  1039. &sband->channels[i],
  1040. NL80211_CHAN_NO_HT);
  1041. /* init channel we're on */
  1042. local->monitor_chanreq.oper = dflt_chandef;
  1043. if (local->emulate_chanctx) {
  1044. local->dflt_chandef = dflt_chandef;
  1045. local->hw.conf.chandef = dflt_chandef;
  1046. }
  1047. }
  1048. channels += sband->n_channels;
  1049. /*
  1050. * Due to the way the aggregation code handles this and it
  1051. * being an HT capability, we can't really support delayed
  1052. * BA in MLO (yet).
  1053. */
  1054. if (WARN_ON(sband->ht_cap.ht_supported &&
  1055. (sband->ht_cap.cap & IEEE80211_HT_CAP_DELAY_BA) &&
  1056. hw->wiphy->flags & WIPHY_FLAG_SUPPORTS_MLO))
  1057. return -EINVAL;
  1058. if (max_bitrates < sband->n_bitrates)
  1059. max_bitrates = sband->n_bitrates;
  1060. supp_ht = supp_ht || sband->ht_cap.ht_supported;
  1061. supp_vht = supp_vht || sband->vht_cap.vht_supported;
  1062. supp_s1g = supp_s1g || sband->s1g_cap.s1g;
  1063. for_each_sband_iftype_data(sband, i, iftd) {
  1064. u8 he_40_mhz_cap;
  1065. supp_he = supp_he || iftd->he_cap.has_he;
  1066. supp_eht = supp_eht || iftd->eht_cap.has_eht;
  1067. if (band == NL80211_BAND_2GHZ)
  1068. he_40_mhz_cap =
  1069. IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_IN_2G;
  1070. else
  1071. he_40_mhz_cap =
  1072. IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_80MHZ_IN_5G;
  1073. /* currently no support for HE client where HT has 40 MHz but not HT */
  1074. if (iftd->he_cap.has_he &&
  1075. iftd->types_mask & (BIT(NL80211_IFTYPE_STATION) |
  1076. BIT(NL80211_IFTYPE_P2P_CLIENT)) &&
  1077. sband->ht_cap.ht_supported &&
  1078. sband->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40 &&
  1079. !(iftd->he_cap.he_cap_elem.phy_cap_info[0] & he_40_mhz_cap))
  1080. return -EINVAL;
  1081. }
  1082. /* HT, VHT, HE require QoS, thus >= 4 queues */
  1083. if (WARN_ON(local->hw.queues < IEEE80211_NUM_ACS &&
  1084. (supp_ht || supp_vht || supp_he)))
  1085. return -EINVAL;
  1086. /* EHT requires HE support */
  1087. if (WARN_ON(supp_eht && !supp_he))
  1088. return -EINVAL;
  1089. if (!sband->ht_cap.ht_supported)
  1090. continue;
  1091. /* TODO: consider VHT for RX chains, hopefully it's the same */
  1092. local->rx_chains =
  1093. max(ieee80211_mcs_to_chains(&sband->ht_cap.mcs),
  1094. local->rx_chains);
  1095. /* no need to mask, SM_PS_DISABLED has all bits set */
  1096. sband->ht_cap.cap |= WLAN_HT_CAP_SM_PS_DISABLED <<
  1097. IEEE80211_HT_CAP_SM_PS_SHIFT;
  1098. }
  1099. /* if low-level driver supports AP, we also support VLAN.
  1100. * drivers advertising SW_CRYPTO_CONTROL should enable AP_VLAN
  1101. * based on their support to transmit SW encrypted packets.
  1102. */
  1103. if (local->hw.wiphy->interface_modes & BIT(NL80211_IFTYPE_AP) &&
  1104. !ieee80211_hw_check(&local->hw, SW_CRYPTO_CONTROL)) {
  1105. hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_AP_VLAN);
  1106. hw->wiphy->software_iftypes |= BIT(NL80211_IFTYPE_AP_VLAN);
  1107. }
  1108. /* mac80211 always supports monitor */
  1109. hw->wiphy->interface_modes |= BIT(NL80211_IFTYPE_MONITOR);
  1110. hw->wiphy->software_iftypes |= BIT(NL80211_IFTYPE_MONITOR);
  1111. local->int_scan_req = kzalloc(struct_size(local->int_scan_req,
  1112. channels, channels),
  1113. GFP_KERNEL);
  1114. if (!local->int_scan_req)
  1115. return -ENOMEM;
  1116. local->int_scan_req->n_channels = channels;
  1117. eth_broadcast_addr(local->int_scan_req->bssid);
  1118. for (band = 0; band < NUM_NL80211_BANDS; band++) {
  1119. if (!local->hw.wiphy->bands[band])
  1120. continue;
  1121. local->int_scan_req->rates[band] = (u32) -1;
  1122. }
  1123. #ifndef CONFIG_MAC80211_MESH
  1124. /* mesh depends on Kconfig, but drivers should set it if they want */
  1125. local->hw.wiphy->interface_modes &= ~BIT(NL80211_IFTYPE_MESH_POINT);
  1126. #endif
  1127. /* if the underlying driver supports mesh, mac80211 will (at least)
  1128. * provide routing of mesh authentication frames to userspace */
  1129. if (local->hw.wiphy->interface_modes & BIT(NL80211_IFTYPE_MESH_POINT))
  1130. local->hw.wiphy->flags |= WIPHY_FLAG_MESH_AUTH;
  1131. /* mac80211 supports control port protocol changing */
  1132. local->hw.wiphy->flags |= WIPHY_FLAG_CONTROL_PORT_PROTOCOL;
  1133. if (ieee80211_hw_check(&local->hw, SIGNAL_DBM)) {
  1134. local->hw.wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
  1135. } else if (ieee80211_hw_check(&local->hw, SIGNAL_UNSPEC)) {
  1136. local->hw.wiphy->signal_type = CFG80211_SIGNAL_TYPE_UNSPEC;
  1137. if (hw->max_signal <= 0) {
  1138. result = -EINVAL;
  1139. goto fail_workqueue;
  1140. }
  1141. }
  1142. /* Mac80211 and therefore all drivers using SW crypto only
  1143. * are able to handle PTK rekeys and Extended Key ID.
  1144. */
  1145. if (!local->ops->set_key) {
  1146. wiphy_ext_feature_set(local->hw.wiphy,
  1147. NL80211_EXT_FEATURE_CAN_REPLACE_PTK0);
  1148. wiphy_ext_feature_set(local->hw.wiphy,
  1149. NL80211_EXT_FEATURE_EXT_KEY_ID);
  1150. }
  1151. if (local->hw.wiphy->interface_modes & BIT(NL80211_IFTYPE_ADHOC))
  1152. wiphy_ext_feature_set(local->hw.wiphy,
  1153. NL80211_EXT_FEATURE_DEL_IBSS_STA);
  1154. /*
  1155. * Calculate scan IE length -- we need this to alloc
  1156. * memory and to subtract from the driver limit. It
  1157. * includes the DS Params, (extended) supported rates, and HT
  1158. * information -- SSID is the driver's responsibility.
  1159. */
  1160. local->scan_ies_len = 4 + max_bitrates /* (ext) supp rates */ +
  1161. 3 /* DS Params */;
  1162. if (supp_ht)
  1163. local->scan_ies_len += 2 + sizeof(struct ieee80211_ht_cap);
  1164. if (supp_vht)
  1165. local->scan_ies_len +=
  1166. 2 + sizeof(struct ieee80211_vht_cap);
  1167. if (supp_s1g)
  1168. local->scan_ies_len += 2 + sizeof(struct ieee80211_s1g_cap);
  1169. /*
  1170. * HE cap element is variable in size - set len to allow max size */
  1171. if (supp_he) {
  1172. local->scan_ies_len +=
  1173. 3 + sizeof(struct ieee80211_he_cap_elem) +
  1174. sizeof(struct ieee80211_he_mcs_nss_supp) +
  1175. IEEE80211_HE_PPE_THRES_MAX_LEN;
  1176. if (supp_eht)
  1177. local->scan_ies_len +=
  1178. 3 + sizeof(struct ieee80211_eht_cap_elem) +
  1179. sizeof(struct ieee80211_eht_mcs_nss_supp) +
  1180. IEEE80211_EHT_PPE_THRES_MAX_LEN;
  1181. }
  1182. if (!local->ops->hw_scan) {
  1183. /* For hw_scan, driver needs to set these up. */
  1184. local->hw.wiphy->max_scan_ssids = 4;
  1185. local->hw.wiphy->max_scan_ie_len = IEEE80211_MAX_DATA_LEN;
  1186. }
  1187. /*
  1188. * If the driver supports any scan IEs, then assume the
  1189. * limit includes the IEs mac80211 will add, otherwise
  1190. * leave it at zero and let the driver sort it out; we
  1191. * still pass our IEs to the driver but userspace will
  1192. * not be allowed to in that case.
  1193. */
  1194. if (local->hw.wiphy->max_scan_ie_len)
  1195. local->hw.wiphy->max_scan_ie_len -= local->scan_ies_len;
  1196. result = ieee80211_init_cipher_suites(local);
  1197. if (result < 0)
  1198. goto fail_workqueue;
  1199. if (!local->ops->remain_on_channel)
  1200. local->hw.wiphy->max_remain_on_channel_duration = 5000;
  1201. /* mac80211 based drivers don't support internal TDLS setup */
  1202. if (local->hw.wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS)
  1203. local->hw.wiphy->flags |= WIPHY_FLAG_TDLS_EXTERNAL_SETUP;
  1204. /* mac80211 supports eCSA, if the driver supports STA CSA at all */
  1205. if (ieee80211_hw_check(&local->hw, CHANCTX_STA_CSA))
  1206. local->ext_capa[0] |= WLAN_EXT_CAPA1_EXT_CHANNEL_SWITCHING;
  1207. /* mac80211 supports multi BSSID, if the driver supports it */
  1208. if (ieee80211_hw_check(&local->hw, SUPPORTS_MULTI_BSSID)) {
  1209. local->hw.wiphy->support_mbssid = true;
  1210. if (ieee80211_hw_check(&local->hw,
  1211. SUPPORTS_ONLY_HE_MULTI_BSSID))
  1212. local->hw.wiphy->support_only_he_mbssid = true;
  1213. else
  1214. local->ext_capa[2] |=
  1215. WLAN_EXT_CAPA3_MULTI_BSSID_SUPPORT;
  1216. }
  1217. local->hw.wiphy->max_num_csa_counters = IEEE80211_MAX_CNTDWN_COUNTERS_NUM;
  1218. /*
  1219. * We use the number of queues for feature tests (QoS, HT) internally
  1220. * so restrict them appropriately.
  1221. */
  1222. if (hw->queues > IEEE80211_MAX_QUEUES)
  1223. hw->queues = IEEE80211_MAX_QUEUES;
  1224. local->workqueue =
  1225. alloc_ordered_workqueue("%s", 0, wiphy_name(local->hw.wiphy));
  1226. if (!local->workqueue) {
  1227. result = -ENOMEM;
  1228. goto fail_workqueue;
  1229. }
  1230. /*
  1231. * The hardware needs headroom for sending the frame,
  1232. * and we need some headroom for passing the frame to monitor
  1233. * interfaces, but never both at the same time.
  1234. */
  1235. local->tx_headroom = max_t(unsigned int , local->hw.extra_tx_headroom,
  1236. IEEE80211_TX_STATUS_HEADROOM);
  1237. /*
  1238. * if the driver doesn't specify a max listen interval we
  1239. * use 5 which should be a safe default
  1240. */
  1241. if (local->hw.max_listen_interval == 0)
  1242. local->hw.max_listen_interval = 5;
  1243. local->hw.conf.listen_interval = local->hw.max_listen_interval;
  1244. local->dynamic_ps_forced_timeout = -1;
  1245. if (!local->hw.max_nan_de_entries)
  1246. local->hw.max_nan_de_entries = IEEE80211_MAX_NAN_INSTANCE_ID;
  1247. if (!local->hw.weight_multiplier)
  1248. local->hw.weight_multiplier = 1;
  1249. ieee80211_wep_init(local);
  1250. local->hw.conf.flags = IEEE80211_CONF_IDLE;
  1251. ieee80211_led_init(local);
  1252. result = ieee80211_txq_setup_flows(local);
  1253. if (result)
  1254. goto fail_flows;
  1255. rtnl_lock();
  1256. result = ieee80211_init_rate_ctrl_alg(local,
  1257. hw->rate_control_algorithm);
  1258. rtnl_unlock();
  1259. if (result < 0) {
  1260. wiphy_debug(local->hw.wiphy,
  1261. "Failed to initialize rate control algorithm\n");
  1262. goto fail_rate;
  1263. }
  1264. if (local->rate_ctrl) {
  1265. clear_bit(IEEE80211_HW_SUPPORTS_VHT_EXT_NSS_BW, hw->flags);
  1266. if (local->rate_ctrl->ops->capa & RATE_CTRL_CAPA_VHT_EXT_NSS_BW)
  1267. ieee80211_hw_set(hw, SUPPORTS_VHT_EXT_NSS_BW);
  1268. }
  1269. /*
  1270. * If the VHT capabilities don't have IEEE80211_VHT_EXT_NSS_BW_CAPABLE,
  1271. * or have it when we don't, copy the sband structure and set/clear it.
  1272. * This is necessary because rate scaling algorithms could be switched
  1273. * and have different support values.
  1274. * Print a message so that in the common case the reallocation can be
  1275. * avoided.
  1276. */
  1277. BUILD_BUG_ON(NUM_NL80211_BANDS > 8 * sizeof(local->sband_allocated));
  1278. for (band = 0; band < NUM_NL80211_BANDS; band++) {
  1279. struct ieee80211_supported_band *sband;
  1280. bool local_cap, ie_cap;
  1281. local_cap = ieee80211_hw_check(hw, SUPPORTS_VHT_EXT_NSS_BW);
  1282. sband = local->hw.wiphy->bands[band];
  1283. if (!sband || !sband->vht_cap.vht_supported)
  1284. continue;
  1285. ie_cap = !!(sband->vht_cap.vht_mcs.tx_highest &
  1286. cpu_to_le16(IEEE80211_VHT_EXT_NSS_BW_CAPABLE));
  1287. if (local_cap == ie_cap)
  1288. continue;
  1289. sband = kmemdup(sband, sizeof(*sband), GFP_KERNEL);
  1290. if (!sband) {
  1291. result = -ENOMEM;
  1292. goto fail_rate;
  1293. }
  1294. wiphy_dbg(hw->wiphy, "copying sband (band %d) due to VHT EXT NSS BW flag\n",
  1295. band);
  1296. sband->vht_cap.vht_mcs.tx_highest ^=
  1297. cpu_to_le16(IEEE80211_VHT_EXT_NSS_BW_CAPABLE);
  1298. local->hw.wiphy->bands[band] = sband;
  1299. local->sband_allocated |= BIT(band);
  1300. }
  1301. result = wiphy_register(local->hw.wiphy);
  1302. if (result < 0)
  1303. goto fail_wiphy_register;
  1304. debugfs_hw_add(local);
  1305. rate_control_add_debugfs(local);
  1306. ieee80211_check_wbrf_support(local);
  1307. rtnl_lock();
  1308. wiphy_lock(hw->wiphy);
  1309. /* add one default STA interface if supported */
  1310. if (local->hw.wiphy->interface_modes & BIT(NL80211_IFTYPE_STATION) &&
  1311. !ieee80211_hw_check(hw, NO_AUTO_VIF)) {
  1312. struct vif_params params = {0};
  1313. result = ieee80211_if_add(local, "wlan%d", NET_NAME_ENUM, NULL,
  1314. NL80211_IFTYPE_STATION, &params);
  1315. if (result)
  1316. wiphy_warn(local->hw.wiphy,
  1317. "Failed to add default virtual iface\n");
  1318. }
  1319. wiphy_unlock(hw->wiphy);
  1320. rtnl_unlock();
  1321. #ifdef CONFIG_INET
  1322. local->ifa_notifier.notifier_call = ieee80211_ifa_changed;
  1323. result = register_inetaddr_notifier(&local->ifa_notifier);
  1324. if (result)
  1325. goto fail_ifa;
  1326. #endif
  1327. #if IS_ENABLED(CONFIG_IPV6)
  1328. local->ifa6_notifier.notifier_call = ieee80211_ifa6_changed;
  1329. result = register_inet6addr_notifier(&local->ifa6_notifier);
  1330. if (result)
  1331. goto fail_ifa6;
  1332. #endif
  1333. return 0;
  1334. #if IS_ENABLED(CONFIG_IPV6)
  1335. fail_ifa6:
  1336. #ifdef CONFIG_INET
  1337. unregister_inetaddr_notifier(&local->ifa_notifier);
  1338. #endif
  1339. #endif
  1340. #if defined(CONFIG_INET) || defined(CONFIG_IPV6)
  1341. fail_ifa:
  1342. #endif
  1343. wiphy_unregister(local->hw.wiphy);
  1344. fail_wiphy_register:
  1345. rtnl_lock();
  1346. rate_control_deinitialize(local);
  1347. ieee80211_remove_interfaces(local);
  1348. rtnl_unlock();
  1349. fail_rate:
  1350. ieee80211_txq_teardown_flows(local);
  1351. fail_flows:
  1352. ieee80211_led_exit(local);
  1353. destroy_workqueue(local->workqueue);
  1354. fail_workqueue:
  1355. if (local->wiphy_ciphers_allocated) {
  1356. kfree(local->hw.wiphy->cipher_suites);
  1357. local->wiphy_ciphers_allocated = false;
  1358. }
  1359. kfree(local->int_scan_req);
  1360. return result;
  1361. }
  1362. EXPORT_SYMBOL(ieee80211_register_hw);
  1363. void ieee80211_unregister_hw(struct ieee80211_hw *hw)
  1364. {
  1365. struct ieee80211_local *local = hw_to_local(hw);
  1366. tasklet_kill(&local->tx_pending_tasklet);
  1367. tasklet_kill(&local->tasklet);
  1368. #ifdef CONFIG_INET
  1369. unregister_inetaddr_notifier(&local->ifa_notifier);
  1370. #endif
  1371. #if IS_ENABLED(CONFIG_IPV6)
  1372. unregister_inet6addr_notifier(&local->ifa6_notifier);
  1373. #endif
  1374. rtnl_lock();
  1375. /*
  1376. * At this point, interface list manipulations are fine
  1377. * because the driver cannot be handing us frames any
  1378. * more and the tasklet is killed.
  1379. */
  1380. ieee80211_remove_interfaces(local);
  1381. ieee80211_txq_teardown_flows(local);
  1382. wiphy_lock(local->hw.wiphy);
  1383. wiphy_delayed_work_cancel(local->hw.wiphy, &local->roc_work);
  1384. wiphy_work_cancel(local->hw.wiphy, &local->reconfig_filter);
  1385. wiphy_work_cancel(local->hw.wiphy, &local->sched_scan_stopped_work);
  1386. wiphy_work_cancel(local->hw.wiphy, &local->radar_detected_work);
  1387. wiphy_unlock(local->hw.wiphy);
  1388. rtnl_unlock();
  1389. cancel_work_sync(&local->restart_work);
  1390. ieee80211_clear_tx_pending(local);
  1391. rate_control_deinitialize(local);
  1392. if (skb_queue_len(&local->skb_queue) ||
  1393. skb_queue_len(&local->skb_queue_unreliable))
  1394. wiphy_warn(local->hw.wiphy, "skb_queue not empty\n");
  1395. skb_queue_purge(&local->skb_queue);
  1396. skb_queue_purge(&local->skb_queue_unreliable);
  1397. wiphy_unregister(local->hw.wiphy);
  1398. destroy_workqueue(local->workqueue);
  1399. ieee80211_led_exit(local);
  1400. kfree(local->int_scan_req);
  1401. }
  1402. EXPORT_SYMBOL(ieee80211_unregister_hw);
  1403. static int ieee80211_free_ack_frame(int id, void *p, void *data)
  1404. {
  1405. WARN_ONCE(1, "Have pending ack frames!\n");
  1406. kfree_skb(p);
  1407. return 0;
  1408. }
  1409. void ieee80211_free_hw(struct ieee80211_hw *hw)
  1410. {
  1411. struct ieee80211_local *local = hw_to_local(hw);
  1412. enum nl80211_band band;
  1413. mutex_destroy(&local->iflist_mtx);
  1414. if (local->wiphy_ciphers_allocated) {
  1415. kfree(local->hw.wiphy->cipher_suites);
  1416. local->wiphy_ciphers_allocated = false;
  1417. }
  1418. idr_for_each(&local->ack_status_frames,
  1419. ieee80211_free_ack_frame, NULL);
  1420. idr_destroy(&local->ack_status_frames);
  1421. sta_info_stop(local);
  1422. ieee80211_free_led_names(local);
  1423. for (band = 0; band < NUM_NL80211_BANDS; band++) {
  1424. if (!(local->sband_allocated & BIT(band)))
  1425. continue;
  1426. kfree(local->hw.wiphy->bands[band]);
  1427. }
  1428. wiphy_free(local->hw.wiphy);
  1429. }
  1430. EXPORT_SYMBOL(ieee80211_free_hw);
  1431. static const char * const drop_reasons_monitor[] = {
  1432. #define V(x) #x,
  1433. [0] = "RX_DROP_MONITOR",
  1434. MAC80211_DROP_REASONS_MONITOR(V)
  1435. };
  1436. static struct drop_reason_list drop_reason_list_monitor = {
  1437. .reasons = drop_reasons_monitor,
  1438. .n_reasons = ARRAY_SIZE(drop_reasons_monitor),
  1439. };
  1440. static const char * const drop_reasons_unusable[] = {
  1441. [0] = "RX_DROP_UNUSABLE",
  1442. MAC80211_DROP_REASONS_UNUSABLE(V)
  1443. #undef V
  1444. };
  1445. static struct drop_reason_list drop_reason_list_unusable = {
  1446. .reasons = drop_reasons_unusable,
  1447. .n_reasons = ARRAY_SIZE(drop_reasons_unusable),
  1448. };
  1449. static int __init ieee80211_init(void)
  1450. {
  1451. struct sk_buff *skb;
  1452. int ret;
  1453. BUILD_BUG_ON(sizeof(struct ieee80211_tx_info) > sizeof(skb->cb));
  1454. BUILD_BUG_ON(offsetof(struct ieee80211_tx_info, driver_data) +
  1455. IEEE80211_TX_INFO_DRIVER_DATA_SIZE > sizeof(skb->cb));
  1456. ret = rc80211_minstrel_init();
  1457. if (ret)
  1458. return ret;
  1459. ret = ieee80211_iface_init();
  1460. if (ret)
  1461. goto err_netdev;
  1462. drop_reasons_register_subsys(SKB_DROP_REASON_SUBSYS_MAC80211_MONITOR,
  1463. &drop_reason_list_monitor);
  1464. drop_reasons_register_subsys(SKB_DROP_REASON_SUBSYS_MAC80211_UNUSABLE,
  1465. &drop_reason_list_unusable);
  1466. return 0;
  1467. err_netdev:
  1468. rc80211_minstrel_exit();
  1469. return ret;
  1470. }
  1471. static void __exit ieee80211_exit(void)
  1472. {
  1473. rc80211_minstrel_exit();
  1474. ieee80211s_stop();
  1475. ieee80211_iface_exit();
  1476. drop_reasons_unregister_subsys(SKB_DROP_REASON_SUBSYS_MAC80211_MONITOR);
  1477. drop_reasons_unregister_subsys(SKB_DROP_REASON_SUBSYS_MAC80211_UNUSABLE);
  1478. rcu_barrier();
  1479. }
  1480. subsys_initcall(ieee80211_init);
  1481. module_exit(ieee80211_exit);
  1482. MODULE_DESCRIPTION("IEEE 802.11 subsystem");
  1483. MODULE_LICENSE("GPL");