tx.c 106 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916
  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. dev_kfree_skb(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 */
  373. if (!atomic_read(&ps->num_sta_ps))
  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. dev_kfree_skb(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. int tail_need = 0;
  1349. if (may_encrypt && sdata->crypto_tx_tailroom_needed_cnt) {
  1350. tail_need = IEEE80211_ENCRYPT_TAILROOM;
  1351. tail_need -= skb_tailroom(skb);
  1352. tail_need = max_t(int, tail_need, 0);
  1353. }
  1354. if (skb_cloned(skb) &&
  1355. (!ieee80211_hw_check(&local->hw, SUPPORTS_CLONED_SKBS) ||
  1356. !skb_clone_writable(skb, ETH_HLEN) ||
  1357. (may_encrypt && sdata->crypto_tx_tailroom_needed_cnt)))
  1358. I802_DEBUG_INC(local->tx_expand_skb_head_cloned);
  1359. else if (head_need || tail_need)
  1360. I802_DEBUG_INC(local->tx_expand_skb_head);
  1361. else
  1362. return 0;
  1363. if (pskb_expand_head(skb, head_need, tail_need, GFP_ATOMIC)) {
  1364. wiphy_debug(local->hw.wiphy,
  1365. "failed to reallocate TX buffer\n");
  1366. return -ENOMEM;
  1367. }
  1368. return 0;
  1369. }
  1370. void ieee80211_xmit(struct ieee80211_sub_if_data *sdata,
  1371. struct sta_info *sta, struct sk_buff *skb)
  1372. {
  1373. struct ieee80211_local *local = sdata->local;
  1374. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  1375. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
  1376. int headroom;
  1377. bool may_encrypt;
  1378. may_encrypt = !(info->flags & IEEE80211_TX_INTFL_DONT_ENCRYPT);
  1379. headroom = local->tx_headroom;
  1380. if (may_encrypt)
  1381. headroom += sdata->encrypt_headroom;
  1382. headroom -= skb_headroom(skb);
  1383. headroom = max_t(int, 0, headroom);
  1384. if (ieee80211_skb_resize(sdata, skb, headroom, may_encrypt)) {
  1385. ieee80211_free_txskb(&local->hw, skb);
  1386. return;
  1387. }
  1388. hdr = (struct ieee80211_hdr *) skb->data;
  1389. info->control.vif = &sdata->vif;
  1390. if (ieee80211_vif_is_mesh(&sdata->vif)) {
  1391. if (ieee80211_is_data(hdr->frame_control) &&
  1392. is_unicast_ether_addr(hdr->addr1)) {
  1393. if (mesh_nexthop_resolve(sdata, skb))
  1394. return; /* skb queued: don't free */
  1395. } else {
  1396. ieee80211_mps_set_frame_flags(sdata, NULL, hdr);
  1397. }
  1398. }
  1399. ieee80211_set_qos_hdr(sdata, skb);
  1400. ieee80211_tx(sdata, sta, skb, false);
  1401. }
  1402. static bool ieee80211_parse_tx_radiotap(struct sk_buff *skb)
  1403. {
  1404. struct ieee80211_radiotap_iterator iterator;
  1405. struct ieee80211_radiotap_header *rthdr =
  1406. (struct ieee80211_radiotap_header *) skb->data;
  1407. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  1408. int ret = ieee80211_radiotap_iterator_init(&iterator, rthdr, skb->len,
  1409. NULL);
  1410. u16 txflags;
  1411. info->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT |
  1412. IEEE80211_TX_CTL_DONTFRAG;
  1413. /*
  1414. * for every radiotap entry that is present
  1415. * (ieee80211_radiotap_iterator_next returns -ENOENT when no more
  1416. * entries present, or -EINVAL on error)
  1417. */
  1418. while (!ret) {
  1419. ret = ieee80211_radiotap_iterator_next(&iterator);
  1420. if (ret)
  1421. continue;
  1422. /* see if this argument is something we can use */
  1423. switch (iterator.this_arg_index) {
  1424. /*
  1425. * You must take care when dereferencing iterator.this_arg
  1426. * for multibyte types... the pointer is not aligned. Use
  1427. * get_unaligned((type *)iterator.this_arg) to dereference
  1428. * iterator.this_arg for type "type" safely on all arches.
  1429. */
  1430. case IEEE80211_RADIOTAP_FLAGS:
  1431. if (*iterator.this_arg & IEEE80211_RADIOTAP_F_FCS) {
  1432. /*
  1433. * this indicates that the skb we have been
  1434. * handed has the 32-bit FCS CRC at the end...
  1435. * we should react to that by snipping it off
  1436. * because it will be recomputed and added
  1437. * on transmission
  1438. */
  1439. if (skb->len < (iterator._max_length + FCS_LEN))
  1440. return false;
  1441. skb_trim(skb, skb->len - FCS_LEN);
  1442. }
  1443. if (*iterator.this_arg & IEEE80211_RADIOTAP_F_WEP)
  1444. info->flags &= ~IEEE80211_TX_INTFL_DONT_ENCRYPT;
  1445. if (*iterator.this_arg & IEEE80211_RADIOTAP_F_FRAG)
  1446. info->flags &= ~IEEE80211_TX_CTL_DONTFRAG;
  1447. break;
  1448. case IEEE80211_RADIOTAP_TX_FLAGS:
  1449. txflags = get_unaligned_le16(iterator.this_arg);
  1450. if (txflags & IEEE80211_RADIOTAP_F_TX_NOACK)
  1451. info->flags |= IEEE80211_TX_CTL_NO_ACK;
  1452. break;
  1453. /*
  1454. * Please update the file
  1455. * Documentation/networking/mac80211-injection.txt
  1456. * when parsing new fields here.
  1457. */
  1458. default:
  1459. break;
  1460. }
  1461. }
  1462. if (ret != -ENOENT) /* ie, if we didn't simply run out of fields */
  1463. return false;
  1464. /*
  1465. * remove the radiotap header
  1466. * iterator->_max_length was sanity-checked against
  1467. * skb->len by iterator init
  1468. */
  1469. skb_pull(skb, iterator._max_length);
  1470. return true;
  1471. }
  1472. netdev_tx_t ieee80211_monitor_start_xmit(struct sk_buff *skb,
  1473. struct net_device *dev)
  1474. {
  1475. struct ieee80211_local *local = wdev_priv(dev->ieee80211_ptr);
  1476. struct ieee80211_chanctx_conf *chanctx_conf;
  1477. struct ieee80211_radiotap_header *prthdr =
  1478. (struct ieee80211_radiotap_header *)skb->data;
  1479. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  1480. struct ieee80211_hdr *hdr;
  1481. struct ieee80211_sub_if_data *tmp_sdata, *sdata;
  1482. struct cfg80211_chan_def *chandef;
  1483. u16 len_rthdr;
  1484. int hdrlen;
  1485. /* check for not even having the fixed radiotap header part */
  1486. if (unlikely(skb->len < sizeof(struct ieee80211_radiotap_header)))
  1487. goto fail; /* too short to be possibly valid */
  1488. /* is it a header version we can trust to find length from? */
  1489. if (unlikely(prthdr->it_version))
  1490. goto fail; /* only version 0 is supported */
  1491. /* then there must be a radiotap header with a length we can use */
  1492. len_rthdr = ieee80211_get_radiotap_len(skb->data);
  1493. /* does the skb contain enough to deliver on the alleged length? */
  1494. if (unlikely(skb->len < len_rthdr))
  1495. goto fail; /* skb too short for claimed rt header extent */
  1496. /*
  1497. * fix up the pointers accounting for the radiotap
  1498. * header still being in there. We are being given
  1499. * a precooked IEEE80211 header so no need for
  1500. * normal processing
  1501. */
  1502. skb_set_mac_header(skb, len_rthdr);
  1503. /*
  1504. * these are just fixed to the end of the rt area since we
  1505. * don't have any better information and at this point, nobody cares
  1506. */
  1507. skb_set_network_header(skb, len_rthdr);
  1508. skb_set_transport_header(skb, len_rthdr);
  1509. if (skb->len < len_rthdr + 2)
  1510. goto fail;
  1511. hdr = (struct ieee80211_hdr *)(skb->data + len_rthdr);
  1512. hdrlen = ieee80211_hdrlen(hdr->frame_control);
  1513. if (skb->len < len_rthdr + hdrlen)
  1514. goto fail;
  1515. /*
  1516. * Initialize skb->protocol if the injected frame is a data frame
  1517. * carrying a rfc1042 header
  1518. */
  1519. if (ieee80211_is_data(hdr->frame_control) &&
  1520. skb->len >= len_rthdr + hdrlen + sizeof(rfc1042_header) + 2) {
  1521. u8 *payload = (u8 *)hdr + hdrlen;
  1522. if (ether_addr_equal(payload, rfc1042_header))
  1523. skb->protocol = cpu_to_be16((payload[6] << 8) |
  1524. payload[7]);
  1525. }
  1526. memset(info, 0, sizeof(*info));
  1527. info->flags = IEEE80211_TX_CTL_REQ_TX_STATUS |
  1528. IEEE80211_TX_CTL_INJECTED;
  1529. /* process and remove the injection radiotap header */
  1530. if (!ieee80211_parse_tx_radiotap(skb))
  1531. goto fail;
  1532. rcu_read_lock();
  1533. /*
  1534. * We process outgoing injected frames that have a local address
  1535. * we handle as though they are non-injected frames.
  1536. * This code here isn't entirely correct, the local MAC address
  1537. * isn't always enough to find the interface to use; for proper
  1538. * VLAN/WDS support we will need a different mechanism (which
  1539. * likely isn't going to be monitor interfaces).
  1540. */
  1541. sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  1542. list_for_each_entry_rcu(tmp_sdata, &local->interfaces, list) {
  1543. if (!ieee80211_sdata_running(tmp_sdata))
  1544. continue;
  1545. if (tmp_sdata->vif.type == NL80211_IFTYPE_MONITOR ||
  1546. tmp_sdata->vif.type == NL80211_IFTYPE_AP_VLAN ||
  1547. tmp_sdata->vif.type == NL80211_IFTYPE_WDS)
  1548. continue;
  1549. if (ether_addr_equal(tmp_sdata->vif.addr, hdr->addr2)) {
  1550. sdata = tmp_sdata;
  1551. break;
  1552. }
  1553. }
  1554. chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
  1555. if (!chanctx_conf) {
  1556. tmp_sdata = rcu_dereference(local->monitor_sdata);
  1557. if (tmp_sdata)
  1558. chanctx_conf =
  1559. rcu_dereference(tmp_sdata->vif.chanctx_conf);
  1560. }
  1561. if (chanctx_conf)
  1562. chandef = &chanctx_conf->def;
  1563. else if (!local->use_chanctx)
  1564. chandef = &local->_oper_chandef;
  1565. else
  1566. goto fail_rcu;
  1567. /*
  1568. * Frame injection is not allowed if beaconing is not allowed
  1569. * or if we need radar detection. Beaconing is usually not allowed when
  1570. * the mode or operation (Adhoc, AP, Mesh) does not support DFS.
  1571. * Passive scan is also used in world regulatory domains where
  1572. * your country is not known and as such it should be treated as
  1573. * NO TX unless the channel is explicitly allowed in which case
  1574. * your current regulatory domain would not have the passive scan
  1575. * flag.
  1576. *
  1577. * Since AP mode uses monitor interfaces to inject/TX management
  1578. * frames we can make AP mode the exception to this rule once it
  1579. * supports radar detection as its implementation can deal with
  1580. * radar detection by itself. We can do that later by adding a
  1581. * monitor flag interfaces used for AP support.
  1582. */
  1583. if (!cfg80211_reg_can_beacon(local->hw.wiphy, chandef,
  1584. sdata->vif.type))
  1585. goto fail_rcu;
  1586. info->band = chandef->chan->band;
  1587. ieee80211_xmit(sdata, NULL, skb);
  1588. rcu_read_unlock();
  1589. return NETDEV_TX_OK;
  1590. fail_rcu:
  1591. rcu_read_unlock();
  1592. fail:
  1593. dev_kfree_skb(skb);
  1594. return NETDEV_TX_OK; /* meaning, we dealt with the skb */
  1595. }
  1596. static inline bool ieee80211_is_tdls_setup(struct sk_buff *skb)
  1597. {
  1598. u16 ethertype = (skb->data[12] << 8) | skb->data[13];
  1599. return ethertype == ETH_P_TDLS &&
  1600. skb->len > 14 &&
  1601. skb->data[14] == WLAN_TDLS_SNAP_RFTYPE;
  1602. }
  1603. static int ieee80211_lookup_ra_sta(struct ieee80211_sub_if_data *sdata,
  1604. struct sk_buff *skb,
  1605. struct sta_info **sta_out)
  1606. {
  1607. struct sta_info *sta;
  1608. switch (sdata->vif.type) {
  1609. case NL80211_IFTYPE_AP_VLAN:
  1610. sta = rcu_dereference(sdata->u.vlan.sta);
  1611. if (sta) {
  1612. *sta_out = sta;
  1613. return 0;
  1614. } else if (sdata->wdev.use_4addr) {
  1615. return -ENOLINK;
  1616. }
  1617. /* fall through */
  1618. case NL80211_IFTYPE_AP:
  1619. case NL80211_IFTYPE_OCB:
  1620. case NL80211_IFTYPE_ADHOC:
  1621. if (is_multicast_ether_addr(skb->data)) {
  1622. *sta_out = ERR_PTR(-ENOENT);
  1623. return 0;
  1624. }
  1625. sta = sta_info_get_bss(sdata, skb->data);
  1626. break;
  1627. case NL80211_IFTYPE_WDS:
  1628. sta = sta_info_get(sdata, sdata->u.wds.remote_addr);
  1629. break;
  1630. #ifdef CONFIG_MAC80211_MESH
  1631. case NL80211_IFTYPE_MESH_POINT:
  1632. /* determined much later */
  1633. *sta_out = NULL;
  1634. return 0;
  1635. #endif
  1636. case NL80211_IFTYPE_STATION:
  1637. if (sdata->wdev.wiphy->flags & WIPHY_FLAG_SUPPORTS_TDLS) {
  1638. sta = sta_info_get(sdata, skb->data);
  1639. if (sta) {
  1640. bool tdls_peer, tdls_auth;
  1641. tdls_peer = test_sta_flag(sta,
  1642. WLAN_STA_TDLS_PEER);
  1643. tdls_auth = test_sta_flag(sta,
  1644. WLAN_STA_TDLS_PEER_AUTH);
  1645. if (tdls_peer && tdls_auth) {
  1646. *sta_out = sta;
  1647. return 0;
  1648. }
  1649. /*
  1650. * TDLS link during setup - throw out frames to
  1651. * peer. Allow TDLS-setup frames to unauthorized
  1652. * peers for the special case of a link teardown
  1653. * after a TDLS sta is removed due to being
  1654. * unreachable.
  1655. */
  1656. if (tdls_peer && !tdls_auth &&
  1657. !ieee80211_is_tdls_setup(skb))
  1658. return -EINVAL;
  1659. }
  1660. }
  1661. sta = sta_info_get(sdata, sdata->u.mgd.bssid);
  1662. if (!sta)
  1663. return -ENOLINK;
  1664. break;
  1665. default:
  1666. return -EINVAL;
  1667. }
  1668. *sta_out = sta ?: ERR_PTR(-ENOENT);
  1669. return 0;
  1670. }
  1671. /**
  1672. * ieee80211_build_hdr - build 802.11 header in the given frame
  1673. * @sdata: virtual interface to build the header for
  1674. * @skb: the skb to build the header in
  1675. * @info_flags: skb flags to set
  1676. *
  1677. * This function takes the skb with 802.3 header and reformats the header to
  1678. * the appropriate IEEE 802.11 header based on which interface the packet is
  1679. * being transmitted on.
  1680. *
  1681. * Note that this function also takes care of the TX status request and
  1682. * potential unsharing of the SKB - this needs to be interleaved with the
  1683. * header building.
  1684. *
  1685. * The function requires the read-side RCU lock held
  1686. *
  1687. * Returns: the (possibly reallocated) skb or an ERR_PTR() code
  1688. */
  1689. static struct sk_buff *ieee80211_build_hdr(struct ieee80211_sub_if_data *sdata,
  1690. struct sk_buff *skb, u32 info_flags,
  1691. struct sta_info *sta)
  1692. {
  1693. struct ieee80211_local *local = sdata->local;
  1694. struct ieee80211_tx_info *info;
  1695. int head_need;
  1696. u16 ethertype, hdrlen, meshhdrlen = 0;
  1697. __le16 fc;
  1698. struct ieee80211_hdr hdr;
  1699. struct ieee80211s_hdr mesh_hdr __maybe_unused;
  1700. struct mesh_path __maybe_unused *mppath = NULL, *mpath = NULL;
  1701. const u8 *encaps_data;
  1702. int encaps_len, skip_header_bytes;
  1703. int nh_pos, h_pos;
  1704. bool wme_sta = false, authorized = false;
  1705. bool tdls_peer;
  1706. bool multicast;
  1707. u16 info_id = 0;
  1708. struct ieee80211_chanctx_conf *chanctx_conf;
  1709. struct ieee80211_sub_if_data *ap_sdata;
  1710. enum ieee80211_band band;
  1711. int ret;
  1712. if (IS_ERR(sta))
  1713. sta = NULL;
  1714. /* convert Ethernet header to proper 802.11 header (based on
  1715. * operation mode) */
  1716. ethertype = (skb->data[12] << 8) | skb->data[13];
  1717. fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_DATA);
  1718. switch (sdata->vif.type) {
  1719. case NL80211_IFTYPE_AP_VLAN:
  1720. if (sdata->wdev.use_4addr) {
  1721. fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS);
  1722. /* RA TA DA SA */
  1723. memcpy(hdr.addr1, sta->sta.addr, ETH_ALEN);
  1724. memcpy(hdr.addr2, sdata->vif.addr, ETH_ALEN);
  1725. memcpy(hdr.addr3, skb->data, ETH_ALEN);
  1726. memcpy(hdr.addr4, skb->data + ETH_ALEN, ETH_ALEN);
  1727. hdrlen = 30;
  1728. authorized = test_sta_flag(sta, WLAN_STA_AUTHORIZED);
  1729. wme_sta = sta->sta.wme;
  1730. }
  1731. ap_sdata = container_of(sdata->bss, struct ieee80211_sub_if_data,
  1732. u.ap);
  1733. chanctx_conf = rcu_dereference(ap_sdata->vif.chanctx_conf);
  1734. if (!chanctx_conf) {
  1735. ret = -ENOTCONN;
  1736. goto free;
  1737. }
  1738. band = chanctx_conf->def.chan->band;
  1739. if (sdata->wdev.use_4addr)
  1740. break;
  1741. /* fall through */
  1742. case NL80211_IFTYPE_AP:
  1743. if (sdata->vif.type == NL80211_IFTYPE_AP)
  1744. chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
  1745. if (!chanctx_conf) {
  1746. ret = -ENOTCONN;
  1747. goto free;
  1748. }
  1749. fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS);
  1750. /* DA BSSID SA */
  1751. memcpy(hdr.addr1, skb->data, ETH_ALEN);
  1752. memcpy(hdr.addr2, sdata->vif.addr, ETH_ALEN);
  1753. memcpy(hdr.addr3, skb->data + ETH_ALEN, ETH_ALEN);
  1754. hdrlen = 24;
  1755. band = chanctx_conf->def.chan->band;
  1756. break;
  1757. case NL80211_IFTYPE_WDS:
  1758. fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS);
  1759. /* RA TA DA SA */
  1760. memcpy(hdr.addr1, sdata->u.wds.remote_addr, ETH_ALEN);
  1761. memcpy(hdr.addr2, sdata->vif.addr, ETH_ALEN);
  1762. memcpy(hdr.addr3, skb->data, ETH_ALEN);
  1763. memcpy(hdr.addr4, skb->data + ETH_ALEN, ETH_ALEN);
  1764. hdrlen = 30;
  1765. /*
  1766. * This is the exception! WDS style interfaces are prohibited
  1767. * when channel contexts are in used so this must be valid
  1768. */
  1769. band = local->hw.conf.chandef.chan->band;
  1770. break;
  1771. #ifdef CONFIG_MAC80211_MESH
  1772. case NL80211_IFTYPE_MESH_POINT:
  1773. if (!is_multicast_ether_addr(skb->data)) {
  1774. struct sta_info *next_hop;
  1775. bool mpp_lookup = true;
  1776. mpath = mesh_path_lookup(sdata, skb->data);
  1777. if (mpath) {
  1778. mpp_lookup = false;
  1779. next_hop = rcu_dereference(mpath->next_hop);
  1780. if (!next_hop ||
  1781. !(mpath->flags & (MESH_PATH_ACTIVE |
  1782. MESH_PATH_RESOLVING)))
  1783. mpp_lookup = true;
  1784. }
  1785. if (mpp_lookup)
  1786. mppath = mpp_path_lookup(sdata, skb->data);
  1787. if (mppath && mpath)
  1788. mesh_path_del(mpath->sdata, mpath->dst);
  1789. }
  1790. /*
  1791. * Use address extension if it is a packet from
  1792. * another interface or if we know the destination
  1793. * is being proxied by a portal (i.e. portal address
  1794. * differs from proxied address)
  1795. */
  1796. if (ether_addr_equal(sdata->vif.addr, skb->data + ETH_ALEN) &&
  1797. !(mppath && !ether_addr_equal(mppath->mpp, skb->data))) {
  1798. hdrlen = ieee80211_fill_mesh_addresses(&hdr, &fc,
  1799. skb->data, skb->data + ETH_ALEN);
  1800. meshhdrlen = ieee80211_new_mesh_header(sdata, &mesh_hdr,
  1801. NULL, NULL);
  1802. } else {
  1803. /* DS -> MBSS (802.11-2012 13.11.3.3).
  1804. * For unicast with unknown forwarding information,
  1805. * destination might be in the MBSS or if that fails
  1806. * forwarded to another mesh gate. In either case
  1807. * resolution will be handled in ieee80211_xmit(), so
  1808. * leave the original DA. This also works for mcast */
  1809. const u8 *mesh_da = skb->data;
  1810. if (mppath)
  1811. mesh_da = mppath->mpp;
  1812. else if (mpath)
  1813. mesh_da = mpath->dst;
  1814. hdrlen = ieee80211_fill_mesh_addresses(&hdr, &fc,
  1815. mesh_da, sdata->vif.addr);
  1816. if (is_multicast_ether_addr(mesh_da))
  1817. /* DA TA mSA AE:SA */
  1818. meshhdrlen = ieee80211_new_mesh_header(
  1819. sdata, &mesh_hdr,
  1820. skb->data + ETH_ALEN, NULL);
  1821. else
  1822. /* RA TA mDA mSA AE:DA SA */
  1823. meshhdrlen = ieee80211_new_mesh_header(
  1824. sdata, &mesh_hdr, skb->data,
  1825. skb->data + ETH_ALEN);
  1826. }
  1827. chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
  1828. if (!chanctx_conf) {
  1829. ret = -ENOTCONN;
  1830. goto free;
  1831. }
  1832. band = chanctx_conf->def.chan->band;
  1833. break;
  1834. #endif
  1835. case NL80211_IFTYPE_STATION:
  1836. /* we already did checks when looking up the RA STA */
  1837. tdls_peer = test_sta_flag(sta, WLAN_STA_TDLS_PEER);
  1838. if (tdls_peer) {
  1839. /* DA SA BSSID */
  1840. memcpy(hdr.addr1, skb->data, ETH_ALEN);
  1841. memcpy(hdr.addr2, skb->data + ETH_ALEN, ETH_ALEN);
  1842. memcpy(hdr.addr3, sdata->u.mgd.bssid, ETH_ALEN);
  1843. hdrlen = 24;
  1844. } else if (sdata->u.mgd.use_4addr &&
  1845. cpu_to_be16(ethertype) != sdata->control_port_protocol) {
  1846. fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS |
  1847. IEEE80211_FCTL_TODS);
  1848. /* RA TA DA SA */
  1849. memcpy(hdr.addr1, sdata->u.mgd.bssid, ETH_ALEN);
  1850. memcpy(hdr.addr2, sdata->vif.addr, ETH_ALEN);
  1851. memcpy(hdr.addr3, skb->data, ETH_ALEN);
  1852. memcpy(hdr.addr4, skb->data + ETH_ALEN, ETH_ALEN);
  1853. hdrlen = 30;
  1854. } else {
  1855. fc |= cpu_to_le16(IEEE80211_FCTL_TODS);
  1856. /* BSSID SA DA */
  1857. memcpy(hdr.addr1, sdata->u.mgd.bssid, ETH_ALEN);
  1858. memcpy(hdr.addr2, skb->data + ETH_ALEN, ETH_ALEN);
  1859. memcpy(hdr.addr3, skb->data, ETH_ALEN);
  1860. hdrlen = 24;
  1861. }
  1862. chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
  1863. if (!chanctx_conf) {
  1864. ret = -ENOTCONN;
  1865. goto free;
  1866. }
  1867. band = chanctx_conf->def.chan->band;
  1868. break;
  1869. case NL80211_IFTYPE_OCB:
  1870. /* DA SA BSSID */
  1871. memcpy(hdr.addr1, skb->data, ETH_ALEN);
  1872. memcpy(hdr.addr2, skb->data + ETH_ALEN, ETH_ALEN);
  1873. eth_broadcast_addr(hdr.addr3);
  1874. hdrlen = 24;
  1875. chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
  1876. if (!chanctx_conf) {
  1877. ret = -ENOTCONN;
  1878. goto free;
  1879. }
  1880. band = chanctx_conf->def.chan->band;
  1881. break;
  1882. case NL80211_IFTYPE_ADHOC:
  1883. /* DA SA BSSID */
  1884. memcpy(hdr.addr1, skb->data, ETH_ALEN);
  1885. memcpy(hdr.addr2, skb->data + ETH_ALEN, ETH_ALEN);
  1886. memcpy(hdr.addr3, sdata->u.ibss.bssid, ETH_ALEN);
  1887. hdrlen = 24;
  1888. chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
  1889. if (!chanctx_conf) {
  1890. ret = -ENOTCONN;
  1891. goto free;
  1892. }
  1893. band = chanctx_conf->def.chan->band;
  1894. break;
  1895. default:
  1896. ret = -EINVAL;
  1897. goto free;
  1898. }
  1899. multicast = is_multicast_ether_addr(hdr.addr1);
  1900. /* sta is always NULL for mesh */
  1901. if (sta) {
  1902. authorized = test_sta_flag(sta, WLAN_STA_AUTHORIZED);
  1903. wme_sta = sta->sta.wme;
  1904. } else if (ieee80211_vif_is_mesh(&sdata->vif)) {
  1905. /* For mesh, the use of the QoS header is mandatory */
  1906. wme_sta = true;
  1907. }
  1908. /* receiver does QoS (which also means we do) use it */
  1909. if (wme_sta) {
  1910. fc |= cpu_to_le16(IEEE80211_STYPE_QOS_DATA);
  1911. hdrlen += 2;
  1912. }
  1913. /*
  1914. * Drop unicast frames to unauthorised stations unless they are
  1915. * EAPOL frames from the local station.
  1916. */
  1917. if (unlikely(!ieee80211_vif_is_mesh(&sdata->vif) &&
  1918. (sdata->vif.type != NL80211_IFTYPE_OCB) &&
  1919. !multicast && !authorized &&
  1920. (cpu_to_be16(ethertype) != sdata->control_port_protocol ||
  1921. !ether_addr_equal(sdata->vif.addr, skb->data + ETH_ALEN)))) {
  1922. #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
  1923. net_info_ratelimited("%s: dropped frame to %pM (unauthorized port)\n",
  1924. sdata->name, hdr.addr1);
  1925. #endif
  1926. I802_DEBUG_INC(local->tx_handlers_drop_unauth_port);
  1927. ret = -EPERM;
  1928. goto free;
  1929. }
  1930. if (unlikely(!multicast && skb->sk &&
  1931. skb_shinfo(skb)->tx_flags & SKBTX_WIFI_STATUS)) {
  1932. struct sk_buff *ack_skb = skb_clone_sk(skb);
  1933. if (ack_skb) {
  1934. unsigned long flags;
  1935. int id;
  1936. spin_lock_irqsave(&local->ack_status_lock, flags);
  1937. id = idr_alloc(&local->ack_status_frames, ack_skb,
  1938. 1, 0x10000, GFP_ATOMIC);
  1939. spin_unlock_irqrestore(&local->ack_status_lock, flags);
  1940. if (id >= 0) {
  1941. info_id = id;
  1942. info_flags |= IEEE80211_TX_CTL_REQ_TX_STATUS;
  1943. } else {
  1944. kfree_skb(ack_skb);
  1945. }
  1946. }
  1947. }
  1948. /*
  1949. * If the skb is shared we need to obtain our own copy.
  1950. */
  1951. if (skb_shared(skb)) {
  1952. struct sk_buff *tmp_skb = skb;
  1953. /* can't happen -- skb is a clone if info_id != 0 */
  1954. WARN_ON(info_id);
  1955. skb = skb_clone(skb, GFP_ATOMIC);
  1956. kfree_skb(tmp_skb);
  1957. if (!skb) {
  1958. ret = -ENOMEM;
  1959. goto free;
  1960. }
  1961. }
  1962. hdr.frame_control = fc;
  1963. hdr.duration_id = 0;
  1964. hdr.seq_ctrl = 0;
  1965. skip_header_bytes = ETH_HLEN;
  1966. if (ethertype == ETH_P_AARP || ethertype == ETH_P_IPX) {
  1967. encaps_data = bridge_tunnel_header;
  1968. encaps_len = sizeof(bridge_tunnel_header);
  1969. skip_header_bytes -= 2;
  1970. } else if (ethertype >= ETH_P_802_3_MIN) {
  1971. encaps_data = rfc1042_header;
  1972. encaps_len = sizeof(rfc1042_header);
  1973. skip_header_bytes -= 2;
  1974. } else {
  1975. encaps_data = NULL;
  1976. encaps_len = 0;
  1977. }
  1978. nh_pos = skb_network_header(skb) - skb->data;
  1979. h_pos = skb_transport_header(skb) - skb->data;
  1980. skb_pull(skb, skip_header_bytes);
  1981. nh_pos -= skip_header_bytes;
  1982. h_pos -= skip_header_bytes;
  1983. head_need = hdrlen + encaps_len + meshhdrlen - skb_headroom(skb);
  1984. /*
  1985. * So we need to modify the skb header and hence need a copy of
  1986. * that. The head_need variable above doesn't, so far, include
  1987. * the needed header space that we don't need right away. If we
  1988. * can, then we don't reallocate right now but only after the
  1989. * frame arrives at the master device (if it does...)
  1990. *
  1991. * If we cannot, however, then we will reallocate to include all
  1992. * the ever needed space. Also, if we need to reallocate it anyway,
  1993. * make it big enough for everything we may ever need.
  1994. */
  1995. if (head_need > 0 || skb_cloned(skb)) {
  1996. head_need += sdata->encrypt_headroom;
  1997. head_need += local->tx_headroom;
  1998. head_need = max_t(int, 0, head_need);
  1999. if (ieee80211_skb_resize(sdata, skb, head_need, true)) {
  2000. ieee80211_free_txskb(&local->hw, skb);
  2001. skb = NULL;
  2002. return ERR_PTR(-ENOMEM);
  2003. }
  2004. }
  2005. if (encaps_data) {
  2006. memcpy(skb_push(skb, encaps_len), encaps_data, encaps_len);
  2007. nh_pos += encaps_len;
  2008. h_pos += encaps_len;
  2009. }
  2010. #ifdef CONFIG_MAC80211_MESH
  2011. if (meshhdrlen > 0) {
  2012. memcpy(skb_push(skb, meshhdrlen), &mesh_hdr, meshhdrlen);
  2013. nh_pos += meshhdrlen;
  2014. h_pos += meshhdrlen;
  2015. }
  2016. #endif
  2017. if (ieee80211_is_data_qos(fc)) {
  2018. __le16 *qos_control;
  2019. qos_control = (__le16 *) skb_push(skb, 2);
  2020. memcpy(skb_push(skb, hdrlen - 2), &hdr, hdrlen - 2);
  2021. /*
  2022. * Maybe we could actually set some fields here, for now just
  2023. * initialise to zero to indicate no special operation.
  2024. */
  2025. *qos_control = 0;
  2026. } else
  2027. memcpy(skb_push(skb, hdrlen), &hdr, hdrlen);
  2028. nh_pos += hdrlen;
  2029. h_pos += hdrlen;
  2030. /* Update skb pointers to various headers since this modified frame
  2031. * is going to go through Linux networking code that may potentially
  2032. * need things like pointer to IP header. */
  2033. skb_set_mac_header(skb, 0);
  2034. skb_set_network_header(skb, nh_pos);
  2035. skb_set_transport_header(skb, h_pos);
  2036. info = IEEE80211_SKB_CB(skb);
  2037. memset(info, 0, sizeof(*info));
  2038. info->flags = info_flags;
  2039. info->ack_frame_id = info_id;
  2040. info->band = band;
  2041. return skb;
  2042. free:
  2043. kfree_skb(skb);
  2044. return ERR_PTR(ret);
  2045. }
  2046. /*
  2047. * fast-xmit overview
  2048. *
  2049. * The core idea of this fast-xmit is to remove per-packet checks by checking
  2050. * them out of band. ieee80211_check_fast_xmit() implements the out-of-band
  2051. * checks that are needed to get the sta->fast_tx pointer assigned, after which
  2052. * much less work can be done per packet. For example, fragmentation must be
  2053. * disabled or the fast_tx pointer will not be set. All the conditions are seen
  2054. * in the code here.
  2055. *
  2056. * Once assigned, the fast_tx data structure also caches the per-packet 802.11
  2057. * header and other data to aid packet processing in ieee80211_xmit_fast().
  2058. *
  2059. * The most difficult part of this is that when any of these assumptions
  2060. * change, an external trigger (i.e. a call to ieee80211_clear_fast_xmit(),
  2061. * ieee80211_check_fast_xmit() or friends) is required to reset the data,
  2062. * since the per-packet code no longer checks the conditions. This is reflected
  2063. * by the calls to these functions throughout the rest of the code, and must be
  2064. * maintained if any of the TX path checks change.
  2065. */
  2066. void ieee80211_check_fast_xmit(struct sta_info *sta)
  2067. {
  2068. struct ieee80211_fast_tx build = {}, *fast_tx = NULL, *old;
  2069. struct ieee80211_local *local = sta->local;
  2070. struct ieee80211_sub_if_data *sdata = sta->sdata;
  2071. struct ieee80211_hdr *hdr = (void *)build.hdr;
  2072. struct ieee80211_chanctx_conf *chanctx_conf;
  2073. __le16 fc;
  2074. if (!ieee80211_hw_check(&local->hw, SUPPORT_FAST_XMIT))
  2075. return;
  2076. /* Locking here protects both the pointer itself, and against concurrent
  2077. * invocations winning data access races to, e.g., the key pointer that
  2078. * is used.
  2079. * Without it, the invocation of this function right after the key
  2080. * pointer changes wouldn't be sufficient, as another CPU could access
  2081. * the pointer, then stall, and then do the cache update after the CPU
  2082. * that invalidated the key.
  2083. * With the locking, such scenarios cannot happen as the check for the
  2084. * key and the fast-tx assignment are done atomically, so the CPU that
  2085. * modifies the key will either wait or other one will see the key
  2086. * cleared/changed already.
  2087. */
  2088. spin_lock_bh(&sta->lock);
  2089. if (ieee80211_hw_check(&local->hw, SUPPORTS_PS) &&
  2090. !ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS) &&
  2091. sdata->vif.type == NL80211_IFTYPE_STATION)
  2092. goto out;
  2093. if (!test_sta_flag(sta, WLAN_STA_AUTHORIZED))
  2094. goto out;
  2095. if (test_sta_flag(sta, WLAN_STA_PS_STA) ||
  2096. test_sta_flag(sta, WLAN_STA_PS_DRIVER) ||
  2097. test_sta_flag(sta, WLAN_STA_PS_DELIVER) ||
  2098. test_sta_flag(sta, WLAN_STA_CLEAR_PS_FILT))
  2099. goto out;
  2100. if (sdata->noack_map)
  2101. goto out;
  2102. /* fast-xmit doesn't handle fragmentation at all */
  2103. if (local->hw.wiphy->frag_threshold != (u32)-1 &&
  2104. !local->ops->set_frag_threshold)
  2105. goto out;
  2106. rcu_read_lock();
  2107. chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
  2108. if (!chanctx_conf) {
  2109. rcu_read_unlock();
  2110. goto out;
  2111. }
  2112. build.band = chanctx_conf->def.chan->band;
  2113. rcu_read_unlock();
  2114. fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_DATA);
  2115. switch (sdata->vif.type) {
  2116. case NL80211_IFTYPE_ADHOC:
  2117. /* DA SA BSSID */
  2118. build.da_offs = offsetof(struct ieee80211_hdr, addr1);
  2119. build.sa_offs = offsetof(struct ieee80211_hdr, addr2);
  2120. memcpy(hdr->addr3, sdata->u.ibss.bssid, ETH_ALEN);
  2121. build.hdr_len = 24;
  2122. break;
  2123. case NL80211_IFTYPE_STATION:
  2124. if (test_sta_flag(sta, WLAN_STA_TDLS_PEER)) {
  2125. /* DA SA BSSID */
  2126. build.da_offs = offsetof(struct ieee80211_hdr, addr1);
  2127. build.sa_offs = offsetof(struct ieee80211_hdr, addr2);
  2128. memcpy(hdr->addr3, sdata->u.mgd.bssid, ETH_ALEN);
  2129. build.hdr_len = 24;
  2130. break;
  2131. }
  2132. if (sdata->u.mgd.use_4addr) {
  2133. /* non-regular ethertype cannot use the fastpath */
  2134. fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS |
  2135. IEEE80211_FCTL_TODS);
  2136. /* RA TA DA SA */
  2137. memcpy(hdr->addr1, sdata->u.mgd.bssid, ETH_ALEN);
  2138. memcpy(hdr->addr2, sdata->vif.addr, ETH_ALEN);
  2139. build.da_offs = offsetof(struct ieee80211_hdr, addr3);
  2140. build.sa_offs = offsetof(struct ieee80211_hdr, addr4);
  2141. build.hdr_len = 30;
  2142. break;
  2143. }
  2144. fc |= cpu_to_le16(IEEE80211_FCTL_TODS);
  2145. /* BSSID SA DA */
  2146. memcpy(hdr->addr1, sdata->u.mgd.bssid, ETH_ALEN);
  2147. build.da_offs = offsetof(struct ieee80211_hdr, addr3);
  2148. build.sa_offs = offsetof(struct ieee80211_hdr, addr2);
  2149. build.hdr_len = 24;
  2150. break;
  2151. case NL80211_IFTYPE_AP_VLAN:
  2152. if (sdata->wdev.use_4addr) {
  2153. fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS |
  2154. IEEE80211_FCTL_TODS);
  2155. /* RA TA DA SA */
  2156. memcpy(hdr->addr1, sta->sta.addr, ETH_ALEN);
  2157. memcpy(hdr->addr2, sdata->vif.addr, ETH_ALEN);
  2158. build.da_offs = offsetof(struct ieee80211_hdr, addr3);
  2159. build.sa_offs = offsetof(struct ieee80211_hdr, addr4);
  2160. build.hdr_len = 30;
  2161. break;
  2162. }
  2163. /* fall through */
  2164. case NL80211_IFTYPE_AP:
  2165. fc |= cpu_to_le16(IEEE80211_FCTL_FROMDS);
  2166. /* DA BSSID SA */
  2167. build.da_offs = offsetof(struct ieee80211_hdr, addr1);
  2168. memcpy(hdr->addr2, sdata->vif.addr, ETH_ALEN);
  2169. build.sa_offs = offsetof(struct ieee80211_hdr, addr3);
  2170. build.hdr_len = 24;
  2171. break;
  2172. default:
  2173. /* not handled on fast-xmit */
  2174. goto out;
  2175. }
  2176. if (sta->sta.wme) {
  2177. build.hdr_len += 2;
  2178. fc |= cpu_to_le16(IEEE80211_STYPE_QOS_DATA);
  2179. }
  2180. /* We store the key here so there's no point in using rcu_dereference()
  2181. * but that's fine because the code that changes the pointers will call
  2182. * this function after doing so. For a single CPU that would be enough,
  2183. * for multiple see the comment above.
  2184. */
  2185. build.key = rcu_access_pointer(sta->ptk[sta->ptk_idx]);
  2186. if (!build.key)
  2187. build.key = rcu_access_pointer(sdata->default_unicast_key);
  2188. if (build.key) {
  2189. bool gen_iv, iv_spc, mmic;
  2190. gen_iv = build.key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_IV;
  2191. iv_spc = build.key->conf.flags & IEEE80211_KEY_FLAG_PUT_IV_SPACE;
  2192. mmic = build.key->conf.flags & IEEE80211_KEY_FLAG_GENERATE_MMIC;
  2193. /* don't handle software crypto */
  2194. if (!(build.key->flags & KEY_FLAG_UPLOADED_TO_HARDWARE))
  2195. goto out;
  2196. switch (build.key->conf.cipher) {
  2197. case WLAN_CIPHER_SUITE_CCMP:
  2198. case WLAN_CIPHER_SUITE_CCMP_256:
  2199. /* add fixed key ID */
  2200. if (gen_iv) {
  2201. (build.hdr + build.hdr_len)[3] =
  2202. 0x20 | (build.key->conf.keyidx << 6);
  2203. build.pn_offs = build.hdr_len;
  2204. }
  2205. if (gen_iv || iv_spc)
  2206. build.hdr_len += IEEE80211_CCMP_HDR_LEN;
  2207. break;
  2208. case WLAN_CIPHER_SUITE_GCMP:
  2209. case WLAN_CIPHER_SUITE_GCMP_256:
  2210. /* add fixed key ID */
  2211. if (gen_iv) {
  2212. (build.hdr + build.hdr_len)[3] =
  2213. 0x20 | (build.key->conf.keyidx << 6);
  2214. build.pn_offs = build.hdr_len;
  2215. }
  2216. if (gen_iv || iv_spc)
  2217. build.hdr_len += IEEE80211_GCMP_HDR_LEN;
  2218. break;
  2219. case WLAN_CIPHER_SUITE_TKIP:
  2220. /* cannot handle MMIC or IV generation in xmit-fast */
  2221. if (mmic || gen_iv)
  2222. goto out;
  2223. if (iv_spc)
  2224. build.hdr_len += IEEE80211_TKIP_IV_LEN;
  2225. break;
  2226. case WLAN_CIPHER_SUITE_WEP40:
  2227. case WLAN_CIPHER_SUITE_WEP104:
  2228. /* cannot handle IV generation in fast-xmit */
  2229. if (gen_iv)
  2230. goto out;
  2231. if (iv_spc)
  2232. build.hdr_len += IEEE80211_WEP_IV_LEN;
  2233. break;
  2234. case WLAN_CIPHER_SUITE_AES_CMAC:
  2235. case WLAN_CIPHER_SUITE_BIP_CMAC_256:
  2236. case WLAN_CIPHER_SUITE_BIP_GMAC_128:
  2237. case WLAN_CIPHER_SUITE_BIP_GMAC_256:
  2238. WARN(1,
  2239. "management cipher suite 0x%x enabled for data\n",
  2240. build.key->conf.cipher);
  2241. goto out;
  2242. default:
  2243. /* we don't know how to generate IVs for this at all */
  2244. if (WARN_ON(gen_iv))
  2245. goto out;
  2246. /* pure hardware keys are OK, of course */
  2247. if (!(build.key->flags & KEY_FLAG_CIPHER_SCHEME))
  2248. break;
  2249. /* cipher scheme might require space allocation */
  2250. if (iv_spc &&
  2251. build.key->conf.iv_len > IEEE80211_FAST_XMIT_MAX_IV)
  2252. goto out;
  2253. if (iv_spc)
  2254. build.hdr_len += build.key->conf.iv_len;
  2255. }
  2256. fc |= cpu_to_le16(IEEE80211_FCTL_PROTECTED);
  2257. }
  2258. hdr->frame_control = fc;
  2259. memcpy(build.hdr + build.hdr_len,
  2260. rfc1042_header, sizeof(rfc1042_header));
  2261. build.hdr_len += sizeof(rfc1042_header);
  2262. fast_tx = kmemdup(&build, sizeof(build), GFP_ATOMIC);
  2263. /* if the kmemdup fails, continue w/o fast_tx */
  2264. if (!fast_tx)
  2265. goto out;
  2266. out:
  2267. /* we might have raced against another call to this function */
  2268. old = rcu_dereference_protected(sta->fast_tx,
  2269. lockdep_is_held(&sta->lock));
  2270. rcu_assign_pointer(sta->fast_tx, fast_tx);
  2271. if (old)
  2272. kfree_rcu(old, rcu_head);
  2273. spin_unlock_bh(&sta->lock);
  2274. }
  2275. void ieee80211_check_fast_xmit_all(struct ieee80211_local *local)
  2276. {
  2277. struct sta_info *sta;
  2278. rcu_read_lock();
  2279. list_for_each_entry_rcu(sta, &local->sta_list, list)
  2280. ieee80211_check_fast_xmit(sta);
  2281. rcu_read_unlock();
  2282. }
  2283. void ieee80211_check_fast_xmit_iface(struct ieee80211_sub_if_data *sdata)
  2284. {
  2285. struct ieee80211_local *local = sdata->local;
  2286. struct sta_info *sta;
  2287. rcu_read_lock();
  2288. list_for_each_entry_rcu(sta, &local->sta_list, list) {
  2289. if (sdata != sta->sdata &&
  2290. (!sta->sdata->bss || sta->sdata->bss != sdata->bss))
  2291. continue;
  2292. ieee80211_check_fast_xmit(sta);
  2293. }
  2294. rcu_read_unlock();
  2295. }
  2296. void ieee80211_clear_fast_xmit(struct sta_info *sta)
  2297. {
  2298. struct ieee80211_fast_tx *fast_tx;
  2299. spin_lock_bh(&sta->lock);
  2300. fast_tx = rcu_dereference_protected(sta->fast_tx,
  2301. lockdep_is_held(&sta->lock));
  2302. RCU_INIT_POINTER(sta->fast_tx, NULL);
  2303. spin_unlock_bh(&sta->lock);
  2304. if (fast_tx)
  2305. kfree_rcu(fast_tx, rcu_head);
  2306. }
  2307. static bool ieee80211_xmit_fast(struct ieee80211_sub_if_data *sdata,
  2308. struct net_device *dev, struct sta_info *sta,
  2309. struct ieee80211_fast_tx *fast_tx,
  2310. struct sk_buff *skb)
  2311. {
  2312. struct ieee80211_local *local = sdata->local;
  2313. u16 ethertype = (skb->data[12] << 8) | skb->data[13];
  2314. int extra_head = fast_tx->hdr_len - (ETH_HLEN - 2);
  2315. int hw_headroom = sdata->local->hw.extra_tx_headroom;
  2316. struct ethhdr eth;
  2317. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  2318. struct ieee80211_hdr *hdr = (void *)fast_tx->hdr;
  2319. struct ieee80211_tx_data tx;
  2320. ieee80211_tx_result r;
  2321. struct tid_ampdu_tx *tid_tx = NULL;
  2322. u8 tid = IEEE80211_NUM_TIDS;
  2323. /* control port protocol needs a lot of special handling */
  2324. if (cpu_to_be16(ethertype) == sdata->control_port_protocol)
  2325. return false;
  2326. /* only RFC 1042 SNAP */
  2327. if (ethertype < ETH_P_802_3_MIN)
  2328. return false;
  2329. /* don't handle TX status request here either */
  2330. if (skb->sk && skb_shinfo(skb)->tx_flags & SKBTX_WIFI_STATUS)
  2331. return false;
  2332. if (hdr->frame_control & cpu_to_le16(IEEE80211_STYPE_QOS_DATA)) {
  2333. tid = skb->priority & IEEE80211_QOS_CTL_TAG1D_MASK;
  2334. tid_tx = rcu_dereference(sta->ampdu_mlme.tid_tx[tid]);
  2335. if (tid_tx) {
  2336. if (!test_bit(HT_AGG_STATE_OPERATIONAL, &tid_tx->state))
  2337. return false;
  2338. if (tid_tx->timeout)
  2339. tid_tx->last_tx = jiffies;
  2340. }
  2341. }
  2342. /* after this point (skb is modified) we cannot return false */
  2343. if (skb_shared(skb)) {
  2344. struct sk_buff *tmp_skb = skb;
  2345. skb = skb_clone(skb, GFP_ATOMIC);
  2346. kfree_skb(tmp_skb);
  2347. if (!skb)
  2348. return true;
  2349. }
  2350. ieee80211_tx_stats(dev, skb->len + extra_head);
  2351. /* will not be crypto-handled beyond what we do here, so use false
  2352. * as the may-encrypt argument for the resize to not account for
  2353. * more room than we already have in 'extra_head'
  2354. */
  2355. if (unlikely(ieee80211_skb_resize(sdata, skb,
  2356. max_t(int, extra_head + hw_headroom -
  2357. skb_headroom(skb), 0),
  2358. false))) {
  2359. kfree_skb(skb);
  2360. return true;
  2361. }
  2362. memcpy(&eth, skb->data, ETH_HLEN - 2);
  2363. hdr = (void *)skb_push(skb, extra_head);
  2364. memcpy(skb->data, fast_tx->hdr, fast_tx->hdr_len);
  2365. memcpy(skb->data + fast_tx->da_offs, eth.h_dest, ETH_ALEN);
  2366. memcpy(skb->data + fast_tx->sa_offs, eth.h_source, ETH_ALEN);
  2367. memset(info, 0, sizeof(*info));
  2368. info->band = fast_tx->band;
  2369. info->control.vif = &sdata->vif;
  2370. info->flags = IEEE80211_TX_CTL_FIRST_FRAGMENT |
  2371. IEEE80211_TX_CTL_DONTFRAG |
  2372. (tid_tx ? IEEE80211_TX_CTL_AMPDU : 0);
  2373. if (hdr->frame_control & cpu_to_le16(IEEE80211_STYPE_QOS_DATA)) {
  2374. *ieee80211_get_qos_ctl(hdr) = tid;
  2375. if (!sta->sta.txq[0])
  2376. hdr->seq_ctrl = ieee80211_tx_next_seq(sta, tid);
  2377. } else {
  2378. info->flags |= IEEE80211_TX_CTL_ASSIGN_SEQ;
  2379. hdr->seq_ctrl = cpu_to_le16(sdata->sequence_number);
  2380. sdata->sequence_number += 0x10;
  2381. }
  2382. if (skb_shinfo(skb)->gso_size)
  2383. sta->tx_stats.msdu[tid] +=
  2384. DIV_ROUND_UP(skb->len, skb_shinfo(skb)->gso_size);
  2385. else
  2386. sta->tx_stats.msdu[tid]++;
  2387. info->hw_queue = sdata->vif.hw_queue[skb_get_queue_mapping(skb)];
  2388. __skb_queue_head_init(&tx.skbs);
  2389. tx.flags = IEEE80211_TX_UNICAST;
  2390. tx.local = local;
  2391. tx.sdata = sdata;
  2392. tx.sta = sta;
  2393. tx.key = fast_tx->key;
  2394. if (fast_tx->key)
  2395. info->control.hw_key = &fast_tx->key->conf;
  2396. if (!ieee80211_hw_check(&local->hw, HAS_RATE_CONTROL)) {
  2397. tx.skb = skb;
  2398. r = ieee80211_tx_h_rate_ctrl(&tx);
  2399. skb = tx.skb;
  2400. tx.skb = NULL;
  2401. if (r != TX_CONTINUE) {
  2402. if (r != TX_QUEUED)
  2403. kfree_skb(skb);
  2404. return true;
  2405. }
  2406. }
  2407. /* statistics normally done by ieee80211_tx_h_stats (but that
  2408. * has to consider fragmentation, so is more complex)
  2409. */
  2410. sta->tx_stats.bytes[skb_get_queue_mapping(skb)] += skb->len;
  2411. sta->tx_stats.packets[skb_get_queue_mapping(skb)]++;
  2412. if (fast_tx->pn_offs) {
  2413. u64 pn;
  2414. u8 *crypto_hdr = skb->data + fast_tx->pn_offs;
  2415. switch (fast_tx->key->conf.cipher) {
  2416. case WLAN_CIPHER_SUITE_CCMP:
  2417. case WLAN_CIPHER_SUITE_CCMP_256:
  2418. case WLAN_CIPHER_SUITE_GCMP:
  2419. case WLAN_CIPHER_SUITE_GCMP_256:
  2420. pn = atomic64_inc_return(&fast_tx->key->conf.tx_pn);
  2421. crypto_hdr[0] = pn;
  2422. crypto_hdr[1] = pn >> 8;
  2423. crypto_hdr[4] = pn >> 16;
  2424. crypto_hdr[5] = pn >> 24;
  2425. crypto_hdr[6] = pn >> 32;
  2426. crypto_hdr[7] = pn >> 40;
  2427. break;
  2428. }
  2429. }
  2430. if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
  2431. sdata = container_of(sdata->bss,
  2432. struct ieee80211_sub_if_data, u.ap);
  2433. __skb_queue_tail(&tx.skbs, skb);
  2434. ieee80211_tx_frags(local, &sdata->vif, &sta->sta, &tx.skbs, false);
  2435. return true;
  2436. }
  2437. void __ieee80211_subif_start_xmit(struct sk_buff *skb,
  2438. struct net_device *dev,
  2439. u32 info_flags)
  2440. {
  2441. struct ieee80211_sub_if_data *sdata = IEEE80211_DEV_TO_SUB_IF(dev);
  2442. struct sta_info *sta;
  2443. struct sk_buff *next;
  2444. if (unlikely(skb->len < ETH_HLEN)) {
  2445. kfree_skb(skb);
  2446. return;
  2447. }
  2448. rcu_read_lock();
  2449. if (ieee80211_lookup_ra_sta(sdata, skb, &sta))
  2450. goto out_free;
  2451. if (!IS_ERR_OR_NULL(sta)) {
  2452. struct ieee80211_fast_tx *fast_tx;
  2453. fast_tx = rcu_dereference(sta->fast_tx);
  2454. if (fast_tx &&
  2455. ieee80211_xmit_fast(sdata, dev, sta, fast_tx, skb))
  2456. goto out;
  2457. }
  2458. if (skb_is_gso(skb)) {
  2459. struct sk_buff *segs;
  2460. segs = skb_gso_segment(skb, 0);
  2461. if (IS_ERR(segs)) {
  2462. goto out_free;
  2463. } else if (segs) {
  2464. consume_skb(skb);
  2465. skb = segs;
  2466. }
  2467. } else {
  2468. /* we cannot process non-linear frames on this path */
  2469. if (skb_linearize(skb)) {
  2470. kfree_skb(skb);
  2471. goto out;
  2472. }
  2473. /* the frame could be fragmented, software-encrypted, and other
  2474. * things so we cannot really handle checksum offload with it -
  2475. * fix it up in software before we handle anything else.
  2476. */
  2477. if (skb->ip_summed == CHECKSUM_PARTIAL) {
  2478. skb_set_transport_header(skb,
  2479. skb_checksum_start_offset(skb));
  2480. if (skb_checksum_help(skb))
  2481. goto out_free;
  2482. }
  2483. }
  2484. next = skb;
  2485. while (next) {
  2486. skb = next;
  2487. next = skb->next;
  2488. skb->prev = NULL;
  2489. skb->next = NULL;
  2490. skb = ieee80211_build_hdr(sdata, skb, info_flags, sta);
  2491. if (IS_ERR(skb))
  2492. goto out;
  2493. ieee80211_tx_stats(dev, skb->len);
  2494. ieee80211_xmit(sdata, sta, skb);
  2495. }
  2496. goto out;
  2497. out_free:
  2498. kfree_skb(skb);
  2499. out:
  2500. rcu_read_unlock();
  2501. }
  2502. /**
  2503. * ieee80211_subif_start_xmit - netif start_xmit function for 802.3 vifs
  2504. * @skb: packet to be sent
  2505. * @dev: incoming interface
  2506. *
  2507. * On failure skb will be freed.
  2508. */
  2509. netdev_tx_t ieee80211_subif_start_xmit(struct sk_buff *skb,
  2510. struct net_device *dev)
  2511. {
  2512. __ieee80211_subif_start_xmit(skb, dev, 0);
  2513. return NETDEV_TX_OK;
  2514. }
  2515. struct sk_buff *
  2516. ieee80211_build_data_template(struct ieee80211_sub_if_data *sdata,
  2517. struct sk_buff *skb, u32 info_flags)
  2518. {
  2519. struct ieee80211_hdr *hdr;
  2520. struct ieee80211_tx_data tx = {
  2521. .local = sdata->local,
  2522. .sdata = sdata,
  2523. };
  2524. struct sta_info *sta;
  2525. rcu_read_lock();
  2526. if (ieee80211_lookup_ra_sta(sdata, skb, &sta)) {
  2527. kfree_skb(skb);
  2528. skb = ERR_PTR(-EINVAL);
  2529. goto out;
  2530. }
  2531. skb = ieee80211_build_hdr(sdata, skb, info_flags, sta);
  2532. if (IS_ERR(skb))
  2533. goto out;
  2534. hdr = (void *)skb->data;
  2535. tx.sta = sta_info_get(sdata, hdr->addr1);
  2536. tx.skb = skb;
  2537. if (ieee80211_tx_h_select_key(&tx) != TX_CONTINUE) {
  2538. rcu_read_unlock();
  2539. kfree_skb(skb);
  2540. return ERR_PTR(-EINVAL);
  2541. }
  2542. out:
  2543. rcu_read_unlock();
  2544. return skb;
  2545. }
  2546. /*
  2547. * ieee80211_clear_tx_pending may not be called in a context where
  2548. * it is possible that it packets could come in again.
  2549. */
  2550. void ieee80211_clear_tx_pending(struct ieee80211_local *local)
  2551. {
  2552. struct sk_buff *skb;
  2553. int i;
  2554. for (i = 0; i < local->hw.queues; i++) {
  2555. while ((skb = skb_dequeue(&local->pending[i])) != NULL)
  2556. ieee80211_free_txskb(&local->hw, skb);
  2557. }
  2558. }
  2559. /*
  2560. * Returns false if the frame couldn't be transmitted but was queued instead,
  2561. * which in this case means re-queued -- take as an indication to stop sending
  2562. * more pending frames.
  2563. */
  2564. static bool ieee80211_tx_pending_skb(struct ieee80211_local *local,
  2565. struct sk_buff *skb)
  2566. {
  2567. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  2568. struct ieee80211_sub_if_data *sdata;
  2569. struct sta_info *sta;
  2570. struct ieee80211_hdr *hdr;
  2571. bool result;
  2572. struct ieee80211_chanctx_conf *chanctx_conf;
  2573. sdata = vif_to_sdata(info->control.vif);
  2574. if (info->flags & IEEE80211_TX_INTFL_NEED_TXPROCESSING) {
  2575. chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
  2576. if (unlikely(!chanctx_conf)) {
  2577. dev_kfree_skb(skb);
  2578. return true;
  2579. }
  2580. info->band = chanctx_conf->def.chan->band;
  2581. result = ieee80211_tx(sdata, NULL, skb, true);
  2582. } else {
  2583. struct sk_buff_head skbs;
  2584. __skb_queue_head_init(&skbs);
  2585. __skb_queue_tail(&skbs, skb);
  2586. hdr = (struct ieee80211_hdr *)skb->data;
  2587. sta = sta_info_get(sdata, hdr->addr1);
  2588. result = __ieee80211_tx(local, &skbs, skb->len, sta, true);
  2589. }
  2590. return result;
  2591. }
  2592. /*
  2593. * Transmit all pending packets. Called from tasklet.
  2594. */
  2595. void ieee80211_tx_pending(unsigned long data)
  2596. {
  2597. struct ieee80211_local *local = (struct ieee80211_local *)data;
  2598. unsigned long flags;
  2599. int i;
  2600. bool txok;
  2601. rcu_read_lock();
  2602. spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
  2603. for (i = 0; i < local->hw.queues; i++) {
  2604. /*
  2605. * If queue is stopped by something other than due to pending
  2606. * frames, or we have no pending frames, proceed to next queue.
  2607. */
  2608. if (local->queue_stop_reasons[i] ||
  2609. skb_queue_empty(&local->pending[i]))
  2610. continue;
  2611. while (!skb_queue_empty(&local->pending[i])) {
  2612. struct sk_buff *skb = __skb_dequeue(&local->pending[i]);
  2613. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
  2614. if (WARN_ON(!info->control.vif)) {
  2615. ieee80211_free_txskb(&local->hw, skb);
  2616. continue;
  2617. }
  2618. spin_unlock_irqrestore(&local->queue_stop_reason_lock,
  2619. flags);
  2620. txok = ieee80211_tx_pending_skb(local, skb);
  2621. spin_lock_irqsave(&local->queue_stop_reason_lock,
  2622. flags);
  2623. if (!txok)
  2624. break;
  2625. }
  2626. if (skb_queue_empty(&local->pending[i]))
  2627. ieee80211_propagate_queue_wake(local, i);
  2628. }
  2629. spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
  2630. rcu_read_unlock();
  2631. }
  2632. /* functions for drivers to get certain frames */
  2633. static void __ieee80211_beacon_add_tim(struct ieee80211_sub_if_data *sdata,
  2634. struct ps_data *ps, struct sk_buff *skb,
  2635. bool is_template)
  2636. {
  2637. u8 *pos, *tim;
  2638. int aid0 = 0;
  2639. int i, have_bits = 0, n1, n2;
  2640. /* Generate bitmap for TIM only if there are any STAs in power save
  2641. * mode. */
  2642. if (atomic_read(&ps->num_sta_ps) > 0)
  2643. /* in the hope that this is faster than
  2644. * checking byte-for-byte */
  2645. have_bits = !bitmap_empty((unsigned long *)ps->tim,
  2646. IEEE80211_MAX_AID+1);
  2647. if (!is_template) {
  2648. if (ps->dtim_count == 0)
  2649. ps->dtim_count = sdata->vif.bss_conf.dtim_period - 1;
  2650. else
  2651. ps->dtim_count--;
  2652. }
  2653. tim = pos = (u8 *) skb_put(skb, 6);
  2654. *pos++ = WLAN_EID_TIM;
  2655. *pos++ = 4;
  2656. *pos++ = ps->dtim_count;
  2657. *pos++ = sdata->vif.bss_conf.dtim_period;
  2658. if (ps->dtim_count == 0 && !skb_queue_empty(&ps->bc_buf))
  2659. aid0 = 1;
  2660. ps->dtim_bc_mc = aid0 == 1;
  2661. if (have_bits) {
  2662. /* Find largest even number N1 so that bits numbered 1 through
  2663. * (N1 x 8) - 1 in the bitmap are 0 and number N2 so that bits
  2664. * (N2 + 1) x 8 through 2007 are 0. */
  2665. n1 = 0;
  2666. for (i = 0; i < IEEE80211_MAX_TIM_LEN; i++) {
  2667. if (ps->tim[i]) {
  2668. n1 = i & 0xfe;
  2669. break;
  2670. }
  2671. }
  2672. n2 = n1;
  2673. for (i = IEEE80211_MAX_TIM_LEN - 1; i >= n1; i--) {
  2674. if (ps->tim[i]) {
  2675. n2 = i;
  2676. break;
  2677. }
  2678. }
  2679. /* Bitmap control */
  2680. *pos++ = n1 | aid0;
  2681. /* Part Virt Bitmap */
  2682. skb_put(skb, n2 - n1);
  2683. memcpy(pos, ps->tim + n1, n2 - n1 + 1);
  2684. tim[1] = n2 - n1 + 4;
  2685. } else {
  2686. *pos++ = aid0; /* Bitmap control */
  2687. *pos++ = 0; /* Part Virt Bitmap */
  2688. }
  2689. }
  2690. static int ieee80211_beacon_add_tim(struct ieee80211_sub_if_data *sdata,
  2691. struct ps_data *ps, struct sk_buff *skb,
  2692. bool is_template)
  2693. {
  2694. struct ieee80211_local *local = sdata->local;
  2695. /*
  2696. * Not very nice, but we want to allow the driver to call
  2697. * ieee80211_beacon_get() as a response to the set_tim()
  2698. * callback. That, however, is already invoked under the
  2699. * sta_lock to guarantee consistent and race-free update
  2700. * of the tim bitmap in mac80211 and the driver.
  2701. */
  2702. if (local->tim_in_locked_section) {
  2703. __ieee80211_beacon_add_tim(sdata, ps, skb, is_template);
  2704. } else {
  2705. spin_lock_bh(&local->tim_lock);
  2706. __ieee80211_beacon_add_tim(sdata, ps, skb, is_template);
  2707. spin_unlock_bh(&local->tim_lock);
  2708. }
  2709. return 0;
  2710. }
  2711. static void ieee80211_set_csa(struct ieee80211_sub_if_data *sdata,
  2712. struct beacon_data *beacon)
  2713. {
  2714. struct probe_resp *resp;
  2715. u8 *beacon_data;
  2716. size_t beacon_data_len;
  2717. int i;
  2718. u8 count = beacon->csa_current_counter;
  2719. switch (sdata->vif.type) {
  2720. case NL80211_IFTYPE_AP:
  2721. beacon_data = beacon->tail;
  2722. beacon_data_len = beacon->tail_len;
  2723. break;
  2724. case NL80211_IFTYPE_ADHOC:
  2725. beacon_data = beacon->head;
  2726. beacon_data_len = beacon->head_len;
  2727. break;
  2728. case NL80211_IFTYPE_MESH_POINT:
  2729. beacon_data = beacon->head;
  2730. beacon_data_len = beacon->head_len;
  2731. break;
  2732. default:
  2733. return;
  2734. }
  2735. rcu_read_lock();
  2736. for (i = 0; i < IEEE80211_MAX_CSA_COUNTERS_NUM; ++i) {
  2737. resp = rcu_dereference(sdata->u.ap.probe_resp);
  2738. if (beacon->csa_counter_offsets[i]) {
  2739. if (WARN_ON_ONCE(beacon->csa_counter_offsets[i] >=
  2740. beacon_data_len)) {
  2741. rcu_read_unlock();
  2742. return;
  2743. }
  2744. beacon_data[beacon->csa_counter_offsets[i]] = count;
  2745. }
  2746. if (sdata->vif.type == NL80211_IFTYPE_AP && resp)
  2747. resp->data[resp->csa_counter_offsets[i]] = count;
  2748. }
  2749. rcu_read_unlock();
  2750. }
  2751. static u8 __ieee80211_csa_update_counter(struct beacon_data *beacon)
  2752. {
  2753. beacon->csa_current_counter--;
  2754. /* the counter should never reach 0 */
  2755. WARN_ON_ONCE(!beacon->csa_current_counter);
  2756. return beacon->csa_current_counter;
  2757. }
  2758. u8 ieee80211_csa_update_counter(struct ieee80211_vif *vif)
  2759. {
  2760. struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
  2761. struct beacon_data *beacon = NULL;
  2762. u8 count = 0;
  2763. rcu_read_lock();
  2764. if (sdata->vif.type == NL80211_IFTYPE_AP)
  2765. beacon = rcu_dereference(sdata->u.ap.beacon);
  2766. else if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
  2767. beacon = rcu_dereference(sdata->u.ibss.presp);
  2768. else if (ieee80211_vif_is_mesh(&sdata->vif))
  2769. beacon = rcu_dereference(sdata->u.mesh.beacon);
  2770. if (!beacon)
  2771. goto unlock;
  2772. count = __ieee80211_csa_update_counter(beacon);
  2773. unlock:
  2774. rcu_read_unlock();
  2775. return count;
  2776. }
  2777. EXPORT_SYMBOL(ieee80211_csa_update_counter);
  2778. bool ieee80211_csa_is_complete(struct ieee80211_vif *vif)
  2779. {
  2780. struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
  2781. struct beacon_data *beacon = NULL;
  2782. u8 *beacon_data;
  2783. size_t beacon_data_len;
  2784. int ret = false;
  2785. if (!ieee80211_sdata_running(sdata))
  2786. return false;
  2787. rcu_read_lock();
  2788. if (vif->type == NL80211_IFTYPE_AP) {
  2789. struct ieee80211_if_ap *ap = &sdata->u.ap;
  2790. beacon = rcu_dereference(ap->beacon);
  2791. if (WARN_ON(!beacon || !beacon->tail))
  2792. goto out;
  2793. beacon_data = beacon->tail;
  2794. beacon_data_len = beacon->tail_len;
  2795. } else if (vif->type == NL80211_IFTYPE_ADHOC) {
  2796. struct ieee80211_if_ibss *ifibss = &sdata->u.ibss;
  2797. beacon = rcu_dereference(ifibss->presp);
  2798. if (!beacon)
  2799. goto out;
  2800. beacon_data = beacon->head;
  2801. beacon_data_len = beacon->head_len;
  2802. } else if (vif->type == NL80211_IFTYPE_MESH_POINT) {
  2803. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  2804. beacon = rcu_dereference(ifmsh->beacon);
  2805. if (!beacon)
  2806. goto out;
  2807. beacon_data = beacon->head;
  2808. beacon_data_len = beacon->head_len;
  2809. } else {
  2810. WARN_ON(1);
  2811. goto out;
  2812. }
  2813. if (!beacon->csa_counter_offsets[0])
  2814. goto out;
  2815. if (WARN_ON_ONCE(beacon->csa_counter_offsets[0] > beacon_data_len))
  2816. goto out;
  2817. if (beacon_data[beacon->csa_counter_offsets[0]] == 1)
  2818. ret = true;
  2819. out:
  2820. rcu_read_unlock();
  2821. return ret;
  2822. }
  2823. EXPORT_SYMBOL(ieee80211_csa_is_complete);
  2824. static struct sk_buff *
  2825. __ieee80211_beacon_get(struct ieee80211_hw *hw,
  2826. struct ieee80211_vif *vif,
  2827. struct ieee80211_mutable_offsets *offs,
  2828. bool is_template)
  2829. {
  2830. struct ieee80211_local *local = hw_to_local(hw);
  2831. struct beacon_data *beacon = NULL;
  2832. struct sk_buff *skb = NULL;
  2833. struct ieee80211_tx_info *info;
  2834. struct ieee80211_sub_if_data *sdata = NULL;
  2835. enum ieee80211_band band;
  2836. struct ieee80211_tx_rate_control txrc;
  2837. struct ieee80211_chanctx_conf *chanctx_conf;
  2838. int csa_off_base = 0;
  2839. rcu_read_lock();
  2840. sdata = vif_to_sdata(vif);
  2841. chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
  2842. if (!ieee80211_sdata_running(sdata) || !chanctx_conf)
  2843. goto out;
  2844. if (offs)
  2845. memset(offs, 0, sizeof(*offs));
  2846. if (sdata->vif.type == NL80211_IFTYPE_AP) {
  2847. struct ieee80211_if_ap *ap = &sdata->u.ap;
  2848. beacon = rcu_dereference(ap->beacon);
  2849. if (beacon) {
  2850. if (beacon->csa_counter_offsets[0]) {
  2851. if (!is_template)
  2852. __ieee80211_csa_update_counter(beacon);
  2853. ieee80211_set_csa(sdata, beacon);
  2854. }
  2855. /*
  2856. * headroom, head length,
  2857. * tail length and maximum TIM length
  2858. */
  2859. skb = dev_alloc_skb(local->tx_headroom +
  2860. beacon->head_len +
  2861. beacon->tail_len + 256 +
  2862. local->hw.extra_beacon_tailroom);
  2863. if (!skb)
  2864. goto out;
  2865. skb_reserve(skb, local->tx_headroom);
  2866. memcpy(skb_put(skb, beacon->head_len), beacon->head,
  2867. beacon->head_len);
  2868. ieee80211_beacon_add_tim(sdata, &ap->ps, skb,
  2869. is_template);
  2870. if (offs) {
  2871. offs->tim_offset = beacon->head_len;
  2872. offs->tim_length = skb->len - beacon->head_len;
  2873. /* for AP the csa offsets are from tail */
  2874. csa_off_base = skb->len;
  2875. }
  2876. if (beacon->tail)
  2877. memcpy(skb_put(skb, beacon->tail_len),
  2878. beacon->tail, beacon->tail_len);
  2879. } else
  2880. goto out;
  2881. } else if (sdata->vif.type == NL80211_IFTYPE_ADHOC) {
  2882. struct ieee80211_if_ibss *ifibss = &sdata->u.ibss;
  2883. struct ieee80211_hdr *hdr;
  2884. beacon = rcu_dereference(ifibss->presp);
  2885. if (!beacon)
  2886. goto out;
  2887. if (beacon->csa_counter_offsets[0]) {
  2888. if (!is_template)
  2889. __ieee80211_csa_update_counter(beacon);
  2890. ieee80211_set_csa(sdata, beacon);
  2891. }
  2892. skb = dev_alloc_skb(local->tx_headroom + beacon->head_len +
  2893. local->hw.extra_beacon_tailroom);
  2894. if (!skb)
  2895. goto out;
  2896. skb_reserve(skb, local->tx_headroom);
  2897. memcpy(skb_put(skb, beacon->head_len), beacon->head,
  2898. beacon->head_len);
  2899. hdr = (struct ieee80211_hdr *) skb->data;
  2900. hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
  2901. IEEE80211_STYPE_BEACON);
  2902. } else if (ieee80211_vif_is_mesh(&sdata->vif)) {
  2903. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  2904. beacon = rcu_dereference(ifmsh->beacon);
  2905. if (!beacon)
  2906. goto out;
  2907. if (beacon->csa_counter_offsets[0]) {
  2908. if (!is_template)
  2909. /* TODO: For mesh csa_counter is in TU, so
  2910. * decrementing it by one isn't correct, but
  2911. * for now we leave it consistent with overall
  2912. * mac80211's behavior.
  2913. */
  2914. __ieee80211_csa_update_counter(beacon);
  2915. ieee80211_set_csa(sdata, beacon);
  2916. }
  2917. if (ifmsh->sync_ops)
  2918. ifmsh->sync_ops->adjust_tbtt(sdata, beacon);
  2919. skb = dev_alloc_skb(local->tx_headroom +
  2920. beacon->head_len +
  2921. 256 + /* TIM IE */
  2922. beacon->tail_len +
  2923. local->hw.extra_beacon_tailroom);
  2924. if (!skb)
  2925. goto out;
  2926. skb_reserve(skb, local->tx_headroom);
  2927. memcpy(skb_put(skb, beacon->head_len), beacon->head,
  2928. beacon->head_len);
  2929. ieee80211_beacon_add_tim(sdata, &ifmsh->ps, skb, is_template);
  2930. if (offs) {
  2931. offs->tim_offset = beacon->head_len;
  2932. offs->tim_length = skb->len - beacon->head_len;
  2933. }
  2934. memcpy(skb_put(skb, beacon->tail_len), beacon->tail,
  2935. beacon->tail_len);
  2936. } else {
  2937. WARN_ON(1);
  2938. goto out;
  2939. }
  2940. /* CSA offsets */
  2941. if (offs && beacon) {
  2942. int i;
  2943. for (i = 0; i < IEEE80211_MAX_CSA_COUNTERS_NUM; i++) {
  2944. u16 csa_off = beacon->csa_counter_offsets[i];
  2945. if (!csa_off)
  2946. continue;
  2947. offs->csa_counter_offs[i] = csa_off_base + csa_off;
  2948. }
  2949. }
  2950. band = chanctx_conf->def.chan->band;
  2951. info = IEEE80211_SKB_CB(skb);
  2952. info->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
  2953. info->flags |= IEEE80211_TX_CTL_NO_ACK;
  2954. info->band = band;
  2955. memset(&txrc, 0, sizeof(txrc));
  2956. txrc.hw = hw;
  2957. txrc.sband = local->hw.wiphy->bands[band];
  2958. txrc.bss_conf = &sdata->vif.bss_conf;
  2959. txrc.skb = skb;
  2960. txrc.reported_rate.idx = -1;
  2961. txrc.rate_idx_mask = sdata->rc_rateidx_mask[band];
  2962. if (txrc.rate_idx_mask == (1 << txrc.sband->n_bitrates) - 1)
  2963. txrc.max_rate_idx = -1;
  2964. else
  2965. txrc.max_rate_idx = fls(txrc.rate_idx_mask) - 1;
  2966. txrc.bss = true;
  2967. rate_control_get_rate(sdata, NULL, &txrc);
  2968. info->control.vif = vif;
  2969. info->flags |= IEEE80211_TX_CTL_CLEAR_PS_FILT |
  2970. IEEE80211_TX_CTL_ASSIGN_SEQ |
  2971. IEEE80211_TX_CTL_FIRST_FRAGMENT;
  2972. out:
  2973. rcu_read_unlock();
  2974. return skb;
  2975. }
  2976. struct sk_buff *
  2977. ieee80211_beacon_get_template(struct ieee80211_hw *hw,
  2978. struct ieee80211_vif *vif,
  2979. struct ieee80211_mutable_offsets *offs)
  2980. {
  2981. return __ieee80211_beacon_get(hw, vif, offs, true);
  2982. }
  2983. EXPORT_SYMBOL(ieee80211_beacon_get_template);
  2984. struct sk_buff *ieee80211_beacon_get_tim(struct ieee80211_hw *hw,
  2985. struct ieee80211_vif *vif,
  2986. u16 *tim_offset, u16 *tim_length)
  2987. {
  2988. struct ieee80211_mutable_offsets offs = {};
  2989. struct sk_buff *bcn = __ieee80211_beacon_get(hw, vif, &offs, false);
  2990. struct sk_buff *copy;
  2991. struct ieee80211_supported_band *sband;
  2992. int shift;
  2993. if (!bcn)
  2994. return bcn;
  2995. if (tim_offset)
  2996. *tim_offset = offs.tim_offset;
  2997. if (tim_length)
  2998. *tim_length = offs.tim_length;
  2999. if (ieee80211_hw_check(hw, BEACON_TX_STATUS) ||
  3000. !hw_to_local(hw)->monitors)
  3001. return bcn;
  3002. /* send a copy to monitor interfaces */
  3003. copy = skb_copy(bcn, GFP_ATOMIC);
  3004. if (!copy)
  3005. return bcn;
  3006. shift = ieee80211_vif_get_shift(vif);
  3007. sband = hw->wiphy->bands[ieee80211_get_sdata_band(vif_to_sdata(vif))];
  3008. ieee80211_tx_monitor(hw_to_local(hw), copy, sband, 1, shift, false);
  3009. return bcn;
  3010. }
  3011. EXPORT_SYMBOL(ieee80211_beacon_get_tim);
  3012. struct sk_buff *ieee80211_proberesp_get(struct ieee80211_hw *hw,
  3013. struct ieee80211_vif *vif)
  3014. {
  3015. struct ieee80211_if_ap *ap = NULL;
  3016. struct sk_buff *skb = NULL;
  3017. struct probe_resp *presp = NULL;
  3018. struct ieee80211_hdr *hdr;
  3019. struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
  3020. if (sdata->vif.type != NL80211_IFTYPE_AP)
  3021. return NULL;
  3022. rcu_read_lock();
  3023. ap = &sdata->u.ap;
  3024. presp = rcu_dereference(ap->probe_resp);
  3025. if (!presp)
  3026. goto out;
  3027. skb = dev_alloc_skb(presp->len);
  3028. if (!skb)
  3029. goto out;
  3030. memcpy(skb_put(skb, presp->len), presp->data, presp->len);
  3031. hdr = (struct ieee80211_hdr *) skb->data;
  3032. memset(hdr->addr1, 0, sizeof(hdr->addr1));
  3033. out:
  3034. rcu_read_unlock();
  3035. return skb;
  3036. }
  3037. EXPORT_SYMBOL(ieee80211_proberesp_get);
  3038. struct sk_buff *ieee80211_pspoll_get(struct ieee80211_hw *hw,
  3039. struct ieee80211_vif *vif)
  3040. {
  3041. struct ieee80211_sub_if_data *sdata;
  3042. struct ieee80211_if_managed *ifmgd;
  3043. struct ieee80211_pspoll *pspoll;
  3044. struct ieee80211_local *local;
  3045. struct sk_buff *skb;
  3046. if (WARN_ON(vif->type != NL80211_IFTYPE_STATION))
  3047. return NULL;
  3048. sdata = vif_to_sdata(vif);
  3049. ifmgd = &sdata->u.mgd;
  3050. local = sdata->local;
  3051. skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*pspoll));
  3052. if (!skb)
  3053. return NULL;
  3054. skb_reserve(skb, local->hw.extra_tx_headroom);
  3055. pspoll = (struct ieee80211_pspoll *) skb_put(skb, sizeof(*pspoll));
  3056. memset(pspoll, 0, sizeof(*pspoll));
  3057. pspoll->frame_control = cpu_to_le16(IEEE80211_FTYPE_CTL |
  3058. IEEE80211_STYPE_PSPOLL);
  3059. pspoll->aid = cpu_to_le16(ifmgd->aid);
  3060. /* aid in PS-Poll has its two MSBs each set to 1 */
  3061. pspoll->aid |= cpu_to_le16(1 << 15 | 1 << 14);
  3062. memcpy(pspoll->bssid, ifmgd->bssid, ETH_ALEN);
  3063. memcpy(pspoll->ta, vif->addr, ETH_ALEN);
  3064. return skb;
  3065. }
  3066. EXPORT_SYMBOL(ieee80211_pspoll_get);
  3067. struct sk_buff *ieee80211_nullfunc_get(struct ieee80211_hw *hw,
  3068. struct ieee80211_vif *vif)
  3069. {
  3070. struct ieee80211_hdr_3addr *nullfunc;
  3071. struct ieee80211_sub_if_data *sdata;
  3072. struct ieee80211_if_managed *ifmgd;
  3073. struct ieee80211_local *local;
  3074. struct sk_buff *skb;
  3075. if (WARN_ON(vif->type != NL80211_IFTYPE_STATION))
  3076. return NULL;
  3077. sdata = vif_to_sdata(vif);
  3078. ifmgd = &sdata->u.mgd;
  3079. local = sdata->local;
  3080. skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*nullfunc));
  3081. if (!skb)
  3082. return NULL;
  3083. skb_reserve(skb, local->hw.extra_tx_headroom);
  3084. nullfunc = (struct ieee80211_hdr_3addr *) skb_put(skb,
  3085. sizeof(*nullfunc));
  3086. memset(nullfunc, 0, sizeof(*nullfunc));
  3087. nullfunc->frame_control = cpu_to_le16(IEEE80211_FTYPE_DATA |
  3088. IEEE80211_STYPE_NULLFUNC |
  3089. IEEE80211_FCTL_TODS);
  3090. memcpy(nullfunc->addr1, ifmgd->bssid, ETH_ALEN);
  3091. memcpy(nullfunc->addr2, vif->addr, ETH_ALEN);
  3092. memcpy(nullfunc->addr3, ifmgd->bssid, ETH_ALEN);
  3093. return skb;
  3094. }
  3095. EXPORT_SYMBOL(ieee80211_nullfunc_get);
  3096. struct sk_buff *ieee80211_probereq_get(struct ieee80211_hw *hw,
  3097. const u8 *src_addr,
  3098. const u8 *ssid, size_t ssid_len,
  3099. size_t tailroom)
  3100. {
  3101. struct ieee80211_local *local = hw_to_local(hw);
  3102. struct ieee80211_hdr_3addr *hdr;
  3103. struct sk_buff *skb;
  3104. size_t ie_ssid_len;
  3105. u8 *pos;
  3106. ie_ssid_len = 2 + ssid_len;
  3107. skb = dev_alloc_skb(local->hw.extra_tx_headroom + sizeof(*hdr) +
  3108. ie_ssid_len + tailroom);
  3109. if (!skb)
  3110. return NULL;
  3111. skb_reserve(skb, local->hw.extra_tx_headroom);
  3112. hdr = (struct ieee80211_hdr_3addr *) skb_put(skb, sizeof(*hdr));
  3113. memset(hdr, 0, sizeof(*hdr));
  3114. hdr->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
  3115. IEEE80211_STYPE_PROBE_REQ);
  3116. eth_broadcast_addr(hdr->addr1);
  3117. memcpy(hdr->addr2, src_addr, ETH_ALEN);
  3118. eth_broadcast_addr(hdr->addr3);
  3119. pos = skb_put(skb, ie_ssid_len);
  3120. *pos++ = WLAN_EID_SSID;
  3121. *pos++ = ssid_len;
  3122. if (ssid_len)
  3123. memcpy(pos, ssid, ssid_len);
  3124. pos += ssid_len;
  3125. return skb;
  3126. }
  3127. EXPORT_SYMBOL(ieee80211_probereq_get);
  3128. void ieee80211_rts_get(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
  3129. const void *frame, size_t frame_len,
  3130. const struct ieee80211_tx_info *frame_txctl,
  3131. struct ieee80211_rts *rts)
  3132. {
  3133. const struct ieee80211_hdr *hdr = frame;
  3134. rts->frame_control =
  3135. cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_RTS);
  3136. rts->duration = ieee80211_rts_duration(hw, vif, frame_len,
  3137. frame_txctl);
  3138. memcpy(rts->ra, hdr->addr1, sizeof(rts->ra));
  3139. memcpy(rts->ta, hdr->addr2, sizeof(rts->ta));
  3140. }
  3141. EXPORT_SYMBOL(ieee80211_rts_get);
  3142. void ieee80211_ctstoself_get(struct ieee80211_hw *hw, struct ieee80211_vif *vif,
  3143. const void *frame, size_t frame_len,
  3144. const struct ieee80211_tx_info *frame_txctl,
  3145. struct ieee80211_cts *cts)
  3146. {
  3147. const struct ieee80211_hdr *hdr = frame;
  3148. cts->frame_control =
  3149. cpu_to_le16(IEEE80211_FTYPE_CTL | IEEE80211_STYPE_CTS);
  3150. cts->duration = ieee80211_ctstoself_duration(hw, vif,
  3151. frame_len, frame_txctl);
  3152. memcpy(cts->ra, hdr->addr1, sizeof(cts->ra));
  3153. }
  3154. EXPORT_SYMBOL(ieee80211_ctstoself_get);
  3155. struct sk_buff *
  3156. ieee80211_get_buffered_bc(struct ieee80211_hw *hw,
  3157. struct ieee80211_vif *vif)
  3158. {
  3159. struct ieee80211_local *local = hw_to_local(hw);
  3160. struct sk_buff *skb = NULL;
  3161. struct ieee80211_tx_data tx;
  3162. struct ieee80211_sub_if_data *sdata;
  3163. struct ps_data *ps;
  3164. struct ieee80211_tx_info *info;
  3165. struct ieee80211_chanctx_conf *chanctx_conf;
  3166. sdata = vif_to_sdata(vif);
  3167. rcu_read_lock();
  3168. chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
  3169. if (!chanctx_conf)
  3170. goto out;
  3171. if (sdata->vif.type == NL80211_IFTYPE_AP) {
  3172. struct beacon_data *beacon =
  3173. rcu_dereference(sdata->u.ap.beacon);
  3174. if (!beacon || !beacon->head)
  3175. goto out;
  3176. ps = &sdata->u.ap.ps;
  3177. } else if (ieee80211_vif_is_mesh(&sdata->vif)) {
  3178. ps = &sdata->u.mesh.ps;
  3179. } else {
  3180. goto out;
  3181. }
  3182. if (ps->dtim_count != 0 || !ps->dtim_bc_mc)
  3183. goto out; /* send buffered bc/mc only after DTIM beacon */
  3184. while (1) {
  3185. skb = skb_dequeue(&ps->bc_buf);
  3186. if (!skb)
  3187. goto out;
  3188. local->total_ps_buffered--;
  3189. if (!skb_queue_empty(&ps->bc_buf) && skb->len >= 2) {
  3190. struct ieee80211_hdr *hdr =
  3191. (struct ieee80211_hdr *) skb->data;
  3192. /* more buffered multicast/broadcast frames ==> set
  3193. * MoreData flag in IEEE 802.11 header to inform PS
  3194. * STAs */
  3195. hdr->frame_control |=
  3196. cpu_to_le16(IEEE80211_FCTL_MOREDATA);
  3197. }
  3198. if (sdata->vif.type == NL80211_IFTYPE_AP)
  3199. sdata = IEEE80211_DEV_TO_SUB_IF(skb->dev);
  3200. if (!ieee80211_tx_prepare(sdata, &tx, NULL, skb))
  3201. break;
  3202. dev_kfree_skb_any(skb);
  3203. }
  3204. info = IEEE80211_SKB_CB(skb);
  3205. tx.flags |= IEEE80211_TX_PS_BUFFERED;
  3206. info->band = chanctx_conf->def.chan->band;
  3207. if (invoke_tx_handlers(&tx))
  3208. skb = NULL;
  3209. out:
  3210. rcu_read_unlock();
  3211. return skb;
  3212. }
  3213. EXPORT_SYMBOL(ieee80211_get_buffered_bc);
  3214. int ieee80211_reserve_tid(struct ieee80211_sta *pubsta, u8 tid)
  3215. {
  3216. struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
  3217. struct ieee80211_sub_if_data *sdata = sta->sdata;
  3218. struct ieee80211_local *local = sdata->local;
  3219. int ret;
  3220. u32 queues;
  3221. lockdep_assert_held(&local->sta_mtx);
  3222. /* only some cases are supported right now */
  3223. switch (sdata->vif.type) {
  3224. case NL80211_IFTYPE_STATION:
  3225. case NL80211_IFTYPE_AP:
  3226. case NL80211_IFTYPE_AP_VLAN:
  3227. break;
  3228. default:
  3229. WARN_ON(1);
  3230. return -EINVAL;
  3231. }
  3232. if (WARN_ON(tid >= IEEE80211_NUM_UPS))
  3233. return -EINVAL;
  3234. if (sta->reserved_tid == tid) {
  3235. ret = 0;
  3236. goto out;
  3237. }
  3238. if (sta->reserved_tid != IEEE80211_TID_UNRESERVED) {
  3239. sdata_err(sdata, "TID reservation already active\n");
  3240. ret = -EALREADY;
  3241. goto out;
  3242. }
  3243. ieee80211_stop_vif_queues(sdata->local, sdata,
  3244. IEEE80211_QUEUE_STOP_REASON_RESERVE_TID);
  3245. synchronize_net();
  3246. /* Tear down BA sessions so we stop aggregating on this TID */
  3247. if (ieee80211_hw_check(&local->hw, AMPDU_AGGREGATION)) {
  3248. set_sta_flag(sta, WLAN_STA_BLOCK_BA);
  3249. __ieee80211_stop_tx_ba_session(sta, tid,
  3250. AGG_STOP_LOCAL_REQUEST);
  3251. }
  3252. queues = BIT(sdata->vif.hw_queue[ieee802_1d_to_ac[tid]]);
  3253. __ieee80211_flush_queues(local, sdata, queues, false);
  3254. sta->reserved_tid = tid;
  3255. ieee80211_wake_vif_queues(local, sdata,
  3256. IEEE80211_QUEUE_STOP_REASON_RESERVE_TID);
  3257. if (ieee80211_hw_check(&local->hw, AMPDU_AGGREGATION))
  3258. clear_sta_flag(sta, WLAN_STA_BLOCK_BA);
  3259. ret = 0;
  3260. out:
  3261. return ret;
  3262. }
  3263. EXPORT_SYMBOL(ieee80211_reserve_tid);
  3264. void ieee80211_unreserve_tid(struct ieee80211_sta *pubsta, u8 tid)
  3265. {
  3266. struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
  3267. struct ieee80211_sub_if_data *sdata = sta->sdata;
  3268. lockdep_assert_held(&sdata->local->sta_mtx);
  3269. /* only some cases are supported right now */
  3270. switch (sdata->vif.type) {
  3271. case NL80211_IFTYPE_STATION:
  3272. case NL80211_IFTYPE_AP:
  3273. case NL80211_IFTYPE_AP_VLAN:
  3274. break;
  3275. default:
  3276. WARN_ON(1);
  3277. return;
  3278. }
  3279. if (tid != sta->reserved_tid) {
  3280. sdata_err(sdata, "TID to unreserve (%d) isn't reserved\n", tid);
  3281. return;
  3282. }
  3283. sta->reserved_tid = IEEE80211_TID_UNRESERVED;
  3284. }
  3285. EXPORT_SYMBOL(ieee80211_unreserve_tid);
  3286. void __ieee80211_tx_skb_tid_band(struct ieee80211_sub_if_data *sdata,
  3287. struct sk_buff *skb, int tid,
  3288. enum ieee80211_band band)
  3289. {
  3290. int ac = ieee802_1d_to_ac[tid & 7];
  3291. skb_set_mac_header(skb, 0);
  3292. skb_set_network_header(skb, 0);
  3293. skb_set_transport_header(skb, 0);
  3294. skb_set_queue_mapping(skb, ac);
  3295. skb->priority = tid;
  3296. skb->dev = sdata->dev;
  3297. /*
  3298. * The other path calling ieee80211_xmit is from the tasklet,
  3299. * and while we can handle concurrent transmissions locking
  3300. * requirements are that we do not come into tx with bhs on.
  3301. */
  3302. local_bh_disable();
  3303. IEEE80211_SKB_CB(skb)->band = band;
  3304. ieee80211_xmit(sdata, NULL, skb);
  3305. local_bh_enable();
  3306. }