util.c 89 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459
  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. * Copyright 2013-2014 Intel Mobile Communications GmbH
  7. * Copyright (C) 2015-2016 Intel Deutschland GmbH
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2 as
  11. * published by the Free Software Foundation.
  12. *
  13. * utilities for mac80211
  14. */
  15. #include <net/mac80211.h>
  16. #include <linux/netdevice.h>
  17. #include <linux/export.h>
  18. #include <linux/types.h>
  19. #include <linux/slab.h>
  20. #include <linux/skbuff.h>
  21. #include <linux/etherdevice.h>
  22. #include <linux/if_arp.h>
  23. #include <linux/bitmap.h>
  24. #include <linux/crc32.h>
  25. #include <net/net_namespace.h>
  26. #include <net/cfg80211.h>
  27. #include <net/rtnetlink.h>
  28. #include "ieee80211_i.h"
  29. #include "driver-ops.h"
  30. #include "rate.h"
  31. #include "mesh.h"
  32. #include "wme.h"
  33. #include "led.h"
  34. #include "wep.h"
  35. /* privid for wiphys to determine whether they belong to us or not */
  36. const void *const mac80211_wiphy_privid = &mac80211_wiphy_privid;
  37. struct ieee80211_hw *wiphy_to_ieee80211_hw(struct wiphy *wiphy)
  38. {
  39. struct ieee80211_local *local;
  40. BUG_ON(!wiphy);
  41. local = wiphy_priv(wiphy);
  42. return &local->hw;
  43. }
  44. EXPORT_SYMBOL(wiphy_to_ieee80211_hw);
  45. void ieee80211_tx_set_protected(struct ieee80211_tx_data *tx)
  46. {
  47. struct sk_buff *skb;
  48. struct ieee80211_hdr *hdr;
  49. skb_queue_walk(&tx->skbs, skb) {
  50. hdr = (struct ieee80211_hdr *) skb->data;
  51. hdr->frame_control |= cpu_to_le16(IEEE80211_FCTL_PROTECTED);
  52. }
  53. }
  54. int ieee80211_frame_duration(enum nl80211_band band, size_t len,
  55. int rate, int erp, int short_preamble,
  56. int shift)
  57. {
  58. int dur;
  59. /* calculate duration (in microseconds, rounded up to next higher
  60. * integer if it includes a fractional microsecond) to send frame of
  61. * len bytes (does not include FCS) at the given rate. Duration will
  62. * also include SIFS.
  63. *
  64. * rate is in 100 kbps, so divident is multiplied by 10 in the
  65. * DIV_ROUND_UP() operations.
  66. *
  67. * shift may be 2 for 5 MHz channels or 1 for 10 MHz channels, and
  68. * is assumed to be 0 otherwise.
  69. */
  70. if (band == NL80211_BAND_5GHZ || erp) {
  71. /*
  72. * OFDM:
  73. *
  74. * N_DBPS = DATARATE x 4
  75. * N_SYM = Ceiling((16+8xLENGTH+6) / N_DBPS)
  76. * (16 = SIGNAL time, 6 = tail bits)
  77. * TXTIME = T_PREAMBLE + T_SIGNAL + T_SYM x N_SYM + Signal Ext
  78. *
  79. * T_SYM = 4 usec
  80. * 802.11a - 18.5.2: aSIFSTime = 16 usec
  81. * 802.11g - 19.8.4: aSIFSTime = 10 usec +
  82. * signal ext = 6 usec
  83. */
  84. dur = 16; /* SIFS + signal ext */
  85. dur += 16; /* IEEE 802.11-2012 18.3.2.4: T_PREAMBLE = 16 usec */
  86. dur += 4; /* IEEE 802.11-2012 18.3.2.4: T_SIGNAL = 4 usec */
  87. /* IEEE 802.11-2012 18.3.2.4: all values above are:
  88. * * times 4 for 5 MHz
  89. * * times 2 for 10 MHz
  90. */
  91. dur *= 1 << shift;
  92. /* rates should already consider the channel bandwidth,
  93. * don't apply divisor again.
  94. */
  95. dur += 4 * DIV_ROUND_UP((16 + 8 * (len + 4) + 6) * 10,
  96. 4 * rate); /* T_SYM x N_SYM */
  97. } else {
  98. /*
  99. * 802.11b or 802.11g with 802.11b compatibility:
  100. * 18.3.4: TXTIME = PreambleLength + PLCPHeaderTime +
  101. * Ceiling(((LENGTH+PBCC)x8)/DATARATE). PBCC=0.
  102. *
  103. * 802.11 (DS): 15.3.3, 802.11b: 18.3.4
  104. * aSIFSTime = 10 usec
  105. * aPreambleLength = 144 usec or 72 usec with short preamble
  106. * aPLCPHeaderLength = 48 usec or 24 usec with short preamble
  107. */
  108. dur = 10; /* aSIFSTime = 10 usec */
  109. dur += short_preamble ? (72 + 24) : (144 + 48);
  110. dur += DIV_ROUND_UP(8 * (len + 4) * 10, rate);
  111. }
  112. return dur;
  113. }
  114. /* Exported duration function for driver use */
  115. __le16 ieee80211_generic_frame_duration(struct ieee80211_hw *hw,
  116. struct ieee80211_vif *vif,
  117. enum nl80211_band band,
  118. size_t frame_len,
  119. struct ieee80211_rate *rate)
  120. {
  121. struct ieee80211_sub_if_data *sdata;
  122. u16 dur;
  123. int erp, shift = 0;
  124. bool short_preamble = false;
  125. erp = 0;
  126. if (vif) {
  127. sdata = vif_to_sdata(vif);
  128. short_preamble = sdata->vif.bss_conf.use_short_preamble;
  129. if (sdata->flags & IEEE80211_SDATA_OPERATING_GMODE)
  130. erp = rate->flags & IEEE80211_RATE_ERP_G;
  131. shift = ieee80211_vif_get_shift(vif);
  132. }
  133. dur = ieee80211_frame_duration(band, frame_len, rate->bitrate, erp,
  134. short_preamble, shift);
  135. return cpu_to_le16(dur);
  136. }
  137. EXPORT_SYMBOL(ieee80211_generic_frame_duration);
  138. __le16 ieee80211_rts_duration(struct ieee80211_hw *hw,
  139. struct ieee80211_vif *vif, size_t frame_len,
  140. const struct ieee80211_tx_info *frame_txctl)
  141. {
  142. struct ieee80211_local *local = hw_to_local(hw);
  143. struct ieee80211_rate *rate;
  144. struct ieee80211_sub_if_data *sdata;
  145. bool short_preamble;
  146. int erp, shift = 0, bitrate;
  147. u16 dur;
  148. struct ieee80211_supported_band *sband;
  149. sband = local->hw.wiphy->bands[frame_txctl->band];
  150. short_preamble = false;
  151. rate = &sband->bitrates[frame_txctl->control.rts_cts_rate_idx];
  152. erp = 0;
  153. if (vif) {
  154. sdata = vif_to_sdata(vif);
  155. short_preamble = sdata->vif.bss_conf.use_short_preamble;
  156. if (sdata->flags & IEEE80211_SDATA_OPERATING_GMODE)
  157. erp = rate->flags & IEEE80211_RATE_ERP_G;
  158. shift = ieee80211_vif_get_shift(vif);
  159. }
  160. bitrate = DIV_ROUND_UP(rate->bitrate, 1 << shift);
  161. /* CTS duration */
  162. dur = ieee80211_frame_duration(sband->band, 10, bitrate,
  163. erp, short_preamble, shift);
  164. /* Data frame duration */
  165. dur += ieee80211_frame_duration(sband->band, frame_len, bitrate,
  166. erp, short_preamble, shift);
  167. /* ACK duration */
  168. dur += ieee80211_frame_duration(sband->band, 10, bitrate,
  169. erp, short_preamble, shift);
  170. return cpu_to_le16(dur);
  171. }
  172. EXPORT_SYMBOL(ieee80211_rts_duration);
  173. __le16 ieee80211_ctstoself_duration(struct ieee80211_hw *hw,
  174. struct ieee80211_vif *vif,
  175. size_t frame_len,
  176. const struct ieee80211_tx_info *frame_txctl)
  177. {
  178. struct ieee80211_local *local = hw_to_local(hw);
  179. struct ieee80211_rate *rate;
  180. struct ieee80211_sub_if_data *sdata;
  181. bool short_preamble;
  182. int erp, shift = 0, bitrate;
  183. u16 dur;
  184. struct ieee80211_supported_band *sband;
  185. sband = local->hw.wiphy->bands[frame_txctl->band];
  186. short_preamble = false;
  187. rate = &sband->bitrates[frame_txctl->control.rts_cts_rate_idx];
  188. erp = 0;
  189. if (vif) {
  190. sdata = vif_to_sdata(vif);
  191. short_preamble = sdata->vif.bss_conf.use_short_preamble;
  192. if (sdata->flags & IEEE80211_SDATA_OPERATING_GMODE)
  193. erp = rate->flags & IEEE80211_RATE_ERP_G;
  194. shift = ieee80211_vif_get_shift(vif);
  195. }
  196. bitrate = DIV_ROUND_UP(rate->bitrate, 1 << shift);
  197. /* Data frame duration */
  198. dur = ieee80211_frame_duration(sband->band, frame_len, bitrate,
  199. erp, short_preamble, shift);
  200. if (!(frame_txctl->flags & IEEE80211_TX_CTL_NO_ACK)) {
  201. /* ACK duration */
  202. dur += ieee80211_frame_duration(sband->band, 10, bitrate,
  203. erp, short_preamble, shift);
  204. }
  205. return cpu_to_le16(dur);
  206. }
  207. EXPORT_SYMBOL(ieee80211_ctstoself_duration);
  208. void ieee80211_propagate_queue_wake(struct ieee80211_local *local, int queue)
  209. {
  210. struct ieee80211_sub_if_data *sdata;
  211. int n_acs = IEEE80211_NUM_ACS;
  212. if (local->ops->wake_tx_queue)
  213. return;
  214. if (local->hw.queues < IEEE80211_NUM_ACS)
  215. n_acs = 1;
  216. list_for_each_entry_rcu(sdata, &local->interfaces, list) {
  217. int ac;
  218. if (!sdata->dev)
  219. continue;
  220. if (sdata->vif.cab_queue != IEEE80211_INVAL_HW_QUEUE &&
  221. local->queue_stop_reasons[sdata->vif.cab_queue] != 0)
  222. continue;
  223. for (ac = 0; ac < n_acs; ac++) {
  224. int ac_queue = sdata->vif.hw_queue[ac];
  225. if (ac_queue == queue ||
  226. (sdata->vif.cab_queue == queue &&
  227. local->queue_stop_reasons[ac_queue] == 0 &&
  228. skb_queue_empty(&local->pending[ac_queue])))
  229. netif_wake_subqueue(sdata->dev, ac);
  230. }
  231. }
  232. }
  233. static void __ieee80211_wake_queue(struct ieee80211_hw *hw, int queue,
  234. enum queue_stop_reason reason,
  235. bool refcounted)
  236. {
  237. struct ieee80211_local *local = hw_to_local(hw);
  238. trace_wake_queue(local, queue, reason);
  239. if (WARN_ON(queue >= hw->queues))
  240. return;
  241. if (!test_bit(reason, &local->queue_stop_reasons[queue]))
  242. return;
  243. if (!refcounted) {
  244. local->q_stop_reasons[queue][reason] = 0;
  245. } else {
  246. local->q_stop_reasons[queue][reason]--;
  247. if (WARN_ON(local->q_stop_reasons[queue][reason] < 0))
  248. local->q_stop_reasons[queue][reason] = 0;
  249. }
  250. if (local->q_stop_reasons[queue][reason] == 0)
  251. __clear_bit(reason, &local->queue_stop_reasons[queue]);
  252. if (local->queue_stop_reasons[queue] != 0)
  253. /* someone still has this queue stopped */
  254. return;
  255. if (skb_queue_empty(&local->pending[queue])) {
  256. rcu_read_lock();
  257. ieee80211_propagate_queue_wake(local, queue);
  258. rcu_read_unlock();
  259. } else
  260. tasklet_schedule(&local->tx_pending_tasklet);
  261. }
  262. void ieee80211_wake_queue_by_reason(struct ieee80211_hw *hw, int queue,
  263. enum queue_stop_reason reason,
  264. bool refcounted)
  265. {
  266. struct ieee80211_local *local = hw_to_local(hw);
  267. unsigned long flags;
  268. spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
  269. __ieee80211_wake_queue(hw, queue, reason, refcounted);
  270. spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
  271. }
  272. void ieee80211_wake_queue(struct ieee80211_hw *hw, int queue)
  273. {
  274. ieee80211_wake_queue_by_reason(hw, queue,
  275. IEEE80211_QUEUE_STOP_REASON_DRIVER,
  276. false);
  277. }
  278. EXPORT_SYMBOL(ieee80211_wake_queue);
  279. static void __ieee80211_stop_queue(struct ieee80211_hw *hw, int queue,
  280. enum queue_stop_reason reason,
  281. bool refcounted)
  282. {
  283. struct ieee80211_local *local = hw_to_local(hw);
  284. struct ieee80211_sub_if_data *sdata;
  285. int n_acs = IEEE80211_NUM_ACS;
  286. trace_stop_queue(local, queue, reason);
  287. if (WARN_ON(queue >= hw->queues))
  288. return;
  289. if (!refcounted)
  290. local->q_stop_reasons[queue][reason] = 1;
  291. else
  292. local->q_stop_reasons[queue][reason]++;
  293. if (__test_and_set_bit(reason, &local->queue_stop_reasons[queue]))
  294. return;
  295. if (local->ops->wake_tx_queue)
  296. return;
  297. if (local->hw.queues < IEEE80211_NUM_ACS)
  298. n_acs = 1;
  299. rcu_read_lock();
  300. list_for_each_entry_rcu(sdata, &local->interfaces, list) {
  301. int ac;
  302. if (!sdata->dev)
  303. continue;
  304. for (ac = 0; ac < n_acs; ac++) {
  305. if (sdata->vif.hw_queue[ac] == queue ||
  306. sdata->vif.cab_queue == queue)
  307. netif_stop_subqueue(sdata->dev, ac);
  308. }
  309. }
  310. rcu_read_unlock();
  311. }
  312. void ieee80211_stop_queue_by_reason(struct ieee80211_hw *hw, int queue,
  313. enum queue_stop_reason reason,
  314. bool refcounted)
  315. {
  316. struct ieee80211_local *local = hw_to_local(hw);
  317. unsigned long flags;
  318. spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
  319. __ieee80211_stop_queue(hw, queue, reason, refcounted);
  320. spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
  321. }
  322. void ieee80211_stop_queue(struct ieee80211_hw *hw, int queue)
  323. {
  324. ieee80211_stop_queue_by_reason(hw, queue,
  325. IEEE80211_QUEUE_STOP_REASON_DRIVER,
  326. false);
  327. }
  328. EXPORT_SYMBOL(ieee80211_stop_queue);
  329. void ieee80211_add_pending_skb(struct ieee80211_local *local,
  330. struct sk_buff *skb)
  331. {
  332. struct ieee80211_hw *hw = &local->hw;
  333. unsigned long flags;
  334. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  335. int queue = info->hw_queue;
  336. if (WARN_ON(!info->control.vif)) {
  337. ieee80211_free_txskb(&local->hw, skb);
  338. return;
  339. }
  340. spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
  341. __ieee80211_stop_queue(hw, queue, IEEE80211_QUEUE_STOP_REASON_SKB_ADD,
  342. false);
  343. __skb_queue_tail(&local->pending[queue], skb);
  344. __ieee80211_wake_queue(hw, queue, IEEE80211_QUEUE_STOP_REASON_SKB_ADD,
  345. false);
  346. spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
  347. }
  348. void ieee80211_add_pending_skbs(struct ieee80211_local *local,
  349. struct sk_buff_head *skbs)
  350. {
  351. struct ieee80211_hw *hw = &local->hw;
  352. struct sk_buff *skb;
  353. unsigned long flags;
  354. int queue, i;
  355. spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
  356. while ((skb = skb_dequeue(skbs))) {
  357. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  358. if (WARN_ON(!info->control.vif)) {
  359. ieee80211_free_txskb(&local->hw, skb);
  360. continue;
  361. }
  362. queue = info->hw_queue;
  363. __ieee80211_stop_queue(hw, queue,
  364. IEEE80211_QUEUE_STOP_REASON_SKB_ADD,
  365. false);
  366. __skb_queue_tail(&local->pending[queue], skb);
  367. }
  368. for (i = 0; i < hw->queues; i++)
  369. __ieee80211_wake_queue(hw, i,
  370. IEEE80211_QUEUE_STOP_REASON_SKB_ADD,
  371. false);
  372. spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
  373. }
  374. void ieee80211_stop_queues_by_reason(struct ieee80211_hw *hw,
  375. unsigned long queues,
  376. enum queue_stop_reason reason,
  377. bool refcounted)
  378. {
  379. struct ieee80211_local *local = hw_to_local(hw);
  380. unsigned long flags;
  381. int i;
  382. spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
  383. for_each_set_bit(i, &queues, hw->queues)
  384. __ieee80211_stop_queue(hw, i, reason, refcounted);
  385. spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
  386. }
  387. void ieee80211_stop_queues(struct ieee80211_hw *hw)
  388. {
  389. ieee80211_stop_queues_by_reason(hw, IEEE80211_MAX_QUEUE_MAP,
  390. IEEE80211_QUEUE_STOP_REASON_DRIVER,
  391. false);
  392. }
  393. EXPORT_SYMBOL(ieee80211_stop_queues);
  394. int ieee80211_queue_stopped(struct ieee80211_hw *hw, int queue)
  395. {
  396. struct ieee80211_local *local = hw_to_local(hw);
  397. unsigned long flags;
  398. int ret;
  399. if (WARN_ON(queue >= hw->queues))
  400. return true;
  401. spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
  402. ret = test_bit(IEEE80211_QUEUE_STOP_REASON_DRIVER,
  403. &local->queue_stop_reasons[queue]);
  404. spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
  405. return ret;
  406. }
  407. EXPORT_SYMBOL(ieee80211_queue_stopped);
  408. void ieee80211_wake_queues_by_reason(struct ieee80211_hw *hw,
  409. unsigned long queues,
  410. enum queue_stop_reason reason,
  411. bool refcounted)
  412. {
  413. struct ieee80211_local *local = hw_to_local(hw);
  414. unsigned long flags;
  415. int i;
  416. spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
  417. for_each_set_bit(i, &queues, hw->queues)
  418. __ieee80211_wake_queue(hw, i, reason, refcounted);
  419. spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
  420. }
  421. void ieee80211_wake_queues(struct ieee80211_hw *hw)
  422. {
  423. ieee80211_wake_queues_by_reason(hw, IEEE80211_MAX_QUEUE_MAP,
  424. IEEE80211_QUEUE_STOP_REASON_DRIVER,
  425. false);
  426. }
  427. EXPORT_SYMBOL(ieee80211_wake_queues);
  428. static unsigned int
  429. ieee80211_get_vif_queues(struct ieee80211_local *local,
  430. struct ieee80211_sub_if_data *sdata)
  431. {
  432. unsigned int queues;
  433. if (sdata && ieee80211_hw_check(&local->hw, QUEUE_CONTROL)) {
  434. int ac;
  435. queues = 0;
  436. for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
  437. queues |= BIT(sdata->vif.hw_queue[ac]);
  438. if (sdata->vif.cab_queue != IEEE80211_INVAL_HW_QUEUE)
  439. queues |= BIT(sdata->vif.cab_queue);
  440. } else {
  441. /* all queues */
  442. queues = BIT(local->hw.queues) - 1;
  443. }
  444. return queues;
  445. }
  446. void __ieee80211_flush_queues(struct ieee80211_local *local,
  447. struct ieee80211_sub_if_data *sdata,
  448. unsigned int queues, bool drop)
  449. {
  450. if (!local->ops->flush)
  451. return;
  452. /*
  453. * If no queue was set, or if the HW doesn't support
  454. * IEEE80211_HW_QUEUE_CONTROL - flush all queues
  455. */
  456. if (!queues || !ieee80211_hw_check(&local->hw, QUEUE_CONTROL))
  457. queues = ieee80211_get_vif_queues(local, sdata);
  458. ieee80211_stop_queues_by_reason(&local->hw, queues,
  459. IEEE80211_QUEUE_STOP_REASON_FLUSH,
  460. false);
  461. drv_flush(local, sdata, queues, drop);
  462. ieee80211_wake_queues_by_reason(&local->hw, queues,
  463. IEEE80211_QUEUE_STOP_REASON_FLUSH,
  464. false);
  465. }
  466. void ieee80211_flush_queues(struct ieee80211_local *local,
  467. struct ieee80211_sub_if_data *sdata, bool drop)
  468. {
  469. __ieee80211_flush_queues(local, sdata, 0, drop);
  470. }
  471. void ieee80211_stop_vif_queues(struct ieee80211_local *local,
  472. struct ieee80211_sub_if_data *sdata,
  473. enum queue_stop_reason reason)
  474. {
  475. ieee80211_stop_queues_by_reason(&local->hw,
  476. ieee80211_get_vif_queues(local, sdata),
  477. reason, true);
  478. }
  479. void ieee80211_wake_vif_queues(struct ieee80211_local *local,
  480. struct ieee80211_sub_if_data *sdata,
  481. enum queue_stop_reason reason)
  482. {
  483. ieee80211_wake_queues_by_reason(&local->hw,
  484. ieee80211_get_vif_queues(local, sdata),
  485. reason, true);
  486. }
  487. static void __iterate_interfaces(struct ieee80211_local *local,
  488. u32 iter_flags,
  489. void (*iterator)(void *data, u8 *mac,
  490. struct ieee80211_vif *vif),
  491. void *data)
  492. {
  493. struct ieee80211_sub_if_data *sdata;
  494. bool active_only = iter_flags & IEEE80211_IFACE_ITER_ACTIVE;
  495. list_for_each_entry_rcu(sdata, &local->interfaces, list) {
  496. switch (sdata->vif.type) {
  497. case NL80211_IFTYPE_MONITOR:
  498. if (!(sdata->u.mntr.flags & MONITOR_FLAG_ACTIVE))
  499. continue;
  500. break;
  501. case NL80211_IFTYPE_AP_VLAN:
  502. continue;
  503. default:
  504. break;
  505. }
  506. if (!(iter_flags & IEEE80211_IFACE_ITER_RESUME_ALL) &&
  507. active_only && !(sdata->flags & IEEE80211_SDATA_IN_DRIVER))
  508. continue;
  509. if (ieee80211_sdata_running(sdata) || !active_only)
  510. iterator(data, sdata->vif.addr,
  511. &sdata->vif);
  512. }
  513. sdata = rcu_dereference_check(local->monitor_sdata,
  514. lockdep_is_held(&local->iflist_mtx) ||
  515. lockdep_rtnl_is_held());
  516. if (sdata &&
  517. (iter_flags & IEEE80211_IFACE_ITER_RESUME_ALL || !active_only ||
  518. sdata->flags & IEEE80211_SDATA_IN_DRIVER))
  519. iterator(data, sdata->vif.addr, &sdata->vif);
  520. }
  521. void ieee80211_iterate_interfaces(
  522. struct ieee80211_hw *hw, u32 iter_flags,
  523. void (*iterator)(void *data, u8 *mac,
  524. struct ieee80211_vif *vif),
  525. void *data)
  526. {
  527. struct ieee80211_local *local = hw_to_local(hw);
  528. mutex_lock(&local->iflist_mtx);
  529. __iterate_interfaces(local, iter_flags, iterator, data);
  530. mutex_unlock(&local->iflist_mtx);
  531. }
  532. EXPORT_SYMBOL_GPL(ieee80211_iterate_interfaces);
  533. void ieee80211_iterate_active_interfaces_atomic(
  534. struct ieee80211_hw *hw, u32 iter_flags,
  535. void (*iterator)(void *data, u8 *mac,
  536. struct ieee80211_vif *vif),
  537. void *data)
  538. {
  539. struct ieee80211_local *local = hw_to_local(hw);
  540. rcu_read_lock();
  541. __iterate_interfaces(local, iter_flags | IEEE80211_IFACE_ITER_ACTIVE,
  542. iterator, data);
  543. rcu_read_unlock();
  544. }
  545. EXPORT_SYMBOL_GPL(ieee80211_iterate_active_interfaces_atomic);
  546. void ieee80211_iterate_active_interfaces_rtnl(
  547. struct ieee80211_hw *hw, u32 iter_flags,
  548. void (*iterator)(void *data, u8 *mac,
  549. struct ieee80211_vif *vif),
  550. void *data)
  551. {
  552. struct ieee80211_local *local = hw_to_local(hw);
  553. ASSERT_RTNL();
  554. __iterate_interfaces(local, iter_flags | IEEE80211_IFACE_ITER_ACTIVE,
  555. iterator, data);
  556. }
  557. EXPORT_SYMBOL_GPL(ieee80211_iterate_active_interfaces_rtnl);
  558. static void __iterate_stations(struct ieee80211_local *local,
  559. void (*iterator)(void *data,
  560. struct ieee80211_sta *sta),
  561. void *data)
  562. {
  563. struct sta_info *sta;
  564. list_for_each_entry_rcu(sta, &local->sta_list, list) {
  565. if (!sta->uploaded)
  566. continue;
  567. iterator(data, &sta->sta);
  568. }
  569. }
  570. void ieee80211_iterate_stations_atomic(struct ieee80211_hw *hw,
  571. void (*iterator)(void *data,
  572. struct ieee80211_sta *sta),
  573. void *data)
  574. {
  575. struct ieee80211_local *local = hw_to_local(hw);
  576. rcu_read_lock();
  577. __iterate_stations(local, iterator, data);
  578. rcu_read_unlock();
  579. }
  580. EXPORT_SYMBOL_GPL(ieee80211_iterate_stations_atomic);
  581. struct ieee80211_vif *wdev_to_ieee80211_vif(struct wireless_dev *wdev)
  582. {
  583. struct ieee80211_sub_if_data *sdata = IEEE80211_WDEV_TO_SUB_IF(wdev);
  584. if (!ieee80211_sdata_running(sdata) ||
  585. !(sdata->flags & IEEE80211_SDATA_IN_DRIVER))
  586. return NULL;
  587. return &sdata->vif;
  588. }
  589. EXPORT_SYMBOL_GPL(wdev_to_ieee80211_vif);
  590. struct wireless_dev *ieee80211_vif_to_wdev(struct ieee80211_vif *vif)
  591. {
  592. struct ieee80211_sub_if_data *sdata;
  593. if (!vif)
  594. return NULL;
  595. sdata = vif_to_sdata(vif);
  596. if (!ieee80211_sdata_running(sdata) ||
  597. !(sdata->flags & IEEE80211_SDATA_IN_DRIVER))
  598. return NULL;
  599. return &sdata->wdev;
  600. }
  601. EXPORT_SYMBOL_GPL(ieee80211_vif_to_wdev);
  602. /*
  603. * Nothing should have been stuffed into the workqueue during
  604. * the suspend->resume cycle. Since we can't check each caller
  605. * of this function if we are already quiescing / suspended,
  606. * check here and don't WARN since this can actually happen when
  607. * the rx path (for example) is racing against __ieee80211_suspend
  608. * and suspending / quiescing was set after the rx path checked
  609. * them.
  610. */
  611. static bool ieee80211_can_queue_work(struct ieee80211_local *local)
  612. {
  613. if (local->quiescing || (local->suspended && !local->resuming)) {
  614. pr_warn("queueing ieee80211 work while going to suspend\n");
  615. return false;
  616. }
  617. return true;
  618. }
  619. void ieee80211_queue_work(struct ieee80211_hw *hw, struct work_struct *work)
  620. {
  621. struct ieee80211_local *local = hw_to_local(hw);
  622. if (!ieee80211_can_queue_work(local))
  623. return;
  624. queue_work(local->workqueue, work);
  625. }
  626. EXPORT_SYMBOL(ieee80211_queue_work);
  627. void ieee80211_queue_delayed_work(struct ieee80211_hw *hw,
  628. struct delayed_work *dwork,
  629. unsigned long delay)
  630. {
  631. struct ieee80211_local *local = hw_to_local(hw);
  632. if (!ieee80211_can_queue_work(local))
  633. return;
  634. queue_delayed_work(local->workqueue, dwork, delay);
  635. }
  636. EXPORT_SYMBOL(ieee80211_queue_delayed_work);
  637. u32 ieee802_11_parse_elems_crc(const u8 *start, size_t len, bool action,
  638. struct ieee802_11_elems *elems,
  639. u64 filter, u32 crc)
  640. {
  641. size_t left = len;
  642. const u8 *pos = start;
  643. bool calc_crc = filter != 0;
  644. DECLARE_BITMAP(seen_elems, 256);
  645. const u8 *ie;
  646. bitmap_zero(seen_elems, 256);
  647. memset(elems, 0, sizeof(*elems));
  648. elems->ie_start = start;
  649. elems->total_len = len;
  650. while (left >= 2) {
  651. u8 id, elen;
  652. bool elem_parse_failed;
  653. id = *pos++;
  654. elen = *pos++;
  655. left -= 2;
  656. if (elen > left) {
  657. elems->parse_error = true;
  658. break;
  659. }
  660. switch (id) {
  661. case WLAN_EID_SSID:
  662. case WLAN_EID_SUPP_RATES:
  663. case WLAN_EID_FH_PARAMS:
  664. case WLAN_EID_DS_PARAMS:
  665. case WLAN_EID_CF_PARAMS:
  666. case WLAN_EID_TIM:
  667. case WLAN_EID_IBSS_PARAMS:
  668. case WLAN_EID_CHALLENGE:
  669. case WLAN_EID_RSN:
  670. case WLAN_EID_ERP_INFO:
  671. case WLAN_EID_EXT_SUPP_RATES:
  672. case WLAN_EID_HT_CAPABILITY:
  673. case WLAN_EID_HT_OPERATION:
  674. case WLAN_EID_VHT_CAPABILITY:
  675. case WLAN_EID_VHT_OPERATION:
  676. case WLAN_EID_MESH_ID:
  677. case WLAN_EID_MESH_CONFIG:
  678. case WLAN_EID_PEER_MGMT:
  679. case WLAN_EID_PREQ:
  680. case WLAN_EID_PREP:
  681. case WLAN_EID_PERR:
  682. case WLAN_EID_RANN:
  683. case WLAN_EID_CHANNEL_SWITCH:
  684. case WLAN_EID_EXT_CHANSWITCH_ANN:
  685. case WLAN_EID_COUNTRY:
  686. case WLAN_EID_PWR_CONSTRAINT:
  687. case WLAN_EID_TIMEOUT_INTERVAL:
  688. case WLAN_EID_SECONDARY_CHANNEL_OFFSET:
  689. case WLAN_EID_WIDE_BW_CHANNEL_SWITCH:
  690. case WLAN_EID_CHAN_SWITCH_PARAM:
  691. case WLAN_EID_EXT_CAPABILITY:
  692. case WLAN_EID_CHAN_SWITCH_TIMING:
  693. case WLAN_EID_LINK_ID:
  694. /*
  695. * not listing WLAN_EID_CHANNEL_SWITCH_WRAPPER -- it seems possible
  696. * that if the content gets bigger it might be needed more than once
  697. */
  698. if (test_bit(id, seen_elems)) {
  699. elems->parse_error = true;
  700. left -= elen;
  701. pos += elen;
  702. continue;
  703. }
  704. break;
  705. }
  706. if (calc_crc && id < 64 && (filter & (1ULL << id)))
  707. crc = crc32_be(crc, pos - 2, elen + 2);
  708. elem_parse_failed = false;
  709. switch (id) {
  710. case WLAN_EID_LINK_ID:
  711. if (elen + 2 != sizeof(struct ieee80211_tdls_lnkie)) {
  712. elem_parse_failed = true;
  713. break;
  714. }
  715. elems->lnk_id = (void *)(pos - 2);
  716. break;
  717. case WLAN_EID_CHAN_SWITCH_TIMING:
  718. if (elen != sizeof(struct ieee80211_ch_switch_timing)) {
  719. elem_parse_failed = true;
  720. break;
  721. }
  722. elems->ch_sw_timing = (void *)pos;
  723. break;
  724. case WLAN_EID_EXT_CAPABILITY:
  725. elems->ext_capab = pos;
  726. elems->ext_capab_len = elen;
  727. break;
  728. case WLAN_EID_SSID:
  729. elems->ssid = pos;
  730. elems->ssid_len = elen;
  731. break;
  732. case WLAN_EID_SUPP_RATES:
  733. elems->supp_rates = pos;
  734. elems->supp_rates_len = elen;
  735. break;
  736. case WLAN_EID_DS_PARAMS:
  737. if (elen >= 1)
  738. elems->ds_params = pos;
  739. else
  740. elem_parse_failed = true;
  741. break;
  742. case WLAN_EID_TIM:
  743. if (elen >= sizeof(struct ieee80211_tim_ie)) {
  744. elems->tim = (void *)pos;
  745. elems->tim_len = elen;
  746. } else
  747. elem_parse_failed = true;
  748. break;
  749. case WLAN_EID_CHALLENGE:
  750. elems->challenge = pos;
  751. elems->challenge_len = elen;
  752. break;
  753. case WLAN_EID_VENDOR_SPECIFIC:
  754. if (elen >= 4 && pos[0] == 0x00 && pos[1] == 0x50 &&
  755. pos[2] == 0xf2) {
  756. /* Microsoft OUI (00:50:F2) */
  757. if (calc_crc)
  758. crc = crc32_be(crc, pos - 2, elen + 2);
  759. if (elen >= 5 && pos[3] == 2) {
  760. /* OUI Type 2 - WMM IE */
  761. if (pos[4] == 0) {
  762. elems->wmm_info = pos;
  763. elems->wmm_info_len = elen;
  764. } else if (pos[4] == 1) {
  765. elems->wmm_param = pos;
  766. elems->wmm_param_len = elen;
  767. }
  768. }
  769. }
  770. break;
  771. case WLAN_EID_RSN:
  772. elems->rsn = pos;
  773. elems->rsn_len = elen;
  774. break;
  775. case WLAN_EID_ERP_INFO:
  776. if (elen >= 1)
  777. elems->erp_info = pos;
  778. else
  779. elem_parse_failed = true;
  780. break;
  781. case WLAN_EID_EXT_SUPP_RATES:
  782. elems->ext_supp_rates = pos;
  783. elems->ext_supp_rates_len = elen;
  784. break;
  785. case WLAN_EID_HT_CAPABILITY:
  786. if (elen >= sizeof(struct ieee80211_ht_cap))
  787. elems->ht_cap_elem = (void *)pos;
  788. else
  789. elem_parse_failed = true;
  790. break;
  791. case WLAN_EID_HT_OPERATION:
  792. if (elen >= sizeof(struct ieee80211_ht_operation))
  793. elems->ht_operation = (void *)pos;
  794. else
  795. elem_parse_failed = true;
  796. break;
  797. case WLAN_EID_VHT_CAPABILITY:
  798. if (elen >= sizeof(struct ieee80211_vht_cap))
  799. elems->vht_cap_elem = (void *)pos;
  800. else
  801. elem_parse_failed = true;
  802. break;
  803. case WLAN_EID_VHT_OPERATION:
  804. if (elen >= sizeof(struct ieee80211_vht_operation))
  805. elems->vht_operation = (void *)pos;
  806. else
  807. elem_parse_failed = true;
  808. break;
  809. case WLAN_EID_OPMODE_NOTIF:
  810. if (elen > 0)
  811. elems->opmode_notif = pos;
  812. else
  813. elem_parse_failed = true;
  814. break;
  815. case WLAN_EID_MESH_ID:
  816. elems->mesh_id = pos;
  817. elems->mesh_id_len = elen;
  818. break;
  819. case WLAN_EID_MESH_CONFIG:
  820. if (elen >= sizeof(struct ieee80211_meshconf_ie))
  821. elems->mesh_config = (void *)pos;
  822. else
  823. elem_parse_failed = true;
  824. break;
  825. case WLAN_EID_PEER_MGMT:
  826. elems->peering = pos;
  827. elems->peering_len = elen;
  828. break;
  829. case WLAN_EID_MESH_AWAKE_WINDOW:
  830. if (elen >= 2)
  831. elems->awake_window = (void *)pos;
  832. break;
  833. case WLAN_EID_PREQ:
  834. elems->preq = pos;
  835. elems->preq_len = elen;
  836. break;
  837. case WLAN_EID_PREP:
  838. elems->prep = pos;
  839. elems->prep_len = elen;
  840. break;
  841. case WLAN_EID_PERR:
  842. elems->perr = pos;
  843. elems->perr_len = elen;
  844. break;
  845. case WLAN_EID_RANN:
  846. if (elen >= sizeof(struct ieee80211_rann_ie))
  847. elems->rann = (void *)pos;
  848. else
  849. elem_parse_failed = true;
  850. break;
  851. case WLAN_EID_CHANNEL_SWITCH:
  852. if (elen != sizeof(struct ieee80211_channel_sw_ie)) {
  853. elem_parse_failed = true;
  854. break;
  855. }
  856. elems->ch_switch_ie = (void *)pos;
  857. break;
  858. case WLAN_EID_EXT_CHANSWITCH_ANN:
  859. if (elen != sizeof(struct ieee80211_ext_chansw_ie)) {
  860. elem_parse_failed = true;
  861. break;
  862. }
  863. elems->ext_chansw_ie = (void *)pos;
  864. break;
  865. case WLAN_EID_SECONDARY_CHANNEL_OFFSET:
  866. if (elen != sizeof(struct ieee80211_sec_chan_offs_ie)) {
  867. elem_parse_failed = true;
  868. break;
  869. }
  870. elems->sec_chan_offs = (void *)pos;
  871. break;
  872. case WLAN_EID_CHAN_SWITCH_PARAM:
  873. if (elen !=
  874. sizeof(*elems->mesh_chansw_params_ie)) {
  875. elem_parse_failed = true;
  876. break;
  877. }
  878. elems->mesh_chansw_params_ie = (void *)pos;
  879. break;
  880. case WLAN_EID_WIDE_BW_CHANNEL_SWITCH:
  881. if (!action ||
  882. elen != sizeof(*elems->wide_bw_chansw_ie)) {
  883. elem_parse_failed = true;
  884. break;
  885. }
  886. elems->wide_bw_chansw_ie = (void *)pos;
  887. break;
  888. case WLAN_EID_CHANNEL_SWITCH_WRAPPER:
  889. if (action) {
  890. elem_parse_failed = true;
  891. break;
  892. }
  893. /*
  894. * This is a bit tricky, but as we only care about
  895. * the wide bandwidth channel switch element, so
  896. * just parse it out manually.
  897. */
  898. ie = cfg80211_find_ie(WLAN_EID_WIDE_BW_CHANNEL_SWITCH,
  899. pos, elen);
  900. if (ie) {
  901. if (ie[1] == sizeof(*elems->wide_bw_chansw_ie))
  902. elems->wide_bw_chansw_ie =
  903. (void *)(ie + 2);
  904. else
  905. elem_parse_failed = true;
  906. }
  907. break;
  908. case WLAN_EID_COUNTRY:
  909. elems->country_elem = pos;
  910. elems->country_elem_len = elen;
  911. break;
  912. case WLAN_EID_PWR_CONSTRAINT:
  913. if (elen != 1) {
  914. elem_parse_failed = true;
  915. break;
  916. }
  917. elems->pwr_constr_elem = pos;
  918. break;
  919. case WLAN_EID_CISCO_VENDOR_SPECIFIC:
  920. /* Lots of different options exist, but we only care
  921. * about the Dynamic Transmit Power Control element.
  922. * First check for the Cisco OUI, then for the DTPC
  923. * tag (0x00).
  924. */
  925. if (elen < 4) {
  926. elem_parse_failed = true;
  927. break;
  928. }
  929. if (pos[0] != 0x00 || pos[1] != 0x40 ||
  930. pos[2] != 0x96 || pos[3] != 0x00)
  931. break;
  932. if (elen != 6) {
  933. elem_parse_failed = true;
  934. break;
  935. }
  936. if (calc_crc)
  937. crc = crc32_be(crc, pos - 2, elen + 2);
  938. elems->cisco_dtpc_elem = pos;
  939. break;
  940. case WLAN_EID_TIMEOUT_INTERVAL:
  941. if (elen >= sizeof(struct ieee80211_timeout_interval_ie))
  942. elems->timeout_int = (void *)pos;
  943. else
  944. elem_parse_failed = true;
  945. break;
  946. default:
  947. break;
  948. }
  949. if (elem_parse_failed)
  950. elems->parse_error = true;
  951. else
  952. __set_bit(id, seen_elems);
  953. left -= elen;
  954. pos += elen;
  955. }
  956. if (left != 0)
  957. elems->parse_error = true;
  958. return crc;
  959. }
  960. void ieee80211_set_wmm_default(struct ieee80211_sub_if_data *sdata,
  961. bool bss_notify, bool enable_qos)
  962. {
  963. struct ieee80211_local *local = sdata->local;
  964. struct ieee80211_tx_queue_params qparam;
  965. struct ieee80211_chanctx_conf *chanctx_conf;
  966. int ac;
  967. bool use_11b;
  968. bool is_ocb; /* Use another EDCA parameters if dot11OCBActivated=true */
  969. int aCWmin, aCWmax;
  970. if (!local->ops->conf_tx)
  971. return;
  972. if (local->hw.queues < IEEE80211_NUM_ACS)
  973. return;
  974. memset(&qparam, 0, sizeof(qparam));
  975. rcu_read_lock();
  976. chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
  977. use_11b = (chanctx_conf &&
  978. chanctx_conf->def.chan->band == NL80211_BAND_2GHZ) &&
  979. !(sdata->flags & IEEE80211_SDATA_OPERATING_GMODE);
  980. rcu_read_unlock();
  981. is_ocb = (sdata->vif.type == NL80211_IFTYPE_OCB);
  982. /* Set defaults according to 802.11-2007 Table 7-37 */
  983. aCWmax = 1023;
  984. if (use_11b)
  985. aCWmin = 31;
  986. else
  987. aCWmin = 15;
  988. /* Confiure old 802.11b/g medium access rules. */
  989. qparam.cw_max = aCWmax;
  990. qparam.cw_min = aCWmin;
  991. qparam.txop = 0;
  992. qparam.aifs = 2;
  993. for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
  994. /* Update if QoS is enabled. */
  995. if (enable_qos) {
  996. switch (ac) {
  997. case IEEE80211_AC_BK:
  998. qparam.cw_max = aCWmax;
  999. qparam.cw_min = aCWmin;
  1000. qparam.txop = 0;
  1001. if (is_ocb)
  1002. qparam.aifs = 9;
  1003. else
  1004. qparam.aifs = 7;
  1005. break;
  1006. /* never happens but let's not leave undefined */
  1007. default:
  1008. case IEEE80211_AC_BE:
  1009. qparam.cw_max = aCWmax;
  1010. qparam.cw_min = aCWmin;
  1011. qparam.txop = 0;
  1012. if (is_ocb)
  1013. qparam.aifs = 6;
  1014. else
  1015. qparam.aifs = 3;
  1016. break;
  1017. case IEEE80211_AC_VI:
  1018. qparam.cw_max = aCWmin;
  1019. qparam.cw_min = (aCWmin + 1) / 2 - 1;
  1020. if (is_ocb)
  1021. qparam.txop = 0;
  1022. else if (use_11b)
  1023. qparam.txop = 6016/32;
  1024. else
  1025. qparam.txop = 3008/32;
  1026. if (is_ocb)
  1027. qparam.aifs = 3;
  1028. else
  1029. qparam.aifs = 2;
  1030. break;
  1031. case IEEE80211_AC_VO:
  1032. qparam.cw_max = (aCWmin + 1) / 2 - 1;
  1033. qparam.cw_min = (aCWmin + 1) / 4 - 1;
  1034. if (is_ocb)
  1035. qparam.txop = 0;
  1036. else if (use_11b)
  1037. qparam.txop = 3264/32;
  1038. else
  1039. qparam.txop = 1504/32;
  1040. qparam.aifs = 2;
  1041. break;
  1042. }
  1043. }
  1044. qparam.uapsd = false;
  1045. sdata->tx_conf[ac] = qparam;
  1046. drv_conf_tx(local, sdata, ac, &qparam);
  1047. }
  1048. if (sdata->vif.type != NL80211_IFTYPE_MONITOR &&
  1049. sdata->vif.type != NL80211_IFTYPE_P2P_DEVICE &&
  1050. sdata->vif.type != NL80211_IFTYPE_NAN) {
  1051. sdata->vif.bss_conf.qos = enable_qos;
  1052. if (bss_notify)
  1053. ieee80211_bss_info_change_notify(sdata,
  1054. BSS_CHANGED_QOS);
  1055. }
  1056. }
  1057. void ieee80211_send_auth(struct ieee80211_sub_if_data *sdata,
  1058. u16 transaction, u16 auth_alg, u16 status,
  1059. const u8 *extra, size_t extra_len, const u8 *da,
  1060. const u8 *bssid, const u8 *key, u8 key_len, u8 key_idx,
  1061. u32 tx_flags)
  1062. {
  1063. struct ieee80211_local *local = sdata->local;
  1064. struct sk_buff *skb;
  1065. struct ieee80211_mgmt *mgmt;
  1066. int err;
  1067. /* 24 + 6 = header + auth_algo + auth_transaction + status_code */
  1068. skb = dev_alloc_skb(local->hw.extra_tx_headroom + IEEE80211_WEP_IV_LEN +
  1069. 24 + 6 + extra_len + IEEE80211_WEP_ICV_LEN);
  1070. if (!skb)
  1071. return;
  1072. skb_reserve(skb, local->hw.extra_tx_headroom + IEEE80211_WEP_IV_LEN);
  1073. mgmt = (struct ieee80211_mgmt *) skb_put(skb, 24 + 6);
  1074. memset(mgmt, 0, 24 + 6);
  1075. mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
  1076. IEEE80211_STYPE_AUTH);
  1077. memcpy(mgmt->da, da, ETH_ALEN);
  1078. memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
  1079. memcpy(mgmt->bssid, bssid, ETH_ALEN);
  1080. mgmt->u.auth.auth_alg = cpu_to_le16(auth_alg);
  1081. mgmt->u.auth.auth_transaction = cpu_to_le16(transaction);
  1082. mgmt->u.auth.status_code = cpu_to_le16(status);
  1083. if (extra)
  1084. memcpy(skb_put(skb, extra_len), extra, extra_len);
  1085. if (auth_alg == WLAN_AUTH_SHARED_KEY && transaction == 3) {
  1086. mgmt->frame_control |= cpu_to_le16(IEEE80211_FCTL_PROTECTED);
  1087. err = ieee80211_wep_encrypt(local, skb, key, key_len, key_idx);
  1088. WARN_ON(err);
  1089. }
  1090. IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT |
  1091. tx_flags;
  1092. ieee80211_tx_skb(sdata, skb);
  1093. }
  1094. void ieee80211_send_deauth_disassoc(struct ieee80211_sub_if_data *sdata,
  1095. const u8 *bssid, u16 stype, u16 reason,
  1096. bool send_frame, u8 *frame_buf)
  1097. {
  1098. struct ieee80211_local *local = sdata->local;
  1099. struct sk_buff *skb;
  1100. struct ieee80211_mgmt *mgmt = (void *)frame_buf;
  1101. /* build frame */
  1102. mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT | stype);
  1103. mgmt->duration = 0; /* initialize only */
  1104. mgmt->seq_ctrl = 0; /* initialize only */
  1105. memcpy(mgmt->da, bssid, ETH_ALEN);
  1106. memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
  1107. memcpy(mgmt->bssid, bssid, ETH_ALEN);
  1108. /* u.deauth.reason_code == u.disassoc.reason_code */
  1109. mgmt->u.deauth.reason_code = cpu_to_le16(reason);
  1110. if (send_frame) {
  1111. skb = dev_alloc_skb(local->hw.extra_tx_headroom +
  1112. IEEE80211_DEAUTH_FRAME_LEN);
  1113. if (!skb)
  1114. return;
  1115. skb_reserve(skb, local->hw.extra_tx_headroom);
  1116. /* copy in frame */
  1117. memcpy(skb_put(skb, IEEE80211_DEAUTH_FRAME_LEN),
  1118. mgmt, IEEE80211_DEAUTH_FRAME_LEN);
  1119. if (sdata->vif.type != NL80211_IFTYPE_STATION ||
  1120. !(sdata->u.mgd.flags & IEEE80211_STA_MFP_ENABLED))
  1121. IEEE80211_SKB_CB(skb)->flags |=
  1122. IEEE80211_TX_INTFL_DONT_ENCRYPT;
  1123. ieee80211_tx_skb(sdata, skb);
  1124. }
  1125. }
  1126. static int ieee80211_build_preq_ies_band(struct ieee80211_local *local,
  1127. u8 *buffer, size_t buffer_len,
  1128. const u8 *ie, size_t ie_len,
  1129. enum nl80211_band band,
  1130. u32 rate_mask,
  1131. struct cfg80211_chan_def *chandef,
  1132. size_t *offset)
  1133. {
  1134. struct ieee80211_supported_band *sband;
  1135. u8 *pos = buffer, *end = buffer + buffer_len;
  1136. size_t noffset;
  1137. int supp_rates_len, i;
  1138. u8 rates[32];
  1139. int num_rates;
  1140. int ext_rates_len;
  1141. int shift;
  1142. u32 rate_flags;
  1143. bool have_80mhz = false;
  1144. *offset = 0;
  1145. sband = local->hw.wiphy->bands[band];
  1146. if (WARN_ON_ONCE(!sband))
  1147. return 0;
  1148. rate_flags = ieee80211_chandef_rate_flags(chandef);
  1149. shift = ieee80211_chandef_get_shift(chandef);
  1150. num_rates = 0;
  1151. for (i = 0; i < sband->n_bitrates; i++) {
  1152. if ((BIT(i) & rate_mask) == 0)
  1153. continue; /* skip rate */
  1154. if ((rate_flags & sband->bitrates[i].flags) != rate_flags)
  1155. continue;
  1156. rates[num_rates++] =
  1157. (u8) DIV_ROUND_UP(sband->bitrates[i].bitrate,
  1158. (1 << shift) * 5);
  1159. }
  1160. supp_rates_len = min_t(int, num_rates, 8);
  1161. if (end - pos < 2 + supp_rates_len)
  1162. goto out_err;
  1163. *pos++ = WLAN_EID_SUPP_RATES;
  1164. *pos++ = supp_rates_len;
  1165. memcpy(pos, rates, supp_rates_len);
  1166. pos += supp_rates_len;
  1167. /* insert "request information" if in custom IEs */
  1168. if (ie && ie_len) {
  1169. static const u8 before_extrates[] = {
  1170. WLAN_EID_SSID,
  1171. WLAN_EID_SUPP_RATES,
  1172. WLAN_EID_REQUEST,
  1173. };
  1174. noffset = ieee80211_ie_split(ie, ie_len,
  1175. before_extrates,
  1176. ARRAY_SIZE(before_extrates),
  1177. *offset);
  1178. if (end - pos < noffset - *offset)
  1179. goto out_err;
  1180. memcpy(pos, ie + *offset, noffset - *offset);
  1181. pos += noffset - *offset;
  1182. *offset = noffset;
  1183. }
  1184. ext_rates_len = num_rates - supp_rates_len;
  1185. if (ext_rates_len > 0) {
  1186. if (end - pos < 2 + ext_rates_len)
  1187. goto out_err;
  1188. *pos++ = WLAN_EID_EXT_SUPP_RATES;
  1189. *pos++ = ext_rates_len;
  1190. memcpy(pos, rates + supp_rates_len, ext_rates_len);
  1191. pos += ext_rates_len;
  1192. }
  1193. if (chandef->chan && sband->band == NL80211_BAND_2GHZ) {
  1194. if (end - pos < 3)
  1195. goto out_err;
  1196. *pos++ = WLAN_EID_DS_PARAMS;
  1197. *pos++ = 1;
  1198. *pos++ = ieee80211_frequency_to_channel(
  1199. chandef->chan->center_freq);
  1200. }
  1201. /* insert custom IEs that go before HT */
  1202. if (ie && ie_len) {
  1203. static const u8 before_ht[] = {
  1204. WLAN_EID_SSID,
  1205. WLAN_EID_SUPP_RATES,
  1206. WLAN_EID_REQUEST,
  1207. WLAN_EID_EXT_SUPP_RATES,
  1208. WLAN_EID_DS_PARAMS,
  1209. WLAN_EID_SUPPORTED_REGULATORY_CLASSES,
  1210. };
  1211. noffset = ieee80211_ie_split(ie, ie_len,
  1212. before_ht, ARRAY_SIZE(before_ht),
  1213. *offset);
  1214. if (end - pos < noffset - *offset)
  1215. goto out_err;
  1216. memcpy(pos, ie + *offset, noffset - *offset);
  1217. pos += noffset - *offset;
  1218. *offset = noffset;
  1219. }
  1220. if (sband->ht_cap.ht_supported) {
  1221. if (end - pos < 2 + sizeof(struct ieee80211_ht_cap))
  1222. goto out_err;
  1223. pos = ieee80211_ie_build_ht_cap(pos, &sband->ht_cap,
  1224. sband->ht_cap.cap);
  1225. }
  1226. /*
  1227. * If adding more here, adjust code in main.c
  1228. * that calculates local->scan_ies_len.
  1229. */
  1230. /* insert custom IEs that go before VHT */
  1231. if (ie && ie_len) {
  1232. static const u8 before_vht[] = {
  1233. WLAN_EID_SSID,
  1234. WLAN_EID_SUPP_RATES,
  1235. WLAN_EID_REQUEST,
  1236. WLAN_EID_EXT_SUPP_RATES,
  1237. WLAN_EID_DS_PARAMS,
  1238. WLAN_EID_SUPPORTED_REGULATORY_CLASSES,
  1239. WLAN_EID_HT_CAPABILITY,
  1240. WLAN_EID_BSS_COEX_2040,
  1241. WLAN_EID_EXT_CAPABILITY,
  1242. WLAN_EID_SSID_LIST,
  1243. WLAN_EID_CHANNEL_USAGE,
  1244. WLAN_EID_INTERWORKING,
  1245. /* mesh ID can't happen here */
  1246. /* 60 GHz can't happen here right now */
  1247. };
  1248. noffset = ieee80211_ie_split(ie, ie_len,
  1249. before_vht, ARRAY_SIZE(before_vht),
  1250. *offset);
  1251. if (end - pos < noffset - *offset)
  1252. goto out_err;
  1253. memcpy(pos, ie + *offset, noffset - *offset);
  1254. pos += noffset - *offset;
  1255. *offset = noffset;
  1256. }
  1257. /* Check if any channel in this sband supports at least 80 MHz */
  1258. for (i = 0; i < sband->n_channels; i++) {
  1259. if (sband->channels[i].flags & (IEEE80211_CHAN_DISABLED |
  1260. IEEE80211_CHAN_NO_80MHZ))
  1261. continue;
  1262. have_80mhz = true;
  1263. break;
  1264. }
  1265. if (sband->vht_cap.vht_supported && have_80mhz) {
  1266. if (end - pos < 2 + sizeof(struct ieee80211_vht_cap))
  1267. goto out_err;
  1268. pos = ieee80211_ie_build_vht_cap(pos, &sband->vht_cap,
  1269. sband->vht_cap.cap);
  1270. }
  1271. return pos - buffer;
  1272. out_err:
  1273. WARN_ONCE(1, "not enough space for preq IEs\n");
  1274. return pos - buffer;
  1275. }
  1276. int ieee80211_build_preq_ies(struct ieee80211_local *local, u8 *buffer,
  1277. size_t buffer_len,
  1278. struct ieee80211_scan_ies *ie_desc,
  1279. const u8 *ie, size_t ie_len,
  1280. u8 bands_used, u32 *rate_masks,
  1281. struct cfg80211_chan_def *chandef)
  1282. {
  1283. size_t pos = 0, old_pos = 0, custom_ie_offset = 0;
  1284. int i;
  1285. memset(ie_desc, 0, sizeof(*ie_desc));
  1286. for (i = 0; i < NUM_NL80211_BANDS; i++) {
  1287. if (bands_used & BIT(i)) {
  1288. pos += ieee80211_build_preq_ies_band(local,
  1289. buffer + pos,
  1290. buffer_len - pos,
  1291. ie, ie_len, i,
  1292. rate_masks[i],
  1293. chandef,
  1294. &custom_ie_offset);
  1295. ie_desc->ies[i] = buffer + old_pos;
  1296. ie_desc->len[i] = pos - old_pos;
  1297. old_pos = pos;
  1298. }
  1299. }
  1300. /* add any remaining custom IEs */
  1301. if (ie && ie_len) {
  1302. if (WARN_ONCE(buffer_len - pos < ie_len - custom_ie_offset,
  1303. "not enough space for preq custom IEs\n"))
  1304. return pos;
  1305. memcpy(buffer + pos, ie + custom_ie_offset,
  1306. ie_len - custom_ie_offset);
  1307. ie_desc->common_ies = buffer + pos;
  1308. ie_desc->common_ie_len = ie_len - custom_ie_offset;
  1309. pos += ie_len - custom_ie_offset;
  1310. }
  1311. return pos;
  1312. };
  1313. struct sk_buff *ieee80211_build_probe_req(struct ieee80211_sub_if_data *sdata,
  1314. const u8 *src, const u8 *dst,
  1315. u32 ratemask,
  1316. struct ieee80211_channel *chan,
  1317. const u8 *ssid, size_t ssid_len,
  1318. const u8 *ie, size_t ie_len,
  1319. bool directed)
  1320. {
  1321. struct ieee80211_local *local = sdata->local;
  1322. struct cfg80211_chan_def chandef;
  1323. struct sk_buff *skb;
  1324. struct ieee80211_mgmt *mgmt;
  1325. int ies_len;
  1326. u32 rate_masks[NUM_NL80211_BANDS] = {};
  1327. struct ieee80211_scan_ies dummy_ie_desc;
  1328. /*
  1329. * Do not send DS Channel parameter for directed probe requests
  1330. * in order to maximize the chance that we get a response. Some
  1331. * badly-behaved APs don't respond when this parameter is included.
  1332. */
  1333. chandef.width = sdata->vif.bss_conf.chandef.width;
  1334. if (directed)
  1335. chandef.chan = NULL;
  1336. else
  1337. chandef.chan = chan;
  1338. skb = ieee80211_probereq_get(&local->hw, src, ssid, ssid_len,
  1339. 100 + ie_len);
  1340. if (!skb)
  1341. return NULL;
  1342. rate_masks[chan->band] = ratemask;
  1343. ies_len = ieee80211_build_preq_ies(local, skb_tail_pointer(skb),
  1344. skb_tailroom(skb), &dummy_ie_desc,
  1345. ie, ie_len, BIT(chan->band),
  1346. rate_masks, &chandef);
  1347. skb_put(skb, ies_len);
  1348. if (dst) {
  1349. mgmt = (struct ieee80211_mgmt *) skb->data;
  1350. memcpy(mgmt->da, dst, ETH_ALEN);
  1351. memcpy(mgmt->bssid, dst, ETH_ALEN);
  1352. }
  1353. IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
  1354. return skb;
  1355. }
  1356. void ieee80211_send_probe_req(struct ieee80211_sub_if_data *sdata,
  1357. const u8 *src, const u8 *dst,
  1358. const u8 *ssid, size_t ssid_len,
  1359. const u8 *ie, size_t ie_len,
  1360. u32 ratemask, bool directed, u32 tx_flags,
  1361. struct ieee80211_channel *channel, bool scan)
  1362. {
  1363. struct sk_buff *skb;
  1364. skb = ieee80211_build_probe_req(sdata, src, dst, ratemask, channel,
  1365. ssid, ssid_len,
  1366. ie, ie_len, directed);
  1367. if (skb) {
  1368. IEEE80211_SKB_CB(skb)->flags |= tx_flags;
  1369. if (scan)
  1370. ieee80211_tx_skb_tid_band(sdata, skb, 7, channel->band);
  1371. else
  1372. ieee80211_tx_skb(sdata, skb);
  1373. }
  1374. }
  1375. u32 ieee80211_sta_get_rates(struct ieee80211_sub_if_data *sdata,
  1376. struct ieee802_11_elems *elems,
  1377. enum nl80211_band band, u32 *basic_rates)
  1378. {
  1379. struct ieee80211_supported_band *sband;
  1380. size_t num_rates;
  1381. u32 supp_rates, rate_flags;
  1382. int i, j, shift;
  1383. sband = sdata->local->hw.wiphy->bands[band];
  1384. if (WARN_ON(!sband))
  1385. return 1;
  1386. rate_flags = ieee80211_chandef_rate_flags(&sdata->vif.bss_conf.chandef);
  1387. shift = ieee80211_vif_get_shift(&sdata->vif);
  1388. num_rates = sband->n_bitrates;
  1389. supp_rates = 0;
  1390. for (i = 0; i < elems->supp_rates_len +
  1391. elems->ext_supp_rates_len; i++) {
  1392. u8 rate = 0;
  1393. int own_rate;
  1394. bool is_basic;
  1395. if (i < elems->supp_rates_len)
  1396. rate = elems->supp_rates[i];
  1397. else if (elems->ext_supp_rates)
  1398. rate = elems->ext_supp_rates
  1399. [i - elems->supp_rates_len];
  1400. own_rate = 5 * (rate & 0x7f);
  1401. is_basic = !!(rate & 0x80);
  1402. if (is_basic && (rate & 0x7f) == BSS_MEMBERSHIP_SELECTOR_HT_PHY)
  1403. continue;
  1404. for (j = 0; j < num_rates; j++) {
  1405. int brate;
  1406. if ((rate_flags & sband->bitrates[j].flags)
  1407. != rate_flags)
  1408. continue;
  1409. brate = DIV_ROUND_UP(sband->bitrates[j].bitrate,
  1410. 1 << shift);
  1411. if (brate == own_rate) {
  1412. supp_rates |= BIT(j);
  1413. if (basic_rates && is_basic)
  1414. *basic_rates |= BIT(j);
  1415. }
  1416. }
  1417. }
  1418. return supp_rates;
  1419. }
  1420. void ieee80211_stop_device(struct ieee80211_local *local)
  1421. {
  1422. ieee80211_led_radio(local, false);
  1423. ieee80211_mod_tpt_led_trig(local, 0, IEEE80211_TPT_LEDTRIG_FL_RADIO);
  1424. cancel_work_sync(&local->reconfig_filter);
  1425. flush_workqueue(local->workqueue);
  1426. drv_stop(local);
  1427. }
  1428. static void ieee80211_flush_completed_scan(struct ieee80211_local *local,
  1429. bool aborted)
  1430. {
  1431. /* It's possible that we don't handle the scan completion in
  1432. * time during suspend, so if it's still marked as completed
  1433. * here, queue the work and flush it to clean things up.
  1434. * Instead of calling the worker function directly here, we
  1435. * really queue it to avoid potential races with other flows
  1436. * scheduling the same work.
  1437. */
  1438. if (test_bit(SCAN_COMPLETED, &local->scanning)) {
  1439. /* If coming from reconfiguration failure, abort the scan so
  1440. * we don't attempt to continue a partial HW scan - which is
  1441. * possible otherwise if (e.g.) the 2.4 GHz portion was the
  1442. * completed scan, and a 5 GHz portion is still pending.
  1443. */
  1444. if (aborted)
  1445. set_bit(SCAN_ABORTED, &local->scanning);
  1446. ieee80211_queue_delayed_work(&local->hw, &local->scan_work, 0);
  1447. flush_delayed_work(&local->scan_work);
  1448. }
  1449. }
  1450. static void ieee80211_handle_reconfig_failure(struct ieee80211_local *local)
  1451. {
  1452. struct ieee80211_sub_if_data *sdata;
  1453. struct ieee80211_chanctx *ctx;
  1454. /*
  1455. * We get here if during resume the device can't be restarted properly.
  1456. * We might also get here if this happens during HW reset, which is a
  1457. * slightly different situation and we need to drop all connections in
  1458. * the latter case.
  1459. *
  1460. * Ask cfg80211 to turn off all interfaces, this will result in more
  1461. * warnings but at least we'll then get into a clean stopped state.
  1462. */
  1463. local->resuming = false;
  1464. local->suspended = false;
  1465. local->in_reconfig = false;
  1466. ieee80211_flush_completed_scan(local, true);
  1467. /* scheduled scan clearly can't be running any more, but tell
  1468. * cfg80211 and clear local state
  1469. */
  1470. ieee80211_sched_scan_end(local);
  1471. list_for_each_entry(sdata, &local->interfaces, list)
  1472. sdata->flags &= ~IEEE80211_SDATA_IN_DRIVER;
  1473. /* Mark channel contexts as not being in the driver any more to avoid
  1474. * removing them from the driver during the shutdown process...
  1475. */
  1476. mutex_lock(&local->chanctx_mtx);
  1477. list_for_each_entry(ctx, &local->chanctx_list, list)
  1478. ctx->driver_present = false;
  1479. mutex_unlock(&local->chanctx_mtx);
  1480. cfg80211_shutdown_all_interfaces(local->hw.wiphy);
  1481. }
  1482. static void ieee80211_assign_chanctx(struct ieee80211_local *local,
  1483. struct ieee80211_sub_if_data *sdata)
  1484. {
  1485. struct ieee80211_chanctx_conf *conf;
  1486. struct ieee80211_chanctx *ctx;
  1487. if (!local->use_chanctx)
  1488. return;
  1489. mutex_lock(&local->chanctx_mtx);
  1490. conf = rcu_dereference_protected(sdata->vif.chanctx_conf,
  1491. lockdep_is_held(&local->chanctx_mtx));
  1492. if (conf) {
  1493. ctx = container_of(conf, struct ieee80211_chanctx, conf);
  1494. drv_assign_vif_chanctx(local, sdata, ctx);
  1495. }
  1496. mutex_unlock(&local->chanctx_mtx);
  1497. }
  1498. static void ieee80211_reconfig_stations(struct ieee80211_sub_if_data *sdata)
  1499. {
  1500. struct ieee80211_local *local = sdata->local;
  1501. struct sta_info *sta;
  1502. /* add STAs back */
  1503. mutex_lock(&local->sta_mtx);
  1504. list_for_each_entry(sta, &local->sta_list, list) {
  1505. enum ieee80211_sta_state state;
  1506. if (!sta->uploaded || sta->sdata != sdata)
  1507. continue;
  1508. for (state = IEEE80211_STA_NOTEXIST;
  1509. state < sta->sta_state; state++)
  1510. WARN_ON(drv_sta_state(local, sta->sdata, sta, state,
  1511. state + 1));
  1512. }
  1513. mutex_unlock(&local->sta_mtx);
  1514. }
  1515. static int ieee80211_reconfig_nan(struct ieee80211_sub_if_data *sdata)
  1516. {
  1517. struct cfg80211_nan_func *func, **funcs;
  1518. int res, id, i = 0;
  1519. res = drv_start_nan(sdata->local, sdata,
  1520. &sdata->u.nan.conf);
  1521. if (WARN_ON(res))
  1522. return res;
  1523. funcs = kzalloc((sdata->local->hw.max_nan_de_entries + 1) *
  1524. sizeof(*funcs), GFP_KERNEL);
  1525. if (!funcs)
  1526. return -ENOMEM;
  1527. /* Add all the functions:
  1528. * This is a little bit ugly. We need to call a potentially sleeping
  1529. * callback for each NAN function, so we can't hold the spinlock.
  1530. */
  1531. spin_lock_bh(&sdata->u.nan.func_lock);
  1532. idr_for_each_entry(&sdata->u.nan.function_inst_ids, func, id)
  1533. funcs[i++] = func;
  1534. spin_unlock_bh(&sdata->u.nan.func_lock);
  1535. for (i = 0; funcs[i]; i++) {
  1536. res = drv_add_nan_func(sdata->local, sdata, funcs[i]);
  1537. if (WARN_ON(res))
  1538. ieee80211_nan_func_terminated(&sdata->vif,
  1539. funcs[i]->instance_id,
  1540. NL80211_NAN_FUNC_TERM_REASON_ERROR,
  1541. GFP_KERNEL);
  1542. }
  1543. kfree(funcs);
  1544. return 0;
  1545. }
  1546. int ieee80211_reconfig(struct ieee80211_local *local)
  1547. {
  1548. struct ieee80211_hw *hw = &local->hw;
  1549. struct ieee80211_sub_if_data *sdata;
  1550. struct ieee80211_chanctx *ctx;
  1551. struct sta_info *sta;
  1552. int res, i;
  1553. bool reconfig_due_to_wowlan = false;
  1554. struct ieee80211_sub_if_data *sched_scan_sdata;
  1555. struct cfg80211_sched_scan_request *sched_scan_req;
  1556. bool sched_scan_stopped = false;
  1557. bool suspended = local->suspended;
  1558. /* nothing to do if HW shouldn't run */
  1559. if (!local->open_count)
  1560. goto wake_up;
  1561. #ifdef CONFIG_PM
  1562. if (suspended)
  1563. local->resuming = true;
  1564. if (local->wowlan) {
  1565. /*
  1566. * In the wowlan case, both mac80211 and the device
  1567. * are functional when the resume op is called, so
  1568. * clear local->suspended so the device could operate
  1569. * normally (e.g. pass rx frames).
  1570. */
  1571. local->suspended = false;
  1572. res = drv_resume(local);
  1573. local->wowlan = false;
  1574. if (res < 0) {
  1575. local->resuming = false;
  1576. return res;
  1577. }
  1578. if (res == 0)
  1579. goto wake_up;
  1580. WARN_ON(res > 1);
  1581. /*
  1582. * res is 1, which means the driver requested
  1583. * to go through a regular reset on wakeup.
  1584. * restore local->suspended in this case.
  1585. */
  1586. reconfig_due_to_wowlan = true;
  1587. local->suspended = true;
  1588. }
  1589. #endif
  1590. /*
  1591. * In case of hw_restart during suspend (without wowlan),
  1592. * cancel restart work, as we are reconfiguring the device
  1593. * anyway.
  1594. * Note that restart_work is scheduled on a frozen workqueue,
  1595. * so we can't deadlock in this case.
  1596. */
  1597. if (suspended && local->in_reconfig && !reconfig_due_to_wowlan)
  1598. cancel_work_sync(&local->restart_work);
  1599. local->started = false;
  1600. /*
  1601. * Upon resume hardware can sometimes be goofy due to
  1602. * various platform / driver / bus issues, so restarting
  1603. * the device may at times not work immediately. Propagate
  1604. * the error.
  1605. */
  1606. res = drv_start(local);
  1607. if (res) {
  1608. if (suspended)
  1609. WARN(1, "Hardware became unavailable upon resume. This could be a software issue prior to suspend or a hardware issue.\n");
  1610. else
  1611. WARN(1, "Hardware became unavailable during restart.\n");
  1612. ieee80211_handle_reconfig_failure(local);
  1613. return res;
  1614. }
  1615. /* setup fragmentation threshold */
  1616. drv_set_frag_threshold(local, hw->wiphy->frag_threshold);
  1617. /* setup RTS threshold */
  1618. drv_set_rts_threshold(local, hw->wiphy->rts_threshold);
  1619. /* reset coverage class */
  1620. drv_set_coverage_class(local, hw->wiphy->coverage_class);
  1621. ieee80211_led_radio(local, true);
  1622. ieee80211_mod_tpt_led_trig(local,
  1623. IEEE80211_TPT_LEDTRIG_FL_RADIO, 0);
  1624. /* add interfaces */
  1625. sdata = rtnl_dereference(local->monitor_sdata);
  1626. if (sdata) {
  1627. /* in HW restart it exists already */
  1628. WARN_ON(local->resuming);
  1629. res = drv_add_interface(local, sdata);
  1630. if (WARN_ON(res)) {
  1631. RCU_INIT_POINTER(local->monitor_sdata, NULL);
  1632. synchronize_net();
  1633. kfree(sdata);
  1634. }
  1635. }
  1636. list_for_each_entry(sdata, &local->interfaces, list) {
  1637. if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
  1638. sdata->vif.type != NL80211_IFTYPE_MONITOR &&
  1639. ieee80211_sdata_running(sdata)) {
  1640. res = drv_add_interface(local, sdata);
  1641. if (WARN_ON(res))
  1642. break;
  1643. }
  1644. }
  1645. /* If adding any of the interfaces failed above, roll back and
  1646. * report failure.
  1647. */
  1648. if (res) {
  1649. list_for_each_entry_continue_reverse(sdata, &local->interfaces,
  1650. list)
  1651. if (sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
  1652. sdata->vif.type != NL80211_IFTYPE_MONITOR &&
  1653. ieee80211_sdata_running(sdata))
  1654. drv_remove_interface(local, sdata);
  1655. ieee80211_handle_reconfig_failure(local);
  1656. return res;
  1657. }
  1658. /* add channel contexts */
  1659. if (local->use_chanctx) {
  1660. mutex_lock(&local->chanctx_mtx);
  1661. list_for_each_entry(ctx, &local->chanctx_list, list)
  1662. if (ctx->replace_state !=
  1663. IEEE80211_CHANCTX_REPLACES_OTHER)
  1664. WARN_ON(drv_add_chanctx(local, ctx));
  1665. mutex_unlock(&local->chanctx_mtx);
  1666. sdata = rtnl_dereference(local->monitor_sdata);
  1667. if (sdata && ieee80211_sdata_running(sdata))
  1668. ieee80211_assign_chanctx(local, sdata);
  1669. }
  1670. /* reconfigure hardware */
  1671. ieee80211_hw_config(local, ~0);
  1672. ieee80211_configure_filter(local);
  1673. /* Finally also reconfigure all the BSS information */
  1674. list_for_each_entry(sdata, &local->interfaces, list) {
  1675. u32 changed;
  1676. if (!ieee80211_sdata_running(sdata))
  1677. continue;
  1678. ieee80211_assign_chanctx(local, sdata);
  1679. switch (sdata->vif.type) {
  1680. case NL80211_IFTYPE_AP_VLAN:
  1681. case NL80211_IFTYPE_MONITOR:
  1682. break;
  1683. default:
  1684. ieee80211_reconfig_stations(sdata);
  1685. /* fall through */
  1686. case NL80211_IFTYPE_AP: /* AP stations are handled later */
  1687. for (i = 0; i < IEEE80211_NUM_ACS; i++)
  1688. drv_conf_tx(local, sdata, i,
  1689. &sdata->tx_conf[i]);
  1690. break;
  1691. }
  1692. /* common change flags for all interface types */
  1693. changed = BSS_CHANGED_ERP_CTS_PROT |
  1694. BSS_CHANGED_ERP_PREAMBLE |
  1695. BSS_CHANGED_ERP_SLOT |
  1696. BSS_CHANGED_HT |
  1697. BSS_CHANGED_BASIC_RATES |
  1698. BSS_CHANGED_BEACON_INT |
  1699. BSS_CHANGED_BSSID |
  1700. BSS_CHANGED_CQM |
  1701. BSS_CHANGED_QOS |
  1702. BSS_CHANGED_IDLE |
  1703. BSS_CHANGED_TXPOWER;
  1704. if (sdata->vif.mu_mimo_owner)
  1705. changed |= BSS_CHANGED_MU_GROUPS;
  1706. switch (sdata->vif.type) {
  1707. case NL80211_IFTYPE_STATION:
  1708. changed |= BSS_CHANGED_ASSOC |
  1709. BSS_CHANGED_ARP_FILTER |
  1710. BSS_CHANGED_PS;
  1711. /* Re-send beacon info report to the driver */
  1712. if (sdata->u.mgd.have_beacon)
  1713. changed |= BSS_CHANGED_BEACON_INFO;
  1714. sdata_lock(sdata);
  1715. ieee80211_bss_info_change_notify(sdata, changed);
  1716. sdata_unlock(sdata);
  1717. break;
  1718. case NL80211_IFTYPE_OCB:
  1719. changed |= BSS_CHANGED_OCB;
  1720. ieee80211_bss_info_change_notify(sdata, changed);
  1721. break;
  1722. case NL80211_IFTYPE_ADHOC:
  1723. changed |= BSS_CHANGED_IBSS;
  1724. /* fall through */
  1725. case NL80211_IFTYPE_AP:
  1726. changed |= BSS_CHANGED_SSID | BSS_CHANGED_P2P_PS;
  1727. if (sdata->vif.type == NL80211_IFTYPE_AP) {
  1728. changed |= BSS_CHANGED_AP_PROBE_RESP;
  1729. if (rcu_access_pointer(sdata->u.ap.beacon))
  1730. drv_start_ap(local, sdata);
  1731. }
  1732. /* fall through */
  1733. case NL80211_IFTYPE_MESH_POINT:
  1734. if (sdata->vif.bss_conf.enable_beacon) {
  1735. changed |= BSS_CHANGED_BEACON |
  1736. BSS_CHANGED_BEACON_ENABLED;
  1737. ieee80211_bss_info_change_notify(sdata, changed);
  1738. }
  1739. break;
  1740. case NL80211_IFTYPE_NAN:
  1741. res = ieee80211_reconfig_nan(sdata);
  1742. if (res < 0) {
  1743. ieee80211_handle_reconfig_failure(local);
  1744. return res;
  1745. }
  1746. break;
  1747. case NL80211_IFTYPE_WDS:
  1748. case NL80211_IFTYPE_AP_VLAN:
  1749. case NL80211_IFTYPE_MONITOR:
  1750. case NL80211_IFTYPE_P2P_DEVICE:
  1751. /* nothing to do */
  1752. break;
  1753. case NL80211_IFTYPE_UNSPECIFIED:
  1754. case NUM_NL80211_IFTYPES:
  1755. case NL80211_IFTYPE_P2P_CLIENT:
  1756. case NL80211_IFTYPE_P2P_GO:
  1757. WARN_ON(1);
  1758. break;
  1759. }
  1760. }
  1761. ieee80211_recalc_ps(local);
  1762. /*
  1763. * The sta might be in psm against the ap (e.g. because
  1764. * this was the state before a hw restart), so we
  1765. * explicitly send a null packet in order to make sure
  1766. * it'll sync against the ap (and get out of psm).
  1767. */
  1768. if (!(local->hw.conf.flags & IEEE80211_CONF_PS)) {
  1769. list_for_each_entry(sdata, &local->interfaces, list) {
  1770. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  1771. continue;
  1772. if (!sdata->u.mgd.associated)
  1773. continue;
  1774. ieee80211_send_nullfunc(local, sdata, false);
  1775. }
  1776. }
  1777. /* APs are now beaconing, add back stations */
  1778. mutex_lock(&local->sta_mtx);
  1779. list_for_each_entry(sta, &local->sta_list, list) {
  1780. enum ieee80211_sta_state state;
  1781. if (!sta->uploaded)
  1782. continue;
  1783. if (sta->sdata->vif.type != NL80211_IFTYPE_AP)
  1784. continue;
  1785. for (state = IEEE80211_STA_NOTEXIST;
  1786. state < sta->sta_state; state++)
  1787. WARN_ON(drv_sta_state(local, sta->sdata, sta, state,
  1788. state + 1));
  1789. }
  1790. mutex_unlock(&local->sta_mtx);
  1791. /* add back keys */
  1792. list_for_each_entry(sdata, &local->interfaces, list)
  1793. ieee80211_reset_crypto_tx_tailroom(sdata);
  1794. list_for_each_entry(sdata, &local->interfaces, list)
  1795. if (ieee80211_sdata_running(sdata))
  1796. ieee80211_enable_keys(sdata);
  1797. /* Reconfigure sched scan if it was interrupted by FW restart */
  1798. mutex_lock(&local->mtx);
  1799. sched_scan_sdata = rcu_dereference_protected(local->sched_scan_sdata,
  1800. lockdep_is_held(&local->mtx));
  1801. sched_scan_req = rcu_dereference_protected(local->sched_scan_req,
  1802. lockdep_is_held(&local->mtx));
  1803. if (sched_scan_sdata && sched_scan_req)
  1804. /*
  1805. * Sched scan stopped, but we don't want to report it. Instead,
  1806. * we're trying to reschedule. However, if more than one scan
  1807. * plan was set, we cannot reschedule since we don't know which
  1808. * scan plan was currently running (and some scan plans may have
  1809. * already finished).
  1810. */
  1811. if (sched_scan_req->n_scan_plans > 1 ||
  1812. __ieee80211_request_sched_scan_start(sched_scan_sdata,
  1813. sched_scan_req)) {
  1814. RCU_INIT_POINTER(local->sched_scan_sdata, NULL);
  1815. RCU_INIT_POINTER(local->sched_scan_req, NULL);
  1816. sched_scan_stopped = true;
  1817. }
  1818. mutex_unlock(&local->mtx);
  1819. if (sched_scan_stopped)
  1820. cfg80211_sched_scan_stopped_rtnl(local->hw.wiphy);
  1821. wake_up:
  1822. if (local->in_reconfig) {
  1823. local->in_reconfig = false;
  1824. barrier();
  1825. /* Restart deferred ROCs */
  1826. mutex_lock(&local->mtx);
  1827. ieee80211_start_next_roc(local);
  1828. mutex_unlock(&local->mtx);
  1829. }
  1830. if (local->monitors == local->open_count && local->monitors > 0)
  1831. ieee80211_add_virtual_monitor(local);
  1832. /*
  1833. * Clear the WLAN_STA_BLOCK_BA flag so new aggregation
  1834. * sessions can be established after a resume.
  1835. *
  1836. * Also tear down aggregation sessions since reconfiguring
  1837. * them in a hardware restart scenario is not easily done
  1838. * right now, and the hardware will have lost information
  1839. * about the sessions, but we and the AP still think they
  1840. * are active. This is really a workaround though.
  1841. */
  1842. if (ieee80211_hw_check(hw, AMPDU_AGGREGATION)) {
  1843. mutex_lock(&local->sta_mtx);
  1844. list_for_each_entry(sta, &local->sta_list, list) {
  1845. if (!local->resuming)
  1846. ieee80211_sta_tear_down_BA_sessions(
  1847. sta, AGG_STOP_LOCAL_REQUEST);
  1848. clear_sta_flag(sta, WLAN_STA_BLOCK_BA);
  1849. }
  1850. mutex_unlock(&local->sta_mtx);
  1851. }
  1852. ieee80211_wake_queues_by_reason(hw, IEEE80211_MAX_QUEUE_MAP,
  1853. IEEE80211_QUEUE_STOP_REASON_SUSPEND,
  1854. false);
  1855. /*
  1856. * If this is for hw restart things are still running.
  1857. * We may want to change that later, however.
  1858. */
  1859. if (local->open_count && (!suspended || reconfig_due_to_wowlan))
  1860. drv_reconfig_complete(local, IEEE80211_RECONFIG_TYPE_RESTART);
  1861. if (!suspended)
  1862. return 0;
  1863. #ifdef CONFIG_PM
  1864. /* first set suspended false, then resuming */
  1865. local->suspended = false;
  1866. mb();
  1867. local->resuming = false;
  1868. ieee80211_flush_completed_scan(local, false);
  1869. if (local->open_count && !reconfig_due_to_wowlan)
  1870. drv_reconfig_complete(local, IEEE80211_RECONFIG_TYPE_SUSPEND);
  1871. list_for_each_entry(sdata, &local->interfaces, list) {
  1872. if (!ieee80211_sdata_running(sdata))
  1873. continue;
  1874. if (sdata->vif.type == NL80211_IFTYPE_STATION)
  1875. ieee80211_sta_restart(sdata);
  1876. }
  1877. mod_timer(&local->sta_cleanup, jiffies + 1);
  1878. #else
  1879. WARN_ON(1);
  1880. #endif
  1881. return 0;
  1882. }
  1883. void ieee80211_resume_disconnect(struct ieee80211_vif *vif)
  1884. {
  1885. struct ieee80211_sub_if_data *sdata;
  1886. struct ieee80211_local *local;
  1887. struct ieee80211_key *key;
  1888. if (WARN_ON(!vif))
  1889. return;
  1890. sdata = vif_to_sdata(vif);
  1891. local = sdata->local;
  1892. if (WARN_ON(!local->resuming))
  1893. return;
  1894. if (WARN_ON(vif->type != NL80211_IFTYPE_STATION))
  1895. return;
  1896. sdata->flags |= IEEE80211_SDATA_DISCONNECT_RESUME;
  1897. mutex_lock(&local->key_mtx);
  1898. list_for_each_entry(key, &sdata->key_list, list)
  1899. key->flags |= KEY_FLAG_TAINTED;
  1900. mutex_unlock(&local->key_mtx);
  1901. }
  1902. EXPORT_SYMBOL_GPL(ieee80211_resume_disconnect);
  1903. void ieee80211_recalc_smps(struct ieee80211_sub_if_data *sdata)
  1904. {
  1905. struct ieee80211_local *local = sdata->local;
  1906. struct ieee80211_chanctx_conf *chanctx_conf;
  1907. struct ieee80211_chanctx *chanctx;
  1908. mutex_lock(&local->chanctx_mtx);
  1909. chanctx_conf = rcu_dereference_protected(sdata->vif.chanctx_conf,
  1910. lockdep_is_held(&local->chanctx_mtx));
  1911. /*
  1912. * This function can be called from a work, thus it may be possible
  1913. * that the chanctx_conf is removed (due to a disconnection, for
  1914. * example).
  1915. * So nothing should be done in such case.
  1916. */
  1917. if (!chanctx_conf)
  1918. goto unlock;
  1919. chanctx = container_of(chanctx_conf, struct ieee80211_chanctx, conf);
  1920. ieee80211_recalc_smps_chanctx(local, chanctx);
  1921. unlock:
  1922. mutex_unlock(&local->chanctx_mtx);
  1923. }
  1924. void ieee80211_recalc_min_chandef(struct ieee80211_sub_if_data *sdata)
  1925. {
  1926. struct ieee80211_local *local = sdata->local;
  1927. struct ieee80211_chanctx_conf *chanctx_conf;
  1928. struct ieee80211_chanctx *chanctx;
  1929. mutex_lock(&local->chanctx_mtx);
  1930. chanctx_conf = rcu_dereference_protected(sdata->vif.chanctx_conf,
  1931. lockdep_is_held(&local->chanctx_mtx));
  1932. if (WARN_ON_ONCE(!chanctx_conf))
  1933. goto unlock;
  1934. chanctx = container_of(chanctx_conf, struct ieee80211_chanctx, conf);
  1935. ieee80211_recalc_chanctx_min_def(local, chanctx);
  1936. unlock:
  1937. mutex_unlock(&local->chanctx_mtx);
  1938. }
  1939. size_t ieee80211_ie_split_vendor(const u8 *ies, size_t ielen, size_t offset)
  1940. {
  1941. size_t pos = offset;
  1942. while (pos < ielen && ies[pos] != WLAN_EID_VENDOR_SPECIFIC)
  1943. pos += 2 + ies[pos + 1];
  1944. return pos;
  1945. }
  1946. static void _ieee80211_enable_rssi_reports(struct ieee80211_sub_if_data *sdata,
  1947. int rssi_min_thold,
  1948. int rssi_max_thold)
  1949. {
  1950. trace_api_enable_rssi_reports(sdata, rssi_min_thold, rssi_max_thold);
  1951. if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
  1952. return;
  1953. /*
  1954. * Scale up threshold values before storing it, as the RSSI averaging
  1955. * algorithm uses a scaled up value as well. Change this scaling
  1956. * factor if the RSSI averaging algorithm changes.
  1957. */
  1958. sdata->u.mgd.rssi_min_thold = rssi_min_thold*16;
  1959. sdata->u.mgd.rssi_max_thold = rssi_max_thold*16;
  1960. }
  1961. void ieee80211_enable_rssi_reports(struct ieee80211_vif *vif,
  1962. int rssi_min_thold,
  1963. int rssi_max_thold)
  1964. {
  1965. struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
  1966. WARN_ON(rssi_min_thold == rssi_max_thold ||
  1967. rssi_min_thold > rssi_max_thold);
  1968. _ieee80211_enable_rssi_reports(sdata, rssi_min_thold,
  1969. rssi_max_thold);
  1970. }
  1971. EXPORT_SYMBOL(ieee80211_enable_rssi_reports);
  1972. void ieee80211_disable_rssi_reports(struct ieee80211_vif *vif)
  1973. {
  1974. struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
  1975. _ieee80211_enable_rssi_reports(sdata, 0, 0);
  1976. }
  1977. EXPORT_SYMBOL(ieee80211_disable_rssi_reports);
  1978. u8 *ieee80211_ie_build_ht_cap(u8 *pos, struct ieee80211_sta_ht_cap *ht_cap,
  1979. u16 cap)
  1980. {
  1981. __le16 tmp;
  1982. *pos++ = WLAN_EID_HT_CAPABILITY;
  1983. *pos++ = sizeof(struct ieee80211_ht_cap);
  1984. memset(pos, 0, sizeof(struct ieee80211_ht_cap));
  1985. /* capability flags */
  1986. tmp = cpu_to_le16(cap);
  1987. memcpy(pos, &tmp, sizeof(u16));
  1988. pos += sizeof(u16);
  1989. /* AMPDU parameters */
  1990. *pos++ = ht_cap->ampdu_factor |
  1991. (ht_cap->ampdu_density <<
  1992. IEEE80211_HT_AMPDU_PARM_DENSITY_SHIFT);
  1993. /* MCS set */
  1994. memcpy(pos, &ht_cap->mcs, sizeof(ht_cap->mcs));
  1995. pos += sizeof(ht_cap->mcs);
  1996. /* extended capabilities */
  1997. pos += sizeof(__le16);
  1998. /* BF capabilities */
  1999. pos += sizeof(__le32);
  2000. /* antenna selection */
  2001. pos += sizeof(u8);
  2002. return pos;
  2003. }
  2004. u8 *ieee80211_ie_build_vht_cap(u8 *pos, struct ieee80211_sta_vht_cap *vht_cap,
  2005. u32 cap)
  2006. {
  2007. __le32 tmp;
  2008. *pos++ = WLAN_EID_VHT_CAPABILITY;
  2009. *pos++ = sizeof(struct ieee80211_vht_cap);
  2010. memset(pos, 0, sizeof(struct ieee80211_vht_cap));
  2011. /* capability flags */
  2012. tmp = cpu_to_le32(cap);
  2013. memcpy(pos, &tmp, sizeof(u32));
  2014. pos += sizeof(u32);
  2015. /* VHT MCS set */
  2016. memcpy(pos, &vht_cap->vht_mcs, sizeof(vht_cap->vht_mcs));
  2017. pos += sizeof(vht_cap->vht_mcs);
  2018. return pos;
  2019. }
  2020. u8 *ieee80211_ie_build_ht_oper(u8 *pos, struct ieee80211_sta_ht_cap *ht_cap,
  2021. const struct cfg80211_chan_def *chandef,
  2022. u16 prot_mode, bool rifs_mode)
  2023. {
  2024. struct ieee80211_ht_operation *ht_oper;
  2025. /* Build HT Information */
  2026. *pos++ = WLAN_EID_HT_OPERATION;
  2027. *pos++ = sizeof(struct ieee80211_ht_operation);
  2028. ht_oper = (struct ieee80211_ht_operation *)pos;
  2029. ht_oper->primary_chan = ieee80211_frequency_to_channel(
  2030. chandef->chan->center_freq);
  2031. switch (chandef->width) {
  2032. case NL80211_CHAN_WIDTH_160:
  2033. case NL80211_CHAN_WIDTH_80P80:
  2034. case NL80211_CHAN_WIDTH_80:
  2035. case NL80211_CHAN_WIDTH_40:
  2036. if (chandef->center_freq1 > chandef->chan->center_freq)
  2037. ht_oper->ht_param = IEEE80211_HT_PARAM_CHA_SEC_ABOVE;
  2038. else
  2039. ht_oper->ht_param = IEEE80211_HT_PARAM_CHA_SEC_BELOW;
  2040. break;
  2041. default:
  2042. ht_oper->ht_param = IEEE80211_HT_PARAM_CHA_SEC_NONE;
  2043. break;
  2044. }
  2045. if (ht_cap->cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40 &&
  2046. chandef->width != NL80211_CHAN_WIDTH_20_NOHT &&
  2047. chandef->width != NL80211_CHAN_WIDTH_20)
  2048. ht_oper->ht_param |= IEEE80211_HT_PARAM_CHAN_WIDTH_ANY;
  2049. if (rifs_mode)
  2050. ht_oper->ht_param |= IEEE80211_HT_PARAM_RIFS_MODE;
  2051. ht_oper->operation_mode = cpu_to_le16(prot_mode);
  2052. ht_oper->stbc_param = 0x0000;
  2053. /* It seems that Basic MCS set and Supported MCS set
  2054. are identical for the first 10 bytes */
  2055. memset(&ht_oper->basic_set, 0, 16);
  2056. memcpy(&ht_oper->basic_set, &ht_cap->mcs, 10);
  2057. return pos + sizeof(struct ieee80211_ht_operation);
  2058. }
  2059. u8 *ieee80211_ie_build_vht_oper(u8 *pos, struct ieee80211_sta_vht_cap *vht_cap,
  2060. const struct cfg80211_chan_def *chandef)
  2061. {
  2062. struct ieee80211_vht_operation *vht_oper;
  2063. *pos++ = WLAN_EID_VHT_OPERATION;
  2064. *pos++ = sizeof(struct ieee80211_vht_operation);
  2065. vht_oper = (struct ieee80211_vht_operation *)pos;
  2066. vht_oper->center_freq_seg1_idx = ieee80211_frequency_to_channel(
  2067. chandef->center_freq1);
  2068. if (chandef->center_freq2)
  2069. vht_oper->center_freq_seg2_idx =
  2070. ieee80211_frequency_to_channel(chandef->center_freq2);
  2071. else
  2072. vht_oper->center_freq_seg2_idx = 0x00;
  2073. switch (chandef->width) {
  2074. case NL80211_CHAN_WIDTH_160:
  2075. /*
  2076. * Convert 160 MHz channel width to new style as interop
  2077. * workaround.
  2078. */
  2079. vht_oper->chan_width = IEEE80211_VHT_CHANWIDTH_80MHZ;
  2080. vht_oper->center_freq_seg2_idx = vht_oper->center_freq_seg1_idx;
  2081. if (chandef->chan->center_freq < chandef->center_freq1)
  2082. vht_oper->center_freq_seg1_idx -= 8;
  2083. else
  2084. vht_oper->center_freq_seg1_idx += 8;
  2085. break;
  2086. case NL80211_CHAN_WIDTH_80P80:
  2087. /*
  2088. * Convert 80+80 MHz channel width to new style as interop
  2089. * workaround.
  2090. */
  2091. vht_oper->chan_width = IEEE80211_VHT_CHANWIDTH_80MHZ;
  2092. break;
  2093. case NL80211_CHAN_WIDTH_80:
  2094. vht_oper->chan_width = IEEE80211_VHT_CHANWIDTH_80MHZ;
  2095. break;
  2096. default:
  2097. vht_oper->chan_width = IEEE80211_VHT_CHANWIDTH_USE_HT;
  2098. break;
  2099. }
  2100. /* don't require special VHT peer rates */
  2101. vht_oper->basic_mcs_set = cpu_to_le16(0xffff);
  2102. return pos + sizeof(struct ieee80211_vht_operation);
  2103. }
  2104. bool ieee80211_chandef_ht_oper(const struct ieee80211_ht_operation *ht_oper,
  2105. struct cfg80211_chan_def *chandef)
  2106. {
  2107. enum nl80211_channel_type channel_type;
  2108. if (!ht_oper)
  2109. return false;
  2110. switch (ht_oper->ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET) {
  2111. case IEEE80211_HT_PARAM_CHA_SEC_NONE:
  2112. channel_type = NL80211_CHAN_HT20;
  2113. break;
  2114. case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
  2115. channel_type = NL80211_CHAN_HT40PLUS;
  2116. break;
  2117. case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
  2118. channel_type = NL80211_CHAN_HT40MINUS;
  2119. break;
  2120. default:
  2121. channel_type = NL80211_CHAN_NO_HT;
  2122. return false;
  2123. }
  2124. cfg80211_chandef_create(chandef, chandef->chan, channel_type);
  2125. return true;
  2126. }
  2127. bool ieee80211_chandef_vht_oper(const struct ieee80211_vht_operation *oper,
  2128. struct cfg80211_chan_def *chandef)
  2129. {
  2130. struct cfg80211_chan_def new = *chandef;
  2131. int cf1, cf2;
  2132. if (!oper)
  2133. return false;
  2134. cf1 = ieee80211_channel_to_frequency(oper->center_freq_seg1_idx,
  2135. chandef->chan->band);
  2136. cf2 = ieee80211_channel_to_frequency(oper->center_freq_seg2_idx,
  2137. chandef->chan->band);
  2138. switch (oper->chan_width) {
  2139. case IEEE80211_VHT_CHANWIDTH_USE_HT:
  2140. break;
  2141. case IEEE80211_VHT_CHANWIDTH_80MHZ:
  2142. new.width = NL80211_CHAN_WIDTH_80;
  2143. new.center_freq1 = cf1;
  2144. /* If needed, adjust based on the newer interop workaround. */
  2145. if (oper->center_freq_seg2_idx) {
  2146. unsigned int diff;
  2147. diff = abs(oper->center_freq_seg2_idx -
  2148. oper->center_freq_seg1_idx);
  2149. if (diff == 8) {
  2150. new.width = NL80211_CHAN_WIDTH_160;
  2151. new.center_freq1 = cf2;
  2152. } else if (diff > 8) {
  2153. new.width = NL80211_CHAN_WIDTH_80P80;
  2154. new.center_freq2 = cf2;
  2155. }
  2156. }
  2157. break;
  2158. case IEEE80211_VHT_CHANWIDTH_160MHZ:
  2159. new.width = NL80211_CHAN_WIDTH_160;
  2160. new.center_freq1 = cf1;
  2161. break;
  2162. case IEEE80211_VHT_CHANWIDTH_80P80MHZ:
  2163. new.width = NL80211_CHAN_WIDTH_80P80;
  2164. new.center_freq1 = cf1;
  2165. new.center_freq2 = cf2;
  2166. break;
  2167. default:
  2168. return false;
  2169. }
  2170. if (!cfg80211_chandef_valid(&new))
  2171. return false;
  2172. *chandef = new;
  2173. return true;
  2174. }
  2175. int ieee80211_parse_bitrates(struct cfg80211_chan_def *chandef,
  2176. const struct ieee80211_supported_band *sband,
  2177. const u8 *srates, int srates_len, u32 *rates)
  2178. {
  2179. u32 rate_flags = ieee80211_chandef_rate_flags(chandef);
  2180. int shift = ieee80211_chandef_get_shift(chandef);
  2181. struct ieee80211_rate *br;
  2182. int brate, rate, i, j, count = 0;
  2183. *rates = 0;
  2184. for (i = 0; i < srates_len; i++) {
  2185. rate = srates[i] & 0x7f;
  2186. for (j = 0; j < sband->n_bitrates; j++) {
  2187. br = &sband->bitrates[j];
  2188. if ((rate_flags & br->flags) != rate_flags)
  2189. continue;
  2190. brate = DIV_ROUND_UP(br->bitrate, (1 << shift) * 5);
  2191. if (brate == rate) {
  2192. *rates |= BIT(j);
  2193. count++;
  2194. break;
  2195. }
  2196. }
  2197. }
  2198. return count;
  2199. }
  2200. int ieee80211_add_srates_ie(struct ieee80211_sub_if_data *sdata,
  2201. struct sk_buff *skb, bool need_basic,
  2202. enum nl80211_band band)
  2203. {
  2204. struct ieee80211_local *local = sdata->local;
  2205. struct ieee80211_supported_band *sband;
  2206. int rate, shift;
  2207. u8 i, rates, *pos;
  2208. u32 basic_rates = sdata->vif.bss_conf.basic_rates;
  2209. u32 rate_flags;
  2210. shift = ieee80211_vif_get_shift(&sdata->vif);
  2211. rate_flags = ieee80211_chandef_rate_flags(&sdata->vif.bss_conf.chandef);
  2212. sband = local->hw.wiphy->bands[band];
  2213. rates = 0;
  2214. for (i = 0; i < sband->n_bitrates; i++) {
  2215. if ((rate_flags & sband->bitrates[i].flags) != rate_flags)
  2216. continue;
  2217. rates++;
  2218. }
  2219. if (rates > 8)
  2220. rates = 8;
  2221. if (skb_tailroom(skb) < rates + 2)
  2222. return -ENOMEM;
  2223. pos = skb_put(skb, rates + 2);
  2224. *pos++ = WLAN_EID_SUPP_RATES;
  2225. *pos++ = rates;
  2226. for (i = 0; i < rates; i++) {
  2227. u8 basic = 0;
  2228. if ((rate_flags & sband->bitrates[i].flags) != rate_flags)
  2229. continue;
  2230. if (need_basic && basic_rates & BIT(i))
  2231. basic = 0x80;
  2232. rate = DIV_ROUND_UP(sband->bitrates[i].bitrate,
  2233. 5 * (1 << shift));
  2234. *pos++ = basic | (u8) rate;
  2235. }
  2236. return 0;
  2237. }
  2238. int ieee80211_add_ext_srates_ie(struct ieee80211_sub_if_data *sdata,
  2239. struct sk_buff *skb, bool need_basic,
  2240. enum nl80211_band band)
  2241. {
  2242. struct ieee80211_local *local = sdata->local;
  2243. struct ieee80211_supported_band *sband;
  2244. int rate, shift;
  2245. u8 i, exrates, *pos;
  2246. u32 basic_rates = sdata->vif.bss_conf.basic_rates;
  2247. u32 rate_flags;
  2248. rate_flags = ieee80211_chandef_rate_flags(&sdata->vif.bss_conf.chandef);
  2249. shift = ieee80211_vif_get_shift(&sdata->vif);
  2250. sband = local->hw.wiphy->bands[band];
  2251. exrates = 0;
  2252. for (i = 0; i < sband->n_bitrates; i++) {
  2253. if ((rate_flags & sband->bitrates[i].flags) != rate_flags)
  2254. continue;
  2255. exrates++;
  2256. }
  2257. if (exrates > 8)
  2258. exrates -= 8;
  2259. else
  2260. exrates = 0;
  2261. if (skb_tailroom(skb) < exrates + 2)
  2262. return -ENOMEM;
  2263. if (exrates) {
  2264. pos = skb_put(skb, exrates + 2);
  2265. *pos++ = WLAN_EID_EXT_SUPP_RATES;
  2266. *pos++ = exrates;
  2267. for (i = 8; i < sband->n_bitrates; i++) {
  2268. u8 basic = 0;
  2269. if ((rate_flags & sband->bitrates[i].flags)
  2270. != rate_flags)
  2271. continue;
  2272. if (need_basic && basic_rates & BIT(i))
  2273. basic = 0x80;
  2274. rate = DIV_ROUND_UP(sband->bitrates[i].bitrate,
  2275. 5 * (1 << shift));
  2276. *pos++ = basic | (u8) rate;
  2277. }
  2278. }
  2279. return 0;
  2280. }
  2281. int ieee80211_ave_rssi(struct ieee80211_vif *vif)
  2282. {
  2283. struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
  2284. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  2285. if (WARN_ON_ONCE(sdata->vif.type != NL80211_IFTYPE_STATION)) {
  2286. /* non-managed type inferfaces */
  2287. return 0;
  2288. }
  2289. return -ewma_beacon_signal_read(&ifmgd->ave_beacon_signal);
  2290. }
  2291. EXPORT_SYMBOL_GPL(ieee80211_ave_rssi);
  2292. u8 ieee80211_mcs_to_chains(const struct ieee80211_mcs_info *mcs)
  2293. {
  2294. if (!mcs)
  2295. return 1;
  2296. /* TODO: consider rx_highest */
  2297. if (mcs->rx_mask[3])
  2298. return 4;
  2299. if (mcs->rx_mask[2])
  2300. return 3;
  2301. if (mcs->rx_mask[1])
  2302. return 2;
  2303. return 1;
  2304. }
  2305. /**
  2306. * ieee80211_calculate_rx_timestamp - calculate timestamp in frame
  2307. * @local: mac80211 hw info struct
  2308. * @status: RX status
  2309. * @mpdu_len: total MPDU length (including FCS)
  2310. * @mpdu_offset: offset into MPDU to calculate timestamp at
  2311. *
  2312. * This function calculates the RX timestamp at the given MPDU offset, taking
  2313. * into account what the RX timestamp was. An offset of 0 will just normalize
  2314. * the timestamp to TSF at beginning of MPDU reception.
  2315. */
  2316. u64 ieee80211_calculate_rx_timestamp(struct ieee80211_local *local,
  2317. struct ieee80211_rx_status *status,
  2318. unsigned int mpdu_len,
  2319. unsigned int mpdu_offset)
  2320. {
  2321. u64 ts = status->mactime;
  2322. struct rate_info ri;
  2323. u16 rate;
  2324. if (WARN_ON(!ieee80211_have_rx_timestamp(status)))
  2325. return 0;
  2326. memset(&ri, 0, sizeof(ri));
  2327. /* Fill cfg80211 rate info */
  2328. if (status->flag & RX_FLAG_HT) {
  2329. ri.mcs = status->rate_idx;
  2330. ri.flags |= RATE_INFO_FLAGS_MCS;
  2331. if (status->flag & RX_FLAG_40MHZ)
  2332. ri.bw = RATE_INFO_BW_40;
  2333. else
  2334. ri.bw = RATE_INFO_BW_20;
  2335. if (status->flag & RX_FLAG_SHORT_GI)
  2336. ri.flags |= RATE_INFO_FLAGS_SHORT_GI;
  2337. } else if (status->flag & RX_FLAG_VHT) {
  2338. ri.flags |= RATE_INFO_FLAGS_VHT_MCS;
  2339. ri.mcs = status->rate_idx;
  2340. ri.nss = status->vht_nss;
  2341. if (status->flag & RX_FLAG_40MHZ)
  2342. ri.bw = RATE_INFO_BW_40;
  2343. else if (status->vht_flag & RX_VHT_FLAG_80MHZ)
  2344. ri.bw = RATE_INFO_BW_80;
  2345. else if (status->vht_flag & RX_VHT_FLAG_160MHZ)
  2346. ri.bw = RATE_INFO_BW_160;
  2347. else
  2348. ri.bw = RATE_INFO_BW_20;
  2349. if (status->flag & RX_FLAG_SHORT_GI)
  2350. ri.flags |= RATE_INFO_FLAGS_SHORT_GI;
  2351. } else {
  2352. struct ieee80211_supported_band *sband;
  2353. int shift = 0;
  2354. int bitrate;
  2355. if (status->flag & RX_FLAG_10MHZ) {
  2356. shift = 1;
  2357. ri.bw = RATE_INFO_BW_10;
  2358. } else if (status->flag & RX_FLAG_5MHZ) {
  2359. shift = 2;
  2360. ri.bw = RATE_INFO_BW_5;
  2361. } else {
  2362. ri.bw = RATE_INFO_BW_20;
  2363. }
  2364. sband = local->hw.wiphy->bands[status->band];
  2365. bitrate = sband->bitrates[status->rate_idx].bitrate;
  2366. ri.legacy = DIV_ROUND_UP(bitrate, (1 << shift));
  2367. if (status->flag & RX_FLAG_MACTIME_PLCP_START) {
  2368. /* TODO: handle HT/VHT preambles */
  2369. if (status->band == NL80211_BAND_5GHZ) {
  2370. ts += 20 << shift;
  2371. mpdu_offset += 2;
  2372. } else if (status->flag & RX_FLAG_SHORTPRE) {
  2373. ts += 96;
  2374. } else {
  2375. ts += 192;
  2376. }
  2377. }
  2378. }
  2379. rate = cfg80211_calculate_bitrate(&ri);
  2380. if (WARN_ONCE(!rate,
  2381. "Invalid bitrate: flags=0x%llx, idx=%d, vht_nss=%d\n",
  2382. (unsigned long long)status->flag, status->rate_idx,
  2383. status->vht_nss))
  2384. return 0;
  2385. /* rewind from end of MPDU */
  2386. if (status->flag & RX_FLAG_MACTIME_END)
  2387. ts -= mpdu_len * 8 * 10 / rate;
  2388. ts += mpdu_offset * 8 * 10 / rate;
  2389. return ts;
  2390. }
  2391. void ieee80211_dfs_cac_cancel(struct ieee80211_local *local)
  2392. {
  2393. struct ieee80211_sub_if_data *sdata;
  2394. struct cfg80211_chan_def chandef;
  2395. mutex_lock(&local->mtx);
  2396. mutex_lock(&local->iflist_mtx);
  2397. list_for_each_entry(sdata, &local->interfaces, list) {
  2398. /* it might be waiting for the local->mtx, but then
  2399. * by the time it gets it, sdata->wdev.cac_started
  2400. * will no longer be true
  2401. */
  2402. cancel_delayed_work(&sdata->dfs_cac_timer_work);
  2403. if (sdata->wdev.cac_started) {
  2404. chandef = sdata->vif.bss_conf.chandef;
  2405. ieee80211_vif_release_channel(sdata);
  2406. cfg80211_cac_event(sdata->dev,
  2407. &chandef,
  2408. NL80211_RADAR_CAC_ABORTED,
  2409. GFP_KERNEL);
  2410. }
  2411. }
  2412. mutex_unlock(&local->iflist_mtx);
  2413. mutex_unlock(&local->mtx);
  2414. }
  2415. void ieee80211_dfs_radar_detected_work(struct work_struct *work)
  2416. {
  2417. struct ieee80211_local *local =
  2418. container_of(work, struct ieee80211_local, radar_detected_work);
  2419. struct cfg80211_chan_def chandef = local->hw.conf.chandef;
  2420. struct ieee80211_chanctx *ctx;
  2421. int num_chanctx = 0;
  2422. mutex_lock(&local->chanctx_mtx);
  2423. list_for_each_entry(ctx, &local->chanctx_list, list) {
  2424. if (ctx->replace_state == IEEE80211_CHANCTX_REPLACES_OTHER)
  2425. continue;
  2426. num_chanctx++;
  2427. chandef = ctx->conf.def;
  2428. }
  2429. mutex_unlock(&local->chanctx_mtx);
  2430. ieee80211_dfs_cac_cancel(local);
  2431. if (num_chanctx > 1)
  2432. /* XXX: multi-channel is not supported yet */
  2433. WARN_ON(1);
  2434. else
  2435. cfg80211_radar_event(local->hw.wiphy, &chandef, GFP_KERNEL);
  2436. }
  2437. void ieee80211_radar_detected(struct ieee80211_hw *hw)
  2438. {
  2439. struct ieee80211_local *local = hw_to_local(hw);
  2440. trace_api_radar_detected(local);
  2441. ieee80211_queue_work(hw, &local->radar_detected_work);
  2442. }
  2443. EXPORT_SYMBOL(ieee80211_radar_detected);
  2444. u32 ieee80211_chandef_downgrade(struct cfg80211_chan_def *c)
  2445. {
  2446. u32 ret;
  2447. int tmp;
  2448. switch (c->width) {
  2449. case NL80211_CHAN_WIDTH_20:
  2450. c->width = NL80211_CHAN_WIDTH_20_NOHT;
  2451. ret = IEEE80211_STA_DISABLE_HT | IEEE80211_STA_DISABLE_VHT;
  2452. break;
  2453. case NL80211_CHAN_WIDTH_40:
  2454. c->width = NL80211_CHAN_WIDTH_20;
  2455. c->center_freq1 = c->chan->center_freq;
  2456. ret = IEEE80211_STA_DISABLE_40MHZ |
  2457. IEEE80211_STA_DISABLE_VHT;
  2458. break;
  2459. case NL80211_CHAN_WIDTH_80:
  2460. tmp = (30 + c->chan->center_freq - c->center_freq1)/20;
  2461. /* n_P40 */
  2462. tmp /= 2;
  2463. /* freq_P40 */
  2464. c->center_freq1 = c->center_freq1 - 20 + 40 * tmp;
  2465. c->width = NL80211_CHAN_WIDTH_40;
  2466. ret = IEEE80211_STA_DISABLE_VHT;
  2467. break;
  2468. case NL80211_CHAN_WIDTH_80P80:
  2469. c->center_freq2 = 0;
  2470. c->width = NL80211_CHAN_WIDTH_80;
  2471. ret = IEEE80211_STA_DISABLE_80P80MHZ |
  2472. IEEE80211_STA_DISABLE_160MHZ;
  2473. break;
  2474. case NL80211_CHAN_WIDTH_160:
  2475. /* n_P20 */
  2476. tmp = (70 + c->chan->center_freq - c->center_freq1)/20;
  2477. /* n_P80 */
  2478. tmp /= 4;
  2479. c->center_freq1 = c->center_freq1 - 40 + 80 * tmp;
  2480. c->width = NL80211_CHAN_WIDTH_80;
  2481. ret = IEEE80211_STA_DISABLE_80P80MHZ |
  2482. IEEE80211_STA_DISABLE_160MHZ;
  2483. break;
  2484. default:
  2485. case NL80211_CHAN_WIDTH_20_NOHT:
  2486. WARN_ON_ONCE(1);
  2487. c->width = NL80211_CHAN_WIDTH_20_NOHT;
  2488. ret = IEEE80211_STA_DISABLE_HT | IEEE80211_STA_DISABLE_VHT;
  2489. break;
  2490. case NL80211_CHAN_WIDTH_5:
  2491. case NL80211_CHAN_WIDTH_10:
  2492. WARN_ON_ONCE(1);
  2493. /* keep c->width */
  2494. ret = IEEE80211_STA_DISABLE_HT | IEEE80211_STA_DISABLE_VHT;
  2495. break;
  2496. }
  2497. WARN_ON_ONCE(!cfg80211_chandef_valid(c));
  2498. return ret;
  2499. }
  2500. /*
  2501. * Returns true if smps_mode_new is strictly more restrictive than
  2502. * smps_mode_old.
  2503. */
  2504. bool ieee80211_smps_is_restrictive(enum ieee80211_smps_mode smps_mode_old,
  2505. enum ieee80211_smps_mode smps_mode_new)
  2506. {
  2507. if (WARN_ON_ONCE(smps_mode_old == IEEE80211_SMPS_AUTOMATIC ||
  2508. smps_mode_new == IEEE80211_SMPS_AUTOMATIC))
  2509. return false;
  2510. switch (smps_mode_old) {
  2511. case IEEE80211_SMPS_STATIC:
  2512. return false;
  2513. case IEEE80211_SMPS_DYNAMIC:
  2514. return smps_mode_new == IEEE80211_SMPS_STATIC;
  2515. case IEEE80211_SMPS_OFF:
  2516. return smps_mode_new != IEEE80211_SMPS_OFF;
  2517. default:
  2518. WARN_ON(1);
  2519. }
  2520. return false;
  2521. }
  2522. int ieee80211_send_action_csa(struct ieee80211_sub_if_data *sdata,
  2523. struct cfg80211_csa_settings *csa_settings)
  2524. {
  2525. struct sk_buff *skb;
  2526. struct ieee80211_mgmt *mgmt;
  2527. struct ieee80211_local *local = sdata->local;
  2528. int freq;
  2529. int hdr_len = offsetof(struct ieee80211_mgmt, u.action.u.chan_switch) +
  2530. sizeof(mgmt->u.action.u.chan_switch);
  2531. u8 *pos;
  2532. if (sdata->vif.type != NL80211_IFTYPE_ADHOC &&
  2533. sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
  2534. return -EOPNOTSUPP;
  2535. skb = dev_alloc_skb(local->tx_headroom + hdr_len +
  2536. 5 + /* channel switch announcement element */
  2537. 3 + /* secondary channel offset element */
  2538. 8); /* mesh channel switch parameters element */
  2539. if (!skb)
  2540. return -ENOMEM;
  2541. skb_reserve(skb, local->tx_headroom);
  2542. mgmt = (struct ieee80211_mgmt *)skb_put(skb, hdr_len);
  2543. memset(mgmt, 0, hdr_len);
  2544. mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
  2545. IEEE80211_STYPE_ACTION);
  2546. eth_broadcast_addr(mgmt->da);
  2547. memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
  2548. if (ieee80211_vif_is_mesh(&sdata->vif)) {
  2549. memcpy(mgmt->bssid, sdata->vif.addr, ETH_ALEN);
  2550. } else {
  2551. struct ieee80211_if_ibss *ifibss = &sdata->u.ibss;
  2552. memcpy(mgmt->bssid, ifibss->bssid, ETH_ALEN);
  2553. }
  2554. mgmt->u.action.category = WLAN_CATEGORY_SPECTRUM_MGMT;
  2555. mgmt->u.action.u.chan_switch.action_code = WLAN_ACTION_SPCT_CHL_SWITCH;
  2556. pos = skb_put(skb, 5);
  2557. *pos++ = WLAN_EID_CHANNEL_SWITCH; /* EID */
  2558. *pos++ = 3; /* IE length */
  2559. *pos++ = csa_settings->block_tx ? 1 : 0; /* CSA mode */
  2560. freq = csa_settings->chandef.chan->center_freq;
  2561. *pos++ = ieee80211_frequency_to_channel(freq); /* channel */
  2562. *pos++ = csa_settings->count; /* count */
  2563. if (csa_settings->chandef.width == NL80211_CHAN_WIDTH_40) {
  2564. enum nl80211_channel_type ch_type;
  2565. skb_put(skb, 3);
  2566. *pos++ = WLAN_EID_SECONDARY_CHANNEL_OFFSET; /* EID */
  2567. *pos++ = 1; /* IE length */
  2568. ch_type = cfg80211_get_chandef_type(&csa_settings->chandef);
  2569. if (ch_type == NL80211_CHAN_HT40PLUS)
  2570. *pos++ = IEEE80211_HT_PARAM_CHA_SEC_ABOVE;
  2571. else
  2572. *pos++ = IEEE80211_HT_PARAM_CHA_SEC_BELOW;
  2573. }
  2574. if (ieee80211_vif_is_mesh(&sdata->vif)) {
  2575. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  2576. skb_put(skb, 8);
  2577. *pos++ = WLAN_EID_CHAN_SWITCH_PARAM; /* EID */
  2578. *pos++ = 6; /* IE length */
  2579. *pos++ = sdata->u.mesh.mshcfg.dot11MeshTTL; /* Mesh TTL */
  2580. *pos = 0x00; /* Mesh Flag: Tx Restrict, Initiator, Reason */
  2581. *pos |= WLAN_EID_CHAN_SWITCH_PARAM_INITIATOR;
  2582. *pos++ |= csa_settings->block_tx ?
  2583. WLAN_EID_CHAN_SWITCH_PARAM_TX_RESTRICT : 0x00;
  2584. put_unaligned_le16(WLAN_REASON_MESH_CHAN, pos); /* Reason Cd */
  2585. pos += 2;
  2586. put_unaligned_le16(ifmsh->pre_value, pos);/* Precedence Value */
  2587. pos += 2;
  2588. }
  2589. ieee80211_tx_skb(sdata, skb);
  2590. return 0;
  2591. }
  2592. bool ieee80211_cs_valid(const struct ieee80211_cipher_scheme *cs)
  2593. {
  2594. return !(cs == NULL || cs->cipher == 0 ||
  2595. cs->hdr_len < cs->pn_len + cs->pn_off ||
  2596. cs->hdr_len <= cs->key_idx_off ||
  2597. cs->key_idx_shift > 7 ||
  2598. cs->key_idx_mask == 0);
  2599. }
  2600. bool ieee80211_cs_list_valid(const struct ieee80211_cipher_scheme *cs, int n)
  2601. {
  2602. int i;
  2603. /* Ensure we have enough iftype bitmap space for all iftype values */
  2604. WARN_ON((NUM_NL80211_IFTYPES / 8 + 1) > sizeof(cs[0].iftype));
  2605. for (i = 0; i < n; i++)
  2606. if (!ieee80211_cs_valid(&cs[i]))
  2607. return false;
  2608. return true;
  2609. }
  2610. const struct ieee80211_cipher_scheme *
  2611. ieee80211_cs_get(struct ieee80211_local *local, u32 cipher,
  2612. enum nl80211_iftype iftype)
  2613. {
  2614. const struct ieee80211_cipher_scheme *l = local->hw.cipher_schemes;
  2615. int n = local->hw.n_cipher_schemes;
  2616. int i;
  2617. const struct ieee80211_cipher_scheme *cs = NULL;
  2618. for (i = 0; i < n; i++) {
  2619. if (l[i].cipher == cipher) {
  2620. cs = &l[i];
  2621. break;
  2622. }
  2623. }
  2624. if (!cs || !(cs->iftype & BIT(iftype)))
  2625. return NULL;
  2626. return cs;
  2627. }
  2628. int ieee80211_cs_headroom(struct ieee80211_local *local,
  2629. struct cfg80211_crypto_settings *crypto,
  2630. enum nl80211_iftype iftype)
  2631. {
  2632. const struct ieee80211_cipher_scheme *cs;
  2633. int headroom = IEEE80211_ENCRYPT_HEADROOM;
  2634. int i;
  2635. for (i = 0; i < crypto->n_ciphers_pairwise; i++) {
  2636. cs = ieee80211_cs_get(local, crypto->ciphers_pairwise[i],
  2637. iftype);
  2638. if (cs && headroom < cs->hdr_len)
  2639. headroom = cs->hdr_len;
  2640. }
  2641. cs = ieee80211_cs_get(local, crypto->cipher_group, iftype);
  2642. if (cs && headroom < cs->hdr_len)
  2643. headroom = cs->hdr_len;
  2644. return headroom;
  2645. }
  2646. static bool
  2647. ieee80211_extend_noa_desc(struct ieee80211_noa_data *data, u32 tsf, int i)
  2648. {
  2649. s32 end = data->desc[i].start + data->desc[i].duration - (tsf + 1);
  2650. int skip;
  2651. if (end > 0)
  2652. return false;
  2653. /* One shot NOA */
  2654. if (data->count[i] == 1)
  2655. return false;
  2656. if (data->desc[i].interval == 0)
  2657. return false;
  2658. /* End time is in the past, check for repetitions */
  2659. skip = DIV_ROUND_UP(-end, data->desc[i].interval);
  2660. if (data->count[i] < 255) {
  2661. if (data->count[i] <= skip) {
  2662. data->count[i] = 0;
  2663. return false;
  2664. }
  2665. data->count[i] -= skip;
  2666. }
  2667. data->desc[i].start += skip * data->desc[i].interval;
  2668. return true;
  2669. }
  2670. static bool
  2671. ieee80211_extend_absent_time(struct ieee80211_noa_data *data, u32 tsf,
  2672. s32 *offset)
  2673. {
  2674. bool ret = false;
  2675. int i;
  2676. for (i = 0; i < IEEE80211_P2P_NOA_DESC_MAX; i++) {
  2677. s32 cur;
  2678. if (!data->count[i])
  2679. continue;
  2680. if (ieee80211_extend_noa_desc(data, tsf + *offset, i))
  2681. ret = true;
  2682. cur = data->desc[i].start - tsf;
  2683. if (cur > *offset)
  2684. continue;
  2685. cur = data->desc[i].start + data->desc[i].duration - tsf;
  2686. if (cur > *offset)
  2687. *offset = cur;
  2688. }
  2689. return ret;
  2690. }
  2691. static u32
  2692. ieee80211_get_noa_absent_time(struct ieee80211_noa_data *data, u32 tsf)
  2693. {
  2694. s32 offset = 0;
  2695. int tries = 0;
  2696. /*
  2697. * arbitrary limit, used to avoid infinite loops when combined NoA
  2698. * descriptors cover the full time period.
  2699. */
  2700. int max_tries = 5;
  2701. ieee80211_extend_absent_time(data, tsf, &offset);
  2702. do {
  2703. if (!ieee80211_extend_absent_time(data, tsf, &offset))
  2704. break;
  2705. tries++;
  2706. } while (tries < max_tries);
  2707. return offset;
  2708. }
  2709. void ieee80211_update_p2p_noa(struct ieee80211_noa_data *data, u32 tsf)
  2710. {
  2711. u32 next_offset = BIT(31) - 1;
  2712. int i;
  2713. data->absent = 0;
  2714. data->has_next_tsf = false;
  2715. for (i = 0; i < IEEE80211_P2P_NOA_DESC_MAX; i++) {
  2716. s32 start;
  2717. if (!data->count[i])
  2718. continue;
  2719. ieee80211_extend_noa_desc(data, tsf, i);
  2720. start = data->desc[i].start - tsf;
  2721. if (start <= 0)
  2722. data->absent |= BIT(i);
  2723. if (next_offset > start)
  2724. next_offset = start;
  2725. data->has_next_tsf = true;
  2726. }
  2727. if (data->absent)
  2728. next_offset = ieee80211_get_noa_absent_time(data, tsf);
  2729. data->next_tsf = tsf + next_offset;
  2730. }
  2731. EXPORT_SYMBOL(ieee80211_update_p2p_noa);
  2732. int ieee80211_parse_p2p_noa(const struct ieee80211_p2p_noa_attr *attr,
  2733. struct ieee80211_noa_data *data, u32 tsf)
  2734. {
  2735. int ret = 0;
  2736. int i;
  2737. memset(data, 0, sizeof(*data));
  2738. for (i = 0; i < IEEE80211_P2P_NOA_DESC_MAX; i++) {
  2739. const struct ieee80211_p2p_noa_desc *desc = &attr->desc[i];
  2740. if (!desc->count || !desc->duration)
  2741. continue;
  2742. data->count[i] = desc->count;
  2743. data->desc[i].start = le32_to_cpu(desc->start_time);
  2744. data->desc[i].duration = le32_to_cpu(desc->duration);
  2745. data->desc[i].interval = le32_to_cpu(desc->interval);
  2746. if (data->count[i] > 1 &&
  2747. data->desc[i].interval < data->desc[i].duration)
  2748. continue;
  2749. ieee80211_extend_noa_desc(data, tsf, i);
  2750. ret++;
  2751. }
  2752. if (ret)
  2753. ieee80211_update_p2p_noa(data, tsf);
  2754. return ret;
  2755. }
  2756. EXPORT_SYMBOL(ieee80211_parse_p2p_noa);
  2757. void ieee80211_recalc_dtim(struct ieee80211_local *local,
  2758. struct ieee80211_sub_if_data *sdata)
  2759. {
  2760. u64 tsf = drv_get_tsf(local, sdata);
  2761. u64 dtim_count = 0;
  2762. u16 beacon_int = sdata->vif.bss_conf.beacon_int * 1024;
  2763. u8 dtim_period = sdata->vif.bss_conf.dtim_period;
  2764. struct ps_data *ps;
  2765. u8 bcns_from_dtim;
  2766. if (tsf == -1ULL || !beacon_int || !dtim_period)
  2767. return;
  2768. if (sdata->vif.type == NL80211_IFTYPE_AP ||
  2769. sdata->vif.type == NL80211_IFTYPE_AP_VLAN) {
  2770. if (!sdata->bss)
  2771. return;
  2772. ps = &sdata->bss->ps;
  2773. } else if (ieee80211_vif_is_mesh(&sdata->vif)) {
  2774. ps = &sdata->u.mesh.ps;
  2775. } else {
  2776. return;
  2777. }
  2778. /*
  2779. * actually finds last dtim_count, mac80211 will update in
  2780. * __beacon_add_tim().
  2781. * dtim_count = dtim_period - (tsf / bcn_int) % dtim_period
  2782. */
  2783. do_div(tsf, beacon_int);
  2784. bcns_from_dtim = do_div(tsf, dtim_period);
  2785. /* just had a DTIM */
  2786. if (!bcns_from_dtim)
  2787. dtim_count = 0;
  2788. else
  2789. dtim_count = dtim_period - bcns_from_dtim;
  2790. ps->dtim_count = dtim_count;
  2791. }
  2792. static u8 ieee80211_chanctx_radar_detect(struct ieee80211_local *local,
  2793. struct ieee80211_chanctx *ctx)
  2794. {
  2795. struct ieee80211_sub_if_data *sdata;
  2796. u8 radar_detect = 0;
  2797. lockdep_assert_held(&local->chanctx_mtx);
  2798. if (WARN_ON(ctx->replace_state == IEEE80211_CHANCTX_WILL_BE_REPLACED))
  2799. return 0;
  2800. list_for_each_entry(sdata, &ctx->reserved_vifs, reserved_chanctx_list)
  2801. if (sdata->reserved_radar_required)
  2802. radar_detect |= BIT(sdata->reserved_chandef.width);
  2803. /*
  2804. * An in-place reservation context should not have any assigned vifs
  2805. * until it replaces the other context.
  2806. */
  2807. WARN_ON(ctx->replace_state == IEEE80211_CHANCTX_REPLACES_OTHER &&
  2808. !list_empty(&ctx->assigned_vifs));
  2809. list_for_each_entry(sdata, &ctx->assigned_vifs, assigned_chanctx_list)
  2810. if (sdata->radar_required)
  2811. radar_detect |= BIT(sdata->vif.bss_conf.chandef.width);
  2812. return radar_detect;
  2813. }
  2814. int ieee80211_check_combinations(struct ieee80211_sub_if_data *sdata,
  2815. const struct cfg80211_chan_def *chandef,
  2816. enum ieee80211_chanctx_mode chanmode,
  2817. u8 radar_detect)
  2818. {
  2819. struct ieee80211_local *local = sdata->local;
  2820. struct ieee80211_sub_if_data *sdata_iter;
  2821. enum nl80211_iftype iftype = sdata->wdev.iftype;
  2822. int num[NUM_NL80211_IFTYPES];
  2823. struct ieee80211_chanctx *ctx;
  2824. int num_different_channels = 0;
  2825. int total = 1;
  2826. lockdep_assert_held(&local->chanctx_mtx);
  2827. if (WARN_ON(hweight32(radar_detect) > 1))
  2828. return -EINVAL;
  2829. if (WARN_ON(chandef && chanmode == IEEE80211_CHANCTX_SHARED &&
  2830. !chandef->chan))
  2831. return -EINVAL;
  2832. if (chandef)
  2833. num_different_channels = 1;
  2834. if (WARN_ON(iftype >= NUM_NL80211_IFTYPES))
  2835. return -EINVAL;
  2836. /* Always allow software iftypes */
  2837. if (local->hw.wiphy->software_iftypes & BIT(iftype)) {
  2838. if (radar_detect)
  2839. return -EINVAL;
  2840. return 0;
  2841. }
  2842. memset(num, 0, sizeof(num));
  2843. if (iftype != NL80211_IFTYPE_UNSPECIFIED)
  2844. num[iftype] = 1;
  2845. list_for_each_entry(ctx, &local->chanctx_list, list) {
  2846. if (ctx->replace_state == IEEE80211_CHANCTX_WILL_BE_REPLACED)
  2847. continue;
  2848. radar_detect |= ieee80211_chanctx_radar_detect(local, ctx);
  2849. if (ctx->mode == IEEE80211_CHANCTX_EXCLUSIVE) {
  2850. num_different_channels++;
  2851. continue;
  2852. }
  2853. if (chandef && chanmode == IEEE80211_CHANCTX_SHARED &&
  2854. cfg80211_chandef_compatible(chandef,
  2855. &ctx->conf.def))
  2856. continue;
  2857. num_different_channels++;
  2858. }
  2859. list_for_each_entry_rcu(sdata_iter, &local->interfaces, list) {
  2860. struct wireless_dev *wdev_iter;
  2861. wdev_iter = &sdata_iter->wdev;
  2862. if (sdata_iter == sdata ||
  2863. !ieee80211_sdata_running(sdata_iter) ||
  2864. local->hw.wiphy->software_iftypes & BIT(wdev_iter->iftype))
  2865. continue;
  2866. num[wdev_iter->iftype]++;
  2867. total++;
  2868. }
  2869. if (total == 1 && !radar_detect)
  2870. return 0;
  2871. return cfg80211_check_combinations(local->hw.wiphy,
  2872. num_different_channels,
  2873. radar_detect, num);
  2874. }
  2875. static void
  2876. ieee80211_iter_max_chans(const struct ieee80211_iface_combination *c,
  2877. void *data)
  2878. {
  2879. u32 *max_num_different_channels = data;
  2880. *max_num_different_channels = max(*max_num_different_channels,
  2881. c->num_different_channels);
  2882. }
  2883. int ieee80211_max_num_channels(struct ieee80211_local *local)
  2884. {
  2885. struct ieee80211_sub_if_data *sdata;
  2886. int num[NUM_NL80211_IFTYPES] = {};
  2887. struct ieee80211_chanctx *ctx;
  2888. int num_different_channels = 0;
  2889. u8 radar_detect = 0;
  2890. u32 max_num_different_channels = 1;
  2891. int err;
  2892. lockdep_assert_held(&local->chanctx_mtx);
  2893. list_for_each_entry(ctx, &local->chanctx_list, list) {
  2894. if (ctx->replace_state == IEEE80211_CHANCTX_WILL_BE_REPLACED)
  2895. continue;
  2896. num_different_channels++;
  2897. radar_detect |= ieee80211_chanctx_radar_detect(local, ctx);
  2898. }
  2899. list_for_each_entry_rcu(sdata, &local->interfaces, list)
  2900. num[sdata->wdev.iftype]++;
  2901. err = cfg80211_iter_combinations(local->hw.wiphy,
  2902. num_different_channels, radar_detect,
  2903. num, ieee80211_iter_max_chans,
  2904. &max_num_different_channels);
  2905. if (err < 0)
  2906. return err;
  2907. return max_num_different_channels;
  2908. }
  2909. u8 *ieee80211_add_wmm_info_ie(u8 *buf, u8 qosinfo)
  2910. {
  2911. *buf++ = WLAN_EID_VENDOR_SPECIFIC;
  2912. *buf++ = 7; /* len */
  2913. *buf++ = 0x00; /* Microsoft OUI 00:50:F2 */
  2914. *buf++ = 0x50;
  2915. *buf++ = 0xf2;
  2916. *buf++ = 2; /* WME */
  2917. *buf++ = 0; /* WME info */
  2918. *buf++ = 1; /* WME ver */
  2919. *buf++ = qosinfo; /* U-APSD no in use */
  2920. return buf;
  2921. }
  2922. void ieee80211_txq_get_depth(struct ieee80211_txq *txq,
  2923. unsigned long *frame_cnt,
  2924. unsigned long *byte_cnt)
  2925. {
  2926. struct txq_info *txqi = to_txq_info(txq);
  2927. u32 frag_cnt = 0, frag_bytes = 0;
  2928. struct sk_buff *skb;
  2929. skb_queue_walk(&txqi->frags, skb) {
  2930. frag_cnt++;
  2931. frag_bytes += skb->len;
  2932. }
  2933. if (frame_cnt)
  2934. *frame_cnt = txqi->tin.backlog_packets + frag_cnt;
  2935. if (byte_cnt)
  2936. *byte_cnt = txqi->tin.backlog_bytes + frag_bytes;
  2937. }
  2938. EXPORT_SYMBOL(ieee80211_txq_get_depth);