rx.c 120 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350
  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-2010 Johannes Berg <johannes@sipsolutions.net>
  6. * Copyright 2013-2014 Intel Mobile Communications GmbH
  7. * Copyright(c) 2015 - 2017 Intel Deutschland GmbH
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2 as
  11. * published by the Free Software Foundation.
  12. */
  13. #include <linux/jiffies.h>
  14. #include <linux/slab.h>
  15. #include <linux/kernel.h>
  16. #include <linux/skbuff.h>
  17. #include <linux/netdevice.h>
  18. #include <linux/etherdevice.h>
  19. #include <linux/rcupdate.h>
  20. #include <linux/export.h>
  21. #include <linux/bitops.h>
  22. #include <net/mac80211.h>
  23. #include <net/ieee80211_radiotap.h>
  24. #include <asm/unaligned.h>
  25. #include "ieee80211_i.h"
  26. #include "driver-ops.h"
  27. #include "led.h"
  28. #include "mesh.h"
  29. #include "wep.h"
  30. #include "wpa.h"
  31. #include "tkip.h"
  32. #include "wme.h"
  33. #include "rate.h"
  34. static inline void ieee80211_rx_stats(struct net_device *dev, u32 len)
  35. {
  36. struct pcpu_sw_netstats *tstats = this_cpu_ptr(dev->tstats);
  37. u64_stats_update_begin(&tstats->syncp);
  38. tstats->rx_packets++;
  39. tstats->rx_bytes += len;
  40. u64_stats_update_end(&tstats->syncp);
  41. }
  42. static u8 *ieee80211_get_bssid(struct ieee80211_hdr *hdr, size_t len,
  43. enum nl80211_iftype type)
  44. {
  45. __le16 fc = hdr->frame_control;
  46. if (ieee80211_is_data(fc)) {
  47. if (len < 24) /* drop incorrect hdr len (data) */
  48. return NULL;
  49. if (ieee80211_has_a4(fc))
  50. return NULL;
  51. if (ieee80211_has_tods(fc))
  52. return hdr->addr1;
  53. if (ieee80211_has_fromds(fc))
  54. return hdr->addr2;
  55. return hdr->addr3;
  56. }
  57. if (ieee80211_is_mgmt(fc)) {
  58. if (len < 24) /* drop incorrect hdr len (mgmt) */
  59. return NULL;
  60. return hdr->addr3;
  61. }
  62. if (ieee80211_is_ctl(fc)) {
  63. if (ieee80211_is_pspoll(fc))
  64. return hdr->addr1;
  65. if (ieee80211_is_back_req(fc)) {
  66. switch (type) {
  67. case NL80211_IFTYPE_STATION:
  68. return hdr->addr2;
  69. case NL80211_IFTYPE_AP:
  70. case NL80211_IFTYPE_AP_VLAN:
  71. return hdr->addr1;
  72. default:
  73. break; /* fall through to the return */
  74. }
  75. }
  76. }
  77. return NULL;
  78. }
  79. /*
  80. * monitor mode reception
  81. *
  82. * This function cleans up the SKB, i.e. it removes all the stuff
  83. * only useful for monitoring.
  84. */
  85. static struct sk_buff *remove_monitor_info(struct ieee80211_local *local,
  86. struct sk_buff *skb,
  87. unsigned int rtap_vendor_space)
  88. {
  89. if (ieee80211_hw_check(&local->hw, RX_INCLUDES_FCS)) {
  90. if (likely(skb->len > FCS_LEN))
  91. __pskb_trim(skb, skb->len - FCS_LEN);
  92. else {
  93. /* driver bug */
  94. WARN_ON(1);
  95. dev_kfree_skb(skb);
  96. return NULL;
  97. }
  98. }
  99. __pskb_pull(skb, rtap_vendor_space);
  100. return skb;
  101. }
  102. static inline bool should_drop_frame(struct sk_buff *skb, int present_fcs_len,
  103. unsigned int rtap_vendor_space)
  104. {
  105. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
  106. struct ieee80211_hdr *hdr;
  107. hdr = (void *)(skb->data + rtap_vendor_space);
  108. if (status->flag & (RX_FLAG_FAILED_FCS_CRC |
  109. RX_FLAG_FAILED_PLCP_CRC |
  110. RX_FLAG_ONLY_MONITOR))
  111. return true;
  112. if (unlikely(skb->len < 16 + present_fcs_len + rtap_vendor_space))
  113. return true;
  114. if (ieee80211_is_ctl(hdr->frame_control) &&
  115. !ieee80211_is_pspoll(hdr->frame_control) &&
  116. !ieee80211_is_back_req(hdr->frame_control))
  117. return true;
  118. return false;
  119. }
  120. static int
  121. ieee80211_rx_radiotap_hdrlen(struct ieee80211_local *local,
  122. struct ieee80211_rx_status *status,
  123. struct sk_buff *skb)
  124. {
  125. int len;
  126. /* always present fields */
  127. len = sizeof(struct ieee80211_radiotap_header) + 8;
  128. /* allocate extra bitmaps */
  129. if (status->chains)
  130. len += 4 * hweight8(status->chains);
  131. if (ieee80211_have_rx_timestamp(status)) {
  132. len = ALIGN(len, 8);
  133. len += 8;
  134. }
  135. if (ieee80211_hw_check(&local->hw, SIGNAL_DBM))
  136. len += 1;
  137. /* antenna field, if we don't have per-chain info */
  138. if (!status->chains)
  139. len += 1;
  140. /* padding for RX_FLAGS if necessary */
  141. len = ALIGN(len, 2);
  142. if (status->flag & RX_FLAG_HT) /* HT info */
  143. len += 3;
  144. if (status->flag & RX_FLAG_AMPDU_DETAILS) {
  145. len = ALIGN(len, 4);
  146. len += 8;
  147. }
  148. if (status->flag & RX_FLAG_VHT) {
  149. len = ALIGN(len, 2);
  150. len += 12;
  151. }
  152. if (local->hw.radiotap_timestamp.units_pos >= 0) {
  153. len = ALIGN(len, 8);
  154. len += 12;
  155. }
  156. if (status->chains) {
  157. /* antenna and antenna signal fields */
  158. len += 2 * hweight8(status->chains);
  159. }
  160. if (status->flag & RX_FLAG_RADIOTAP_VENDOR_DATA) {
  161. struct ieee80211_vendor_radiotap *rtap = (void *)skb->data;
  162. /* vendor presence bitmap */
  163. len += 4;
  164. /* alignment for fixed 6-byte vendor data header */
  165. len = ALIGN(len, 2);
  166. /* vendor data header */
  167. len += 6;
  168. if (WARN_ON(rtap->align == 0))
  169. rtap->align = 1;
  170. len = ALIGN(len, rtap->align);
  171. len += rtap->len + rtap->pad;
  172. }
  173. return len;
  174. }
  175. static void ieee80211_handle_mu_mimo_mon(struct ieee80211_sub_if_data *sdata,
  176. struct sk_buff *skb,
  177. int rtap_vendor_space)
  178. {
  179. struct {
  180. struct ieee80211_hdr_3addr hdr;
  181. u8 category;
  182. u8 action_code;
  183. } __packed action;
  184. if (!sdata)
  185. return;
  186. BUILD_BUG_ON(sizeof(action) != IEEE80211_MIN_ACTION_SIZE + 1);
  187. if (skb->len < rtap_vendor_space + sizeof(action) +
  188. VHT_MUMIMO_GROUPS_DATA_LEN)
  189. return;
  190. if (!is_valid_ether_addr(sdata->u.mntr.mu_follow_addr))
  191. return;
  192. skb_copy_bits(skb, rtap_vendor_space, &action, sizeof(action));
  193. if (!ieee80211_is_action(action.hdr.frame_control))
  194. return;
  195. if (action.category != WLAN_CATEGORY_VHT)
  196. return;
  197. if (action.action_code != WLAN_VHT_ACTION_GROUPID_MGMT)
  198. return;
  199. if (!ether_addr_equal(action.hdr.addr1, sdata->u.mntr.mu_follow_addr))
  200. return;
  201. skb = skb_copy(skb, GFP_ATOMIC);
  202. if (!skb)
  203. return;
  204. skb->pkt_type = IEEE80211_SDATA_QUEUE_TYPE_FRAME;
  205. skb_queue_tail(&sdata->skb_queue, skb);
  206. ieee80211_queue_work(&sdata->local->hw, &sdata->work);
  207. }
  208. /*
  209. * ieee80211_add_rx_radiotap_header - add radiotap header
  210. *
  211. * add a radiotap header containing all the fields which the hardware provided.
  212. */
  213. static void
  214. ieee80211_add_rx_radiotap_header(struct ieee80211_local *local,
  215. struct sk_buff *skb,
  216. struct ieee80211_rate *rate,
  217. int rtap_len, bool has_fcs)
  218. {
  219. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
  220. struct ieee80211_radiotap_header *rthdr;
  221. unsigned char *pos;
  222. __le32 *it_present;
  223. u32 it_present_val;
  224. u16 rx_flags = 0;
  225. u16 channel_flags = 0;
  226. int mpdulen, chain;
  227. unsigned long chains = status->chains;
  228. struct ieee80211_vendor_radiotap rtap = {};
  229. if (status->flag & RX_FLAG_RADIOTAP_VENDOR_DATA) {
  230. rtap = *(struct ieee80211_vendor_radiotap *)skb->data;
  231. /* rtap.len and rtap.pad are undone immediately */
  232. skb_pull(skb, sizeof(rtap) + rtap.len + rtap.pad);
  233. }
  234. mpdulen = skb->len;
  235. if (!(has_fcs && ieee80211_hw_check(&local->hw, RX_INCLUDES_FCS)))
  236. mpdulen += FCS_LEN;
  237. rthdr = (struct ieee80211_radiotap_header *)skb_push(skb, rtap_len);
  238. memset(rthdr, 0, rtap_len - rtap.len - rtap.pad);
  239. it_present = &rthdr->it_present;
  240. /* radiotap header, set always present flags */
  241. rthdr->it_len = cpu_to_le16(rtap_len);
  242. it_present_val = BIT(IEEE80211_RADIOTAP_FLAGS) |
  243. BIT(IEEE80211_RADIOTAP_CHANNEL) |
  244. BIT(IEEE80211_RADIOTAP_RX_FLAGS);
  245. if (!status->chains)
  246. it_present_val |= BIT(IEEE80211_RADIOTAP_ANTENNA);
  247. for_each_set_bit(chain, &chains, IEEE80211_MAX_CHAINS) {
  248. it_present_val |=
  249. BIT(IEEE80211_RADIOTAP_EXT) |
  250. BIT(IEEE80211_RADIOTAP_RADIOTAP_NAMESPACE);
  251. put_unaligned_le32(it_present_val, it_present);
  252. it_present++;
  253. it_present_val = BIT(IEEE80211_RADIOTAP_ANTENNA) |
  254. BIT(IEEE80211_RADIOTAP_DBM_ANTSIGNAL);
  255. }
  256. if (status->flag & RX_FLAG_RADIOTAP_VENDOR_DATA) {
  257. it_present_val |= BIT(IEEE80211_RADIOTAP_VENDOR_NAMESPACE) |
  258. BIT(IEEE80211_RADIOTAP_EXT);
  259. put_unaligned_le32(it_present_val, it_present);
  260. it_present++;
  261. it_present_val = rtap.present;
  262. }
  263. put_unaligned_le32(it_present_val, it_present);
  264. pos = (void *)(it_present + 1);
  265. /* the order of the following fields is important */
  266. /* IEEE80211_RADIOTAP_TSFT */
  267. if (ieee80211_have_rx_timestamp(status)) {
  268. /* padding */
  269. while ((pos - (u8 *)rthdr) & 7)
  270. *pos++ = 0;
  271. put_unaligned_le64(
  272. ieee80211_calculate_rx_timestamp(local, status,
  273. mpdulen, 0),
  274. pos);
  275. rthdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_TSFT);
  276. pos += 8;
  277. }
  278. /* IEEE80211_RADIOTAP_FLAGS */
  279. if (has_fcs && ieee80211_hw_check(&local->hw, RX_INCLUDES_FCS))
  280. *pos |= IEEE80211_RADIOTAP_F_FCS;
  281. if (status->flag & (RX_FLAG_FAILED_FCS_CRC | RX_FLAG_FAILED_PLCP_CRC))
  282. *pos |= IEEE80211_RADIOTAP_F_BADFCS;
  283. if (status->flag & RX_FLAG_SHORTPRE)
  284. *pos |= IEEE80211_RADIOTAP_F_SHORTPRE;
  285. pos++;
  286. /* IEEE80211_RADIOTAP_RATE */
  287. if (!rate || status->flag & (RX_FLAG_HT | RX_FLAG_VHT)) {
  288. /*
  289. * Without rate information don't add it. If we have,
  290. * MCS information is a separate field in radiotap,
  291. * added below. The byte here is needed as padding
  292. * for the channel though, so initialise it to 0.
  293. */
  294. *pos = 0;
  295. } else {
  296. int shift = 0;
  297. rthdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_RATE);
  298. if (status->flag & RX_FLAG_10MHZ)
  299. shift = 1;
  300. else if (status->flag & RX_FLAG_5MHZ)
  301. shift = 2;
  302. *pos = DIV_ROUND_UP(rate->bitrate, 5 * (1 << shift));
  303. }
  304. pos++;
  305. /* IEEE80211_RADIOTAP_CHANNEL */
  306. put_unaligned_le16(status->freq, pos);
  307. pos += 2;
  308. if (status->flag & RX_FLAG_10MHZ)
  309. channel_flags |= IEEE80211_CHAN_HALF;
  310. else if (status->flag & RX_FLAG_5MHZ)
  311. channel_flags |= IEEE80211_CHAN_QUARTER;
  312. if (status->band == NL80211_BAND_5GHZ)
  313. channel_flags |= IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ;
  314. else if (status->flag & (RX_FLAG_HT | RX_FLAG_VHT))
  315. channel_flags |= IEEE80211_CHAN_DYN | IEEE80211_CHAN_2GHZ;
  316. else if (rate && rate->flags & IEEE80211_RATE_ERP_G)
  317. channel_flags |= IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ;
  318. else if (rate)
  319. channel_flags |= IEEE80211_CHAN_CCK | IEEE80211_CHAN_2GHZ;
  320. else
  321. channel_flags |= IEEE80211_CHAN_2GHZ;
  322. put_unaligned_le16(channel_flags, pos);
  323. pos += 2;
  324. /* IEEE80211_RADIOTAP_DBM_ANTSIGNAL */
  325. if (ieee80211_hw_check(&local->hw, SIGNAL_DBM) &&
  326. !(status->flag & RX_FLAG_NO_SIGNAL_VAL)) {
  327. *pos = status->signal;
  328. rthdr->it_present |=
  329. cpu_to_le32(1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL);
  330. pos++;
  331. }
  332. /* IEEE80211_RADIOTAP_LOCK_QUALITY is missing */
  333. if (!status->chains) {
  334. /* IEEE80211_RADIOTAP_ANTENNA */
  335. *pos = status->antenna;
  336. pos++;
  337. }
  338. /* IEEE80211_RADIOTAP_DB_ANTNOISE is not used */
  339. /* IEEE80211_RADIOTAP_RX_FLAGS */
  340. /* ensure 2 byte alignment for the 2 byte field as required */
  341. if ((pos - (u8 *)rthdr) & 1)
  342. *pos++ = 0;
  343. if (status->flag & RX_FLAG_FAILED_PLCP_CRC)
  344. rx_flags |= IEEE80211_RADIOTAP_F_RX_BADPLCP;
  345. put_unaligned_le16(rx_flags, pos);
  346. pos += 2;
  347. if (status->flag & RX_FLAG_HT) {
  348. unsigned int stbc;
  349. rthdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_MCS);
  350. *pos++ = local->hw.radiotap_mcs_details;
  351. *pos = 0;
  352. if (status->flag & RX_FLAG_SHORT_GI)
  353. *pos |= IEEE80211_RADIOTAP_MCS_SGI;
  354. if (status->flag & RX_FLAG_40MHZ)
  355. *pos |= IEEE80211_RADIOTAP_MCS_BW_40;
  356. if (status->flag & RX_FLAG_HT_GF)
  357. *pos |= IEEE80211_RADIOTAP_MCS_FMT_GF;
  358. if (status->flag & RX_FLAG_LDPC)
  359. *pos |= IEEE80211_RADIOTAP_MCS_FEC_LDPC;
  360. stbc = (status->flag & RX_FLAG_STBC_MASK) >> RX_FLAG_STBC_SHIFT;
  361. *pos |= stbc << IEEE80211_RADIOTAP_MCS_STBC_SHIFT;
  362. pos++;
  363. *pos++ = status->rate_idx;
  364. }
  365. if (status->flag & RX_FLAG_AMPDU_DETAILS) {
  366. u16 flags = 0;
  367. /* ensure 4 byte alignment */
  368. while ((pos - (u8 *)rthdr) & 3)
  369. pos++;
  370. rthdr->it_present |=
  371. cpu_to_le32(1 << IEEE80211_RADIOTAP_AMPDU_STATUS);
  372. put_unaligned_le32(status->ampdu_reference, pos);
  373. pos += 4;
  374. if (status->flag & RX_FLAG_AMPDU_LAST_KNOWN)
  375. flags |= IEEE80211_RADIOTAP_AMPDU_LAST_KNOWN;
  376. if (status->flag & RX_FLAG_AMPDU_IS_LAST)
  377. flags |= IEEE80211_RADIOTAP_AMPDU_IS_LAST;
  378. if (status->flag & RX_FLAG_AMPDU_DELIM_CRC_ERROR)
  379. flags |= IEEE80211_RADIOTAP_AMPDU_DELIM_CRC_ERR;
  380. if (status->flag & RX_FLAG_AMPDU_DELIM_CRC_KNOWN)
  381. flags |= IEEE80211_RADIOTAP_AMPDU_DELIM_CRC_KNOWN;
  382. put_unaligned_le16(flags, pos);
  383. pos += 2;
  384. if (status->flag & RX_FLAG_AMPDU_DELIM_CRC_KNOWN)
  385. *pos++ = status->ampdu_delimiter_crc;
  386. else
  387. *pos++ = 0;
  388. *pos++ = 0;
  389. }
  390. if (status->flag & RX_FLAG_VHT) {
  391. u16 known = local->hw.radiotap_vht_details;
  392. rthdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_VHT);
  393. put_unaligned_le16(known, pos);
  394. pos += 2;
  395. /* flags */
  396. if (status->flag & RX_FLAG_SHORT_GI)
  397. *pos |= IEEE80211_RADIOTAP_VHT_FLAG_SGI;
  398. /* in VHT, STBC is binary */
  399. if (status->flag & RX_FLAG_STBC_MASK)
  400. *pos |= IEEE80211_RADIOTAP_VHT_FLAG_STBC;
  401. if (status->vht_flag & RX_VHT_FLAG_BF)
  402. *pos |= IEEE80211_RADIOTAP_VHT_FLAG_BEAMFORMED;
  403. pos++;
  404. /* bandwidth */
  405. if (status->vht_flag & RX_VHT_FLAG_80MHZ)
  406. *pos++ = 4;
  407. else if (status->vht_flag & RX_VHT_FLAG_160MHZ)
  408. *pos++ = 11;
  409. else if (status->flag & RX_FLAG_40MHZ)
  410. *pos++ = 1;
  411. else /* 20 MHz */
  412. *pos++ = 0;
  413. /* MCS/NSS */
  414. *pos = (status->rate_idx << 4) | status->vht_nss;
  415. pos += 4;
  416. /* coding field */
  417. if (status->flag & RX_FLAG_LDPC)
  418. *pos |= IEEE80211_RADIOTAP_CODING_LDPC_USER0;
  419. pos++;
  420. /* group ID */
  421. pos++;
  422. /* partial_aid */
  423. pos += 2;
  424. }
  425. if (local->hw.radiotap_timestamp.units_pos >= 0) {
  426. u16 accuracy = 0;
  427. u8 flags = IEEE80211_RADIOTAP_TIMESTAMP_FLAG_32BIT;
  428. rthdr->it_present |=
  429. cpu_to_le32(1 << IEEE80211_RADIOTAP_TIMESTAMP);
  430. /* ensure 8 byte alignment */
  431. while ((pos - (u8 *)rthdr) & 7)
  432. pos++;
  433. put_unaligned_le64(status->device_timestamp, pos);
  434. pos += sizeof(u64);
  435. if (local->hw.radiotap_timestamp.accuracy >= 0) {
  436. accuracy = local->hw.radiotap_timestamp.accuracy;
  437. flags |= IEEE80211_RADIOTAP_TIMESTAMP_FLAG_ACCURACY;
  438. }
  439. put_unaligned_le16(accuracy, pos);
  440. pos += sizeof(u16);
  441. *pos++ = local->hw.radiotap_timestamp.units_pos;
  442. *pos++ = flags;
  443. }
  444. for_each_set_bit(chain, &chains, IEEE80211_MAX_CHAINS) {
  445. *pos++ = status->chain_signal[chain];
  446. *pos++ = chain;
  447. }
  448. if (status->flag & RX_FLAG_RADIOTAP_VENDOR_DATA) {
  449. /* ensure 2 byte alignment for the vendor field as required */
  450. if ((pos - (u8 *)rthdr) & 1)
  451. *pos++ = 0;
  452. *pos++ = rtap.oui[0];
  453. *pos++ = rtap.oui[1];
  454. *pos++ = rtap.oui[2];
  455. *pos++ = rtap.subns;
  456. put_unaligned_le16(rtap.len, pos);
  457. pos += 2;
  458. /* align the actual payload as requested */
  459. while ((pos - (u8 *)rthdr) & (rtap.align - 1))
  460. *pos++ = 0;
  461. /* data (and possible padding) already follows */
  462. }
  463. }
  464. /*
  465. * This function copies a received frame to all monitor interfaces and
  466. * returns a cleaned-up SKB that no longer includes the FCS nor the
  467. * radiotap header the driver might have added.
  468. */
  469. static struct sk_buff *
  470. ieee80211_rx_monitor(struct ieee80211_local *local, struct sk_buff *origskb,
  471. struct ieee80211_rate *rate)
  472. {
  473. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(origskb);
  474. struct ieee80211_sub_if_data *sdata;
  475. int rt_hdrlen, needed_headroom;
  476. struct sk_buff *skb, *skb2;
  477. struct net_device *prev_dev = NULL;
  478. int present_fcs_len = 0;
  479. unsigned int rtap_vendor_space = 0;
  480. struct ieee80211_sub_if_data *monitor_sdata =
  481. rcu_dereference(local->monitor_sdata);
  482. if (unlikely(status->flag & RX_FLAG_RADIOTAP_VENDOR_DATA)) {
  483. struct ieee80211_vendor_radiotap *rtap = (void *)origskb->data;
  484. rtap_vendor_space = sizeof(*rtap) + rtap->len + rtap->pad;
  485. }
  486. /*
  487. * First, we may need to make a copy of the skb because
  488. * (1) we need to modify it for radiotap (if not present), and
  489. * (2) the other RX handlers will modify the skb we got.
  490. *
  491. * We don't need to, of course, if we aren't going to return
  492. * the SKB because it has a bad FCS/PLCP checksum.
  493. */
  494. if (ieee80211_hw_check(&local->hw, RX_INCLUDES_FCS))
  495. present_fcs_len = FCS_LEN;
  496. /* ensure hdr->frame_control and vendor radiotap data are in skb head */
  497. if (!pskb_may_pull(origskb, 2 + rtap_vendor_space)) {
  498. dev_kfree_skb(origskb);
  499. return NULL;
  500. }
  501. if (!local->monitors || (status->flag & RX_FLAG_SKIP_MONITOR)) {
  502. if (should_drop_frame(origskb, present_fcs_len,
  503. rtap_vendor_space)) {
  504. dev_kfree_skb(origskb);
  505. return NULL;
  506. }
  507. return remove_monitor_info(local, origskb, rtap_vendor_space);
  508. }
  509. ieee80211_handle_mu_mimo_mon(monitor_sdata, origskb, rtap_vendor_space);
  510. /* room for the radiotap header based on driver features */
  511. rt_hdrlen = ieee80211_rx_radiotap_hdrlen(local, status, origskb);
  512. needed_headroom = rt_hdrlen - rtap_vendor_space;
  513. if (should_drop_frame(origskb, present_fcs_len, rtap_vendor_space)) {
  514. /* only need to expand headroom if necessary */
  515. skb = origskb;
  516. origskb = NULL;
  517. /*
  518. * This shouldn't trigger often because most devices have an
  519. * RX header they pull before we get here, and that should
  520. * be big enough for our radiotap information. We should
  521. * probably export the length to drivers so that we can have
  522. * them allocate enough headroom to start with.
  523. */
  524. if (skb_headroom(skb) < needed_headroom &&
  525. pskb_expand_head(skb, needed_headroom, 0, GFP_ATOMIC)) {
  526. dev_kfree_skb(skb);
  527. return NULL;
  528. }
  529. } else {
  530. /*
  531. * Need to make a copy and possibly remove radiotap header
  532. * and FCS from the original.
  533. */
  534. skb = skb_copy_expand(origskb, needed_headroom, 0, GFP_ATOMIC);
  535. origskb = remove_monitor_info(local, origskb,
  536. rtap_vendor_space);
  537. if (!skb)
  538. return origskb;
  539. }
  540. /* prepend radiotap information */
  541. ieee80211_add_rx_radiotap_header(local, skb, rate, rt_hdrlen, true);
  542. skb_reset_mac_header(skb);
  543. skb->ip_summed = CHECKSUM_UNNECESSARY;
  544. skb->pkt_type = PACKET_OTHERHOST;
  545. skb->protocol = htons(ETH_P_802_2);
  546. list_for_each_entry_rcu(sdata, &local->interfaces, list) {
  547. if (sdata->vif.type != NL80211_IFTYPE_MONITOR)
  548. continue;
  549. if (sdata->u.mntr.flags & MONITOR_FLAG_COOK_FRAMES)
  550. continue;
  551. if (!ieee80211_sdata_running(sdata))
  552. continue;
  553. if (prev_dev) {
  554. skb2 = skb_clone(skb, GFP_ATOMIC);
  555. if (skb2) {
  556. skb2->dev = prev_dev;
  557. netif_receive_skb(skb2);
  558. }
  559. }
  560. prev_dev = sdata->dev;
  561. ieee80211_rx_stats(sdata->dev, skb->len);
  562. }
  563. if (prev_dev) {
  564. skb->dev = prev_dev;
  565. netif_receive_skb(skb);
  566. } else
  567. dev_kfree_skb(skb);
  568. return origskb;
  569. }
  570. static void ieee80211_parse_qos(struct ieee80211_rx_data *rx)
  571. {
  572. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
  573. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
  574. int tid, seqno_idx, security_idx;
  575. /* does the frame have a qos control field? */
  576. if (ieee80211_is_data_qos(hdr->frame_control)) {
  577. u8 *qc = ieee80211_get_qos_ctl(hdr);
  578. /* frame has qos control */
  579. tid = *qc & IEEE80211_QOS_CTL_TID_MASK;
  580. if (*qc & IEEE80211_QOS_CTL_A_MSDU_PRESENT)
  581. status->rx_flags |= IEEE80211_RX_AMSDU;
  582. seqno_idx = tid;
  583. security_idx = tid;
  584. } else {
  585. /*
  586. * IEEE 802.11-2007, 7.1.3.4.1 ("Sequence Number field"):
  587. *
  588. * Sequence numbers for management frames, QoS data
  589. * frames with a broadcast/multicast address in the
  590. * Address 1 field, and all non-QoS data frames sent
  591. * by QoS STAs are assigned using an additional single
  592. * modulo-4096 counter, [...]
  593. *
  594. * We also use that counter for non-QoS STAs.
  595. */
  596. seqno_idx = IEEE80211_NUM_TIDS;
  597. security_idx = 0;
  598. if (ieee80211_is_mgmt(hdr->frame_control))
  599. security_idx = IEEE80211_NUM_TIDS;
  600. tid = 0;
  601. }
  602. rx->seqno_idx = seqno_idx;
  603. rx->security_idx = security_idx;
  604. /* Set skb->priority to 1d tag if highest order bit of TID is not set.
  605. * For now, set skb->priority to 0 for other cases. */
  606. rx->skb->priority = (tid > 7) ? 0 : tid;
  607. }
  608. /**
  609. * DOC: Packet alignment
  610. *
  611. * Drivers always need to pass packets that are aligned to two-byte boundaries
  612. * to the stack.
  613. *
  614. * Additionally, should, if possible, align the payload data in a way that
  615. * guarantees that the contained IP header is aligned to a four-byte
  616. * boundary. In the case of regular frames, this simply means aligning the
  617. * payload to a four-byte boundary (because either the IP header is directly
  618. * contained, or IV/RFC1042 headers that have a length divisible by four are
  619. * in front of it). If the payload data is not properly aligned and the
  620. * architecture doesn't support efficient unaligned operations, mac80211
  621. * will align the data.
  622. *
  623. * With A-MSDU frames, however, the payload data address must yield two modulo
  624. * four because there are 14-byte 802.3 headers within the A-MSDU frames that
  625. * push the IP header further back to a multiple of four again. Thankfully, the
  626. * specs were sane enough this time around to require padding each A-MSDU
  627. * subframe to a length that is a multiple of four.
  628. *
  629. * Padding like Atheros hardware adds which is between the 802.11 header and
  630. * the payload is not supported, the driver is required to move the 802.11
  631. * header to be directly in front of the payload in that case.
  632. */
  633. static void ieee80211_verify_alignment(struct ieee80211_rx_data *rx)
  634. {
  635. #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
  636. WARN_ON_ONCE((unsigned long)rx->skb->data & 1);
  637. #endif
  638. }
  639. /* rx handlers */
  640. static int ieee80211_is_unicast_robust_mgmt_frame(struct sk_buff *skb)
  641. {
  642. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
  643. if (is_multicast_ether_addr(hdr->addr1))
  644. return 0;
  645. return ieee80211_is_robust_mgmt_frame(skb);
  646. }
  647. static int ieee80211_is_multicast_robust_mgmt_frame(struct sk_buff *skb)
  648. {
  649. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
  650. if (!is_multicast_ether_addr(hdr->addr1))
  651. return 0;
  652. return ieee80211_is_robust_mgmt_frame(skb);
  653. }
  654. /* Get the BIP key index from MMIE; return -1 if this is not a BIP frame */
  655. static int ieee80211_get_mmie_keyidx(struct sk_buff *skb)
  656. {
  657. struct ieee80211_mgmt *hdr = (struct ieee80211_mgmt *) skb->data;
  658. struct ieee80211_mmie *mmie;
  659. struct ieee80211_mmie_16 *mmie16;
  660. if (skb->len < 24 + sizeof(*mmie) || !is_multicast_ether_addr(hdr->da))
  661. return -1;
  662. if (!ieee80211_is_robust_mgmt_frame(skb))
  663. return -1; /* not a robust management frame */
  664. mmie = (struct ieee80211_mmie *)
  665. (skb->data + skb->len - sizeof(*mmie));
  666. if (mmie->element_id == WLAN_EID_MMIE &&
  667. mmie->length == sizeof(*mmie) - 2)
  668. return le16_to_cpu(mmie->key_id);
  669. mmie16 = (struct ieee80211_mmie_16 *)
  670. (skb->data + skb->len - sizeof(*mmie16));
  671. if (skb->len >= 24 + sizeof(*mmie16) &&
  672. mmie16->element_id == WLAN_EID_MMIE &&
  673. mmie16->length == sizeof(*mmie16) - 2)
  674. return le16_to_cpu(mmie16->key_id);
  675. return -1;
  676. }
  677. static int ieee80211_get_cs_keyid(const struct ieee80211_cipher_scheme *cs,
  678. struct sk_buff *skb)
  679. {
  680. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
  681. __le16 fc;
  682. int hdrlen;
  683. u8 keyid;
  684. fc = hdr->frame_control;
  685. hdrlen = ieee80211_hdrlen(fc);
  686. if (skb->len < hdrlen + cs->hdr_len)
  687. return -EINVAL;
  688. skb_copy_bits(skb, hdrlen + cs->key_idx_off, &keyid, 1);
  689. keyid &= cs->key_idx_mask;
  690. keyid >>= cs->key_idx_shift;
  691. return keyid;
  692. }
  693. static ieee80211_rx_result ieee80211_rx_mesh_check(struct ieee80211_rx_data *rx)
  694. {
  695. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
  696. char *dev_addr = rx->sdata->vif.addr;
  697. if (ieee80211_is_data(hdr->frame_control)) {
  698. if (is_multicast_ether_addr(hdr->addr1)) {
  699. if (ieee80211_has_tods(hdr->frame_control) ||
  700. !ieee80211_has_fromds(hdr->frame_control))
  701. return RX_DROP_MONITOR;
  702. if (ether_addr_equal(hdr->addr3, dev_addr))
  703. return RX_DROP_MONITOR;
  704. } else {
  705. if (!ieee80211_has_a4(hdr->frame_control))
  706. return RX_DROP_MONITOR;
  707. if (ether_addr_equal(hdr->addr4, dev_addr))
  708. return RX_DROP_MONITOR;
  709. }
  710. }
  711. /* If there is not an established peer link and this is not a peer link
  712. * establisment frame, beacon or probe, drop the frame.
  713. */
  714. if (!rx->sta || sta_plink_state(rx->sta) != NL80211_PLINK_ESTAB) {
  715. struct ieee80211_mgmt *mgmt;
  716. if (!ieee80211_is_mgmt(hdr->frame_control))
  717. return RX_DROP_MONITOR;
  718. if (ieee80211_is_action(hdr->frame_control)) {
  719. u8 category;
  720. /* make sure category field is present */
  721. if (rx->skb->len < IEEE80211_MIN_ACTION_SIZE)
  722. return RX_DROP_MONITOR;
  723. mgmt = (struct ieee80211_mgmt *)hdr;
  724. category = mgmt->u.action.category;
  725. if (category != WLAN_CATEGORY_MESH_ACTION &&
  726. category != WLAN_CATEGORY_SELF_PROTECTED)
  727. return RX_DROP_MONITOR;
  728. return RX_CONTINUE;
  729. }
  730. if (ieee80211_is_probe_req(hdr->frame_control) ||
  731. ieee80211_is_probe_resp(hdr->frame_control) ||
  732. ieee80211_is_beacon(hdr->frame_control) ||
  733. ieee80211_is_auth(hdr->frame_control))
  734. return RX_CONTINUE;
  735. return RX_DROP_MONITOR;
  736. }
  737. return RX_CONTINUE;
  738. }
  739. static inline bool ieee80211_rx_reorder_ready(struct tid_ampdu_rx *tid_agg_rx,
  740. int index)
  741. {
  742. struct sk_buff_head *frames = &tid_agg_rx->reorder_buf[index];
  743. struct sk_buff *tail = skb_peek_tail(frames);
  744. struct ieee80211_rx_status *status;
  745. if (tid_agg_rx->reorder_buf_filtered & BIT_ULL(index))
  746. return true;
  747. if (!tail)
  748. return false;
  749. status = IEEE80211_SKB_RXCB(tail);
  750. if (status->flag & RX_FLAG_AMSDU_MORE)
  751. return false;
  752. return true;
  753. }
  754. static void ieee80211_release_reorder_frame(struct ieee80211_sub_if_data *sdata,
  755. struct tid_ampdu_rx *tid_agg_rx,
  756. int index,
  757. struct sk_buff_head *frames)
  758. {
  759. struct sk_buff_head *skb_list = &tid_agg_rx->reorder_buf[index];
  760. struct sk_buff *skb;
  761. struct ieee80211_rx_status *status;
  762. lockdep_assert_held(&tid_agg_rx->reorder_lock);
  763. if (skb_queue_empty(skb_list))
  764. goto no_frame;
  765. if (!ieee80211_rx_reorder_ready(tid_agg_rx, index)) {
  766. __skb_queue_purge(skb_list);
  767. goto no_frame;
  768. }
  769. /* release frames from the reorder ring buffer */
  770. tid_agg_rx->stored_mpdu_num--;
  771. while ((skb = __skb_dequeue(skb_list))) {
  772. status = IEEE80211_SKB_RXCB(skb);
  773. status->rx_flags |= IEEE80211_RX_DEFERRED_RELEASE;
  774. __skb_queue_tail(frames, skb);
  775. }
  776. no_frame:
  777. tid_agg_rx->reorder_buf_filtered &= ~BIT_ULL(index);
  778. tid_agg_rx->head_seq_num = ieee80211_sn_inc(tid_agg_rx->head_seq_num);
  779. }
  780. static void ieee80211_release_reorder_frames(struct ieee80211_sub_if_data *sdata,
  781. struct tid_ampdu_rx *tid_agg_rx,
  782. u16 head_seq_num,
  783. struct sk_buff_head *frames)
  784. {
  785. int index;
  786. lockdep_assert_held(&tid_agg_rx->reorder_lock);
  787. while (ieee80211_sn_less(tid_agg_rx->head_seq_num, head_seq_num)) {
  788. index = tid_agg_rx->head_seq_num % tid_agg_rx->buf_size;
  789. ieee80211_release_reorder_frame(sdata, tid_agg_rx, index,
  790. frames);
  791. }
  792. }
  793. /*
  794. * Timeout (in jiffies) for skb's that are waiting in the RX reorder buffer. If
  795. * the skb was added to the buffer longer than this time ago, the earlier
  796. * frames that have not yet been received are assumed to be lost and the skb
  797. * can be released for processing. This may also release other skb's from the
  798. * reorder buffer if there are no additional gaps between the frames.
  799. *
  800. * Callers must hold tid_agg_rx->reorder_lock.
  801. */
  802. #define HT_RX_REORDER_BUF_TIMEOUT (HZ / 10)
  803. static void ieee80211_sta_reorder_release(struct ieee80211_sub_if_data *sdata,
  804. struct tid_ampdu_rx *tid_agg_rx,
  805. struct sk_buff_head *frames)
  806. {
  807. int index, i, j;
  808. lockdep_assert_held(&tid_agg_rx->reorder_lock);
  809. /* release the buffer until next missing frame */
  810. index = tid_agg_rx->head_seq_num % tid_agg_rx->buf_size;
  811. if (!ieee80211_rx_reorder_ready(tid_agg_rx, index) &&
  812. tid_agg_rx->stored_mpdu_num) {
  813. /*
  814. * No buffers ready to be released, but check whether any
  815. * frames in the reorder buffer have timed out.
  816. */
  817. int skipped = 1;
  818. for (j = (index + 1) % tid_agg_rx->buf_size; j != index;
  819. j = (j + 1) % tid_agg_rx->buf_size) {
  820. if (!ieee80211_rx_reorder_ready(tid_agg_rx, j)) {
  821. skipped++;
  822. continue;
  823. }
  824. if (skipped &&
  825. !time_after(jiffies, tid_agg_rx->reorder_time[j] +
  826. HT_RX_REORDER_BUF_TIMEOUT))
  827. goto set_release_timer;
  828. /* don't leave incomplete A-MSDUs around */
  829. for (i = (index + 1) % tid_agg_rx->buf_size; i != j;
  830. i = (i + 1) % tid_agg_rx->buf_size)
  831. __skb_queue_purge(&tid_agg_rx->reorder_buf[i]);
  832. ht_dbg_ratelimited(sdata,
  833. "release an RX reorder frame due to timeout on earlier frames\n");
  834. ieee80211_release_reorder_frame(sdata, tid_agg_rx, j,
  835. frames);
  836. /*
  837. * Increment the head seq# also for the skipped slots.
  838. */
  839. tid_agg_rx->head_seq_num =
  840. (tid_agg_rx->head_seq_num +
  841. skipped) & IEEE80211_SN_MASK;
  842. skipped = 0;
  843. }
  844. } else while (ieee80211_rx_reorder_ready(tid_agg_rx, index)) {
  845. ieee80211_release_reorder_frame(sdata, tid_agg_rx, index,
  846. frames);
  847. index = tid_agg_rx->head_seq_num % tid_agg_rx->buf_size;
  848. }
  849. if (tid_agg_rx->stored_mpdu_num) {
  850. j = index = tid_agg_rx->head_seq_num % tid_agg_rx->buf_size;
  851. for (; j != (index - 1) % tid_agg_rx->buf_size;
  852. j = (j + 1) % tid_agg_rx->buf_size) {
  853. if (ieee80211_rx_reorder_ready(tid_agg_rx, j))
  854. break;
  855. }
  856. set_release_timer:
  857. if (!tid_agg_rx->removed)
  858. mod_timer(&tid_agg_rx->reorder_timer,
  859. tid_agg_rx->reorder_time[j] + 1 +
  860. HT_RX_REORDER_BUF_TIMEOUT);
  861. } else {
  862. del_timer(&tid_agg_rx->reorder_timer);
  863. }
  864. }
  865. /*
  866. * As this function belongs to the RX path it must be under
  867. * rcu_read_lock protection. It returns false if the frame
  868. * can be processed immediately, true if it was consumed.
  869. */
  870. static bool ieee80211_sta_manage_reorder_buf(struct ieee80211_sub_if_data *sdata,
  871. struct tid_ampdu_rx *tid_agg_rx,
  872. struct sk_buff *skb,
  873. struct sk_buff_head *frames)
  874. {
  875. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
  876. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
  877. u16 sc = le16_to_cpu(hdr->seq_ctrl);
  878. u16 mpdu_seq_num = (sc & IEEE80211_SCTL_SEQ) >> 4;
  879. u16 head_seq_num, buf_size;
  880. int index;
  881. bool ret = true;
  882. spin_lock(&tid_agg_rx->reorder_lock);
  883. /*
  884. * Offloaded BA sessions have no known starting sequence number so pick
  885. * one from first Rxed frame for this tid after BA was started.
  886. */
  887. if (unlikely(tid_agg_rx->auto_seq)) {
  888. tid_agg_rx->auto_seq = false;
  889. tid_agg_rx->ssn = mpdu_seq_num;
  890. tid_agg_rx->head_seq_num = mpdu_seq_num;
  891. }
  892. buf_size = tid_agg_rx->buf_size;
  893. head_seq_num = tid_agg_rx->head_seq_num;
  894. /*
  895. * If the current MPDU's SN is smaller than the SSN, it shouldn't
  896. * be reordered.
  897. */
  898. if (unlikely(!tid_agg_rx->started)) {
  899. if (ieee80211_sn_less(mpdu_seq_num, head_seq_num)) {
  900. ret = false;
  901. goto out;
  902. }
  903. tid_agg_rx->started = true;
  904. }
  905. /* frame with out of date sequence number */
  906. if (ieee80211_sn_less(mpdu_seq_num, head_seq_num)) {
  907. dev_kfree_skb(skb);
  908. goto out;
  909. }
  910. /*
  911. * If frame the sequence number exceeds our buffering window
  912. * size release some previous frames to make room for this one.
  913. */
  914. if (!ieee80211_sn_less(mpdu_seq_num, head_seq_num + buf_size)) {
  915. head_seq_num = ieee80211_sn_inc(
  916. ieee80211_sn_sub(mpdu_seq_num, buf_size));
  917. /* release stored frames up to new head to stack */
  918. ieee80211_release_reorder_frames(sdata, tid_agg_rx,
  919. head_seq_num, frames);
  920. }
  921. /* Now the new frame is always in the range of the reordering buffer */
  922. index = mpdu_seq_num % tid_agg_rx->buf_size;
  923. /* check if we already stored this frame */
  924. if (ieee80211_rx_reorder_ready(tid_agg_rx, index)) {
  925. dev_kfree_skb(skb);
  926. goto out;
  927. }
  928. /*
  929. * If the current MPDU is in the right order and nothing else
  930. * is stored we can process it directly, no need to buffer it.
  931. * If it is first but there's something stored, we may be able
  932. * to release frames after this one.
  933. */
  934. if (mpdu_seq_num == tid_agg_rx->head_seq_num &&
  935. tid_agg_rx->stored_mpdu_num == 0) {
  936. if (!(status->flag & RX_FLAG_AMSDU_MORE))
  937. tid_agg_rx->head_seq_num =
  938. ieee80211_sn_inc(tid_agg_rx->head_seq_num);
  939. ret = false;
  940. goto out;
  941. }
  942. /* put the frame in the reordering buffer */
  943. __skb_queue_tail(&tid_agg_rx->reorder_buf[index], skb);
  944. if (!(status->flag & RX_FLAG_AMSDU_MORE)) {
  945. tid_agg_rx->reorder_time[index] = jiffies;
  946. tid_agg_rx->stored_mpdu_num++;
  947. ieee80211_sta_reorder_release(sdata, tid_agg_rx, frames);
  948. }
  949. out:
  950. spin_unlock(&tid_agg_rx->reorder_lock);
  951. return ret;
  952. }
  953. /*
  954. * Reorder MPDUs from A-MPDUs, keeping them on a buffer. Returns
  955. * true if the MPDU was buffered, false if it should be processed.
  956. */
  957. static void ieee80211_rx_reorder_ampdu(struct ieee80211_rx_data *rx,
  958. struct sk_buff_head *frames)
  959. {
  960. struct sk_buff *skb = rx->skb;
  961. struct ieee80211_local *local = rx->local;
  962. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
  963. struct sta_info *sta = rx->sta;
  964. struct tid_ampdu_rx *tid_agg_rx;
  965. u16 sc;
  966. u8 tid, ack_policy;
  967. if (!ieee80211_is_data_qos(hdr->frame_control) ||
  968. is_multicast_ether_addr(hdr->addr1))
  969. goto dont_reorder;
  970. /*
  971. * filter the QoS data rx stream according to
  972. * STA/TID and check if this STA/TID is on aggregation
  973. */
  974. if (!sta)
  975. goto dont_reorder;
  976. ack_policy = *ieee80211_get_qos_ctl(hdr) &
  977. IEEE80211_QOS_CTL_ACK_POLICY_MASK;
  978. tid = *ieee80211_get_qos_ctl(hdr) & IEEE80211_QOS_CTL_TID_MASK;
  979. tid_agg_rx = rcu_dereference(sta->ampdu_mlme.tid_rx[tid]);
  980. if (!tid_agg_rx) {
  981. if (ack_policy == IEEE80211_QOS_CTL_ACK_POLICY_BLOCKACK &&
  982. !test_bit(tid, rx->sta->ampdu_mlme.agg_session_valid) &&
  983. !test_and_set_bit(tid, rx->sta->ampdu_mlme.unexpected_agg))
  984. ieee80211_send_delba(rx->sdata, rx->sta->sta.addr, tid,
  985. WLAN_BACK_RECIPIENT,
  986. WLAN_REASON_QSTA_REQUIRE_SETUP);
  987. goto dont_reorder;
  988. }
  989. /* qos null data frames are excluded */
  990. if (unlikely(hdr->frame_control & cpu_to_le16(IEEE80211_STYPE_NULLFUNC)))
  991. goto dont_reorder;
  992. /* not part of a BA session */
  993. if (ack_policy != IEEE80211_QOS_CTL_ACK_POLICY_BLOCKACK &&
  994. ack_policy != IEEE80211_QOS_CTL_ACK_POLICY_NORMAL)
  995. goto dont_reorder;
  996. /* new, potentially un-ordered, ampdu frame - process it */
  997. /* reset session timer */
  998. if (tid_agg_rx->timeout)
  999. tid_agg_rx->last_rx = jiffies;
  1000. /* if this mpdu is fragmented - terminate rx aggregation session */
  1001. sc = le16_to_cpu(hdr->seq_ctrl);
  1002. if (sc & IEEE80211_SCTL_FRAG) {
  1003. skb->pkt_type = IEEE80211_SDATA_QUEUE_TYPE_FRAME;
  1004. skb_queue_tail(&rx->sdata->skb_queue, skb);
  1005. ieee80211_queue_work(&local->hw, &rx->sdata->work);
  1006. return;
  1007. }
  1008. /*
  1009. * No locking needed -- we will only ever process one
  1010. * RX packet at a time, and thus own tid_agg_rx. All
  1011. * other code manipulating it needs to (and does) make
  1012. * sure that we cannot get to it any more before doing
  1013. * anything with it.
  1014. */
  1015. if (ieee80211_sta_manage_reorder_buf(rx->sdata, tid_agg_rx, skb,
  1016. frames))
  1017. return;
  1018. dont_reorder:
  1019. __skb_queue_tail(frames, skb);
  1020. }
  1021. static ieee80211_rx_result debug_noinline
  1022. ieee80211_rx_h_check_dup(struct ieee80211_rx_data *rx)
  1023. {
  1024. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
  1025. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
  1026. if (status->flag & RX_FLAG_DUP_VALIDATED)
  1027. return RX_CONTINUE;
  1028. /*
  1029. * Drop duplicate 802.11 retransmissions
  1030. * (IEEE 802.11-2012: 9.3.2.10 "Duplicate detection and recovery")
  1031. */
  1032. if (rx->skb->len < 24)
  1033. return RX_CONTINUE;
  1034. if (ieee80211_is_ctl(hdr->frame_control) ||
  1035. ieee80211_is_qos_nullfunc(hdr->frame_control) ||
  1036. is_multicast_ether_addr(hdr->addr1))
  1037. return RX_CONTINUE;
  1038. if (!rx->sta)
  1039. return RX_CONTINUE;
  1040. if (unlikely(ieee80211_has_retry(hdr->frame_control) &&
  1041. rx->sta->last_seq_ctrl[rx->seqno_idx] == hdr->seq_ctrl)) {
  1042. I802_DEBUG_INC(rx->local->dot11FrameDuplicateCount);
  1043. rx->sta->rx_stats.num_duplicates++;
  1044. return RX_DROP_UNUSABLE;
  1045. } else if (!(status->flag & RX_FLAG_AMSDU_MORE)) {
  1046. rx->sta->last_seq_ctrl[rx->seqno_idx] = hdr->seq_ctrl;
  1047. }
  1048. return RX_CONTINUE;
  1049. }
  1050. static ieee80211_rx_result debug_noinline
  1051. ieee80211_rx_h_check(struct ieee80211_rx_data *rx)
  1052. {
  1053. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
  1054. /* Drop disallowed frame classes based on STA auth/assoc state;
  1055. * IEEE 802.11, Chap 5.5.
  1056. *
  1057. * mac80211 filters only based on association state, i.e. it drops
  1058. * Class 3 frames from not associated stations. hostapd sends
  1059. * deauth/disassoc frames when needed. In addition, hostapd is
  1060. * responsible for filtering on both auth and assoc states.
  1061. */
  1062. if (ieee80211_vif_is_mesh(&rx->sdata->vif))
  1063. return ieee80211_rx_mesh_check(rx);
  1064. if (unlikely((ieee80211_is_data(hdr->frame_control) ||
  1065. ieee80211_is_pspoll(hdr->frame_control)) &&
  1066. rx->sdata->vif.type != NL80211_IFTYPE_ADHOC &&
  1067. rx->sdata->vif.type != NL80211_IFTYPE_WDS &&
  1068. rx->sdata->vif.type != NL80211_IFTYPE_OCB &&
  1069. (!rx->sta || !test_sta_flag(rx->sta, WLAN_STA_ASSOC)))) {
  1070. /*
  1071. * accept port control frames from the AP even when it's not
  1072. * yet marked ASSOC to prevent a race where we don't set the
  1073. * assoc bit quickly enough before it sends the first frame
  1074. */
  1075. if (rx->sta && rx->sdata->vif.type == NL80211_IFTYPE_STATION &&
  1076. ieee80211_is_data_present(hdr->frame_control)) {
  1077. unsigned int hdrlen;
  1078. __be16 ethertype;
  1079. hdrlen = ieee80211_hdrlen(hdr->frame_control);
  1080. if (rx->skb->len < hdrlen + 8)
  1081. return RX_DROP_MONITOR;
  1082. skb_copy_bits(rx->skb, hdrlen + 6, &ethertype, 2);
  1083. if (ethertype == rx->sdata->control_port_protocol)
  1084. return RX_CONTINUE;
  1085. }
  1086. if (rx->sdata->vif.type == NL80211_IFTYPE_AP &&
  1087. cfg80211_rx_spurious_frame(rx->sdata->dev,
  1088. hdr->addr2,
  1089. GFP_ATOMIC))
  1090. return RX_DROP_UNUSABLE;
  1091. return RX_DROP_MONITOR;
  1092. }
  1093. return RX_CONTINUE;
  1094. }
  1095. static ieee80211_rx_result debug_noinline
  1096. ieee80211_rx_h_check_more_data(struct ieee80211_rx_data *rx)
  1097. {
  1098. struct ieee80211_local *local;
  1099. struct ieee80211_hdr *hdr;
  1100. struct sk_buff *skb;
  1101. local = rx->local;
  1102. skb = rx->skb;
  1103. hdr = (struct ieee80211_hdr *) skb->data;
  1104. if (!local->pspolling)
  1105. return RX_CONTINUE;
  1106. if (!ieee80211_has_fromds(hdr->frame_control))
  1107. /* this is not from AP */
  1108. return RX_CONTINUE;
  1109. if (!ieee80211_is_data(hdr->frame_control))
  1110. return RX_CONTINUE;
  1111. if (!ieee80211_has_moredata(hdr->frame_control)) {
  1112. /* AP has no more frames buffered for us */
  1113. local->pspolling = false;
  1114. return RX_CONTINUE;
  1115. }
  1116. /* more data bit is set, let's request a new frame from the AP */
  1117. ieee80211_send_pspoll(local, rx->sdata);
  1118. return RX_CONTINUE;
  1119. }
  1120. static void sta_ps_start(struct sta_info *sta)
  1121. {
  1122. struct ieee80211_sub_if_data *sdata = sta->sdata;
  1123. struct ieee80211_local *local = sdata->local;
  1124. struct ps_data *ps;
  1125. int tid;
  1126. if (sta->sdata->vif.type == NL80211_IFTYPE_AP ||
  1127. sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
  1128. ps = &sdata->bss->ps;
  1129. else
  1130. return;
  1131. atomic_inc(&ps->num_sta_ps);
  1132. set_sta_flag(sta, WLAN_STA_PS_STA);
  1133. if (!ieee80211_hw_check(&local->hw, AP_LINK_PS))
  1134. drv_sta_notify(local, sdata, STA_NOTIFY_SLEEP, &sta->sta);
  1135. ps_dbg(sdata, "STA %pM aid %d enters power save mode\n",
  1136. sta->sta.addr, sta->sta.aid);
  1137. ieee80211_clear_fast_xmit(sta);
  1138. if (!sta->sta.txq[0])
  1139. return;
  1140. for (tid = 0; tid < ARRAY_SIZE(sta->sta.txq); tid++) {
  1141. if (txq_has_queue(sta->sta.txq[tid]))
  1142. set_bit(tid, &sta->txq_buffered_tids);
  1143. else
  1144. clear_bit(tid, &sta->txq_buffered_tids);
  1145. }
  1146. }
  1147. static void sta_ps_end(struct sta_info *sta)
  1148. {
  1149. ps_dbg(sta->sdata, "STA %pM aid %d exits power save mode\n",
  1150. sta->sta.addr, sta->sta.aid);
  1151. if (test_sta_flag(sta, WLAN_STA_PS_DRIVER)) {
  1152. /*
  1153. * Clear the flag only if the other one is still set
  1154. * so that the TX path won't start TX'ing new frames
  1155. * directly ... In the case that the driver flag isn't
  1156. * set ieee80211_sta_ps_deliver_wakeup() will clear it.
  1157. */
  1158. clear_sta_flag(sta, WLAN_STA_PS_STA);
  1159. ps_dbg(sta->sdata, "STA %pM aid %d driver-ps-blocked\n",
  1160. sta->sta.addr, sta->sta.aid);
  1161. return;
  1162. }
  1163. set_sta_flag(sta, WLAN_STA_PS_DELIVER);
  1164. clear_sta_flag(sta, WLAN_STA_PS_STA);
  1165. ieee80211_sta_ps_deliver_wakeup(sta);
  1166. }
  1167. int ieee80211_sta_ps_transition(struct ieee80211_sta *pubsta, bool start)
  1168. {
  1169. struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
  1170. bool in_ps;
  1171. WARN_ON(!ieee80211_hw_check(&sta->local->hw, AP_LINK_PS));
  1172. /* Don't let the same PS state be set twice */
  1173. in_ps = test_sta_flag(sta, WLAN_STA_PS_STA);
  1174. if ((start && in_ps) || (!start && !in_ps))
  1175. return -EINVAL;
  1176. if (start)
  1177. sta_ps_start(sta);
  1178. else
  1179. sta_ps_end(sta);
  1180. return 0;
  1181. }
  1182. EXPORT_SYMBOL(ieee80211_sta_ps_transition);
  1183. void ieee80211_sta_pspoll(struct ieee80211_sta *pubsta)
  1184. {
  1185. struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
  1186. if (test_sta_flag(sta, WLAN_STA_SP))
  1187. return;
  1188. if (!test_sta_flag(sta, WLAN_STA_PS_DRIVER))
  1189. ieee80211_sta_ps_deliver_poll_response(sta);
  1190. else
  1191. set_sta_flag(sta, WLAN_STA_PSPOLL);
  1192. }
  1193. EXPORT_SYMBOL(ieee80211_sta_pspoll);
  1194. void ieee80211_sta_uapsd_trigger(struct ieee80211_sta *pubsta, u8 tid)
  1195. {
  1196. struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
  1197. u8 ac = ieee802_1d_to_ac[tid & 7];
  1198. /*
  1199. * If this AC is not trigger-enabled do nothing.
  1200. *
  1201. * NB: This could/should check a separate bitmap of trigger-
  1202. * enabled queues, but for now we only implement uAPSD w/o
  1203. * TSPEC changes to the ACs, so they're always the same.
  1204. */
  1205. if (!(sta->sta.uapsd_queues & BIT(ac)))
  1206. return;
  1207. /* if we are in a service period, do nothing */
  1208. if (test_sta_flag(sta, WLAN_STA_SP))
  1209. return;
  1210. if (!test_sta_flag(sta, WLAN_STA_PS_DRIVER))
  1211. ieee80211_sta_ps_deliver_uapsd(sta);
  1212. else
  1213. set_sta_flag(sta, WLAN_STA_UAPSD);
  1214. }
  1215. EXPORT_SYMBOL(ieee80211_sta_uapsd_trigger);
  1216. static ieee80211_rx_result debug_noinline
  1217. ieee80211_rx_h_uapsd_and_pspoll(struct ieee80211_rx_data *rx)
  1218. {
  1219. struct ieee80211_sub_if_data *sdata = rx->sdata;
  1220. struct ieee80211_hdr *hdr = (void *)rx->skb->data;
  1221. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
  1222. if (!rx->sta)
  1223. return RX_CONTINUE;
  1224. if (sdata->vif.type != NL80211_IFTYPE_AP &&
  1225. sdata->vif.type != NL80211_IFTYPE_AP_VLAN)
  1226. return RX_CONTINUE;
  1227. /*
  1228. * The device handles station powersave, so don't do anything about
  1229. * uAPSD and PS-Poll frames (the latter shouldn't even come up from
  1230. * it to mac80211 since they're handled.)
  1231. */
  1232. if (ieee80211_hw_check(&sdata->local->hw, AP_LINK_PS))
  1233. return RX_CONTINUE;
  1234. /*
  1235. * Don't do anything if the station isn't already asleep. In
  1236. * the uAPSD case, the station will probably be marked asleep,
  1237. * in the PS-Poll case the station must be confused ...
  1238. */
  1239. if (!test_sta_flag(rx->sta, WLAN_STA_PS_STA))
  1240. return RX_CONTINUE;
  1241. if (unlikely(ieee80211_is_pspoll(hdr->frame_control))) {
  1242. ieee80211_sta_pspoll(&rx->sta->sta);
  1243. /* Free PS Poll skb here instead of returning RX_DROP that would
  1244. * count as an dropped frame. */
  1245. dev_kfree_skb(rx->skb);
  1246. return RX_QUEUED;
  1247. } else if (!ieee80211_has_morefrags(hdr->frame_control) &&
  1248. !(status->rx_flags & IEEE80211_RX_DEFERRED_RELEASE) &&
  1249. ieee80211_has_pm(hdr->frame_control) &&
  1250. (ieee80211_is_data_qos(hdr->frame_control) ||
  1251. ieee80211_is_qos_nullfunc(hdr->frame_control))) {
  1252. u8 tid;
  1253. tid = *ieee80211_get_qos_ctl(hdr) & IEEE80211_QOS_CTL_TID_MASK;
  1254. ieee80211_sta_uapsd_trigger(&rx->sta->sta, tid);
  1255. }
  1256. return RX_CONTINUE;
  1257. }
  1258. static ieee80211_rx_result debug_noinline
  1259. ieee80211_rx_h_sta_process(struct ieee80211_rx_data *rx)
  1260. {
  1261. struct sta_info *sta = rx->sta;
  1262. struct sk_buff *skb = rx->skb;
  1263. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
  1264. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
  1265. int i;
  1266. if (!sta)
  1267. return RX_CONTINUE;
  1268. /*
  1269. * Update last_rx only for IBSS packets which are for the current
  1270. * BSSID and for station already AUTHORIZED to avoid keeping the
  1271. * current IBSS network alive in cases where other STAs start
  1272. * using different BSSID. This will also give the station another
  1273. * chance to restart the authentication/authorization in case
  1274. * something went wrong the first time.
  1275. */
  1276. if (rx->sdata->vif.type == NL80211_IFTYPE_ADHOC) {
  1277. u8 *bssid = ieee80211_get_bssid(hdr, rx->skb->len,
  1278. NL80211_IFTYPE_ADHOC);
  1279. if (ether_addr_equal(bssid, rx->sdata->u.ibss.bssid) &&
  1280. test_sta_flag(sta, WLAN_STA_AUTHORIZED)) {
  1281. sta->rx_stats.last_rx = jiffies;
  1282. if (ieee80211_is_data(hdr->frame_control) &&
  1283. !is_multicast_ether_addr(hdr->addr1))
  1284. sta->rx_stats.last_rate =
  1285. sta_stats_encode_rate(status);
  1286. }
  1287. } else if (rx->sdata->vif.type == NL80211_IFTYPE_OCB) {
  1288. sta->rx_stats.last_rx = jiffies;
  1289. } else if (!is_multicast_ether_addr(hdr->addr1)) {
  1290. /*
  1291. * Mesh beacons will update last_rx when if they are found to
  1292. * match the current local configuration when processed.
  1293. */
  1294. sta->rx_stats.last_rx = jiffies;
  1295. if (ieee80211_is_data(hdr->frame_control))
  1296. sta->rx_stats.last_rate = sta_stats_encode_rate(status);
  1297. }
  1298. if (rx->sdata->vif.type == NL80211_IFTYPE_STATION)
  1299. ieee80211_sta_rx_notify(rx->sdata, hdr);
  1300. sta->rx_stats.fragments++;
  1301. u64_stats_update_begin(&rx->sta->rx_stats.syncp);
  1302. sta->rx_stats.bytes += rx->skb->len;
  1303. u64_stats_update_end(&rx->sta->rx_stats.syncp);
  1304. if (!(status->flag & RX_FLAG_NO_SIGNAL_VAL)) {
  1305. sta->rx_stats.last_signal = status->signal;
  1306. ewma_signal_add(&sta->rx_stats_avg.signal, -status->signal);
  1307. }
  1308. if (status->chains) {
  1309. sta->rx_stats.chains = status->chains;
  1310. for (i = 0; i < ARRAY_SIZE(status->chain_signal); i++) {
  1311. int signal = status->chain_signal[i];
  1312. if (!(status->chains & BIT(i)))
  1313. continue;
  1314. sta->rx_stats.chain_signal_last[i] = signal;
  1315. ewma_signal_add(&sta->rx_stats_avg.chain_signal[i],
  1316. -signal);
  1317. }
  1318. }
  1319. /*
  1320. * Change STA power saving mode only at the end of a frame
  1321. * exchange sequence.
  1322. */
  1323. if (!ieee80211_hw_check(&sta->local->hw, AP_LINK_PS) &&
  1324. !ieee80211_has_morefrags(hdr->frame_control) &&
  1325. !ieee80211_is_back_req(hdr->frame_control) &&
  1326. !(status->rx_flags & IEEE80211_RX_DEFERRED_RELEASE) &&
  1327. (rx->sdata->vif.type == NL80211_IFTYPE_AP ||
  1328. rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN) &&
  1329. /*
  1330. * PM bit is only checked in frames where it isn't reserved,
  1331. * in AP mode it's reserved in non-bufferable management frames
  1332. * (cf. IEEE 802.11-2012 8.2.4.1.7 Power Management field)
  1333. * BAR frames should be ignored as specified in
  1334. * IEEE 802.11-2012 10.2.1.2.
  1335. */
  1336. (!ieee80211_is_mgmt(hdr->frame_control) ||
  1337. ieee80211_is_bufferable_mmpdu(hdr->frame_control))) {
  1338. if (test_sta_flag(sta, WLAN_STA_PS_STA)) {
  1339. if (!ieee80211_has_pm(hdr->frame_control))
  1340. sta_ps_end(sta);
  1341. } else {
  1342. if (ieee80211_has_pm(hdr->frame_control))
  1343. sta_ps_start(sta);
  1344. }
  1345. }
  1346. /* mesh power save support */
  1347. if (ieee80211_vif_is_mesh(&rx->sdata->vif))
  1348. ieee80211_mps_rx_h_sta_process(sta, hdr);
  1349. /*
  1350. * Drop (qos-)data::nullfunc frames silently, since they
  1351. * are used only to control station power saving mode.
  1352. */
  1353. if (ieee80211_is_nullfunc(hdr->frame_control) ||
  1354. ieee80211_is_qos_nullfunc(hdr->frame_control)) {
  1355. I802_DEBUG_INC(rx->local->rx_handlers_drop_nullfunc);
  1356. /*
  1357. * If we receive a 4-addr nullfunc frame from a STA
  1358. * that was not moved to a 4-addr STA vlan yet send
  1359. * the event to userspace and for older hostapd drop
  1360. * the frame to the monitor interface.
  1361. */
  1362. if (ieee80211_has_a4(hdr->frame_control) &&
  1363. (rx->sdata->vif.type == NL80211_IFTYPE_AP ||
  1364. (rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
  1365. !rx->sdata->u.vlan.sta))) {
  1366. if (!test_and_set_sta_flag(sta, WLAN_STA_4ADDR_EVENT))
  1367. cfg80211_rx_unexpected_4addr_frame(
  1368. rx->sdata->dev, sta->sta.addr,
  1369. GFP_ATOMIC);
  1370. return RX_DROP_MONITOR;
  1371. }
  1372. /*
  1373. * Update counter and free packet here to avoid
  1374. * counting this as a dropped packed.
  1375. */
  1376. sta->rx_stats.packets++;
  1377. dev_kfree_skb(rx->skb);
  1378. return RX_QUEUED;
  1379. }
  1380. return RX_CONTINUE;
  1381. } /* ieee80211_rx_h_sta_process */
  1382. static ieee80211_rx_result debug_noinline
  1383. ieee80211_rx_h_decrypt(struct ieee80211_rx_data *rx)
  1384. {
  1385. struct sk_buff *skb = rx->skb;
  1386. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
  1387. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
  1388. int keyidx;
  1389. int hdrlen;
  1390. ieee80211_rx_result result = RX_DROP_UNUSABLE;
  1391. struct ieee80211_key *sta_ptk = NULL;
  1392. int mmie_keyidx = -1;
  1393. __le16 fc;
  1394. const struct ieee80211_cipher_scheme *cs = NULL;
  1395. /*
  1396. * Key selection 101
  1397. *
  1398. * There are four types of keys:
  1399. * - GTK (group keys)
  1400. * - IGTK (group keys for management frames)
  1401. * - PTK (pairwise keys)
  1402. * - STK (station-to-station pairwise keys)
  1403. *
  1404. * When selecting a key, we have to distinguish between multicast
  1405. * (including broadcast) and unicast frames, the latter can only
  1406. * use PTKs and STKs while the former always use GTKs and IGTKs.
  1407. * Unless, of course, actual WEP keys ("pre-RSNA") are used, then
  1408. * unicast frames can also use key indices like GTKs. Hence, if we
  1409. * don't have a PTK/STK we check the key index for a WEP key.
  1410. *
  1411. * Note that in a regular BSS, multicast frames are sent by the
  1412. * AP only, associated stations unicast the frame to the AP first
  1413. * which then multicasts it on their behalf.
  1414. *
  1415. * There is also a slight problem in IBSS mode: GTKs are negotiated
  1416. * with each station, that is something we don't currently handle.
  1417. * The spec seems to expect that one negotiates the same key with
  1418. * every station but there's no such requirement; VLANs could be
  1419. * possible.
  1420. */
  1421. /* start without a key */
  1422. rx->key = NULL;
  1423. fc = hdr->frame_control;
  1424. if (rx->sta) {
  1425. int keyid = rx->sta->ptk_idx;
  1426. if (ieee80211_has_protected(fc) && rx->sta->cipher_scheme) {
  1427. cs = rx->sta->cipher_scheme;
  1428. keyid = ieee80211_get_cs_keyid(cs, rx->skb);
  1429. if (unlikely(keyid < 0))
  1430. return RX_DROP_UNUSABLE;
  1431. }
  1432. sta_ptk = rcu_dereference(rx->sta->ptk[keyid]);
  1433. }
  1434. if (!ieee80211_has_protected(fc))
  1435. mmie_keyidx = ieee80211_get_mmie_keyidx(rx->skb);
  1436. if (!is_multicast_ether_addr(hdr->addr1) && sta_ptk) {
  1437. rx->key = sta_ptk;
  1438. if ((status->flag & RX_FLAG_DECRYPTED) &&
  1439. (status->flag & RX_FLAG_IV_STRIPPED))
  1440. return RX_CONTINUE;
  1441. /* Skip decryption if the frame is not protected. */
  1442. if (!ieee80211_has_protected(fc))
  1443. return RX_CONTINUE;
  1444. } else if (mmie_keyidx >= 0) {
  1445. /* Broadcast/multicast robust management frame / BIP */
  1446. if ((status->flag & RX_FLAG_DECRYPTED) &&
  1447. (status->flag & RX_FLAG_IV_STRIPPED))
  1448. return RX_CONTINUE;
  1449. if (mmie_keyidx < NUM_DEFAULT_KEYS ||
  1450. mmie_keyidx >= NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS)
  1451. return RX_DROP_MONITOR; /* unexpected BIP keyidx */
  1452. if (rx->sta) {
  1453. if (ieee80211_is_group_privacy_action(skb) &&
  1454. test_sta_flag(rx->sta, WLAN_STA_MFP))
  1455. return RX_DROP_MONITOR;
  1456. rx->key = rcu_dereference(rx->sta->gtk[mmie_keyidx]);
  1457. }
  1458. if (!rx->key)
  1459. rx->key = rcu_dereference(rx->sdata->keys[mmie_keyidx]);
  1460. } else if (!ieee80211_has_protected(fc)) {
  1461. /*
  1462. * The frame was not protected, so skip decryption. However, we
  1463. * need to set rx->key if there is a key that could have been
  1464. * used so that the frame may be dropped if encryption would
  1465. * have been expected.
  1466. */
  1467. struct ieee80211_key *key = NULL;
  1468. struct ieee80211_sub_if_data *sdata = rx->sdata;
  1469. int i;
  1470. if (ieee80211_is_mgmt(fc) &&
  1471. is_multicast_ether_addr(hdr->addr1) &&
  1472. (key = rcu_dereference(rx->sdata->default_mgmt_key)))
  1473. rx->key = key;
  1474. else {
  1475. if (rx->sta) {
  1476. for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
  1477. key = rcu_dereference(rx->sta->gtk[i]);
  1478. if (key)
  1479. break;
  1480. }
  1481. }
  1482. if (!key) {
  1483. for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
  1484. key = rcu_dereference(sdata->keys[i]);
  1485. if (key)
  1486. break;
  1487. }
  1488. }
  1489. if (key)
  1490. rx->key = key;
  1491. }
  1492. return RX_CONTINUE;
  1493. } else {
  1494. u8 keyid;
  1495. /*
  1496. * The device doesn't give us the IV so we won't be
  1497. * able to look up the key. That's ok though, we
  1498. * don't need to decrypt the frame, we just won't
  1499. * be able to keep statistics accurate.
  1500. * Except for key threshold notifications, should
  1501. * we somehow allow the driver to tell us which key
  1502. * the hardware used if this flag is set?
  1503. */
  1504. if ((status->flag & RX_FLAG_DECRYPTED) &&
  1505. (status->flag & RX_FLAG_IV_STRIPPED))
  1506. return RX_CONTINUE;
  1507. hdrlen = ieee80211_hdrlen(fc);
  1508. if (cs) {
  1509. keyidx = ieee80211_get_cs_keyid(cs, rx->skb);
  1510. if (unlikely(keyidx < 0))
  1511. return RX_DROP_UNUSABLE;
  1512. } else {
  1513. if (rx->skb->len < 8 + hdrlen)
  1514. return RX_DROP_UNUSABLE; /* TODO: count this? */
  1515. /*
  1516. * no need to call ieee80211_wep_get_keyidx,
  1517. * it verifies a bunch of things we've done already
  1518. */
  1519. skb_copy_bits(rx->skb, hdrlen + 3, &keyid, 1);
  1520. keyidx = keyid >> 6;
  1521. }
  1522. /* check per-station GTK first, if multicast packet */
  1523. if (is_multicast_ether_addr(hdr->addr1) && rx->sta)
  1524. rx->key = rcu_dereference(rx->sta->gtk[keyidx]);
  1525. /* if not found, try default key */
  1526. if (!rx->key) {
  1527. rx->key = rcu_dereference(rx->sdata->keys[keyidx]);
  1528. /*
  1529. * RSNA-protected unicast frames should always be
  1530. * sent with pairwise or station-to-station keys,
  1531. * but for WEP we allow using a key index as well.
  1532. */
  1533. if (rx->key &&
  1534. rx->key->conf.cipher != WLAN_CIPHER_SUITE_WEP40 &&
  1535. rx->key->conf.cipher != WLAN_CIPHER_SUITE_WEP104 &&
  1536. !is_multicast_ether_addr(hdr->addr1))
  1537. rx->key = NULL;
  1538. }
  1539. }
  1540. if (rx->key) {
  1541. if (unlikely(rx->key->flags & KEY_FLAG_TAINTED))
  1542. return RX_DROP_MONITOR;
  1543. /* TODO: add threshold stuff again */
  1544. } else {
  1545. return RX_DROP_MONITOR;
  1546. }
  1547. switch (rx->key->conf.cipher) {
  1548. case WLAN_CIPHER_SUITE_WEP40:
  1549. case WLAN_CIPHER_SUITE_WEP104:
  1550. result = ieee80211_crypto_wep_decrypt(rx);
  1551. break;
  1552. case WLAN_CIPHER_SUITE_TKIP:
  1553. result = ieee80211_crypto_tkip_decrypt(rx);
  1554. break;
  1555. case WLAN_CIPHER_SUITE_CCMP:
  1556. result = ieee80211_crypto_ccmp_decrypt(
  1557. rx, IEEE80211_CCMP_MIC_LEN);
  1558. break;
  1559. case WLAN_CIPHER_SUITE_CCMP_256:
  1560. result = ieee80211_crypto_ccmp_decrypt(
  1561. rx, IEEE80211_CCMP_256_MIC_LEN);
  1562. break;
  1563. case WLAN_CIPHER_SUITE_AES_CMAC:
  1564. result = ieee80211_crypto_aes_cmac_decrypt(rx);
  1565. break;
  1566. case WLAN_CIPHER_SUITE_BIP_CMAC_256:
  1567. result = ieee80211_crypto_aes_cmac_256_decrypt(rx);
  1568. break;
  1569. case WLAN_CIPHER_SUITE_BIP_GMAC_128:
  1570. case WLAN_CIPHER_SUITE_BIP_GMAC_256:
  1571. result = ieee80211_crypto_aes_gmac_decrypt(rx);
  1572. break;
  1573. case WLAN_CIPHER_SUITE_GCMP:
  1574. case WLAN_CIPHER_SUITE_GCMP_256:
  1575. result = ieee80211_crypto_gcmp_decrypt(rx);
  1576. break;
  1577. default:
  1578. result = ieee80211_crypto_hw_decrypt(rx);
  1579. }
  1580. /* the hdr variable is invalid after the decrypt handlers */
  1581. /* either the frame has been decrypted or will be dropped */
  1582. status->flag |= RX_FLAG_DECRYPTED;
  1583. return result;
  1584. }
  1585. static inline struct ieee80211_fragment_entry *
  1586. ieee80211_reassemble_add(struct ieee80211_sub_if_data *sdata,
  1587. unsigned int frag, unsigned int seq, int rx_queue,
  1588. struct sk_buff **skb)
  1589. {
  1590. struct ieee80211_fragment_entry *entry;
  1591. entry = &sdata->fragments[sdata->fragment_next++];
  1592. if (sdata->fragment_next >= IEEE80211_FRAGMENT_MAX)
  1593. sdata->fragment_next = 0;
  1594. if (!skb_queue_empty(&entry->skb_list))
  1595. __skb_queue_purge(&entry->skb_list);
  1596. __skb_queue_tail(&entry->skb_list, *skb); /* no need for locking */
  1597. *skb = NULL;
  1598. entry->first_frag_time = jiffies;
  1599. entry->seq = seq;
  1600. entry->rx_queue = rx_queue;
  1601. entry->last_frag = frag;
  1602. entry->check_sequential_pn = false;
  1603. entry->extra_len = 0;
  1604. return entry;
  1605. }
  1606. static inline struct ieee80211_fragment_entry *
  1607. ieee80211_reassemble_find(struct ieee80211_sub_if_data *sdata,
  1608. unsigned int frag, unsigned int seq,
  1609. int rx_queue, struct ieee80211_hdr *hdr)
  1610. {
  1611. struct ieee80211_fragment_entry *entry;
  1612. int i, idx;
  1613. idx = sdata->fragment_next;
  1614. for (i = 0; i < IEEE80211_FRAGMENT_MAX; i++) {
  1615. struct ieee80211_hdr *f_hdr;
  1616. idx--;
  1617. if (idx < 0)
  1618. idx = IEEE80211_FRAGMENT_MAX - 1;
  1619. entry = &sdata->fragments[idx];
  1620. if (skb_queue_empty(&entry->skb_list) || entry->seq != seq ||
  1621. entry->rx_queue != rx_queue ||
  1622. entry->last_frag + 1 != frag)
  1623. continue;
  1624. f_hdr = (struct ieee80211_hdr *)entry->skb_list.next->data;
  1625. /*
  1626. * Check ftype and addresses are equal, else check next fragment
  1627. */
  1628. if (((hdr->frame_control ^ f_hdr->frame_control) &
  1629. cpu_to_le16(IEEE80211_FCTL_FTYPE)) ||
  1630. !ether_addr_equal(hdr->addr1, f_hdr->addr1) ||
  1631. !ether_addr_equal(hdr->addr2, f_hdr->addr2))
  1632. continue;
  1633. if (time_after(jiffies, entry->first_frag_time + 2 * HZ)) {
  1634. __skb_queue_purge(&entry->skb_list);
  1635. continue;
  1636. }
  1637. return entry;
  1638. }
  1639. return NULL;
  1640. }
  1641. static ieee80211_rx_result debug_noinline
  1642. ieee80211_rx_h_defragment(struct ieee80211_rx_data *rx)
  1643. {
  1644. struct ieee80211_hdr *hdr;
  1645. u16 sc;
  1646. __le16 fc;
  1647. unsigned int frag, seq;
  1648. struct ieee80211_fragment_entry *entry;
  1649. struct sk_buff *skb;
  1650. struct ieee80211_rx_status *status;
  1651. hdr = (struct ieee80211_hdr *)rx->skb->data;
  1652. fc = hdr->frame_control;
  1653. if (ieee80211_is_ctl(fc))
  1654. return RX_CONTINUE;
  1655. sc = le16_to_cpu(hdr->seq_ctrl);
  1656. frag = sc & IEEE80211_SCTL_FRAG;
  1657. if (is_multicast_ether_addr(hdr->addr1)) {
  1658. I802_DEBUG_INC(rx->local->dot11MulticastReceivedFrameCount);
  1659. goto out_no_led;
  1660. }
  1661. if (likely(!ieee80211_has_morefrags(fc) && frag == 0))
  1662. goto out;
  1663. I802_DEBUG_INC(rx->local->rx_handlers_fragments);
  1664. if (skb_linearize(rx->skb))
  1665. return RX_DROP_UNUSABLE;
  1666. /*
  1667. * skb_linearize() might change the skb->data and
  1668. * previously cached variables (in this case, hdr) need to
  1669. * be refreshed with the new data.
  1670. */
  1671. hdr = (struct ieee80211_hdr *)rx->skb->data;
  1672. seq = (sc & IEEE80211_SCTL_SEQ) >> 4;
  1673. if (frag == 0) {
  1674. /* This is the first fragment of a new frame. */
  1675. entry = ieee80211_reassemble_add(rx->sdata, frag, seq,
  1676. rx->seqno_idx, &(rx->skb));
  1677. if (rx->key &&
  1678. (rx->key->conf.cipher == WLAN_CIPHER_SUITE_CCMP ||
  1679. rx->key->conf.cipher == WLAN_CIPHER_SUITE_CCMP_256 ||
  1680. rx->key->conf.cipher == WLAN_CIPHER_SUITE_GCMP ||
  1681. rx->key->conf.cipher == WLAN_CIPHER_SUITE_GCMP_256) &&
  1682. ieee80211_has_protected(fc)) {
  1683. int queue = rx->security_idx;
  1684. /* Store CCMP/GCMP PN so that we can verify that the
  1685. * next fragment has a sequential PN value.
  1686. */
  1687. entry->check_sequential_pn = true;
  1688. memcpy(entry->last_pn,
  1689. rx->key->u.ccmp.rx_pn[queue],
  1690. IEEE80211_CCMP_PN_LEN);
  1691. BUILD_BUG_ON(offsetof(struct ieee80211_key,
  1692. u.ccmp.rx_pn) !=
  1693. offsetof(struct ieee80211_key,
  1694. u.gcmp.rx_pn));
  1695. BUILD_BUG_ON(sizeof(rx->key->u.ccmp.rx_pn[queue]) !=
  1696. sizeof(rx->key->u.gcmp.rx_pn[queue]));
  1697. BUILD_BUG_ON(IEEE80211_CCMP_PN_LEN !=
  1698. IEEE80211_GCMP_PN_LEN);
  1699. }
  1700. return RX_QUEUED;
  1701. }
  1702. /* This is a fragment for a frame that should already be pending in
  1703. * fragment cache. Add this fragment to the end of the pending entry.
  1704. */
  1705. entry = ieee80211_reassemble_find(rx->sdata, frag, seq,
  1706. rx->seqno_idx, hdr);
  1707. if (!entry) {
  1708. I802_DEBUG_INC(rx->local->rx_handlers_drop_defrag);
  1709. return RX_DROP_MONITOR;
  1710. }
  1711. /* "The receiver shall discard MSDUs and MMPDUs whose constituent
  1712. * MPDU PN values are not incrementing in steps of 1."
  1713. * see IEEE P802.11-REVmc/D5.0, 12.5.3.4.4, item d (for CCMP)
  1714. * and IEEE P802.11-REVmc/D5.0, 12.5.5.4.4, item d (for GCMP)
  1715. */
  1716. if (entry->check_sequential_pn) {
  1717. int i;
  1718. u8 pn[IEEE80211_CCMP_PN_LEN], *rpn;
  1719. int queue;
  1720. if (!rx->key ||
  1721. (rx->key->conf.cipher != WLAN_CIPHER_SUITE_CCMP &&
  1722. rx->key->conf.cipher != WLAN_CIPHER_SUITE_CCMP_256 &&
  1723. rx->key->conf.cipher != WLAN_CIPHER_SUITE_GCMP &&
  1724. rx->key->conf.cipher != WLAN_CIPHER_SUITE_GCMP_256))
  1725. return RX_DROP_UNUSABLE;
  1726. memcpy(pn, entry->last_pn, IEEE80211_CCMP_PN_LEN);
  1727. for (i = IEEE80211_CCMP_PN_LEN - 1; i >= 0; i--) {
  1728. pn[i]++;
  1729. if (pn[i])
  1730. break;
  1731. }
  1732. queue = rx->security_idx;
  1733. rpn = rx->key->u.ccmp.rx_pn[queue];
  1734. if (memcmp(pn, rpn, IEEE80211_CCMP_PN_LEN))
  1735. return RX_DROP_UNUSABLE;
  1736. memcpy(entry->last_pn, pn, IEEE80211_CCMP_PN_LEN);
  1737. }
  1738. skb_pull(rx->skb, ieee80211_hdrlen(fc));
  1739. __skb_queue_tail(&entry->skb_list, rx->skb);
  1740. entry->last_frag = frag;
  1741. entry->extra_len += rx->skb->len;
  1742. if (ieee80211_has_morefrags(fc)) {
  1743. rx->skb = NULL;
  1744. return RX_QUEUED;
  1745. }
  1746. rx->skb = __skb_dequeue(&entry->skb_list);
  1747. if (skb_tailroom(rx->skb) < entry->extra_len) {
  1748. I802_DEBUG_INC(rx->local->rx_expand_skb_head_defrag);
  1749. if (unlikely(pskb_expand_head(rx->skb, 0, entry->extra_len,
  1750. GFP_ATOMIC))) {
  1751. I802_DEBUG_INC(rx->local->rx_handlers_drop_defrag);
  1752. __skb_queue_purge(&entry->skb_list);
  1753. return RX_DROP_UNUSABLE;
  1754. }
  1755. }
  1756. while ((skb = __skb_dequeue(&entry->skb_list))) {
  1757. memcpy(skb_put(rx->skb, skb->len), skb->data, skb->len);
  1758. dev_kfree_skb(skb);
  1759. }
  1760. /* Complete frame has been reassembled - process it now */
  1761. status = IEEE80211_SKB_RXCB(rx->skb);
  1762. out:
  1763. ieee80211_led_rx(rx->local);
  1764. out_no_led:
  1765. if (rx->sta)
  1766. rx->sta->rx_stats.packets++;
  1767. return RX_CONTINUE;
  1768. }
  1769. static int ieee80211_802_1x_port_control(struct ieee80211_rx_data *rx)
  1770. {
  1771. if (unlikely(!rx->sta || !test_sta_flag(rx->sta, WLAN_STA_AUTHORIZED)))
  1772. return -EACCES;
  1773. return 0;
  1774. }
  1775. static int ieee80211_drop_unencrypted(struct ieee80211_rx_data *rx, __le16 fc)
  1776. {
  1777. struct sk_buff *skb = rx->skb;
  1778. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
  1779. /*
  1780. * Pass through unencrypted frames if the hardware has
  1781. * decrypted them already.
  1782. */
  1783. if (status->flag & RX_FLAG_DECRYPTED)
  1784. return 0;
  1785. /* Drop unencrypted frames if key is set. */
  1786. if (unlikely(!ieee80211_has_protected(fc) &&
  1787. !ieee80211_is_nullfunc(fc) &&
  1788. ieee80211_is_data(fc) && rx->key))
  1789. return -EACCES;
  1790. return 0;
  1791. }
  1792. static int ieee80211_drop_unencrypted_mgmt(struct ieee80211_rx_data *rx)
  1793. {
  1794. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
  1795. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
  1796. __le16 fc = hdr->frame_control;
  1797. /*
  1798. * Pass through unencrypted frames if the hardware has
  1799. * decrypted them already.
  1800. */
  1801. if (status->flag & RX_FLAG_DECRYPTED)
  1802. return 0;
  1803. if (rx->sta && test_sta_flag(rx->sta, WLAN_STA_MFP)) {
  1804. if (unlikely(!ieee80211_has_protected(fc) &&
  1805. ieee80211_is_unicast_robust_mgmt_frame(rx->skb) &&
  1806. rx->key)) {
  1807. if (ieee80211_is_deauth(fc) ||
  1808. ieee80211_is_disassoc(fc))
  1809. cfg80211_rx_unprot_mlme_mgmt(rx->sdata->dev,
  1810. rx->skb->data,
  1811. rx->skb->len);
  1812. return -EACCES;
  1813. }
  1814. /* BIP does not use Protected field, so need to check MMIE */
  1815. if (unlikely(ieee80211_is_multicast_robust_mgmt_frame(rx->skb) &&
  1816. ieee80211_get_mmie_keyidx(rx->skb) < 0)) {
  1817. if (ieee80211_is_deauth(fc) ||
  1818. ieee80211_is_disassoc(fc))
  1819. cfg80211_rx_unprot_mlme_mgmt(rx->sdata->dev,
  1820. rx->skb->data,
  1821. rx->skb->len);
  1822. return -EACCES;
  1823. }
  1824. /*
  1825. * When using MFP, Action frames are not allowed prior to
  1826. * having configured keys.
  1827. */
  1828. if (unlikely(ieee80211_is_action(fc) && !rx->key &&
  1829. ieee80211_is_robust_mgmt_frame(rx->skb)))
  1830. return -EACCES;
  1831. }
  1832. return 0;
  1833. }
  1834. static int
  1835. __ieee80211_data_to_8023(struct ieee80211_rx_data *rx, bool *port_control)
  1836. {
  1837. struct ieee80211_sub_if_data *sdata = rx->sdata;
  1838. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
  1839. bool check_port_control = false;
  1840. struct ethhdr *ehdr;
  1841. int ret;
  1842. *port_control = false;
  1843. if (ieee80211_has_a4(hdr->frame_control) &&
  1844. sdata->vif.type == NL80211_IFTYPE_AP_VLAN && !sdata->u.vlan.sta)
  1845. return -1;
  1846. if (sdata->vif.type == NL80211_IFTYPE_STATION &&
  1847. !!sdata->u.mgd.use_4addr != !!ieee80211_has_a4(hdr->frame_control)) {
  1848. if (!sdata->u.mgd.use_4addr)
  1849. return -1;
  1850. else
  1851. check_port_control = true;
  1852. }
  1853. if (is_multicast_ether_addr(hdr->addr1) &&
  1854. sdata->vif.type == NL80211_IFTYPE_AP_VLAN && sdata->u.vlan.sta)
  1855. return -1;
  1856. ret = ieee80211_data_to_8023(rx->skb, sdata->vif.addr, sdata->vif.type);
  1857. if (ret < 0)
  1858. return ret;
  1859. ehdr = (struct ethhdr *) rx->skb->data;
  1860. if (ehdr->h_proto == rx->sdata->control_port_protocol)
  1861. *port_control = true;
  1862. else if (check_port_control)
  1863. return -1;
  1864. return 0;
  1865. }
  1866. /*
  1867. * requires that rx->skb is a frame with ethernet header
  1868. */
  1869. static bool ieee80211_frame_allowed(struct ieee80211_rx_data *rx, __le16 fc)
  1870. {
  1871. static const u8 pae_group_addr[ETH_ALEN] __aligned(2)
  1872. = { 0x01, 0x80, 0xC2, 0x00, 0x00, 0x03 };
  1873. struct ethhdr *ehdr = (struct ethhdr *) rx->skb->data;
  1874. /*
  1875. * Allow EAPOL frames to us/the PAE group address regardless
  1876. * of whether the frame was encrypted or not.
  1877. */
  1878. if (ehdr->h_proto == rx->sdata->control_port_protocol &&
  1879. (ether_addr_equal(ehdr->h_dest, rx->sdata->vif.addr) ||
  1880. ether_addr_equal(ehdr->h_dest, pae_group_addr)))
  1881. return true;
  1882. if (ieee80211_802_1x_port_control(rx) ||
  1883. ieee80211_drop_unencrypted(rx, fc))
  1884. return false;
  1885. return true;
  1886. }
  1887. /*
  1888. * requires that rx->skb is a frame with ethernet header
  1889. */
  1890. static void
  1891. ieee80211_deliver_skb(struct ieee80211_rx_data *rx)
  1892. {
  1893. struct ieee80211_sub_if_data *sdata = rx->sdata;
  1894. struct net_device *dev = sdata->dev;
  1895. struct sk_buff *skb, *xmit_skb;
  1896. struct ethhdr *ehdr = (struct ethhdr *) rx->skb->data;
  1897. struct sta_info *dsta;
  1898. skb = rx->skb;
  1899. xmit_skb = NULL;
  1900. ieee80211_rx_stats(dev, skb->len);
  1901. if (rx->sta) {
  1902. /* The seqno index has the same property as needed
  1903. * for the rx_msdu field, i.e. it is IEEE80211_NUM_TIDS
  1904. * for non-QoS-data frames. Here we know it's a data
  1905. * frame, so count MSDUs.
  1906. */
  1907. u64_stats_update_begin(&rx->sta->rx_stats.syncp);
  1908. rx->sta->rx_stats.msdu[rx->seqno_idx]++;
  1909. u64_stats_update_end(&rx->sta->rx_stats.syncp);
  1910. }
  1911. if ((sdata->vif.type == NL80211_IFTYPE_AP ||
  1912. sdata->vif.type == NL80211_IFTYPE_AP_VLAN) &&
  1913. !(sdata->flags & IEEE80211_SDATA_DONT_BRIDGE_PACKETS) &&
  1914. (sdata->vif.type != NL80211_IFTYPE_AP_VLAN || !sdata->u.vlan.sta)) {
  1915. if (is_multicast_ether_addr(ehdr->h_dest)) {
  1916. /*
  1917. * send multicast frames both to higher layers in
  1918. * local net stack and back to the wireless medium
  1919. */
  1920. xmit_skb = skb_copy(skb, GFP_ATOMIC);
  1921. if (!xmit_skb)
  1922. net_info_ratelimited("%s: failed to clone multicast frame\n",
  1923. dev->name);
  1924. } else {
  1925. dsta = sta_info_get(sdata, skb->data);
  1926. if (dsta) {
  1927. /*
  1928. * The destination station is associated to
  1929. * this AP (in this VLAN), so send the frame
  1930. * directly to it and do not pass it to local
  1931. * net stack.
  1932. */
  1933. xmit_skb = skb;
  1934. skb = NULL;
  1935. }
  1936. }
  1937. }
  1938. #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
  1939. if (skb) {
  1940. /* 'align' will only take the values 0 or 2 here since all
  1941. * frames are required to be aligned to 2-byte boundaries
  1942. * when being passed to mac80211; the code here works just
  1943. * as well if that isn't true, but mac80211 assumes it can
  1944. * access fields as 2-byte aligned (e.g. for ether_addr_equal)
  1945. */
  1946. int align;
  1947. align = (unsigned long)(skb->data + sizeof(struct ethhdr)) & 3;
  1948. if (align) {
  1949. if (WARN_ON(skb_headroom(skb) < 3)) {
  1950. dev_kfree_skb(skb);
  1951. skb = NULL;
  1952. } else {
  1953. u8 *data = skb->data;
  1954. size_t len = skb_headlen(skb);
  1955. skb->data -= align;
  1956. memmove(skb->data, data, len);
  1957. skb_set_tail_pointer(skb, len);
  1958. }
  1959. }
  1960. }
  1961. #endif
  1962. if (skb) {
  1963. /* deliver to local stack */
  1964. skb->protocol = eth_type_trans(skb, dev);
  1965. memset(skb->cb, 0, sizeof(skb->cb));
  1966. if (rx->napi)
  1967. napi_gro_receive(rx->napi, skb);
  1968. else
  1969. netif_receive_skb(skb);
  1970. }
  1971. if (xmit_skb) {
  1972. /*
  1973. * Send to wireless media and increase priority by 256 to
  1974. * keep the received priority instead of reclassifying
  1975. * the frame (see cfg80211_classify8021d).
  1976. */
  1977. xmit_skb->priority += 256;
  1978. xmit_skb->protocol = htons(ETH_P_802_3);
  1979. skb_reset_network_header(xmit_skb);
  1980. skb_reset_mac_header(xmit_skb);
  1981. dev_queue_xmit(xmit_skb);
  1982. }
  1983. }
  1984. static ieee80211_rx_result debug_noinline
  1985. ieee80211_rx_h_amsdu(struct ieee80211_rx_data *rx)
  1986. {
  1987. struct net_device *dev = rx->sdata->dev;
  1988. struct sk_buff *skb = rx->skb;
  1989. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
  1990. __le16 fc = hdr->frame_control;
  1991. struct sk_buff_head frame_list;
  1992. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
  1993. struct ethhdr ethhdr;
  1994. const u8 *check_da = ethhdr.h_dest, *check_sa = ethhdr.h_source;
  1995. if (unlikely(!ieee80211_is_data(fc)))
  1996. return RX_CONTINUE;
  1997. if (unlikely(!ieee80211_is_data_present(fc)))
  1998. return RX_DROP_MONITOR;
  1999. if (!(status->rx_flags & IEEE80211_RX_AMSDU))
  2000. return RX_CONTINUE;
  2001. if (unlikely(ieee80211_has_a4(hdr->frame_control))) {
  2002. switch (rx->sdata->vif.type) {
  2003. case NL80211_IFTYPE_AP_VLAN:
  2004. if (!rx->sdata->u.vlan.sta)
  2005. return RX_DROP_UNUSABLE;
  2006. break;
  2007. case NL80211_IFTYPE_STATION:
  2008. if (!rx->sdata->u.mgd.use_4addr)
  2009. return RX_DROP_UNUSABLE;
  2010. break;
  2011. default:
  2012. return RX_DROP_UNUSABLE;
  2013. }
  2014. check_da = NULL;
  2015. check_sa = NULL;
  2016. } else switch (rx->sdata->vif.type) {
  2017. case NL80211_IFTYPE_AP:
  2018. case NL80211_IFTYPE_AP_VLAN:
  2019. check_da = NULL;
  2020. break;
  2021. case NL80211_IFTYPE_STATION:
  2022. if (!rx->sta ||
  2023. !test_sta_flag(rx->sta, WLAN_STA_TDLS_PEER))
  2024. check_sa = NULL;
  2025. break;
  2026. case NL80211_IFTYPE_MESH_POINT:
  2027. check_sa = NULL;
  2028. break;
  2029. default:
  2030. break;
  2031. }
  2032. if (is_multicast_ether_addr(hdr->addr1))
  2033. return RX_DROP_UNUSABLE;
  2034. skb->dev = dev;
  2035. __skb_queue_head_init(&frame_list);
  2036. if (ieee80211_data_to_8023_exthdr(skb, &ethhdr,
  2037. rx->sdata->vif.addr,
  2038. rx->sdata->vif.type))
  2039. return RX_DROP_UNUSABLE;
  2040. ieee80211_amsdu_to_8023s(skb, &frame_list, dev->dev_addr,
  2041. rx->sdata->vif.type,
  2042. rx->local->hw.extra_tx_headroom,
  2043. check_da, check_sa);
  2044. while (!skb_queue_empty(&frame_list)) {
  2045. rx->skb = __skb_dequeue(&frame_list);
  2046. if (!ieee80211_frame_allowed(rx, fc)) {
  2047. dev_kfree_skb(rx->skb);
  2048. continue;
  2049. }
  2050. ieee80211_deliver_skb(rx);
  2051. }
  2052. return RX_QUEUED;
  2053. }
  2054. #ifdef CONFIG_MAC80211_MESH
  2055. static ieee80211_rx_result
  2056. ieee80211_rx_h_mesh_fwding(struct ieee80211_rx_data *rx)
  2057. {
  2058. struct ieee80211_hdr *fwd_hdr, *hdr;
  2059. struct ieee80211_tx_info *info;
  2060. struct ieee80211s_hdr *mesh_hdr;
  2061. struct sk_buff *skb = rx->skb, *fwd_skb;
  2062. struct ieee80211_local *local = rx->local;
  2063. struct ieee80211_sub_if_data *sdata = rx->sdata;
  2064. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  2065. u16 ac, q, hdrlen;
  2066. hdr = (struct ieee80211_hdr *) skb->data;
  2067. hdrlen = ieee80211_hdrlen(hdr->frame_control);
  2068. /* make sure fixed part of mesh header is there, also checks skb len */
  2069. if (!pskb_may_pull(rx->skb, hdrlen + 6))
  2070. return RX_DROP_MONITOR;
  2071. mesh_hdr = (struct ieee80211s_hdr *) (skb->data + hdrlen);
  2072. /* make sure full mesh header is there, also checks skb len */
  2073. if (!pskb_may_pull(rx->skb,
  2074. hdrlen + ieee80211_get_mesh_hdrlen(mesh_hdr)))
  2075. return RX_DROP_MONITOR;
  2076. /* reload pointers */
  2077. hdr = (struct ieee80211_hdr *) skb->data;
  2078. mesh_hdr = (struct ieee80211s_hdr *) (skb->data + hdrlen);
  2079. if (ieee80211_drop_unencrypted(rx, hdr->frame_control))
  2080. return RX_DROP_MONITOR;
  2081. /* frame is in RMC, don't forward */
  2082. if (ieee80211_is_data(hdr->frame_control) &&
  2083. is_multicast_ether_addr(hdr->addr1) &&
  2084. mesh_rmc_check(rx->sdata, hdr->addr3, mesh_hdr))
  2085. return RX_DROP_MONITOR;
  2086. if (!ieee80211_is_data(hdr->frame_control))
  2087. return RX_CONTINUE;
  2088. if (!mesh_hdr->ttl)
  2089. return RX_DROP_MONITOR;
  2090. if (mesh_hdr->flags & MESH_FLAGS_AE) {
  2091. struct mesh_path *mppath;
  2092. char *proxied_addr;
  2093. char *mpp_addr;
  2094. if (is_multicast_ether_addr(hdr->addr1)) {
  2095. mpp_addr = hdr->addr3;
  2096. proxied_addr = mesh_hdr->eaddr1;
  2097. } else if ((mesh_hdr->flags & MESH_FLAGS_AE) ==
  2098. MESH_FLAGS_AE_A5_A6) {
  2099. /* has_a4 already checked in ieee80211_rx_mesh_check */
  2100. mpp_addr = hdr->addr4;
  2101. proxied_addr = mesh_hdr->eaddr2;
  2102. } else {
  2103. return RX_DROP_MONITOR;
  2104. }
  2105. rcu_read_lock();
  2106. mppath = mpp_path_lookup(sdata, proxied_addr);
  2107. if (!mppath) {
  2108. mpp_path_add(sdata, proxied_addr, mpp_addr);
  2109. } else {
  2110. spin_lock_bh(&mppath->state_lock);
  2111. if (!ether_addr_equal(mppath->mpp, mpp_addr))
  2112. memcpy(mppath->mpp, mpp_addr, ETH_ALEN);
  2113. mppath->exp_time = jiffies;
  2114. spin_unlock_bh(&mppath->state_lock);
  2115. }
  2116. rcu_read_unlock();
  2117. }
  2118. /* Frame has reached destination. Don't forward */
  2119. if (!is_multicast_ether_addr(hdr->addr1) &&
  2120. ether_addr_equal(sdata->vif.addr, hdr->addr3))
  2121. return RX_CONTINUE;
  2122. ac = ieee80211_select_queue_80211(sdata, skb, hdr);
  2123. q = sdata->vif.hw_queue[ac];
  2124. if (ieee80211_queue_stopped(&local->hw, q)) {
  2125. IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, dropped_frames_congestion);
  2126. return RX_DROP_MONITOR;
  2127. }
  2128. skb_set_queue_mapping(skb, q);
  2129. if (!--mesh_hdr->ttl) {
  2130. IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, dropped_frames_ttl);
  2131. goto out;
  2132. }
  2133. if (!ifmsh->mshcfg.dot11MeshForwarding)
  2134. goto out;
  2135. fwd_skb = skb_copy(skb, GFP_ATOMIC);
  2136. if (!fwd_skb) {
  2137. net_info_ratelimited("%s: failed to clone mesh frame\n",
  2138. sdata->name);
  2139. goto out;
  2140. }
  2141. fwd_hdr = (struct ieee80211_hdr *) fwd_skb->data;
  2142. fwd_hdr->frame_control &= ~cpu_to_le16(IEEE80211_FCTL_RETRY);
  2143. info = IEEE80211_SKB_CB(fwd_skb);
  2144. memset(info, 0, sizeof(*info));
  2145. info->flags |= IEEE80211_TX_INTFL_NEED_TXPROCESSING;
  2146. info->control.vif = &rx->sdata->vif;
  2147. info->control.jiffies = jiffies;
  2148. if (is_multicast_ether_addr(fwd_hdr->addr1)) {
  2149. IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, fwded_mcast);
  2150. memcpy(fwd_hdr->addr2, sdata->vif.addr, ETH_ALEN);
  2151. /* update power mode indication when forwarding */
  2152. ieee80211_mps_set_frame_flags(sdata, NULL, fwd_hdr);
  2153. } else if (!mesh_nexthop_lookup(sdata, fwd_skb)) {
  2154. /* mesh power mode flags updated in mesh_nexthop_lookup */
  2155. IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, fwded_unicast);
  2156. } else {
  2157. /* unable to resolve next hop */
  2158. mesh_path_error_tx(sdata, ifmsh->mshcfg.element_ttl,
  2159. fwd_hdr->addr3, 0,
  2160. WLAN_REASON_MESH_PATH_NOFORWARD,
  2161. fwd_hdr->addr2);
  2162. IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, dropped_frames_no_route);
  2163. kfree_skb(fwd_skb);
  2164. return RX_DROP_MONITOR;
  2165. }
  2166. IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, fwded_frames);
  2167. ieee80211_add_pending_skb(local, fwd_skb);
  2168. out:
  2169. if (is_multicast_ether_addr(hdr->addr1))
  2170. return RX_CONTINUE;
  2171. return RX_DROP_MONITOR;
  2172. }
  2173. #endif
  2174. static ieee80211_rx_result debug_noinline
  2175. ieee80211_rx_h_data(struct ieee80211_rx_data *rx)
  2176. {
  2177. struct ieee80211_sub_if_data *sdata = rx->sdata;
  2178. struct ieee80211_local *local = rx->local;
  2179. struct net_device *dev = sdata->dev;
  2180. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
  2181. __le16 fc = hdr->frame_control;
  2182. bool port_control;
  2183. int err;
  2184. if (unlikely(!ieee80211_is_data(hdr->frame_control)))
  2185. return RX_CONTINUE;
  2186. if (unlikely(!ieee80211_is_data_present(hdr->frame_control)))
  2187. return RX_DROP_MONITOR;
  2188. /*
  2189. * Send unexpected-4addr-frame event to hostapd. For older versions,
  2190. * also drop the frame to cooked monitor interfaces.
  2191. */
  2192. if (ieee80211_has_a4(hdr->frame_control) &&
  2193. sdata->vif.type == NL80211_IFTYPE_AP) {
  2194. if (rx->sta &&
  2195. !test_and_set_sta_flag(rx->sta, WLAN_STA_4ADDR_EVENT))
  2196. cfg80211_rx_unexpected_4addr_frame(
  2197. rx->sdata->dev, rx->sta->sta.addr, GFP_ATOMIC);
  2198. return RX_DROP_MONITOR;
  2199. }
  2200. err = __ieee80211_data_to_8023(rx, &port_control);
  2201. if (unlikely(err))
  2202. return RX_DROP_UNUSABLE;
  2203. if (!ieee80211_frame_allowed(rx, fc))
  2204. return RX_DROP_MONITOR;
  2205. /* directly handle TDLS channel switch requests/responses */
  2206. if (unlikely(((struct ethhdr *)rx->skb->data)->h_proto ==
  2207. cpu_to_be16(ETH_P_TDLS))) {
  2208. struct ieee80211_tdls_data *tf = (void *)rx->skb->data;
  2209. if (pskb_may_pull(rx->skb,
  2210. offsetof(struct ieee80211_tdls_data, u)) &&
  2211. tf->payload_type == WLAN_TDLS_SNAP_RFTYPE &&
  2212. tf->category == WLAN_CATEGORY_TDLS &&
  2213. (tf->action_code == WLAN_TDLS_CHANNEL_SWITCH_REQUEST ||
  2214. tf->action_code == WLAN_TDLS_CHANNEL_SWITCH_RESPONSE)) {
  2215. skb_queue_tail(&local->skb_queue_tdls_chsw, rx->skb);
  2216. schedule_work(&local->tdls_chsw_work);
  2217. if (rx->sta)
  2218. rx->sta->rx_stats.packets++;
  2219. return RX_QUEUED;
  2220. }
  2221. }
  2222. if (rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
  2223. unlikely(port_control) && sdata->bss) {
  2224. sdata = container_of(sdata->bss, struct ieee80211_sub_if_data,
  2225. u.ap);
  2226. dev = sdata->dev;
  2227. rx->sdata = sdata;
  2228. }
  2229. rx->skb->dev = dev;
  2230. if (!ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS) &&
  2231. local->ps_sdata && local->hw.conf.dynamic_ps_timeout > 0 &&
  2232. !is_multicast_ether_addr(
  2233. ((struct ethhdr *)rx->skb->data)->h_dest) &&
  2234. (!local->scanning &&
  2235. !test_bit(SDATA_STATE_OFFCHANNEL, &sdata->state)))
  2236. mod_timer(&local->dynamic_ps_timer, jiffies +
  2237. msecs_to_jiffies(local->hw.conf.dynamic_ps_timeout));
  2238. ieee80211_deliver_skb(rx);
  2239. return RX_QUEUED;
  2240. }
  2241. static ieee80211_rx_result debug_noinline
  2242. ieee80211_rx_h_ctrl(struct ieee80211_rx_data *rx, struct sk_buff_head *frames)
  2243. {
  2244. struct sk_buff *skb = rx->skb;
  2245. struct ieee80211_bar *bar = (struct ieee80211_bar *)skb->data;
  2246. struct tid_ampdu_rx *tid_agg_rx;
  2247. u16 start_seq_num;
  2248. u16 tid;
  2249. if (likely(!ieee80211_is_ctl(bar->frame_control)))
  2250. return RX_CONTINUE;
  2251. if (ieee80211_is_back_req(bar->frame_control)) {
  2252. struct {
  2253. __le16 control, start_seq_num;
  2254. } __packed bar_data;
  2255. struct ieee80211_event event = {
  2256. .type = BAR_RX_EVENT,
  2257. };
  2258. if (!rx->sta)
  2259. return RX_DROP_MONITOR;
  2260. if (skb_copy_bits(skb, offsetof(struct ieee80211_bar, control),
  2261. &bar_data, sizeof(bar_data)))
  2262. return RX_DROP_MONITOR;
  2263. tid = le16_to_cpu(bar_data.control) >> 12;
  2264. if (!test_bit(tid, rx->sta->ampdu_mlme.agg_session_valid) &&
  2265. !test_and_set_bit(tid, rx->sta->ampdu_mlme.unexpected_agg))
  2266. ieee80211_send_delba(rx->sdata, rx->sta->sta.addr, tid,
  2267. WLAN_BACK_RECIPIENT,
  2268. WLAN_REASON_QSTA_REQUIRE_SETUP);
  2269. tid_agg_rx = rcu_dereference(rx->sta->ampdu_mlme.tid_rx[tid]);
  2270. if (!tid_agg_rx)
  2271. return RX_DROP_MONITOR;
  2272. start_seq_num = le16_to_cpu(bar_data.start_seq_num) >> 4;
  2273. event.u.ba.tid = tid;
  2274. event.u.ba.ssn = start_seq_num;
  2275. event.u.ba.sta = &rx->sta->sta;
  2276. /* reset session timer */
  2277. if (tid_agg_rx->timeout)
  2278. mod_timer(&tid_agg_rx->session_timer,
  2279. TU_TO_EXP_TIME(tid_agg_rx->timeout));
  2280. spin_lock(&tid_agg_rx->reorder_lock);
  2281. /* release stored frames up to start of BAR */
  2282. ieee80211_release_reorder_frames(rx->sdata, tid_agg_rx,
  2283. start_seq_num, frames);
  2284. spin_unlock(&tid_agg_rx->reorder_lock);
  2285. drv_event_callback(rx->local, rx->sdata, &event);
  2286. kfree_skb(skb);
  2287. return RX_QUEUED;
  2288. }
  2289. /*
  2290. * After this point, we only want management frames,
  2291. * so we can drop all remaining control frames to
  2292. * cooked monitor interfaces.
  2293. */
  2294. return RX_DROP_MONITOR;
  2295. }
  2296. static void ieee80211_process_sa_query_req(struct ieee80211_sub_if_data *sdata,
  2297. struct ieee80211_mgmt *mgmt,
  2298. size_t len)
  2299. {
  2300. struct ieee80211_local *local = sdata->local;
  2301. struct sk_buff *skb;
  2302. struct ieee80211_mgmt *resp;
  2303. if (!ether_addr_equal(mgmt->da, sdata->vif.addr)) {
  2304. /* Not to own unicast address */
  2305. return;
  2306. }
  2307. if (!ether_addr_equal(mgmt->sa, sdata->u.mgd.bssid) ||
  2308. !ether_addr_equal(mgmt->bssid, sdata->u.mgd.bssid)) {
  2309. /* Not from the current AP or not associated yet. */
  2310. return;
  2311. }
  2312. if (len < 24 + 1 + sizeof(resp->u.action.u.sa_query)) {
  2313. /* Too short SA Query request frame */
  2314. return;
  2315. }
  2316. skb = dev_alloc_skb(sizeof(*resp) + local->hw.extra_tx_headroom);
  2317. if (skb == NULL)
  2318. return;
  2319. skb_reserve(skb, local->hw.extra_tx_headroom);
  2320. resp = (struct ieee80211_mgmt *) skb_put(skb, 24);
  2321. memset(resp, 0, 24);
  2322. memcpy(resp->da, mgmt->sa, ETH_ALEN);
  2323. memcpy(resp->sa, sdata->vif.addr, ETH_ALEN);
  2324. memcpy(resp->bssid, sdata->u.mgd.bssid, ETH_ALEN);
  2325. resp->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
  2326. IEEE80211_STYPE_ACTION);
  2327. skb_put(skb, 1 + sizeof(resp->u.action.u.sa_query));
  2328. resp->u.action.category = WLAN_CATEGORY_SA_QUERY;
  2329. resp->u.action.u.sa_query.action = WLAN_ACTION_SA_QUERY_RESPONSE;
  2330. memcpy(resp->u.action.u.sa_query.trans_id,
  2331. mgmt->u.action.u.sa_query.trans_id,
  2332. WLAN_SA_QUERY_TR_ID_LEN);
  2333. ieee80211_tx_skb(sdata, skb);
  2334. }
  2335. static ieee80211_rx_result debug_noinline
  2336. ieee80211_rx_h_mgmt_check(struct ieee80211_rx_data *rx)
  2337. {
  2338. struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) rx->skb->data;
  2339. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
  2340. /*
  2341. * From here on, look only at management frames.
  2342. * Data and control frames are already handled,
  2343. * and unknown (reserved) frames are useless.
  2344. */
  2345. if (rx->skb->len < 24)
  2346. return RX_DROP_MONITOR;
  2347. if (!ieee80211_is_mgmt(mgmt->frame_control))
  2348. return RX_DROP_MONITOR;
  2349. if (rx->sdata->vif.type == NL80211_IFTYPE_AP &&
  2350. ieee80211_is_beacon(mgmt->frame_control) &&
  2351. !(rx->flags & IEEE80211_RX_BEACON_REPORTED)) {
  2352. int sig = 0;
  2353. if (ieee80211_hw_check(&rx->local->hw, SIGNAL_DBM))
  2354. sig = status->signal;
  2355. cfg80211_report_obss_beacon(rx->local->hw.wiphy,
  2356. rx->skb->data, rx->skb->len,
  2357. status->freq, sig);
  2358. rx->flags |= IEEE80211_RX_BEACON_REPORTED;
  2359. }
  2360. if (ieee80211_drop_unencrypted_mgmt(rx))
  2361. return RX_DROP_UNUSABLE;
  2362. return RX_CONTINUE;
  2363. }
  2364. static ieee80211_rx_result debug_noinline
  2365. ieee80211_rx_h_action(struct ieee80211_rx_data *rx)
  2366. {
  2367. struct ieee80211_local *local = rx->local;
  2368. struct ieee80211_sub_if_data *sdata = rx->sdata;
  2369. struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) rx->skb->data;
  2370. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
  2371. int len = rx->skb->len;
  2372. if (!ieee80211_is_action(mgmt->frame_control))
  2373. return RX_CONTINUE;
  2374. /* drop too small frames */
  2375. if (len < IEEE80211_MIN_ACTION_SIZE)
  2376. return RX_DROP_UNUSABLE;
  2377. if (!rx->sta && mgmt->u.action.category != WLAN_CATEGORY_PUBLIC &&
  2378. mgmt->u.action.category != WLAN_CATEGORY_SELF_PROTECTED &&
  2379. mgmt->u.action.category != WLAN_CATEGORY_SPECTRUM_MGMT)
  2380. return RX_DROP_UNUSABLE;
  2381. switch (mgmt->u.action.category) {
  2382. case WLAN_CATEGORY_HT:
  2383. /* reject HT action frames from stations not supporting HT */
  2384. if (!rx->sta->sta.ht_cap.ht_supported)
  2385. goto invalid;
  2386. if (sdata->vif.type != NL80211_IFTYPE_STATION &&
  2387. sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
  2388. sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
  2389. sdata->vif.type != NL80211_IFTYPE_AP &&
  2390. sdata->vif.type != NL80211_IFTYPE_ADHOC)
  2391. break;
  2392. /* verify action & smps_control/chanwidth are present */
  2393. if (len < IEEE80211_MIN_ACTION_SIZE + 2)
  2394. goto invalid;
  2395. switch (mgmt->u.action.u.ht_smps.action) {
  2396. case WLAN_HT_ACTION_SMPS: {
  2397. struct ieee80211_supported_band *sband;
  2398. enum ieee80211_smps_mode smps_mode;
  2399. /* convert to HT capability */
  2400. switch (mgmt->u.action.u.ht_smps.smps_control) {
  2401. case WLAN_HT_SMPS_CONTROL_DISABLED:
  2402. smps_mode = IEEE80211_SMPS_OFF;
  2403. break;
  2404. case WLAN_HT_SMPS_CONTROL_STATIC:
  2405. smps_mode = IEEE80211_SMPS_STATIC;
  2406. break;
  2407. case WLAN_HT_SMPS_CONTROL_DYNAMIC:
  2408. smps_mode = IEEE80211_SMPS_DYNAMIC;
  2409. break;
  2410. default:
  2411. goto invalid;
  2412. }
  2413. /* if no change do nothing */
  2414. if (rx->sta->sta.smps_mode == smps_mode)
  2415. goto handled;
  2416. rx->sta->sta.smps_mode = smps_mode;
  2417. sband = rx->local->hw.wiphy->bands[status->band];
  2418. rate_control_rate_update(local, sband, rx->sta,
  2419. IEEE80211_RC_SMPS_CHANGED);
  2420. goto handled;
  2421. }
  2422. case WLAN_HT_ACTION_NOTIFY_CHANWIDTH: {
  2423. struct ieee80211_supported_band *sband;
  2424. u8 chanwidth = mgmt->u.action.u.ht_notify_cw.chanwidth;
  2425. enum ieee80211_sta_rx_bandwidth max_bw, new_bw;
  2426. /* If it doesn't support 40 MHz it can't change ... */
  2427. if (!(rx->sta->sta.ht_cap.cap &
  2428. IEEE80211_HT_CAP_SUP_WIDTH_20_40))
  2429. goto handled;
  2430. if (chanwidth == IEEE80211_HT_CHANWIDTH_20MHZ)
  2431. max_bw = IEEE80211_STA_RX_BW_20;
  2432. else
  2433. max_bw = ieee80211_sta_cap_rx_bw(rx->sta);
  2434. /* set cur_max_bandwidth and recalc sta bw */
  2435. rx->sta->cur_max_bandwidth = max_bw;
  2436. new_bw = ieee80211_sta_cur_vht_bw(rx->sta);
  2437. if (rx->sta->sta.bandwidth == new_bw)
  2438. goto handled;
  2439. rx->sta->sta.bandwidth = new_bw;
  2440. sband = rx->local->hw.wiphy->bands[status->band];
  2441. rate_control_rate_update(local, sband, rx->sta,
  2442. IEEE80211_RC_BW_CHANGED);
  2443. goto handled;
  2444. }
  2445. default:
  2446. goto invalid;
  2447. }
  2448. break;
  2449. case WLAN_CATEGORY_PUBLIC:
  2450. if (len < IEEE80211_MIN_ACTION_SIZE + 1)
  2451. goto invalid;
  2452. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  2453. break;
  2454. if (!rx->sta)
  2455. break;
  2456. if (!ether_addr_equal(mgmt->bssid, sdata->u.mgd.bssid))
  2457. break;
  2458. if (mgmt->u.action.u.ext_chan_switch.action_code !=
  2459. WLAN_PUB_ACTION_EXT_CHANSW_ANN)
  2460. break;
  2461. if (len < offsetof(struct ieee80211_mgmt,
  2462. u.action.u.ext_chan_switch.variable))
  2463. goto invalid;
  2464. goto queue;
  2465. case WLAN_CATEGORY_VHT:
  2466. if (sdata->vif.type != NL80211_IFTYPE_STATION &&
  2467. sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
  2468. sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
  2469. sdata->vif.type != NL80211_IFTYPE_AP &&
  2470. sdata->vif.type != NL80211_IFTYPE_ADHOC)
  2471. break;
  2472. /* verify action code is present */
  2473. if (len < IEEE80211_MIN_ACTION_SIZE + 1)
  2474. goto invalid;
  2475. switch (mgmt->u.action.u.vht_opmode_notif.action_code) {
  2476. case WLAN_VHT_ACTION_OPMODE_NOTIF: {
  2477. /* verify opmode is present */
  2478. if (len < IEEE80211_MIN_ACTION_SIZE + 2)
  2479. goto invalid;
  2480. goto queue;
  2481. }
  2482. case WLAN_VHT_ACTION_GROUPID_MGMT: {
  2483. if (len < IEEE80211_MIN_ACTION_SIZE + 25)
  2484. goto invalid;
  2485. goto queue;
  2486. }
  2487. default:
  2488. break;
  2489. }
  2490. break;
  2491. case WLAN_CATEGORY_BACK:
  2492. if (sdata->vif.type != NL80211_IFTYPE_STATION &&
  2493. sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
  2494. sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
  2495. sdata->vif.type != NL80211_IFTYPE_AP &&
  2496. sdata->vif.type != NL80211_IFTYPE_ADHOC)
  2497. break;
  2498. /* verify action_code is present */
  2499. if (len < IEEE80211_MIN_ACTION_SIZE + 1)
  2500. break;
  2501. switch (mgmt->u.action.u.addba_req.action_code) {
  2502. case WLAN_ACTION_ADDBA_REQ:
  2503. if (len < (IEEE80211_MIN_ACTION_SIZE +
  2504. sizeof(mgmt->u.action.u.addba_req)))
  2505. goto invalid;
  2506. break;
  2507. case WLAN_ACTION_ADDBA_RESP:
  2508. if (len < (IEEE80211_MIN_ACTION_SIZE +
  2509. sizeof(mgmt->u.action.u.addba_resp)))
  2510. goto invalid;
  2511. break;
  2512. case WLAN_ACTION_DELBA:
  2513. if (len < (IEEE80211_MIN_ACTION_SIZE +
  2514. sizeof(mgmt->u.action.u.delba)))
  2515. goto invalid;
  2516. break;
  2517. default:
  2518. goto invalid;
  2519. }
  2520. goto queue;
  2521. case WLAN_CATEGORY_SPECTRUM_MGMT:
  2522. /* verify action_code is present */
  2523. if (len < IEEE80211_MIN_ACTION_SIZE + 1)
  2524. break;
  2525. switch (mgmt->u.action.u.measurement.action_code) {
  2526. case WLAN_ACTION_SPCT_MSR_REQ:
  2527. if (status->band != NL80211_BAND_5GHZ)
  2528. break;
  2529. if (len < (IEEE80211_MIN_ACTION_SIZE +
  2530. sizeof(mgmt->u.action.u.measurement)))
  2531. break;
  2532. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  2533. break;
  2534. ieee80211_process_measurement_req(sdata, mgmt, len);
  2535. goto handled;
  2536. case WLAN_ACTION_SPCT_CHL_SWITCH: {
  2537. u8 *bssid;
  2538. if (len < (IEEE80211_MIN_ACTION_SIZE +
  2539. sizeof(mgmt->u.action.u.chan_switch)))
  2540. break;
  2541. if (sdata->vif.type != NL80211_IFTYPE_STATION &&
  2542. sdata->vif.type != NL80211_IFTYPE_ADHOC &&
  2543. sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
  2544. break;
  2545. if (sdata->vif.type == NL80211_IFTYPE_STATION)
  2546. bssid = sdata->u.mgd.bssid;
  2547. else if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
  2548. bssid = sdata->u.ibss.bssid;
  2549. else if (sdata->vif.type == NL80211_IFTYPE_MESH_POINT)
  2550. bssid = mgmt->sa;
  2551. else
  2552. break;
  2553. if (!ether_addr_equal(mgmt->bssid, bssid))
  2554. break;
  2555. goto queue;
  2556. }
  2557. }
  2558. break;
  2559. case WLAN_CATEGORY_SA_QUERY:
  2560. if (len < (IEEE80211_MIN_ACTION_SIZE +
  2561. sizeof(mgmt->u.action.u.sa_query)))
  2562. break;
  2563. switch (mgmt->u.action.u.sa_query.action) {
  2564. case WLAN_ACTION_SA_QUERY_REQUEST:
  2565. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  2566. break;
  2567. ieee80211_process_sa_query_req(sdata, mgmt, len);
  2568. goto handled;
  2569. }
  2570. break;
  2571. case WLAN_CATEGORY_SELF_PROTECTED:
  2572. if (len < (IEEE80211_MIN_ACTION_SIZE +
  2573. sizeof(mgmt->u.action.u.self_prot.action_code)))
  2574. break;
  2575. switch (mgmt->u.action.u.self_prot.action_code) {
  2576. case WLAN_SP_MESH_PEERING_OPEN:
  2577. case WLAN_SP_MESH_PEERING_CLOSE:
  2578. case WLAN_SP_MESH_PEERING_CONFIRM:
  2579. if (!ieee80211_vif_is_mesh(&sdata->vif))
  2580. goto invalid;
  2581. if (sdata->u.mesh.user_mpm)
  2582. /* userspace handles this frame */
  2583. break;
  2584. goto queue;
  2585. case WLAN_SP_MGK_INFORM:
  2586. case WLAN_SP_MGK_ACK:
  2587. if (!ieee80211_vif_is_mesh(&sdata->vif))
  2588. goto invalid;
  2589. break;
  2590. }
  2591. break;
  2592. case WLAN_CATEGORY_MESH_ACTION:
  2593. if (len < (IEEE80211_MIN_ACTION_SIZE +
  2594. sizeof(mgmt->u.action.u.mesh_action.action_code)))
  2595. break;
  2596. if (!ieee80211_vif_is_mesh(&sdata->vif))
  2597. break;
  2598. if (mesh_action_is_path_sel(mgmt) &&
  2599. !mesh_path_sel_is_hwmp(sdata))
  2600. break;
  2601. goto queue;
  2602. }
  2603. return RX_CONTINUE;
  2604. invalid:
  2605. status->rx_flags |= IEEE80211_RX_MALFORMED_ACTION_FRM;
  2606. /* will return in the next handlers */
  2607. return RX_CONTINUE;
  2608. handled:
  2609. if (rx->sta)
  2610. rx->sta->rx_stats.packets++;
  2611. dev_kfree_skb(rx->skb);
  2612. return RX_QUEUED;
  2613. queue:
  2614. rx->skb->pkt_type = IEEE80211_SDATA_QUEUE_TYPE_FRAME;
  2615. skb_queue_tail(&sdata->skb_queue, rx->skb);
  2616. ieee80211_queue_work(&local->hw, &sdata->work);
  2617. if (rx->sta)
  2618. rx->sta->rx_stats.packets++;
  2619. return RX_QUEUED;
  2620. }
  2621. static ieee80211_rx_result debug_noinline
  2622. ieee80211_rx_h_userspace_mgmt(struct ieee80211_rx_data *rx)
  2623. {
  2624. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
  2625. int sig = 0;
  2626. /* skip known-bad action frames and return them in the next handler */
  2627. if (status->rx_flags & IEEE80211_RX_MALFORMED_ACTION_FRM)
  2628. return RX_CONTINUE;
  2629. /*
  2630. * Getting here means the kernel doesn't know how to handle
  2631. * it, but maybe userspace does ... include returned frames
  2632. * so userspace can register for those to know whether ones
  2633. * it transmitted were processed or returned.
  2634. */
  2635. if (ieee80211_hw_check(&rx->local->hw, SIGNAL_DBM))
  2636. sig = status->signal;
  2637. if (cfg80211_rx_mgmt(&rx->sdata->wdev, status->freq, sig,
  2638. rx->skb->data, rx->skb->len, 0)) {
  2639. if (rx->sta)
  2640. rx->sta->rx_stats.packets++;
  2641. dev_kfree_skb(rx->skb);
  2642. return RX_QUEUED;
  2643. }
  2644. return RX_CONTINUE;
  2645. }
  2646. static ieee80211_rx_result debug_noinline
  2647. ieee80211_rx_h_action_return(struct ieee80211_rx_data *rx)
  2648. {
  2649. struct ieee80211_local *local = rx->local;
  2650. struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) rx->skb->data;
  2651. struct sk_buff *nskb;
  2652. struct ieee80211_sub_if_data *sdata = rx->sdata;
  2653. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
  2654. if (!ieee80211_is_action(mgmt->frame_control))
  2655. return RX_CONTINUE;
  2656. /*
  2657. * For AP mode, hostapd is responsible for handling any action
  2658. * frames that we didn't handle, including returning unknown
  2659. * ones. For all other modes we will return them to the sender,
  2660. * setting the 0x80 bit in the action category, as required by
  2661. * 802.11-2012 9.24.4.
  2662. * Newer versions of hostapd shall also use the management frame
  2663. * registration mechanisms, but older ones still use cooked
  2664. * monitor interfaces so push all frames there.
  2665. */
  2666. if (!(status->rx_flags & IEEE80211_RX_MALFORMED_ACTION_FRM) &&
  2667. (sdata->vif.type == NL80211_IFTYPE_AP ||
  2668. sdata->vif.type == NL80211_IFTYPE_AP_VLAN))
  2669. return RX_DROP_MONITOR;
  2670. if (is_multicast_ether_addr(mgmt->da))
  2671. return RX_DROP_MONITOR;
  2672. /* do not return rejected action frames */
  2673. if (mgmt->u.action.category & 0x80)
  2674. return RX_DROP_UNUSABLE;
  2675. nskb = skb_copy_expand(rx->skb, local->hw.extra_tx_headroom, 0,
  2676. GFP_ATOMIC);
  2677. if (nskb) {
  2678. struct ieee80211_mgmt *nmgmt = (void *)nskb->data;
  2679. nmgmt->u.action.category |= 0x80;
  2680. memcpy(nmgmt->da, nmgmt->sa, ETH_ALEN);
  2681. memcpy(nmgmt->sa, rx->sdata->vif.addr, ETH_ALEN);
  2682. memset(nskb->cb, 0, sizeof(nskb->cb));
  2683. if (rx->sdata->vif.type == NL80211_IFTYPE_P2P_DEVICE) {
  2684. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(nskb);
  2685. info->flags = IEEE80211_TX_CTL_TX_OFFCHAN |
  2686. IEEE80211_TX_INTFL_OFFCHAN_TX_OK |
  2687. IEEE80211_TX_CTL_NO_CCK_RATE;
  2688. if (ieee80211_hw_check(&local->hw, QUEUE_CONTROL))
  2689. info->hw_queue =
  2690. local->hw.offchannel_tx_hw_queue;
  2691. }
  2692. __ieee80211_tx_skb_tid_band(rx->sdata, nskb, 7,
  2693. status->band);
  2694. }
  2695. dev_kfree_skb(rx->skb);
  2696. return RX_QUEUED;
  2697. }
  2698. static ieee80211_rx_result debug_noinline
  2699. ieee80211_rx_h_mgmt(struct ieee80211_rx_data *rx)
  2700. {
  2701. struct ieee80211_sub_if_data *sdata = rx->sdata;
  2702. struct ieee80211_mgmt *mgmt = (void *)rx->skb->data;
  2703. __le16 stype;
  2704. stype = mgmt->frame_control & cpu_to_le16(IEEE80211_FCTL_STYPE);
  2705. if (!ieee80211_vif_is_mesh(&sdata->vif) &&
  2706. sdata->vif.type != NL80211_IFTYPE_ADHOC &&
  2707. sdata->vif.type != NL80211_IFTYPE_OCB &&
  2708. sdata->vif.type != NL80211_IFTYPE_STATION)
  2709. return RX_DROP_MONITOR;
  2710. switch (stype) {
  2711. case cpu_to_le16(IEEE80211_STYPE_AUTH):
  2712. case cpu_to_le16(IEEE80211_STYPE_BEACON):
  2713. case cpu_to_le16(IEEE80211_STYPE_PROBE_RESP):
  2714. /* process for all: mesh, mlme, ibss */
  2715. break;
  2716. case cpu_to_le16(IEEE80211_STYPE_ASSOC_RESP):
  2717. case cpu_to_le16(IEEE80211_STYPE_REASSOC_RESP):
  2718. case cpu_to_le16(IEEE80211_STYPE_DEAUTH):
  2719. case cpu_to_le16(IEEE80211_STYPE_DISASSOC):
  2720. if (is_multicast_ether_addr(mgmt->da) &&
  2721. !is_broadcast_ether_addr(mgmt->da))
  2722. return RX_DROP_MONITOR;
  2723. /* process only for station */
  2724. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  2725. return RX_DROP_MONITOR;
  2726. break;
  2727. case cpu_to_le16(IEEE80211_STYPE_PROBE_REQ):
  2728. /* process only for ibss and mesh */
  2729. if (sdata->vif.type != NL80211_IFTYPE_ADHOC &&
  2730. sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
  2731. return RX_DROP_MONITOR;
  2732. break;
  2733. default:
  2734. return RX_DROP_MONITOR;
  2735. }
  2736. /* queue up frame and kick off work to process it */
  2737. rx->skb->pkt_type = IEEE80211_SDATA_QUEUE_TYPE_FRAME;
  2738. skb_queue_tail(&sdata->skb_queue, rx->skb);
  2739. ieee80211_queue_work(&rx->local->hw, &sdata->work);
  2740. if (rx->sta)
  2741. rx->sta->rx_stats.packets++;
  2742. return RX_QUEUED;
  2743. }
  2744. static void ieee80211_rx_cooked_monitor(struct ieee80211_rx_data *rx,
  2745. struct ieee80211_rate *rate)
  2746. {
  2747. struct ieee80211_sub_if_data *sdata;
  2748. struct ieee80211_local *local = rx->local;
  2749. struct sk_buff *skb = rx->skb, *skb2;
  2750. struct net_device *prev_dev = NULL;
  2751. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
  2752. int needed_headroom;
  2753. /*
  2754. * If cooked monitor has been processed already, then
  2755. * don't do it again. If not, set the flag.
  2756. */
  2757. if (rx->flags & IEEE80211_RX_CMNTR)
  2758. goto out_free_skb;
  2759. rx->flags |= IEEE80211_RX_CMNTR;
  2760. /* If there are no cooked monitor interfaces, just free the SKB */
  2761. if (!local->cooked_mntrs)
  2762. goto out_free_skb;
  2763. /* vendor data is long removed here */
  2764. status->flag &= ~RX_FLAG_RADIOTAP_VENDOR_DATA;
  2765. /* room for the radiotap header based on driver features */
  2766. needed_headroom = ieee80211_rx_radiotap_hdrlen(local, status, skb);
  2767. if (skb_headroom(skb) < needed_headroom &&
  2768. pskb_expand_head(skb, needed_headroom, 0, GFP_ATOMIC))
  2769. goto out_free_skb;
  2770. /* prepend radiotap information */
  2771. ieee80211_add_rx_radiotap_header(local, skb, rate, needed_headroom,
  2772. false);
  2773. skb_reset_mac_header(skb);
  2774. skb->ip_summed = CHECKSUM_UNNECESSARY;
  2775. skb->pkt_type = PACKET_OTHERHOST;
  2776. skb->protocol = htons(ETH_P_802_2);
  2777. list_for_each_entry_rcu(sdata, &local->interfaces, list) {
  2778. if (!ieee80211_sdata_running(sdata))
  2779. continue;
  2780. if (sdata->vif.type != NL80211_IFTYPE_MONITOR ||
  2781. !(sdata->u.mntr.flags & MONITOR_FLAG_COOK_FRAMES))
  2782. continue;
  2783. if (prev_dev) {
  2784. skb2 = skb_clone(skb, GFP_ATOMIC);
  2785. if (skb2) {
  2786. skb2->dev = prev_dev;
  2787. netif_receive_skb(skb2);
  2788. }
  2789. }
  2790. prev_dev = sdata->dev;
  2791. ieee80211_rx_stats(sdata->dev, skb->len);
  2792. }
  2793. if (prev_dev) {
  2794. skb->dev = prev_dev;
  2795. netif_receive_skb(skb);
  2796. return;
  2797. }
  2798. out_free_skb:
  2799. dev_kfree_skb(skb);
  2800. }
  2801. static void ieee80211_rx_handlers_result(struct ieee80211_rx_data *rx,
  2802. ieee80211_rx_result res)
  2803. {
  2804. switch (res) {
  2805. case RX_DROP_MONITOR:
  2806. I802_DEBUG_INC(rx->sdata->local->rx_handlers_drop);
  2807. if (rx->sta)
  2808. rx->sta->rx_stats.dropped++;
  2809. /* fall through */
  2810. case RX_CONTINUE: {
  2811. struct ieee80211_rate *rate = NULL;
  2812. struct ieee80211_supported_band *sband;
  2813. struct ieee80211_rx_status *status;
  2814. status = IEEE80211_SKB_RXCB((rx->skb));
  2815. sband = rx->local->hw.wiphy->bands[status->band];
  2816. if (!(status->flag & RX_FLAG_HT) &&
  2817. !(status->flag & RX_FLAG_VHT))
  2818. rate = &sband->bitrates[status->rate_idx];
  2819. ieee80211_rx_cooked_monitor(rx, rate);
  2820. break;
  2821. }
  2822. case RX_DROP_UNUSABLE:
  2823. I802_DEBUG_INC(rx->sdata->local->rx_handlers_drop);
  2824. if (rx->sta)
  2825. rx->sta->rx_stats.dropped++;
  2826. dev_kfree_skb(rx->skb);
  2827. break;
  2828. case RX_QUEUED:
  2829. I802_DEBUG_INC(rx->sdata->local->rx_handlers_queued);
  2830. break;
  2831. }
  2832. }
  2833. static void ieee80211_rx_handlers(struct ieee80211_rx_data *rx,
  2834. struct sk_buff_head *frames)
  2835. {
  2836. ieee80211_rx_result res = RX_DROP_MONITOR;
  2837. struct sk_buff *skb;
  2838. #define CALL_RXH(rxh) \
  2839. do { \
  2840. res = rxh(rx); \
  2841. if (res != RX_CONTINUE) \
  2842. goto rxh_next; \
  2843. } while (0)
  2844. /* Lock here to avoid hitting all of the data used in the RX
  2845. * path (e.g. key data, station data, ...) concurrently when
  2846. * a frame is released from the reorder buffer due to timeout
  2847. * from the timer, potentially concurrently with RX from the
  2848. * driver.
  2849. */
  2850. spin_lock_bh(&rx->local->rx_path_lock);
  2851. while ((skb = __skb_dequeue(frames))) {
  2852. /*
  2853. * all the other fields are valid across frames
  2854. * that belong to an aMPDU since they are on the
  2855. * same TID from the same station
  2856. */
  2857. rx->skb = skb;
  2858. CALL_RXH(ieee80211_rx_h_check_more_data);
  2859. CALL_RXH(ieee80211_rx_h_uapsd_and_pspoll);
  2860. CALL_RXH(ieee80211_rx_h_sta_process);
  2861. CALL_RXH(ieee80211_rx_h_decrypt);
  2862. CALL_RXH(ieee80211_rx_h_defragment);
  2863. CALL_RXH(ieee80211_rx_h_michael_mic_verify);
  2864. /* must be after MMIC verify so header is counted in MPDU mic */
  2865. #ifdef CONFIG_MAC80211_MESH
  2866. if (ieee80211_vif_is_mesh(&rx->sdata->vif))
  2867. CALL_RXH(ieee80211_rx_h_mesh_fwding);
  2868. #endif
  2869. CALL_RXH(ieee80211_rx_h_amsdu);
  2870. CALL_RXH(ieee80211_rx_h_data);
  2871. /* special treatment -- needs the queue */
  2872. res = ieee80211_rx_h_ctrl(rx, frames);
  2873. if (res != RX_CONTINUE)
  2874. goto rxh_next;
  2875. CALL_RXH(ieee80211_rx_h_mgmt_check);
  2876. CALL_RXH(ieee80211_rx_h_action);
  2877. CALL_RXH(ieee80211_rx_h_userspace_mgmt);
  2878. CALL_RXH(ieee80211_rx_h_action_return);
  2879. CALL_RXH(ieee80211_rx_h_mgmt);
  2880. rxh_next:
  2881. ieee80211_rx_handlers_result(rx, res);
  2882. #undef CALL_RXH
  2883. }
  2884. spin_unlock_bh(&rx->local->rx_path_lock);
  2885. }
  2886. static void ieee80211_invoke_rx_handlers(struct ieee80211_rx_data *rx)
  2887. {
  2888. struct sk_buff_head reorder_release;
  2889. ieee80211_rx_result res = RX_DROP_MONITOR;
  2890. __skb_queue_head_init(&reorder_release);
  2891. #define CALL_RXH(rxh) \
  2892. do { \
  2893. res = rxh(rx); \
  2894. if (res != RX_CONTINUE) \
  2895. goto rxh_next; \
  2896. } while (0)
  2897. CALL_RXH(ieee80211_rx_h_check_dup);
  2898. CALL_RXH(ieee80211_rx_h_check);
  2899. ieee80211_rx_reorder_ampdu(rx, &reorder_release);
  2900. ieee80211_rx_handlers(rx, &reorder_release);
  2901. return;
  2902. rxh_next:
  2903. ieee80211_rx_handlers_result(rx, res);
  2904. #undef CALL_RXH
  2905. }
  2906. /*
  2907. * This function makes calls into the RX path, therefore
  2908. * it has to be invoked under RCU read lock.
  2909. */
  2910. void ieee80211_release_reorder_timeout(struct sta_info *sta, int tid)
  2911. {
  2912. struct sk_buff_head frames;
  2913. struct ieee80211_rx_data rx = {
  2914. .sta = sta,
  2915. .sdata = sta->sdata,
  2916. .local = sta->local,
  2917. /* This is OK -- must be QoS data frame */
  2918. .security_idx = tid,
  2919. .seqno_idx = tid,
  2920. .napi = NULL, /* must be NULL to not have races */
  2921. };
  2922. struct tid_ampdu_rx *tid_agg_rx;
  2923. tid_agg_rx = rcu_dereference(sta->ampdu_mlme.tid_rx[tid]);
  2924. if (!tid_agg_rx)
  2925. return;
  2926. __skb_queue_head_init(&frames);
  2927. spin_lock(&tid_agg_rx->reorder_lock);
  2928. ieee80211_sta_reorder_release(sta->sdata, tid_agg_rx, &frames);
  2929. spin_unlock(&tid_agg_rx->reorder_lock);
  2930. if (!skb_queue_empty(&frames)) {
  2931. struct ieee80211_event event = {
  2932. .type = BA_FRAME_TIMEOUT,
  2933. .u.ba.tid = tid,
  2934. .u.ba.sta = &sta->sta,
  2935. };
  2936. drv_event_callback(rx.local, rx.sdata, &event);
  2937. }
  2938. ieee80211_rx_handlers(&rx, &frames);
  2939. }
  2940. void ieee80211_mark_rx_ba_filtered_frames(struct ieee80211_sta *pubsta, u8 tid,
  2941. u16 ssn, u64 filtered,
  2942. u16 received_mpdus)
  2943. {
  2944. struct sta_info *sta;
  2945. struct tid_ampdu_rx *tid_agg_rx;
  2946. struct sk_buff_head frames;
  2947. struct ieee80211_rx_data rx = {
  2948. /* This is OK -- must be QoS data frame */
  2949. .security_idx = tid,
  2950. .seqno_idx = tid,
  2951. };
  2952. int i, diff;
  2953. if (WARN_ON(!pubsta || tid >= IEEE80211_NUM_TIDS))
  2954. return;
  2955. __skb_queue_head_init(&frames);
  2956. sta = container_of(pubsta, struct sta_info, sta);
  2957. rx.sta = sta;
  2958. rx.sdata = sta->sdata;
  2959. rx.local = sta->local;
  2960. rcu_read_lock();
  2961. tid_agg_rx = rcu_dereference(sta->ampdu_mlme.tid_rx[tid]);
  2962. if (!tid_agg_rx)
  2963. goto out;
  2964. spin_lock_bh(&tid_agg_rx->reorder_lock);
  2965. if (received_mpdus >= IEEE80211_SN_MODULO >> 1) {
  2966. int release;
  2967. /* release all frames in the reorder buffer */
  2968. release = (tid_agg_rx->head_seq_num + tid_agg_rx->buf_size) %
  2969. IEEE80211_SN_MODULO;
  2970. ieee80211_release_reorder_frames(sta->sdata, tid_agg_rx,
  2971. release, &frames);
  2972. /* update ssn to match received ssn */
  2973. tid_agg_rx->head_seq_num = ssn;
  2974. } else {
  2975. ieee80211_release_reorder_frames(sta->sdata, tid_agg_rx, ssn,
  2976. &frames);
  2977. }
  2978. /* handle the case that received ssn is behind the mac ssn.
  2979. * it can be tid_agg_rx->buf_size behind and still be valid */
  2980. diff = (tid_agg_rx->head_seq_num - ssn) & IEEE80211_SN_MASK;
  2981. if (diff >= tid_agg_rx->buf_size) {
  2982. tid_agg_rx->reorder_buf_filtered = 0;
  2983. goto release;
  2984. }
  2985. filtered = filtered >> diff;
  2986. ssn += diff;
  2987. /* update bitmap */
  2988. for (i = 0; i < tid_agg_rx->buf_size; i++) {
  2989. int index = (ssn + i) % tid_agg_rx->buf_size;
  2990. tid_agg_rx->reorder_buf_filtered &= ~BIT_ULL(index);
  2991. if (filtered & BIT_ULL(i))
  2992. tid_agg_rx->reorder_buf_filtered |= BIT_ULL(index);
  2993. }
  2994. /* now process also frames that the filter marking released */
  2995. ieee80211_sta_reorder_release(sta->sdata, tid_agg_rx, &frames);
  2996. release:
  2997. spin_unlock_bh(&tid_agg_rx->reorder_lock);
  2998. ieee80211_rx_handlers(&rx, &frames);
  2999. out:
  3000. rcu_read_unlock();
  3001. }
  3002. EXPORT_SYMBOL(ieee80211_mark_rx_ba_filtered_frames);
  3003. /* main receive path */
  3004. static bool ieee80211_accept_frame(struct ieee80211_rx_data *rx)
  3005. {
  3006. struct ieee80211_sub_if_data *sdata = rx->sdata;
  3007. struct sk_buff *skb = rx->skb;
  3008. struct ieee80211_hdr *hdr = (void *)skb->data;
  3009. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
  3010. u8 *bssid = ieee80211_get_bssid(hdr, skb->len, sdata->vif.type);
  3011. int multicast = is_multicast_ether_addr(hdr->addr1);
  3012. switch (sdata->vif.type) {
  3013. case NL80211_IFTYPE_STATION:
  3014. if (!bssid && !sdata->u.mgd.use_4addr)
  3015. return false;
  3016. if (multicast)
  3017. return true;
  3018. return ether_addr_equal(sdata->vif.addr, hdr->addr1);
  3019. case NL80211_IFTYPE_ADHOC:
  3020. if (!bssid)
  3021. return false;
  3022. if (ether_addr_equal(sdata->vif.addr, hdr->addr2) ||
  3023. ether_addr_equal(sdata->u.ibss.bssid, hdr->addr2))
  3024. return false;
  3025. if (ieee80211_is_beacon(hdr->frame_control))
  3026. return true;
  3027. if (!ieee80211_bssid_match(bssid, sdata->u.ibss.bssid))
  3028. return false;
  3029. if (!multicast &&
  3030. !ether_addr_equal(sdata->vif.addr, hdr->addr1))
  3031. return false;
  3032. if (!rx->sta) {
  3033. int rate_idx;
  3034. if (status->flag & (RX_FLAG_HT | RX_FLAG_VHT))
  3035. rate_idx = 0; /* TODO: HT/VHT rates */
  3036. else
  3037. rate_idx = status->rate_idx;
  3038. ieee80211_ibss_rx_no_sta(sdata, bssid, hdr->addr2,
  3039. BIT(rate_idx));
  3040. }
  3041. return true;
  3042. case NL80211_IFTYPE_OCB:
  3043. if (!bssid)
  3044. return false;
  3045. if (!ieee80211_is_data_present(hdr->frame_control))
  3046. return false;
  3047. if (!is_broadcast_ether_addr(bssid))
  3048. return false;
  3049. if (!multicast &&
  3050. !ether_addr_equal(sdata->dev->dev_addr, hdr->addr1))
  3051. return false;
  3052. if (!rx->sta) {
  3053. int rate_idx;
  3054. if (status->flag & RX_FLAG_HT)
  3055. rate_idx = 0; /* TODO: HT rates */
  3056. else
  3057. rate_idx = status->rate_idx;
  3058. ieee80211_ocb_rx_no_sta(sdata, bssid, hdr->addr2,
  3059. BIT(rate_idx));
  3060. }
  3061. return true;
  3062. case NL80211_IFTYPE_MESH_POINT:
  3063. if (ether_addr_equal(sdata->vif.addr, hdr->addr2))
  3064. return false;
  3065. if (multicast)
  3066. return true;
  3067. return ether_addr_equal(sdata->vif.addr, hdr->addr1);
  3068. case NL80211_IFTYPE_AP_VLAN:
  3069. case NL80211_IFTYPE_AP:
  3070. if (!bssid)
  3071. return ether_addr_equal(sdata->vif.addr, hdr->addr1);
  3072. if (!ieee80211_bssid_match(bssid, sdata->vif.addr)) {
  3073. /*
  3074. * Accept public action frames even when the
  3075. * BSSID doesn't match, this is used for P2P
  3076. * and location updates. Note that mac80211
  3077. * itself never looks at these frames.
  3078. */
  3079. if (!multicast &&
  3080. !ether_addr_equal(sdata->vif.addr, hdr->addr1))
  3081. return false;
  3082. if (ieee80211_is_public_action(hdr, skb->len))
  3083. return true;
  3084. return ieee80211_is_beacon(hdr->frame_control);
  3085. }
  3086. if (!ieee80211_has_tods(hdr->frame_control)) {
  3087. /* ignore data frames to TDLS-peers */
  3088. if (ieee80211_is_data(hdr->frame_control))
  3089. return false;
  3090. /* ignore action frames to TDLS-peers */
  3091. if (ieee80211_is_action(hdr->frame_control) &&
  3092. !is_broadcast_ether_addr(bssid) &&
  3093. !ether_addr_equal(bssid, hdr->addr1))
  3094. return false;
  3095. }
  3096. /*
  3097. * 802.11-2016 Table 9-26 says that for data frames, A1 must be
  3098. * the BSSID - we've checked that already but may have accepted
  3099. * the wildcard (ff:ff:ff:ff:ff:ff).
  3100. *
  3101. * It also says:
  3102. * The BSSID of the Data frame is determined as follows:
  3103. * a) If the STA is contained within an AP or is associated
  3104. * with an AP, the BSSID is the address currently in use
  3105. * by the STA contained in the AP.
  3106. *
  3107. * So we should not accept data frames with an address that's
  3108. * multicast.
  3109. *
  3110. * Accepting it also opens a security problem because stations
  3111. * could encrypt it with the GTK and inject traffic that way.
  3112. */
  3113. if (ieee80211_is_data(hdr->frame_control) && multicast)
  3114. return false;
  3115. return true;
  3116. case NL80211_IFTYPE_WDS:
  3117. if (bssid || !ieee80211_is_data(hdr->frame_control))
  3118. return false;
  3119. return ether_addr_equal(sdata->u.wds.remote_addr, hdr->addr2);
  3120. case NL80211_IFTYPE_P2P_DEVICE:
  3121. return ieee80211_is_public_action(hdr, skb->len) ||
  3122. ieee80211_is_probe_req(hdr->frame_control) ||
  3123. ieee80211_is_probe_resp(hdr->frame_control) ||
  3124. ieee80211_is_beacon(hdr->frame_control);
  3125. case NL80211_IFTYPE_NAN:
  3126. /* Currently no frames on NAN interface are allowed */
  3127. return false;
  3128. default:
  3129. break;
  3130. }
  3131. WARN_ON_ONCE(1);
  3132. return false;
  3133. }
  3134. void ieee80211_check_fast_rx(struct sta_info *sta)
  3135. {
  3136. struct ieee80211_sub_if_data *sdata = sta->sdata;
  3137. struct ieee80211_local *local = sdata->local;
  3138. struct ieee80211_key *key;
  3139. struct ieee80211_fast_rx fastrx = {
  3140. .dev = sdata->dev,
  3141. .vif_type = sdata->vif.type,
  3142. .control_port_protocol = sdata->control_port_protocol,
  3143. }, *old, *new = NULL;
  3144. bool assign = false;
  3145. /* use sparse to check that we don't return without updating */
  3146. __acquire(check_fast_rx);
  3147. BUILD_BUG_ON(sizeof(fastrx.rfc1042_hdr) != sizeof(rfc1042_header));
  3148. BUILD_BUG_ON(sizeof(fastrx.rfc1042_hdr) != ETH_ALEN);
  3149. ether_addr_copy(fastrx.rfc1042_hdr, rfc1042_header);
  3150. ether_addr_copy(fastrx.vif_addr, sdata->vif.addr);
  3151. fastrx.uses_rss = ieee80211_hw_check(&local->hw, USES_RSS);
  3152. /* fast-rx doesn't do reordering */
  3153. if (ieee80211_hw_check(&local->hw, AMPDU_AGGREGATION) &&
  3154. !ieee80211_hw_check(&local->hw, SUPPORTS_REORDERING_BUFFER))
  3155. goto clear;
  3156. switch (sdata->vif.type) {
  3157. case NL80211_IFTYPE_STATION:
  3158. /* 4-addr is harder to deal with, later maybe */
  3159. if (sdata->u.mgd.use_4addr)
  3160. goto clear;
  3161. /* software powersave is a huge mess, avoid all of it */
  3162. if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK))
  3163. goto clear;
  3164. if (ieee80211_hw_check(&local->hw, SUPPORTS_PS) &&
  3165. !ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS))
  3166. goto clear;
  3167. if (sta->sta.tdls) {
  3168. fastrx.da_offs = offsetof(struct ieee80211_hdr, addr1);
  3169. fastrx.sa_offs = offsetof(struct ieee80211_hdr, addr2);
  3170. fastrx.expected_ds_bits = 0;
  3171. } else {
  3172. fastrx.sta_notify = sdata->u.mgd.probe_send_count > 0;
  3173. fastrx.da_offs = offsetof(struct ieee80211_hdr, addr1);
  3174. fastrx.sa_offs = offsetof(struct ieee80211_hdr, addr3);
  3175. fastrx.expected_ds_bits =
  3176. cpu_to_le16(IEEE80211_FCTL_FROMDS);
  3177. }
  3178. break;
  3179. case NL80211_IFTYPE_AP_VLAN:
  3180. case NL80211_IFTYPE_AP:
  3181. /* parallel-rx requires this, at least with calls to
  3182. * ieee80211_sta_ps_transition()
  3183. */
  3184. if (!ieee80211_hw_check(&local->hw, AP_LINK_PS))
  3185. goto clear;
  3186. fastrx.da_offs = offsetof(struct ieee80211_hdr, addr3);
  3187. fastrx.sa_offs = offsetof(struct ieee80211_hdr, addr2);
  3188. fastrx.expected_ds_bits = cpu_to_le16(IEEE80211_FCTL_TODS);
  3189. fastrx.internal_forward =
  3190. !(sdata->flags & IEEE80211_SDATA_DONT_BRIDGE_PACKETS) &&
  3191. (sdata->vif.type != NL80211_IFTYPE_AP_VLAN ||
  3192. !sdata->u.vlan.sta);
  3193. break;
  3194. default:
  3195. goto clear;
  3196. }
  3197. if (!test_sta_flag(sta, WLAN_STA_AUTHORIZED))
  3198. goto clear;
  3199. rcu_read_lock();
  3200. key = rcu_dereference(sta->ptk[sta->ptk_idx]);
  3201. if (key) {
  3202. switch (key->conf.cipher) {
  3203. case WLAN_CIPHER_SUITE_TKIP:
  3204. /* we don't want to deal with MMIC in fast-rx */
  3205. goto clear_rcu;
  3206. case WLAN_CIPHER_SUITE_CCMP:
  3207. case WLAN_CIPHER_SUITE_CCMP_256:
  3208. case WLAN_CIPHER_SUITE_GCMP:
  3209. case WLAN_CIPHER_SUITE_GCMP_256:
  3210. break;
  3211. default:
  3212. /* we also don't want to deal with WEP or cipher scheme
  3213. * since those require looking up the key idx in the
  3214. * frame, rather than assuming the PTK is used
  3215. * (we need to revisit this once we implement the real
  3216. * PTK index, which is now valid in the spec, but we
  3217. * haven't implemented that part yet)
  3218. */
  3219. goto clear_rcu;
  3220. }
  3221. fastrx.key = true;
  3222. fastrx.icv_len = key->conf.icv_len;
  3223. }
  3224. assign = true;
  3225. clear_rcu:
  3226. rcu_read_unlock();
  3227. clear:
  3228. __release(check_fast_rx);
  3229. if (assign)
  3230. new = kmemdup(&fastrx, sizeof(fastrx), GFP_KERNEL);
  3231. spin_lock_bh(&sta->lock);
  3232. old = rcu_dereference_protected(sta->fast_rx, true);
  3233. rcu_assign_pointer(sta->fast_rx, new);
  3234. spin_unlock_bh(&sta->lock);
  3235. if (old)
  3236. kfree_rcu(old, rcu_head);
  3237. }
  3238. void ieee80211_clear_fast_rx(struct sta_info *sta)
  3239. {
  3240. struct ieee80211_fast_rx *old;
  3241. spin_lock_bh(&sta->lock);
  3242. old = rcu_dereference_protected(sta->fast_rx, true);
  3243. RCU_INIT_POINTER(sta->fast_rx, NULL);
  3244. spin_unlock_bh(&sta->lock);
  3245. if (old)
  3246. kfree_rcu(old, rcu_head);
  3247. }
  3248. void __ieee80211_check_fast_rx_iface(struct ieee80211_sub_if_data *sdata)
  3249. {
  3250. struct ieee80211_local *local = sdata->local;
  3251. struct sta_info *sta;
  3252. lockdep_assert_held(&local->sta_mtx);
  3253. list_for_each_entry_rcu(sta, &local->sta_list, list) {
  3254. if (sdata != sta->sdata &&
  3255. (!sta->sdata->bss || sta->sdata->bss != sdata->bss))
  3256. continue;
  3257. ieee80211_check_fast_rx(sta);
  3258. }
  3259. }
  3260. void ieee80211_check_fast_rx_iface(struct ieee80211_sub_if_data *sdata)
  3261. {
  3262. struct ieee80211_local *local = sdata->local;
  3263. mutex_lock(&local->sta_mtx);
  3264. __ieee80211_check_fast_rx_iface(sdata);
  3265. mutex_unlock(&local->sta_mtx);
  3266. }
  3267. static bool ieee80211_invoke_fast_rx(struct ieee80211_rx_data *rx,
  3268. struct ieee80211_fast_rx *fast_rx)
  3269. {
  3270. struct sk_buff *skb = rx->skb;
  3271. struct ieee80211_hdr *hdr = (void *)skb->data;
  3272. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
  3273. struct sta_info *sta = rx->sta;
  3274. int orig_len = skb->len;
  3275. int snap_offs = ieee80211_hdrlen(hdr->frame_control);
  3276. struct {
  3277. u8 snap[sizeof(rfc1042_header)];
  3278. __be16 proto;
  3279. } *payload __aligned(2);
  3280. struct {
  3281. u8 da[ETH_ALEN];
  3282. u8 sa[ETH_ALEN];
  3283. } addrs __aligned(2);
  3284. struct ieee80211_sta_rx_stats *stats = &sta->rx_stats;
  3285. if (fast_rx->uses_rss)
  3286. stats = this_cpu_ptr(sta->pcpu_rx_stats);
  3287. /* for parallel-rx, we need to have DUP_VALIDATED, otherwise we write
  3288. * to a common data structure; drivers can implement that per queue
  3289. * but we don't have that information in mac80211
  3290. */
  3291. if (!(status->flag & RX_FLAG_DUP_VALIDATED))
  3292. return false;
  3293. #define FAST_RX_CRYPT_FLAGS (RX_FLAG_PN_VALIDATED | RX_FLAG_DECRYPTED)
  3294. /* If using encryption, we also need to have:
  3295. * - PN_VALIDATED: similar, but the implementation is tricky
  3296. * - DECRYPTED: necessary for PN_VALIDATED
  3297. */
  3298. if (fast_rx->key &&
  3299. (status->flag & FAST_RX_CRYPT_FLAGS) != FAST_RX_CRYPT_FLAGS)
  3300. return false;
  3301. /* we don't deal with A-MSDU deaggregation here */
  3302. if (status->rx_flags & IEEE80211_RX_AMSDU)
  3303. return false;
  3304. if (unlikely(!ieee80211_is_data_present(hdr->frame_control)))
  3305. return false;
  3306. if (unlikely(ieee80211_is_frag(hdr)))
  3307. return false;
  3308. /* Since our interface address cannot be multicast, this
  3309. * implicitly also rejects multicast frames without the
  3310. * explicit check.
  3311. *
  3312. * We shouldn't get any *data* frames not addressed to us
  3313. * (AP mode will accept multicast *management* frames), but
  3314. * punting here will make it go through the full checks in
  3315. * ieee80211_accept_frame().
  3316. */
  3317. if (!ether_addr_equal(fast_rx->vif_addr, hdr->addr1))
  3318. return false;
  3319. if ((hdr->frame_control & cpu_to_le16(IEEE80211_FCTL_FROMDS |
  3320. IEEE80211_FCTL_TODS)) !=
  3321. fast_rx->expected_ds_bits)
  3322. return false;
  3323. /* assign the key to drop unencrypted frames (later)
  3324. * and strip the IV/MIC if necessary
  3325. */
  3326. if (fast_rx->key && !(status->flag & RX_FLAG_IV_STRIPPED)) {
  3327. /* GCMP header length is the same */
  3328. snap_offs += IEEE80211_CCMP_HDR_LEN;
  3329. }
  3330. if (!pskb_may_pull(skb, snap_offs + sizeof(*payload)))
  3331. goto drop;
  3332. payload = (void *)(skb->data + snap_offs);
  3333. if (!ether_addr_equal(payload->snap, fast_rx->rfc1042_hdr))
  3334. return false;
  3335. /* Don't handle these here since they require special code.
  3336. * Accept AARP and IPX even though they should come with a
  3337. * bridge-tunnel header - but if we get them this way then
  3338. * there's little point in discarding them.
  3339. */
  3340. if (unlikely(payload->proto == cpu_to_be16(ETH_P_TDLS) ||
  3341. payload->proto == fast_rx->control_port_protocol))
  3342. return false;
  3343. /* after this point, don't punt to the slowpath! */
  3344. if (rx->key && !(status->flag & RX_FLAG_MIC_STRIPPED) &&
  3345. pskb_trim(skb, skb->len - fast_rx->icv_len))
  3346. goto drop;
  3347. if (unlikely(fast_rx->sta_notify)) {
  3348. ieee80211_sta_rx_notify(rx->sdata, hdr);
  3349. fast_rx->sta_notify = false;
  3350. }
  3351. /* statistics part of ieee80211_rx_h_sta_process() */
  3352. stats->last_rx = jiffies;
  3353. stats->last_rate = sta_stats_encode_rate(status);
  3354. stats->fragments++;
  3355. stats->packets++;
  3356. if (!(status->flag & RX_FLAG_NO_SIGNAL_VAL)) {
  3357. stats->last_signal = status->signal;
  3358. if (!fast_rx->uses_rss)
  3359. ewma_signal_add(&sta->rx_stats_avg.signal,
  3360. -status->signal);
  3361. }
  3362. if (status->chains) {
  3363. int i;
  3364. stats->chains = status->chains;
  3365. for (i = 0; i < ARRAY_SIZE(status->chain_signal); i++) {
  3366. int signal = status->chain_signal[i];
  3367. if (!(status->chains & BIT(i)))
  3368. continue;
  3369. stats->chain_signal_last[i] = signal;
  3370. if (!fast_rx->uses_rss)
  3371. ewma_signal_add(&sta->rx_stats_avg.chain_signal[i],
  3372. -signal);
  3373. }
  3374. }
  3375. /* end of statistics */
  3376. if (rx->key && !ieee80211_has_protected(hdr->frame_control))
  3377. goto drop;
  3378. /* do the header conversion - first grab the addresses */
  3379. ether_addr_copy(addrs.da, skb->data + fast_rx->da_offs);
  3380. ether_addr_copy(addrs.sa, skb->data + fast_rx->sa_offs);
  3381. /* remove the SNAP but leave the ethertype */
  3382. skb_pull(skb, snap_offs + sizeof(rfc1042_header));
  3383. /* push the addresses in front */
  3384. memcpy(skb_push(skb, sizeof(addrs)), &addrs, sizeof(addrs));
  3385. skb->dev = fast_rx->dev;
  3386. ieee80211_rx_stats(fast_rx->dev, skb->len);
  3387. /* The seqno index has the same property as needed
  3388. * for the rx_msdu field, i.e. it is IEEE80211_NUM_TIDS
  3389. * for non-QoS-data frames. Here we know it's a data
  3390. * frame, so count MSDUs.
  3391. */
  3392. u64_stats_update_begin(&stats->syncp);
  3393. stats->msdu[rx->seqno_idx]++;
  3394. stats->bytes += orig_len;
  3395. u64_stats_update_end(&stats->syncp);
  3396. if (fast_rx->internal_forward) {
  3397. struct sk_buff *xmit_skb = NULL;
  3398. bool multicast = is_multicast_ether_addr(skb->data);
  3399. if (multicast) {
  3400. xmit_skb = skb_copy(skb, GFP_ATOMIC);
  3401. } else if (sta_info_get(rx->sdata, skb->data)) {
  3402. xmit_skb = skb;
  3403. skb = NULL;
  3404. }
  3405. if (xmit_skb) {
  3406. /*
  3407. * Send to wireless media and increase priority by 256
  3408. * to keep the received priority instead of
  3409. * reclassifying the frame (see cfg80211_classify8021d).
  3410. */
  3411. xmit_skb->priority += 256;
  3412. xmit_skb->protocol = htons(ETH_P_802_3);
  3413. skb_reset_network_header(xmit_skb);
  3414. skb_reset_mac_header(xmit_skb);
  3415. dev_queue_xmit(xmit_skb);
  3416. }
  3417. if (!skb)
  3418. return true;
  3419. }
  3420. /* deliver to local stack */
  3421. skb->protocol = eth_type_trans(skb, fast_rx->dev);
  3422. memset(skb->cb, 0, sizeof(skb->cb));
  3423. if (rx->napi)
  3424. napi_gro_receive(rx->napi, skb);
  3425. else
  3426. netif_receive_skb(skb);
  3427. return true;
  3428. drop:
  3429. dev_kfree_skb(skb);
  3430. stats->dropped++;
  3431. return true;
  3432. }
  3433. /*
  3434. * This function returns whether or not the SKB
  3435. * was destined for RX processing or not, which,
  3436. * if consume is true, is equivalent to whether
  3437. * or not the skb was consumed.
  3438. */
  3439. static bool ieee80211_prepare_and_rx_handle(struct ieee80211_rx_data *rx,
  3440. struct sk_buff *skb, bool consume)
  3441. {
  3442. struct ieee80211_local *local = rx->local;
  3443. struct ieee80211_sub_if_data *sdata = rx->sdata;
  3444. rx->skb = skb;
  3445. /* See if we can do fast-rx; if we have to copy we already lost,
  3446. * so punt in that case. We should never have to deliver a data
  3447. * frame to multiple interfaces anyway.
  3448. *
  3449. * We skip the ieee80211_accept_frame() call and do the necessary
  3450. * checking inside ieee80211_invoke_fast_rx().
  3451. */
  3452. if (consume && rx->sta) {
  3453. struct ieee80211_fast_rx *fast_rx;
  3454. fast_rx = rcu_dereference(rx->sta->fast_rx);
  3455. if (fast_rx && ieee80211_invoke_fast_rx(rx, fast_rx))
  3456. return true;
  3457. }
  3458. if (!ieee80211_accept_frame(rx))
  3459. return false;
  3460. if (!consume) {
  3461. skb = skb_copy(skb, GFP_ATOMIC);
  3462. if (!skb) {
  3463. if (net_ratelimit())
  3464. wiphy_debug(local->hw.wiphy,
  3465. "failed to copy skb for %s\n",
  3466. sdata->name);
  3467. return true;
  3468. }
  3469. rx->skb = skb;
  3470. }
  3471. ieee80211_invoke_rx_handlers(rx);
  3472. return true;
  3473. }
  3474. /*
  3475. * This is the actual Rx frames handler. as it belongs to Rx path it must
  3476. * be called with rcu_read_lock protection.
  3477. */
  3478. static void __ieee80211_rx_handle_packet(struct ieee80211_hw *hw,
  3479. struct ieee80211_sta *pubsta,
  3480. struct sk_buff *skb,
  3481. struct napi_struct *napi)
  3482. {
  3483. struct ieee80211_local *local = hw_to_local(hw);
  3484. struct ieee80211_sub_if_data *sdata;
  3485. struct ieee80211_hdr *hdr;
  3486. __le16 fc;
  3487. struct ieee80211_rx_data rx;
  3488. struct ieee80211_sub_if_data *prev;
  3489. struct rhlist_head *tmp;
  3490. int err = 0;
  3491. fc = ((struct ieee80211_hdr *)skb->data)->frame_control;
  3492. memset(&rx, 0, sizeof(rx));
  3493. rx.skb = skb;
  3494. rx.local = local;
  3495. rx.napi = napi;
  3496. if (ieee80211_is_data(fc) || ieee80211_is_mgmt(fc))
  3497. I802_DEBUG_INC(local->dot11ReceivedFragmentCount);
  3498. if (ieee80211_is_mgmt(fc)) {
  3499. /* drop frame if too short for header */
  3500. if (skb->len < ieee80211_hdrlen(fc))
  3501. err = -ENOBUFS;
  3502. else
  3503. err = skb_linearize(skb);
  3504. } else {
  3505. err = !pskb_may_pull(skb, ieee80211_hdrlen(fc));
  3506. }
  3507. if (err) {
  3508. dev_kfree_skb(skb);
  3509. return;
  3510. }
  3511. hdr = (struct ieee80211_hdr *)skb->data;
  3512. ieee80211_parse_qos(&rx);
  3513. ieee80211_verify_alignment(&rx);
  3514. if (unlikely(ieee80211_is_probe_resp(hdr->frame_control) ||
  3515. ieee80211_is_beacon(hdr->frame_control)))
  3516. ieee80211_scan_rx(local, skb);
  3517. if (ieee80211_is_data(fc)) {
  3518. struct sta_info *sta, *prev_sta;
  3519. if (pubsta) {
  3520. rx.sta = container_of(pubsta, struct sta_info, sta);
  3521. rx.sdata = rx.sta->sdata;
  3522. if (ieee80211_prepare_and_rx_handle(&rx, skb, true))
  3523. return;
  3524. goto out;
  3525. }
  3526. prev_sta = NULL;
  3527. for_each_sta_info(local, hdr->addr2, sta, tmp) {
  3528. if (!prev_sta) {
  3529. prev_sta = sta;
  3530. continue;
  3531. }
  3532. rx.sta = prev_sta;
  3533. rx.sdata = prev_sta->sdata;
  3534. ieee80211_prepare_and_rx_handle(&rx, skb, false);
  3535. prev_sta = sta;
  3536. }
  3537. if (prev_sta) {
  3538. rx.sta = prev_sta;
  3539. rx.sdata = prev_sta->sdata;
  3540. if (ieee80211_prepare_and_rx_handle(&rx, skb, true))
  3541. return;
  3542. goto out;
  3543. }
  3544. }
  3545. prev = NULL;
  3546. list_for_each_entry_rcu(sdata, &local->interfaces, list) {
  3547. if (!ieee80211_sdata_running(sdata))
  3548. continue;
  3549. if (sdata->vif.type == NL80211_IFTYPE_MONITOR ||
  3550. sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
  3551. continue;
  3552. /*
  3553. * frame is destined for this interface, but if it's
  3554. * not also for the previous one we handle that after
  3555. * the loop to avoid copying the SKB once too much
  3556. */
  3557. if (!prev) {
  3558. prev = sdata;
  3559. continue;
  3560. }
  3561. rx.sta = sta_info_get_bss(prev, hdr->addr2);
  3562. rx.sdata = prev;
  3563. ieee80211_prepare_and_rx_handle(&rx, skb, false);
  3564. prev = sdata;
  3565. }
  3566. if (prev) {
  3567. rx.sta = sta_info_get_bss(prev, hdr->addr2);
  3568. rx.sdata = prev;
  3569. if (ieee80211_prepare_and_rx_handle(&rx, skb, true))
  3570. return;
  3571. }
  3572. out:
  3573. dev_kfree_skb(skb);
  3574. }
  3575. /*
  3576. * This is the receive path handler. It is called by a low level driver when an
  3577. * 802.11 MPDU is received from the hardware.
  3578. */
  3579. void ieee80211_rx_napi(struct ieee80211_hw *hw, struct ieee80211_sta *pubsta,
  3580. struct sk_buff *skb, struct napi_struct *napi)
  3581. {
  3582. struct ieee80211_local *local = hw_to_local(hw);
  3583. struct ieee80211_rate *rate = NULL;
  3584. struct ieee80211_supported_band *sband;
  3585. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
  3586. WARN_ON_ONCE(softirq_count() == 0);
  3587. if (WARN_ON(status->band >= NUM_NL80211_BANDS))
  3588. goto drop;
  3589. sband = local->hw.wiphy->bands[status->band];
  3590. if (WARN_ON(!sband))
  3591. goto drop;
  3592. /*
  3593. * If we're suspending, it is possible although not too likely
  3594. * that we'd be receiving frames after having already partially
  3595. * quiesced the stack. We can't process such frames then since
  3596. * that might, for example, cause stations to be added or other
  3597. * driver callbacks be invoked.
  3598. */
  3599. if (unlikely(local->quiescing || local->suspended))
  3600. goto drop;
  3601. /* We might be during a HW reconfig, prevent Rx for the same reason */
  3602. if (unlikely(local->in_reconfig))
  3603. goto drop;
  3604. /*
  3605. * The same happens when we're not even started,
  3606. * but that's worth a warning.
  3607. */
  3608. if (WARN_ON(!local->started))
  3609. goto drop;
  3610. if (likely(!(status->flag & RX_FLAG_FAILED_PLCP_CRC))) {
  3611. /*
  3612. * Validate the rate, unless a PLCP error means that
  3613. * we probably can't have a valid rate here anyway.
  3614. */
  3615. if (status->flag & RX_FLAG_HT) {
  3616. /*
  3617. * rate_idx is MCS index, which can be [0-76]
  3618. * as documented on:
  3619. *
  3620. * http://wireless.kernel.org/en/developers/Documentation/ieee80211/802.11n
  3621. *
  3622. * Anything else would be some sort of driver or
  3623. * hardware error. The driver should catch hardware
  3624. * errors.
  3625. */
  3626. if (WARN(status->rate_idx > 76,
  3627. "Rate marked as an HT rate but passed "
  3628. "status->rate_idx is not "
  3629. "an MCS index [0-76]: %d (0x%02x)\n",
  3630. status->rate_idx,
  3631. status->rate_idx))
  3632. goto drop;
  3633. } else if (status->flag & RX_FLAG_VHT) {
  3634. if (WARN_ONCE(status->rate_idx > 9 ||
  3635. !status->vht_nss ||
  3636. status->vht_nss > 8,
  3637. "Rate marked as a VHT rate but data is invalid: MCS: %d, NSS: %d\n",
  3638. status->rate_idx, status->vht_nss))
  3639. goto drop;
  3640. } else {
  3641. if (WARN_ON(status->rate_idx >= sband->n_bitrates))
  3642. goto drop;
  3643. rate = &sband->bitrates[status->rate_idx];
  3644. }
  3645. }
  3646. status->rx_flags = 0;
  3647. /*
  3648. * key references and virtual interfaces are protected using RCU
  3649. * and this requires that we are in a read-side RCU section during
  3650. * receive processing
  3651. */
  3652. rcu_read_lock();
  3653. /*
  3654. * Frames with failed FCS/PLCP checksum are not returned,
  3655. * all other frames are returned without radiotap header
  3656. * if it was previously present.
  3657. * Also, frames with less than 16 bytes are dropped.
  3658. */
  3659. skb = ieee80211_rx_monitor(local, skb, rate);
  3660. if (!skb) {
  3661. rcu_read_unlock();
  3662. return;
  3663. }
  3664. ieee80211_tpt_led_trig_rx(local,
  3665. ((struct ieee80211_hdr *)skb->data)->frame_control,
  3666. skb->len);
  3667. __ieee80211_rx_handle_packet(hw, pubsta, skb, napi);
  3668. rcu_read_unlock();
  3669. return;
  3670. drop:
  3671. kfree_skb(skb);
  3672. }
  3673. EXPORT_SYMBOL(ieee80211_rx_napi);
  3674. /* This is a version of the rx handler that can be called from hard irq
  3675. * context. Post the skb on the queue and schedule the tasklet */
  3676. void ieee80211_rx_irqsafe(struct ieee80211_hw *hw, struct sk_buff *skb)
  3677. {
  3678. struct ieee80211_local *local = hw_to_local(hw);
  3679. BUILD_BUG_ON(sizeof(struct ieee80211_rx_status) > sizeof(skb->cb));
  3680. skb->pkt_type = IEEE80211_RX_MSG;
  3681. skb_queue_tail(&local->skb_queue, skb);
  3682. tasklet_schedule(&local->tasklet);
  3683. }
  3684. EXPORT_SYMBOL(ieee80211_rx_irqsafe);