tx.c 105 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885
  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. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License version 2 as
  10. * published by the Free Software Foundation.
  11. *
  12. *
  13. * Transmit and frame generation functions.
  14. */
  15. #include <linux/kernel.h>
  16. #include <linux/slab.h>
  17. #include <linux/skbuff.h>
  18. #include <linux/etherdevice.h>
  19. #include <linux/bitmap.h>
  20. #include <linux/rcupdate.h>
  21. #include <linux/export.h>
  22. #include <net/net_namespace.h>
  23. #include <net/ieee80211_radiotap.h>
  24. #include <net/cfg80211.h>
  25. #include <net/mac80211.h>
  26. #include <asm/unaligned.h>
  27. #include "ieee80211_i.h"
  28. #include "driver-ops.h"
  29. #include "led.h"
  30. #include "mesh.h"
  31. #include "wep.h"
  32. #include "wpa.h"
  33. #include "wme.h"
  34. #include "rate.h"
  35. /* misc utils */
  36. static inline void ieee80211_tx_stats(struct net_device *dev, u32 len)
  37. {
  38. struct pcpu_sw_netstats *tstats = this_cpu_ptr(dev->tstats);
  39. u64_stats_update_begin(&tstats->syncp);
  40. tstats->tx_packets++;
  41. tstats->tx_bytes += len;
  42. u64_stats_update_end(&tstats->syncp);
  43. }
  44. static __le16 ieee80211_duration(struct ieee80211_tx_data *tx,
  45. struct sk_buff *skb, int group_addr,
  46. int next_frag_len)
  47. {
  48. int rate, mrate, erp, dur, i, shift = 0;
  49. struct ieee80211_rate *txrate;
  50. struct ieee80211_local *local = tx->local;
  51. struct ieee80211_supported_band *sband;
  52. struct ieee80211_hdr *hdr;
  53. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  54. struct ieee80211_chanctx_conf *chanctx_conf;
  55. u32 rate_flags = 0;
  56. rcu_read_lock();
  57. chanctx_conf = rcu_dereference(tx->sdata->vif.chanctx_conf);
  58. if (chanctx_conf) {
  59. shift = ieee80211_chandef_get_shift(&chanctx_conf->def);
  60. rate_flags = ieee80211_chandef_rate_flags(&chanctx_conf->def);
  61. }
  62. rcu_read_unlock();
  63. /* assume HW handles this */
  64. if (tx->rate.flags & (IEEE80211_TX_RC_MCS | IEEE80211_TX_RC_VHT_MCS))
  65. return 0;
  66. /* uh huh? */
  67. if (WARN_ON_ONCE(tx->rate.idx < 0))
  68. return 0;
  69. sband = local->hw.wiphy->bands[info->band];
  70. txrate = &sband->bitrates[tx->rate.idx];
  71. erp = txrate->flags & IEEE80211_RATE_ERP_G;
  72. /*
  73. * data and mgmt (except PS Poll):
  74. * - during CFP: 32768
  75. * - during contention period:
  76. * if addr1 is group address: 0
  77. * if more fragments = 0 and addr1 is individual address: time to
  78. * transmit one ACK plus SIFS
  79. * if more fragments = 1 and addr1 is individual address: time to
  80. * transmit next fragment plus 2 x ACK plus 3 x SIFS
  81. *
  82. * IEEE 802.11, 9.6:
  83. * - control response frame (CTS or ACK) shall be transmitted using the
  84. * same rate as the immediately previous frame in the frame exchange
  85. * sequence, if this rate belongs to the PHY mandatory rates, or else
  86. * at the highest possible rate belonging to the PHY rates in the
  87. * BSSBasicRateSet
  88. */
  89. hdr = (struct ieee80211_hdr *)skb->data;
  90. if (ieee80211_is_ctl(hdr->frame_control)) {
  91. /* TODO: These control frames are not currently sent by
  92. * mac80211, but should they be implemented, this function
  93. * needs to be updated to support duration field calculation.
  94. *
  95. * RTS: time needed to transmit pending data/mgmt frame plus
  96. * one CTS frame plus one ACK frame plus 3 x SIFS
  97. * CTS: duration of immediately previous RTS minus time
  98. * required to transmit CTS and its SIFS
  99. * ACK: 0 if immediately previous directed data/mgmt had
  100. * more=0, with more=1 duration in ACK frame is duration
  101. * from previous frame minus time needed to transmit ACK
  102. * and its SIFS
  103. * PS Poll: BIT(15) | BIT(14) | aid
  104. */
  105. return 0;
  106. }
  107. /* data/mgmt */
  108. if (0 /* FIX: data/mgmt during CFP */)
  109. return cpu_to_le16(32768);
  110. if (group_addr) /* Group address as the destination - no ACK */
  111. return 0;
  112. /* Individual destination address:
  113. * IEEE 802.11, Ch. 9.6 (after IEEE 802.11g changes)
  114. * CTS and ACK frames shall be transmitted using the highest rate in
  115. * basic rate set that is less than or equal to the rate of the
  116. * immediately previous frame and that is using the same modulation
  117. * (CCK or OFDM). If no basic rate set matches with these requirements,
  118. * the highest mandatory rate of the PHY that is less than or equal to
  119. * the rate of the previous frame is used.
  120. * Mandatory rates for IEEE 802.11g PHY: 1, 2, 5.5, 11, 6, 12, 24 Mbps
  121. */
  122. rate = -1;
  123. /* use lowest available if everything fails */
  124. mrate = sband->bitrates[0].bitrate;
  125. for (i = 0; i < sband->n_bitrates; i++) {
  126. struct ieee80211_rate *r = &sband->bitrates[i];
  127. if (r->bitrate > txrate->bitrate)
  128. break;
  129. if ((rate_flags & r->flags) != rate_flags)
  130. continue;
  131. if (tx->sdata->vif.bss_conf.basic_rates & BIT(i))
  132. rate = DIV_ROUND_UP(r->bitrate, 1 << shift);
  133. switch (sband->band) {
  134. case IEEE80211_BAND_2GHZ: {
  135. u32 flag;
  136. if (tx->sdata->flags & IEEE80211_SDATA_OPERATING_GMODE)
  137. flag = IEEE80211_RATE_MANDATORY_G;
  138. else
  139. flag = IEEE80211_RATE_MANDATORY_B;
  140. if (r->flags & flag)
  141. mrate = r->bitrate;
  142. break;
  143. }
  144. case IEEE80211_BAND_5GHZ:
  145. if (r->flags & IEEE80211_RATE_MANDATORY_A)
  146. mrate = r->bitrate;
  147. break;
  148. case IEEE80211_BAND_60GHZ:
  149. /* TODO, for now fall through */
  150. case IEEE80211_NUM_BANDS:
  151. WARN_ON(1);
  152. break;
  153. }
  154. }
  155. if (rate == -1) {
  156. /* No matching basic rate found; use highest suitable mandatory
  157. * PHY rate */
  158. rate = DIV_ROUND_UP(mrate, 1 << shift);
  159. }
  160. /* Don't calculate ACKs for QoS Frames with NoAck Policy set */
  161. if (ieee80211_is_data_qos(hdr->frame_control) &&
  162. *(ieee80211_get_qos_ctl(hdr)) & IEEE80211_QOS_CTL_ACK_POLICY_NOACK)
  163. dur = 0;
  164. else
  165. /* Time needed to transmit ACK
  166. * (10 bytes + 4-byte FCS = 112 bits) plus SIFS; rounded up
  167. * to closest integer */
  168. dur = ieee80211_frame_duration(sband->band, 10, rate, erp,
  169. tx->sdata->vif.bss_conf.use_short_preamble,
  170. shift);
  171. if (next_frag_len) {
  172. /* Frame is fragmented: duration increases with time needed to
  173. * transmit next fragment plus ACK and 2 x SIFS. */
  174. dur *= 2; /* ACK + SIFS */
  175. /* next fragment */
  176. dur += ieee80211_frame_duration(sband->band, next_frag_len,
  177. txrate->bitrate, erp,
  178. tx->sdata->vif.bss_conf.use_short_preamble,
  179. shift);
  180. }
  181. return cpu_to_le16(dur);
  182. }
  183. /* tx handlers */
  184. static ieee80211_tx_result debug_noinline
  185. ieee80211_tx_h_dynamic_ps(struct ieee80211_tx_data *tx)
  186. {
  187. struct ieee80211_local *local = tx->local;
  188. struct ieee80211_if_managed *ifmgd;
  189. /* driver doesn't support power save */
  190. if (!ieee80211_hw_check(&local->hw, SUPPORTS_PS))
  191. return TX_CONTINUE;
  192. /* hardware does dynamic power save */
  193. if (ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS))
  194. return TX_CONTINUE;
  195. /* dynamic power save disabled */
  196. if (local->hw.conf.dynamic_ps_timeout <= 0)
  197. return TX_CONTINUE;
  198. /* we are scanning, don't enable power save */
  199. if (local->scanning)
  200. return TX_CONTINUE;
  201. if (!local->ps_sdata)
  202. return TX_CONTINUE;
  203. /* No point if we're going to suspend */
  204. if (local->quiescing)
  205. return TX_CONTINUE;
  206. /* dynamic ps is supported only in managed mode */
  207. if (tx->sdata->vif.type != NL80211_IFTYPE_STATION)
  208. return TX_CONTINUE;
  209. ifmgd = &tx->sdata->u.mgd;
  210. /*
  211. * Don't wakeup from power save if u-apsd is enabled, voip ac has
  212. * u-apsd enabled and the frame is in voip class. This effectively
  213. * means that even if all access categories have u-apsd enabled, in
  214. * practise u-apsd is only used with the voip ac. This is a
  215. * workaround for the case when received voip class packets do not
  216. * have correct qos tag for some reason, due the network or the
  217. * peer application.
  218. *
  219. * Note: ifmgd->uapsd_queues access is racy here. If the value is
  220. * changed via debugfs, user needs to reassociate manually to have
  221. * everything in sync.
  222. */
  223. if ((ifmgd->flags & IEEE80211_STA_UAPSD_ENABLED) &&
  224. (ifmgd->uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO) &&
  225. skb_get_queue_mapping(tx->skb) == IEEE80211_AC_VO)
  226. return TX_CONTINUE;
  227. if (local->hw.conf.flags & IEEE80211_CONF_PS) {
  228. ieee80211_stop_queues_by_reason(&local->hw,
  229. IEEE80211_MAX_QUEUE_MAP,
  230. IEEE80211_QUEUE_STOP_REASON_PS,
  231. false);
  232. ifmgd->flags &= ~IEEE80211_STA_NULLFUNC_ACKED;
  233. ieee80211_queue_work(&local->hw,
  234. &local->dynamic_ps_disable_work);
  235. }
  236. /* Don't restart the timer if we're not disassociated */
  237. if (!ifmgd->associated)
  238. return TX_CONTINUE;
  239. mod_timer(&local->dynamic_ps_timer, jiffies +
  240. msecs_to_jiffies(local->hw.conf.dynamic_ps_timeout));
  241. return TX_CONTINUE;
  242. }
  243. static ieee80211_tx_result debug_noinline
  244. ieee80211_tx_h_check_assoc(struct ieee80211_tx_data *tx)
  245. {
  246. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx->skb->data;
  247. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb);
  248. bool assoc = false;
  249. if (unlikely(info->flags & IEEE80211_TX_CTL_INJECTED))
  250. return TX_CONTINUE;
  251. if (unlikely(test_bit(SCAN_SW_SCANNING, &tx->local->scanning)) &&
  252. test_bit(SDATA_STATE_OFFCHANNEL, &tx->sdata->state) &&
  253. !ieee80211_is_probe_req(hdr->frame_control) &&
  254. !ieee80211_is_nullfunc(hdr->frame_control))
  255. /*
  256. * When software scanning only nullfunc frames (to notify
  257. * the sleep state to the AP) and probe requests (for the
  258. * active scan) are allowed, all other frames should not be
  259. * sent and we should not get here, but if we do
  260. * nonetheless, drop them to avoid sending them
  261. * off-channel. See the link below and
  262. * ieee80211_start_scan() for more.
  263. *
  264. * http://article.gmane.org/gmane.linux.kernel.wireless.general/30089
  265. */
  266. return TX_DROP;
  267. if (tx->sdata->vif.type == NL80211_IFTYPE_OCB)
  268. return TX_CONTINUE;
  269. if (tx->sdata->vif.type == NL80211_IFTYPE_WDS)
  270. return TX_CONTINUE;
  271. if (tx->sdata->vif.type == NL80211_IFTYPE_MESH_POINT)
  272. return TX_CONTINUE;
  273. if (tx->flags & IEEE80211_TX_PS_BUFFERED)
  274. return TX_CONTINUE;
  275. if (tx->sta)
  276. assoc = test_sta_flag(tx->sta, WLAN_STA_ASSOC);
  277. if (likely(tx->flags & IEEE80211_TX_UNICAST)) {
  278. if (unlikely(!assoc &&
  279. ieee80211_is_data(hdr->frame_control))) {
  280. #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
  281. sdata_info(tx->sdata,
  282. "dropped data frame to not associated station %pM\n",
  283. hdr->addr1);
  284. #endif
  285. I802_DEBUG_INC(tx->local->tx_handlers_drop_not_assoc);
  286. return TX_DROP;
  287. }
  288. } else if (unlikely(tx->sdata->vif.type == NL80211_IFTYPE_AP &&
  289. ieee80211_is_data(hdr->frame_control) &&
  290. !atomic_read(&tx->sdata->u.ap.num_mcast_sta))) {
  291. /*
  292. * No associated STAs - no need to send multicast
  293. * frames.
  294. */
  295. return TX_DROP;
  296. }
  297. return TX_CONTINUE;
  298. }
  299. /* This function is called whenever the AP is about to exceed the maximum limit
  300. * of buffered frames for power saving STAs. This situation should not really
  301. * happen often during normal operation, so dropping the oldest buffered packet
  302. * from each queue should be OK to make some room for new frames. */
  303. static void purge_old_ps_buffers(struct ieee80211_local *local)
  304. {
  305. int total = 0, purged = 0;
  306. struct sk_buff *skb;
  307. struct ieee80211_sub_if_data *sdata;
  308. struct sta_info *sta;
  309. list_for_each_entry_rcu(sdata, &local->interfaces, list) {
  310. struct ps_data *ps;
  311. if (sdata->vif.type == NL80211_IFTYPE_AP)
  312. ps = &sdata->u.ap.ps;
  313. else if (ieee80211_vif_is_mesh(&sdata->vif))
  314. ps = &sdata->u.mesh.ps;
  315. else
  316. continue;
  317. skb = skb_dequeue(&ps->bc_buf);
  318. if (skb) {
  319. purged++;
  320. dev_kfree_skb(skb);
  321. }
  322. total += skb_queue_len(&ps->bc_buf);
  323. }
  324. /*
  325. * Drop one frame from each station from the lowest-priority
  326. * AC that has frames at all.
  327. */
  328. list_for_each_entry_rcu(sta, &local->sta_list, list) {
  329. int ac;
  330. for (ac = IEEE80211_AC_BK; ac >= IEEE80211_AC_VO; ac--) {
  331. skb = skb_dequeue(&sta->ps_tx_buf[ac]);
  332. total += skb_queue_len(&sta->ps_tx_buf[ac]);
  333. if (skb) {
  334. purged++;
  335. ieee80211_free_txskb(&local->hw, skb);
  336. break;
  337. }
  338. }
  339. }
  340. local->total_ps_buffered = total;
  341. ps_dbg_hw(&local->hw, "PS buffers full - purged %d frames\n", purged);
  342. }
  343. static ieee80211_tx_result
  344. ieee80211_tx_h_multicast_ps_buf(struct ieee80211_tx_data *tx)
  345. {
  346. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb);
  347. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx->skb->data;
  348. struct ps_data *ps;
  349. /*
  350. * broadcast/multicast frame
  351. *
  352. * If any of the associated/peer stations is in power save mode,
  353. * the frame is buffered to be sent after DTIM beacon frame.
  354. * This is done either by the hardware or us.
  355. */
  356. /* powersaving STAs currently only in AP/VLAN/mesh mode */
  357. if (tx->sdata->vif.type == NL80211_IFTYPE_AP ||
  358. tx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN) {
  359. if (!tx->sdata->bss)
  360. return TX_CONTINUE;
  361. ps = &tx->sdata->bss->ps;
  362. } else if (ieee80211_vif_is_mesh(&tx->sdata->vif)) {
  363. ps = &tx->sdata->u.mesh.ps;
  364. } else {
  365. return TX_CONTINUE;
  366. }
  367. /* no buffering for ordered frames */
  368. if (ieee80211_has_order(hdr->frame_control))
  369. return TX_CONTINUE;
  370. if (ieee80211_is_probe_req(hdr->frame_control))
  371. return TX_CONTINUE;
  372. if (ieee80211_hw_check(&tx->local->hw, QUEUE_CONTROL))
  373. info->hw_queue = tx->sdata->vif.cab_queue;
  374. /* no stations in PS mode */
  375. if (!atomic_read(&ps->num_sta_ps))
  376. return TX_CONTINUE;
  377. info->flags |= IEEE80211_TX_CTL_SEND_AFTER_DTIM;
  378. /* device releases frame after DTIM beacon */
  379. if (!ieee80211_hw_check(&tx->local->hw, HOST_BROADCAST_PS_BUFFERING))
  380. return TX_CONTINUE;
  381. /* buffered in mac80211 */
  382. if (tx->local->total_ps_buffered >= TOTAL_MAX_TX_BUFFER)
  383. purge_old_ps_buffers(tx->local);
  384. if (skb_queue_len(&ps->bc_buf) >= AP_MAX_BC_BUFFER) {
  385. ps_dbg(tx->sdata,
  386. "BC TX buffer full - dropping the oldest frame\n");
  387. dev_kfree_skb(skb_dequeue(&ps->bc_buf));
  388. } else
  389. tx->local->total_ps_buffered++;
  390. skb_queue_tail(&ps->bc_buf, tx->skb);
  391. return TX_QUEUED;
  392. }
  393. static int ieee80211_use_mfp(__le16 fc, struct sta_info *sta,
  394. struct sk_buff *skb)
  395. {
  396. if (!ieee80211_is_mgmt(fc))
  397. return 0;
  398. if (sta == NULL || !test_sta_flag(sta, WLAN_STA_MFP))
  399. return 0;
  400. if (!ieee80211_is_robust_mgmt_frame(skb))
  401. return 0;
  402. return 1;
  403. }
  404. static ieee80211_tx_result
  405. ieee80211_tx_h_unicast_ps_buf(struct ieee80211_tx_data *tx)
  406. {
  407. struct sta_info *sta = tx->sta;
  408. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb);
  409. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx->skb->data;
  410. struct ieee80211_local *local = tx->local;
  411. if (unlikely(!sta))
  412. return TX_CONTINUE;
  413. if (unlikely((test_sta_flag(sta, WLAN_STA_PS_STA) ||
  414. test_sta_flag(sta, WLAN_STA_PS_DRIVER) ||
  415. test_sta_flag(sta, WLAN_STA_PS_DELIVER)) &&
  416. !(info->flags & IEEE80211_TX_CTL_NO_PS_BUFFER))) {
  417. int ac = skb_get_queue_mapping(tx->skb);
  418. if (ieee80211_is_mgmt(hdr->frame_control) &&
  419. !ieee80211_is_bufferable_mmpdu(hdr->frame_control)) {
  420. info->flags |= IEEE80211_TX_CTL_NO_PS_BUFFER;
  421. return TX_CONTINUE;
  422. }
  423. ps_dbg(sta->sdata, "STA %pM aid %d: PS buffer for AC %d\n",
  424. sta->sta.addr, sta->sta.aid, ac);
  425. if (tx->local->total_ps_buffered >= TOTAL_MAX_TX_BUFFER)
  426. purge_old_ps_buffers(tx->local);
  427. /* sync with ieee80211_sta_ps_deliver_wakeup */
  428. spin_lock(&sta->ps_lock);
  429. /*
  430. * STA woke up the meantime and all the frames on ps_tx_buf have
  431. * been queued to pending queue. No reordering can happen, go
  432. * ahead and Tx the packet.
  433. */
  434. if (!test_sta_flag(sta, WLAN_STA_PS_STA) &&
  435. !test_sta_flag(sta, WLAN_STA_PS_DRIVER) &&
  436. !test_sta_flag(sta, WLAN_STA_PS_DELIVER)) {
  437. spin_unlock(&sta->ps_lock);
  438. return TX_CONTINUE;
  439. }
  440. if (skb_queue_len(&sta->ps_tx_buf[ac]) >= STA_MAX_TX_BUFFER) {
  441. struct sk_buff *old = skb_dequeue(&sta->ps_tx_buf[ac]);
  442. ps_dbg(tx->sdata,
  443. "STA %pM TX buffer for AC %d full - dropping oldest frame\n",
  444. sta->sta.addr, ac);
  445. ieee80211_free_txskb(&local->hw, old);
  446. } else
  447. tx->local->total_ps_buffered++;
  448. info->control.jiffies = jiffies;
  449. info->control.vif = &tx->sdata->vif;
  450. info->flags |= IEEE80211_TX_INTFL_NEED_TXPROCESSING;
  451. info->flags &= ~IEEE80211_TX_TEMPORARY_FLAGS;
  452. skb_queue_tail(&sta->ps_tx_buf[ac], tx->skb);
  453. spin_unlock(&sta->ps_lock);
  454. if (!timer_pending(&local->sta_cleanup))
  455. mod_timer(&local->sta_cleanup,
  456. round_jiffies(jiffies +
  457. STA_INFO_CLEANUP_INTERVAL));
  458. /*
  459. * We queued up some frames, so the TIM bit might
  460. * need to be set, recalculate it.
  461. */
  462. sta_info_recalc_tim(sta);
  463. return TX_QUEUED;
  464. } else if (unlikely(test_sta_flag(sta, WLAN_STA_PS_STA))) {
  465. ps_dbg(tx->sdata,
  466. "STA %pM in PS mode, but polling/in SP -> send frame\n",
  467. sta->sta.addr);
  468. }
  469. return TX_CONTINUE;
  470. }
  471. static ieee80211_tx_result debug_noinline
  472. ieee80211_tx_h_ps_buf(struct ieee80211_tx_data *tx)
  473. {
  474. if (unlikely(tx->flags & IEEE80211_TX_PS_BUFFERED))
  475. return TX_CONTINUE;
  476. if (tx->flags & IEEE80211_TX_UNICAST)
  477. return ieee80211_tx_h_unicast_ps_buf(tx);
  478. else
  479. return ieee80211_tx_h_multicast_ps_buf(tx);
  480. }
  481. static ieee80211_tx_result debug_noinline
  482. ieee80211_tx_h_check_control_port_protocol(struct ieee80211_tx_data *tx)
  483. {
  484. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb);
  485. if (unlikely(tx->sdata->control_port_protocol == tx->skb->protocol)) {
  486. if (tx->sdata->control_port_no_encrypt)
  487. info->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
  488. info->control.flags |= IEEE80211_TX_CTRL_PORT_CTRL_PROTO;
  489. info->flags |= IEEE80211_TX_CTL_USE_MINRATE;
  490. }
  491. return TX_CONTINUE;
  492. }
  493. static ieee80211_tx_result debug_noinline
  494. ieee80211_tx_h_select_key(struct ieee80211_tx_data *tx)
  495. {
  496. struct ieee80211_key *key;
  497. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb);
  498. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx->skb->data;
  499. if (unlikely(info->flags & IEEE80211_TX_INTFL_DONT_ENCRYPT))
  500. tx->key = NULL;
  501. else if (tx->sta &&
  502. (key = rcu_dereference(tx->sta->ptk[tx->sta->ptk_idx])))
  503. tx->key = key;
  504. else if (ieee80211_is_mgmt(hdr->frame_control) &&
  505. is_multicast_ether_addr(hdr->addr1) &&
  506. ieee80211_is_robust_mgmt_frame(tx->skb) &&
  507. (key = rcu_dereference(tx->sdata->default_mgmt_key)))
  508. tx->key = key;
  509. else if (is_multicast_ether_addr(hdr->addr1) &&
  510. (key = rcu_dereference(tx->sdata->default_multicast_key)))
  511. tx->key = key;
  512. else if (!is_multicast_ether_addr(hdr->addr1) &&
  513. (key = rcu_dereference(tx->sdata->default_unicast_key)))
  514. tx->key = key;
  515. else
  516. tx->key = NULL;
  517. if (tx->key) {
  518. bool skip_hw = false;
  519. tx->key->tx_rx_count++;
  520. /* TODO: add threshold stuff again */
  521. switch (tx->key->conf.cipher) {
  522. case WLAN_CIPHER_SUITE_WEP40:
  523. case WLAN_CIPHER_SUITE_WEP104:
  524. case WLAN_CIPHER_SUITE_TKIP:
  525. if (!ieee80211_is_data_present(hdr->frame_control))
  526. tx->key = NULL;
  527. break;
  528. case WLAN_CIPHER_SUITE_CCMP:
  529. case WLAN_CIPHER_SUITE_CCMP_256:
  530. case WLAN_CIPHER_SUITE_GCMP:
  531. case WLAN_CIPHER_SUITE_GCMP_256:
  532. if (!ieee80211_is_data_present(hdr->frame_control) &&
  533. !ieee80211_use_mfp(hdr->frame_control, tx->sta,
  534. tx->skb))
  535. tx->key = NULL;
  536. else
  537. skip_hw = (tx->key->conf.flags &
  538. IEEE80211_KEY_FLAG_SW_MGMT_TX) &&
  539. ieee80211_is_mgmt(hdr->frame_control);
  540. break;
  541. case WLAN_CIPHER_SUITE_AES_CMAC:
  542. case WLAN_CIPHER_SUITE_BIP_CMAC_256:
  543. case WLAN_CIPHER_SUITE_BIP_GMAC_128:
  544. case WLAN_CIPHER_SUITE_BIP_GMAC_256:
  545. if (!ieee80211_is_mgmt(hdr->frame_control))
  546. tx->key = NULL;
  547. break;
  548. }
  549. if (unlikely(tx->key && tx->key->flags & KEY_FLAG_TAINTED &&
  550. !ieee80211_is_deauth(hdr->frame_control)))
  551. return TX_DROP;
  552. if (!skip_hw && tx->key &&
  553. tx->key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE)
  554. info->control.hw_key = &tx->key->conf;
  555. }
  556. return TX_CONTINUE;
  557. }
  558. static ieee80211_tx_result debug_noinline
  559. ieee80211_tx_h_rate_ctrl(struct ieee80211_tx_data *tx)
  560. {
  561. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb);
  562. struct ieee80211_hdr *hdr = (void *)tx->skb->data;
  563. struct ieee80211_supported_band *sband;
  564. u32 len;
  565. struct ieee80211_tx_rate_control txrc;
  566. struct ieee80211_sta_rates *ratetbl = NULL;
  567. bool assoc = false;
  568. memset(&txrc, 0, sizeof(txrc));
  569. sband = tx->local->hw.wiphy->bands[info->band];
  570. len = min_t(u32, tx->skb->len + FCS_LEN,
  571. tx->local->hw.wiphy->frag_threshold);
  572. /* set up the tx rate control struct we give the RC algo */
  573. txrc.hw = &tx->local->hw;
  574. txrc.sband = sband;
  575. txrc.bss_conf = &tx->sdata->vif.bss_conf;
  576. txrc.skb = tx->skb;
  577. txrc.reported_rate.idx = -1;
  578. txrc.rate_idx_mask = tx->sdata->rc_rateidx_mask[info->band];
  579. if (txrc.rate_idx_mask == (1 << sband->n_bitrates) - 1)
  580. txrc.max_rate_idx = -1;
  581. else
  582. txrc.max_rate_idx = fls(txrc.rate_idx_mask) - 1;
  583. if (tx->sdata->rc_has_mcs_mask[info->band])
  584. txrc.rate_idx_mcs_mask =
  585. tx->sdata->rc_rateidx_mcs_mask[info->band];
  586. txrc.bss = (tx->sdata->vif.type == NL80211_IFTYPE_AP ||
  587. tx->sdata->vif.type == NL80211_IFTYPE_MESH_POINT ||
  588. tx->sdata->vif.type == NL80211_IFTYPE_ADHOC);
  589. /* set up RTS protection if desired */
  590. if (len > tx->local->hw.wiphy->rts_threshold) {
  591. txrc.rts = true;
  592. }
  593. info->control.use_rts = txrc.rts;
  594. info->control.use_cts_prot = tx->sdata->vif.bss_conf.use_cts_prot;
  595. /*
  596. * Use short preamble if the BSS can handle it, but not for
  597. * management frames unless we know the receiver can handle
  598. * that -- the management frame might be to a station that
  599. * just wants a probe response.
  600. */
  601. if (tx->sdata->vif.bss_conf.use_short_preamble &&
  602. (ieee80211_is_data(hdr->frame_control) ||
  603. (tx->sta && test_sta_flag(tx->sta, WLAN_STA_SHORT_PREAMBLE))))
  604. txrc.short_preamble = true;
  605. info->control.short_preamble = txrc.short_preamble;
  606. if (tx->sta)
  607. assoc = test_sta_flag(tx->sta, WLAN_STA_ASSOC);
  608. /*
  609. * Lets not bother rate control if we're associated and cannot
  610. * talk to the sta. This should not happen.
  611. */
  612. if (WARN(test_bit(SCAN_SW_SCANNING, &tx->local->scanning) && assoc &&
  613. !rate_usable_index_exists(sband, &tx->sta->sta),
  614. "%s: Dropped data frame as no usable bitrate found while "
  615. "scanning and associated. Target station: "
  616. "%pM on %d GHz band\n",
  617. tx->sdata->name, hdr->addr1,
  618. info->band ? 5 : 2))
  619. return TX_DROP;
  620. /*
  621. * If we're associated with the sta at this point we know we can at
  622. * least send the frame at the lowest bit rate.
  623. */
  624. rate_control_get_rate(tx->sdata, tx->sta, &txrc);
  625. if (tx->sta && !info->control.skip_table)
  626. ratetbl = rcu_dereference(tx->sta->sta.rates);
  627. if (unlikely(info->control.rates[0].idx < 0)) {
  628. if (ratetbl) {
  629. struct ieee80211_tx_rate rate = {
  630. .idx = ratetbl->rate[0].idx,
  631. .flags = ratetbl->rate[0].flags,
  632. .count = ratetbl->rate[0].count
  633. };
  634. if (ratetbl->rate[0].idx < 0)
  635. return TX_DROP;
  636. tx->rate = rate;
  637. } else {
  638. return TX_DROP;
  639. }
  640. } else {
  641. tx->rate = info->control.rates[0];
  642. }
  643. if (txrc.reported_rate.idx < 0) {
  644. txrc.reported_rate = tx->rate;
  645. if (tx->sta && ieee80211_is_data(hdr->frame_control))
  646. tx->sta->last_tx_rate = txrc.reported_rate;
  647. } else if (tx->sta)
  648. tx->sta->last_tx_rate = txrc.reported_rate;
  649. if (ratetbl)
  650. return TX_CONTINUE;
  651. if (unlikely(!info->control.rates[0].count))
  652. info->control.rates[0].count = 1;
  653. if (WARN_ON_ONCE((info->control.rates[0].count > 1) &&
  654. (info->flags & IEEE80211_TX_CTL_NO_ACK)))
  655. info->control.rates[0].count = 1;
  656. return TX_CONTINUE;
  657. }
  658. static __le16 ieee80211_tx_next_seq(struct sta_info *sta, int tid)
  659. {
  660. u16 *seq = &sta->tid_seq[tid];
  661. __le16 ret = cpu_to_le16(*seq);
  662. /* Increase the sequence number. */
  663. *seq = (*seq + 0x10) & IEEE80211_SCTL_SEQ;
  664. return ret;
  665. }
  666. static ieee80211_tx_result debug_noinline
  667. ieee80211_tx_h_sequence(struct ieee80211_tx_data *tx)
  668. {
  669. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb);
  670. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)tx->skb->data;
  671. u8 *qc;
  672. int tid;
  673. /*
  674. * Packet injection may want to control the sequence
  675. * number, if we have no matching interface then we
  676. * neither assign one ourselves nor ask the driver to.
  677. */
  678. if (unlikely(info->control.vif->type == NL80211_IFTYPE_MONITOR))
  679. return TX_CONTINUE;
  680. if (unlikely(ieee80211_is_ctl(hdr->frame_control)))
  681. return TX_CONTINUE;
  682. if (ieee80211_hdrlen(hdr->frame_control) < 24)
  683. return TX_CONTINUE;
  684. if (ieee80211_is_qos_nullfunc(hdr->frame_control))
  685. return TX_CONTINUE;
  686. /*
  687. * Anything but QoS data that has a sequence number field
  688. * (is long enough) gets a sequence number from the global
  689. * counter. QoS data frames with a multicast destination
  690. * also use the global counter (802.11-2012 9.3.2.10).
  691. */
  692. if (!ieee80211_is_data_qos(hdr->frame_control) ||
  693. is_multicast_ether_addr(hdr->addr1)) {
  694. /* driver should assign sequence number */
  695. info->flags |= IEEE80211_TX_CTL_ASSIGN_SEQ;
  696. /* for pure STA mode without beacons, we can do it */
  697. hdr->seq_ctrl = cpu_to_le16(tx->sdata->sequence_number);
  698. tx->sdata->sequence_number += 0x10;
  699. if (tx->sta)
  700. tx->sta->tx_msdu[IEEE80211_NUM_TIDS]++;
  701. return TX_CONTINUE;
  702. }
  703. /*
  704. * This should be true for injected/management frames only, for
  705. * management frames we have set the IEEE80211_TX_CTL_ASSIGN_SEQ
  706. * above since they are not QoS-data frames.
  707. */
  708. if (!tx->sta)
  709. return TX_CONTINUE;
  710. /* include per-STA, per-TID sequence counter */
  711. qc = ieee80211_get_qos_ctl(hdr);
  712. tid = *qc & IEEE80211_QOS_CTL_TID_MASK;
  713. tx->sta->tx_msdu[tid]++;
  714. if (!tx->sta->sta.txq[0])
  715. hdr->seq_ctrl = ieee80211_tx_next_seq(tx->sta, tid);
  716. return TX_CONTINUE;
  717. }
  718. static int ieee80211_fragment(struct ieee80211_tx_data *tx,
  719. struct sk_buff *skb, int hdrlen,
  720. int frag_threshold)
  721. {
  722. struct ieee80211_local *local = tx->local;
  723. struct ieee80211_tx_info *info;
  724. struct sk_buff *tmp;
  725. int per_fragm = frag_threshold - hdrlen - FCS_LEN;
  726. int pos = hdrlen + per_fragm;
  727. int rem = skb->len - hdrlen - per_fragm;
  728. if (WARN_ON(rem < 0))
  729. return -EINVAL;
  730. /* first fragment was already added to queue by caller */
  731. while (rem) {
  732. int fraglen = per_fragm;
  733. if (fraglen > rem)
  734. fraglen = rem;
  735. rem -= fraglen;
  736. tmp = dev_alloc_skb(local->tx_headroom +
  737. frag_threshold +
  738. tx->sdata->encrypt_headroom +
  739. IEEE80211_ENCRYPT_TAILROOM);
  740. if (!tmp)
  741. return -ENOMEM;
  742. __skb_queue_tail(&tx->skbs, tmp);
  743. skb_reserve(tmp,
  744. local->tx_headroom + tx->sdata->encrypt_headroom);
  745. /* copy control information */
  746. memcpy(tmp->cb, skb->cb, sizeof(tmp->cb));
  747. info = IEEE80211_SKB_CB(tmp);
  748. info->flags &= ~(IEEE80211_TX_CTL_CLEAR_PS_FILT |
  749. IEEE80211_TX_CTL_FIRST_FRAGMENT);
  750. if (rem)
  751. info->flags |= IEEE80211_TX_CTL_MORE_FRAMES;
  752. skb_copy_queue_mapping(tmp, skb);
  753. tmp->priority = skb->priority;
  754. tmp->dev = skb->dev;
  755. /* copy header and data */
  756. memcpy(skb_put(tmp, hdrlen), skb->data, hdrlen);
  757. memcpy(skb_put(tmp, fraglen), skb->data + pos, fraglen);
  758. pos += fraglen;
  759. }
  760. /* adjust first fragment's length */
  761. skb_trim(skb, hdrlen + per_fragm);
  762. return 0;
  763. }
  764. static ieee80211_tx_result debug_noinline
  765. ieee80211_tx_h_fragment(struct ieee80211_tx_data *tx)
  766. {
  767. struct sk_buff *skb = tx->skb;
  768. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  769. struct ieee80211_hdr *hdr = (void *)skb->data;
  770. int frag_threshold = tx->local->hw.wiphy->frag_threshold;
  771. int hdrlen;
  772. int fragnum;
  773. /* no matter what happens, tx->skb moves to tx->skbs */
  774. __skb_queue_tail(&tx->skbs, skb);
  775. tx->skb = NULL;
  776. if (info->flags & IEEE80211_TX_CTL_DONTFRAG)
  777. return TX_CONTINUE;
  778. if (tx->local->ops->set_frag_threshold)
  779. return TX_CONTINUE;
  780. /*
  781. * Warn when submitting a fragmented A-MPDU frame and drop it.
  782. * This scenario is handled in ieee80211_tx_prepare but extra
  783. * caution taken here as fragmented ampdu may cause Tx stop.
  784. */
  785. if (WARN_ON(info->flags & IEEE80211_TX_CTL_AMPDU))
  786. return TX_DROP;
  787. hdrlen = ieee80211_hdrlen(hdr->frame_control);
  788. /* internal error, why isn't DONTFRAG set? */
  789. if (WARN_ON(skb->len + FCS_LEN <= frag_threshold))
  790. return TX_DROP;
  791. /*
  792. * Now fragment the frame. This will allocate all the fragments and
  793. * chain them (using skb as the first fragment) to skb->next.
  794. * During transmission, we will remove the successfully transmitted
  795. * fragments from this list. When the low-level driver rejects one
  796. * of the fragments then we will simply pretend to accept the skb
  797. * but store it away as pending.
  798. */
  799. if (ieee80211_fragment(tx, skb, hdrlen, frag_threshold))
  800. return TX_DROP;
  801. /* update duration/seq/flags of fragments */
  802. fragnum = 0;
  803. skb_queue_walk(&tx->skbs, skb) {
  804. const __le16 morefrags = cpu_to_le16(IEEE80211_FCTL_MOREFRAGS);
  805. hdr = (void *)skb->data;
  806. info = IEEE80211_SKB_CB(skb);
  807. if (!skb_queue_is_last(&tx->skbs, skb)) {
  808. hdr->frame_control |= morefrags;
  809. /*
  810. * No multi-rate retries for fragmented frames, that
  811. * would completely throw off the NAV at other STAs.
  812. */
  813. info->control.rates[1].idx = -1;
  814. info->control.rates[2].idx = -1;
  815. info->control.rates[3].idx = -1;
  816. BUILD_BUG_ON(IEEE80211_TX_MAX_RATES != 4);
  817. info->flags &= ~IEEE80211_TX_CTL_RATE_CTRL_PROBE;
  818. } else {
  819. hdr->frame_control &= ~morefrags;
  820. }
  821. hdr->seq_ctrl |= cpu_to_le16(fragnum & IEEE80211_SCTL_FRAG);
  822. fragnum++;
  823. }
  824. return TX_CONTINUE;
  825. }
  826. static ieee80211_tx_result debug_noinline
  827. ieee80211_tx_h_stats(struct ieee80211_tx_data *tx)
  828. {
  829. struct sk_buff *skb;
  830. int ac = -1;
  831. if (!tx->sta)
  832. return TX_CONTINUE;
  833. skb_queue_walk(&tx->skbs, skb) {
  834. ac = skb_get_queue_mapping(skb);
  835. tx->sta->tx_bytes[ac] += skb->len;
  836. }
  837. if (ac >= 0)
  838. tx->sta->tx_packets[ac]++;
  839. return TX_CONTINUE;
  840. }
  841. static ieee80211_tx_result debug_noinline
  842. ieee80211_tx_h_encrypt(struct ieee80211_tx_data *tx)
  843. {
  844. if (!tx->key)
  845. return TX_CONTINUE;
  846. switch (tx->key->conf.cipher) {
  847. case WLAN_CIPHER_SUITE_WEP40:
  848. case WLAN_CIPHER_SUITE_WEP104:
  849. return ieee80211_crypto_wep_encrypt(tx);
  850. case WLAN_CIPHER_SUITE_TKIP:
  851. return ieee80211_crypto_tkip_encrypt(tx);
  852. case WLAN_CIPHER_SUITE_CCMP:
  853. return ieee80211_crypto_ccmp_encrypt(
  854. tx, IEEE80211_CCMP_MIC_LEN);
  855. case WLAN_CIPHER_SUITE_CCMP_256:
  856. return ieee80211_crypto_ccmp_encrypt(
  857. tx, IEEE80211_CCMP_256_MIC_LEN);
  858. case WLAN_CIPHER_SUITE_AES_CMAC:
  859. return ieee80211_crypto_aes_cmac_encrypt(tx);
  860. case WLAN_CIPHER_SUITE_BIP_CMAC_256:
  861. return ieee80211_crypto_aes_cmac_256_encrypt(tx);
  862. case WLAN_CIPHER_SUITE_BIP_GMAC_128:
  863. case WLAN_CIPHER_SUITE_BIP_GMAC_256:
  864. return ieee80211_crypto_aes_gmac_encrypt(tx);
  865. case WLAN_CIPHER_SUITE_GCMP:
  866. case WLAN_CIPHER_SUITE_GCMP_256:
  867. return ieee80211_crypto_gcmp_encrypt(tx);
  868. default:
  869. return ieee80211_crypto_hw_encrypt(tx);
  870. }
  871. return TX_DROP;
  872. }
  873. static ieee80211_tx_result debug_noinline
  874. ieee80211_tx_h_calculate_duration(struct ieee80211_tx_data *tx)
  875. {
  876. struct sk_buff *skb;
  877. struct ieee80211_hdr *hdr;
  878. int next_len;
  879. bool group_addr;
  880. skb_queue_walk(&tx->skbs, skb) {
  881. hdr = (void *) skb->data;
  882. if (unlikely(ieee80211_is_pspoll(hdr->frame_control)))
  883. break; /* must not overwrite AID */
  884. if (!skb_queue_is_last(&tx->skbs, skb)) {
  885. struct sk_buff *next = skb_queue_next(&tx->skbs, skb);
  886. next_len = next->len;
  887. } else
  888. next_len = 0;
  889. group_addr = is_multicast_ether_addr(hdr->addr1);
  890. hdr->duration_id =
  891. ieee80211_duration(tx, skb, group_addr, next_len);
  892. }
  893. return TX_CONTINUE;
  894. }
  895. /* actual transmit path */
  896. static bool ieee80211_tx_prep_agg(struct ieee80211_tx_data *tx,
  897. struct sk_buff *skb,
  898. struct ieee80211_tx_info *info,
  899. struct tid_ampdu_tx *tid_tx,
  900. int tid)
  901. {
  902. bool queued = false;
  903. bool reset_agg_timer = false;
  904. struct sk_buff *purge_skb = NULL;
  905. if (test_bit(HT_AGG_STATE_OPERATIONAL, &tid_tx->state)) {
  906. info->flags |= IEEE80211_TX_CTL_AMPDU;
  907. reset_agg_timer = true;
  908. } else if (test_bit(HT_AGG_STATE_WANT_START, &tid_tx->state)) {
  909. /*
  910. * nothing -- this aggregation session is being started
  911. * but that might still fail with the driver
  912. */
  913. } else if (!tx->sta->sta.txq[tid]) {
  914. spin_lock(&tx->sta->lock);
  915. /*
  916. * Need to re-check now, because we may get here
  917. *
  918. * 1) in the window during which the setup is actually
  919. * already done, but not marked yet because not all
  920. * packets are spliced over to the driver pending
  921. * queue yet -- if this happened we acquire the lock
  922. * either before or after the splice happens, but
  923. * need to recheck which of these cases happened.
  924. *
  925. * 2) during session teardown, if the OPERATIONAL bit
  926. * was cleared due to the teardown but the pointer
  927. * hasn't been assigned NULL yet (or we loaded it
  928. * before it was assigned) -- in this case it may
  929. * now be NULL which means we should just let the
  930. * packet pass through because splicing the frames
  931. * back is already done.
  932. */
  933. tid_tx = rcu_dereference_protected_tid_tx(tx->sta, tid);
  934. if (!tid_tx) {
  935. /* do nothing, let packet pass through */
  936. } else if (test_bit(HT_AGG_STATE_OPERATIONAL, &tid_tx->state)) {
  937. info->flags |= IEEE80211_TX_CTL_AMPDU;
  938. reset_agg_timer = true;
  939. } else {
  940. queued = true;
  941. info->control.vif = &tx->sdata->vif;
  942. info->flags |= IEEE80211_TX_INTFL_NEED_TXPROCESSING;
  943. info->flags &= ~IEEE80211_TX_TEMPORARY_FLAGS;
  944. __skb_queue_tail(&tid_tx->pending, skb);
  945. if (skb_queue_len(&tid_tx->pending) > STA_MAX_TX_BUFFER)
  946. purge_skb = __skb_dequeue(&tid_tx->pending);
  947. }
  948. spin_unlock(&tx->sta->lock);
  949. if (purge_skb)
  950. ieee80211_free_txskb(&tx->local->hw, purge_skb);
  951. }
  952. /* reset session timer */
  953. if (reset_agg_timer && tid_tx->timeout)
  954. tid_tx->last_tx = jiffies;
  955. return queued;
  956. }
  957. /*
  958. * initialises @tx
  959. * pass %NULL for the station if unknown, a valid pointer if known
  960. * or an ERR_PTR() if the station is known not to exist
  961. */
  962. static ieee80211_tx_result
  963. ieee80211_tx_prepare(struct ieee80211_sub_if_data *sdata,
  964. struct ieee80211_tx_data *tx,
  965. struct sta_info *sta, struct sk_buff *skb)
  966. {
  967. struct ieee80211_local *local = sdata->local;
  968. struct ieee80211_hdr *hdr;
  969. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  970. int tid;
  971. u8 *qc;
  972. memset(tx, 0, sizeof(*tx));
  973. tx->skb = skb;
  974. tx->local = local;
  975. tx->sdata = sdata;
  976. __skb_queue_head_init(&tx->skbs);
  977. /*
  978. * If this flag is set to true anywhere, and we get here,
  979. * we are doing the needed processing, so remove the flag
  980. * now.
  981. */
  982. info->flags &= ~IEEE80211_TX_INTFL_NEED_TXPROCESSING;
  983. hdr = (struct ieee80211_hdr *) skb->data;
  984. if (likely(sta)) {
  985. if (!IS_ERR(sta))
  986. tx->sta = sta;
  987. } else {
  988. if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN) {
  989. tx->sta = rcu_dereference(sdata->u.vlan.sta);
  990. if (!tx->sta && sdata->wdev.use_4addr)
  991. return TX_DROP;
  992. } else if (info->flags & (IEEE80211_TX_INTFL_NL80211_FRAME_TX |
  993. IEEE80211_TX_CTL_INJECTED) ||
  994. tx->sdata->control_port_protocol == tx->skb->protocol) {
  995. tx->sta = sta_info_get_bss(sdata, hdr->addr1);
  996. }
  997. if (!tx->sta && !is_multicast_ether_addr(hdr->addr1))
  998. tx->sta = sta_info_get(sdata, hdr->addr1);
  999. }
  1000. if (tx->sta && ieee80211_is_data_qos(hdr->frame_control) &&
  1001. !ieee80211_is_qos_nullfunc(hdr->frame_control) &&
  1002. ieee80211_hw_check(&local->hw, AMPDU_AGGREGATION) &&
  1003. !ieee80211_hw_check(&local->hw, TX_AMPDU_SETUP_IN_HW)) {
  1004. struct tid_ampdu_tx *tid_tx;
  1005. qc = ieee80211_get_qos_ctl(hdr);
  1006. tid = *qc & IEEE80211_QOS_CTL_TID_MASK;
  1007. tid_tx = rcu_dereference(tx->sta->ampdu_mlme.tid_tx[tid]);
  1008. if (tid_tx) {
  1009. bool queued;
  1010. queued = ieee80211_tx_prep_agg(tx, skb, info,
  1011. tid_tx, tid);
  1012. if (unlikely(queued))
  1013. return TX_QUEUED;
  1014. }
  1015. }
  1016. if (is_multicast_ether_addr(hdr->addr1)) {
  1017. tx->flags &= ~IEEE80211_TX_UNICAST;
  1018. info->flags |= IEEE80211_TX_CTL_NO_ACK;
  1019. } else
  1020. tx->flags |= IEEE80211_TX_UNICAST;
  1021. if (!(info->flags & IEEE80211_TX_CTL_DONTFRAG)) {
  1022. if (!(tx->flags & IEEE80211_TX_UNICAST) ||
  1023. skb->len + FCS_LEN <= local->hw.wiphy->frag_threshold ||
  1024. info->flags & IEEE80211_TX_CTL_AMPDU)
  1025. info->flags |= IEEE80211_TX_CTL_DONTFRAG;
  1026. }
  1027. if (!tx->sta)
  1028. info->flags |= IEEE80211_TX_CTL_CLEAR_PS_FILT;
  1029. else if (test_and_clear_sta_flag(tx->sta, WLAN_STA_CLEAR_PS_FILT))
  1030. info->flags |= IEEE80211_TX_CTL_CLEAR_PS_FILT;
  1031. info->flags |= IEEE80211_TX_CTL_FIRST_FRAGMENT;
  1032. return TX_CONTINUE;
  1033. }
  1034. static void ieee80211_drv_tx(struct ieee80211_local *local,
  1035. struct ieee80211_vif *vif,
  1036. struct ieee80211_sta *pubsta,
  1037. struct sk_buff *skb)
  1038. {
  1039. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
  1040. struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
  1041. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  1042. struct ieee80211_tx_control control = {
  1043. .sta = pubsta,
  1044. };
  1045. struct ieee80211_txq *txq = NULL;
  1046. struct txq_info *txqi;
  1047. u8 ac;
  1048. if (info->control.flags & IEEE80211_TX_CTRL_PS_RESPONSE)
  1049. goto tx_normal;
  1050. if (!ieee80211_is_data(hdr->frame_control))
  1051. goto tx_normal;
  1052. if (pubsta) {
  1053. u8 tid = skb->priority & IEEE80211_QOS_CTL_TID_MASK;
  1054. txq = pubsta->txq[tid];
  1055. } else if (vif) {
  1056. txq = vif->txq;
  1057. }
  1058. if (!txq)
  1059. goto tx_normal;
  1060. ac = txq->ac;
  1061. txqi = to_txq_info(txq);
  1062. atomic_inc(&sdata->txqs_len[ac]);
  1063. if (atomic_read(&sdata->txqs_len[ac]) >= local->hw.txq_ac_max_pending)
  1064. netif_stop_subqueue(sdata->dev, ac);
  1065. skb_queue_tail(&txqi->queue, skb);
  1066. drv_wake_tx_queue(local, txqi);
  1067. return;
  1068. tx_normal:
  1069. drv_tx(local, &control, skb);
  1070. }
  1071. struct sk_buff *ieee80211_tx_dequeue(struct ieee80211_hw *hw,
  1072. struct ieee80211_txq *txq)
  1073. {
  1074. struct ieee80211_local *local = hw_to_local(hw);
  1075. struct ieee80211_sub_if_data *sdata = vif_to_sdata(txq->vif);
  1076. struct txq_info *txqi = container_of(txq, struct txq_info, txq);
  1077. struct ieee80211_hdr *hdr;
  1078. struct sk_buff *skb = NULL;
  1079. u8 ac = txq->ac;
  1080. spin_lock_bh(&txqi->queue.lock);
  1081. if (test_bit(IEEE80211_TXQ_STOP, &txqi->flags))
  1082. goto out;
  1083. skb = __skb_dequeue(&txqi->queue);
  1084. if (!skb)
  1085. goto out;
  1086. atomic_dec(&sdata->txqs_len[ac]);
  1087. if (__netif_subqueue_stopped(sdata->dev, ac))
  1088. ieee80211_propagate_queue_wake(local, sdata->vif.hw_queue[ac]);
  1089. hdr = (struct ieee80211_hdr *)skb->data;
  1090. if (txq->sta && ieee80211_is_data_qos(hdr->frame_control)) {
  1091. struct sta_info *sta = container_of(txq->sta, struct sta_info,
  1092. sta);
  1093. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  1094. hdr->seq_ctrl = ieee80211_tx_next_seq(sta, txq->tid);
  1095. if (test_bit(IEEE80211_TXQ_AMPDU, &txqi->flags))
  1096. info->flags |= IEEE80211_TX_CTL_AMPDU;
  1097. else
  1098. info->flags &= ~IEEE80211_TX_CTL_AMPDU;
  1099. }
  1100. out:
  1101. spin_unlock_bh(&txqi->queue.lock);
  1102. return skb;
  1103. }
  1104. EXPORT_SYMBOL(ieee80211_tx_dequeue);
  1105. static bool ieee80211_tx_frags(struct ieee80211_local *local,
  1106. struct ieee80211_vif *vif,
  1107. struct ieee80211_sta *sta,
  1108. struct sk_buff_head *skbs,
  1109. bool txpending)
  1110. {
  1111. struct sk_buff *skb, *tmp;
  1112. unsigned long flags;
  1113. skb_queue_walk_safe(skbs, skb, tmp) {
  1114. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  1115. int q = info->hw_queue;
  1116. #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
  1117. if (WARN_ON_ONCE(q >= local->hw.queues)) {
  1118. __skb_unlink(skb, skbs);
  1119. ieee80211_free_txskb(&local->hw, skb);
  1120. continue;
  1121. }
  1122. #endif
  1123. spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
  1124. if (local->queue_stop_reasons[q] ||
  1125. (!txpending && !skb_queue_empty(&local->pending[q]))) {
  1126. if (unlikely(info->flags &
  1127. IEEE80211_TX_INTFL_OFFCHAN_TX_OK)) {
  1128. if (local->queue_stop_reasons[q] &
  1129. ~BIT(IEEE80211_QUEUE_STOP_REASON_OFFCHANNEL)) {
  1130. /*
  1131. * Drop off-channel frames if queues
  1132. * are stopped for any reason other
  1133. * than off-channel operation. Never
  1134. * queue them.
  1135. */
  1136. spin_unlock_irqrestore(
  1137. &local->queue_stop_reason_lock,
  1138. flags);
  1139. ieee80211_purge_tx_queue(&local->hw,
  1140. skbs);
  1141. return true;
  1142. }
  1143. } else {
  1144. /*
  1145. * Since queue is stopped, queue up frames for
  1146. * later transmission from the tx-pending
  1147. * tasklet when the queue is woken again.
  1148. */
  1149. if (txpending)
  1150. skb_queue_splice_init(skbs,
  1151. &local->pending[q]);
  1152. else
  1153. skb_queue_splice_tail_init(skbs,
  1154. &local->pending[q]);
  1155. spin_unlock_irqrestore(&local->queue_stop_reason_lock,
  1156. flags);
  1157. return false;
  1158. }
  1159. }
  1160. spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
  1161. info->control.vif = vif;
  1162. __skb_unlink(skb, skbs);
  1163. ieee80211_drv_tx(local, vif, sta, skb);
  1164. }
  1165. return true;
  1166. }
  1167. /*
  1168. * Returns false if the frame couldn't be transmitted but was queued instead.
  1169. */
  1170. static bool __ieee80211_tx(struct ieee80211_local *local,
  1171. struct sk_buff_head *skbs, int led_len,
  1172. struct sta_info *sta, bool txpending)
  1173. {
  1174. struct ieee80211_tx_info *info;
  1175. struct ieee80211_sub_if_data *sdata;
  1176. struct ieee80211_vif *vif;
  1177. struct ieee80211_sta *pubsta;
  1178. struct sk_buff *skb;
  1179. bool result = true;
  1180. __le16 fc;
  1181. if (WARN_ON(skb_queue_empty(skbs)))
  1182. return true;
  1183. skb = skb_peek(skbs);
  1184. fc = ((struct ieee80211_hdr *)skb->data)->frame_control;
  1185. info = IEEE80211_SKB_CB(skb);
  1186. sdata = vif_to_sdata(info->control.vif);
  1187. if (sta && !sta->uploaded)
  1188. sta = NULL;
  1189. if (sta)
  1190. pubsta = &sta->sta;
  1191. else
  1192. pubsta = NULL;
  1193. switch (sdata->vif.type) {
  1194. case NL80211_IFTYPE_MONITOR:
  1195. if (sdata->u.mntr_flags & MONITOR_FLAG_ACTIVE) {
  1196. vif = &sdata->vif;
  1197. break;
  1198. }
  1199. sdata = rcu_dereference(local->monitor_sdata);
  1200. if (sdata) {
  1201. vif = &sdata->vif;
  1202. info->hw_queue =
  1203. vif->hw_queue[skb_get_queue_mapping(skb)];
  1204. } else if (ieee80211_hw_check(&local->hw, QUEUE_CONTROL)) {
  1205. dev_kfree_skb(skb);
  1206. return true;
  1207. } else
  1208. vif = NULL;
  1209. break;
  1210. case NL80211_IFTYPE_AP_VLAN:
  1211. sdata = container_of(sdata->bss,
  1212. struct ieee80211_sub_if_data, u.ap);
  1213. /* fall through */
  1214. default:
  1215. vif = &sdata->vif;
  1216. break;
  1217. }
  1218. result = ieee80211_tx_frags(local, vif, pubsta, skbs,
  1219. txpending);
  1220. ieee80211_tpt_led_trig_tx(local, fc, led_len);
  1221. WARN_ON_ONCE(!skb_queue_empty(skbs));
  1222. return result;
  1223. }
  1224. /*
  1225. * Invoke TX handlers, return 0 on success and non-zero if the
  1226. * frame was dropped or queued.
  1227. */
  1228. static int invoke_tx_handlers(struct ieee80211_tx_data *tx)
  1229. {
  1230. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(tx->skb);
  1231. ieee80211_tx_result res = TX_DROP;
  1232. #define CALL_TXH(txh) \
  1233. do { \
  1234. res = txh(tx); \
  1235. if (res != TX_CONTINUE) \
  1236. goto txh_done; \
  1237. } while (0)
  1238. CALL_TXH(ieee80211_tx_h_dynamic_ps);
  1239. CALL_TXH(ieee80211_tx_h_check_assoc);
  1240. CALL_TXH(ieee80211_tx_h_ps_buf);
  1241. CALL_TXH(ieee80211_tx_h_check_control_port_protocol);
  1242. CALL_TXH(ieee80211_tx_h_select_key);
  1243. if (!ieee80211_hw_check(&tx->local->hw, HAS_RATE_CONTROL))
  1244. CALL_TXH(ieee80211_tx_h_rate_ctrl);
  1245. if (unlikely(info->flags & IEEE80211_TX_INTFL_RETRANSMISSION)) {
  1246. __skb_queue_tail(&tx->skbs, tx->skb);
  1247. tx->skb = NULL;
  1248. goto txh_done;
  1249. }
  1250. CALL_TXH(ieee80211_tx_h_michael_mic_add);
  1251. CALL_TXH(ieee80211_tx_h_sequence);
  1252. CALL_TXH(ieee80211_tx_h_fragment);
  1253. /* handlers after fragment must be aware of tx info fragmentation! */
  1254. CALL_TXH(ieee80211_tx_h_stats);
  1255. CALL_TXH(ieee80211_tx_h_encrypt);
  1256. if (!ieee80211_hw_check(&tx->local->hw, HAS_RATE_CONTROL))
  1257. CALL_TXH(ieee80211_tx_h_calculate_duration);
  1258. #undef CALL_TXH
  1259. txh_done:
  1260. if (unlikely(res == TX_DROP)) {
  1261. I802_DEBUG_INC(tx->local->tx_handlers_drop);
  1262. if (tx->skb)
  1263. ieee80211_free_txskb(&tx->local->hw, tx->skb);
  1264. else
  1265. ieee80211_purge_tx_queue(&tx->local->hw, &tx->skbs);
  1266. return -1;
  1267. } else if (unlikely(res == TX_QUEUED)) {
  1268. I802_DEBUG_INC(tx->local->tx_handlers_queued);
  1269. return -1;
  1270. }
  1271. return 0;
  1272. }
  1273. bool ieee80211_tx_prepare_skb(struct ieee80211_hw *hw,
  1274. struct ieee80211_vif *vif, struct sk_buff *skb,
  1275. int band, struct ieee80211_sta **sta)
  1276. {
  1277. struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
  1278. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  1279. struct ieee80211_tx_data tx;
  1280. struct sk_buff *skb2;
  1281. if (ieee80211_tx_prepare(sdata, &tx, NULL, skb) == TX_DROP)
  1282. return false;
  1283. info->band = band;
  1284. info->control.vif = vif;
  1285. info->hw_queue = vif->hw_queue[skb_get_queue_mapping(skb)];
  1286. if (invoke_tx_handlers(&tx))
  1287. return false;
  1288. if (sta) {
  1289. if (tx.sta)
  1290. *sta = &tx.sta->sta;
  1291. else
  1292. *sta = NULL;
  1293. }
  1294. /* this function isn't suitable for fragmented data frames */
  1295. skb2 = __skb_dequeue(&tx.skbs);
  1296. if (WARN_ON(skb2 != skb || !skb_queue_empty(&tx.skbs))) {
  1297. ieee80211_free_txskb(hw, skb2);
  1298. ieee80211_purge_tx_queue(hw, &tx.skbs);
  1299. return false;
  1300. }
  1301. return true;
  1302. }
  1303. EXPORT_SYMBOL(ieee80211_tx_prepare_skb);
  1304. /*
  1305. * Returns false if the frame couldn't be transmitted but was queued instead.
  1306. */
  1307. static bool ieee80211_tx(struct ieee80211_sub_if_data *sdata,
  1308. struct sta_info *sta, struct sk_buff *skb,
  1309. bool txpending)
  1310. {
  1311. struct ieee80211_local *local = sdata->local;
  1312. struct ieee80211_tx_data tx;
  1313. ieee80211_tx_result res_prepare;
  1314. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  1315. bool result = true;
  1316. int led_len;
  1317. if (unlikely(skb->len < 10)) {
  1318. dev_kfree_skb(skb);
  1319. return true;
  1320. }
  1321. /* initialises tx */
  1322. led_len = skb->len;
  1323. res_prepare = ieee80211_tx_prepare(sdata, &tx, sta, skb);
  1324. if (unlikely(res_prepare == TX_DROP)) {
  1325. ieee80211_free_txskb(&local->hw, skb);
  1326. return true;
  1327. } else if (unlikely(res_prepare == TX_QUEUED)) {
  1328. return true;
  1329. }
  1330. /* set up hw_queue value early */
  1331. if (!(info->flags & IEEE80211_TX_CTL_TX_OFFCHAN) ||
  1332. !ieee80211_hw_check(&local->hw, QUEUE_CONTROL))
  1333. info->hw_queue =
  1334. sdata->vif.hw_queue[skb_get_queue_mapping(skb)];
  1335. if (!invoke_tx_handlers(&tx))
  1336. result = __ieee80211_tx(local, &tx.skbs, led_len,
  1337. tx.sta, txpending);
  1338. return result;
  1339. }
  1340. /* device xmit handlers */
  1341. static int ieee80211_skb_resize(struct ieee80211_sub_if_data *sdata,
  1342. struct sk_buff *skb,
  1343. int head_need, bool may_encrypt)
  1344. {
  1345. struct ieee80211_local *local = sdata->local;
  1346. int tail_need = 0;
  1347. if (may_encrypt && sdata->crypto_tx_tailroom_needed_cnt) {
  1348. tail_need = IEEE80211_ENCRYPT_TAILROOM;
  1349. tail_need -= skb_tailroom(skb);
  1350. tail_need = max_t(int, tail_need, 0);
  1351. }
  1352. if (skb_cloned(skb) &&
  1353. (!ieee80211_hw_check(&local->hw, SUPPORTS_CLONED_SKBS) ||
  1354. !skb_clone_writable(skb, ETH_HLEN) ||
  1355. (may_encrypt && sdata->crypto_tx_tailroom_needed_cnt)))
  1356. I802_DEBUG_INC(local->tx_expand_skb_head_cloned);
  1357. else if (head_need || tail_need)
  1358. I802_DEBUG_INC(local->tx_expand_skb_head);
  1359. else
  1360. return 0;
  1361. if (pskb_expand_head(skb, head_need, tail_need, GFP_ATOMIC)) {
  1362. wiphy_debug(local->hw.wiphy,
  1363. "failed to reallocate TX buffer\n");
  1364. return -ENOMEM;
  1365. }
  1366. return 0;
  1367. }
  1368. void ieee80211_xmit(struct ieee80211_sub_if_data *sdata,
  1369. struct sta_info *sta, struct sk_buff *skb)
  1370. {
  1371. struct ieee80211_local *local = sdata->local;
  1372. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  1373. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
  1374. int headroom;
  1375. bool may_encrypt;
  1376. may_encrypt = !(info->flags & IEEE80211_TX_INTFL_DONT_ENCRYPT);
  1377. headroom = local->tx_headroom;
  1378. if (may_encrypt)
  1379. headroom += sdata->encrypt_headroom;
  1380. headroom -= skb_headroom(skb);
  1381. headroom = max_t(int, 0, headroom);
  1382. if (ieee80211_skb_resize(sdata, skb, headroom, may_encrypt)) {
  1383. ieee80211_free_txskb(&local->hw, skb);
  1384. return;
  1385. }
  1386. hdr = (struct ieee80211_hdr *) skb->data;
  1387. info->control.vif = &sdata->vif;
  1388. if (ieee80211_vif_is_mesh(&sdata->vif)) {
  1389. if (ieee80211_is_data(hdr->frame_control) &&
  1390. is_unicast_ether_addr(hdr->addr1)) {
  1391. if (mesh_nexthop_resolve(sdata, skb))
  1392. return; /* skb queued: don't free */
  1393. } else {
  1394. ieee80211_mps_set_frame_flags(sdata, NULL, hdr);
  1395. }
  1396. }
  1397. ieee80211_set_qos_hdr(sdata, skb);
  1398. ieee80211_tx(sdata, sta, skb, false);
  1399. }
  1400. static bool ieee80211_parse_tx_radiotap(struct sk_buff *skb)
  1401. {
  1402. struct ieee80211_radiotap_iterator iterator;
  1403. struct ieee80211_radiotap_header *rthdr =
  1404. (struct ieee80211_radiotap_header *) skb->data;
  1405. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  1406. int ret = ieee80211_radiotap_iterator_init(&iterator, rthdr, skb->len,
  1407. NULL);
  1408. u16 txflags;
  1409. info->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT |
  1410. IEEE80211_TX_CTL_DONTFRAG;
  1411. /*
  1412. * for every radiotap entry that is present
  1413. * (ieee80211_radiotap_iterator_next returns -ENOENT when no more
  1414. * entries present, or -EINVAL on error)
  1415. */
  1416. while (!ret) {
  1417. ret = ieee80211_radiotap_iterator_next(&iterator);
  1418. if (ret)
  1419. continue;
  1420. /* see if this argument is something we can use */
  1421. switch (iterator.this_arg_index) {
  1422. /*
  1423. * You must take care when dereferencing iterator.this_arg
  1424. * for multibyte types... the pointer is not aligned. Use
  1425. * get_unaligned((type *)iterator.this_arg) to dereference
  1426. * iterator.this_arg for type "type" safely on all arches.
  1427. */
  1428. case IEEE80211_RADIOTAP_FLAGS:
  1429. if (*iterator.this_arg & IEEE80211_RADIOTAP_F_FCS) {
  1430. /*
  1431. * this indicates that the skb we have been
  1432. * handed has the 32-bit FCS CRC at the end...
  1433. * we should react to that by snipping it off
  1434. * because it will be recomputed and added
  1435. * on transmission
  1436. */
  1437. if (skb->len < (iterator._max_length + FCS_LEN))
  1438. return false;
  1439. skb_trim(skb, skb->len - FCS_LEN);
  1440. }
  1441. if (*iterator.this_arg & IEEE80211_RADIOTAP_F_WEP)
  1442. info->flags &= ~IEEE80211_TX_INTFL_DONT_ENCRYPT;
  1443. if (*iterator.this_arg & IEEE80211_RADIOTAP_F_FRAG)
  1444. info->flags &= ~IEEE80211_TX_CTL_DONTFRAG;
  1445. break;
  1446. case IEEE80211_RADIOTAP_TX_FLAGS:
  1447. txflags = get_unaligned_le16(iterator.this_arg);
  1448. if (txflags & IEEE80211_RADIOTAP_F_TX_NOACK)
  1449. info->flags |= IEEE80211_TX_CTL_NO_ACK;
  1450. break;
  1451. /*
  1452. * Please update the file
  1453. * Documentation/networking/mac80211-injection.txt
  1454. * when parsing new fields here.
  1455. */
  1456. default:
  1457. break;
  1458. }
  1459. }
  1460. if (ret != -ENOENT) /* ie, if we didn't simply run out of fields */
  1461. return false;
  1462. /*
  1463. * remove the radiotap header
  1464. * iterator->_max_length was sanity-checked against
  1465. * skb->len by iterator init
  1466. */
  1467. skb_pull(skb, iterator._max_length);
  1468. return true;
  1469. }
  1470. netdev_tx_t ieee80211_monitor_start_xmit(struct sk_buff *skb,
  1471. struct net_device *dev)
  1472. {
  1473. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  1474. struct ieee80211_chanctx_conf *chanctx_conf;
  1475. struct ieee80211_radiotap_header *prthdr =
  1476. (struct ieee80211_radiotap_header *)skb->data;
  1477. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  1478. struct ieee80211_hdr *hdr;
  1479. struct ieee80211_sub_if_data *tmp_sdata, *sdata;
  1480. struct cfg80211_chan_def *chandef;
  1481. u16 len_rthdr;
  1482. int hdrlen;
  1483. /* check for not even having the fixed radiotap header part */
  1484. if (unlikely(skb->len < sizeof(struct ieee80211_radiotap_header)))
  1485. goto fail; /* too short to be possibly valid */
  1486. /* is it a header version we can trust to find length from? */
  1487. if (unlikely(prthdr->it_version))
  1488. goto fail; /* only version 0 is supported */
  1489. /* then there must be a radiotap header with a length we can use */
  1490. len_rthdr = ieee80211_get_radiotap_len(skb->data);
  1491. /* does the skb contain enough to deliver on the alleged length? */
  1492. if (unlikely(skb->len < len_rthdr))
  1493. goto fail; /* skb too short for claimed rt header extent */
  1494. /*
  1495. * fix up the pointers accounting for the radiotap
  1496. * header still being in there. We are being given
  1497. * a precooked IEEE80211 header so no need for
  1498. * normal processing
  1499. */
  1500. skb_set_mac_header(skb, len_rthdr);
  1501. /*
  1502. * these are just fixed to the end of the rt area since we
  1503. * don't have any better information and at this point, nobody cares
  1504. */
  1505. skb_set_network_header(skb, len_rthdr);
  1506. skb_set_transport_header(skb, len_rthdr);
  1507. if (skb->len < len_rthdr + 2)
  1508. goto fail;
  1509. hdr = (struct ieee80211_hdr *)(skb->data + len_rthdr);
  1510. hdrlen = ieee80211_hdrlen(hdr->frame_control);
  1511. if (skb->len < len_rthdr + hdrlen)
  1512. goto fail;
  1513. /*
  1514. * Initialize skb->protocol if the injected frame is a data frame
  1515. * carrying a rfc1042 header
  1516. */
  1517. if (ieee80211_is_data(hdr->frame_control) &&
  1518. skb->len >= len_rthdr + hdrlen + sizeof(rfc1042_header) + 2) {
  1519. u8 *payload = (u8 *)hdr + hdrlen;
  1520. if (ether_addr_equal(payload, rfc1042_header))
  1521. skb->protocol = cpu_to_be16((payload[6] << 8) |
  1522. payload[7]);
  1523. }
  1524. memset(info, 0, sizeof(*info));
  1525. info->flags = IEEE80211_TX_CTL_REQ_TX_STATUS |
  1526. IEEE80211_TX_CTL_INJECTED;
  1527. /* process and remove the injection radiotap header */
  1528. if (!ieee80211_parse_tx_radiotap(skb))
  1529. goto fail;
  1530. rcu_read_lock();
  1531. /*
  1532. * We process outgoing injected frames that have a local address
  1533. * we handle as though they are non-injected frames.
  1534. * This code here isn't entirely correct, the local MAC address
  1535. * isn't always enough to find the interface to use; for proper
  1536. * VLAN/WDS support we will need a different mechanism (which
  1537. * likely isn't going to be monitor interfaces).
  1538. */
  1539. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1540. list_for_each_entry_rcu(tmp_sdata, &local->interfaces, list) {
  1541. if (!ieee80211_sdata_running(tmp_sdata))
  1542. continue;
  1543. if (tmp_sdata->vif.type == NL80211_IFTYPE_MONITOR ||
  1544. tmp_sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
  1545. tmp_sdata->vif.type == NL80211_IFTYPE_WDS)
  1546. continue;
  1547. if (ether_addr_equal(tmp_sdata->vif.addr, hdr->addr2)) {
  1548. sdata = tmp_sdata;
  1549. break;
  1550. }
  1551. }
  1552. chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
  1553. if (!chanctx_conf) {
  1554. tmp_sdata = rcu_dereference(local->monitor_sdata);
  1555. if (tmp_sdata)
  1556. chanctx_conf =
  1557. rcu_dereference(tmp_sdata->vif.chanctx_conf);
  1558. }
  1559. if (chanctx_conf)
  1560. chandef = &chanctx_conf->def;
  1561. else if (!local->use_chanctx)
  1562. chandef = &local->_oper_chandef;
  1563. else
  1564. goto fail_rcu;
  1565. /*
  1566. * Frame injection is not allowed if beaconing is not allowed
  1567. * or if we need radar detection. Beaconing is usually not allowed when
  1568. * the mode or operation (Adhoc, AP, Mesh) does not support DFS.
  1569. * Passive scan is also used in world regulatory domains where
  1570. * your country is not known and as such it should be treated as
  1571. * NO TX unless the channel is explicitly allowed in which case
  1572. * your current regulatory domain would not have the passive scan
  1573. * flag.
  1574. *
  1575. * Since AP mode uses monitor interfaces to inject/TX management
  1576. * frames we can make AP mode the exception to this rule once it
  1577. * supports radar detection as its implementation can deal with
  1578. * radar detection by itself. We can do that later by adding a
  1579. * monitor flag interfaces used for AP support.
  1580. */
  1581. if (!cfg80211_reg_can_beacon(local->hw.wiphy, chandef,
  1582. sdata->vif.type))
  1583. goto fail_rcu;
  1584. info->band = chandef->chan->band;
  1585. ieee80211_xmit(sdata, NULL, skb);
  1586. rcu_read_unlock();
  1587. return NETDEV_TX_OK;
  1588. fail_rcu:
  1589. rcu_read_unlock();
  1590. fail:
  1591. dev_kfree_skb(skb);
  1592. return NETDEV_TX_OK; /* meaning, we dealt with the skb */
  1593. }
  1594. static inline bool ieee80211_is_tdls_setup(struct sk_buff *skb)
  1595. {
  1596. u16 ethertype = (skb->data[12] << 8) | skb->data[13];
  1597. return ethertype == ETH_P_TDLS &&
  1598. skb->len > 14 &&
  1599. skb->data[14] == WLAN_TDLS_SNAP_RFTYPE;
  1600. }
  1601. static int ieee80211_lookup_ra_sta(struct ieee80211_sub_if_data *sdata,
  1602. struct sk_buff *skb,
  1603. struct sta_info **sta_out)
  1604. {
  1605. struct sta_info *sta;
  1606. switch (sdata->vif.type) {
  1607. case NL80211_IFTYPE_AP_VLAN:
  1608. sta = rcu_dereference(sdata->u.vlan.sta);
  1609. if (sta) {
  1610. *sta_out = sta;
  1611. return 0;
  1612. } else if (sdata->wdev.use_4addr) {
  1613. return -ENOLINK;
  1614. }
  1615. /* fall through */
  1616. case NL80211_IFTYPE_AP:
  1617. case NL80211_IFTYPE_OCB:
  1618. case NL80211_IFTYPE_ADHOC:
  1619. if (is_multicast_ether_addr(skb->data)) {
  1620. *sta_out = ERR_PTR(-ENOENT);
  1621. return 0;
  1622. }
  1623. sta = sta_info_get_bss(sdata, skb->data);
  1624. break;
  1625. case NL80211_IFTYPE_WDS:
  1626. sta = sta_info_get(sdata, sdata->u.wds.remote_addr);
  1627. break;
  1628. #ifdef CONFIG_MAC80211_MESH
  1629. case NL80211_IFTYPE_MESH_POINT:
  1630. /* determined much later */
  1631. *sta_out = NULL;
  1632. return 0;
  1633. #endif
  1634. case NL80211_IFTYPE_STATION:
  1635. if (sdata->wdev.wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS) {
  1636. sta = sta_info_get(sdata, skb->data);
  1637. if (sta) {
  1638. bool tdls_peer, tdls_auth;
  1639. tdls_peer = test_sta_flag(sta,
  1640. WLAN_STA_TDLS_PEER);
  1641. tdls_auth = test_sta_flag(sta,
  1642. WLAN_STA_TDLS_PEER_AUTH);
  1643. if (tdls_peer && tdls_auth) {
  1644. *sta_out = sta;
  1645. return 0;
  1646. }
  1647. /*
  1648. * TDLS link during setup - throw out frames to
  1649. * peer. Allow TDLS-setup frames to unauthorized
  1650. * peers for the special case of a link teardown
  1651. * after a TDLS sta is removed due to being
  1652. * unreachable.
  1653. */
  1654. if (tdls_peer && !tdls_auth &&
  1655. !ieee80211_is_tdls_setup(skb))
  1656. return -EINVAL;
  1657. }
  1658. }
  1659. sta = sta_info_get(sdata, sdata->u.mgd.bssid);
  1660. if (!sta)
  1661. return -ENOLINK;
  1662. break;
  1663. default:
  1664. return -EINVAL;
  1665. }
  1666. *sta_out = sta ?: ERR_PTR(-ENOENT);
  1667. return 0;
  1668. }
  1669. /**
  1670. * ieee80211_build_hdr - build 802.11 header in the given frame
  1671. * @sdata: virtual interface to build the header for
  1672. * @skb: the skb to build the header in
  1673. * @info_flags: skb flags to set
  1674. *
  1675. * This function takes the skb with 802.3 header and reformats the header to
  1676. * the appropriate IEEE 802.11 header based on which interface the packet is
  1677. * being transmitted on.
  1678. *
  1679. * Note that this function also takes care of the TX status request and
  1680. * potential unsharing of the SKB - this needs to be interleaved with the
  1681. * header building.
  1682. *
  1683. * The function requires the read-side RCU lock held
  1684. *
  1685. * Returns: the (possibly reallocated) skb or an ERR_PTR() code
  1686. */
  1687. static struct sk_buff *ieee80211_build_hdr(struct ieee80211_sub_if_data *sdata,
  1688. struct sk_buff *skb, u32 info_flags,
  1689. struct sta_info *sta)
  1690. {
  1691. struct ieee80211_local *local = sdata->local;
  1692. struct ieee80211_tx_info *info;
  1693. int head_need;
  1694. u16 ethertype, hdrlen, meshhdrlen = 0;
  1695. __le16 fc;
  1696. struct ieee80211_hdr hdr;
  1697. struct ieee80211s_hdr mesh_hdr __maybe_unused;
  1698. struct mesh_path __maybe_unused *mppath = NULL, *mpath = NULL;
  1699. const u8 *encaps_data;
  1700. int encaps_len, skip_header_bytes;
  1701. int nh_pos, h_pos;
  1702. bool wme_sta = false, authorized = false;
  1703. bool tdls_peer;
  1704. bool multicast;
  1705. u16 info_id = 0;
  1706. struct ieee80211_chanctx_conf *chanctx_conf;
  1707. struct ieee80211_sub_if_data *ap_sdata;
  1708. enum ieee80211_band band;
  1709. int ret;
  1710. if (IS_ERR(sta))
  1711. sta = NULL;
  1712. /* convert Ethernet header to proper 802.11 header (based on
  1713. * operation mode) */
  1714. ethertype = (skb->data[12] << 8) | skb->data[13];
  1715. fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_DATA);
  1716. switch (sdata->vif.type) {
  1717. case NL80211_IFTYPE_AP_VLAN:
  1718. if (sdata->wdev.use_4addr) {
  1719. fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS);
  1720. /* RA TA DA SA */
  1721. memcpy(hdr.addr1, sta->sta.addr, ETH_ALEN);
  1722. memcpy(hdr.addr2, sdata->vif.addr, ETH_ALEN);
  1723. memcpy(hdr.addr3, skb->data, ETH_ALEN);
  1724. memcpy(hdr.addr4, skb->data + ETH_ALEN, ETH_ALEN);
  1725. hdrlen = 30;
  1726. authorized = test_sta_flag(sta, WLAN_STA_AUTHORIZED);
  1727. wme_sta = sta->sta.wme;
  1728. }
  1729. ap_sdata = container_of(sdata->bss, struct ieee80211_sub_if_data,
  1730. u.ap);
  1731. chanctx_conf = rcu_dereference(ap_sdata->vif.chanctx_conf);
  1732. if (!chanctx_conf) {
  1733. ret = -ENOTCONN;
  1734. goto free;
  1735. }
  1736. band = chanctx_conf->def.chan->band;
  1737. if (sdata->wdev.use_4addr)
  1738. break;
  1739. /* fall through */
  1740. case NL80211_IFTYPE_AP:
  1741. if (sdata->vif.type == NL80211_IFTYPE_AP)
  1742. chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
  1743. if (!chanctx_conf) {
  1744. ret = -ENOTCONN;
  1745. goto free;
  1746. }
  1747. fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS);
  1748. /* DA BSSID SA */
  1749. memcpy(hdr.addr1, skb->data, ETH_ALEN);
  1750. memcpy(hdr.addr2, sdata->vif.addr, ETH_ALEN);
  1751. memcpy(hdr.addr3, skb->data + ETH_ALEN, ETH_ALEN);
  1752. hdrlen = 24;
  1753. band = chanctx_conf->def.chan->band;
  1754. break;
  1755. case NL80211_IFTYPE_WDS:
  1756. fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS);
  1757. /* RA TA DA SA */
  1758. memcpy(hdr.addr1, sdata->u.wds.remote_addr, ETH_ALEN);
  1759. memcpy(hdr.addr2, sdata->vif.addr, ETH_ALEN);
  1760. memcpy(hdr.addr3, skb->data, ETH_ALEN);
  1761. memcpy(hdr.addr4, skb->data + ETH_ALEN, ETH_ALEN);
  1762. hdrlen = 30;
  1763. /*
  1764. * This is the exception! WDS style interfaces are prohibited
  1765. * when channel contexts are in used so this must be valid
  1766. */
  1767. band = local->hw.conf.chandef.chan->band;
  1768. break;
  1769. #ifdef CONFIG_MAC80211_MESH
  1770. case NL80211_IFTYPE_MESH_POINT:
  1771. if (!is_multicast_ether_addr(skb->data)) {
  1772. struct sta_info *next_hop;
  1773. bool mpp_lookup = true;
  1774. mpath = mesh_path_lookup(sdata, skb->data);
  1775. if (mpath) {
  1776. mpp_lookup = false;
  1777. next_hop = rcu_dereference(mpath->next_hop);
  1778. if (!next_hop ||
  1779. !(mpath->flags & (MESH_PATH_ACTIVE |
  1780. MESH_PATH_RESOLVING)))
  1781. mpp_lookup = true;
  1782. }
  1783. if (mpp_lookup)
  1784. mppath = mpp_path_lookup(sdata, skb->data);
  1785. if (mppath && mpath)
  1786. mesh_path_del(mpath->sdata, mpath->dst);
  1787. }
  1788. /*
  1789. * Use address extension if it is a packet from
  1790. * another interface or if we know the destination
  1791. * is being proxied by a portal (i.e. portal address
  1792. * differs from proxied address)
  1793. */
  1794. if (ether_addr_equal(sdata->vif.addr, skb->data + ETH_ALEN) &&
  1795. !(mppath && !ether_addr_equal(mppath->mpp, skb->data))) {
  1796. hdrlen = ieee80211_fill_mesh_addresses(&hdr, &fc,
  1797. skb->data, skb->data + ETH_ALEN);
  1798. meshhdrlen = ieee80211_new_mesh_header(sdata, &mesh_hdr,
  1799. NULL, NULL);
  1800. } else {
  1801. /* DS -> MBSS (802.11-2012 13.11.3.3).
  1802. * For unicast with unknown forwarding information,
  1803. * destination might be in the MBSS or if that fails
  1804. * forwarded to another mesh gate. In either case
  1805. * resolution will be handled in ieee80211_xmit(), so
  1806. * leave the original DA. This also works for mcast */
  1807. const u8 *mesh_da = skb->data;
  1808. if (mppath)
  1809. mesh_da = mppath->mpp;
  1810. else if (mpath)
  1811. mesh_da = mpath->dst;
  1812. hdrlen = ieee80211_fill_mesh_addresses(&hdr, &fc,
  1813. mesh_da, sdata->vif.addr);
  1814. if (is_multicast_ether_addr(mesh_da))
  1815. /* DA TA mSA AE:SA */
  1816. meshhdrlen = ieee80211_new_mesh_header(
  1817. sdata, &mesh_hdr,
  1818. skb->data + ETH_ALEN, NULL);
  1819. else
  1820. /* RA TA mDA mSA AE:DA SA */
  1821. meshhdrlen = ieee80211_new_mesh_header(
  1822. sdata, &mesh_hdr, skb->data,
  1823. skb->data + ETH_ALEN);
  1824. }
  1825. chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
  1826. if (!chanctx_conf) {
  1827. ret = -ENOTCONN;
  1828. goto free;
  1829. }
  1830. band = chanctx_conf->def.chan->band;
  1831. break;
  1832. #endif
  1833. case NL80211_IFTYPE_STATION:
  1834. /* we already did checks when looking up the RA STA */
  1835. tdls_peer = test_sta_flag(sta, WLAN_STA_TDLS_PEER);
  1836. if (tdls_peer) {
  1837. /* DA SA BSSID */
  1838. memcpy(hdr.addr1, skb->data, ETH_ALEN);
  1839. memcpy(hdr.addr2, skb->data + ETH_ALEN, ETH_ALEN);
  1840. memcpy(hdr.addr3, sdata->u.mgd.bssid, ETH_ALEN);
  1841. hdrlen = 24;
  1842. } else if (sdata->u.mgd.use_4addr &&
  1843. cpu_to_be16(ethertype) != sdata->control_port_protocol) {
  1844. fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS |
  1845. IEEE80211_FCTL_TODS);
  1846. /* RA TA DA SA */
  1847. memcpy(hdr.addr1, sdata->u.mgd.bssid, ETH_ALEN);
  1848. memcpy(hdr.addr2, sdata->vif.addr, ETH_ALEN);
  1849. memcpy(hdr.addr3, skb->data, ETH_ALEN);
  1850. memcpy(hdr.addr4, skb->data + ETH_ALEN, ETH_ALEN);
  1851. hdrlen = 30;
  1852. } else {
  1853. fc |= cpu_to_le16(IEEE80211_FCTL_TODS);
  1854. /* BSSID SA DA */
  1855. memcpy(hdr.addr1, sdata->u.mgd.bssid, ETH_ALEN);
  1856. memcpy(hdr.addr2, skb->data + ETH_ALEN, ETH_ALEN);
  1857. memcpy(hdr.addr3, skb->data, ETH_ALEN);
  1858. hdrlen = 24;
  1859. }
  1860. chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
  1861. if (!chanctx_conf) {
  1862. ret = -ENOTCONN;
  1863. goto free;
  1864. }
  1865. band = chanctx_conf->def.chan->band;
  1866. break;
  1867. case NL80211_IFTYPE_OCB:
  1868. /* DA SA BSSID */
  1869. memcpy(hdr.addr1, skb->data, ETH_ALEN);
  1870. memcpy(hdr.addr2, skb->data + ETH_ALEN, ETH_ALEN);
  1871. eth_broadcast_addr(hdr.addr3);
  1872. hdrlen = 24;
  1873. chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
  1874. if (!chanctx_conf) {
  1875. ret = -ENOTCONN;
  1876. goto free;
  1877. }
  1878. band = chanctx_conf->def.chan->band;
  1879. break;
  1880. case NL80211_IFTYPE_ADHOC:
  1881. /* DA SA BSSID */
  1882. memcpy(hdr.addr1, skb->data, ETH_ALEN);
  1883. memcpy(hdr.addr2, skb->data + ETH_ALEN, ETH_ALEN);
  1884. memcpy(hdr.addr3, sdata->u.ibss.bssid, ETH_ALEN);
  1885. hdrlen = 24;
  1886. chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
  1887. if (!chanctx_conf) {
  1888. ret = -ENOTCONN;
  1889. goto free;
  1890. }
  1891. band = chanctx_conf->def.chan->band;
  1892. break;
  1893. default:
  1894. ret = -EINVAL;
  1895. goto free;
  1896. }
  1897. multicast = is_multicast_ether_addr(hdr.addr1);
  1898. /* sta is always NULL for mesh */
  1899. if (sta) {
  1900. authorized = test_sta_flag(sta, WLAN_STA_AUTHORIZED);
  1901. wme_sta = sta->sta.wme;
  1902. } else if (ieee80211_vif_is_mesh(&sdata->vif)) {
  1903. /* For mesh, the use of the QoS header is mandatory */
  1904. wme_sta = true;
  1905. }
  1906. /* receiver does QoS (which also means we do) use it */
  1907. if (wme_sta) {
  1908. fc |= cpu_to_le16(IEEE80211_STYPE_QOS_DATA);
  1909. hdrlen += 2;
  1910. }
  1911. /*
  1912. * Drop unicast frames to unauthorised stations unless they are
  1913. * EAPOL frames from the local station.
  1914. */
  1915. if (unlikely(!ieee80211_vif_is_mesh(&sdata->vif) &&
  1916. (sdata->vif.type != NL80211_IFTYPE_OCB) &&
  1917. !multicast && !authorized &&
  1918. (cpu_to_be16(ethertype) != sdata->control_port_protocol ||
  1919. !ether_addr_equal(sdata->vif.addr, skb->data + ETH_ALEN)))) {
  1920. #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
  1921. net_info_ratelimited("%s: dropped frame to %pM (unauthorized port)\n",
  1922. sdata->name, hdr.addr1);
  1923. #endif
  1924. I802_DEBUG_INC(local->tx_handlers_drop_unauth_port);
  1925. ret = -EPERM;
  1926. goto free;
  1927. }
  1928. if (unlikely(!multicast && skb->sk &&
  1929. skb_shinfo(skb)->tx_flags & SKBTX_WIFI_STATUS)) {
  1930. struct sk_buff *ack_skb = skb_clone_sk(skb);
  1931. if (ack_skb) {
  1932. unsigned long flags;
  1933. int id;
  1934. spin_lock_irqsave(&local->ack_status_lock, flags);
  1935. id = idr_alloc(&local->ack_status_frames, ack_skb,
  1936. 1, 0x10000, GFP_ATOMIC);
  1937. spin_unlock_irqrestore(&local->ack_status_lock, flags);
  1938. if (id >= 0) {
  1939. info_id = id;
  1940. info_flags |= IEEE80211_TX_CTL_REQ_TX_STATUS;
  1941. } else {
  1942. kfree_skb(ack_skb);
  1943. }
  1944. }
  1945. }
  1946. /*
  1947. * If the skb is shared we need to obtain our own copy.
  1948. */
  1949. if (skb_shared(skb)) {
  1950. struct sk_buff *tmp_skb = skb;
  1951. /* can't happen -- skb is a clone if info_id != 0 */
  1952. WARN_ON(info_id);
  1953. skb = skb_clone(skb, GFP_ATOMIC);
  1954. kfree_skb(tmp_skb);
  1955. if (!skb) {
  1956. ret = -ENOMEM;
  1957. goto free;
  1958. }
  1959. }
  1960. hdr.frame_control = fc;
  1961. hdr.duration_id = 0;
  1962. hdr.seq_ctrl = 0;
  1963. skip_header_bytes = ETH_HLEN;
  1964. if (ethertype == ETH_P_AARP || ethertype == ETH_P_IPX) {
  1965. encaps_data = bridge_tunnel_header;
  1966. encaps_len = sizeof(bridge_tunnel_header);
  1967. skip_header_bytes -= 2;
  1968. } else if (ethertype >= ETH_P_802_3_MIN) {
  1969. encaps_data = rfc1042_header;
  1970. encaps_len = sizeof(rfc1042_header);
  1971. skip_header_bytes -= 2;
  1972. } else {
  1973. encaps_data = NULL;
  1974. encaps_len = 0;
  1975. }
  1976. nh_pos = skb_network_header(skb) - skb->data;
  1977. h_pos = skb_transport_header(skb) - skb->data;
  1978. skb_pull(skb, skip_header_bytes);
  1979. nh_pos -= skip_header_bytes;
  1980. h_pos -= skip_header_bytes;
  1981. head_need = hdrlen + encaps_len + meshhdrlen - skb_headroom(skb);
  1982. /*
  1983. * So we need to modify the skb header and hence need a copy of
  1984. * that. The head_need variable above doesn't, so far, include
  1985. * the needed header space that we don't need right away. If we
  1986. * can, then we don't reallocate right now but only after the
  1987. * frame arrives at the master device (if it does...)
  1988. *
  1989. * If we cannot, however, then we will reallocate to include all
  1990. * the ever needed space. Also, if we need to reallocate it anyway,
  1991. * make it big enough for everything we may ever need.
  1992. */
  1993. if (head_need > 0 || skb_cloned(skb)) {
  1994. head_need += sdata->encrypt_headroom;
  1995. head_need += local->tx_headroom;
  1996. head_need = max_t(int, 0, head_need);
  1997. if (ieee80211_skb_resize(sdata, skb, head_need, true)) {
  1998. ieee80211_free_txskb(&local->hw, skb);
  1999. skb = NULL;
  2000. return ERR_PTR(-ENOMEM);
  2001. }
  2002. }
  2003. if (encaps_data) {
  2004. memcpy(skb_push(skb, encaps_len), encaps_data, encaps_len);
  2005. nh_pos += encaps_len;
  2006. h_pos += encaps_len;
  2007. }
  2008. #ifdef CONFIG_MAC80211_MESH
  2009. if (meshhdrlen > 0) {
  2010. memcpy(skb_push(skb, meshhdrlen), &mesh_hdr, meshhdrlen);
  2011. nh_pos += meshhdrlen;
  2012. h_pos += meshhdrlen;
  2013. }
  2014. #endif
  2015. if (ieee80211_is_data_qos(fc)) {
  2016. __le16 *qos_control;
  2017. qos_control = (__le16 *) skb_push(skb, 2);
  2018. memcpy(skb_push(skb, hdrlen - 2), &hdr, hdrlen - 2);
  2019. /*
  2020. * Maybe we could actually set some fields here, for now just
  2021. * initialise to zero to indicate no special operation.
  2022. */
  2023. *qos_control = 0;
  2024. } else
  2025. memcpy(skb_push(skb, hdrlen), &hdr, hdrlen);
  2026. nh_pos += hdrlen;
  2027. h_pos += hdrlen;
  2028. /* Update skb pointers to various headers since this modified frame
  2029. * is going to go through Linux networking code that may potentially
  2030. * need things like pointer to IP header. */
  2031. skb_set_mac_header(skb, 0);
  2032. skb_set_network_header(skb, nh_pos);
  2033. skb_set_transport_header(skb, h_pos);
  2034. info = IEEE80211_SKB_CB(skb);
  2035. memset(info, 0, sizeof(*info));
  2036. info->flags = info_flags;
  2037. info->ack_frame_id = info_id;
  2038. info->band = band;
  2039. return skb;
  2040. free:
  2041. kfree_skb(skb);
  2042. return ERR_PTR(ret);
  2043. }
  2044. /*
  2045. * fast-xmit overview
  2046. *
  2047. * The core idea of this fast-xmit is to remove per-packet checks by checking
  2048. * them out of band. ieee80211_check_fast_xmit() implements the out-of-band
  2049. * checks that are needed to get the sta->fast_tx pointer assigned, after which
  2050. * much less work can be done per packet. For example, fragmentation must be
  2051. * disabled or the fast_tx pointer will not be set. All the conditions are seen
  2052. * in the code here.
  2053. *
  2054. * Once assigned, the fast_tx data structure also caches the per-packet 802.11
  2055. * header and other data to aid packet processing in ieee80211_xmit_fast().
  2056. *
  2057. * The most difficult part of this is that when any of these assumptions
  2058. * change, an external trigger (i.e. a call to ieee80211_clear_fast_xmit(),
  2059. * ieee80211_check_fast_xmit() or friends) is required to reset the data,
  2060. * since the per-packet code no longer checks the conditions. This is reflected
  2061. * by the calls to these functions throughout the rest of the code, and must be
  2062. * maintained if any of the TX path checks change.
  2063. */
  2064. void ieee80211_check_fast_xmit(struct sta_info *sta)
  2065. {
  2066. struct ieee80211_fast_tx build = {}, *fast_tx = NULL, *old;
  2067. struct ieee80211_local *local = sta->local;
  2068. struct ieee80211_sub_if_data *sdata = sta->sdata;
  2069. struct ieee80211_hdr *hdr = (void *)build.hdr;
  2070. struct ieee80211_chanctx_conf *chanctx_conf;
  2071. __le16 fc;
  2072. if (!ieee80211_hw_check(&local->hw, SUPPORT_FAST_XMIT))
  2073. return;
  2074. /* Locking here protects both the pointer itself, and against concurrent
  2075. * invocations winning data access races to, e.g., the key pointer that
  2076. * is used.
  2077. * Without it, the invocation of this function right after the key
  2078. * pointer changes wouldn't be sufficient, as another CPU could access
  2079. * the pointer, then stall, and then do the cache update after the CPU
  2080. * that invalidated the key.
  2081. * With the locking, such scenarios cannot happen as the check for the
  2082. * key and the fast-tx assignment are done atomically, so the CPU that
  2083. * modifies the key will either wait or other one will see the key
  2084. * cleared/changed already.
  2085. */
  2086. spin_lock_bh(&sta->lock);
  2087. if (ieee80211_hw_check(&local->hw, SUPPORTS_PS) &&
  2088. !ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS) &&
  2089. sdata->vif.type == NL80211_IFTYPE_STATION)
  2090. goto out;
  2091. if (!test_sta_flag(sta, WLAN_STA_AUTHORIZED))
  2092. goto out;
  2093. if (test_sta_flag(sta, WLAN_STA_PS_STA) ||
  2094. test_sta_flag(sta, WLAN_STA_PS_DRIVER) ||
  2095. test_sta_flag(sta, WLAN_STA_PS_DELIVER))
  2096. goto out;
  2097. if (sdata->noack_map)
  2098. goto out;
  2099. /* fast-xmit doesn't handle fragmentation at all */
  2100. if (local->hw.wiphy->frag_threshold != (u32)-1 &&
  2101. !local->ops->set_frag_threshold)
  2102. goto out;
  2103. rcu_read_lock();
  2104. chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
  2105. if (!chanctx_conf) {
  2106. rcu_read_unlock();
  2107. goto out;
  2108. }
  2109. build.band = chanctx_conf->def.chan->band;
  2110. rcu_read_unlock();
  2111. fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_DATA);
  2112. switch (sdata->vif.type) {
  2113. case NL80211_IFTYPE_ADHOC:
  2114. /* DA SA BSSID */
  2115. build.da_offs = offsetof(struct ieee80211_hdr, addr1);
  2116. build.sa_offs = offsetof(struct ieee80211_hdr, addr2);
  2117. memcpy(hdr->addr3, sdata->u.ibss.bssid, ETH_ALEN);
  2118. build.hdr_len = 24;
  2119. break;
  2120. case NL80211_IFTYPE_STATION:
  2121. if (test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
  2122. /* DA SA BSSID */
  2123. build.da_offs = offsetof(struct ieee80211_hdr, addr1);
  2124. build.sa_offs = offsetof(struct ieee80211_hdr, addr2);
  2125. memcpy(hdr->addr3, sdata->u.mgd.bssid, ETH_ALEN);
  2126. build.hdr_len = 24;
  2127. break;
  2128. }
  2129. if (sdata->u.mgd.use_4addr) {
  2130. /* non-regular ethertype cannot use the fastpath */
  2131. fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS |
  2132. IEEE80211_FCTL_TODS);
  2133. /* RA TA DA SA */
  2134. memcpy(hdr->addr1, sdata->u.mgd.bssid, ETH_ALEN);
  2135. memcpy(hdr->addr2, sdata->vif.addr, ETH_ALEN);
  2136. build.da_offs = offsetof(struct ieee80211_hdr, addr3);
  2137. build.sa_offs = offsetof(struct ieee80211_hdr, addr4);
  2138. build.hdr_len = 30;
  2139. break;
  2140. }
  2141. fc |= cpu_to_le16(IEEE80211_FCTL_TODS);
  2142. /* BSSID SA DA */
  2143. memcpy(hdr->addr1, sdata->u.mgd.bssid, ETH_ALEN);
  2144. build.da_offs = offsetof(struct ieee80211_hdr, addr3);
  2145. build.sa_offs = offsetof(struct ieee80211_hdr, addr2);
  2146. build.hdr_len = 24;
  2147. break;
  2148. case NL80211_IFTYPE_AP_VLAN:
  2149. if (sdata->wdev.use_4addr) {
  2150. fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS |
  2151. IEEE80211_FCTL_TODS);
  2152. /* RA TA DA SA */
  2153. memcpy(hdr->addr1, sta->sta.addr, ETH_ALEN);
  2154. memcpy(hdr->addr2, sdata->vif.addr, ETH_ALEN);
  2155. build.da_offs = offsetof(struct ieee80211_hdr, addr3);
  2156. build.sa_offs = offsetof(struct ieee80211_hdr, addr4);
  2157. build.hdr_len = 30;
  2158. break;
  2159. }
  2160. /* fall through */
  2161. case NL80211_IFTYPE_AP:
  2162. fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS);
  2163. /* DA BSSID SA */
  2164. build.da_offs = offsetof(struct ieee80211_hdr, addr1);
  2165. memcpy(hdr->addr2, sdata->vif.addr, ETH_ALEN);
  2166. build.sa_offs = offsetof(struct ieee80211_hdr, addr3);
  2167. build.hdr_len = 24;
  2168. break;
  2169. default:
  2170. /* not handled on fast-xmit */
  2171. goto out;
  2172. }
  2173. if (sta->sta.wme) {
  2174. build.hdr_len += 2;
  2175. fc |= cpu_to_le16(IEEE80211_STYPE_QOS_DATA);
  2176. }
  2177. /* We store the key here so there's no point in using rcu_dereference()
  2178. * but that's fine because the code that changes the pointers will call
  2179. * this function after doing so. For a single CPU that would be enough,
  2180. * for multiple see the comment above.
  2181. */
  2182. build.key = rcu_access_pointer(sta->ptk[sta->ptk_idx]);
  2183. if (!build.key)
  2184. build.key = rcu_access_pointer(sdata->default_unicast_key);
  2185. if (build.key) {
  2186. bool gen_iv, iv_spc, mmic;
  2187. gen_iv = build.key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV;
  2188. iv_spc = build.key->conf.flags & IEEE80211_KEY_FLAG_PUT_IV_SPACE;
  2189. mmic = build.key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_MMIC;
  2190. /* don't handle software crypto */
  2191. if (!(build.key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE))
  2192. goto out;
  2193. switch (build.key->conf.cipher) {
  2194. case WLAN_CIPHER_SUITE_CCMP:
  2195. case WLAN_CIPHER_SUITE_CCMP_256:
  2196. /* add fixed key ID */
  2197. if (gen_iv) {
  2198. (build.hdr + build.hdr_len)[3] =
  2199. 0x20 | (build.key->conf.keyidx << 6);
  2200. build.pn_offs = build.hdr_len;
  2201. }
  2202. if (gen_iv || iv_spc)
  2203. build.hdr_len += IEEE80211_CCMP_HDR_LEN;
  2204. break;
  2205. case WLAN_CIPHER_SUITE_GCMP:
  2206. case WLAN_CIPHER_SUITE_GCMP_256:
  2207. /* add fixed key ID */
  2208. if (gen_iv) {
  2209. (build.hdr + build.hdr_len)[3] =
  2210. 0x20 | (build.key->conf.keyidx << 6);
  2211. build.pn_offs = build.hdr_len;
  2212. }
  2213. if (gen_iv || iv_spc)
  2214. build.hdr_len += IEEE80211_GCMP_HDR_LEN;
  2215. break;
  2216. case WLAN_CIPHER_SUITE_TKIP:
  2217. /* cannot handle MMIC or IV generation in xmit-fast */
  2218. if (mmic || gen_iv)
  2219. goto out;
  2220. if (iv_spc)
  2221. build.hdr_len += IEEE80211_TKIP_IV_LEN;
  2222. break;
  2223. case WLAN_CIPHER_SUITE_WEP40:
  2224. case WLAN_CIPHER_SUITE_WEP104:
  2225. /* cannot handle IV generation in fast-xmit */
  2226. if (gen_iv)
  2227. goto out;
  2228. if (iv_spc)
  2229. build.hdr_len += IEEE80211_WEP_IV_LEN;
  2230. break;
  2231. case WLAN_CIPHER_SUITE_AES_CMAC:
  2232. case WLAN_CIPHER_SUITE_BIP_CMAC_256:
  2233. case WLAN_CIPHER_SUITE_BIP_GMAC_128:
  2234. case WLAN_CIPHER_SUITE_BIP_GMAC_256:
  2235. WARN(1,
  2236. "management cipher suite 0x%x enabled for data\n",
  2237. build.key->conf.cipher);
  2238. goto out;
  2239. default:
  2240. /* we don't know how to generate IVs for this at all */
  2241. if (WARN_ON(gen_iv))
  2242. goto out;
  2243. /* pure hardware keys are OK, of course */
  2244. if (!(build.key->flags & KEY_FLAG_CIPHER_SCHEME))
  2245. break;
  2246. /* cipher scheme might require space allocation */
  2247. if (iv_spc &&
  2248. build.key->conf.iv_len > IEEE80211_FAST_XMIT_MAX_IV)
  2249. goto out;
  2250. if (iv_spc)
  2251. build.hdr_len += build.key->conf.iv_len;
  2252. }
  2253. fc |= cpu_to_le16(IEEE80211_FCTL_PROTECTED);
  2254. }
  2255. hdr->frame_control = fc;
  2256. memcpy(build.hdr + build.hdr_len,
  2257. rfc1042_header, sizeof(rfc1042_header));
  2258. build.hdr_len += sizeof(rfc1042_header);
  2259. fast_tx = kmemdup(&build, sizeof(build), GFP_ATOMIC);
  2260. /* if the kmemdup fails, continue w/o fast_tx */
  2261. if (!fast_tx)
  2262. goto out;
  2263. out:
  2264. /* we might have raced against another call to this function */
  2265. old = rcu_dereference_protected(sta->fast_tx,
  2266. lockdep_is_held(&sta->lock));
  2267. rcu_assign_pointer(sta->fast_tx, fast_tx);
  2268. if (old)
  2269. kfree_rcu(old, rcu_head);
  2270. spin_unlock_bh(&sta->lock);
  2271. }
  2272. void ieee80211_check_fast_xmit_all(struct ieee80211_local *local)
  2273. {
  2274. struct sta_info *sta;
  2275. rcu_read_lock();
  2276. list_for_each_entry_rcu(sta, &local->sta_list, list)
  2277. ieee80211_check_fast_xmit(sta);
  2278. rcu_read_unlock();
  2279. }
  2280. void ieee80211_check_fast_xmit_iface(struct ieee80211_sub_if_data *sdata)
  2281. {
  2282. struct ieee80211_local *local = sdata->local;
  2283. struct sta_info *sta;
  2284. rcu_read_lock();
  2285. list_for_each_entry_rcu(sta, &local->sta_list, list) {
  2286. if (sdata != sta->sdata &&
  2287. (!sta->sdata->bss || sta->sdata->bss != sdata->bss))
  2288. continue;
  2289. ieee80211_check_fast_xmit(sta);
  2290. }
  2291. rcu_read_unlock();
  2292. }
  2293. void ieee80211_clear_fast_xmit(struct sta_info *sta)
  2294. {
  2295. struct ieee80211_fast_tx *fast_tx;
  2296. spin_lock_bh(&sta->lock);
  2297. fast_tx = rcu_dereference_protected(sta->fast_tx,
  2298. lockdep_is_held(&sta->lock));
  2299. RCU_INIT_POINTER(sta->fast_tx, NULL);
  2300. spin_unlock_bh(&sta->lock);
  2301. if (fast_tx)
  2302. kfree_rcu(fast_tx, rcu_head);
  2303. }
  2304. static bool ieee80211_xmit_fast(struct ieee80211_sub_if_data *sdata,
  2305. struct net_device *dev, struct sta_info *sta,
  2306. struct ieee80211_fast_tx *fast_tx,
  2307. struct sk_buff *skb)
  2308. {
  2309. struct ieee80211_local *local = sdata->local;
  2310. u16 ethertype = (skb->data[12] << 8) | skb->data[13];
  2311. int extra_head = fast_tx->hdr_len - (ETH_HLEN - 2);
  2312. int hw_headroom = sdata->local->hw.extra_tx_headroom;
  2313. struct ethhdr eth;
  2314. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  2315. struct ieee80211_hdr *hdr = (void *)fast_tx->hdr;
  2316. struct ieee80211_tx_data tx;
  2317. ieee80211_tx_result r;
  2318. struct tid_ampdu_tx *tid_tx = NULL;
  2319. u8 tid = IEEE80211_NUM_TIDS;
  2320. /* control port protocol needs a lot of special handling */
  2321. if (cpu_to_be16(ethertype) == sdata->control_port_protocol)
  2322. return false;
  2323. /* only RFC 1042 SNAP */
  2324. if (ethertype < ETH_P_802_3_MIN)
  2325. return false;
  2326. /* don't handle TX status request here either */
  2327. if (skb->sk && skb_shinfo(skb)->tx_flags & SKBTX_WIFI_STATUS)
  2328. return false;
  2329. if (hdr->frame_control & cpu_to_le16(IEEE80211_STYPE_QOS_DATA)) {
  2330. tid = skb->priority & IEEE80211_QOS_CTL_TAG1D_MASK;
  2331. tid_tx = rcu_dereference(sta->ampdu_mlme.tid_tx[tid]);
  2332. if (tid_tx) {
  2333. if (!test_bit(HT_AGG_STATE_OPERATIONAL, &tid_tx->state))
  2334. return false;
  2335. if (tid_tx->timeout)
  2336. tid_tx->last_tx = jiffies;
  2337. }
  2338. }
  2339. /* after this point (skb is modified) we cannot return false */
  2340. if (skb_shared(skb)) {
  2341. struct sk_buff *tmp_skb = skb;
  2342. skb = skb_clone(skb, GFP_ATOMIC);
  2343. kfree_skb(tmp_skb);
  2344. if (!skb)
  2345. return true;
  2346. }
  2347. ieee80211_tx_stats(dev, skb->len + extra_head);
  2348. /* will not be crypto-handled beyond what we do here, so use false
  2349. * as the may-encrypt argument for the resize to not account for
  2350. * more room than we already have in 'extra_head'
  2351. */
  2352. if (unlikely(ieee80211_skb_resize(sdata, skb,
  2353. max_t(int, extra_head + hw_headroom -
  2354. skb_headroom(skb), 0),
  2355. false))) {
  2356. kfree_skb(skb);
  2357. return true;
  2358. }
  2359. memcpy(&eth, skb->data, ETH_HLEN - 2);
  2360. hdr = (void *)skb_push(skb, extra_head);
  2361. memcpy(skb->data, fast_tx->hdr, fast_tx->hdr_len);
  2362. memcpy(skb->data + fast_tx->da_offs, eth.h_dest, ETH_ALEN);
  2363. memcpy(skb->data + fast_tx->sa_offs, eth.h_source, ETH_ALEN);
  2364. memset(info, 0, sizeof(*info));
  2365. info->band = fast_tx->band;
  2366. info->control.vif = &sdata->vif;
  2367. info->flags = IEEE80211_TX_CTL_FIRST_FRAGMENT |
  2368. IEEE80211_TX_CTL_DONTFRAG |
  2369. (tid_tx ? IEEE80211_TX_CTL_AMPDU : 0);
  2370. if (hdr->frame_control & cpu_to_le16(IEEE80211_STYPE_QOS_DATA)) {
  2371. *ieee80211_get_qos_ctl(hdr) = tid;
  2372. hdr->seq_ctrl = ieee80211_tx_next_seq(sta, tid);
  2373. } else {
  2374. info->flags |= IEEE80211_TX_CTL_ASSIGN_SEQ;
  2375. hdr->seq_ctrl = cpu_to_le16(sdata->sequence_number);
  2376. sdata->sequence_number += 0x10;
  2377. }
  2378. sta->tx_msdu[tid]++;
  2379. info->hw_queue = sdata->vif.hw_queue[skb_get_queue_mapping(skb)];
  2380. __skb_queue_head_init(&tx.skbs);
  2381. tx.flags = IEEE80211_TX_UNICAST;
  2382. tx.local = local;
  2383. tx.sdata = sdata;
  2384. tx.sta = sta;
  2385. tx.key = fast_tx->key;
  2386. if (fast_tx->key)
  2387. info->control.hw_key = &fast_tx->key->conf;
  2388. if (!ieee80211_hw_check(&local->hw, HAS_RATE_CONTROL)) {
  2389. tx.skb = skb;
  2390. r = ieee80211_tx_h_rate_ctrl(&tx);
  2391. skb = tx.skb;
  2392. tx.skb = NULL;
  2393. if (r != TX_CONTINUE) {
  2394. if (r != TX_QUEUED)
  2395. kfree_skb(skb);
  2396. return true;
  2397. }
  2398. }
  2399. /* statistics normally done by ieee80211_tx_h_stats (but that
  2400. * has to consider fragmentation, so is more complex)
  2401. */
  2402. sta->tx_bytes[skb_get_queue_mapping(skb)] += skb->len;
  2403. sta->tx_packets[skb_get_queue_mapping(skb)]++;
  2404. if (fast_tx->pn_offs) {
  2405. u64 pn;
  2406. u8 *crypto_hdr = skb->data + fast_tx->pn_offs;
  2407. switch (fast_tx->key->conf.cipher) {
  2408. case WLAN_CIPHER_SUITE_CCMP:
  2409. case WLAN_CIPHER_SUITE_CCMP_256:
  2410. case WLAN_CIPHER_SUITE_GCMP:
  2411. case WLAN_CIPHER_SUITE_GCMP_256:
  2412. pn = atomic64_inc_return(&fast_tx->key->conf.tx_pn);
  2413. crypto_hdr[0] = pn;
  2414. crypto_hdr[1] = pn >> 8;
  2415. crypto_hdr[4] = pn >> 16;
  2416. crypto_hdr[5] = pn >> 24;
  2417. crypto_hdr[6] = pn >> 32;
  2418. crypto_hdr[7] = pn >> 40;
  2419. break;
  2420. }
  2421. }
  2422. if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
  2423. sdata = container_of(sdata->bss,
  2424. struct ieee80211_sub_if_data, u.ap);
  2425. __skb_queue_tail(&tx.skbs, skb);
  2426. ieee80211_tx_frags(local, &sdata->vif, &sta->sta, &tx.skbs, false);
  2427. return true;
  2428. }
  2429. void __ieee80211_subif_start_xmit(struct sk_buff *skb,
  2430. struct net_device *dev,
  2431. u32 info_flags)
  2432. {
  2433. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  2434. struct sta_info *sta;
  2435. struct sk_buff *next;
  2436. if (unlikely(skb->len < ETH_HLEN)) {
  2437. kfree_skb(skb);
  2438. return;
  2439. }
  2440. rcu_read_lock();
  2441. if (ieee80211_lookup_ra_sta(sdata, skb, &sta))
  2442. goto out_free;
  2443. if (!IS_ERR_OR_NULL(sta)) {
  2444. struct ieee80211_fast_tx *fast_tx;
  2445. fast_tx = rcu_dereference(sta->fast_tx);
  2446. if (fast_tx &&
  2447. ieee80211_xmit_fast(sdata, dev, sta, fast_tx, skb))
  2448. goto out;
  2449. }
  2450. if (skb_is_gso(skb)) {
  2451. struct sk_buff *segs;
  2452. segs = skb_gso_segment(skb, 0);
  2453. if (IS_ERR(segs)) {
  2454. goto out_free;
  2455. } else if (segs) {
  2456. consume_skb(skb);
  2457. skb = segs;
  2458. }
  2459. } else {
  2460. /* we cannot process non-linear frames on this path */
  2461. if (skb_linearize(skb)) {
  2462. kfree_skb(skb);
  2463. goto out;
  2464. }
  2465. /* the frame could be fragmented, software-encrypted, and other
  2466. * things so we cannot really handle checksum offload with it -
  2467. * fix it up in software before we handle anything else.
  2468. */
  2469. if (skb->ip_summed == CHECKSUM_PARTIAL) {
  2470. skb_set_transport_header(skb,
  2471. skb_checksum_start_offset(skb));
  2472. if (skb_checksum_help(skb))
  2473. goto out_free;
  2474. }
  2475. }
  2476. next = skb;
  2477. while (next) {
  2478. skb = next;
  2479. next = skb->next;
  2480. skb->prev = NULL;
  2481. skb->next = NULL;
  2482. skb = ieee80211_build_hdr(sdata, skb, info_flags, sta);
  2483. if (IS_ERR(skb))
  2484. goto out;
  2485. ieee80211_tx_stats(dev, skb->len);
  2486. ieee80211_xmit(sdata, sta, skb);
  2487. }
  2488. goto out;
  2489. out_free:
  2490. kfree_skb(skb);
  2491. out:
  2492. rcu_read_unlock();
  2493. }
  2494. /**
  2495. * ieee80211_subif_start_xmit - netif start_xmit function for 802.3 vifs
  2496. * @skb: packet to be sent
  2497. * @dev: incoming interface
  2498. *
  2499. * On failure skb will be freed.
  2500. */
  2501. netdev_tx_t ieee80211_subif_start_xmit(struct sk_buff *skb,
  2502. struct net_device *dev)
  2503. {
  2504. __ieee80211_subif_start_xmit(skb, dev, 0);
  2505. return NETDEV_TX_OK;
  2506. }
  2507. struct sk_buff *
  2508. ieee80211_build_data_template(struct ieee80211_sub_if_data *sdata,
  2509. struct sk_buff *skb, u32 info_flags)
  2510. {
  2511. struct ieee80211_hdr *hdr;
  2512. struct ieee80211_tx_data tx = {
  2513. .local = sdata->local,
  2514. .sdata = sdata,
  2515. };
  2516. struct sta_info *sta;
  2517. rcu_read_lock();
  2518. if (ieee80211_lookup_ra_sta(sdata, skb, &sta)) {
  2519. kfree_skb(skb);
  2520. skb = ERR_PTR(-EINVAL);
  2521. goto out;
  2522. }
  2523. skb = ieee80211_build_hdr(sdata, skb, info_flags, sta);
  2524. if (IS_ERR(skb))
  2525. goto out;
  2526. hdr = (void *)skb->data;
  2527. tx.sta = sta_info_get(sdata, hdr->addr1);
  2528. tx.skb = skb;
  2529. if (ieee80211_tx_h_select_key(&tx) != TX_CONTINUE) {
  2530. rcu_read_unlock();
  2531. kfree_skb(skb);
  2532. return ERR_PTR(-EINVAL);
  2533. }
  2534. out:
  2535. rcu_read_unlock();
  2536. return skb;
  2537. }
  2538. /*
  2539. * ieee80211_clear_tx_pending may not be called in a context where
  2540. * it is possible that it packets could come in again.
  2541. */
  2542. void ieee80211_clear_tx_pending(struct ieee80211_local *local)
  2543. {
  2544. struct sk_buff *skb;
  2545. int i;
  2546. for (i = 0; i < local->hw.queues; i++) {
  2547. while ((skb = skb_dequeue(&local->pending[i])) != NULL)
  2548. ieee80211_free_txskb(&local->hw, skb);
  2549. }
  2550. }
  2551. /*
  2552. * Returns false if the frame couldn't be transmitted but was queued instead,
  2553. * which in this case means re-queued -- take as an indication to stop sending
  2554. * more pending frames.
  2555. */
  2556. static bool ieee80211_tx_pending_skb(struct ieee80211_local *local,
  2557. struct sk_buff *skb)
  2558. {
  2559. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  2560. struct ieee80211_sub_if_data *sdata;
  2561. struct sta_info *sta;
  2562. struct ieee80211_hdr *hdr;
  2563. bool result;
  2564. struct ieee80211_chanctx_conf *chanctx_conf;
  2565. sdata = vif_to_sdata(info->control.vif);
  2566. if (info->flags & IEEE80211_TX_INTFL_NEED_TXPROCESSING) {
  2567. chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
  2568. if (unlikely(!chanctx_conf)) {
  2569. dev_kfree_skb(skb);
  2570. return true;
  2571. }
  2572. info->band = chanctx_conf->def.chan->band;
  2573. result = ieee80211_tx(sdata, NULL, skb, true);
  2574. } else {
  2575. struct sk_buff_head skbs;
  2576. __skb_queue_head_init(&skbs);
  2577. __skb_queue_tail(&skbs, skb);
  2578. hdr = (struct ieee80211_hdr *)skb->data;
  2579. sta = sta_info_get(sdata, hdr->addr1);
  2580. result = __ieee80211_tx(local, &skbs, skb->len, sta, true);
  2581. }
  2582. return result;
  2583. }
  2584. /*
  2585. * Transmit all pending packets. Called from tasklet.
  2586. */
  2587. void ieee80211_tx_pending(unsigned long data)
  2588. {
  2589. struct ieee80211_local *local = (struct ieee80211_local *)data;
  2590. unsigned long flags;
  2591. int i;
  2592. bool txok;
  2593. rcu_read_lock();
  2594. spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
  2595. for (i = 0; i < local->hw.queues; i++) {
  2596. /*
  2597. * If queue is stopped by something other than due to pending
  2598. * frames, or we have no pending frames, proceed to next queue.
  2599. */
  2600. if (local->queue_stop_reasons[i] ||
  2601. skb_queue_empty(&local->pending[i]))
  2602. continue;
  2603. while (!skb_queue_empty(&local->pending[i])) {
  2604. struct sk_buff *skb = __skb_dequeue(&local->pending[i]);
  2605. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  2606. if (WARN_ON(!info->control.vif)) {
  2607. ieee80211_free_txskb(&local->hw, skb);
  2608. continue;
  2609. }
  2610. spin_unlock_irqrestore(&local->queue_stop_reason_lock,
  2611. flags);
  2612. txok = ieee80211_tx_pending_skb(local, skb);
  2613. spin_lock_irqsave(&local->queue_stop_reason_lock,
  2614. flags);
  2615. if (!txok)
  2616. break;
  2617. }
  2618. if (skb_queue_empty(&local->pending[i]))
  2619. ieee80211_propagate_queue_wake(local, i);
  2620. }
  2621. spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
  2622. rcu_read_unlock();
  2623. }
  2624. /* functions for drivers to get certain frames */
  2625. static void __ieee80211_beacon_add_tim(struct ieee80211_sub_if_data *sdata,
  2626. struct ps_data *ps, struct sk_buff *skb,
  2627. bool is_template)
  2628. {
  2629. u8 *pos, *tim;
  2630. int aid0 = 0;
  2631. int i, have_bits = 0, n1, n2;
  2632. /* Generate bitmap for TIM only if there are any STAs in power save
  2633. * mode. */
  2634. if (atomic_read(&ps->num_sta_ps) > 0)
  2635. /* in the hope that this is faster than
  2636. * checking byte-for-byte */
  2637. have_bits = !bitmap_empty((unsigned long *)ps->tim,
  2638. IEEE80211_MAX_AID+1);
  2639. if (!is_template) {
  2640. if (ps->dtim_count == 0)
  2641. ps->dtim_count = sdata->vif.bss_conf.dtim_period - 1;
  2642. else
  2643. ps->dtim_count--;
  2644. }
  2645. tim = pos = (u8 *) skb_put(skb, 6);
  2646. *pos++ = WLAN_EID_TIM;
  2647. *pos++ = 4;
  2648. *pos++ = ps->dtim_count;
  2649. *pos++ = sdata->vif.bss_conf.dtim_period;
  2650. if (ps->dtim_count == 0 && !skb_queue_empty(&ps->bc_buf))
  2651. aid0 = 1;
  2652. ps->dtim_bc_mc = aid0 == 1;
  2653. if (have_bits) {
  2654. /* Find largest even number N1 so that bits numbered 1 through
  2655. * (N1 x 8) - 1 in the bitmap are 0 and number N2 so that bits
  2656. * (N2 + 1) x 8 through 2007 are 0. */
  2657. n1 = 0;
  2658. for (i = 0; i < IEEE80211_MAX_TIM_LEN; i++) {
  2659. if (ps->tim[i]) {
  2660. n1 = i & 0xfe;
  2661. break;
  2662. }
  2663. }
  2664. n2 = n1;
  2665. for (i = IEEE80211_MAX_TIM_LEN - 1; i >= n1; i--) {
  2666. if (ps->tim[i]) {
  2667. n2 = i;
  2668. break;
  2669. }
  2670. }
  2671. /* Bitmap control */
  2672. *pos++ = n1 | aid0;
  2673. /* Part Virt Bitmap */
  2674. skb_put(skb, n2 - n1);
  2675. memcpy(pos, ps->tim + n1, n2 - n1 + 1);
  2676. tim[1] = n2 - n1 + 4;
  2677. } else {
  2678. *pos++ = aid0; /* Bitmap control */
  2679. *pos++ = 0; /* Part Virt Bitmap */
  2680. }
  2681. }
  2682. static int ieee80211_beacon_add_tim(struct ieee80211_sub_if_data *sdata,
  2683. struct ps_data *ps, struct sk_buff *skb,
  2684. bool is_template)
  2685. {
  2686. struct ieee80211_local *local = sdata->local;
  2687. /*
  2688. * Not very nice, but we want to allow the driver to call
  2689. * ieee80211_beacon_get() as a response to the set_tim()
  2690. * callback. That, however, is already invoked under the
  2691. * sta_lock to guarantee consistent and race-free update
  2692. * of the tim bitmap in mac80211 and the driver.
  2693. */
  2694. if (local->tim_in_locked_section) {
  2695. __ieee80211_beacon_add_tim(sdata, ps, skb, is_template);
  2696. } else {
  2697. spin_lock_bh(&local->tim_lock);
  2698. __ieee80211_beacon_add_tim(sdata, ps, skb, is_template);
  2699. spin_unlock_bh(&local->tim_lock);
  2700. }
  2701. return 0;
  2702. }
  2703. static void ieee80211_set_csa(struct ieee80211_sub_if_data *sdata,
  2704. struct beacon_data *beacon)
  2705. {
  2706. struct probe_resp *resp;
  2707. u8 *beacon_data;
  2708. size_t beacon_data_len;
  2709. int i;
  2710. u8 count = beacon->csa_current_counter;
  2711. switch (sdata->vif.type) {
  2712. case NL80211_IFTYPE_AP:
  2713. beacon_data = beacon->tail;
  2714. beacon_data_len = beacon->tail_len;
  2715. break;
  2716. case NL80211_IFTYPE_ADHOC:
  2717. beacon_data = beacon->head;
  2718. beacon_data_len = beacon->head_len;
  2719. break;
  2720. case NL80211_IFTYPE_MESH_POINT:
  2721. beacon_data = beacon->head;
  2722. beacon_data_len = beacon->head_len;
  2723. break;
  2724. default:
  2725. return;
  2726. }
  2727. rcu_read_lock();
  2728. for (i = 0; i < IEEE80211_MAX_CSA_COUNTERS_NUM; ++i) {
  2729. resp = rcu_dereference(sdata->u.ap.probe_resp);
  2730. if (beacon->csa_counter_offsets[i]) {
  2731. if (WARN_ON_ONCE(beacon->csa_counter_offsets[i] >=
  2732. beacon_data_len)) {
  2733. rcu_read_unlock();
  2734. return;
  2735. }
  2736. beacon_data[beacon->csa_counter_offsets[i]] = count;
  2737. }
  2738. if (sdata->vif.type == NL80211_IFTYPE_AP && resp)
  2739. resp->data[resp->csa_counter_offsets[i]] = count;
  2740. }
  2741. rcu_read_unlock();
  2742. }
  2743. u8 ieee80211_csa_update_counter(struct ieee80211_vif *vif)
  2744. {
  2745. struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
  2746. struct beacon_data *beacon = NULL;
  2747. u8 count = 0;
  2748. rcu_read_lock();
  2749. if (sdata->vif.type == NL80211_IFTYPE_AP)
  2750. beacon = rcu_dereference(sdata->u.ap.beacon);
  2751. else if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
  2752. beacon = rcu_dereference(sdata->u.ibss.presp);
  2753. else if (ieee80211_vif_is_mesh(&sdata->vif))
  2754. beacon = rcu_dereference(sdata->u.mesh.beacon);
  2755. if (!beacon)
  2756. goto unlock;
  2757. beacon->csa_current_counter--;
  2758. /* the counter should never reach 0 */
  2759. WARN_ON_ONCE(!beacon->csa_current_counter);
  2760. count = beacon->csa_current_counter;
  2761. unlock:
  2762. rcu_read_unlock();
  2763. return count;
  2764. }
  2765. EXPORT_SYMBOL(ieee80211_csa_update_counter);
  2766. bool ieee80211_csa_is_complete(struct ieee80211_vif *vif)
  2767. {
  2768. struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
  2769. struct beacon_data *beacon = NULL;
  2770. u8 *beacon_data;
  2771. size_t beacon_data_len;
  2772. int ret = false;
  2773. if (!ieee80211_sdata_running(sdata))
  2774. return false;
  2775. rcu_read_lock();
  2776. if (vif->type == NL80211_IFTYPE_AP) {
  2777. struct ieee80211_if_ap *ap = &sdata->u.ap;
  2778. beacon = rcu_dereference(ap->beacon);
  2779. if (WARN_ON(!beacon || !beacon->tail))
  2780. goto out;
  2781. beacon_data = beacon->tail;
  2782. beacon_data_len = beacon->tail_len;
  2783. } else if (vif->type == NL80211_IFTYPE_ADHOC) {
  2784. struct ieee80211_if_ibss *ifibss = &sdata->u.ibss;
  2785. beacon = rcu_dereference(ifibss->presp);
  2786. if (!beacon)
  2787. goto out;
  2788. beacon_data = beacon->head;
  2789. beacon_data_len = beacon->head_len;
  2790. } else if (vif->type == NL80211_IFTYPE_MESH_POINT) {
  2791. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  2792. beacon = rcu_dereference(ifmsh->beacon);
  2793. if (!beacon)
  2794. goto out;
  2795. beacon_data = beacon->head;
  2796. beacon_data_len = beacon->head_len;
  2797. } else {
  2798. WARN_ON(1);
  2799. goto out;
  2800. }
  2801. if (!beacon->csa_counter_offsets[0])
  2802. goto out;
  2803. if (WARN_ON_ONCE(beacon->csa_counter_offsets[0] > beacon_data_len))
  2804. goto out;
  2805. if (beacon_data[beacon->csa_counter_offsets[0]] == 1)
  2806. ret = true;
  2807. out:
  2808. rcu_read_unlock();
  2809. return ret;
  2810. }
  2811. EXPORT_SYMBOL(ieee80211_csa_is_complete);
  2812. static struct sk_buff *
  2813. __ieee80211_beacon_get(struct ieee80211_hw *hw,
  2814. struct ieee80211_vif *vif,
  2815. struct ieee80211_mutable_offsets *offs,
  2816. bool is_template)
  2817. {
  2818. struct ieee80211_local *local = hw_to_local(hw);
  2819. struct beacon_data *beacon = NULL;
  2820. struct sk_buff *skb = NULL;
  2821. struct ieee80211_tx_info *info;
  2822. struct ieee80211_sub_if_data *sdata = NULL;
  2823. enum ieee80211_band band;
  2824. struct ieee80211_tx_rate_control txrc;
  2825. struct ieee80211_chanctx_conf *chanctx_conf;
  2826. int csa_off_base = 0;
  2827. rcu_read_lock();
  2828. sdata = vif_to_sdata(vif);
  2829. chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
  2830. if (!ieee80211_sdata_running(sdata) || !chanctx_conf)
  2831. goto out;
  2832. if (offs)
  2833. memset(offs, 0, sizeof(*offs));
  2834. if (sdata->vif.type == NL80211_IFTYPE_AP) {
  2835. struct ieee80211_if_ap *ap = &sdata->u.ap;
  2836. beacon = rcu_dereference(ap->beacon);
  2837. if (beacon) {
  2838. if (beacon->csa_counter_offsets[0]) {
  2839. if (!is_template)
  2840. ieee80211_csa_update_counter(vif);
  2841. ieee80211_set_csa(sdata, beacon);
  2842. }
  2843. /*
  2844. * headroom, head length,
  2845. * tail length and maximum TIM length
  2846. */
  2847. skb = dev_alloc_skb(local->tx_headroom +
  2848. beacon->head_len +
  2849. beacon->tail_len + 256 +
  2850. local->hw.extra_beacon_tailroom);
  2851. if (!skb)
  2852. goto out;
  2853. skb_reserve(skb, local->tx_headroom);
  2854. memcpy(skb_put(skb, beacon->head_len), beacon->head,
  2855. beacon->head_len);
  2856. ieee80211_beacon_add_tim(sdata, &ap->ps, skb,
  2857. is_template);
  2858. if (offs) {
  2859. offs->tim_offset = beacon->head_len;
  2860. offs->tim_length = skb->len - beacon->head_len;
  2861. /* for AP the csa offsets are from tail */
  2862. csa_off_base = skb->len;
  2863. }
  2864. if (beacon->tail)
  2865. memcpy(skb_put(skb, beacon->tail_len),
  2866. beacon->tail, beacon->tail_len);
  2867. } else
  2868. goto out;
  2869. } else if (sdata->vif.type == NL80211_IFTYPE_ADHOC) {
  2870. struct ieee80211_if_ibss *ifibss = &sdata->u.ibss;
  2871. struct ieee80211_hdr *hdr;
  2872. beacon = rcu_dereference(ifibss->presp);
  2873. if (!beacon)
  2874. goto out;
  2875. if (beacon->csa_counter_offsets[0]) {
  2876. if (!is_template)
  2877. ieee80211_csa_update_counter(vif);
  2878. ieee80211_set_csa(sdata, beacon);
  2879. }
  2880. skb = dev_alloc_skb(local->tx_headroom + beacon->head_len +
  2881. local->hw.extra_beacon_tailroom);
  2882. if (!skb)
  2883. goto out;
  2884. skb_reserve(skb, local->tx_headroom);
  2885. memcpy(skb_put(skb, beacon->head_len), beacon->head,
  2886. beacon->head_len);
  2887. hdr = (struct ieee80211_hdr *) skb->data;
  2888. hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
  2889. IEEE80211_STYPE_BEACON);
  2890. } else if (ieee80211_vif_is_mesh(&sdata->vif)) {
  2891. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  2892. beacon = rcu_dereference(ifmsh->beacon);
  2893. if (!beacon)
  2894. goto out;
  2895. if (beacon->csa_counter_offsets[0]) {
  2896. if (!is_template)
  2897. /* TODO: For mesh csa_counter is in TU, so
  2898. * decrementing it by one isn't correct, but
  2899. * for now we leave it consistent with overall
  2900. * mac80211's behavior.
  2901. */
  2902. ieee80211_csa_update_counter(vif);
  2903. ieee80211_set_csa(sdata, beacon);
  2904. }
  2905. if (ifmsh->sync_ops)
  2906. ifmsh->sync_ops->adjust_tbtt(sdata, beacon);
  2907. skb = dev_alloc_skb(local->tx_headroom +
  2908. beacon->head_len +
  2909. 256 + /* TIM IE */
  2910. beacon->tail_len +
  2911. local->hw.extra_beacon_tailroom);
  2912. if (!skb)
  2913. goto out;
  2914. skb_reserve(skb, local->tx_headroom);
  2915. memcpy(skb_put(skb, beacon->head_len), beacon->head,
  2916. beacon->head_len);
  2917. ieee80211_beacon_add_tim(sdata, &ifmsh->ps, skb, is_template);
  2918. if (offs) {
  2919. offs->tim_offset = beacon->head_len;
  2920. offs->tim_length = skb->len - beacon->head_len;
  2921. }
  2922. memcpy(skb_put(skb, beacon->tail_len), beacon->tail,
  2923. beacon->tail_len);
  2924. } else {
  2925. WARN_ON(1);
  2926. goto out;
  2927. }
  2928. /* CSA offsets */
  2929. if (offs && beacon) {
  2930. int i;
  2931. for (i = 0; i < IEEE80211_MAX_CSA_COUNTERS_NUM; i++) {
  2932. u16 csa_off = beacon->csa_counter_offsets[i];
  2933. if (!csa_off)
  2934. continue;
  2935. offs->csa_counter_offs[i] = csa_off_base + csa_off;
  2936. }
  2937. }
  2938. band = chanctx_conf->def.chan->band;
  2939. info = IEEE80211_SKB_CB(skb);
  2940. info->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
  2941. info->flags |= IEEE80211_TX_CTL_NO_ACK;
  2942. info->band = band;
  2943. memset(&txrc, 0, sizeof(txrc));
  2944. txrc.hw = hw;
  2945. txrc.sband = local->hw.wiphy->bands[band];
  2946. txrc.bss_conf = &sdata->vif.bss_conf;
  2947. txrc.skb = skb;
  2948. txrc.reported_rate.idx = -1;
  2949. txrc.rate_idx_mask = sdata->rc_rateidx_mask[band];
  2950. if (txrc.rate_idx_mask == (1 << txrc.sband->n_bitrates) - 1)
  2951. txrc.max_rate_idx = -1;
  2952. else
  2953. txrc.max_rate_idx = fls(txrc.rate_idx_mask) - 1;
  2954. txrc.bss = true;
  2955. rate_control_get_rate(sdata, NULL, &txrc);
  2956. info->control.vif = vif;
  2957. info->flags |= IEEE80211_TX_CTL_CLEAR_PS_FILT |
  2958. IEEE80211_TX_CTL_ASSIGN_SEQ |
  2959. IEEE80211_TX_CTL_FIRST_FRAGMENT;
  2960. out:
  2961. rcu_read_unlock();
  2962. return skb;
  2963. }
  2964. struct sk_buff *
  2965. ieee80211_beacon_get_template(struct ieee80211_hw *hw,
  2966. struct ieee80211_vif *vif,
  2967. struct ieee80211_mutable_offsets *offs)
  2968. {
  2969. return __ieee80211_beacon_get(hw, vif, offs, true);
  2970. }
  2971. EXPORT_SYMBOL(ieee80211_beacon_get_template);
  2972. struct sk_buff *ieee80211_beacon_get_tim(struct ieee80211_hw *hw,
  2973. struct ieee80211_vif *vif,
  2974. u16 *tim_offset, u16 *tim_length)
  2975. {
  2976. struct ieee80211_mutable_offsets offs = {};
  2977. struct sk_buff *bcn = __ieee80211_beacon_get(hw, vif, &offs, false);
  2978. if (tim_offset)
  2979. *tim_offset = offs.tim_offset;
  2980. if (tim_length)
  2981. *tim_length = offs.tim_length;
  2982. return bcn;
  2983. }
  2984. EXPORT_SYMBOL(ieee80211_beacon_get_tim);
  2985. struct sk_buff *ieee80211_proberesp_get(struct ieee80211_hw *hw,
  2986. struct ieee80211_vif *vif)
  2987. {
  2988. struct ieee80211_if_ap *ap = NULL;
  2989. struct sk_buff *skb = NULL;
  2990. struct probe_resp *presp = NULL;
  2991. struct ieee80211_hdr *hdr;
  2992. struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
  2993. if (sdata->vif.type != NL80211_IFTYPE_AP)
  2994. return NULL;
  2995. rcu_read_lock();
  2996. ap = &sdata->u.ap;
  2997. presp = rcu_dereference(ap->probe_resp);
  2998. if (!presp)
  2999. goto out;
  3000. skb = dev_alloc_skb(presp->len);
  3001. if (!skb)
  3002. goto out;
  3003. memcpy(skb_put(skb, presp->len), presp->data, presp->len);
  3004. hdr = (struct ieee80211_hdr *) skb->data;
  3005. memset(hdr->addr1, 0, sizeof(hdr->addr1));
  3006. out:
  3007. rcu_read_unlock();
  3008. return skb;
  3009. }
  3010. EXPORT_SYMBOL(ieee80211_proberesp_get);
  3011. struct sk_buff *ieee80211_pspoll_get(struct ieee80211_hw *hw,
  3012. struct ieee80211_vif *vif)
  3013. {
  3014. struct ieee80211_sub_if_data *sdata;
  3015. struct ieee80211_if_managed *ifmgd;
  3016. struct ieee80211_pspoll *pspoll;
  3017. struct ieee80211_local *local;
  3018. struct sk_buff *skb;
  3019. if (WARN_ON(vif->type != NL80211_IFTYPE_STATION))
  3020. return NULL;
  3021. sdata = vif_to_sdata(vif);
  3022. ifmgd = &sdata->u.mgd;
  3023. local = sdata->local;
  3024. skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*pspoll));
  3025. if (!skb)
  3026. return NULL;
  3027. skb_reserve(skb, local->hw.extra_tx_headroom);
  3028. pspoll = (struct ieee80211_pspoll *) skb_put(skb, sizeof(*pspoll));
  3029. memset(pspoll, 0, sizeof(*pspoll));
  3030. pspoll->frame_control = cpu_to_le16(IEEE80211_FTYPE_CTL |
  3031. IEEE80211_STYPE_PSPOLL);
  3032. pspoll->aid = cpu_to_le16(ifmgd->aid);
  3033. /* aid in PS-Poll has its two MSBs each set to 1 */
  3034. pspoll->aid |= cpu_to_le16(1 << 15 | 1 << 14);
  3035. memcpy(pspoll->bssid, ifmgd->bssid, ETH_ALEN);
  3036. memcpy(pspoll->ta, vif->addr, ETH_ALEN);
  3037. return skb;
  3038. }
  3039. EXPORT_SYMBOL(ieee80211_pspoll_get);
  3040. struct sk_buff *ieee80211_nullfunc_get(struct ieee80211_hw *hw,
  3041. struct ieee80211_vif *vif)
  3042. {
  3043. struct ieee80211_hdr_3addr *nullfunc;
  3044. struct ieee80211_sub_if_data *sdata;
  3045. struct ieee80211_if_managed *ifmgd;
  3046. struct ieee80211_local *local;
  3047. struct sk_buff *skb;
  3048. if (WARN_ON(vif->type != NL80211_IFTYPE_STATION))
  3049. return NULL;
  3050. sdata = vif_to_sdata(vif);
  3051. ifmgd = &sdata->u.mgd;
  3052. local = sdata->local;
  3053. skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*nullfunc));
  3054. if (!skb)
  3055. return NULL;
  3056. skb_reserve(skb, local->hw.extra_tx_headroom);
  3057. nullfunc = (struct ieee80211_hdr_3addr *) skb_put(skb,
  3058. sizeof(*nullfunc));
  3059. memset(nullfunc, 0, sizeof(*nullfunc));
  3060. nullfunc->frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
  3061. IEEE80211_STYPE_NULLFUNC |
  3062. IEEE80211_FCTL_TODS);
  3063. memcpy(nullfunc->addr1, ifmgd->bssid, ETH_ALEN);
  3064. memcpy(nullfunc->addr2, vif->addr, ETH_ALEN);
  3065. memcpy(nullfunc->addr3, ifmgd->bssid, ETH_ALEN);
  3066. return skb;
  3067. }
  3068. EXPORT_SYMBOL(ieee80211_nullfunc_get);
  3069. struct sk_buff *ieee80211_probereq_get(struct ieee80211_hw *hw,
  3070. const u8 *src_addr,
  3071. const u8 *ssid, size_t ssid_len,
  3072. size_t tailroom)
  3073. {
  3074. struct ieee80211_local *local = hw_to_local(hw);
  3075. struct ieee80211_hdr_3addr *hdr;
  3076. struct sk_buff *skb;
  3077. size_t ie_ssid_len;
  3078. u8 *pos;
  3079. ie_ssid_len = 2 + ssid_len;
  3080. skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*hdr) +
  3081. ie_ssid_len + tailroom);
  3082. if (!skb)
  3083. return NULL;
  3084. skb_reserve(skb, local->hw.extra_tx_headroom);
  3085. hdr = (struct ieee80211_hdr_3addr *) skb_put(skb, sizeof(*hdr));
  3086. memset(hdr, 0, sizeof(*hdr));
  3087. hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
  3088. IEEE80211_STYPE_PROBE_REQ);
  3089. eth_broadcast_addr(hdr->addr1);
  3090. memcpy(hdr->addr2, src_addr, ETH_ALEN);
  3091. eth_broadcast_addr(hdr->addr3);
  3092. pos = skb_put(skb, ie_ssid_len);
  3093. *pos++ = WLAN_EID_SSID;
  3094. *pos++ = ssid_len;
  3095. if (ssid_len)
  3096. memcpy(pos, ssid, ssid_len);
  3097. pos += ssid_len;
  3098. return skb;
  3099. }
  3100. EXPORT_SYMBOL(ieee80211_probereq_get);
  3101. void ieee80211_rts_get(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
  3102. const void *frame, size_t frame_len,
  3103. const struct ieee80211_tx_info *frame_txctl,
  3104. struct ieee80211_rts *rts)
  3105. {
  3106. const struct ieee80211_hdr *hdr = frame;
  3107. rts->frame_control =
  3108. cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_RTS);
  3109. rts->duration = ieee80211_rts_duration(hw, vif, frame_len,
  3110. frame_txctl);
  3111. memcpy(rts->ra, hdr->addr1, sizeof(rts->ra));
  3112. memcpy(rts->ta, hdr->addr2, sizeof(rts->ta));
  3113. }
  3114. EXPORT_SYMBOL(ieee80211_rts_get);
  3115. void ieee80211_ctstoself_get(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
  3116. const void *frame, size_t frame_len,
  3117. const struct ieee80211_tx_info *frame_txctl,
  3118. struct ieee80211_cts *cts)
  3119. {
  3120. const struct ieee80211_hdr *hdr = frame;
  3121. cts->frame_control =
  3122. cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_CTS);
  3123. cts->duration = ieee80211_ctstoself_duration(hw, vif,
  3124. frame_len, frame_txctl);
  3125. memcpy(cts->ra, hdr->addr1, sizeof(cts->ra));
  3126. }
  3127. EXPORT_SYMBOL(ieee80211_ctstoself_get);
  3128. struct sk_buff *
  3129. ieee80211_get_buffered_bc(struct ieee80211_hw *hw,
  3130. struct ieee80211_vif *vif)
  3131. {
  3132. struct ieee80211_local *local = hw_to_local(hw);
  3133. struct sk_buff *skb = NULL;
  3134. struct ieee80211_tx_data tx;
  3135. struct ieee80211_sub_if_data *sdata;
  3136. struct ps_data *ps;
  3137. struct ieee80211_tx_info *info;
  3138. struct ieee80211_chanctx_conf *chanctx_conf;
  3139. sdata = vif_to_sdata(vif);
  3140. rcu_read_lock();
  3141. chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
  3142. if (!chanctx_conf)
  3143. goto out;
  3144. if (sdata->vif.type == NL80211_IFTYPE_AP) {
  3145. struct beacon_data *beacon =
  3146. rcu_dereference(sdata->u.ap.beacon);
  3147. if (!beacon || !beacon->head)
  3148. goto out;
  3149. ps = &sdata->u.ap.ps;
  3150. } else if (ieee80211_vif_is_mesh(&sdata->vif)) {
  3151. ps = &sdata->u.mesh.ps;
  3152. } else {
  3153. goto out;
  3154. }
  3155. if (ps->dtim_count != 0 || !ps->dtim_bc_mc)
  3156. goto out; /* send buffered bc/mc only after DTIM beacon */
  3157. while (1) {
  3158. skb = skb_dequeue(&ps->bc_buf);
  3159. if (!skb)
  3160. goto out;
  3161. local->total_ps_buffered--;
  3162. if (!skb_queue_empty(&ps->bc_buf) && skb->len >= 2) {
  3163. struct ieee80211_hdr *hdr =
  3164. (struct ieee80211_hdr *) skb->data;
  3165. /* more buffered multicast/broadcast frames ==> set
  3166. * MoreData flag in IEEE 802.11 header to inform PS
  3167. * STAs */
  3168. hdr->frame_control |=
  3169. cpu_to_le16(IEEE80211_FCTL_MOREDATA);
  3170. }
  3171. if (sdata->vif.type == NL80211_IFTYPE_AP)
  3172. sdata = IEEE80211_DEV_TO_SUB_IF(skb->dev);
  3173. if (!ieee80211_tx_prepare(sdata, &tx, NULL, skb))
  3174. break;
  3175. dev_kfree_skb_any(skb);
  3176. }
  3177. info = IEEE80211_SKB_CB(skb);
  3178. tx.flags |= IEEE80211_TX_PS_BUFFERED;
  3179. info->band = chanctx_conf->def.chan->band;
  3180. if (invoke_tx_handlers(&tx))
  3181. skb = NULL;
  3182. out:
  3183. rcu_read_unlock();
  3184. return skb;
  3185. }
  3186. EXPORT_SYMBOL(ieee80211_get_buffered_bc);
  3187. int ieee80211_reserve_tid(struct ieee80211_sta *pubsta, u8 tid)
  3188. {
  3189. struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
  3190. struct ieee80211_sub_if_data *sdata = sta->sdata;
  3191. struct ieee80211_local *local = sdata->local;
  3192. int ret;
  3193. u32 queues;
  3194. lockdep_assert_held(&local->sta_mtx);
  3195. /* only some cases are supported right now */
  3196. switch (sdata->vif.type) {
  3197. case NL80211_IFTYPE_STATION:
  3198. case NL80211_IFTYPE_AP:
  3199. case NL80211_IFTYPE_AP_VLAN:
  3200. break;
  3201. default:
  3202. WARN_ON(1);
  3203. return -EINVAL;
  3204. }
  3205. if (WARN_ON(tid >= IEEE80211_NUM_UPS))
  3206. return -EINVAL;
  3207. if (sta->reserved_tid == tid) {
  3208. ret = 0;
  3209. goto out;
  3210. }
  3211. if (sta->reserved_tid != IEEE80211_TID_UNRESERVED) {
  3212. sdata_err(sdata, "TID reservation already active\n");
  3213. ret = -EALREADY;
  3214. goto out;
  3215. }
  3216. ieee80211_stop_vif_queues(sdata->local, sdata,
  3217. IEEE80211_QUEUE_STOP_REASON_RESERVE_TID);
  3218. synchronize_net();
  3219. /* Tear down BA sessions so we stop aggregating on this TID */
  3220. if (ieee80211_hw_check(&local->hw, AMPDU_AGGREGATION)) {
  3221. set_sta_flag(sta, WLAN_STA_BLOCK_BA);
  3222. __ieee80211_stop_tx_ba_session(sta, tid,
  3223. AGG_STOP_LOCAL_REQUEST);
  3224. }
  3225. queues = BIT(sdata->vif.hw_queue[ieee802_1d_to_ac[tid]]);
  3226. __ieee80211_flush_queues(local, sdata, queues, false);
  3227. sta->reserved_tid = tid;
  3228. ieee80211_wake_vif_queues(local, sdata,
  3229. IEEE80211_QUEUE_STOP_REASON_RESERVE_TID);
  3230. if (ieee80211_hw_check(&local->hw, AMPDU_AGGREGATION))
  3231. clear_sta_flag(sta, WLAN_STA_BLOCK_BA);
  3232. ret = 0;
  3233. out:
  3234. return ret;
  3235. }
  3236. EXPORT_SYMBOL(ieee80211_reserve_tid);
  3237. void ieee80211_unreserve_tid(struct ieee80211_sta *pubsta, u8 tid)
  3238. {
  3239. struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
  3240. struct ieee80211_sub_if_data *sdata = sta->sdata;
  3241. lockdep_assert_held(&sdata->local->sta_mtx);
  3242. /* only some cases are supported right now */
  3243. switch (sdata->vif.type) {
  3244. case NL80211_IFTYPE_STATION:
  3245. case NL80211_IFTYPE_AP:
  3246. case NL80211_IFTYPE_AP_VLAN:
  3247. break;
  3248. default:
  3249. WARN_ON(1);
  3250. return;
  3251. }
  3252. if (tid != sta->reserved_tid) {
  3253. sdata_err(sdata, "TID to unreserve (%d) isn't reserved\n", tid);
  3254. return;
  3255. }
  3256. sta->reserved_tid = IEEE80211_TID_UNRESERVED;
  3257. }
  3258. EXPORT_SYMBOL(ieee80211_unreserve_tid);
  3259. void __ieee80211_tx_skb_tid_band(struct ieee80211_sub_if_data *sdata,
  3260. struct sk_buff *skb, int tid,
  3261. enum ieee80211_band band)
  3262. {
  3263. int ac = ieee802_1d_to_ac[tid & 7];
  3264. skb_set_mac_header(skb, 0);
  3265. skb_set_network_header(skb, 0);
  3266. skb_set_transport_header(skb, 0);
  3267. skb_set_queue_mapping(skb, ac);
  3268. skb->priority = tid;
  3269. skb->dev = sdata->dev;
  3270. /*
  3271. * The other path calling ieee80211_xmit is from the tasklet,
  3272. * and while we can handle concurrent transmissions locking
  3273. * requirements are that we do not come into tx with bhs on.
  3274. */
  3275. local_bh_disable();
  3276. IEEE80211_SKB_CB(skb)->band = band;
  3277. ieee80211_xmit(sdata, NULL, skb);
  3278. local_bh_enable();
  3279. }