util.c 60 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356
  1. /*
  2. * Copyright 2002-2005, Instant802 Networks, Inc.
  3. * Copyright 2005-2006, Devicescape Software, Inc.
  4. * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz>
  5. * Copyright 2007 Johannes Berg <johannes@sipsolutions.net>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. *
  11. * utilities for mac80211
  12. */
  13. #include <net/mac80211.h>
  14. #include <linux/netdevice.h>
  15. #include <linux/export.h>
  16. #include <linux/types.h>
  17. #include <linux/slab.h>
  18. #include <linux/skbuff.h>
  19. #include <linux/etherdevice.h>
  20. #include <linux/if_arp.h>
  21. #include <linux/bitmap.h>
  22. #include <linux/crc32.h>
  23. #include <net/net_namespace.h>
  24. #include <net/cfg80211.h>
  25. #include <net/rtnetlink.h>
  26. #include "ieee80211_i.h"
  27. #include "driver-ops.h"
  28. #include "rate.h"
  29. #include "mesh.h"
  30. #include "wme.h"
  31. #include "led.h"
  32. #include "wep.h"
  33. /* privid for wiphys to determine whether they belong to us or not */
  34. void *mac80211_wiphy_privid = &mac80211_wiphy_privid;
  35. struct ieee80211_hw *wiphy_to_ieee80211_hw(struct wiphy *wiphy)
  36. {
  37. struct ieee80211_local *local;
  38. BUG_ON(!wiphy);
  39. local = wiphy_priv(wiphy);
  40. return &local->hw;
  41. }
  42. EXPORT_SYMBOL(wiphy_to_ieee80211_hw);
  43. u8 *ieee80211_get_bssid(struct ieee80211_hdr *hdr, size_t len,
  44. enum nl80211_iftype type)
  45. {
  46. __le16 fc = hdr->frame_control;
  47. /* drop ACK/CTS frames and incorrect hdr len (ctrl) */
  48. if (len < 16)
  49. return NULL;
  50. if (ieee80211_is_data(fc)) {
  51. if (len < 24) /* drop incorrect hdr len (data) */
  52. return NULL;
  53. if (ieee80211_has_a4(fc))
  54. return NULL;
  55. if (ieee80211_has_tods(fc))
  56. return hdr->addr1;
  57. if (ieee80211_has_fromds(fc))
  58. return hdr->addr2;
  59. return hdr->addr3;
  60. }
  61. if (ieee80211_is_mgmt(fc)) {
  62. if (len < 24) /* drop incorrect hdr len (mgmt) */
  63. return NULL;
  64. return hdr->addr3;
  65. }
  66. if (ieee80211_is_ctl(fc)) {
  67. if(ieee80211_is_pspoll(fc))
  68. return hdr->addr1;
  69. if (ieee80211_is_back_req(fc)) {
  70. switch (type) {
  71. case NL80211_IFTYPE_STATION:
  72. return hdr->addr2;
  73. case NL80211_IFTYPE_AP:
  74. case NL80211_IFTYPE_AP_VLAN:
  75. return hdr->addr1;
  76. default:
  77. break; /* fall through to the return */
  78. }
  79. }
  80. }
  81. return NULL;
  82. }
  83. void ieee80211_tx_set_protected(struct ieee80211_tx_data *tx)
  84. {
  85. struct sk_buff *skb;
  86. struct ieee80211_hdr *hdr;
  87. skb_queue_walk(&tx->skbs, skb) {
  88. hdr = (struct ieee80211_hdr *) skb->data;
  89. hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_PROTECTED);
  90. }
  91. }
  92. int ieee80211_frame_duration(enum ieee80211_band band, size_t len,
  93. int rate, int erp, int short_preamble,
  94. int shift)
  95. {
  96. int dur;
  97. /* calculate duration (in microseconds, rounded up to next higher
  98. * integer if it includes a fractional microsecond) to send frame of
  99. * len bytes (does not include FCS) at the given rate. Duration will
  100. * also include SIFS.
  101. *
  102. * rate is in 100 kbps, so divident is multiplied by 10 in the
  103. * DIV_ROUND_UP() operations.
  104. *
  105. * shift may be 2 for 5 MHz channels or 1 for 10 MHz channels, and
  106. * is assumed to be 0 otherwise.
  107. */
  108. if (band == IEEE80211_BAND_5GHZ || erp) {
  109. /*
  110. * OFDM:
  111. *
  112. * N_DBPS = DATARATE x 4
  113. * N_SYM = Ceiling((16+8xLENGTH+6) / N_DBPS)
  114. * (16 = SIGNAL time, 6 = tail bits)
  115. * TXTIME = T_PREAMBLE + T_SIGNAL + T_SYM x N_SYM + Signal Ext
  116. *
  117. * T_SYM = 4 usec
  118. * 802.11a - 18.5.2: aSIFSTime = 16 usec
  119. * 802.11g - 19.8.4: aSIFSTime = 10 usec +
  120. * signal ext = 6 usec
  121. */
  122. dur = 16; /* SIFS + signal ext */
  123. dur += 16; /* IEEE 802.11-2012 18.3.2.4: T_PREAMBLE = 16 usec */
  124. dur += 4; /* IEEE 802.11-2012 18.3.2.4: T_SIGNAL = 4 usec */
  125. /* IEEE 802.11-2012 18.3.2.4: all values above are:
  126. * * times 4 for 5 MHz
  127. * * times 2 for 10 MHz
  128. */
  129. dur *= 1 << shift;
  130. /* rates should already consider the channel bandwidth,
  131. * don't apply divisor again.
  132. */
  133. dur += 4 * DIV_ROUND_UP((16 + 8 * (len + 4) + 6) * 10,
  134. 4 * rate); /* T_SYM x N_SYM */
  135. } else {
  136. /*
  137. * 802.11b or 802.11g with 802.11b compatibility:
  138. * 18.3.4: TXTIME = PreambleLength + PLCPHeaderTime +
  139. * Ceiling(((LENGTH+PBCC)x8)/DATARATE). PBCC=0.
  140. *
  141. * 802.11 (DS): 15.3.3, 802.11b: 18.3.4
  142. * aSIFSTime = 10 usec
  143. * aPreambleLength = 144 usec or 72 usec with short preamble
  144. * aPLCPHeaderLength = 48 usec or 24 usec with short preamble
  145. */
  146. dur = 10; /* aSIFSTime = 10 usec */
  147. dur += short_preamble ? (72 + 24) : (144 + 48);
  148. dur += DIV_ROUND_UP(8 * (len + 4) * 10, rate);
  149. }
  150. return dur;
  151. }
  152. /* Exported duration function for driver use */
  153. __le16 ieee80211_generic_frame_duration(struct ieee80211_hw *hw,
  154. struct ieee80211_vif *vif,
  155. enum ieee80211_band band,
  156. size_t frame_len,
  157. struct ieee80211_rate *rate)
  158. {
  159. struct ieee80211_sub_if_data *sdata;
  160. u16 dur;
  161. int erp, shift = 0;
  162. bool short_preamble = false;
  163. erp = 0;
  164. if (vif) {
  165. sdata = vif_to_sdata(vif);
  166. short_preamble = sdata->vif.bss_conf.use_short_preamble;
  167. if (sdata->flags & IEEE80211_SDATA_OPERATING_GMODE)
  168. erp = rate->flags & IEEE80211_RATE_ERP_G;
  169. shift = ieee80211_vif_get_shift(vif);
  170. }
  171. dur = ieee80211_frame_duration(band, frame_len, rate->bitrate, erp,
  172. short_preamble, shift);
  173. return cpu_to_le16(dur);
  174. }
  175. EXPORT_SYMBOL(ieee80211_generic_frame_duration);
  176. __le16 ieee80211_rts_duration(struct ieee80211_hw *hw,
  177. struct ieee80211_vif *vif, size_t frame_len,
  178. const struct ieee80211_tx_info *frame_txctl)
  179. {
  180. struct ieee80211_local *local = hw_to_local(hw);
  181. struct ieee80211_rate *rate;
  182. struct ieee80211_sub_if_data *sdata;
  183. bool short_preamble;
  184. int erp, shift = 0, bitrate;
  185. u16 dur;
  186. struct ieee80211_supported_band *sband;
  187. sband = local->hw.wiphy->bands[frame_txctl->band];
  188. short_preamble = false;
  189. rate = &sband->bitrates[frame_txctl->control.rts_cts_rate_idx];
  190. erp = 0;
  191. if (vif) {
  192. sdata = vif_to_sdata(vif);
  193. short_preamble = sdata->vif.bss_conf.use_short_preamble;
  194. if (sdata->flags & IEEE80211_SDATA_OPERATING_GMODE)
  195. erp = rate->flags & IEEE80211_RATE_ERP_G;
  196. shift = ieee80211_vif_get_shift(vif);
  197. }
  198. bitrate = DIV_ROUND_UP(rate->bitrate, 1 << shift);
  199. /* CTS duration */
  200. dur = ieee80211_frame_duration(sband->band, 10, bitrate,
  201. erp, short_preamble, shift);
  202. /* Data frame duration */
  203. dur += ieee80211_frame_duration(sband->band, frame_len, bitrate,
  204. erp, short_preamble, shift);
  205. /* ACK duration */
  206. dur += ieee80211_frame_duration(sband->band, 10, bitrate,
  207. erp, short_preamble, shift);
  208. return cpu_to_le16(dur);
  209. }
  210. EXPORT_SYMBOL(ieee80211_rts_duration);
  211. __le16 ieee80211_ctstoself_duration(struct ieee80211_hw *hw,
  212. struct ieee80211_vif *vif,
  213. size_t frame_len,
  214. const struct ieee80211_tx_info *frame_txctl)
  215. {
  216. struct ieee80211_local *local = hw_to_local(hw);
  217. struct ieee80211_rate *rate;
  218. struct ieee80211_sub_if_data *sdata;
  219. bool short_preamble;
  220. int erp, shift = 0, bitrate;
  221. u16 dur;
  222. struct ieee80211_supported_band *sband;
  223. sband = local->hw.wiphy->bands[frame_txctl->band];
  224. short_preamble = false;
  225. rate = &sband->bitrates[frame_txctl->control.rts_cts_rate_idx];
  226. erp = 0;
  227. if (vif) {
  228. sdata = vif_to_sdata(vif);
  229. short_preamble = sdata->vif.bss_conf.use_short_preamble;
  230. if (sdata->flags & IEEE80211_SDATA_OPERATING_GMODE)
  231. erp = rate->flags & IEEE80211_RATE_ERP_G;
  232. shift = ieee80211_vif_get_shift(vif);
  233. }
  234. bitrate = DIV_ROUND_UP(rate->bitrate, 1 << shift);
  235. /* Data frame duration */
  236. dur = ieee80211_frame_duration(sband->band, frame_len, bitrate,
  237. erp, short_preamble, shift);
  238. if (!(frame_txctl->flags & IEEE80211_TX_CTL_NO_ACK)) {
  239. /* ACK duration */
  240. dur += ieee80211_frame_duration(sband->band, 10, bitrate,
  241. erp, short_preamble, shift);
  242. }
  243. return cpu_to_le16(dur);
  244. }
  245. EXPORT_SYMBOL(ieee80211_ctstoself_duration);
  246. void ieee80211_propagate_queue_wake(struct ieee80211_local *local, int queue)
  247. {
  248. struct ieee80211_sub_if_data *sdata;
  249. int n_acs = IEEE80211_NUM_ACS;
  250. if (local->hw.queues < IEEE80211_NUM_ACS)
  251. n_acs = 1;
  252. list_for_each_entry_rcu(sdata, &local->interfaces, list) {
  253. int ac;
  254. if (!sdata->dev)
  255. continue;
  256. if (test_bit(SDATA_STATE_OFFCHANNEL, &sdata->state))
  257. continue;
  258. if (sdata->vif.cab_queue != IEEE80211_INVAL_HW_QUEUE &&
  259. local->queue_stop_reasons[sdata->vif.cab_queue] != 0)
  260. continue;
  261. for (ac = 0; ac < n_acs; ac++) {
  262. int ac_queue = sdata->vif.hw_queue[ac];
  263. if (ac_queue == queue ||
  264. (sdata->vif.cab_queue == queue &&
  265. local->queue_stop_reasons[ac_queue] == 0 &&
  266. skb_queue_empty(&local->pending[ac_queue])))
  267. netif_wake_subqueue(sdata->dev, ac);
  268. }
  269. }
  270. }
  271. static void __ieee80211_wake_queue(struct ieee80211_hw *hw, int queue,
  272. enum queue_stop_reason reason)
  273. {
  274. struct ieee80211_local *local = hw_to_local(hw);
  275. trace_wake_queue(local, queue, reason);
  276. if (WARN_ON(queue >= hw->queues))
  277. return;
  278. if (!test_bit(reason, &local->queue_stop_reasons[queue]))
  279. return;
  280. __clear_bit(reason, &local->queue_stop_reasons[queue]);
  281. if (local->queue_stop_reasons[queue] != 0)
  282. /* someone still has this queue stopped */
  283. return;
  284. if (skb_queue_empty(&local->pending[queue])) {
  285. rcu_read_lock();
  286. ieee80211_propagate_queue_wake(local, queue);
  287. rcu_read_unlock();
  288. } else
  289. tasklet_schedule(&local->tx_pending_tasklet);
  290. }
  291. void ieee80211_wake_queue_by_reason(struct ieee80211_hw *hw, int queue,
  292. enum queue_stop_reason reason)
  293. {
  294. struct ieee80211_local *local = hw_to_local(hw);
  295. unsigned long flags;
  296. spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
  297. __ieee80211_wake_queue(hw, queue, reason);
  298. spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
  299. }
  300. void ieee80211_wake_queue(struct ieee80211_hw *hw, int queue)
  301. {
  302. ieee80211_wake_queue_by_reason(hw, queue,
  303. IEEE80211_QUEUE_STOP_REASON_DRIVER);
  304. }
  305. EXPORT_SYMBOL(ieee80211_wake_queue);
  306. static void __ieee80211_stop_queue(struct ieee80211_hw *hw, int queue,
  307. enum queue_stop_reason reason)
  308. {
  309. struct ieee80211_local *local = hw_to_local(hw);
  310. struct ieee80211_sub_if_data *sdata;
  311. int n_acs = IEEE80211_NUM_ACS;
  312. trace_stop_queue(local, queue, reason);
  313. if (WARN_ON(queue >= hw->queues))
  314. return;
  315. if (test_bit(reason, &local->queue_stop_reasons[queue]))
  316. return;
  317. __set_bit(reason, &local->queue_stop_reasons[queue]);
  318. if (local->hw.queues < IEEE80211_NUM_ACS)
  319. n_acs = 1;
  320. rcu_read_lock();
  321. list_for_each_entry_rcu(sdata, &local->interfaces, list) {
  322. int ac;
  323. if (!sdata->dev)
  324. continue;
  325. for (ac = 0; ac < n_acs; ac++) {
  326. if (sdata->vif.hw_queue[ac] == queue ||
  327. sdata->vif.cab_queue == queue)
  328. netif_stop_subqueue(sdata->dev, ac);
  329. }
  330. }
  331. rcu_read_unlock();
  332. }
  333. void ieee80211_stop_queue_by_reason(struct ieee80211_hw *hw, int queue,
  334. enum queue_stop_reason reason)
  335. {
  336. struct ieee80211_local *local = hw_to_local(hw);
  337. unsigned long flags;
  338. spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
  339. __ieee80211_stop_queue(hw, queue, reason);
  340. spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
  341. }
  342. void ieee80211_stop_queue(struct ieee80211_hw *hw, int queue)
  343. {
  344. ieee80211_stop_queue_by_reason(hw, queue,
  345. IEEE80211_QUEUE_STOP_REASON_DRIVER);
  346. }
  347. EXPORT_SYMBOL(ieee80211_stop_queue);
  348. void ieee80211_add_pending_skb(struct ieee80211_local *local,
  349. struct sk_buff *skb)
  350. {
  351. struct ieee80211_hw *hw = &local->hw;
  352. unsigned long flags;
  353. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  354. int queue = info->hw_queue;
  355. if (WARN_ON(!info->control.vif)) {
  356. ieee80211_free_txskb(&local->hw, skb);
  357. return;
  358. }
  359. spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
  360. __ieee80211_stop_queue(hw, queue, IEEE80211_QUEUE_STOP_REASON_SKB_ADD);
  361. __skb_queue_tail(&local->pending[queue], skb);
  362. __ieee80211_wake_queue(hw, queue, IEEE80211_QUEUE_STOP_REASON_SKB_ADD);
  363. spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
  364. }
  365. void ieee80211_add_pending_skbs_fn(struct ieee80211_local *local,
  366. struct sk_buff_head *skbs,
  367. void (*fn)(void *data), void *data)
  368. {
  369. struct ieee80211_hw *hw = &local->hw;
  370. struct sk_buff *skb;
  371. unsigned long flags;
  372. int queue, i;
  373. spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
  374. while ((skb = skb_dequeue(skbs))) {
  375. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  376. if (WARN_ON(!info->control.vif)) {
  377. ieee80211_free_txskb(&local->hw, skb);
  378. continue;
  379. }
  380. queue = info->hw_queue;
  381. __ieee80211_stop_queue(hw, queue,
  382. IEEE80211_QUEUE_STOP_REASON_SKB_ADD);
  383. __skb_queue_tail(&local->pending[queue], skb);
  384. }
  385. if (fn)
  386. fn(data);
  387. for (i = 0; i < hw->queues; i++)
  388. __ieee80211_wake_queue(hw, i,
  389. IEEE80211_QUEUE_STOP_REASON_SKB_ADD);
  390. spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
  391. }
  392. void ieee80211_stop_queues_by_reason(struct ieee80211_hw *hw,
  393. unsigned long queues,
  394. enum queue_stop_reason reason)
  395. {
  396. struct ieee80211_local *local = hw_to_local(hw);
  397. unsigned long flags;
  398. int i;
  399. spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
  400. for_each_set_bit(i, &queues, hw->queues)
  401. __ieee80211_stop_queue(hw, i, reason);
  402. spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
  403. }
  404. void ieee80211_stop_queues(struct ieee80211_hw *hw)
  405. {
  406. ieee80211_stop_queues_by_reason(hw, IEEE80211_MAX_QUEUE_MAP,
  407. IEEE80211_QUEUE_STOP_REASON_DRIVER);
  408. }
  409. EXPORT_SYMBOL(ieee80211_stop_queues);
  410. int ieee80211_queue_stopped(struct ieee80211_hw *hw, int queue)
  411. {
  412. struct ieee80211_local *local = hw_to_local(hw);
  413. unsigned long flags;
  414. int ret;
  415. if (WARN_ON(queue >= hw->queues))
  416. return true;
  417. spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
  418. ret = test_bit(IEEE80211_QUEUE_STOP_REASON_DRIVER,
  419. &local->queue_stop_reasons[queue]);
  420. spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
  421. return ret;
  422. }
  423. EXPORT_SYMBOL(ieee80211_queue_stopped);
  424. void ieee80211_wake_queues_by_reason(struct ieee80211_hw *hw,
  425. unsigned long queues,
  426. enum queue_stop_reason reason)
  427. {
  428. struct ieee80211_local *local = hw_to_local(hw);
  429. unsigned long flags;
  430. int i;
  431. spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
  432. for_each_set_bit(i, &queues, hw->queues)
  433. __ieee80211_wake_queue(hw, i, reason);
  434. spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
  435. }
  436. void ieee80211_wake_queues(struct ieee80211_hw *hw)
  437. {
  438. ieee80211_wake_queues_by_reason(hw, IEEE80211_MAX_QUEUE_MAP,
  439. IEEE80211_QUEUE_STOP_REASON_DRIVER);
  440. }
  441. EXPORT_SYMBOL(ieee80211_wake_queues);
  442. void ieee80211_flush_queues(struct ieee80211_local *local,
  443. struct ieee80211_sub_if_data *sdata)
  444. {
  445. u32 queues;
  446. if (!local->ops->flush)
  447. return;
  448. if (sdata && local->hw.flags & IEEE80211_HW_QUEUE_CONTROL) {
  449. int ac;
  450. queues = 0;
  451. for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
  452. queues |= BIT(sdata->vif.hw_queue[ac]);
  453. if (sdata->vif.cab_queue != IEEE80211_INVAL_HW_QUEUE)
  454. queues |= BIT(sdata->vif.cab_queue);
  455. } else {
  456. /* all queues */
  457. queues = BIT(local->hw.queues) - 1;
  458. }
  459. ieee80211_stop_queues_by_reason(&local->hw, IEEE80211_MAX_QUEUE_MAP,
  460. IEEE80211_QUEUE_STOP_REASON_FLUSH);
  461. drv_flush(local, queues, false);
  462. ieee80211_wake_queues_by_reason(&local->hw, IEEE80211_MAX_QUEUE_MAP,
  463. IEEE80211_QUEUE_STOP_REASON_FLUSH);
  464. }
  465. static void __iterate_active_interfaces(struct ieee80211_local *local,
  466. u32 iter_flags,
  467. void (*iterator)(void *data, u8 *mac,
  468. struct ieee80211_vif *vif),
  469. void *data)
  470. {
  471. struct ieee80211_sub_if_data *sdata;
  472. list_for_each_entry_rcu(sdata, &local->interfaces, list) {
  473. switch (sdata->vif.type) {
  474. case NL80211_IFTYPE_MONITOR:
  475. if (!(sdata->u.mntr_flags & MONITOR_FLAG_ACTIVE))
  476. continue;
  477. break;
  478. case NL80211_IFTYPE_AP_VLAN:
  479. continue;
  480. default:
  481. break;
  482. }
  483. if (!(iter_flags & IEEE80211_IFACE_ITER_RESUME_ALL) &&
  484. !(sdata->flags & IEEE80211_SDATA_IN_DRIVER))
  485. continue;
  486. if (ieee80211_sdata_running(sdata))
  487. iterator(data, sdata->vif.addr,
  488. &sdata->vif);
  489. }
  490. sdata = rcu_dereference_check(local->monitor_sdata,
  491. lockdep_is_held(&local->iflist_mtx) ||
  492. lockdep_rtnl_is_held());
  493. if (sdata &&
  494. (iter_flags & IEEE80211_IFACE_ITER_RESUME_ALL ||
  495. sdata->flags & IEEE80211_SDATA_IN_DRIVER))
  496. iterator(data, sdata->vif.addr, &sdata->vif);
  497. }
  498. void ieee80211_iterate_active_interfaces(
  499. struct ieee80211_hw *hw, u32 iter_flags,
  500. void (*iterator)(void *data, u8 *mac,
  501. struct ieee80211_vif *vif),
  502. void *data)
  503. {
  504. struct ieee80211_local *local = hw_to_local(hw);
  505. mutex_lock(&local->iflist_mtx);
  506. __iterate_active_interfaces(local, iter_flags, iterator, data);
  507. mutex_unlock(&local->iflist_mtx);
  508. }
  509. EXPORT_SYMBOL_GPL(ieee80211_iterate_active_interfaces);
  510. void ieee80211_iterate_active_interfaces_atomic(
  511. struct ieee80211_hw *hw, u32 iter_flags,
  512. void (*iterator)(void *data, u8 *mac,
  513. struct ieee80211_vif *vif),
  514. void *data)
  515. {
  516. struct ieee80211_local *local = hw_to_local(hw);
  517. rcu_read_lock();
  518. __iterate_active_interfaces(local, iter_flags, iterator, data);
  519. rcu_read_unlock();
  520. }
  521. EXPORT_SYMBOL_GPL(ieee80211_iterate_active_interfaces_atomic);
  522. void ieee80211_iterate_active_interfaces_rtnl(
  523. struct ieee80211_hw *hw, u32 iter_flags,
  524. void (*iterator)(void *data, u8 *mac,
  525. struct ieee80211_vif *vif),
  526. void *data)
  527. {
  528. struct ieee80211_local *local = hw_to_local(hw);
  529. ASSERT_RTNL();
  530. __iterate_active_interfaces(local, iter_flags, iterator, data);
  531. }
  532. EXPORT_SYMBOL_GPL(ieee80211_iterate_active_interfaces_rtnl);
  533. /*
  534. * Nothing should have been stuffed into the workqueue during
  535. * the suspend->resume cycle. If this WARN is seen then there
  536. * is a bug with either the driver suspend or something in
  537. * mac80211 stuffing into the workqueue which we haven't yet
  538. * cleared during mac80211's suspend cycle.
  539. */
  540. static bool ieee80211_can_queue_work(struct ieee80211_local *local)
  541. {
  542. if (WARN(local->suspended && !local->resuming,
  543. "queueing ieee80211 work while going to suspend\n"))
  544. return false;
  545. return true;
  546. }
  547. void ieee80211_queue_work(struct ieee80211_hw *hw, struct work_struct *work)
  548. {
  549. struct ieee80211_local *local = hw_to_local(hw);
  550. if (!ieee80211_can_queue_work(local))
  551. return;
  552. queue_work(local->workqueue, work);
  553. }
  554. EXPORT_SYMBOL(ieee80211_queue_work);
  555. void ieee80211_queue_delayed_work(struct ieee80211_hw *hw,
  556. struct delayed_work *dwork,
  557. unsigned long delay)
  558. {
  559. struct ieee80211_local *local = hw_to_local(hw);
  560. if (!ieee80211_can_queue_work(local))
  561. return;
  562. queue_delayed_work(local->workqueue, dwork, delay);
  563. }
  564. EXPORT_SYMBOL(ieee80211_queue_delayed_work);
  565. u32 ieee802_11_parse_elems_crc(const u8 *start, size_t len, bool action,
  566. struct ieee802_11_elems *elems,
  567. u64 filter, u32 crc)
  568. {
  569. size_t left = len;
  570. const u8 *pos = start;
  571. bool calc_crc = filter != 0;
  572. DECLARE_BITMAP(seen_elems, 256);
  573. const u8 *ie;
  574. bitmap_zero(seen_elems, 256);
  575. memset(elems, 0, sizeof(*elems));
  576. elems->ie_start = start;
  577. elems->total_len = len;
  578. while (left >= 2) {
  579. u8 id, elen;
  580. bool elem_parse_failed;
  581. id = *pos++;
  582. elen = *pos++;
  583. left -= 2;
  584. if (elen > left) {
  585. elems->parse_error = true;
  586. break;
  587. }
  588. switch (id) {
  589. case WLAN_EID_SSID:
  590. case WLAN_EID_SUPP_RATES:
  591. case WLAN_EID_FH_PARAMS:
  592. case WLAN_EID_DS_PARAMS:
  593. case WLAN_EID_CF_PARAMS:
  594. case WLAN_EID_TIM:
  595. case WLAN_EID_IBSS_PARAMS:
  596. case WLAN_EID_CHALLENGE:
  597. case WLAN_EID_RSN:
  598. case WLAN_EID_ERP_INFO:
  599. case WLAN_EID_EXT_SUPP_RATES:
  600. case WLAN_EID_HT_CAPABILITY:
  601. case WLAN_EID_HT_OPERATION:
  602. case WLAN_EID_VHT_CAPABILITY:
  603. case WLAN_EID_VHT_OPERATION:
  604. case WLAN_EID_MESH_ID:
  605. case WLAN_EID_MESH_CONFIG:
  606. case WLAN_EID_PEER_MGMT:
  607. case WLAN_EID_PREQ:
  608. case WLAN_EID_PREP:
  609. case WLAN_EID_PERR:
  610. case WLAN_EID_RANN:
  611. case WLAN_EID_CHANNEL_SWITCH:
  612. case WLAN_EID_EXT_CHANSWITCH_ANN:
  613. case WLAN_EID_COUNTRY:
  614. case WLAN_EID_PWR_CONSTRAINT:
  615. case WLAN_EID_TIMEOUT_INTERVAL:
  616. case WLAN_EID_SECONDARY_CHANNEL_OFFSET:
  617. case WLAN_EID_WIDE_BW_CHANNEL_SWITCH:
  618. /*
  619. * not listing WLAN_EID_CHANNEL_SWITCH_WRAPPER -- it seems possible
  620. * that if the content gets bigger it might be needed more than once
  621. */
  622. if (test_bit(id, seen_elems)) {
  623. elems->parse_error = true;
  624. left -= elen;
  625. pos += elen;
  626. continue;
  627. }
  628. break;
  629. }
  630. if (calc_crc && id < 64 && (filter & (1ULL << id)))
  631. crc = crc32_be(crc, pos - 2, elen + 2);
  632. elem_parse_failed = false;
  633. switch (id) {
  634. case WLAN_EID_SSID:
  635. elems->ssid = pos;
  636. elems->ssid_len = elen;
  637. break;
  638. case WLAN_EID_SUPP_RATES:
  639. elems->supp_rates = pos;
  640. elems->supp_rates_len = elen;
  641. break;
  642. case WLAN_EID_DS_PARAMS:
  643. if (elen >= 1)
  644. elems->ds_params = pos;
  645. else
  646. elem_parse_failed = true;
  647. break;
  648. case WLAN_EID_TIM:
  649. if (elen >= sizeof(struct ieee80211_tim_ie)) {
  650. elems->tim = (void *)pos;
  651. elems->tim_len = elen;
  652. } else
  653. elem_parse_failed = true;
  654. break;
  655. case WLAN_EID_CHALLENGE:
  656. elems->challenge = pos;
  657. elems->challenge_len = elen;
  658. break;
  659. case WLAN_EID_VENDOR_SPECIFIC:
  660. if (elen >= 4 && pos[0] == 0x00 && pos[1] == 0x50 &&
  661. pos[2] == 0xf2) {
  662. /* Microsoft OUI (00:50:F2) */
  663. if (calc_crc)
  664. crc = crc32_be(crc, pos - 2, elen + 2);
  665. if (elen >= 5 && pos[3] == 2) {
  666. /* OUI Type 2 - WMM IE */
  667. if (pos[4] == 0) {
  668. elems->wmm_info = pos;
  669. elems->wmm_info_len = elen;
  670. } else if (pos[4] == 1) {
  671. elems->wmm_param = pos;
  672. elems->wmm_param_len = elen;
  673. }
  674. }
  675. }
  676. break;
  677. case WLAN_EID_RSN:
  678. elems->rsn = pos;
  679. elems->rsn_len = elen;
  680. break;
  681. case WLAN_EID_ERP_INFO:
  682. if (elen >= 1)
  683. elems->erp_info = pos;
  684. else
  685. elem_parse_failed = true;
  686. break;
  687. case WLAN_EID_EXT_SUPP_RATES:
  688. elems->ext_supp_rates = pos;
  689. elems->ext_supp_rates_len = elen;
  690. break;
  691. case WLAN_EID_HT_CAPABILITY:
  692. if (elen >= sizeof(struct ieee80211_ht_cap))
  693. elems->ht_cap_elem = (void *)pos;
  694. else
  695. elem_parse_failed = true;
  696. break;
  697. case WLAN_EID_HT_OPERATION:
  698. if (elen >= sizeof(struct ieee80211_ht_operation))
  699. elems->ht_operation = (void *)pos;
  700. else
  701. elem_parse_failed = true;
  702. break;
  703. case WLAN_EID_VHT_CAPABILITY:
  704. if (elen >= sizeof(struct ieee80211_vht_cap))
  705. elems->vht_cap_elem = (void *)pos;
  706. else
  707. elem_parse_failed = true;
  708. break;
  709. case WLAN_EID_VHT_OPERATION:
  710. if (elen >= sizeof(struct ieee80211_vht_operation))
  711. elems->vht_operation = (void *)pos;
  712. else
  713. elem_parse_failed = true;
  714. break;
  715. case WLAN_EID_OPMODE_NOTIF:
  716. if (elen > 0)
  717. elems->opmode_notif = pos;
  718. else
  719. elem_parse_failed = true;
  720. break;
  721. case WLAN_EID_MESH_ID:
  722. elems->mesh_id = pos;
  723. elems->mesh_id_len = elen;
  724. break;
  725. case WLAN_EID_MESH_CONFIG:
  726. if (elen >= sizeof(struct ieee80211_meshconf_ie))
  727. elems->mesh_config = (void *)pos;
  728. else
  729. elem_parse_failed = true;
  730. break;
  731. case WLAN_EID_PEER_MGMT:
  732. elems->peering = pos;
  733. elems->peering_len = elen;
  734. break;
  735. case WLAN_EID_MESH_AWAKE_WINDOW:
  736. if (elen >= 2)
  737. elems->awake_window = (void *)pos;
  738. break;
  739. case WLAN_EID_PREQ:
  740. elems->preq = pos;
  741. elems->preq_len = elen;
  742. break;
  743. case WLAN_EID_PREP:
  744. elems->prep = pos;
  745. elems->prep_len = elen;
  746. break;
  747. case WLAN_EID_PERR:
  748. elems->perr = pos;
  749. elems->perr_len = elen;
  750. break;
  751. case WLAN_EID_RANN:
  752. if (elen >= sizeof(struct ieee80211_rann_ie))
  753. elems->rann = (void *)pos;
  754. else
  755. elem_parse_failed = true;
  756. break;
  757. case WLAN_EID_CHANNEL_SWITCH:
  758. if (elen != sizeof(struct ieee80211_channel_sw_ie)) {
  759. elem_parse_failed = true;
  760. break;
  761. }
  762. elems->ch_switch_ie = (void *)pos;
  763. break;
  764. case WLAN_EID_EXT_CHANSWITCH_ANN:
  765. if (elen != sizeof(struct ieee80211_ext_chansw_ie)) {
  766. elem_parse_failed = true;
  767. break;
  768. }
  769. elems->ext_chansw_ie = (void *)pos;
  770. break;
  771. case WLAN_EID_SECONDARY_CHANNEL_OFFSET:
  772. if (elen != sizeof(struct ieee80211_sec_chan_offs_ie)) {
  773. elem_parse_failed = true;
  774. break;
  775. }
  776. elems->sec_chan_offs = (void *)pos;
  777. break;
  778. case WLAN_EID_WIDE_BW_CHANNEL_SWITCH:
  779. if (!action ||
  780. elen != sizeof(*elems->wide_bw_chansw_ie)) {
  781. elem_parse_failed = true;
  782. break;
  783. }
  784. elems->wide_bw_chansw_ie = (void *)pos;
  785. break;
  786. case WLAN_EID_CHANNEL_SWITCH_WRAPPER:
  787. if (action) {
  788. elem_parse_failed = true;
  789. break;
  790. }
  791. /*
  792. * This is a bit tricky, but as we only care about
  793. * the wide bandwidth channel switch element, so
  794. * just parse it out manually.
  795. */
  796. ie = cfg80211_find_ie(WLAN_EID_WIDE_BW_CHANNEL_SWITCH,
  797. pos, elen);
  798. if (ie) {
  799. if (ie[1] == sizeof(*elems->wide_bw_chansw_ie))
  800. elems->wide_bw_chansw_ie =
  801. (void *)(ie + 2);
  802. else
  803. elem_parse_failed = true;
  804. }
  805. break;
  806. case WLAN_EID_COUNTRY:
  807. elems->country_elem = pos;
  808. elems->country_elem_len = elen;
  809. break;
  810. case WLAN_EID_PWR_CONSTRAINT:
  811. if (elen != 1) {
  812. elem_parse_failed = true;
  813. break;
  814. }
  815. elems->pwr_constr_elem = pos;
  816. break;
  817. case WLAN_EID_TIMEOUT_INTERVAL:
  818. if (elen >= sizeof(struct ieee80211_timeout_interval_ie))
  819. elems->timeout_int = (void *)pos;
  820. else
  821. elem_parse_failed = true;
  822. break;
  823. default:
  824. break;
  825. }
  826. if (elem_parse_failed)
  827. elems->parse_error = true;
  828. else
  829. __set_bit(id, seen_elems);
  830. left -= elen;
  831. pos += elen;
  832. }
  833. if (left != 0)
  834. elems->parse_error = true;
  835. return crc;
  836. }
  837. void ieee80211_set_wmm_default(struct ieee80211_sub_if_data *sdata,
  838. bool bss_notify)
  839. {
  840. struct ieee80211_local *local = sdata->local;
  841. struct ieee80211_tx_queue_params qparam;
  842. struct ieee80211_chanctx_conf *chanctx_conf;
  843. int ac;
  844. bool use_11b, enable_qos;
  845. int aCWmin, aCWmax;
  846. if (!local->ops->conf_tx)
  847. return;
  848. if (local->hw.queues < IEEE80211_NUM_ACS)
  849. return;
  850. memset(&qparam, 0, sizeof(qparam));
  851. rcu_read_lock();
  852. chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
  853. use_11b = (chanctx_conf &&
  854. chanctx_conf->def.chan->band == IEEE80211_BAND_2GHZ) &&
  855. !(sdata->flags & IEEE80211_SDATA_OPERATING_GMODE);
  856. rcu_read_unlock();
  857. /*
  858. * By default disable QoS in STA mode for old access points, which do
  859. * not support 802.11e. New APs will provide proper queue parameters,
  860. * that we will configure later.
  861. */
  862. enable_qos = (sdata->vif.type != NL80211_IFTYPE_STATION);
  863. /* Set defaults according to 802.11-2007 Table 7-37 */
  864. aCWmax = 1023;
  865. if (use_11b)
  866. aCWmin = 31;
  867. else
  868. aCWmin = 15;
  869. /* Confiure old 802.11b/g medium access rules. */
  870. qparam.cw_max = aCWmax;
  871. qparam.cw_min = aCWmin;
  872. qparam.txop = 0;
  873. qparam.aifs = 2;
  874. for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
  875. /* Update if QoS is enabled. */
  876. if (enable_qos) {
  877. switch (ac) {
  878. case IEEE80211_AC_BK:
  879. qparam.cw_max = aCWmax;
  880. qparam.cw_min = aCWmin;
  881. qparam.txop = 0;
  882. qparam.aifs = 7;
  883. break;
  884. /* never happens but let's not leave undefined */
  885. default:
  886. case IEEE80211_AC_BE:
  887. qparam.cw_max = aCWmax;
  888. qparam.cw_min = aCWmin;
  889. qparam.txop = 0;
  890. qparam.aifs = 3;
  891. break;
  892. case IEEE80211_AC_VI:
  893. qparam.cw_max = aCWmin;
  894. qparam.cw_min = (aCWmin + 1) / 2 - 1;
  895. if (use_11b)
  896. qparam.txop = 6016/32;
  897. else
  898. qparam.txop = 3008/32;
  899. qparam.aifs = 2;
  900. break;
  901. case IEEE80211_AC_VO:
  902. qparam.cw_max = (aCWmin + 1) / 2 - 1;
  903. qparam.cw_min = (aCWmin + 1) / 4 - 1;
  904. if (use_11b)
  905. qparam.txop = 3264/32;
  906. else
  907. qparam.txop = 1504/32;
  908. qparam.aifs = 2;
  909. break;
  910. }
  911. }
  912. qparam.uapsd = false;
  913. sdata->tx_conf[ac] = qparam;
  914. drv_conf_tx(local, sdata, ac, &qparam);
  915. }
  916. if (sdata->vif.type != NL80211_IFTYPE_MONITOR &&
  917. sdata->vif.type != NL80211_IFTYPE_P2P_DEVICE) {
  918. sdata->vif.bss_conf.qos = enable_qos;
  919. if (bss_notify)
  920. ieee80211_bss_info_change_notify(sdata,
  921. BSS_CHANGED_QOS);
  922. }
  923. }
  924. void ieee80211_send_auth(struct ieee80211_sub_if_data *sdata,
  925. u16 transaction, u16 auth_alg, u16 status,
  926. const u8 *extra, size_t extra_len, const u8 *da,
  927. const u8 *bssid, const u8 *key, u8 key_len, u8 key_idx,
  928. u32 tx_flags)
  929. {
  930. struct ieee80211_local *local = sdata->local;
  931. struct sk_buff *skb;
  932. struct ieee80211_mgmt *mgmt;
  933. int err;
  934. /* 24 + 6 = header + auth_algo + auth_transaction + status_code */
  935. skb = dev_alloc_skb(local->hw.extra_tx_headroom + 24 + 6 + extra_len);
  936. if (!skb)
  937. return;
  938. skb_reserve(skb, local->hw.extra_tx_headroom);
  939. mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24 + 6);
  940. memset(mgmt, 0, 24 + 6);
  941. mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
  942. IEEE80211_STYPE_AUTH);
  943. memcpy(mgmt->da, da, ETH_ALEN);
  944. memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
  945. memcpy(mgmt->bssid, bssid, ETH_ALEN);
  946. mgmt->u.auth.auth_alg = cpu_to_le16(auth_alg);
  947. mgmt->u.auth.auth_transaction = cpu_to_le16(transaction);
  948. mgmt->u.auth.status_code = cpu_to_le16(status);
  949. if (extra)
  950. memcpy(skb_put(skb, extra_len), extra, extra_len);
  951. if (auth_alg == WLAN_AUTH_SHARED_KEY && transaction == 3) {
  952. mgmt->frame_control |= cpu_to_le16(IEEE80211_FCTL_PROTECTED);
  953. err = ieee80211_wep_encrypt(local, skb, key, key_len, key_idx);
  954. WARN_ON(err);
  955. }
  956. IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT |
  957. tx_flags;
  958. ieee80211_tx_skb(sdata, skb);
  959. }
  960. void ieee80211_send_deauth_disassoc(struct ieee80211_sub_if_data *sdata,
  961. const u8 *bssid, u16 stype, u16 reason,
  962. bool send_frame, u8 *frame_buf)
  963. {
  964. struct ieee80211_local *local = sdata->local;
  965. struct sk_buff *skb;
  966. struct ieee80211_mgmt *mgmt = (void *)frame_buf;
  967. /* build frame */
  968. mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | stype);
  969. mgmt->duration = 0; /* initialize only */
  970. mgmt->seq_ctrl = 0; /* initialize only */
  971. memcpy(mgmt->da, bssid, ETH_ALEN);
  972. memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
  973. memcpy(mgmt->bssid, bssid, ETH_ALEN);
  974. /* u.deauth.reason_code == u.disassoc.reason_code */
  975. mgmt->u.deauth.reason_code = cpu_to_le16(reason);
  976. if (send_frame) {
  977. skb = dev_alloc_skb(local->hw.extra_tx_headroom +
  978. IEEE80211_DEAUTH_FRAME_LEN);
  979. if (!skb)
  980. return;
  981. skb_reserve(skb, local->hw.extra_tx_headroom);
  982. /* copy in frame */
  983. memcpy(skb_put(skb, IEEE80211_DEAUTH_FRAME_LEN),
  984. mgmt, IEEE80211_DEAUTH_FRAME_LEN);
  985. if (sdata->vif.type != NL80211_IFTYPE_STATION ||
  986. !(sdata->u.mgd.flags & IEEE80211_STA_MFP_ENABLED))
  987. IEEE80211_SKB_CB(skb)->flags |=
  988. IEEE80211_TX_INTFL_DONT_ENCRYPT;
  989. ieee80211_tx_skb(sdata, skb);
  990. }
  991. }
  992. int ieee80211_build_preq_ies(struct ieee80211_local *local, u8 *buffer,
  993. size_t buffer_len, const u8 *ie, size_t ie_len,
  994. enum ieee80211_band band, u32 rate_mask,
  995. struct cfg80211_chan_def *chandef)
  996. {
  997. struct ieee80211_supported_band *sband;
  998. u8 *pos = buffer, *end = buffer + buffer_len;
  999. size_t offset = 0, noffset;
  1000. int supp_rates_len, i;
  1001. u8 rates[32];
  1002. int num_rates;
  1003. int ext_rates_len;
  1004. int shift;
  1005. u32 rate_flags;
  1006. sband = local->hw.wiphy->bands[band];
  1007. if (WARN_ON_ONCE(!sband))
  1008. return 0;
  1009. rate_flags = ieee80211_chandef_rate_flags(chandef);
  1010. shift = ieee80211_chandef_get_shift(chandef);
  1011. num_rates = 0;
  1012. for (i = 0; i < sband->n_bitrates; i++) {
  1013. if ((BIT(i) & rate_mask) == 0)
  1014. continue; /* skip rate */
  1015. if ((rate_flags & sband->bitrates[i].flags) != rate_flags)
  1016. continue;
  1017. rates[num_rates++] =
  1018. (u8) DIV_ROUND_UP(sband->bitrates[i].bitrate,
  1019. (1 << shift) * 5);
  1020. }
  1021. supp_rates_len = min_t(int, num_rates, 8);
  1022. if (end - pos < 2 + supp_rates_len)
  1023. goto out_err;
  1024. *pos++ = WLAN_EID_SUPP_RATES;
  1025. *pos++ = supp_rates_len;
  1026. memcpy(pos, rates, supp_rates_len);
  1027. pos += supp_rates_len;
  1028. /* insert "request information" if in custom IEs */
  1029. if (ie && ie_len) {
  1030. static const u8 before_extrates[] = {
  1031. WLAN_EID_SSID,
  1032. WLAN_EID_SUPP_RATES,
  1033. WLAN_EID_REQUEST,
  1034. };
  1035. noffset = ieee80211_ie_split(ie, ie_len,
  1036. before_extrates,
  1037. ARRAY_SIZE(before_extrates),
  1038. offset);
  1039. if (end - pos < noffset - offset)
  1040. goto out_err;
  1041. memcpy(pos, ie + offset, noffset - offset);
  1042. pos += noffset - offset;
  1043. offset = noffset;
  1044. }
  1045. ext_rates_len = num_rates - supp_rates_len;
  1046. if (ext_rates_len > 0) {
  1047. if (end - pos < 2 + ext_rates_len)
  1048. goto out_err;
  1049. *pos++ = WLAN_EID_EXT_SUPP_RATES;
  1050. *pos++ = ext_rates_len;
  1051. memcpy(pos, rates + supp_rates_len, ext_rates_len);
  1052. pos += ext_rates_len;
  1053. }
  1054. if (chandef->chan && sband->band == IEEE80211_BAND_2GHZ) {
  1055. if (end - pos < 3)
  1056. goto out_err;
  1057. *pos++ = WLAN_EID_DS_PARAMS;
  1058. *pos++ = 1;
  1059. *pos++ = ieee80211_frequency_to_channel(
  1060. chandef->chan->center_freq);
  1061. }
  1062. /* insert custom IEs that go before HT */
  1063. if (ie && ie_len) {
  1064. static const u8 before_ht[] = {
  1065. WLAN_EID_SSID,
  1066. WLAN_EID_SUPP_RATES,
  1067. WLAN_EID_REQUEST,
  1068. WLAN_EID_EXT_SUPP_RATES,
  1069. WLAN_EID_DS_PARAMS,
  1070. WLAN_EID_SUPPORTED_REGULATORY_CLASSES,
  1071. };
  1072. noffset = ieee80211_ie_split(ie, ie_len,
  1073. before_ht, ARRAY_SIZE(before_ht),
  1074. offset);
  1075. if (end - pos < noffset - offset)
  1076. goto out_err;
  1077. memcpy(pos, ie + offset, noffset - offset);
  1078. pos += noffset - offset;
  1079. offset = noffset;
  1080. }
  1081. if (sband->ht_cap.ht_supported) {
  1082. if (end - pos < 2 + sizeof(struct ieee80211_ht_cap))
  1083. goto out_err;
  1084. pos = ieee80211_ie_build_ht_cap(pos, &sband->ht_cap,
  1085. sband->ht_cap.cap);
  1086. }
  1087. /*
  1088. * If adding more here, adjust code in main.c
  1089. * that calculates local->scan_ies_len.
  1090. */
  1091. /* add any remaining custom IEs */
  1092. if (ie && ie_len) {
  1093. noffset = ie_len;
  1094. if (end - pos < noffset - offset)
  1095. goto out_err;
  1096. memcpy(pos, ie + offset, noffset - offset);
  1097. pos += noffset - offset;
  1098. }
  1099. if (sband->vht_cap.vht_supported) {
  1100. if (end - pos < 2 + sizeof(struct ieee80211_vht_cap))
  1101. goto out_err;
  1102. pos = ieee80211_ie_build_vht_cap(pos, &sband->vht_cap,
  1103. sband->vht_cap.cap);
  1104. }
  1105. return pos - buffer;
  1106. out_err:
  1107. WARN_ONCE(1, "not enough space for preq IEs\n");
  1108. return pos - buffer;
  1109. }
  1110. struct sk_buff *ieee80211_build_probe_req(struct ieee80211_sub_if_data *sdata,
  1111. u8 *dst, u32 ratemask,
  1112. struct ieee80211_channel *chan,
  1113. const u8 *ssid, size_t ssid_len,
  1114. const u8 *ie, size_t ie_len,
  1115. bool directed)
  1116. {
  1117. struct ieee80211_local *local = sdata->local;
  1118. struct cfg80211_chan_def chandef;
  1119. struct sk_buff *skb;
  1120. struct ieee80211_mgmt *mgmt;
  1121. int ies_len;
  1122. /*
  1123. * Do not send DS Channel parameter for directed probe requests
  1124. * in order to maximize the chance that we get a response. Some
  1125. * badly-behaved APs don't respond when this parameter is included.
  1126. */
  1127. chandef.width = sdata->vif.bss_conf.chandef.width;
  1128. if (directed)
  1129. chandef.chan = NULL;
  1130. else
  1131. chandef.chan = chan;
  1132. skb = ieee80211_probereq_get(&local->hw, &sdata->vif,
  1133. ssid, ssid_len, 100 + ie_len);
  1134. if (!skb)
  1135. return NULL;
  1136. ies_len = ieee80211_build_preq_ies(local, skb_tail_pointer(skb),
  1137. skb_tailroom(skb),
  1138. ie, ie_len, chan->band,
  1139. ratemask, &chandef);
  1140. skb_put(skb, ies_len);
  1141. if (dst) {
  1142. mgmt = (struct ieee80211_mgmt *) skb->data;
  1143. memcpy(mgmt->da, dst, ETH_ALEN);
  1144. memcpy(mgmt->bssid, dst, ETH_ALEN);
  1145. }
  1146. IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
  1147. return skb;
  1148. }
  1149. void ieee80211_send_probe_req(struct ieee80211_sub_if_data *sdata, u8 *dst,
  1150. const u8 *ssid, size_t ssid_len,
  1151. const u8 *ie, size_t ie_len,
  1152. u32 ratemask, bool directed, u32 tx_flags,
  1153. struct ieee80211_channel *channel, bool scan)
  1154. {
  1155. struct sk_buff *skb;
  1156. skb = ieee80211_build_probe_req(sdata, dst, ratemask, channel,
  1157. ssid, ssid_len,
  1158. ie, ie_len, directed);
  1159. if (skb) {
  1160. IEEE80211_SKB_CB(skb)->flags |= tx_flags;
  1161. if (scan)
  1162. ieee80211_tx_skb_tid_band(sdata, skb, 7, channel->band);
  1163. else
  1164. ieee80211_tx_skb(sdata, skb);
  1165. }
  1166. }
  1167. u32 ieee80211_sta_get_rates(struct ieee80211_sub_if_data *sdata,
  1168. struct ieee802_11_elems *elems,
  1169. enum ieee80211_band band, u32 *basic_rates)
  1170. {
  1171. struct ieee80211_supported_band *sband;
  1172. struct ieee80211_rate *bitrates;
  1173. size_t num_rates;
  1174. u32 supp_rates, rate_flags;
  1175. int i, j, shift;
  1176. sband = sdata->local->hw.wiphy->bands[band];
  1177. rate_flags = ieee80211_chandef_rate_flags(&sdata->vif.bss_conf.chandef);
  1178. shift = ieee80211_vif_get_shift(&sdata->vif);
  1179. if (WARN_ON(!sband))
  1180. return 1;
  1181. bitrates = sband->bitrates;
  1182. num_rates = sband->n_bitrates;
  1183. supp_rates = 0;
  1184. for (i = 0; i < elems->supp_rates_len +
  1185. elems->ext_supp_rates_len; i++) {
  1186. u8 rate = 0;
  1187. int own_rate;
  1188. bool is_basic;
  1189. if (i < elems->supp_rates_len)
  1190. rate = elems->supp_rates[i];
  1191. else if (elems->ext_supp_rates)
  1192. rate = elems->ext_supp_rates
  1193. [i - elems->supp_rates_len];
  1194. own_rate = 5 * (rate & 0x7f);
  1195. is_basic = !!(rate & 0x80);
  1196. if (is_basic && (rate & 0x7f) == BSS_MEMBERSHIP_SELECTOR_HT_PHY)
  1197. continue;
  1198. for (j = 0; j < num_rates; j++) {
  1199. int brate;
  1200. if ((rate_flags & sband->bitrates[j].flags)
  1201. != rate_flags)
  1202. continue;
  1203. brate = DIV_ROUND_UP(sband->bitrates[j].bitrate,
  1204. 1 << shift);
  1205. if (brate == own_rate) {
  1206. supp_rates |= BIT(j);
  1207. if (basic_rates && is_basic)
  1208. *basic_rates |= BIT(j);
  1209. }
  1210. }
  1211. }
  1212. return supp_rates;
  1213. }
  1214. void ieee80211_stop_device(struct ieee80211_local *local)
  1215. {
  1216. ieee80211_led_radio(local, false);
  1217. ieee80211_mod_tpt_led_trig(local, 0, IEEE80211_TPT_LEDTRIG_FL_RADIO);
  1218. cancel_work_sync(&local->reconfig_filter);
  1219. flush_workqueue(local->workqueue);
  1220. drv_stop(local);
  1221. }
  1222. static void ieee80211_assign_chanctx(struct ieee80211_local *local,
  1223. struct ieee80211_sub_if_data *sdata)
  1224. {
  1225. struct ieee80211_chanctx_conf *conf;
  1226. struct ieee80211_chanctx *ctx;
  1227. if (!local->use_chanctx)
  1228. return;
  1229. mutex_lock(&local->chanctx_mtx);
  1230. conf = rcu_dereference_protected(sdata->vif.chanctx_conf,
  1231. lockdep_is_held(&local->chanctx_mtx));
  1232. if (conf) {
  1233. ctx = container_of(conf, struct ieee80211_chanctx, conf);
  1234. drv_assign_vif_chanctx(local, sdata, ctx);
  1235. }
  1236. mutex_unlock(&local->chanctx_mtx);
  1237. }
  1238. int ieee80211_reconfig(struct ieee80211_local *local)
  1239. {
  1240. struct ieee80211_hw *hw = &local->hw;
  1241. struct ieee80211_sub_if_data *sdata;
  1242. struct ieee80211_chanctx *ctx;
  1243. struct sta_info *sta;
  1244. int res, i;
  1245. bool reconfig_due_to_wowlan = false;
  1246. #ifdef CONFIG_PM
  1247. if (local->suspended)
  1248. local->resuming = true;
  1249. if (local->wowlan) {
  1250. res = drv_resume(local);
  1251. local->wowlan = false;
  1252. if (res < 0) {
  1253. local->resuming = false;
  1254. return res;
  1255. }
  1256. if (res == 0)
  1257. goto wake_up;
  1258. WARN_ON(res > 1);
  1259. /*
  1260. * res is 1, which means the driver requested
  1261. * to go through a regular reset on wakeup.
  1262. */
  1263. reconfig_due_to_wowlan = true;
  1264. }
  1265. #endif
  1266. /* everything else happens only if HW was up & running */
  1267. if (!local->open_count)
  1268. goto wake_up;
  1269. /*
  1270. * Upon resume hardware can sometimes be goofy due to
  1271. * various platform / driver / bus issues, so restarting
  1272. * the device may at times not work immediately. Propagate
  1273. * the error.
  1274. */
  1275. res = drv_start(local);
  1276. if (res) {
  1277. WARN(local->suspended, "Hardware became unavailable "
  1278. "upon resume. This could be a software issue "
  1279. "prior to suspend or a hardware issue.\n");
  1280. return res;
  1281. }
  1282. /* setup fragmentation threshold */
  1283. drv_set_frag_threshold(local, hw->wiphy->frag_threshold);
  1284. /* setup RTS threshold */
  1285. drv_set_rts_threshold(local, hw->wiphy->rts_threshold);
  1286. /* reset coverage class */
  1287. drv_set_coverage_class(local, hw->wiphy->coverage_class);
  1288. ieee80211_led_radio(local, true);
  1289. ieee80211_mod_tpt_led_trig(local,
  1290. IEEE80211_TPT_LEDTRIG_FL_RADIO, 0);
  1291. /* add interfaces */
  1292. sdata = rtnl_dereference(local->monitor_sdata);
  1293. if (sdata) {
  1294. /* in HW restart it exists already */
  1295. WARN_ON(local->resuming);
  1296. res = drv_add_interface(local, sdata);
  1297. if (WARN_ON(res)) {
  1298. rcu_assign_pointer(local->monitor_sdata, NULL);
  1299. synchronize_net();
  1300. kfree(sdata);
  1301. }
  1302. }
  1303. list_for_each_entry(sdata, &local->interfaces, list) {
  1304. if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
  1305. sdata->vif.type != NL80211_IFTYPE_MONITOR &&
  1306. ieee80211_sdata_running(sdata))
  1307. res = drv_add_interface(local, sdata);
  1308. }
  1309. /* add channel contexts */
  1310. if (local->use_chanctx) {
  1311. mutex_lock(&local->chanctx_mtx);
  1312. list_for_each_entry(ctx, &local->chanctx_list, list)
  1313. WARN_ON(drv_add_chanctx(local, ctx));
  1314. mutex_unlock(&local->chanctx_mtx);
  1315. }
  1316. list_for_each_entry(sdata, &local->interfaces, list) {
  1317. if (!ieee80211_sdata_running(sdata))
  1318. continue;
  1319. ieee80211_assign_chanctx(local, sdata);
  1320. }
  1321. sdata = rtnl_dereference(local->monitor_sdata);
  1322. if (sdata && ieee80211_sdata_running(sdata))
  1323. ieee80211_assign_chanctx(local, sdata);
  1324. /* add STAs back */
  1325. mutex_lock(&local->sta_mtx);
  1326. list_for_each_entry(sta, &local->sta_list, list) {
  1327. enum ieee80211_sta_state state;
  1328. if (!sta->uploaded)
  1329. continue;
  1330. /* AP-mode stations will be added later */
  1331. if (sta->sdata->vif.type == NL80211_IFTYPE_AP)
  1332. continue;
  1333. for (state = IEEE80211_STA_NOTEXIST;
  1334. state < sta->sta_state; state++)
  1335. WARN_ON(drv_sta_state(local, sta->sdata, sta, state,
  1336. state + 1));
  1337. }
  1338. mutex_unlock(&local->sta_mtx);
  1339. /* reconfigure tx conf */
  1340. if (hw->queues >= IEEE80211_NUM_ACS) {
  1341. list_for_each_entry(sdata, &local->interfaces, list) {
  1342. if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
  1343. sdata->vif.type == NL80211_IFTYPE_MONITOR ||
  1344. !ieee80211_sdata_running(sdata))
  1345. continue;
  1346. for (i = 0; i < IEEE80211_NUM_ACS; i++)
  1347. drv_conf_tx(local, sdata, i,
  1348. &sdata->tx_conf[i]);
  1349. }
  1350. }
  1351. /* reconfigure hardware */
  1352. ieee80211_hw_config(local, ~0);
  1353. ieee80211_configure_filter(local);
  1354. /* Finally also reconfigure all the BSS information */
  1355. list_for_each_entry(sdata, &local->interfaces, list) {
  1356. u32 changed;
  1357. if (!ieee80211_sdata_running(sdata))
  1358. continue;
  1359. /* common change flags for all interface types */
  1360. changed = BSS_CHANGED_ERP_CTS_PROT |
  1361. BSS_CHANGED_ERP_PREAMBLE |
  1362. BSS_CHANGED_ERP_SLOT |
  1363. BSS_CHANGED_HT |
  1364. BSS_CHANGED_BASIC_RATES |
  1365. BSS_CHANGED_BEACON_INT |
  1366. BSS_CHANGED_BSSID |
  1367. BSS_CHANGED_CQM |
  1368. BSS_CHANGED_QOS |
  1369. BSS_CHANGED_IDLE |
  1370. BSS_CHANGED_TXPOWER;
  1371. switch (sdata->vif.type) {
  1372. case NL80211_IFTYPE_STATION:
  1373. changed |= BSS_CHANGED_ASSOC |
  1374. BSS_CHANGED_ARP_FILTER |
  1375. BSS_CHANGED_PS;
  1376. /* Re-send beacon info report to the driver */
  1377. if (sdata->u.mgd.have_beacon)
  1378. changed |= BSS_CHANGED_BEACON_INFO;
  1379. sdata_lock(sdata);
  1380. ieee80211_bss_info_change_notify(sdata, changed);
  1381. sdata_unlock(sdata);
  1382. break;
  1383. case NL80211_IFTYPE_ADHOC:
  1384. changed |= BSS_CHANGED_IBSS;
  1385. /* fall through */
  1386. case NL80211_IFTYPE_AP:
  1387. changed |= BSS_CHANGED_SSID | BSS_CHANGED_P2P_PS;
  1388. if (sdata->vif.type == NL80211_IFTYPE_AP) {
  1389. changed |= BSS_CHANGED_AP_PROBE_RESP;
  1390. if (rcu_access_pointer(sdata->u.ap.beacon))
  1391. drv_start_ap(local, sdata);
  1392. }
  1393. /* fall through */
  1394. case NL80211_IFTYPE_MESH_POINT:
  1395. if (sdata->vif.bss_conf.enable_beacon) {
  1396. changed |= BSS_CHANGED_BEACON |
  1397. BSS_CHANGED_BEACON_ENABLED;
  1398. ieee80211_bss_info_change_notify(sdata, changed);
  1399. }
  1400. break;
  1401. case NL80211_IFTYPE_WDS:
  1402. break;
  1403. case NL80211_IFTYPE_AP_VLAN:
  1404. case NL80211_IFTYPE_MONITOR:
  1405. /* ignore virtual */
  1406. break;
  1407. case NL80211_IFTYPE_P2P_DEVICE:
  1408. changed = BSS_CHANGED_IDLE;
  1409. break;
  1410. case NL80211_IFTYPE_UNSPECIFIED:
  1411. case NUM_NL80211_IFTYPES:
  1412. case NL80211_IFTYPE_P2P_CLIENT:
  1413. case NL80211_IFTYPE_P2P_GO:
  1414. WARN_ON(1);
  1415. break;
  1416. }
  1417. }
  1418. ieee80211_recalc_ps(local, -1);
  1419. /*
  1420. * The sta might be in psm against the ap (e.g. because
  1421. * this was the state before a hw restart), so we
  1422. * explicitly send a null packet in order to make sure
  1423. * it'll sync against the ap (and get out of psm).
  1424. */
  1425. if (!(local->hw.conf.flags & IEEE80211_CONF_PS)) {
  1426. list_for_each_entry(sdata, &local->interfaces, list) {
  1427. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  1428. continue;
  1429. if (!sdata->u.mgd.associated)
  1430. continue;
  1431. ieee80211_send_nullfunc(local, sdata, 0);
  1432. }
  1433. }
  1434. /* APs are now beaconing, add back stations */
  1435. mutex_lock(&local->sta_mtx);
  1436. list_for_each_entry(sta, &local->sta_list, list) {
  1437. enum ieee80211_sta_state state;
  1438. if (!sta->uploaded)
  1439. continue;
  1440. if (sta->sdata->vif.type != NL80211_IFTYPE_AP)
  1441. continue;
  1442. for (state = IEEE80211_STA_NOTEXIST;
  1443. state < sta->sta_state; state++)
  1444. WARN_ON(drv_sta_state(local, sta->sdata, sta, state,
  1445. state + 1));
  1446. }
  1447. mutex_unlock(&local->sta_mtx);
  1448. /* add back keys */
  1449. list_for_each_entry(sdata, &local->interfaces, list)
  1450. if (ieee80211_sdata_running(sdata))
  1451. ieee80211_enable_keys(sdata);
  1452. wake_up:
  1453. local->in_reconfig = false;
  1454. barrier();
  1455. if (local->monitors == local->open_count && local->monitors > 0)
  1456. ieee80211_add_virtual_monitor(local);
  1457. /*
  1458. * Clear the WLAN_STA_BLOCK_BA flag so new aggregation
  1459. * sessions can be established after a resume.
  1460. *
  1461. * Also tear down aggregation sessions since reconfiguring
  1462. * them in a hardware restart scenario is not easily done
  1463. * right now, and the hardware will have lost information
  1464. * about the sessions, but we and the AP still think they
  1465. * are active. This is really a workaround though.
  1466. */
  1467. if (hw->flags & IEEE80211_HW_AMPDU_AGGREGATION) {
  1468. mutex_lock(&local->sta_mtx);
  1469. list_for_each_entry(sta, &local->sta_list, list) {
  1470. ieee80211_sta_tear_down_BA_sessions(
  1471. sta, AGG_STOP_LOCAL_REQUEST);
  1472. clear_sta_flag(sta, WLAN_STA_BLOCK_BA);
  1473. }
  1474. mutex_unlock(&local->sta_mtx);
  1475. }
  1476. ieee80211_wake_queues_by_reason(hw, IEEE80211_MAX_QUEUE_MAP,
  1477. IEEE80211_QUEUE_STOP_REASON_SUSPEND);
  1478. /*
  1479. * If this is for hw restart things are still running.
  1480. * We may want to change that later, however.
  1481. */
  1482. if (!local->suspended || reconfig_due_to_wowlan)
  1483. drv_restart_complete(local);
  1484. if (!local->suspended)
  1485. return 0;
  1486. #ifdef CONFIG_PM
  1487. /* first set suspended false, then resuming */
  1488. local->suspended = false;
  1489. mb();
  1490. local->resuming = false;
  1491. list_for_each_entry(sdata, &local->interfaces, list) {
  1492. if (!ieee80211_sdata_running(sdata))
  1493. continue;
  1494. if (sdata->vif.type == NL80211_IFTYPE_STATION)
  1495. ieee80211_sta_restart(sdata);
  1496. }
  1497. mod_timer(&local->sta_cleanup, jiffies + 1);
  1498. #else
  1499. WARN_ON(1);
  1500. #endif
  1501. return 0;
  1502. }
  1503. void ieee80211_resume_disconnect(struct ieee80211_vif *vif)
  1504. {
  1505. struct ieee80211_sub_if_data *sdata;
  1506. struct ieee80211_local *local;
  1507. struct ieee80211_key *key;
  1508. if (WARN_ON(!vif))
  1509. return;
  1510. sdata = vif_to_sdata(vif);
  1511. local = sdata->local;
  1512. if (WARN_ON(!local->resuming))
  1513. return;
  1514. if (WARN_ON(vif->type != NL80211_IFTYPE_STATION))
  1515. return;
  1516. sdata->flags |= IEEE80211_SDATA_DISCONNECT_RESUME;
  1517. mutex_lock(&local->key_mtx);
  1518. list_for_each_entry(key, &sdata->key_list, list)
  1519. key->flags |= KEY_FLAG_TAINTED;
  1520. mutex_unlock(&local->key_mtx);
  1521. }
  1522. EXPORT_SYMBOL_GPL(ieee80211_resume_disconnect);
  1523. void ieee80211_recalc_smps(struct ieee80211_sub_if_data *sdata)
  1524. {
  1525. struct ieee80211_local *local = sdata->local;
  1526. struct ieee80211_chanctx_conf *chanctx_conf;
  1527. struct ieee80211_chanctx *chanctx;
  1528. mutex_lock(&local->chanctx_mtx);
  1529. chanctx_conf = rcu_dereference_protected(sdata->vif.chanctx_conf,
  1530. lockdep_is_held(&local->chanctx_mtx));
  1531. if (WARN_ON_ONCE(!chanctx_conf))
  1532. goto unlock;
  1533. chanctx = container_of(chanctx_conf, struct ieee80211_chanctx, conf);
  1534. ieee80211_recalc_smps_chanctx(local, chanctx);
  1535. unlock:
  1536. mutex_unlock(&local->chanctx_mtx);
  1537. }
  1538. static bool ieee80211_id_in_list(const u8 *ids, int n_ids, u8 id)
  1539. {
  1540. int i;
  1541. for (i = 0; i < n_ids; i++)
  1542. if (ids[i] == id)
  1543. return true;
  1544. return false;
  1545. }
  1546. /**
  1547. * ieee80211_ie_split - split an IE buffer according to ordering
  1548. *
  1549. * @ies: the IE buffer
  1550. * @ielen: the length of the IE buffer
  1551. * @ids: an array with element IDs that are allowed before
  1552. * the split
  1553. * @n_ids: the size of the element ID array
  1554. * @offset: offset where to start splitting in the buffer
  1555. *
  1556. * This function splits an IE buffer by updating the @offset
  1557. * variable to point to the location where the buffer should be
  1558. * split.
  1559. *
  1560. * It assumes that the given IE buffer is well-formed, this
  1561. * has to be guaranteed by the caller!
  1562. *
  1563. * It also assumes that the IEs in the buffer are ordered
  1564. * correctly, if not the result of using this function will not
  1565. * be ordered correctly either, i.e. it does no reordering.
  1566. *
  1567. * The function returns the offset where the next part of the
  1568. * buffer starts, which may be @ielen if the entire (remainder)
  1569. * of the buffer should be used.
  1570. */
  1571. size_t ieee80211_ie_split(const u8 *ies, size_t ielen,
  1572. const u8 *ids, int n_ids, size_t offset)
  1573. {
  1574. size_t pos = offset;
  1575. while (pos < ielen && ieee80211_id_in_list(ids, n_ids, ies[pos]))
  1576. pos += 2 + ies[pos + 1];
  1577. return pos;
  1578. }
  1579. size_t ieee80211_ie_split_vendor(const u8 *ies, size_t ielen, size_t offset)
  1580. {
  1581. size_t pos = offset;
  1582. while (pos < ielen && ies[pos] != WLAN_EID_VENDOR_SPECIFIC)
  1583. pos += 2 + ies[pos + 1];
  1584. return pos;
  1585. }
  1586. static void _ieee80211_enable_rssi_reports(struct ieee80211_sub_if_data *sdata,
  1587. int rssi_min_thold,
  1588. int rssi_max_thold)
  1589. {
  1590. trace_api_enable_rssi_reports(sdata, rssi_min_thold, rssi_max_thold);
  1591. if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
  1592. return;
  1593. /*
  1594. * Scale up threshold values before storing it, as the RSSI averaging
  1595. * algorithm uses a scaled up value as well. Change this scaling
  1596. * factor if the RSSI averaging algorithm changes.
  1597. */
  1598. sdata->u.mgd.rssi_min_thold = rssi_min_thold*16;
  1599. sdata->u.mgd.rssi_max_thold = rssi_max_thold*16;
  1600. }
  1601. void ieee80211_enable_rssi_reports(struct ieee80211_vif *vif,
  1602. int rssi_min_thold,
  1603. int rssi_max_thold)
  1604. {
  1605. struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
  1606. WARN_ON(rssi_min_thold == rssi_max_thold ||
  1607. rssi_min_thold > rssi_max_thold);
  1608. _ieee80211_enable_rssi_reports(sdata, rssi_min_thold,
  1609. rssi_max_thold);
  1610. }
  1611. EXPORT_SYMBOL(ieee80211_enable_rssi_reports);
  1612. void ieee80211_disable_rssi_reports(struct ieee80211_vif *vif)
  1613. {
  1614. struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
  1615. _ieee80211_enable_rssi_reports(sdata, 0, 0);
  1616. }
  1617. EXPORT_SYMBOL(ieee80211_disable_rssi_reports);
  1618. u8 *ieee80211_ie_build_ht_cap(u8 *pos, struct ieee80211_sta_ht_cap *ht_cap,
  1619. u16 cap)
  1620. {
  1621. __le16 tmp;
  1622. *pos++ = WLAN_EID_HT_CAPABILITY;
  1623. *pos++ = sizeof(struct ieee80211_ht_cap);
  1624. memset(pos, 0, sizeof(struct ieee80211_ht_cap));
  1625. /* capability flags */
  1626. tmp = cpu_to_le16(cap);
  1627. memcpy(pos, &tmp, sizeof(u16));
  1628. pos += sizeof(u16);
  1629. /* AMPDU parameters */
  1630. *pos++ = ht_cap->ampdu_factor |
  1631. (ht_cap->ampdu_density <<
  1632. IEEE80211_HT_AMPDU_PARM_DENSITY_SHIFT);
  1633. /* MCS set */
  1634. memcpy(pos, &ht_cap->mcs, sizeof(ht_cap->mcs));
  1635. pos += sizeof(ht_cap->mcs);
  1636. /* extended capabilities */
  1637. pos += sizeof(__le16);
  1638. /* BF capabilities */
  1639. pos += sizeof(__le32);
  1640. /* antenna selection */
  1641. pos += sizeof(u8);
  1642. return pos;
  1643. }
  1644. u8 *ieee80211_ie_build_vht_cap(u8 *pos, struct ieee80211_sta_vht_cap *vht_cap,
  1645. u32 cap)
  1646. {
  1647. __le32 tmp;
  1648. *pos++ = WLAN_EID_VHT_CAPABILITY;
  1649. *pos++ = sizeof(struct ieee80211_vht_cap);
  1650. memset(pos, 0, sizeof(struct ieee80211_vht_cap));
  1651. /* capability flags */
  1652. tmp = cpu_to_le32(cap);
  1653. memcpy(pos, &tmp, sizeof(u32));
  1654. pos += sizeof(u32);
  1655. /* VHT MCS set */
  1656. memcpy(pos, &vht_cap->vht_mcs, sizeof(vht_cap->vht_mcs));
  1657. pos += sizeof(vht_cap->vht_mcs);
  1658. return pos;
  1659. }
  1660. u8 *ieee80211_ie_build_ht_oper(u8 *pos, struct ieee80211_sta_ht_cap *ht_cap,
  1661. const struct cfg80211_chan_def *chandef,
  1662. u16 prot_mode)
  1663. {
  1664. struct ieee80211_ht_operation *ht_oper;
  1665. /* Build HT Information */
  1666. *pos++ = WLAN_EID_HT_OPERATION;
  1667. *pos++ = sizeof(struct ieee80211_ht_operation);
  1668. ht_oper = (struct ieee80211_ht_operation *)pos;
  1669. ht_oper->primary_chan = ieee80211_frequency_to_channel(
  1670. chandef->chan->center_freq);
  1671. switch (chandef->width) {
  1672. case NL80211_CHAN_WIDTH_160:
  1673. case NL80211_CHAN_WIDTH_80P80:
  1674. case NL80211_CHAN_WIDTH_80:
  1675. case NL80211_CHAN_WIDTH_40:
  1676. if (chandef->center_freq1 > chandef->chan->center_freq)
  1677. ht_oper->ht_param = IEEE80211_HT_PARAM_CHA_SEC_ABOVE;
  1678. else
  1679. ht_oper->ht_param = IEEE80211_HT_PARAM_CHA_SEC_BELOW;
  1680. break;
  1681. default:
  1682. ht_oper->ht_param = IEEE80211_HT_PARAM_CHA_SEC_NONE;
  1683. break;
  1684. }
  1685. if (ht_cap->cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40 &&
  1686. chandef->width != NL80211_CHAN_WIDTH_20_NOHT &&
  1687. chandef->width != NL80211_CHAN_WIDTH_20)
  1688. ht_oper->ht_param |= IEEE80211_HT_PARAM_CHAN_WIDTH_ANY;
  1689. ht_oper->operation_mode = cpu_to_le16(prot_mode);
  1690. ht_oper->stbc_param = 0x0000;
  1691. /* It seems that Basic MCS set and Supported MCS set
  1692. are identical for the first 10 bytes */
  1693. memset(&ht_oper->basic_set, 0, 16);
  1694. memcpy(&ht_oper->basic_set, &ht_cap->mcs, 10);
  1695. return pos + sizeof(struct ieee80211_ht_operation);
  1696. }
  1697. void ieee80211_ht_oper_to_chandef(struct ieee80211_channel *control_chan,
  1698. const struct ieee80211_ht_operation *ht_oper,
  1699. struct cfg80211_chan_def *chandef)
  1700. {
  1701. enum nl80211_channel_type channel_type;
  1702. if (!ht_oper) {
  1703. cfg80211_chandef_create(chandef, control_chan,
  1704. NL80211_CHAN_NO_HT);
  1705. return;
  1706. }
  1707. switch (ht_oper->ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET) {
  1708. case IEEE80211_HT_PARAM_CHA_SEC_NONE:
  1709. channel_type = NL80211_CHAN_HT20;
  1710. break;
  1711. case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
  1712. channel_type = NL80211_CHAN_HT40PLUS;
  1713. break;
  1714. case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
  1715. channel_type = NL80211_CHAN_HT40MINUS;
  1716. break;
  1717. default:
  1718. channel_type = NL80211_CHAN_NO_HT;
  1719. }
  1720. cfg80211_chandef_create(chandef, control_chan, channel_type);
  1721. }
  1722. int ieee80211_parse_bitrates(struct cfg80211_chan_def *chandef,
  1723. const struct ieee80211_supported_band *sband,
  1724. const u8 *srates, int srates_len, u32 *rates)
  1725. {
  1726. u32 rate_flags = ieee80211_chandef_rate_flags(chandef);
  1727. int shift = ieee80211_chandef_get_shift(chandef);
  1728. struct ieee80211_rate *br;
  1729. int brate, rate, i, j, count = 0;
  1730. *rates = 0;
  1731. for (i = 0; i < srates_len; i++) {
  1732. rate = srates[i] & 0x7f;
  1733. for (j = 0; j < sband->n_bitrates; j++) {
  1734. br = &sband->bitrates[j];
  1735. if ((rate_flags & br->flags) != rate_flags)
  1736. continue;
  1737. brate = DIV_ROUND_UP(br->bitrate, (1 << shift) * 5);
  1738. if (brate == rate) {
  1739. *rates |= BIT(j);
  1740. count++;
  1741. break;
  1742. }
  1743. }
  1744. }
  1745. return count;
  1746. }
  1747. int ieee80211_add_srates_ie(struct ieee80211_sub_if_data *sdata,
  1748. struct sk_buff *skb, bool need_basic,
  1749. enum ieee80211_band band)
  1750. {
  1751. struct ieee80211_local *local = sdata->local;
  1752. struct ieee80211_supported_band *sband;
  1753. int rate, shift;
  1754. u8 i, rates, *pos;
  1755. u32 basic_rates = sdata->vif.bss_conf.basic_rates;
  1756. u32 rate_flags;
  1757. shift = ieee80211_vif_get_shift(&sdata->vif);
  1758. rate_flags = ieee80211_chandef_rate_flags(&sdata->vif.bss_conf.chandef);
  1759. sband = local->hw.wiphy->bands[band];
  1760. rates = 0;
  1761. for (i = 0; i < sband->n_bitrates; i++) {
  1762. if ((rate_flags & sband->bitrates[i].flags) != rate_flags)
  1763. continue;
  1764. rates++;
  1765. }
  1766. if (rates > 8)
  1767. rates = 8;
  1768. if (skb_tailroom(skb) < rates + 2)
  1769. return -ENOMEM;
  1770. pos = skb_put(skb, rates + 2);
  1771. *pos++ = WLAN_EID_SUPP_RATES;
  1772. *pos++ = rates;
  1773. for (i = 0; i < rates; i++) {
  1774. u8 basic = 0;
  1775. if ((rate_flags & sband->bitrates[i].flags) != rate_flags)
  1776. continue;
  1777. if (need_basic && basic_rates & BIT(i))
  1778. basic = 0x80;
  1779. rate = sband->bitrates[i].bitrate;
  1780. rate = DIV_ROUND_UP(sband->bitrates[i].bitrate,
  1781. 5 * (1 << shift));
  1782. *pos++ = basic | (u8) rate;
  1783. }
  1784. return 0;
  1785. }
  1786. int ieee80211_add_ext_srates_ie(struct ieee80211_sub_if_data *sdata,
  1787. struct sk_buff *skb, bool need_basic,
  1788. enum ieee80211_band band)
  1789. {
  1790. struct ieee80211_local *local = sdata->local;
  1791. struct ieee80211_supported_band *sband;
  1792. int rate, shift;
  1793. u8 i, exrates, *pos;
  1794. u32 basic_rates = sdata->vif.bss_conf.basic_rates;
  1795. u32 rate_flags;
  1796. rate_flags = ieee80211_chandef_rate_flags(&sdata->vif.bss_conf.chandef);
  1797. shift = ieee80211_vif_get_shift(&sdata->vif);
  1798. sband = local->hw.wiphy->bands[band];
  1799. exrates = 0;
  1800. for (i = 0; i < sband->n_bitrates; i++) {
  1801. if ((rate_flags & sband->bitrates[i].flags) != rate_flags)
  1802. continue;
  1803. exrates++;
  1804. }
  1805. if (exrates > 8)
  1806. exrates -= 8;
  1807. else
  1808. exrates = 0;
  1809. if (skb_tailroom(skb) < exrates + 2)
  1810. return -ENOMEM;
  1811. if (exrates) {
  1812. pos = skb_put(skb, exrates + 2);
  1813. *pos++ = WLAN_EID_EXT_SUPP_RATES;
  1814. *pos++ = exrates;
  1815. for (i = 8; i < sband->n_bitrates; i++) {
  1816. u8 basic = 0;
  1817. if ((rate_flags & sband->bitrates[i].flags)
  1818. != rate_flags)
  1819. continue;
  1820. if (need_basic && basic_rates & BIT(i))
  1821. basic = 0x80;
  1822. rate = DIV_ROUND_UP(sband->bitrates[i].bitrate,
  1823. 5 * (1 << shift));
  1824. *pos++ = basic | (u8) rate;
  1825. }
  1826. }
  1827. return 0;
  1828. }
  1829. int ieee80211_ave_rssi(struct ieee80211_vif *vif)
  1830. {
  1831. struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
  1832. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  1833. if (WARN_ON_ONCE(sdata->vif.type != NL80211_IFTYPE_STATION)) {
  1834. /* non-managed type inferfaces */
  1835. return 0;
  1836. }
  1837. return ifmgd->ave_beacon_signal / 16;
  1838. }
  1839. EXPORT_SYMBOL_GPL(ieee80211_ave_rssi);
  1840. u8 ieee80211_mcs_to_chains(const struct ieee80211_mcs_info *mcs)
  1841. {
  1842. if (!mcs)
  1843. return 1;
  1844. /* TODO: consider rx_highest */
  1845. if (mcs->rx_mask[3])
  1846. return 4;
  1847. if (mcs->rx_mask[2])
  1848. return 3;
  1849. if (mcs->rx_mask[1])
  1850. return 2;
  1851. return 1;
  1852. }
  1853. /**
  1854. * ieee80211_calculate_rx_timestamp - calculate timestamp in frame
  1855. * @local: mac80211 hw info struct
  1856. * @status: RX status
  1857. * @mpdu_len: total MPDU length (including FCS)
  1858. * @mpdu_offset: offset into MPDU to calculate timestamp at
  1859. *
  1860. * This function calculates the RX timestamp at the given MPDU offset, taking
  1861. * into account what the RX timestamp was. An offset of 0 will just normalize
  1862. * the timestamp to TSF at beginning of MPDU reception.
  1863. */
  1864. u64 ieee80211_calculate_rx_timestamp(struct ieee80211_local *local,
  1865. struct ieee80211_rx_status *status,
  1866. unsigned int mpdu_len,
  1867. unsigned int mpdu_offset)
  1868. {
  1869. u64 ts = status->mactime;
  1870. struct rate_info ri;
  1871. u16 rate;
  1872. if (WARN_ON(!ieee80211_have_rx_timestamp(status)))
  1873. return 0;
  1874. memset(&ri, 0, sizeof(ri));
  1875. /* Fill cfg80211 rate info */
  1876. if (status->flag & RX_FLAG_HT) {
  1877. ri.mcs = status->rate_idx;
  1878. ri.flags |= RATE_INFO_FLAGS_MCS;
  1879. if (status->flag & RX_FLAG_40MHZ)
  1880. ri.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
  1881. if (status->flag & RX_FLAG_SHORT_GI)
  1882. ri.flags |= RATE_INFO_FLAGS_SHORT_GI;
  1883. } else if (status->flag & RX_FLAG_VHT) {
  1884. ri.flags |= RATE_INFO_FLAGS_VHT_MCS;
  1885. ri.mcs = status->rate_idx;
  1886. ri.nss = status->vht_nss;
  1887. if (status->flag & RX_FLAG_40MHZ)
  1888. ri.flags |= RATE_INFO_FLAGS_40_MHZ_WIDTH;
  1889. if (status->flag & RX_FLAG_80MHZ)
  1890. ri.flags |= RATE_INFO_FLAGS_80_MHZ_WIDTH;
  1891. if (status->flag & RX_FLAG_80P80MHZ)
  1892. ri.flags |= RATE_INFO_FLAGS_80P80_MHZ_WIDTH;
  1893. if (status->flag & RX_FLAG_160MHZ)
  1894. ri.flags |= RATE_INFO_FLAGS_160_MHZ_WIDTH;
  1895. if (status->flag & RX_FLAG_SHORT_GI)
  1896. ri.flags |= RATE_INFO_FLAGS_SHORT_GI;
  1897. } else {
  1898. struct ieee80211_supported_band *sband;
  1899. int shift = 0;
  1900. int bitrate;
  1901. if (status->flag & RX_FLAG_10MHZ)
  1902. shift = 1;
  1903. if (status->flag & RX_FLAG_5MHZ)
  1904. shift = 2;
  1905. sband = local->hw.wiphy->bands[status->band];
  1906. bitrate = sband->bitrates[status->rate_idx].bitrate;
  1907. ri.legacy = DIV_ROUND_UP(bitrate, (1 << shift));
  1908. }
  1909. rate = cfg80211_calculate_bitrate(&ri);
  1910. if (WARN_ONCE(!rate,
  1911. "Invalid bitrate: flags=0x%x, idx=%d, vht_nss=%d\n",
  1912. status->flag, status->rate_idx, status->vht_nss))
  1913. return 0;
  1914. /* rewind from end of MPDU */
  1915. if (status->flag & RX_FLAG_MACTIME_END)
  1916. ts -= mpdu_len * 8 * 10 / rate;
  1917. ts += mpdu_offset * 8 * 10 / rate;
  1918. return ts;
  1919. }
  1920. void ieee80211_dfs_cac_cancel(struct ieee80211_local *local)
  1921. {
  1922. struct ieee80211_sub_if_data *sdata;
  1923. mutex_lock(&local->iflist_mtx);
  1924. list_for_each_entry(sdata, &local->interfaces, list) {
  1925. cancel_delayed_work_sync(&sdata->dfs_cac_timer_work);
  1926. if (sdata->wdev.cac_started) {
  1927. ieee80211_vif_release_channel(sdata);
  1928. cfg80211_cac_event(sdata->dev,
  1929. NL80211_RADAR_CAC_ABORTED,
  1930. GFP_KERNEL);
  1931. }
  1932. }
  1933. mutex_unlock(&local->iflist_mtx);
  1934. }
  1935. void ieee80211_dfs_radar_detected_work(struct work_struct *work)
  1936. {
  1937. struct ieee80211_local *local =
  1938. container_of(work, struct ieee80211_local, radar_detected_work);
  1939. struct cfg80211_chan_def chandef;
  1940. ieee80211_dfs_cac_cancel(local);
  1941. if (local->use_chanctx)
  1942. /* currently not handled */
  1943. WARN_ON(1);
  1944. else {
  1945. chandef = local->hw.conf.chandef;
  1946. cfg80211_radar_event(local->hw.wiphy, &chandef, GFP_KERNEL);
  1947. }
  1948. }
  1949. void ieee80211_radar_detected(struct ieee80211_hw *hw)
  1950. {
  1951. struct ieee80211_local *local = hw_to_local(hw);
  1952. trace_api_radar_detected(local);
  1953. ieee80211_queue_work(hw, &local->radar_detected_work);
  1954. }
  1955. EXPORT_SYMBOL(ieee80211_radar_detected);
  1956. u32 ieee80211_chandef_downgrade(struct cfg80211_chan_def *c)
  1957. {
  1958. u32 ret;
  1959. int tmp;
  1960. switch (c->width) {
  1961. case NL80211_CHAN_WIDTH_20:
  1962. c->width = NL80211_CHAN_WIDTH_20_NOHT;
  1963. ret = IEEE80211_STA_DISABLE_HT | IEEE80211_STA_DISABLE_VHT;
  1964. break;
  1965. case NL80211_CHAN_WIDTH_40:
  1966. c->width = NL80211_CHAN_WIDTH_20;
  1967. c->center_freq1 = c->chan->center_freq;
  1968. ret = IEEE80211_STA_DISABLE_40MHZ |
  1969. IEEE80211_STA_DISABLE_VHT;
  1970. break;
  1971. case NL80211_CHAN_WIDTH_80:
  1972. tmp = (30 + c->chan->center_freq - c->center_freq1)/20;
  1973. /* n_P40 */
  1974. tmp /= 2;
  1975. /* freq_P40 */
  1976. c->center_freq1 = c->center_freq1 - 20 + 40 * tmp;
  1977. c->width = NL80211_CHAN_WIDTH_40;
  1978. ret = IEEE80211_STA_DISABLE_VHT;
  1979. break;
  1980. case NL80211_CHAN_WIDTH_80P80:
  1981. c->center_freq2 = 0;
  1982. c->width = NL80211_CHAN_WIDTH_80;
  1983. ret = IEEE80211_STA_DISABLE_80P80MHZ |
  1984. IEEE80211_STA_DISABLE_160MHZ;
  1985. break;
  1986. case NL80211_CHAN_WIDTH_160:
  1987. /* n_P20 */
  1988. tmp = (70 + c->chan->center_freq - c->center_freq1)/20;
  1989. /* n_P80 */
  1990. tmp /= 4;
  1991. c->center_freq1 = c->center_freq1 - 40 + 80 * tmp;
  1992. c->width = NL80211_CHAN_WIDTH_80;
  1993. ret = IEEE80211_STA_DISABLE_80P80MHZ |
  1994. IEEE80211_STA_DISABLE_160MHZ;
  1995. break;
  1996. default:
  1997. case NL80211_CHAN_WIDTH_20_NOHT:
  1998. WARN_ON_ONCE(1);
  1999. c->width = NL80211_CHAN_WIDTH_20_NOHT;
  2000. ret = IEEE80211_STA_DISABLE_HT | IEEE80211_STA_DISABLE_VHT;
  2001. break;
  2002. case NL80211_CHAN_WIDTH_5:
  2003. case NL80211_CHAN_WIDTH_10:
  2004. WARN_ON_ONCE(1);
  2005. /* keep c->width */
  2006. ret = IEEE80211_STA_DISABLE_HT | IEEE80211_STA_DISABLE_VHT;
  2007. break;
  2008. }
  2009. WARN_ON_ONCE(!cfg80211_chandef_valid(c));
  2010. return ret;
  2011. }