rx.c 121 KB

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