tx.c 106 KB

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