rx.c 95 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411
  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. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. */
  11. #include <linux/jiffies.h>
  12. #include <linux/slab.h>
  13. #include <linux/kernel.h>
  14. #include <linux/skbuff.h>
  15. #include <linux/netdevice.h>
  16. #include <linux/etherdevice.h>
  17. #include <linux/rcupdate.h>
  18. #include <linux/export.h>
  19. #include <net/mac80211.h>
  20. #include <net/ieee80211_radiotap.h>
  21. #include <asm/unaligned.h>
  22. #include "ieee80211_i.h"
  23. #include "driver-ops.h"
  24. #include "led.h"
  25. #include "mesh.h"
  26. #include "wep.h"
  27. #include "wpa.h"
  28. #include "tkip.h"
  29. #include "wme.h"
  30. #include "rate.h"
  31. /*
  32. * monitor mode reception
  33. *
  34. * This function cleans up the SKB, i.e. it removes all the stuff
  35. * only useful for monitoring.
  36. */
  37. static struct sk_buff *remove_monitor_info(struct ieee80211_local *local,
  38. struct sk_buff *skb)
  39. {
  40. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
  41. if (local->hw.flags & IEEE80211_HW_RX_INCLUDES_FCS) {
  42. if (likely(skb->len > FCS_LEN))
  43. __pskb_trim(skb, skb->len - FCS_LEN);
  44. else {
  45. /* driver bug */
  46. WARN_ON(1);
  47. dev_kfree_skb(skb);
  48. return NULL;
  49. }
  50. }
  51. if (status->vendor_radiotap_len)
  52. __pskb_pull(skb, status->vendor_radiotap_len);
  53. return skb;
  54. }
  55. static inline int should_drop_frame(struct sk_buff *skb, int present_fcs_len)
  56. {
  57. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
  58. struct ieee80211_hdr *hdr;
  59. hdr = (void *)(skb->data + status->vendor_radiotap_len);
  60. if (status->flag & (RX_FLAG_FAILED_FCS_CRC |
  61. RX_FLAG_FAILED_PLCP_CRC |
  62. RX_FLAG_AMPDU_IS_ZEROLEN))
  63. return 1;
  64. if (unlikely(skb->len < 16 + present_fcs_len +
  65. status->vendor_radiotap_len))
  66. return 1;
  67. if (ieee80211_is_ctl(hdr->frame_control) &&
  68. !ieee80211_is_pspoll(hdr->frame_control) &&
  69. !ieee80211_is_back_req(hdr->frame_control))
  70. return 1;
  71. return 0;
  72. }
  73. static int
  74. ieee80211_rx_radiotap_space(struct ieee80211_local *local,
  75. struct ieee80211_rx_status *status)
  76. {
  77. int len;
  78. /* always present fields */
  79. len = sizeof(struct ieee80211_radiotap_header) + 8;
  80. /* allocate extra bitmaps */
  81. if (status->vendor_radiotap_len)
  82. len += 4;
  83. if (status->chains)
  84. len += 4 * hweight8(status->chains);
  85. if (ieee80211_have_rx_timestamp(status)) {
  86. len = ALIGN(len, 8);
  87. len += 8;
  88. }
  89. if (local->hw.flags & IEEE80211_HW_SIGNAL_DBM)
  90. len += 1;
  91. /* antenna field, if we don't have per-chain info */
  92. if (!status->chains)
  93. len += 1;
  94. /* padding for RX_FLAGS if necessary */
  95. len = ALIGN(len, 2);
  96. if (status->flag & RX_FLAG_HT) /* HT info */
  97. len += 3;
  98. if (status->flag & RX_FLAG_AMPDU_DETAILS) {
  99. len = ALIGN(len, 4);
  100. len += 8;
  101. }
  102. if (status->flag & RX_FLAG_VHT) {
  103. len = ALIGN(len, 2);
  104. len += 12;
  105. }
  106. if (status->chains) {
  107. /* antenna and antenna signal fields */
  108. len += 2 * hweight8(status->chains);
  109. }
  110. if (status->vendor_radiotap_len) {
  111. if (WARN_ON_ONCE(status->vendor_radiotap_align == 0))
  112. status->vendor_radiotap_align = 1;
  113. /* align standard part of vendor namespace */
  114. len = ALIGN(len, 2);
  115. /* allocate standard part of vendor namespace */
  116. len += 6;
  117. /* align vendor-defined part */
  118. len = ALIGN(len, status->vendor_radiotap_align);
  119. /* vendor-defined part is already in skb */
  120. }
  121. return len;
  122. }
  123. /*
  124. * ieee80211_add_rx_radiotap_header - add radiotap header
  125. *
  126. * add a radiotap header containing all the fields which the hardware provided.
  127. */
  128. static void
  129. ieee80211_add_rx_radiotap_header(struct ieee80211_local *local,
  130. struct sk_buff *skb,
  131. struct ieee80211_rate *rate,
  132. int rtap_len, bool has_fcs)
  133. {
  134. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
  135. struct ieee80211_radiotap_header *rthdr;
  136. unsigned char *pos;
  137. __le32 *it_present;
  138. u32 it_present_val;
  139. u16 rx_flags = 0;
  140. u16 channel_flags = 0;
  141. int mpdulen, chain;
  142. unsigned long chains = status->chains;
  143. mpdulen = skb->len;
  144. if (!(has_fcs && (local->hw.flags & IEEE80211_HW_RX_INCLUDES_FCS)))
  145. mpdulen += FCS_LEN;
  146. rthdr = (struct ieee80211_radiotap_header *)skb_push(skb, rtap_len);
  147. memset(rthdr, 0, rtap_len);
  148. it_present = &rthdr->it_present;
  149. /* radiotap header, set always present flags */
  150. rthdr->it_len = cpu_to_le16(rtap_len + status->vendor_radiotap_len);
  151. it_present_val = BIT(IEEE80211_RADIOTAP_FLAGS) |
  152. BIT(IEEE80211_RADIOTAP_CHANNEL) |
  153. BIT(IEEE80211_RADIOTAP_RX_FLAGS);
  154. if (!status->chains)
  155. it_present_val |= BIT(IEEE80211_RADIOTAP_ANTENNA);
  156. for_each_set_bit(chain, &chains, IEEE80211_MAX_CHAINS) {
  157. it_present_val |=
  158. BIT(IEEE80211_RADIOTAP_EXT) |
  159. BIT(IEEE80211_RADIOTAP_RADIOTAP_NAMESPACE);
  160. put_unaligned_le32(it_present_val, it_present);
  161. it_present++;
  162. it_present_val = BIT(IEEE80211_RADIOTAP_ANTENNA) |
  163. BIT(IEEE80211_RADIOTAP_DBM_ANTSIGNAL);
  164. }
  165. if (status->vendor_radiotap_len) {
  166. it_present_val |= BIT(IEEE80211_RADIOTAP_VENDOR_NAMESPACE) |
  167. BIT(IEEE80211_RADIOTAP_EXT);
  168. put_unaligned_le32(it_present_val, it_present);
  169. it_present++;
  170. it_present_val = status->vendor_radiotap_bitmap;
  171. }
  172. put_unaligned_le32(it_present_val, it_present);
  173. pos = (void *)(it_present + 1);
  174. /* the order of the following fields is important */
  175. /* IEEE80211_RADIOTAP_TSFT */
  176. if (ieee80211_have_rx_timestamp(status)) {
  177. /* padding */
  178. while ((pos - (u8 *)rthdr) & 7)
  179. *pos++ = 0;
  180. put_unaligned_le64(
  181. ieee80211_calculate_rx_timestamp(local, status,
  182. mpdulen, 0),
  183. pos);
  184. rthdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_TSFT);
  185. pos += 8;
  186. }
  187. /* IEEE80211_RADIOTAP_FLAGS */
  188. if (has_fcs && (local->hw.flags & IEEE80211_HW_RX_INCLUDES_FCS))
  189. *pos |= IEEE80211_RADIOTAP_F_FCS;
  190. if (status->flag & (RX_FLAG_FAILED_FCS_CRC | RX_FLAG_FAILED_PLCP_CRC))
  191. *pos |= IEEE80211_RADIOTAP_F_BADFCS;
  192. if (status->flag & RX_FLAG_SHORTPRE)
  193. *pos |= IEEE80211_RADIOTAP_F_SHORTPRE;
  194. pos++;
  195. /* IEEE80211_RADIOTAP_RATE */
  196. if (!rate || status->flag & (RX_FLAG_HT | RX_FLAG_VHT)) {
  197. /*
  198. * Without rate information don't add it. If we have,
  199. * MCS information is a separate field in radiotap,
  200. * added below. The byte here is needed as padding
  201. * for the channel though, so initialise it to 0.
  202. */
  203. *pos = 0;
  204. } else {
  205. int shift = 0;
  206. rthdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_RATE);
  207. if (status->flag & RX_FLAG_10MHZ)
  208. shift = 1;
  209. else if (status->flag & RX_FLAG_5MHZ)
  210. shift = 2;
  211. *pos = DIV_ROUND_UP(rate->bitrate, 5 * (1 << shift));
  212. }
  213. pos++;
  214. /* IEEE80211_RADIOTAP_CHANNEL */
  215. put_unaligned_le16(status->freq, pos);
  216. pos += 2;
  217. if (status->flag & RX_FLAG_10MHZ)
  218. channel_flags |= IEEE80211_CHAN_HALF;
  219. else if (status->flag & RX_FLAG_5MHZ)
  220. channel_flags |= IEEE80211_CHAN_QUARTER;
  221. if (status->band == IEEE80211_BAND_5GHZ)
  222. channel_flags |= IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ;
  223. else if (status->flag & (RX_FLAG_HT | RX_FLAG_VHT))
  224. channel_flags |= IEEE80211_CHAN_DYN | IEEE80211_CHAN_2GHZ;
  225. else if (rate && rate->flags & IEEE80211_RATE_ERP_G)
  226. channel_flags |= IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ;
  227. else if (rate)
  228. channel_flags |= IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ;
  229. else
  230. channel_flags |= IEEE80211_CHAN_2GHZ;
  231. put_unaligned_le16(channel_flags, pos);
  232. pos += 2;
  233. /* IEEE80211_RADIOTAP_DBM_ANTSIGNAL */
  234. if (local->hw.flags & IEEE80211_HW_SIGNAL_DBM &&
  235. !(status->flag & RX_FLAG_NO_SIGNAL_VAL)) {
  236. *pos = status->signal;
  237. rthdr->it_present |=
  238. cpu_to_le32(1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL);
  239. pos++;
  240. }
  241. /* IEEE80211_RADIOTAP_LOCK_QUALITY is missing */
  242. if (!status->chains) {
  243. /* IEEE80211_RADIOTAP_ANTENNA */
  244. *pos = status->antenna;
  245. pos++;
  246. }
  247. /* IEEE80211_RADIOTAP_DB_ANTNOISE is not used */
  248. /* IEEE80211_RADIOTAP_RX_FLAGS */
  249. /* ensure 2 byte alignment for the 2 byte field as required */
  250. if ((pos - (u8 *)rthdr) & 1)
  251. *pos++ = 0;
  252. if (status->flag & RX_FLAG_FAILED_PLCP_CRC)
  253. rx_flags |= IEEE80211_RADIOTAP_F_RX_BADPLCP;
  254. put_unaligned_le16(rx_flags, pos);
  255. pos += 2;
  256. if (status->flag & RX_FLAG_HT) {
  257. unsigned int stbc;
  258. rthdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_MCS);
  259. *pos++ = local->hw.radiotap_mcs_details;
  260. *pos = 0;
  261. if (status->flag & RX_FLAG_SHORT_GI)
  262. *pos |= IEEE80211_RADIOTAP_MCS_SGI;
  263. if (status->flag & RX_FLAG_40MHZ)
  264. *pos |= IEEE80211_RADIOTAP_MCS_BW_40;
  265. if (status->flag & RX_FLAG_HT_GF)
  266. *pos |= IEEE80211_RADIOTAP_MCS_FMT_GF;
  267. stbc = (status->flag & RX_FLAG_STBC_MASK) >> RX_FLAG_STBC_SHIFT;
  268. *pos |= stbc << IEEE80211_RADIOTAP_MCS_STBC_SHIFT;
  269. pos++;
  270. *pos++ = status->rate_idx;
  271. }
  272. if (status->flag & RX_FLAG_AMPDU_DETAILS) {
  273. u16 flags = 0;
  274. /* ensure 4 byte alignment */
  275. while ((pos - (u8 *)rthdr) & 3)
  276. pos++;
  277. rthdr->it_present |=
  278. cpu_to_le32(1 << IEEE80211_RADIOTAP_AMPDU_STATUS);
  279. put_unaligned_le32(status->ampdu_reference, pos);
  280. pos += 4;
  281. if (status->flag & RX_FLAG_AMPDU_REPORT_ZEROLEN)
  282. flags |= IEEE80211_RADIOTAP_AMPDU_REPORT_ZEROLEN;
  283. if (status->flag & RX_FLAG_AMPDU_IS_ZEROLEN)
  284. flags |= IEEE80211_RADIOTAP_AMPDU_IS_ZEROLEN;
  285. if (status->flag & RX_FLAG_AMPDU_LAST_KNOWN)
  286. flags |= IEEE80211_RADIOTAP_AMPDU_LAST_KNOWN;
  287. if (status->flag & RX_FLAG_AMPDU_IS_LAST)
  288. flags |= IEEE80211_RADIOTAP_AMPDU_IS_LAST;
  289. if (status->flag & RX_FLAG_AMPDU_DELIM_CRC_ERROR)
  290. flags |= IEEE80211_RADIOTAP_AMPDU_DELIM_CRC_ERR;
  291. if (status->flag & RX_FLAG_AMPDU_DELIM_CRC_KNOWN)
  292. flags |= IEEE80211_RADIOTAP_AMPDU_DELIM_CRC_KNOWN;
  293. put_unaligned_le16(flags, pos);
  294. pos += 2;
  295. if (status->flag & RX_FLAG_AMPDU_DELIM_CRC_KNOWN)
  296. *pos++ = status->ampdu_delimiter_crc;
  297. else
  298. *pos++ = 0;
  299. *pos++ = 0;
  300. }
  301. if (status->flag & RX_FLAG_VHT) {
  302. u16 known = local->hw.radiotap_vht_details;
  303. rthdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_VHT);
  304. /* known field - how to handle 80+80? */
  305. if (status->flag & RX_FLAG_80P80MHZ)
  306. known &= ~IEEE80211_RADIOTAP_VHT_KNOWN_BANDWIDTH;
  307. put_unaligned_le16(known, pos);
  308. pos += 2;
  309. /* flags */
  310. if (status->flag & RX_FLAG_SHORT_GI)
  311. *pos |= IEEE80211_RADIOTAP_VHT_FLAG_SGI;
  312. pos++;
  313. /* bandwidth */
  314. if (status->flag & RX_FLAG_80MHZ)
  315. *pos++ = 4;
  316. else if (status->flag & RX_FLAG_80P80MHZ)
  317. *pos++ = 0; /* marked not known above */
  318. else if (status->flag & RX_FLAG_160MHZ)
  319. *pos++ = 11;
  320. else if (status->flag & RX_FLAG_40MHZ)
  321. *pos++ = 1;
  322. else /* 20 MHz */
  323. *pos++ = 0;
  324. /* MCS/NSS */
  325. *pos = (status->rate_idx << 4) | status->vht_nss;
  326. pos += 4;
  327. /* coding field */
  328. pos++;
  329. /* group ID */
  330. pos++;
  331. /* partial_aid */
  332. pos += 2;
  333. }
  334. for_each_set_bit(chain, &chains, IEEE80211_MAX_CHAINS) {
  335. *pos++ = status->chain_signal[chain];
  336. *pos++ = chain;
  337. }
  338. if (status->vendor_radiotap_len) {
  339. /* ensure 2 byte alignment for the vendor field as required */
  340. if ((pos - (u8 *)rthdr) & 1)
  341. *pos++ = 0;
  342. *pos++ = status->vendor_radiotap_oui[0];
  343. *pos++ = status->vendor_radiotap_oui[1];
  344. *pos++ = status->vendor_radiotap_oui[2];
  345. *pos++ = status->vendor_radiotap_subns;
  346. put_unaligned_le16(status->vendor_radiotap_len, pos);
  347. pos += 2;
  348. /* align the actual payload as requested */
  349. while ((pos - (u8 *)rthdr) & (status->vendor_radiotap_align - 1))
  350. *pos++ = 0;
  351. }
  352. }
  353. /*
  354. * This function copies a received frame to all monitor interfaces and
  355. * returns a cleaned-up SKB that no longer includes the FCS nor the
  356. * radiotap header the driver might have added.
  357. */
  358. static struct sk_buff *
  359. ieee80211_rx_monitor(struct ieee80211_local *local, struct sk_buff *origskb,
  360. struct ieee80211_rate *rate)
  361. {
  362. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(origskb);
  363. struct ieee80211_sub_if_data *sdata;
  364. int needed_headroom;
  365. struct sk_buff *skb, *skb2;
  366. struct net_device *prev_dev = NULL;
  367. int present_fcs_len = 0;
  368. /*
  369. * First, we may need to make a copy of the skb because
  370. * (1) we need to modify it for radiotap (if not present), and
  371. * (2) the other RX handlers will modify the skb we got.
  372. *
  373. * We don't need to, of course, if we aren't going to return
  374. * the SKB because it has a bad FCS/PLCP checksum.
  375. */
  376. if (local->hw.flags & IEEE80211_HW_RX_INCLUDES_FCS)
  377. present_fcs_len = FCS_LEN;
  378. /* ensure hdr->frame_control and vendor radiotap data are in skb head */
  379. if (!pskb_may_pull(origskb, 2 + status->vendor_radiotap_len)) {
  380. dev_kfree_skb(origskb);
  381. return NULL;
  382. }
  383. if (!local->monitors) {
  384. if (should_drop_frame(origskb, present_fcs_len)) {
  385. dev_kfree_skb(origskb);
  386. return NULL;
  387. }
  388. return remove_monitor_info(local, origskb);
  389. }
  390. /* room for the radiotap header based on driver features */
  391. needed_headroom = ieee80211_rx_radiotap_space(local, status);
  392. if (should_drop_frame(origskb, present_fcs_len)) {
  393. /* only need to expand headroom if necessary */
  394. skb = origskb;
  395. origskb = NULL;
  396. /*
  397. * This shouldn't trigger often because most devices have an
  398. * RX header they pull before we get here, and that should
  399. * be big enough for our radiotap information. We should
  400. * probably export the length to drivers so that we can have
  401. * them allocate enough headroom to start with.
  402. */
  403. if (skb_headroom(skb) < needed_headroom &&
  404. pskb_expand_head(skb, needed_headroom, 0, GFP_ATOMIC)) {
  405. dev_kfree_skb(skb);
  406. return NULL;
  407. }
  408. } else {
  409. /*
  410. * Need to make a copy and possibly remove radiotap header
  411. * and FCS from the original.
  412. */
  413. skb = skb_copy_expand(origskb, needed_headroom, 0, GFP_ATOMIC);
  414. origskb = remove_monitor_info(local, origskb);
  415. if (!skb)
  416. return origskb;
  417. }
  418. /* prepend radiotap information */
  419. ieee80211_add_rx_radiotap_header(local, skb, rate, needed_headroom,
  420. true);
  421. skb_reset_mac_header(skb);
  422. skb->ip_summed = CHECKSUM_UNNECESSARY;
  423. skb->pkt_type = PACKET_OTHERHOST;
  424. skb->protocol = htons(ETH_P_802_2);
  425. list_for_each_entry_rcu(sdata, &local->interfaces, list) {
  426. if (sdata->vif.type != NL80211_IFTYPE_MONITOR)
  427. continue;
  428. if (sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES)
  429. continue;
  430. if (!ieee80211_sdata_running(sdata))
  431. continue;
  432. if (prev_dev) {
  433. skb2 = skb_clone(skb, GFP_ATOMIC);
  434. if (skb2) {
  435. skb2->dev = prev_dev;
  436. netif_receive_skb(skb2);
  437. }
  438. }
  439. prev_dev = sdata->dev;
  440. sdata->dev->stats.rx_packets++;
  441. sdata->dev->stats.rx_bytes += skb->len;
  442. }
  443. if (prev_dev) {
  444. skb->dev = prev_dev;
  445. netif_receive_skb(skb);
  446. } else
  447. dev_kfree_skb(skb);
  448. return origskb;
  449. }
  450. static void ieee80211_parse_qos(struct ieee80211_rx_data *rx)
  451. {
  452. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
  453. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
  454. int tid, seqno_idx, security_idx;
  455. /* does the frame have a qos control field? */
  456. if (ieee80211_is_data_qos(hdr->frame_control)) {
  457. u8 *qc = ieee80211_get_qos_ctl(hdr);
  458. /* frame has qos control */
  459. tid = *qc & IEEE80211_QOS_CTL_TID_MASK;
  460. if (*qc & IEEE80211_QOS_CTL_A_MSDU_PRESENT)
  461. status->rx_flags |= IEEE80211_RX_AMSDU;
  462. seqno_idx = tid;
  463. security_idx = tid;
  464. } else {
  465. /*
  466. * IEEE 802.11-2007, 7.1.3.4.1 ("Sequence Number field"):
  467. *
  468. * Sequence numbers for management frames, QoS data
  469. * frames with a broadcast/multicast address in the
  470. * Address 1 field, and all non-QoS data frames sent
  471. * by QoS STAs are assigned using an additional single
  472. * modulo-4096 counter, [...]
  473. *
  474. * We also use that counter for non-QoS STAs.
  475. */
  476. seqno_idx = IEEE80211_NUM_TIDS;
  477. security_idx = 0;
  478. if (ieee80211_is_mgmt(hdr->frame_control))
  479. security_idx = IEEE80211_NUM_TIDS;
  480. tid = 0;
  481. }
  482. rx->seqno_idx = seqno_idx;
  483. rx->security_idx = security_idx;
  484. /* Set skb->priority to 1d tag if highest order bit of TID is not set.
  485. * For now, set skb->priority to 0 for other cases. */
  486. rx->skb->priority = (tid > 7) ? 0 : tid;
  487. }
  488. /**
  489. * DOC: Packet alignment
  490. *
  491. * Drivers always need to pass packets that are aligned to two-byte boundaries
  492. * to the stack.
  493. *
  494. * Additionally, should, if possible, align the payload data in a way that
  495. * guarantees that the contained IP header is aligned to a four-byte
  496. * boundary. In the case of regular frames, this simply means aligning the
  497. * payload to a four-byte boundary (because either the IP header is directly
  498. * contained, or IV/RFC1042 headers that have a length divisible by four are
  499. * in front of it). If the payload data is not properly aligned and the
  500. * architecture doesn't support efficient unaligned operations, mac80211
  501. * will align the data.
  502. *
  503. * With A-MSDU frames, however, the payload data address must yield two modulo
  504. * four because there are 14-byte 802.3 headers within the A-MSDU frames that
  505. * push the IP header further back to a multiple of four again. Thankfully, the
  506. * specs were sane enough this time around to require padding each A-MSDU
  507. * subframe to a length that is a multiple of four.
  508. *
  509. * Padding like Atheros hardware adds which is between the 802.11 header and
  510. * the payload is not supported, the driver is required to move the 802.11
  511. * header to be directly in front of the payload in that case.
  512. */
  513. static void ieee80211_verify_alignment(struct ieee80211_rx_data *rx)
  514. {
  515. #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
  516. WARN_ONCE((unsigned long)rx->skb->data & 1,
  517. "unaligned packet at 0x%p\n", rx->skb->data);
  518. #endif
  519. }
  520. /* rx handlers */
  521. static int ieee80211_is_unicast_robust_mgmt_frame(struct sk_buff *skb)
  522. {
  523. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
  524. if (skb->len < 24 || is_multicast_ether_addr(hdr->addr1))
  525. return 0;
  526. return ieee80211_is_robust_mgmt_frame(hdr);
  527. }
  528. static int ieee80211_is_multicast_robust_mgmt_frame(struct sk_buff *skb)
  529. {
  530. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
  531. if (skb->len < 24 || !is_multicast_ether_addr(hdr->addr1))
  532. return 0;
  533. return ieee80211_is_robust_mgmt_frame(hdr);
  534. }
  535. /* Get the BIP key index from MMIE; return -1 if this is not a BIP frame */
  536. static int ieee80211_get_mmie_keyidx(struct sk_buff *skb)
  537. {
  538. struct ieee80211_mgmt *hdr = (struct ieee80211_mgmt *) skb->data;
  539. struct ieee80211_mmie *mmie;
  540. if (skb->len < 24 + sizeof(*mmie) || !is_multicast_ether_addr(hdr->da))
  541. return -1;
  542. if (!ieee80211_is_robust_mgmt_frame((struct ieee80211_hdr *) hdr))
  543. return -1; /* not a robust management frame */
  544. mmie = (struct ieee80211_mmie *)
  545. (skb->data + skb->len - sizeof(*mmie));
  546. if (mmie->element_id != WLAN_EID_MMIE ||
  547. mmie->length != sizeof(*mmie) - 2)
  548. return -1;
  549. return le16_to_cpu(mmie->key_id);
  550. }
  551. static ieee80211_rx_result ieee80211_rx_mesh_check(struct ieee80211_rx_data *rx)
  552. {
  553. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
  554. char *dev_addr = rx->sdata->vif.addr;
  555. if (ieee80211_is_data(hdr->frame_control)) {
  556. if (is_multicast_ether_addr(hdr->addr1)) {
  557. if (ieee80211_has_tods(hdr->frame_control) ||
  558. !ieee80211_has_fromds(hdr->frame_control))
  559. return RX_DROP_MONITOR;
  560. if (ether_addr_equal(hdr->addr3, dev_addr))
  561. return RX_DROP_MONITOR;
  562. } else {
  563. if (!ieee80211_has_a4(hdr->frame_control))
  564. return RX_DROP_MONITOR;
  565. if (ether_addr_equal(hdr->addr4, dev_addr))
  566. return RX_DROP_MONITOR;
  567. }
  568. }
  569. /* If there is not an established peer link and this is not a peer link
  570. * establisment frame, beacon or probe, drop the frame.
  571. */
  572. if (!rx->sta || sta_plink_state(rx->sta) != NL80211_PLINK_ESTAB) {
  573. struct ieee80211_mgmt *mgmt;
  574. if (!ieee80211_is_mgmt(hdr->frame_control))
  575. return RX_DROP_MONITOR;
  576. if (ieee80211_is_action(hdr->frame_control)) {
  577. u8 category;
  578. /* make sure category field is present */
  579. if (rx->skb->len < IEEE80211_MIN_ACTION_SIZE)
  580. return RX_DROP_MONITOR;
  581. mgmt = (struct ieee80211_mgmt *)hdr;
  582. category = mgmt->u.action.category;
  583. if (category != WLAN_CATEGORY_MESH_ACTION &&
  584. category != WLAN_CATEGORY_SELF_PROTECTED)
  585. return RX_DROP_MONITOR;
  586. return RX_CONTINUE;
  587. }
  588. if (ieee80211_is_probe_req(hdr->frame_control) ||
  589. ieee80211_is_probe_resp(hdr->frame_control) ||
  590. ieee80211_is_beacon(hdr->frame_control) ||
  591. ieee80211_is_auth(hdr->frame_control))
  592. return RX_CONTINUE;
  593. return RX_DROP_MONITOR;
  594. }
  595. return RX_CONTINUE;
  596. }
  597. static void ieee80211_release_reorder_frame(struct ieee80211_sub_if_data *sdata,
  598. struct tid_ampdu_rx *tid_agg_rx,
  599. int index,
  600. struct sk_buff_head *frames)
  601. {
  602. struct sk_buff *skb = tid_agg_rx->reorder_buf[index];
  603. struct ieee80211_rx_status *status;
  604. lockdep_assert_held(&tid_agg_rx->reorder_lock);
  605. if (!skb)
  606. goto no_frame;
  607. /* release the frame from the reorder ring buffer */
  608. tid_agg_rx->stored_mpdu_num--;
  609. tid_agg_rx->reorder_buf[index] = NULL;
  610. status = IEEE80211_SKB_RXCB(skb);
  611. status->rx_flags |= IEEE80211_RX_DEFERRED_RELEASE;
  612. __skb_queue_tail(frames, skb);
  613. no_frame:
  614. tid_agg_rx->head_seq_num = ieee80211_sn_inc(tid_agg_rx->head_seq_num);
  615. }
  616. static void ieee80211_release_reorder_frames(struct ieee80211_sub_if_data *sdata,
  617. struct tid_ampdu_rx *tid_agg_rx,
  618. u16 head_seq_num,
  619. struct sk_buff_head *frames)
  620. {
  621. int index;
  622. lockdep_assert_held(&tid_agg_rx->reorder_lock);
  623. while (ieee80211_sn_less(tid_agg_rx->head_seq_num, head_seq_num)) {
  624. index = ieee80211_sn_sub(tid_agg_rx->head_seq_num,
  625. tid_agg_rx->ssn) %
  626. tid_agg_rx->buf_size;
  627. ieee80211_release_reorder_frame(sdata, tid_agg_rx, index,
  628. frames);
  629. }
  630. }
  631. /*
  632. * Timeout (in jiffies) for skb's that are waiting in the RX reorder buffer. If
  633. * the skb was added to the buffer longer than this time ago, the earlier
  634. * frames that have not yet been received are assumed to be lost and the skb
  635. * can be released for processing. This may also release other skb's from the
  636. * reorder buffer if there are no additional gaps between the frames.
  637. *
  638. * Callers must hold tid_agg_rx->reorder_lock.
  639. */
  640. #define HT_RX_REORDER_BUF_TIMEOUT (HZ / 10)
  641. static void ieee80211_sta_reorder_release(struct ieee80211_sub_if_data *sdata,
  642. struct tid_ampdu_rx *tid_agg_rx,
  643. struct sk_buff_head *frames)
  644. {
  645. int index, j;
  646. lockdep_assert_held(&tid_agg_rx->reorder_lock);
  647. /* release the buffer until next missing frame */
  648. index = ieee80211_sn_sub(tid_agg_rx->head_seq_num,
  649. tid_agg_rx->ssn) % tid_agg_rx->buf_size;
  650. if (!tid_agg_rx->reorder_buf[index] &&
  651. tid_agg_rx->stored_mpdu_num) {
  652. /*
  653. * No buffers ready to be released, but check whether any
  654. * frames in the reorder buffer have timed out.
  655. */
  656. int skipped = 1;
  657. for (j = (index + 1) % tid_agg_rx->buf_size; j != index;
  658. j = (j + 1) % tid_agg_rx->buf_size) {
  659. if (!tid_agg_rx->reorder_buf[j]) {
  660. skipped++;
  661. continue;
  662. }
  663. if (skipped &&
  664. !time_after(jiffies, tid_agg_rx->reorder_time[j] +
  665. HT_RX_REORDER_BUF_TIMEOUT))
  666. goto set_release_timer;
  667. ht_dbg_ratelimited(sdata,
  668. "release an RX reorder frame due to timeout on earlier frames\n");
  669. ieee80211_release_reorder_frame(sdata, tid_agg_rx, j,
  670. frames);
  671. /*
  672. * Increment the head seq# also for the skipped slots.
  673. */
  674. tid_agg_rx->head_seq_num =
  675. (tid_agg_rx->head_seq_num +
  676. skipped) & IEEE80211_SN_MASK;
  677. skipped = 0;
  678. }
  679. } else while (tid_agg_rx->reorder_buf[index]) {
  680. ieee80211_release_reorder_frame(sdata, tid_agg_rx, index,
  681. frames);
  682. index = ieee80211_sn_sub(tid_agg_rx->head_seq_num,
  683. tid_agg_rx->ssn) %
  684. tid_agg_rx->buf_size;
  685. }
  686. if (tid_agg_rx->stored_mpdu_num) {
  687. j = index = ieee80211_sn_sub(tid_agg_rx->head_seq_num,
  688. tid_agg_rx->ssn) %
  689. tid_agg_rx->buf_size;
  690. for (; j != (index - 1) % tid_agg_rx->buf_size;
  691. j = (j + 1) % tid_agg_rx->buf_size) {
  692. if (tid_agg_rx->reorder_buf[j])
  693. break;
  694. }
  695. set_release_timer:
  696. mod_timer(&tid_agg_rx->reorder_timer,
  697. tid_agg_rx->reorder_time[j] + 1 +
  698. HT_RX_REORDER_BUF_TIMEOUT);
  699. } else {
  700. del_timer(&tid_agg_rx->reorder_timer);
  701. }
  702. }
  703. /*
  704. * As this function belongs to the RX path it must be under
  705. * rcu_read_lock protection. It returns false if the frame
  706. * can be processed immediately, true if it was consumed.
  707. */
  708. static bool ieee80211_sta_manage_reorder_buf(struct ieee80211_sub_if_data *sdata,
  709. struct tid_ampdu_rx *tid_agg_rx,
  710. struct sk_buff *skb,
  711. struct sk_buff_head *frames)
  712. {
  713. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
  714. u16 sc = le16_to_cpu(hdr->seq_ctrl);
  715. u16 mpdu_seq_num = (sc & IEEE80211_SCTL_SEQ) >> 4;
  716. u16 head_seq_num, buf_size;
  717. int index;
  718. bool ret = true;
  719. spin_lock(&tid_agg_rx->reorder_lock);
  720. buf_size = tid_agg_rx->buf_size;
  721. head_seq_num = tid_agg_rx->head_seq_num;
  722. /* frame with out of date sequence number */
  723. if (ieee80211_sn_less(mpdu_seq_num, head_seq_num)) {
  724. dev_kfree_skb(skb);
  725. goto out;
  726. }
  727. /*
  728. * If frame the sequence number exceeds our buffering window
  729. * size release some previous frames to make room for this one.
  730. */
  731. if (!ieee80211_sn_less(mpdu_seq_num, head_seq_num + buf_size)) {
  732. head_seq_num = ieee80211_sn_inc(
  733. ieee80211_sn_sub(mpdu_seq_num, buf_size));
  734. /* release stored frames up to new head to stack */
  735. ieee80211_release_reorder_frames(sdata, tid_agg_rx,
  736. head_seq_num, frames);
  737. }
  738. /* Now the new frame is always in the range of the reordering buffer */
  739. index = ieee80211_sn_sub(mpdu_seq_num,
  740. tid_agg_rx->ssn) % tid_agg_rx->buf_size;
  741. /* check if we already stored this frame */
  742. if (tid_agg_rx->reorder_buf[index]) {
  743. dev_kfree_skb(skb);
  744. goto out;
  745. }
  746. /*
  747. * If the current MPDU is in the right order and nothing else
  748. * is stored we can process it directly, no need to buffer it.
  749. * If it is first but there's something stored, we may be able
  750. * to release frames after this one.
  751. */
  752. if (mpdu_seq_num == tid_agg_rx->head_seq_num &&
  753. tid_agg_rx->stored_mpdu_num == 0) {
  754. tid_agg_rx->head_seq_num =
  755. ieee80211_sn_inc(tid_agg_rx->head_seq_num);
  756. ret = false;
  757. goto out;
  758. }
  759. /* put the frame in the reordering buffer */
  760. tid_agg_rx->reorder_buf[index] = skb;
  761. tid_agg_rx->reorder_time[index] = jiffies;
  762. tid_agg_rx->stored_mpdu_num++;
  763. ieee80211_sta_reorder_release(sdata, tid_agg_rx, frames);
  764. out:
  765. spin_unlock(&tid_agg_rx->reorder_lock);
  766. return ret;
  767. }
  768. /*
  769. * Reorder MPDUs from A-MPDUs, keeping them on a buffer. Returns
  770. * true if the MPDU was buffered, false if it should be processed.
  771. */
  772. static void ieee80211_rx_reorder_ampdu(struct ieee80211_rx_data *rx,
  773. struct sk_buff_head *frames)
  774. {
  775. struct sk_buff *skb = rx->skb;
  776. struct ieee80211_local *local = rx->local;
  777. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
  778. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
  779. struct sta_info *sta = rx->sta;
  780. struct tid_ampdu_rx *tid_agg_rx;
  781. u16 sc;
  782. u8 tid, ack_policy;
  783. if (!ieee80211_is_data_qos(hdr->frame_control))
  784. goto dont_reorder;
  785. /*
  786. * filter the QoS data rx stream according to
  787. * STA/TID and check if this STA/TID is on aggregation
  788. */
  789. if (!sta)
  790. goto dont_reorder;
  791. ack_policy = *ieee80211_get_qos_ctl(hdr) &
  792. IEEE80211_QOS_CTL_ACK_POLICY_MASK;
  793. tid = *ieee80211_get_qos_ctl(hdr) & IEEE80211_QOS_CTL_TID_MASK;
  794. tid_agg_rx = rcu_dereference(sta->ampdu_mlme.tid_rx[tid]);
  795. if (!tid_agg_rx)
  796. goto dont_reorder;
  797. /* qos null data frames are excluded */
  798. if (unlikely(hdr->frame_control & cpu_to_le16(IEEE80211_STYPE_NULLFUNC)))
  799. goto dont_reorder;
  800. /* not part of a BA session */
  801. if (ack_policy != IEEE80211_QOS_CTL_ACK_POLICY_BLOCKACK &&
  802. ack_policy != IEEE80211_QOS_CTL_ACK_POLICY_NORMAL)
  803. goto dont_reorder;
  804. /* not actually part of this BA session */
  805. if (!(status->rx_flags & IEEE80211_RX_RA_MATCH))
  806. goto dont_reorder;
  807. /* new, potentially un-ordered, ampdu frame - process it */
  808. /* reset session timer */
  809. if (tid_agg_rx->timeout)
  810. tid_agg_rx->last_rx = jiffies;
  811. /* if this mpdu is fragmented - terminate rx aggregation session */
  812. sc = le16_to_cpu(hdr->seq_ctrl);
  813. if (sc & IEEE80211_SCTL_FRAG) {
  814. skb->pkt_type = IEEE80211_SDATA_QUEUE_TYPE_FRAME;
  815. skb_queue_tail(&rx->sdata->skb_queue, skb);
  816. ieee80211_queue_work(&local->hw, &rx->sdata->work);
  817. return;
  818. }
  819. /*
  820. * No locking needed -- we will only ever process one
  821. * RX packet at a time, and thus own tid_agg_rx. All
  822. * other code manipulating it needs to (and does) make
  823. * sure that we cannot get to it any more before doing
  824. * anything with it.
  825. */
  826. if (ieee80211_sta_manage_reorder_buf(rx->sdata, tid_agg_rx, skb,
  827. frames))
  828. return;
  829. dont_reorder:
  830. __skb_queue_tail(frames, skb);
  831. }
  832. static ieee80211_rx_result debug_noinline
  833. ieee80211_rx_h_check(struct ieee80211_rx_data *rx)
  834. {
  835. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
  836. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
  837. /*
  838. * Drop duplicate 802.11 retransmissions
  839. * (IEEE 802.11-2012: 9.3.2.10 "Duplicate detection and recovery")
  840. */
  841. if (rx->skb->len >= 24 && rx->sta &&
  842. !ieee80211_is_ctl(hdr->frame_control) &&
  843. !ieee80211_is_qos_nullfunc(hdr->frame_control) &&
  844. !is_multicast_ether_addr(hdr->addr1)) {
  845. if (unlikely(ieee80211_has_retry(hdr->frame_control) &&
  846. rx->sta->last_seq_ctrl[rx->seqno_idx] ==
  847. hdr->seq_ctrl)) {
  848. if (status->rx_flags & IEEE80211_RX_RA_MATCH) {
  849. rx->local->dot11FrameDuplicateCount++;
  850. rx->sta->num_duplicates++;
  851. }
  852. return RX_DROP_UNUSABLE;
  853. } else
  854. rx->sta->last_seq_ctrl[rx->seqno_idx] = hdr->seq_ctrl;
  855. }
  856. if (unlikely(rx->skb->len < 16)) {
  857. I802_DEBUG_INC(rx->local->rx_handlers_drop_short);
  858. return RX_DROP_MONITOR;
  859. }
  860. /* Drop disallowed frame classes based on STA auth/assoc state;
  861. * IEEE 802.11, Chap 5.5.
  862. *
  863. * mac80211 filters only based on association state, i.e. it drops
  864. * Class 3 frames from not associated stations. hostapd sends
  865. * deauth/disassoc frames when needed. In addition, hostapd is
  866. * responsible for filtering on both auth and assoc states.
  867. */
  868. if (ieee80211_vif_is_mesh(&rx->sdata->vif))
  869. return ieee80211_rx_mesh_check(rx);
  870. if (unlikely((ieee80211_is_data(hdr->frame_control) ||
  871. ieee80211_is_pspoll(hdr->frame_control)) &&
  872. rx->sdata->vif.type != NL80211_IFTYPE_ADHOC &&
  873. rx->sdata->vif.type != NL80211_IFTYPE_WDS &&
  874. (!rx->sta || !test_sta_flag(rx->sta, WLAN_STA_ASSOC)))) {
  875. /*
  876. * accept port control frames from the AP even when it's not
  877. * yet marked ASSOC to prevent a race where we don't set the
  878. * assoc bit quickly enough before it sends the first frame
  879. */
  880. if (rx->sta && rx->sdata->vif.type == NL80211_IFTYPE_STATION &&
  881. ieee80211_is_data_present(hdr->frame_control)) {
  882. unsigned int hdrlen;
  883. __be16 ethertype;
  884. hdrlen = ieee80211_hdrlen(hdr->frame_control);
  885. if (rx->skb->len < hdrlen + 8)
  886. return RX_DROP_MONITOR;
  887. skb_copy_bits(rx->skb, hdrlen + 6, &ethertype, 2);
  888. if (ethertype == rx->sdata->control_port_protocol)
  889. return RX_CONTINUE;
  890. }
  891. if (rx->sdata->vif.type == NL80211_IFTYPE_AP &&
  892. cfg80211_rx_spurious_frame(rx->sdata->dev,
  893. hdr->addr2,
  894. GFP_ATOMIC))
  895. return RX_DROP_UNUSABLE;
  896. return RX_DROP_MONITOR;
  897. }
  898. return RX_CONTINUE;
  899. }
  900. static ieee80211_rx_result debug_noinline
  901. ieee80211_rx_h_check_more_data(struct ieee80211_rx_data *rx)
  902. {
  903. struct ieee80211_local *local;
  904. struct ieee80211_hdr *hdr;
  905. struct sk_buff *skb;
  906. local = rx->local;
  907. skb = rx->skb;
  908. hdr = (struct ieee80211_hdr *) skb->data;
  909. if (!local->pspolling)
  910. return RX_CONTINUE;
  911. if (!ieee80211_has_fromds(hdr->frame_control))
  912. /* this is not from AP */
  913. return RX_CONTINUE;
  914. if (!ieee80211_is_data(hdr->frame_control))
  915. return RX_CONTINUE;
  916. if (!ieee80211_has_moredata(hdr->frame_control)) {
  917. /* AP has no more frames buffered for us */
  918. local->pspolling = false;
  919. return RX_CONTINUE;
  920. }
  921. /* more data bit is set, let's request a new frame from the AP */
  922. ieee80211_send_pspoll(local, rx->sdata);
  923. return RX_CONTINUE;
  924. }
  925. static void sta_ps_start(struct sta_info *sta)
  926. {
  927. struct ieee80211_sub_if_data *sdata = sta->sdata;
  928. struct ieee80211_local *local = sdata->local;
  929. struct ps_data *ps;
  930. if (sta->sdata->vif.type == NL80211_IFTYPE_AP ||
  931. sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
  932. ps = &sdata->bss->ps;
  933. else
  934. return;
  935. atomic_inc(&ps->num_sta_ps);
  936. set_sta_flag(sta, WLAN_STA_PS_STA);
  937. if (!(local->hw.flags & IEEE80211_HW_AP_LINK_PS))
  938. drv_sta_notify(local, sdata, STA_NOTIFY_SLEEP, &sta->sta);
  939. ps_dbg(sdata, "STA %pM aid %d enters power save mode\n",
  940. sta->sta.addr, sta->sta.aid);
  941. }
  942. static void sta_ps_end(struct sta_info *sta)
  943. {
  944. ps_dbg(sta->sdata, "STA %pM aid %d exits power save mode\n",
  945. sta->sta.addr, sta->sta.aid);
  946. if (test_sta_flag(sta, WLAN_STA_PS_DRIVER)) {
  947. ps_dbg(sta->sdata, "STA %pM aid %d driver-ps-blocked\n",
  948. sta->sta.addr, sta->sta.aid);
  949. return;
  950. }
  951. ieee80211_sta_ps_deliver_wakeup(sta);
  952. }
  953. int ieee80211_sta_ps_transition(struct ieee80211_sta *sta, bool start)
  954. {
  955. struct sta_info *sta_inf = container_of(sta, struct sta_info, sta);
  956. bool in_ps;
  957. WARN_ON(!(sta_inf->local->hw.flags & IEEE80211_HW_AP_LINK_PS));
  958. /* Don't let the same PS state be set twice */
  959. in_ps = test_sta_flag(sta_inf, WLAN_STA_PS_STA);
  960. if ((start && in_ps) || (!start && !in_ps))
  961. return -EINVAL;
  962. if (start)
  963. sta_ps_start(sta_inf);
  964. else
  965. sta_ps_end(sta_inf);
  966. return 0;
  967. }
  968. EXPORT_SYMBOL(ieee80211_sta_ps_transition);
  969. static ieee80211_rx_result debug_noinline
  970. ieee80211_rx_h_uapsd_and_pspoll(struct ieee80211_rx_data *rx)
  971. {
  972. struct ieee80211_sub_if_data *sdata = rx->sdata;
  973. struct ieee80211_hdr *hdr = (void *)rx->skb->data;
  974. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
  975. int tid, ac;
  976. if (!rx->sta || !(status->rx_flags & IEEE80211_RX_RA_MATCH))
  977. return RX_CONTINUE;
  978. if (sdata->vif.type != NL80211_IFTYPE_AP &&
  979. sdata->vif.type != NL80211_IFTYPE_AP_VLAN)
  980. return RX_CONTINUE;
  981. /*
  982. * The device handles station powersave, so don't do anything about
  983. * uAPSD and PS-Poll frames (the latter shouldn't even come up from
  984. * it to mac80211 since they're handled.)
  985. */
  986. if (sdata->local->hw.flags & IEEE80211_HW_AP_LINK_PS)
  987. return RX_CONTINUE;
  988. /*
  989. * Don't do anything if the station isn't already asleep. In
  990. * the uAPSD case, the station will probably be marked asleep,
  991. * in the PS-Poll case the station must be confused ...
  992. */
  993. if (!test_sta_flag(rx->sta, WLAN_STA_PS_STA))
  994. return RX_CONTINUE;
  995. if (unlikely(ieee80211_is_pspoll(hdr->frame_control))) {
  996. if (!test_sta_flag(rx->sta, WLAN_STA_SP)) {
  997. if (!test_sta_flag(rx->sta, WLAN_STA_PS_DRIVER))
  998. ieee80211_sta_ps_deliver_poll_response(rx->sta);
  999. else
  1000. set_sta_flag(rx->sta, WLAN_STA_PSPOLL);
  1001. }
  1002. /* Free PS Poll skb here instead of returning RX_DROP that would
  1003. * count as an dropped frame. */
  1004. dev_kfree_skb(rx->skb);
  1005. return RX_QUEUED;
  1006. } else if (!ieee80211_has_morefrags(hdr->frame_control) &&
  1007. !(status->rx_flags & IEEE80211_RX_DEFERRED_RELEASE) &&
  1008. ieee80211_has_pm(hdr->frame_control) &&
  1009. (ieee80211_is_data_qos(hdr->frame_control) ||
  1010. ieee80211_is_qos_nullfunc(hdr->frame_control))) {
  1011. tid = *ieee80211_get_qos_ctl(hdr) & IEEE80211_QOS_CTL_TID_MASK;
  1012. ac = ieee802_1d_to_ac[tid & 7];
  1013. /*
  1014. * If this AC is not trigger-enabled do nothing.
  1015. *
  1016. * NB: This could/should check a separate bitmap of trigger-
  1017. * enabled queues, but for now we only implement uAPSD w/o
  1018. * TSPEC changes to the ACs, so they're always the same.
  1019. */
  1020. if (!(rx->sta->sta.uapsd_queues & BIT(ac)))
  1021. return RX_CONTINUE;
  1022. /* if we are in a service period, do nothing */
  1023. if (test_sta_flag(rx->sta, WLAN_STA_SP))
  1024. return RX_CONTINUE;
  1025. if (!test_sta_flag(rx->sta, WLAN_STA_PS_DRIVER))
  1026. ieee80211_sta_ps_deliver_uapsd(rx->sta);
  1027. else
  1028. set_sta_flag(rx->sta, WLAN_STA_UAPSD);
  1029. }
  1030. return RX_CONTINUE;
  1031. }
  1032. static ieee80211_rx_result debug_noinline
  1033. ieee80211_rx_h_sta_process(struct ieee80211_rx_data *rx)
  1034. {
  1035. struct sta_info *sta = rx->sta;
  1036. struct sk_buff *skb = rx->skb;
  1037. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
  1038. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
  1039. int i;
  1040. if (!sta)
  1041. return RX_CONTINUE;
  1042. /*
  1043. * Update last_rx only for IBSS packets which are for the current
  1044. * BSSID and for station already AUTHORIZED to avoid keeping the
  1045. * current IBSS network alive in cases where other STAs start
  1046. * using different BSSID. This will also give the station another
  1047. * chance to restart the authentication/authorization in case
  1048. * something went wrong the first time.
  1049. */
  1050. if (rx->sdata->vif.type == NL80211_IFTYPE_ADHOC) {
  1051. u8 *bssid = ieee80211_get_bssid(hdr, rx->skb->len,
  1052. NL80211_IFTYPE_ADHOC);
  1053. if (ether_addr_equal(bssid, rx->sdata->u.ibss.bssid) &&
  1054. test_sta_flag(sta, WLAN_STA_AUTHORIZED)) {
  1055. sta->last_rx = jiffies;
  1056. if (ieee80211_is_data(hdr->frame_control)) {
  1057. sta->last_rx_rate_idx = status->rate_idx;
  1058. sta->last_rx_rate_flag = status->flag;
  1059. sta->last_rx_rate_vht_nss = status->vht_nss;
  1060. }
  1061. }
  1062. } else if (!is_multicast_ether_addr(hdr->addr1)) {
  1063. /*
  1064. * Mesh beacons will update last_rx when if they are found to
  1065. * match the current local configuration when processed.
  1066. */
  1067. sta->last_rx = jiffies;
  1068. if (ieee80211_is_data(hdr->frame_control)) {
  1069. sta->last_rx_rate_idx = status->rate_idx;
  1070. sta->last_rx_rate_flag = status->flag;
  1071. sta->last_rx_rate_vht_nss = status->vht_nss;
  1072. }
  1073. }
  1074. if (!(status->rx_flags & IEEE80211_RX_RA_MATCH))
  1075. return RX_CONTINUE;
  1076. if (rx->sdata->vif.type == NL80211_IFTYPE_STATION)
  1077. ieee80211_sta_rx_notify(rx->sdata, hdr);
  1078. sta->rx_fragments++;
  1079. sta->rx_bytes += rx->skb->len;
  1080. if (!(status->flag & RX_FLAG_NO_SIGNAL_VAL)) {
  1081. sta->last_signal = status->signal;
  1082. ewma_add(&sta->avg_signal, -status->signal);
  1083. }
  1084. if (status->chains) {
  1085. sta->chains = status->chains;
  1086. for (i = 0; i < ARRAY_SIZE(status->chain_signal); i++) {
  1087. int signal = status->chain_signal[i];
  1088. if (!(status->chains & BIT(i)))
  1089. continue;
  1090. sta->chain_signal_last[i] = signal;
  1091. ewma_add(&sta->chain_signal_avg[i], -signal);
  1092. }
  1093. }
  1094. /*
  1095. * Change STA power saving mode only at the end of a frame
  1096. * exchange sequence.
  1097. */
  1098. if (!(sta->local->hw.flags & IEEE80211_HW_AP_LINK_PS) &&
  1099. !ieee80211_has_morefrags(hdr->frame_control) &&
  1100. !(status->rx_flags & IEEE80211_RX_DEFERRED_RELEASE) &&
  1101. (rx->sdata->vif.type == NL80211_IFTYPE_AP ||
  1102. rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN)) {
  1103. if (test_sta_flag(sta, WLAN_STA_PS_STA)) {
  1104. /*
  1105. * Ignore doze->wake transitions that are
  1106. * indicated by non-data frames, the standard
  1107. * is unclear here, but for example going to
  1108. * PS mode and then scanning would cause a
  1109. * doze->wake transition for the probe request,
  1110. * and that is clearly undesirable.
  1111. */
  1112. if (ieee80211_is_data(hdr->frame_control) &&
  1113. !ieee80211_has_pm(hdr->frame_control))
  1114. sta_ps_end(sta);
  1115. } else {
  1116. if (ieee80211_has_pm(hdr->frame_control))
  1117. sta_ps_start(sta);
  1118. }
  1119. }
  1120. /* mesh power save support */
  1121. if (ieee80211_vif_is_mesh(&rx->sdata->vif))
  1122. ieee80211_mps_rx_h_sta_process(sta, hdr);
  1123. /*
  1124. * Drop (qos-)data::nullfunc frames silently, since they
  1125. * are used only to control station power saving mode.
  1126. */
  1127. if (ieee80211_is_nullfunc(hdr->frame_control) ||
  1128. ieee80211_is_qos_nullfunc(hdr->frame_control)) {
  1129. I802_DEBUG_INC(rx->local->rx_handlers_drop_nullfunc);
  1130. /*
  1131. * If we receive a 4-addr nullfunc frame from a STA
  1132. * that was not moved to a 4-addr STA vlan yet send
  1133. * the event to userspace and for older hostapd drop
  1134. * the frame to the monitor interface.
  1135. */
  1136. if (ieee80211_has_a4(hdr->frame_control) &&
  1137. (rx->sdata->vif.type == NL80211_IFTYPE_AP ||
  1138. (rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
  1139. !rx->sdata->u.vlan.sta))) {
  1140. if (!test_and_set_sta_flag(sta, WLAN_STA_4ADDR_EVENT))
  1141. cfg80211_rx_unexpected_4addr_frame(
  1142. rx->sdata->dev, sta->sta.addr,
  1143. GFP_ATOMIC);
  1144. return RX_DROP_MONITOR;
  1145. }
  1146. /*
  1147. * Update counter and free packet here to avoid
  1148. * counting this as a dropped packed.
  1149. */
  1150. sta->rx_packets++;
  1151. dev_kfree_skb(rx->skb);
  1152. return RX_QUEUED;
  1153. }
  1154. return RX_CONTINUE;
  1155. } /* ieee80211_rx_h_sta_process */
  1156. static ieee80211_rx_result debug_noinline
  1157. ieee80211_rx_h_decrypt(struct ieee80211_rx_data *rx)
  1158. {
  1159. struct sk_buff *skb = rx->skb;
  1160. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
  1161. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
  1162. int keyidx;
  1163. int hdrlen;
  1164. ieee80211_rx_result result = RX_DROP_UNUSABLE;
  1165. struct ieee80211_key *sta_ptk = NULL;
  1166. int mmie_keyidx = -1;
  1167. __le16 fc;
  1168. /*
  1169. * Key selection 101
  1170. *
  1171. * There are four types of keys:
  1172. * - GTK (group keys)
  1173. * - IGTK (group keys for management frames)
  1174. * - PTK (pairwise keys)
  1175. * - STK (station-to-station pairwise keys)
  1176. *
  1177. * When selecting a key, we have to distinguish between multicast
  1178. * (including broadcast) and unicast frames, the latter can only
  1179. * use PTKs and STKs while the former always use GTKs and IGTKs.
  1180. * Unless, of course, actual WEP keys ("pre-RSNA") are used, then
  1181. * unicast frames can also use key indices like GTKs. Hence, if we
  1182. * don't have a PTK/STK we check the key index for a WEP key.
  1183. *
  1184. * Note that in a regular BSS, multicast frames are sent by the
  1185. * AP only, associated stations unicast the frame to the AP first
  1186. * which then multicasts it on their behalf.
  1187. *
  1188. * There is also a slight problem in IBSS mode: GTKs are negotiated
  1189. * with each station, that is something we don't currently handle.
  1190. * The spec seems to expect that one negotiates the same key with
  1191. * every station but there's no such requirement; VLANs could be
  1192. * possible.
  1193. */
  1194. /*
  1195. * No point in finding a key and decrypting if the frame is neither
  1196. * addressed to us nor a multicast frame.
  1197. */
  1198. if (!(status->rx_flags & IEEE80211_RX_RA_MATCH))
  1199. return RX_CONTINUE;
  1200. /* start without a key */
  1201. rx->key = NULL;
  1202. if (rx->sta)
  1203. sta_ptk = rcu_dereference(rx->sta->ptk);
  1204. fc = hdr->frame_control;
  1205. if (!ieee80211_has_protected(fc))
  1206. mmie_keyidx = ieee80211_get_mmie_keyidx(rx->skb);
  1207. if (!is_multicast_ether_addr(hdr->addr1) && sta_ptk) {
  1208. rx->key = sta_ptk;
  1209. if ((status->flag & RX_FLAG_DECRYPTED) &&
  1210. (status->flag & RX_FLAG_IV_STRIPPED))
  1211. return RX_CONTINUE;
  1212. /* Skip decryption if the frame is not protected. */
  1213. if (!ieee80211_has_protected(fc))
  1214. return RX_CONTINUE;
  1215. } else if (mmie_keyidx >= 0) {
  1216. /* Broadcast/multicast robust management frame / BIP */
  1217. if ((status->flag & RX_FLAG_DECRYPTED) &&
  1218. (status->flag & RX_FLAG_IV_STRIPPED))
  1219. return RX_CONTINUE;
  1220. if (mmie_keyidx < NUM_DEFAULT_KEYS ||
  1221. mmie_keyidx >= NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS)
  1222. return RX_DROP_MONITOR; /* unexpected BIP keyidx */
  1223. if (rx->sta)
  1224. rx->key = rcu_dereference(rx->sta->gtk[mmie_keyidx]);
  1225. if (!rx->key)
  1226. rx->key = rcu_dereference(rx->sdata->keys[mmie_keyidx]);
  1227. } else if (!ieee80211_has_protected(fc)) {
  1228. /*
  1229. * The frame was not protected, so skip decryption. However, we
  1230. * need to set rx->key if there is a key that could have been
  1231. * used so that the frame may be dropped if encryption would
  1232. * have been expected.
  1233. */
  1234. struct ieee80211_key *key = NULL;
  1235. struct ieee80211_sub_if_data *sdata = rx->sdata;
  1236. int i;
  1237. if (ieee80211_is_mgmt(fc) &&
  1238. is_multicast_ether_addr(hdr->addr1) &&
  1239. (key = rcu_dereference(rx->sdata->default_mgmt_key)))
  1240. rx->key = key;
  1241. else {
  1242. if (rx->sta) {
  1243. for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
  1244. key = rcu_dereference(rx->sta->gtk[i]);
  1245. if (key)
  1246. break;
  1247. }
  1248. }
  1249. if (!key) {
  1250. for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
  1251. key = rcu_dereference(sdata->keys[i]);
  1252. if (key)
  1253. break;
  1254. }
  1255. }
  1256. if (key)
  1257. rx->key = key;
  1258. }
  1259. return RX_CONTINUE;
  1260. } else {
  1261. u8 keyid;
  1262. /*
  1263. * The device doesn't give us the IV so we won't be
  1264. * able to look up the key. That's ok though, we
  1265. * don't need to decrypt the frame, we just won't
  1266. * be able to keep statistics accurate.
  1267. * Except for key threshold notifications, should
  1268. * we somehow allow the driver to tell us which key
  1269. * the hardware used if this flag is set?
  1270. */
  1271. if ((status->flag & RX_FLAG_DECRYPTED) &&
  1272. (status->flag & RX_FLAG_IV_STRIPPED))
  1273. return RX_CONTINUE;
  1274. hdrlen = ieee80211_hdrlen(fc);
  1275. if (rx->skb->len < 8 + hdrlen)
  1276. return RX_DROP_UNUSABLE; /* TODO: count this? */
  1277. /*
  1278. * no need to call ieee80211_wep_get_keyidx,
  1279. * it verifies a bunch of things we've done already
  1280. */
  1281. skb_copy_bits(rx->skb, hdrlen + 3, &keyid, 1);
  1282. keyidx = keyid >> 6;
  1283. /* check per-station GTK first, if multicast packet */
  1284. if (is_multicast_ether_addr(hdr->addr1) && rx->sta)
  1285. rx->key = rcu_dereference(rx->sta->gtk[keyidx]);
  1286. /* if not found, try default key */
  1287. if (!rx->key) {
  1288. rx->key = rcu_dereference(rx->sdata->keys[keyidx]);
  1289. /*
  1290. * RSNA-protected unicast frames should always be
  1291. * sent with pairwise or station-to-station keys,
  1292. * but for WEP we allow using a key index as well.
  1293. */
  1294. if (rx->key &&
  1295. rx->key->conf.cipher != WLAN_CIPHER_SUITE_WEP40 &&
  1296. rx->key->conf.cipher != WLAN_CIPHER_SUITE_WEP104 &&
  1297. !is_multicast_ether_addr(hdr->addr1))
  1298. rx->key = NULL;
  1299. }
  1300. }
  1301. if (rx->key) {
  1302. if (unlikely(rx->key->flags & KEY_FLAG_TAINTED))
  1303. return RX_DROP_MONITOR;
  1304. rx->key->tx_rx_count++;
  1305. /* TODO: add threshold stuff again */
  1306. } else {
  1307. return RX_DROP_MONITOR;
  1308. }
  1309. switch (rx->key->conf.cipher) {
  1310. case WLAN_CIPHER_SUITE_WEP40:
  1311. case WLAN_CIPHER_SUITE_WEP104:
  1312. result = ieee80211_crypto_wep_decrypt(rx);
  1313. break;
  1314. case WLAN_CIPHER_SUITE_TKIP:
  1315. result = ieee80211_crypto_tkip_decrypt(rx);
  1316. break;
  1317. case WLAN_CIPHER_SUITE_CCMP:
  1318. result = ieee80211_crypto_ccmp_decrypt(rx);
  1319. break;
  1320. case WLAN_CIPHER_SUITE_AES_CMAC:
  1321. result = ieee80211_crypto_aes_cmac_decrypt(rx);
  1322. break;
  1323. default:
  1324. /*
  1325. * We can reach here only with HW-only algorithms
  1326. * but why didn't it decrypt the frame?!
  1327. */
  1328. return RX_DROP_UNUSABLE;
  1329. }
  1330. /* the hdr variable is invalid after the decrypt handlers */
  1331. /* either the frame has been decrypted or will be dropped */
  1332. status->flag |= RX_FLAG_DECRYPTED;
  1333. return result;
  1334. }
  1335. static inline struct ieee80211_fragment_entry *
  1336. ieee80211_reassemble_add(struct ieee80211_sub_if_data *sdata,
  1337. unsigned int frag, unsigned int seq, int rx_queue,
  1338. struct sk_buff **skb)
  1339. {
  1340. struct ieee80211_fragment_entry *entry;
  1341. entry = &sdata->fragments[sdata->fragment_next++];
  1342. if (sdata->fragment_next >= IEEE80211_FRAGMENT_MAX)
  1343. sdata->fragment_next = 0;
  1344. if (!skb_queue_empty(&entry->skb_list))
  1345. __skb_queue_purge(&entry->skb_list);
  1346. __skb_queue_tail(&entry->skb_list, *skb); /* no need for locking */
  1347. *skb = NULL;
  1348. entry->first_frag_time = jiffies;
  1349. entry->seq = seq;
  1350. entry->rx_queue = rx_queue;
  1351. entry->last_frag = frag;
  1352. entry->ccmp = 0;
  1353. entry->extra_len = 0;
  1354. return entry;
  1355. }
  1356. static inline struct ieee80211_fragment_entry *
  1357. ieee80211_reassemble_find(struct ieee80211_sub_if_data *sdata,
  1358. unsigned int frag, unsigned int seq,
  1359. int rx_queue, struct ieee80211_hdr *hdr)
  1360. {
  1361. struct ieee80211_fragment_entry *entry;
  1362. int i, idx;
  1363. idx = sdata->fragment_next;
  1364. for (i = 0; i < IEEE80211_FRAGMENT_MAX; i++) {
  1365. struct ieee80211_hdr *f_hdr;
  1366. idx--;
  1367. if (idx < 0)
  1368. idx = IEEE80211_FRAGMENT_MAX - 1;
  1369. entry = &sdata->fragments[idx];
  1370. if (skb_queue_empty(&entry->skb_list) || entry->seq != seq ||
  1371. entry->rx_queue != rx_queue ||
  1372. entry->last_frag + 1 != frag)
  1373. continue;
  1374. f_hdr = (struct ieee80211_hdr *)entry->skb_list.next->data;
  1375. /*
  1376. * Check ftype and addresses are equal, else check next fragment
  1377. */
  1378. if (((hdr->frame_control ^ f_hdr->frame_control) &
  1379. cpu_to_le16(IEEE80211_FCTL_FTYPE)) ||
  1380. !ether_addr_equal(hdr->addr1, f_hdr->addr1) ||
  1381. !ether_addr_equal(hdr->addr2, f_hdr->addr2))
  1382. continue;
  1383. if (time_after(jiffies, entry->first_frag_time + 2 * HZ)) {
  1384. __skb_queue_purge(&entry->skb_list);
  1385. continue;
  1386. }
  1387. return entry;
  1388. }
  1389. return NULL;
  1390. }
  1391. static ieee80211_rx_result debug_noinline
  1392. ieee80211_rx_h_defragment(struct ieee80211_rx_data *rx)
  1393. {
  1394. struct ieee80211_hdr *hdr;
  1395. u16 sc;
  1396. __le16 fc;
  1397. unsigned int frag, seq;
  1398. struct ieee80211_fragment_entry *entry;
  1399. struct sk_buff *skb;
  1400. struct ieee80211_rx_status *status;
  1401. hdr = (struct ieee80211_hdr *)rx->skb->data;
  1402. fc = hdr->frame_control;
  1403. if (ieee80211_is_ctl(fc))
  1404. return RX_CONTINUE;
  1405. sc = le16_to_cpu(hdr->seq_ctrl);
  1406. frag = sc & IEEE80211_SCTL_FRAG;
  1407. if (likely((!ieee80211_has_morefrags(fc) && frag == 0) ||
  1408. is_multicast_ether_addr(hdr->addr1))) {
  1409. /* not fragmented */
  1410. goto out;
  1411. }
  1412. I802_DEBUG_INC(rx->local->rx_handlers_fragments);
  1413. if (skb_linearize(rx->skb))
  1414. return RX_DROP_UNUSABLE;
  1415. /*
  1416. * skb_linearize() might change the skb->data and
  1417. * previously cached variables (in this case, hdr) need to
  1418. * be refreshed with the new data.
  1419. */
  1420. hdr = (struct ieee80211_hdr *)rx->skb->data;
  1421. seq = (sc & IEEE80211_SCTL_SEQ) >> 4;
  1422. if (frag == 0) {
  1423. /* This is the first fragment of a new frame. */
  1424. entry = ieee80211_reassemble_add(rx->sdata, frag, seq,
  1425. rx->seqno_idx, &(rx->skb));
  1426. if (rx->key && rx->key->conf.cipher == WLAN_CIPHER_SUITE_CCMP &&
  1427. ieee80211_has_protected(fc)) {
  1428. int queue = rx->security_idx;
  1429. /* Store CCMP PN so that we can verify that the next
  1430. * fragment has a sequential PN value. */
  1431. entry->ccmp = 1;
  1432. memcpy(entry->last_pn,
  1433. rx->key->u.ccmp.rx_pn[queue],
  1434. IEEE80211_CCMP_PN_LEN);
  1435. }
  1436. return RX_QUEUED;
  1437. }
  1438. /* This is a fragment for a frame that should already be pending in
  1439. * fragment cache. Add this fragment to the end of the pending entry.
  1440. */
  1441. entry = ieee80211_reassemble_find(rx->sdata, frag, seq,
  1442. rx->seqno_idx, hdr);
  1443. if (!entry) {
  1444. I802_DEBUG_INC(rx->local->rx_handlers_drop_defrag);
  1445. return RX_DROP_MONITOR;
  1446. }
  1447. /* Verify that MPDUs within one MSDU have sequential PN values.
  1448. * (IEEE 802.11i, 8.3.3.4.5) */
  1449. if (entry->ccmp) {
  1450. int i;
  1451. u8 pn[IEEE80211_CCMP_PN_LEN], *rpn;
  1452. int queue;
  1453. if (!rx->key || rx->key->conf.cipher != WLAN_CIPHER_SUITE_CCMP)
  1454. return RX_DROP_UNUSABLE;
  1455. memcpy(pn, entry->last_pn, IEEE80211_CCMP_PN_LEN);
  1456. for (i = IEEE80211_CCMP_PN_LEN - 1; i >= 0; i--) {
  1457. pn[i]++;
  1458. if (pn[i])
  1459. break;
  1460. }
  1461. queue = rx->security_idx;
  1462. rpn = rx->key->u.ccmp.rx_pn[queue];
  1463. if (memcmp(pn, rpn, IEEE80211_CCMP_PN_LEN))
  1464. return RX_DROP_UNUSABLE;
  1465. memcpy(entry->last_pn, pn, IEEE80211_CCMP_PN_LEN);
  1466. }
  1467. skb_pull(rx->skb, ieee80211_hdrlen(fc));
  1468. __skb_queue_tail(&entry->skb_list, rx->skb);
  1469. entry->last_frag = frag;
  1470. entry->extra_len += rx->skb->len;
  1471. if (ieee80211_has_morefrags(fc)) {
  1472. rx->skb = NULL;
  1473. return RX_QUEUED;
  1474. }
  1475. rx->skb = __skb_dequeue(&entry->skb_list);
  1476. if (skb_tailroom(rx->skb) < entry->extra_len) {
  1477. I802_DEBUG_INC(rx->local->rx_expand_skb_head2);
  1478. if (unlikely(pskb_expand_head(rx->skb, 0, entry->extra_len,
  1479. GFP_ATOMIC))) {
  1480. I802_DEBUG_INC(rx->local->rx_handlers_drop_defrag);
  1481. __skb_queue_purge(&entry->skb_list);
  1482. return RX_DROP_UNUSABLE;
  1483. }
  1484. }
  1485. while ((skb = __skb_dequeue(&entry->skb_list))) {
  1486. memcpy(skb_put(rx->skb, skb->len), skb->data, skb->len);
  1487. dev_kfree_skb(skb);
  1488. }
  1489. /* Complete frame has been reassembled - process it now */
  1490. status = IEEE80211_SKB_RXCB(rx->skb);
  1491. status->rx_flags |= IEEE80211_RX_FRAGMENTED;
  1492. out:
  1493. if (rx->sta)
  1494. rx->sta->rx_packets++;
  1495. if (is_multicast_ether_addr(hdr->addr1))
  1496. rx->local->dot11MulticastReceivedFrameCount++;
  1497. else
  1498. ieee80211_led_rx(rx->local);
  1499. return RX_CONTINUE;
  1500. }
  1501. static int ieee80211_802_1x_port_control(struct ieee80211_rx_data *rx)
  1502. {
  1503. if (unlikely(!rx->sta || !test_sta_flag(rx->sta, WLAN_STA_AUTHORIZED)))
  1504. return -EACCES;
  1505. return 0;
  1506. }
  1507. static int ieee80211_drop_unencrypted(struct ieee80211_rx_data *rx, __le16 fc)
  1508. {
  1509. struct sk_buff *skb = rx->skb;
  1510. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
  1511. /*
  1512. * Pass through unencrypted frames if the hardware has
  1513. * decrypted them already.
  1514. */
  1515. if (status->flag & RX_FLAG_DECRYPTED)
  1516. return 0;
  1517. /* Drop unencrypted frames if key is set. */
  1518. if (unlikely(!ieee80211_has_protected(fc) &&
  1519. !ieee80211_is_nullfunc(fc) &&
  1520. ieee80211_is_data(fc) &&
  1521. (rx->key || rx->sdata->drop_unencrypted)))
  1522. return -EACCES;
  1523. return 0;
  1524. }
  1525. static int ieee80211_drop_unencrypted_mgmt(struct ieee80211_rx_data *rx)
  1526. {
  1527. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
  1528. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
  1529. __le16 fc = hdr->frame_control;
  1530. /*
  1531. * Pass through unencrypted frames if the hardware has
  1532. * decrypted them already.
  1533. */
  1534. if (status->flag & RX_FLAG_DECRYPTED)
  1535. return 0;
  1536. if (rx->sta && test_sta_flag(rx->sta, WLAN_STA_MFP)) {
  1537. if (unlikely(!ieee80211_has_protected(fc) &&
  1538. ieee80211_is_unicast_robust_mgmt_frame(rx->skb) &&
  1539. rx->key)) {
  1540. if (ieee80211_is_deauth(fc) ||
  1541. ieee80211_is_disassoc(fc))
  1542. cfg80211_rx_unprot_mlme_mgmt(rx->sdata->dev,
  1543. rx->skb->data,
  1544. rx->skb->len);
  1545. return -EACCES;
  1546. }
  1547. /* BIP does not use Protected field, so need to check MMIE */
  1548. if (unlikely(ieee80211_is_multicast_robust_mgmt_frame(rx->skb) &&
  1549. ieee80211_get_mmie_keyidx(rx->skb) < 0)) {
  1550. if (ieee80211_is_deauth(fc) ||
  1551. ieee80211_is_disassoc(fc))
  1552. cfg80211_rx_unprot_mlme_mgmt(rx->sdata->dev,
  1553. rx->skb->data,
  1554. rx->skb->len);
  1555. return -EACCES;
  1556. }
  1557. /*
  1558. * When using MFP, Action frames are not allowed prior to
  1559. * having configured keys.
  1560. */
  1561. if (unlikely(ieee80211_is_action(fc) && !rx->key &&
  1562. ieee80211_is_robust_mgmt_frame(
  1563. (struct ieee80211_hdr *) rx->skb->data)))
  1564. return -EACCES;
  1565. }
  1566. return 0;
  1567. }
  1568. static int
  1569. __ieee80211_data_to_8023(struct ieee80211_rx_data *rx, bool *port_control)
  1570. {
  1571. struct ieee80211_sub_if_data *sdata = rx->sdata;
  1572. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
  1573. bool check_port_control = false;
  1574. struct ethhdr *ehdr;
  1575. int ret;
  1576. *port_control = false;
  1577. if (ieee80211_has_a4(hdr->frame_control) &&
  1578. sdata->vif.type == NL80211_IFTYPE_AP_VLAN && !sdata->u.vlan.sta)
  1579. return -1;
  1580. if (sdata->vif.type == NL80211_IFTYPE_STATION &&
  1581. !!sdata->u.mgd.use_4addr != !!ieee80211_has_a4(hdr->frame_control)) {
  1582. if (!sdata->u.mgd.use_4addr)
  1583. return -1;
  1584. else
  1585. check_port_control = true;
  1586. }
  1587. if (is_multicast_ether_addr(hdr->addr1) &&
  1588. sdata->vif.type == NL80211_IFTYPE_AP_VLAN && sdata->u.vlan.sta)
  1589. return -1;
  1590. ret = ieee80211_data_to_8023(rx->skb, sdata->vif.addr, sdata->vif.type);
  1591. if (ret < 0)
  1592. return ret;
  1593. ehdr = (struct ethhdr *) rx->skb->data;
  1594. if (ehdr->h_proto == rx->sdata->control_port_protocol)
  1595. *port_control = true;
  1596. else if (check_port_control)
  1597. return -1;
  1598. return 0;
  1599. }
  1600. /*
  1601. * requires that rx->skb is a frame with ethernet header
  1602. */
  1603. static bool ieee80211_frame_allowed(struct ieee80211_rx_data *rx, __le16 fc)
  1604. {
  1605. static const u8 pae_group_addr[ETH_ALEN] __aligned(2)
  1606. = { 0x01, 0x80, 0xC2, 0x00, 0x00, 0x03 };
  1607. struct ethhdr *ehdr = (struct ethhdr *) rx->skb->data;
  1608. /*
  1609. * Allow EAPOL frames to us/the PAE group address regardless
  1610. * of whether the frame was encrypted or not.
  1611. */
  1612. if (ehdr->h_proto == rx->sdata->control_port_protocol &&
  1613. (ether_addr_equal(ehdr->h_dest, rx->sdata->vif.addr) ||
  1614. ether_addr_equal(ehdr->h_dest, pae_group_addr)))
  1615. return true;
  1616. if (ieee80211_802_1x_port_control(rx) ||
  1617. ieee80211_drop_unencrypted(rx, fc))
  1618. return false;
  1619. return true;
  1620. }
  1621. /*
  1622. * requires that rx->skb is a frame with ethernet header
  1623. */
  1624. static void
  1625. ieee80211_deliver_skb(struct ieee80211_rx_data *rx)
  1626. {
  1627. struct ieee80211_sub_if_data *sdata = rx->sdata;
  1628. struct net_device *dev = sdata->dev;
  1629. struct sk_buff *skb, *xmit_skb;
  1630. struct ethhdr *ehdr = (struct ethhdr *) rx->skb->data;
  1631. struct sta_info *dsta;
  1632. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
  1633. skb = rx->skb;
  1634. xmit_skb = NULL;
  1635. if ((sdata->vif.type == NL80211_IFTYPE_AP ||
  1636. sdata->vif.type == NL80211_IFTYPE_AP_VLAN) &&
  1637. !(sdata->flags & IEEE80211_SDATA_DONT_BRIDGE_PACKETS) &&
  1638. (status->rx_flags & IEEE80211_RX_RA_MATCH) &&
  1639. (sdata->vif.type != NL80211_IFTYPE_AP_VLAN || !sdata->u.vlan.sta)) {
  1640. if (is_multicast_ether_addr(ehdr->h_dest)) {
  1641. /*
  1642. * send multicast frames both to higher layers in
  1643. * local net stack and back to the wireless medium
  1644. */
  1645. xmit_skb = skb_copy(skb, GFP_ATOMIC);
  1646. if (!xmit_skb)
  1647. net_info_ratelimited("%s: failed to clone multicast frame\n",
  1648. dev->name);
  1649. } else {
  1650. dsta = sta_info_get(sdata, skb->data);
  1651. if (dsta) {
  1652. /*
  1653. * The destination station is associated to
  1654. * this AP (in this VLAN), so send the frame
  1655. * directly to it and do not pass it to local
  1656. * net stack.
  1657. */
  1658. xmit_skb = skb;
  1659. skb = NULL;
  1660. }
  1661. }
  1662. }
  1663. if (skb) {
  1664. int align __maybe_unused;
  1665. #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
  1666. /*
  1667. * 'align' will only take the values 0 or 2 here
  1668. * since all frames are required to be aligned
  1669. * to 2-byte boundaries when being passed to
  1670. * mac80211; the code here works just as well if
  1671. * that isn't true, but mac80211 assumes it can
  1672. * access fields as 2-byte aligned (e.g. for
  1673. * compare_ether_addr)
  1674. */
  1675. align = ((unsigned long)(skb->data + sizeof(struct ethhdr))) & 3;
  1676. if (align) {
  1677. if (WARN_ON(skb_headroom(skb) < 3)) {
  1678. dev_kfree_skb(skb);
  1679. skb = NULL;
  1680. } else {
  1681. u8 *data = skb->data;
  1682. size_t len = skb_headlen(skb);
  1683. skb->data -= align;
  1684. memmove(skb->data, data, len);
  1685. skb_set_tail_pointer(skb, len);
  1686. }
  1687. }
  1688. #endif
  1689. if (skb) {
  1690. /* deliver to local stack */
  1691. skb->protocol = eth_type_trans(skb, dev);
  1692. memset(skb->cb, 0, sizeof(skb->cb));
  1693. netif_receive_skb(skb);
  1694. }
  1695. }
  1696. if (xmit_skb) {
  1697. /*
  1698. * Send to wireless media and increase priority by 256 to
  1699. * keep the received priority instead of reclassifying
  1700. * the frame (see cfg80211_classify8021d).
  1701. */
  1702. xmit_skb->priority += 256;
  1703. xmit_skb->protocol = htons(ETH_P_802_3);
  1704. skb_reset_network_header(xmit_skb);
  1705. skb_reset_mac_header(xmit_skb);
  1706. dev_queue_xmit(xmit_skb);
  1707. }
  1708. }
  1709. static ieee80211_rx_result debug_noinline
  1710. ieee80211_rx_h_amsdu(struct ieee80211_rx_data *rx)
  1711. {
  1712. struct net_device *dev = rx->sdata->dev;
  1713. struct sk_buff *skb = rx->skb;
  1714. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
  1715. __le16 fc = hdr->frame_control;
  1716. struct sk_buff_head frame_list;
  1717. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
  1718. if (unlikely(!ieee80211_is_data(fc)))
  1719. return RX_CONTINUE;
  1720. if (unlikely(!ieee80211_is_data_present(fc)))
  1721. return RX_DROP_MONITOR;
  1722. if (!(status->rx_flags & IEEE80211_RX_AMSDU))
  1723. return RX_CONTINUE;
  1724. if (ieee80211_has_a4(hdr->frame_control) &&
  1725. rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
  1726. !rx->sdata->u.vlan.sta)
  1727. return RX_DROP_UNUSABLE;
  1728. if (is_multicast_ether_addr(hdr->addr1) &&
  1729. ((rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
  1730. rx->sdata->u.vlan.sta) ||
  1731. (rx->sdata->vif.type == NL80211_IFTYPE_STATION &&
  1732. rx->sdata->u.mgd.use_4addr)))
  1733. return RX_DROP_UNUSABLE;
  1734. skb->dev = dev;
  1735. __skb_queue_head_init(&frame_list);
  1736. if (skb_linearize(skb))
  1737. return RX_DROP_UNUSABLE;
  1738. ieee80211_amsdu_to_8023s(skb, &frame_list, dev->dev_addr,
  1739. rx->sdata->vif.type,
  1740. rx->local->hw.extra_tx_headroom, true);
  1741. while (!skb_queue_empty(&frame_list)) {
  1742. rx->skb = __skb_dequeue(&frame_list);
  1743. if (!ieee80211_frame_allowed(rx, fc)) {
  1744. dev_kfree_skb(rx->skb);
  1745. continue;
  1746. }
  1747. dev->stats.rx_packets++;
  1748. dev->stats.rx_bytes += rx->skb->len;
  1749. ieee80211_deliver_skb(rx);
  1750. }
  1751. return RX_QUEUED;
  1752. }
  1753. #ifdef CONFIG_MAC80211_MESH
  1754. static ieee80211_rx_result
  1755. ieee80211_rx_h_mesh_fwding(struct ieee80211_rx_data *rx)
  1756. {
  1757. struct ieee80211_hdr *fwd_hdr, *hdr;
  1758. struct ieee80211_tx_info *info;
  1759. struct ieee80211s_hdr *mesh_hdr;
  1760. struct sk_buff *skb = rx->skb, *fwd_skb;
  1761. struct ieee80211_local *local = rx->local;
  1762. struct ieee80211_sub_if_data *sdata = rx->sdata;
  1763. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
  1764. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  1765. __le16 reason = cpu_to_le16(WLAN_REASON_MESH_PATH_NOFORWARD);
  1766. u16 q, hdrlen;
  1767. hdr = (struct ieee80211_hdr *) skb->data;
  1768. hdrlen = ieee80211_hdrlen(hdr->frame_control);
  1769. /* make sure fixed part of mesh header is there, also checks skb len */
  1770. if (!pskb_may_pull(rx->skb, hdrlen + 6))
  1771. return RX_DROP_MONITOR;
  1772. mesh_hdr = (struct ieee80211s_hdr *) (skb->data + hdrlen);
  1773. /* make sure full mesh header is there, also checks skb len */
  1774. if (!pskb_may_pull(rx->skb,
  1775. hdrlen + ieee80211_get_mesh_hdrlen(mesh_hdr)))
  1776. return RX_DROP_MONITOR;
  1777. /* reload pointers */
  1778. hdr = (struct ieee80211_hdr *) skb->data;
  1779. mesh_hdr = (struct ieee80211s_hdr *) (skb->data + hdrlen);
  1780. /* frame is in RMC, don't forward */
  1781. if (ieee80211_is_data(hdr->frame_control) &&
  1782. is_multicast_ether_addr(hdr->addr1) &&
  1783. mesh_rmc_check(rx->sdata, hdr->addr3, mesh_hdr))
  1784. return RX_DROP_MONITOR;
  1785. if (!ieee80211_is_data(hdr->frame_control) ||
  1786. !(status->rx_flags & IEEE80211_RX_RA_MATCH))
  1787. return RX_CONTINUE;
  1788. if (!mesh_hdr->ttl)
  1789. return RX_DROP_MONITOR;
  1790. if (mesh_hdr->flags & MESH_FLAGS_AE) {
  1791. struct mesh_path *mppath;
  1792. char *proxied_addr;
  1793. char *mpp_addr;
  1794. if (is_multicast_ether_addr(hdr->addr1)) {
  1795. mpp_addr = hdr->addr3;
  1796. proxied_addr = mesh_hdr->eaddr1;
  1797. } else if (mesh_hdr->flags & MESH_FLAGS_AE_A5_A6) {
  1798. /* has_a4 already checked in ieee80211_rx_mesh_check */
  1799. mpp_addr = hdr->addr4;
  1800. proxied_addr = mesh_hdr->eaddr2;
  1801. } else {
  1802. return RX_DROP_MONITOR;
  1803. }
  1804. rcu_read_lock();
  1805. mppath = mpp_path_lookup(sdata, proxied_addr);
  1806. if (!mppath) {
  1807. mpp_path_add(sdata, proxied_addr, mpp_addr);
  1808. } else {
  1809. spin_lock_bh(&mppath->state_lock);
  1810. if (!ether_addr_equal(mppath->mpp, mpp_addr))
  1811. memcpy(mppath->mpp, mpp_addr, ETH_ALEN);
  1812. spin_unlock_bh(&mppath->state_lock);
  1813. }
  1814. rcu_read_unlock();
  1815. }
  1816. /* Frame has reached destination. Don't forward */
  1817. if (!is_multicast_ether_addr(hdr->addr1) &&
  1818. ether_addr_equal(sdata->vif.addr, hdr->addr3))
  1819. return RX_CONTINUE;
  1820. q = ieee80211_select_queue_80211(sdata, skb, hdr);
  1821. if (ieee80211_queue_stopped(&local->hw, q)) {
  1822. IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, dropped_frames_congestion);
  1823. return RX_DROP_MONITOR;
  1824. }
  1825. skb_set_queue_mapping(skb, q);
  1826. if (!--mesh_hdr->ttl) {
  1827. IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, dropped_frames_ttl);
  1828. goto out;
  1829. }
  1830. if (!ifmsh->mshcfg.dot11MeshForwarding)
  1831. goto out;
  1832. fwd_skb = skb_copy(skb, GFP_ATOMIC);
  1833. if (!fwd_skb) {
  1834. net_info_ratelimited("%s: failed to clone mesh frame\n",
  1835. sdata->name);
  1836. goto out;
  1837. }
  1838. fwd_hdr = (struct ieee80211_hdr *) fwd_skb->data;
  1839. fwd_hdr->frame_control &= ~cpu_to_le16(IEEE80211_FCTL_RETRY);
  1840. info = IEEE80211_SKB_CB(fwd_skb);
  1841. memset(info, 0, sizeof(*info));
  1842. info->flags |= IEEE80211_TX_INTFL_NEED_TXPROCESSING;
  1843. info->control.vif = &rx->sdata->vif;
  1844. info->control.jiffies = jiffies;
  1845. if (is_multicast_ether_addr(fwd_hdr->addr1)) {
  1846. IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, fwded_mcast);
  1847. memcpy(fwd_hdr->addr2, sdata->vif.addr, ETH_ALEN);
  1848. /* update power mode indication when forwarding */
  1849. ieee80211_mps_set_frame_flags(sdata, NULL, fwd_hdr);
  1850. } else if (!mesh_nexthop_lookup(sdata, fwd_skb)) {
  1851. /* mesh power mode flags updated in mesh_nexthop_lookup */
  1852. IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, fwded_unicast);
  1853. } else {
  1854. /* unable to resolve next hop */
  1855. mesh_path_error_tx(sdata, ifmsh->mshcfg.element_ttl,
  1856. fwd_hdr->addr3, 0, reason, fwd_hdr->addr2);
  1857. IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, dropped_frames_no_route);
  1858. kfree_skb(fwd_skb);
  1859. return RX_DROP_MONITOR;
  1860. }
  1861. IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, fwded_frames);
  1862. ieee80211_add_pending_skb(local, fwd_skb);
  1863. out:
  1864. if (is_multicast_ether_addr(hdr->addr1) ||
  1865. sdata->dev->flags & IFF_PROMISC)
  1866. return RX_CONTINUE;
  1867. else
  1868. return RX_DROP_MONITOR;
  1869. }
  1870. #endif
  1871. static ieee80211_rx_result debug_noinline
  1872. ieee80211_rx_h_data(struct ieee80211_rx_data *rx)
  1873. {
  1874. struct ieee80211_sub_if_data *sdata = rx->sdata;
  1875. struct ieee80211_local *local = rx->local;
  1876. struct net_device *dev = sdata->dev;
  1877. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
  1878. __le16 fc = hdr->frame_control;
  1879. bool port_control;
  1880. int err;
  1881. if (unlikely(!ieee80211_is_data(hdr->frame_control)))
  1882. return RX_CONTINUE;
  1883. if (unlikely(!ieee80211_is_data_present(hdr->frame_control)))
  1884. return RX_DROP_MONITOR;
  1885. /*
  1886. * Send unexpected-4addr-frame event to hostapd. For older versions,
  1887. * also drop the frame to cooked monitor interfaces.
  1888. */
  1889. if (ieee80211_has_a4(hdr->frame_control) &&
  1890. sdata->vif.type == NL80211_IFTYPE_AP) {
  1891. if (rx->sta &&
  1892. !test_and_set_sta_flag(rx->sta, WLAN_STA_4ADDR_EVENT))
  1893. cfg80211_rx_unexpected_4addr_frame(
  1894. rx->sdata->dev, rx->sta->sta.addr, GFP_ATOMIC);
  1895. return RX_DROP_MONITOR;
  1896. }
  1897. err = __ieee80211_data_to_8023(rx, &port_control);
  1898. if (unlikely(err))
  1899. return RX_DROP_UNUSABLE;
  1900. if (!ieee80211_frame_allowed(rx, fc))
  1901. return RX_DROP_MONITOR;
  1902. if (rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
  1903. unlikely(port_control) && sdata->bss) {
  1904. sdata = container_of(sdata->bss, struct ieee80211_sub_if_data,
  1905. u.ap);
  1906. dev = sdata->dev;
  1907. rx->sdata = sdata;
  1908. }
  1909. rx->skb->dev = dev;
  1910. dev->stats.rx_packets++;
  1911. dev->stats.rx_bytes += rx->skb->len;
  1912. if (local->ps_sdata && local->hw.conf.dynamic_ps_timeout > 0 &&
  1913. !is_multicast_ether_addr(
  1914. ((struct ethhdr *)rx->skb->data)->h_dest) &&
  1915. (!local->scanning &&
  1916. !test_bit(SDATA_STATE_OFFCHANNEL, &sdata->state))) {
  1917. mod_timer(&local->dynamic_ps_timer, jiffies +
  1918. msecs_to_jiffies(local->hw.conf.dynamic_ps_timeout));
  1919. }
  1920. ieee80211_deliver_skb(rx);
  1921. return RX_QUEUED;
  1922. }
  1923. static ieee80211_rx_result debug_noinline
  1924. ieee80211_rx_h_ctrl(struct ieee80211_rx_data *rx, struct sk_buff_head *frames)
  1925. {
  1926. struct sk_buff *skb = rx->skb;
  1927. struct ieee80211_bar *bar = (struct ieee80211_bar *)skb->data;
  1928. struct tid_ampdu_rx *tid_agg_rx;
  1929. u16 start_seq_num;
  1930. u16 tid;
  1931. if (likely(!ieee80211_is_ctl(bar->frame_control)))
  1932. return RX_CONTINUE;
  1933. if (ieee80211_is_back_req(bar->frame_control)) {
  1934. struct {
  1935. __le16 control, start_seq_num;
  1936. } __packed bar_data;
  1937. if (!rx->sta)
  1938. return RX_DROP_MONITOR;
  1939. if (skb_copy_bits(skb, offsetof(struct ieee80211_bar, control),
  1940. &bar_data, sizeof(bar_data)))
  1941. return RX_DROP_MONITOR;
  1942. tid = le16_to_cpu(bar_data.control) >> 12;
  1943. tid_agg_rx = rcu_dereference(rx->sta->ampdu_mlme.tid_rx[tid]);
  1944. if (!tid_agg_rx)
  1945. return RX_DROP_MONITOR;
  1946. start_seq_num = le16_to_cpu(bar_data.start_seq_num) >> 4;
  1947. /* reset session timer */
  1948. if (tid_agg_rx->timeout)
  1949. mod_timer(&tid_agg_rx->session_timer,
  1950. TU_TO_EXP_TIME(tid_agg_rx->timeout));
  1951. spin_lock(&tid_agg_rx->reorder_lock);
  1952. /* release stored frames up to start of BAR */
  1953. ieee80211_release_reorder_frames(rx->sdata, tid_agg_rx,
  1954. start_seq_num, frames);
  1955. spin_unlock(&tid_agg_rx->reorder_lock);
  1956. kfree_skb(skb);
  1957. return RX_QUEUED;
  1958. }
  1959. /*
  1960. * After this point, we only want management frames,
  1961. * so we can drop all remaining control frames to
  1962. * cooked monitor interfaces.
  1963. */
  1964. return RX_DROP_MONITOR;
  1965. }
  1966. static void ieee80211_process_sa_query_req(struct ieee80211_sub_if_data *sdata,
  1967. struct ieee80211_mgmt *mgmt,
  1968. size_t len)
  1969. {
  1970. struct ieee80211_local *local = sdata->local;
  1971. struct sk_buff *skb;
  1972. struct ieee80211_mgmt *resp;
  1973. if (!ether_addr_equal(mgmt->da, sdata->vif.addr)) {
  1974. /* Not to own unicast address */
  1975. return;
  1976. }
  1977. if (!ether_addr_equal(mgmt->sa, sdata->u.mgd.bssid) ||
  1978. !ether_addr_equal(mgmt->bssid, sdata->u.mgd.bssid)) {
  1979. /* Not from the current AP or not associated yet. */
  1980. return;
  1981. }
  1982. if (len < 24 + 1 + sizeof(resp->u.action.u.sa_query)) {
  1983. /* Too short SA Query request frame */
  1984. return;
  1985. }
  1986. skb = dev_alloc_skb(sizeof(*resp) + local->hw.extra_tx_headroom);
  1987. if (skb == NULL)
  1988. return;
  1989. skb_reserve(skb, local->hw.extra_tx_headroom);
  1990. resp = (struct ieee80211_mgmt *) skb_put(skb, 24);
  1991. memset(resp, 0, 24);
  1992. memcpy(resp->da, mgmt->sa, ETH_ALEN);
  1993. memcpy(resp->sa, sdata->vif.addr, ETH_ALEN);
  1994. memcpy(resp->bssid, sdata->u.mgd.bssid, ETH_ALEN);
  1995. resp->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
  1996. IEEE80211_STYPE_ACTION);
  1997. skb_put(skb, 1 + sizeof(resp->u.action.u.sa_query));
  1998. resp->u.action.category = WLAN_CATEGORY_SA_QUERY;
  1999. resp->u.action.u.sa_query.action = WLAN_ACTION_SA_QUERY_RESPONSE;
  2000. memcpy(resp->u.action.u.sa_query.trans_id,
  2001. mgmt->u.action.u.sa_query.trans_id,
  2002. WLAN_SA_QUERY_TR_ID_LEN);
  2003. ieee80211_tx_skb(sdata, skb);
  2004. }
  2005. static ieee80211_rx_result debug_noinline
  2006. ieee80211_rx_h_mgmt_check(struct ieee80211_rx_data *rx)
  2007. {
  2008. struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) rx->skb->data;
  2009. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
  2010. /*
  2011. * From here on, look only at management frames.
  2012. * Data and control frames are already handled,
  2013. * and unknown (reserved) frames are useless.
  2014. */
  2015. if (rx->skb->len < 24)
  2016. return RX_DROP_MONITOR;
  2017. if (!ieee80211_is_mgmt(mgmt->frame_control))
  2018. return RX_DROP_MONITOR;
  2019. if (rx->sdata->vif.type == NL80211_IFTYPE_AP &&
  2020. ieee80211_is_beacon(mgmt->frame_control) &&
  2021. !(rx->flags & IEEE80211_RX_BEACON_REPORTED)) {
  2022. int sig = 0;
  2023. if (rx->local->hw.flags & IEEE80211_HW_SIGNAL_DBM)
  2024. sig = status->signal;
  2025. cfg80211_report_obss_beacon(rx->local->hw.wiphy,
  2026. rx->skb->data, rx->skb->len,
  2027. status->freq, sig);
  2028. rx->flags |= IEEE80211_RX_BEACON_REPORTED;
  2029. }
  2030. if (!(status->rx_flags & IEEE80211_RX_RA_MATCH))
  2031. return RX_DROP_MONITOR;
  2032. if (ieee80211_drop_unencrypted_mgmt(rx))
  2033. return RX_DROP_UNUSABLE;
  2034. return RX_CONTINUE;
  2035. }
  2036. static ieee80211_rx_result debug_noinline
  2037. ieee80211_rx_h_action(struct ieee80211_rx_data *rx)
  2038. {
  2039. struct ieee80211_local *local = rx->local;
  2040. struct ieee80211_sub_if_data *sdata = rx->sdata;
  2041. struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) rx->skb->data;
  2042. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
  2043. int len = rx->skb->len;
  2044. if (!ieee80211_is_action(mgmt->frame_control))
  2045. return RX_CONTINUE;
  2046. /* drop too small frames */
  2047. if (len < IEEE80211_MIN_ACTION_SIZE)
  2048. return RX_DROP_UNUSABLE;
  2049. if (!rx->sta && mgmt->u.action.category != WLAN_CATEGORY_PUBLIC &&
  2050. mgmt->u.action.category != WLAN_CATEGORY_SELF_PROTECTED)
  2051. return RX_DROP_UNUSABLE;
  2052. if (!(status->rx_flags & IEEE80211_RX_RA_MATCH))
  2053. return RX_DROP_UNUSABLE;
  2054. switch (mgmt->u.action.category) {
  2055. case WLAN_CATEGORY_HT:
  2056. /* reject HT action frames from stations not supporting HT */
  2057. if (!rx->sta->sta.ht_cap.ht_supported)
  2058. goto invalid;
  2059. if (sdata->vif.type != NL80211_IFTYPE_STATION &&
  2060. sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
  2061. sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
  2062. sdata->vif.type != NL80211_IFTYPE_AP &&
  2063. sdata->vif.type != NL80211_IFTYPE_ADHOC)
  2064. break;
  2065. /* verify action & smps_control/chanwidth are present */
  2066. if (len < IEEE80211_MIN_ACTION_SIZE + 2)
  2067. goto invalid;
  2068. switch (mgmt->u.action.u.ht_smps.action) {
  2069. case WLAN_HT_ACTION_SMPS: {
  2070. struct ieee80211_supported_band *sband;
  2071. enum ieee80211_smps_mode smps_mode;
  2072. /* convert to HT capability */
  2073. switch (mgmt->u.action.u.ht_smps.smps_control) {
  2074. case WLAN_HT_SMPS_CONTROL_DISABLED:
  2075. smps_mode = IEEE80211_SMPS_OFF;
  2076. break;
  2077. case WLAN_HT_SMPS_CONTROL_STATIC:
  2078. smps_mode = IEEE80211_SMPS_STATIC;
  2079. break;
  2080. case WLAN_HT_SMPS_CONTROL_DYNAMIC:
  2081. smps_mode = IEEE80211_SMPS_DYNAMIC;
  2082. break;
  2083. default:
  2084. goto invalid;
  2085. }
  2086. /* if no change do nothing */
  2087. if (rx->sta->sta.smps_mode == smps_mode)
  2088. goto handled;
  2089. rx->sta->sta.smps_mode = smps_mode;
  2090. sband = rx->local->hw.wiphy->bands[status->band];
  2091. rate_control_rate_update(local, sband, rx->sta,
  2092. IEEE80211_RC_SMPS_CHANGED);
  2093. goto handled;
  2094. }
  2095. case WLAN_HT_ACTION_NOTIFY_CHANWIDTH: {
  2096. struct ieee80211_supported_band *sband;
  2097. u8 chanwidth = mgmt->u.action.u.ht_notify_cw.chanwidth;
  2098. enum ieee80211_sta_rx_bandwidth new_bw;
  2099. /* If it doesn't support 40 MHz it can't change ... */
  2100. if (!(rx->sta->sta.ht_cap.cap &
  2101. IEEE80211_HT_CAP_SUP_WIDTH_20_40))
  2102. goto handled;
  2103. if (chanwidth == IEEE80211_HT_CHANWIDTH_20MHZ)
  2104. new_bw = IEEE80211_STA_RX_BW_20;
  2105. else
  2106. new_bw = ieee80211_sta_cur_vht_bw(rx->sta);
  2107. if (rx->sta->sta.bandwidth == new_bw)
  2108. goto handled;
  2109. sband = rx->local->hw.wiphy->bands[status->band];
  2110. rate_control_rate_update(local, sband, rx->sta,
  2111. IEEE80211_RC_BW_CHANGED);
  2112. goto handled;
  2113. }
  2114. default:
  2115. goto invalid;
  2116. }
  2117. break;
  2118. case WLAN_CATEGORY_PUBLIC:
  2119. if (len < IEEE80211_MIN_ACTION_SIZE + 1)
  2120. goto invalid;
  2121. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  2122. break;
  2123. if (!rx->sta)
  2124. break;
  2125. if (!ether_addr_equal(mgmt->bssid, sdata->u.mgd.bssid))
  2126. break;
  2127. if (mgmt->u.action.u.ext_chan_switch.action_code !=
  2128. WLAN_PUB_ACTION_EXT_CHANSW_ANN)
  2129. break;
  2130. if (len < offsetof(struct ieee80211_mgmt,
  2131. u.action.u.ext_chan_switch.variable))
  2132. goto invalid;
  2133. goto queue;
  2134. case WLAN_CATEGORY_VHT:
  2135. if (sdata->vif.type != NL80211_IFTYPE_STATION &&
  2136. sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
  2137. sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
  2138. sdata->vif.type != NL80211_IFTYPE_AP &&
  2139. sdata->vif.type != NL80211_IFTYPE_ADHOC)
  2140. break;
  2141. /* verify action code is present */
  2142. if (len < IEEE80211_MIN_ACTION_SIZE + 1)
  2143. goto invalid;
  2144. switch (mgmt->u.action.u.vht_opmode_notif.action_code) {
  2145. case WLAN_VHT_ACTION_OPMODE_NOTIF: {
  2146. u8 opmode;
  2147. /* verify opmode is present */
  2148. if (len < IEEE80211_MIN_ACTION_SIZE + 2)
  2149. goto invalid;
  2150. opmode = mgmt->u.action.u.vht_opmode_notif.operating_mode;
  2151. ieee80211_vht_handle_opmode(rx->sdata, rx->sta,
  2152. opmode, status->band,
  2153. false);
  2154. goto handled;
  2155. }
  2156. default:
  2157. break;
  2158. }
  2159. break;
  2160. case WLAN_CATEGORY_BACK:
  2161. if (sdata->vif.type != NL80211_IFTYPE_STATION &&
  2162. sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
  2163. sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
  2164. sdata->vif.type != NL80211_IFTYPE_AP &&
  2165. sdata->vif.type != NL80211_IFTYPE_ADHOC)
  2166. break;
  2167. /* verify action_code is present */
  2168. if (len < IEEE80211_MIN_ACTION_SIZE + 1)
  2169. break;
  2170. switch (mgmt->u.action.u.addba_req.action_code) {
  2171. case WLAN_ACTION_ADDBA_REQ:
  2172. if (len < (IEEE80211_MIN_ACTION_SIZE +
  2173. sizeof(mgmt->u.action.u.addba_req)))
  2174. goto invalid;
  2175. break;
  2176. case WLAN_ACTION_ADDBA_RESP:
  2177. if (len < (IEEE80211_MIN_ACTION_SIZE +
  2178. sizeof(mgmt->u.action.u.addba_resp)))
  2179. goto invalid;
  2180. break;
  2181. case WLAN_ACTION_DELBA:
  2182. if (len < (IEEE80211_MIN_ACTION_SIZE +
  2183. sizeof(mgmt->u.action.u.delba)))
  2184. goto invalid;
  2185. break;
  2186. default:
  2187. goto invalid;
  2188. }
  2189. goto queue;
  2190. case WLAN_CATEGORY_SPECTRUM_MGMT:
  2191. if (status->band != IEEE80211_BAND_5GHZ)
  2192. break;
  2193. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  2194. break;
  2195. /* verify action_code is present */
  2196. if (len < IEEE80211_MIN_ACTION_SIZE + 1)
  2197. break;
  2198. switch (mgmt->u.action.u.measurement.action_code) {
  2199. case WLAN_ACTION_SPCT_MSR_REQ:
  2200. if (len < (IEEE80211_MIN_ACTION_SIZE +
  2201. sizeof(mgmt->u.action.u.measurement)))
  2202. break;
  2203. ieee80211_process_measurement_req(sdata, mgmt, len);
  2204. goto handled;
  2205. case WLAN_ACTION_SPCT_CHL_SWITCH:
  2206. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  2207. break;
  2208. if (!ether_addr_equal(mgmt->bssid, sdata->u.mgd.bssid))
  2209. break;
  2210. goto queue;
  2211. }
  2212. break;
  2213. case WLAN_CATEGORY_SA_QUERY:
  2214. if (len < (IEEE80211_MIN_ACTION_SIZE +
  2215. sizeof(mgmt->u.action.u.sa_query)))
  2216. break;
  2217. switch (mgmt->u.action.u.sa_query.action) {
  2218. case WLAN_ACTION_SA_QUERY_REQUEST:
  2219. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  2220. break;
  2221. ieee80211_process_sa_query_req(sdata, mgmt, len);
  2222. goto handled;
  2223. }
  2224. break;
  2225. case WLAN_CATEGORY_SELF_PROTECTED:
  2226. if (len < (IEEE80211_MIN_ACTION_SIZE +
  2227. sizeof(mgmt->u.action.u.self_prot.action_code)))
  2228. break;
  2229. switch (mgmt->u.action.u.self_prot.action_code) {
  2230. case WLAN_SP_MESH_PEERING_OPEN:
  2231. case WLAN_SP_MESH_PEERING_CLOSE:
  2232. case WLAN_SP_MESH_PEERING_CONFIRM:
  2233. if (!ieee80211_vif_is_mesh(&sdata->vif))
  2234. goto invalid;
  2235. if (sdata->u.mesh.user_mpm)
  2236. /* userspace handles this frame */
  2237. break;
  2238. goto queue;
  2239. case WLAN_SP_MGK_INFORM:
  2240. case WLAN_SP_MGK_ACK:
  2241. if (!ieee80211_vif_is_mesh(&sdata->vif))
  2242. goto invalid;
  2243. break;
  2244. }
  2245. break;
  2246. case WLAN_CATEGORY_MESH_ACTION:
  2247. if (len < (IEEE80211_MIN_ACTION_SIZE +
  2248. sizeof(mgmt->u.action.u.mesh_action.action_code)))
  2249. break;
  2250. if (!ieee80211_vif_is_mesh(&sdata->vif))
  2251. break;
  2252. if (mesh_action_is_path_sel(mgmt) &&
  2253. !mesh_path_sel_is_hwmp(sdata))
  2254. break;
  2255. goto queue;
  2256. }
  2257. return RX_CONTINUE;
  2258. invalid:
  2259. status->rx_flags |= IEEE80211_RX_MALFORMED_ACTION_FRM;
  2260. /* will return in the next handlers */
  2261. return RX_CONTINUE;
  2262. handled:
  2263. if (rx->sta)
  2264. rx->sta->rx_packets++;
  2265. dev_kfree_skb(rx->skb);
  2266. return RX_QUEUED;
  2267. queue:
  2268. rx->skb->pkt_type = IEEE80211_SDATA_QUEUE_TYPE_FRAME;
  2269. skb_queue_tail(&sdata->skb_queue, rx->skb);
  2270. ieee80211_queue_work(&local->hw, &sdata->work);
  2271. if (rx->sta)
  2272. rx->sta->rx_packets++;
  2273. return RX_QUEUED;
  2274. }
  2275. static ieee80211_rx_result debug_noinline
  2276. ieee80211_rx_h_userspace_mgmt(struct ieee80211_rx_data *rx)
  2277. {
  2278. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
  2279. int sig = 0;
  2280. /* skip known-bad action frames and return them in the next handler */
  2281. if (status->rx_flags & IEEE80211_RX_MALFORMED_ACTION_FRM)
  2282. return RX_CONTINUE;
  2283. /*
  2284. * Getting here means the kernel doesn't know how to handle
  2285. * it, but maybe userspace does ... include returned frames
  2286. * so userspace can register for those to know whether ones
  2287. * it transmitted were processed or returned.
  2288. */
  2289. if (rx->local->hw.flags & IEEE80211_HW_SIGNAL_DBM)
  2290. sig = status->signal;
  2291. if (cfg80211_rx_mgmt(&rx->sdata->wdev, status->freq, sig,
  2292. rx->skb->data, rx->skb->len, 0, GFP_ATOMIC)) {
  2293. if (rx->sta)
  2294. rx->sta->rx_packets++;
  2295. dev_kfree_skb(rx->skb);
  2296. return RX_QUEUED;
  2297. }
  2298. return RX_CONTINUE;
  2299. }
  2300. static ieee80211_rx_result debug_noinline
  2301. ieee80211_rx_h_action_return(struct ieee80211_rx_data *rx)
  2302. {
  2303. struct ieee80211_local *local = rx->local;
  2304. struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) rx->skb->data;
  2305. struct sk_buff *nskb;
  2306. struct ieee80211_sub_if_data *sdata = rx->sdata;
  2307. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
  2308. if (!ieee80211_is_action(mgmt->frame_control))
  2309. return RX_CONTINUE;
  2310. /*
  2311. * For AP mode, hostapd is responsible for handling any action
  2312. * frames that we didn't handle, including returning unknown
  2313. * ones. For all other modes we will return them to the sender,
  2314. * setting the 0x80 bit in the action category, as required by
  2315. * 802.11-2012 9.24.4.
  2316. * Newer versions of hostapd shall also use the management frame
  2317. * registration mechanisms, but older ones still use cooked
  2318. * monitor interfaces so push all frames there.
  2319. */
  2320. if (!(status->rx_flags & IEEE80211_RX_MALFORMED_ACTION_FRM) &&
  2321. (sdata->vif.type == NL80211_IFTYPE_AP ||
  2322. sdata->vif.type == NL80211_IFTYPE_AP_VLAN))
  2323. return RX_DROP_MONITOR;
  2324. if (is_multicast_ether_addr(mgmt->da))
  2325. return RX_DROP_MONITOR;
  2326. /* do not return rejected action frames */
  2327. if (mgmt->u.action.category & 0x80)
  2328. return RX_DROP_UNUSABLE;
  2329. nskb = skb_copy_expand(rx->skb, local->hw.extra_tx_headroom, 0,
  2330. GFP_ATOMIC);
  2331. if (nskb) {
  2332. struct ieee80211_mgmt *nmgmt = (void *)nskb->data;
  2333. nmgmt->u.action.category |= 0x80;
  2334. memcpy(nmgmt->da, nmgmt->sa, ETH_ALEN);
  2335. memcpy(nmgmt->sa, rx->sdata->vif.addr, ETH_ALEN);
  2336. memset(nskb->cb, 0, sizeof(nskb->cb));
  2337. if (rx->sdata->vif.type == NL80211_IFTYPE_P2P_DEVICE) {
  2338. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(nskb);
  2339. info->flags = IEEE80211_TX_CTL_TX_OFFCHAN |
  2340. IEEE80211_TX_INTFL_OFFCHAN_TX_OK |
  2341. IEEE80211_TX_CTL_NO_CCK_RATE;
  2342. if (local->hw.flags & IEEE80211_HW_QUEUE_CONTROL)
  2343. info->hw_queue =
  2344. local->hw.offchannel_tx_hw_queue;
  2345. }
  2346. __ieee80211_tx_skb_tid_band(rx->sdata, nskb, 7,
  2347. status->band);
  2348. }
  2349. dev_kfree_skb(rx->skb);
  2350. return RX_QUEUED;
  2351. }
  2352. static ieee80211_rx_result debug_noinline
  2353. ieee80211_rx_h_mgmt(struct ieee80211_rx_data *rx)
  2354. {
  2355. struct ieee80211_sub_if_data *sdata = rx->sdata;
  2356. struct ieee80211_mgmt *mgmt = (void *)rx->skb->data;
  2357. __le16 stype;
  2358. stype = mgmt->frame_control & cpu_to_le16(IEEE80211_FCTL_STYPE);
  2359. if (!ieee80211_vif_is_mesh(&sdata->vif) &&
  2360. sdata->vif.type != NL80211_IFTYPE_ADHOC &&
  2361. sdata->vif.type != NL80211_IFTYPE_STATION)
  2362. return RX_DROP_MONITOR;
  2363. switch (stype) {
  2364. case cpu_to_le16(IEEE80211_STYPE_AUTH):
  2365. case cpu_to_le16(IEEE80211_STYPE_BEACON):
  2366. case cpu_to_le16(IEEE80211_STYPE_PROBE_RESP):
  2367. /* process for all: mesh, mlme, ibss */
  2368. break;
  2369. case cpu_to_le16(IEEE80211_STYPE_ASSOC_RESP):
  2370. case cpu_to_le16(IEEE80211_STYPE_REASSOC_RESP):
  2371. case cpu_to_le16(IEEE80211_STYPE_DEAUTH):
  2372. case cpu_to_le16(IEEE80211_STYPE_DISASSOC):
  2373. if (is_multicast_ether_addr(mgmt->da) &&
  2374. !is_broadcast_ether_addr(mgmt->da))
  2375. return RX_DROP_MONITOR;
  2376. /* process only for station */
  2377. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  2378. return RX_DROP_MONITOR;
  2379. break;
  2380. case cpu_to_le16(IEEE80211_STYPE_PROBE_REQ):
  2381. /* process only for ibss and mesh */
  2382. if (sdata->vif.type != NL80211_IFTYPE_ADHOC &&
  2383. sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
  2384. return RX_DROP_MONITOR;
  2385. break;
  2386. default:
  2387. return RX_DROP_MONITOR;
  2388. }
  2389. /* queue up frame and kick off work to process it */
  2390. rx->skb->pkt_type = IEEE80211_SDATA_QUEUE_TYPE_FRAME;
  2391. skb_queue_tail(&sdata->skb_queue, rx->skb);
  2392. ieee80211_queue_work(&rx->local->hw, &sdata->work);
  2393. if (rx->sta)
  2394. rx->sta->rx_packets++;
  2395. return RX_QUEUED;
  2396. }
  2397. /* TODO: use IEEE80211_RX_FRAGMENTED */
  2398. static void ieee80211_rx_cooked_monitor(struct ieee80211_rx_data *rx,
  2399. struct ieee80211_rate *rate)
  2400. {
  2401. struct ieee80211_sub_if_data *sdata;
  2402. struct ieee80211_local *local = rx->local;
  2403. struct sk_buff *skb = rx->skb, *skb2;
  2404. struct net_device *prev_dev = NULL;
  2405. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
  2406. int needed_headroom;
  2407. /*
  2408. * If cooked monitor has been processed already, then
  2409. * don't do it again. If not, set the flag.
  2410. */
  2411. if (rx->flags & IEEE80211_RX_CMNTR)
  2412. goto out_free_skb;
  2413. rx->flags |= IEEE80211_RX_CMNTR;
  2414. /* If there are no cooked monitor interfaces, just free the SKB */
  2415. if (!local->cooked_mntrs)
  2416. goto out_free_skb;
  2417. /* room for the radiotap header based on driver features */
  2418. needed_headroom = ieee80211_rx_radiotap_space(local, status);
  2419. if (skb_headroom(skb) < needed_headroom &&
  2420. pskb_expand_head(skb, needed_headroom, 0, GFP_ATOMIC))
  2421. goto out_free_skb;
  2422. /* prepend radiotap information */
  2423. ieee80211_add_rx_radiotap_header(local, skb, rate, needed_headroom,
  2424. false);
  2425. skb_set_mac_header(skb, 0);
  2426. skb->ip_summed = CHECKSUM_UNNECESSARY;
  2427. skb->pkt_type = PACKET_OTHERHOST;
  2428. skb->protocol = htons(ETH_P_802_2);
  2429. list_for_each_entry_rcu(sdata, &local->interfaces, list) {
  2430. if (!ieee80211_sdata_running(sdata))
  2431. continue;
  2432. if (sdata->vif.type != NL80211_IFTYPE_MONITOR ||
  2433. !(sdata->u.mntr_flags & MONITOR_FLAG_COOK_FRAMES))
  2434. continue;
  2435. if (prev_dev) {
  2436. skb2 = skb_clone(skb, GFP_ATOMIC);
  2437. if (skb2) {
  2438. skb2->dev = prev_dev;
  2439. netif_receive_skb(skb2);
  2440. }
  2441. }
  2442. prev_dev = sdata->dev;
  2443. sdata->dev->stats.rx_packets++;
  2444. sdata->dev->stats.rx_bytes += skb->len;
  2445. }
  2446. if (prev_dev) {
  2447. skb->dev = prev_dev;
  2448. netif_receive_skb(skb);
  2449. return;
  2450. }
  2451. out_free_skb:
  2452. dev_kfree_skb(skb);
  2453. }
  2454. static void ieee80211_rx_handlers_result(struct ieee80211_rx_data *rx,
  2455. ieee80211_rx_result res)
  2456. {
  2457. switch (res) {
  2458. case RX_DROP_MONITOR:
  2459. I802_DEBUG_INC(rx->sdata->local->rx_handlers_drop);
  2460. if (rx->sta)
  2461. rx->sta->rx_dropped++;
  2462. /* fall through */
  2463. case RX_CONTINUE: {
  2464. struct ieee80211_rate *rate = NULL;
  2465. struct ieee80211_supported_band *sband;
  2466. struct ieee80211_rx_status *status;
  2467. status = IEEE80211_SKB_RXCB((rx->skb));
  2468. sband = rx->local->hw.wiphy->bands[status->band];
  2469. if (!(status->flag & RX_FLAG_HT) &&
  2470. !(status->flag & RX_FLAG_VHT))
  2471. rate = &sband->bitrates[status->rate_idx];
  2472. ieee80211_rx_cooked_monitor(rx, rate);
  2473. break;
  2474. }
  2475. case RX_DROP_UNUSABLE:
  2476. I802_DEBUG_INC(rx->sdata->local->rx_handlers_drop);
  2477. if (rx->sta)
  2478. rx->sta->rx_dropped++;
  2479. dev_kfree_skb(rx->skb);
  2480. break;
  2481. case RX_QUEUED:
  2482. I802_DEBUG_INC(rx->sdata->local->rx_handlers_queued);
  2483. break;
  2484. }
  2485. }
  2486. static void ieee80211_rx_handlers(struct ieee80211_rx_data *rx,
  2487. struct sk_buff_head *frames)
  2488. {
  2489. ieee80211_rx_result res = RX_DROP_MONITOR;
  2490. struct sk_buff *skb;
  2491. #define CALL_RXH(rxh) \
  2492. do { \
  2493. res = rxh(rx); \
  2494. if (res != RX_CONTINUE) \
  2495. goto rxh_next; \
  2496. } while (0);
  2497. spin_lock_bh(&rx->local->rx_path_lock);
  2498. while ((skb = __skb_dequeue(frames))) {
  2499. /*
  2500. * all the other fields are valid across frames
  2501. * that belong to an aMPDU since they are on the
  2502. * same TID from the same station
  2503. */
  2504. rx->skb = skb;
  2505. CALL_RXH(ieee80211_rx_h_check_more_data)
  2506. CALL_RXH(ieee80211_rx_h_uapsd_and_pspoll)
  2507. CALL_RXH(ieee80211_rx_h_sta_process)
  2508. CALL_RXH(ieee80211_rx_h_decrypt)
  2509. CALL_RXH(ieee80211_rx_h_defragment)
  2510. CALL_RXH(ieee80211_rx_h_michael_mic_verify)
  2511. /* must be after MMIC verify so header is counted in MPDU mic */
  2512. #ifdef CONFIG_MAC80211_MESH
  2513. if (ieee80211_vif_is_mesh(&rx->sdata->vif))
  2514. CALL_RXH(ieee80211_rx_h_mesh_fwding);
  2515. #endif
  2516. CALL_RXH(ieee80211_rx_h_amsdu)
  2517. CALL_RXH(ieee80211_rx_h_data)
  2518. /* special treatment -- needs the queue */
  2519. res = ieee80211_rx_h_ctrl(rx, frames);
  2520. if (res != RX_CONTINUE)
  2521. goto rxh_next;
  2522. CALL_RXH(ieee80211_rx_h_mgmt_check)
  2523. CALL_RXH(ieee80211_rx_h_action)
  2524. CALL_RXH(ieee80211_rx_h_userspace_mgmt)
  2525. CALL_RXH(ieee80211_rx_h_action_return)
  2526. CALL_RXH(ieee80211_rx_h_mgmt)
  2527. rxh_next:
  2528. ieee80211_rx_handlers_result(rx, res);
  2529. #undef CALL_RXH
  2530. }
  2531. spin_unlock_bh(&rx->local->rx_path_lock);
  2532. }
  2533. static void ieee80211_invoke_rx_handlers(struct ieee80211_rx_data *rx)
  2534. {
  2535. struct sk_buff_head reorder_release;
  2536. ieee80211_rx_result res = RX_DROP_MONITOR;
  2537. __skb_queue_head_init(&reorder_release);
  2538. #define CALL_RXH(rxh) \
  2539. do { \
  2540. res = rxh(rx); \
  2541. if (res != RX_CONTINUE) \
  2542. goto rxh_next; \
  2543. } while (0);
  2544. CALL_RXH(ieee80211_rx_h_check)
  2545. ieee80211_rx_reorder_ampdu(rx, &reorder_release);
  2546. ieee80211_rx_handlers(rx, &reorder_release);
  2547. return;
  2548. rxh_next:
  2549. ieee80211_rx_handlers_result(rx, res);
  2550. #undef CALL_RXH
  2551. }
  2552. /*
  2553. * This function makes calls into the RX path, therefore
  2554. * it has to be invoked under RCU read lock.
  2555. */
  2556. void ieee80211_release_reorder_timeout(struct sta_info *sta, int tid)
  2557. {
  2558. struct sk_buff_head frames;
  2559. struct ieee80211_rx_data rx = {
  2560. .sta = sta,
  2561. .sdata = sta->sdata,
  2562. .local = sta->local,
  2563. /* This is OK -- must be QoS data frame */
  2564. .security_idx = tid,
  2565. .seqno_idx = tid,
  2566. .flags = 0,
  2567. };
  2568. struct tid_ampdu_rx *tid_agg_rx;
  2569. tid_agg_rx = rcu_dereference(sta->ampdu_mlme.tid_rx[tid]);
  2570. if (!tid_agg_rx)
  2571. return;
  2572. __skb_queue_head_init(&frames);
  2573. spin_lock(&tid_agg_rx->reorder_lock);
  2574. ieee80211_sta_reorder_release(sta->sdata, tid_agg_rx, &frames);
  2575. spin_unlock(&tid_agg_rx->reorder_lock);
  2576. ieee80211_rx_handlers(&rx, &frames);
  2577. }
  2578. /* main receive path */
  2579. static int prepare_for_handlers(struct ieee80211_rx_data *rx,
  2580. struct ieee80211_hdr *hdr)
  2581. {
  2582. struct ieee80211_sub_if_data *sdata = rx->sdata;
  2583. struct sk_buff *skb = rx->skb;
  2584. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
  2585. u8 *bssid = ieee80211_get_bssid(hdr, skb->len, sdata->vif.type);
  2586. int multicast = is_multicast_ether_addr(hdr->addr1);
  2587. switch (sdata->vif.type) {
  2588. case NL80211_IFTYPE_STATION:
  2589. if (!bssid && !sdata->u.mgd.use_4addr)
  2590. return 0;
  2591. if (!multicast &&
  2592. !ether_addr_equal(sdata->vif.addr, hdr->addr1)) {
  2593. if (!(sdata->dev->flags & IFF_PROMISC) ||
  2594. sdata->u.mgd.use_4addr)
  2595. return 0;
  2596. status->rx_flags &= ~IEEE80211_RX_RA_MATCH;
  2597. }
  2598. break;
  2599. case NL80211_IFTYPE_ADHOC:
  2600. if (!bssid)
  2601. return 0;
  2602. if (ieee80211_is_beacon(hdr->frame_control)) {
  2603. return 1;
  2604. } else if (!ieee80211_bssid_match(bssid, sdata->u.ibss.bssid)) {
  2605. return 0;
  2606. } else if (!multicast &&
  2607. !ether_addr_equal(sdata->vif.addr, hdr->addr1)) {
  2608. if (!(sdata->dev->flags & IFF_PROMISC))
  2609. return 0;
  2610. status->rx_flags &= ~IEEE80211_RX_RA_MATCH;
  2611. } else if (!rx->sta) {
  2612. int rate_idx;
  2613. if (status->flag & (RX_FLAG_HT | RX_FLAG_VHT))
  2614. rate_idx = 0; /* TODO: HT/VHT rates */
  2615. else
  2616. rate_idx = status->rate_idx;
  2617. ieee80211_ibss_rx_no_sta(sdata, bssid, hdr->addr2,
  2618. BIT(rate_idx));
  2619. }
  2620. break;
  2621. case NL80211_IFTYPE_MESH_POINT:
  2622. if (!multicast &&
  2623. !ether_addr_equal(sdata->vif.addr, hdr->addr1)) {
  2624. if (!(sdata->dev->flags & IFF_PROMISC))
  2625. return 0;
  2626. status->rx_flags &= ~IEEE80211_RX_RA_MATCH;
  2627. }
  2628. break;
  2629. case NL80211_IFTYPE_AP_VLAN:
  2630. case NL80211_IFTYPE_AP:
  2631. if (!bssid) {
  2632. if (!ether_addr_equal(sdata->vif.addr, hdr->addr1))
  2633. return 0;
  2634. } else if (!ieee80211_bssid_match(bssid, sdata->vif.addr)) {
  2635. /*
  2636. * Accept public action frames even when the
  2637. * BSSID doesn't match, this is used for P2P
  2638. * and location updates. Note that mac80211
  2639. * itself never looks at these frames.
  2640. */
  2641. if (!multicast &&
  2642. !ether_addr_equal(sdata->vif.addr, hdr->addr1))
  2643. return 0;
  2644. if (ieee80211_is_public_action(hdr, skb->len))
  2645. return 1;
  2646. if (!ieee80211_is_beacon(hdr->frame_control))
  2647. return 0;
  2648. status->rx_flags &= ~IEEE80211_RX_RA_MATCH;
  2649. }
  2650. break;
  2651. case NL80211_IFTYPE_WDS:
  2652. if (bssid || !ieee80211_is_data(hdr->frame_control))
  2653. return 0;
  2654. if (!ether_addr_equal(sdata->u.wds.remote_addr, hdr->addr2))
  2655. return 0;
  2656. break;
  2657. case NL80211_IFTYPE_P2P_DEVICE:
  2658. if (!ieee80211_is_public_action(hdr, skb->len) &&
  2659. !ieee80211_is_probe_req(hdr->frame_control) &&
  2660. !ieee80211_is_probe_resp(hdr->frame_control) &&
  2661. !ieee80211_is_beacon(hdr->frame_control))
  2662. return 0;
  2663. if (!ether_addr_equal(sdata->vif.addr, hdr->addr1) &&
  2664. !multicast)
  2665. status->rx_flags &= ~IEEE80211_RX_RA_MATCH;
  2666. break;
  2667. default:
  2668. /* should never get here */
  2669. WARN_ON_ONCE(1);
  2670. break;
  2671. }
  2672. return 1;
  2673. }
  2674. /*
  2675. * This function returns whether or not the SKB
  2676. * was destined for RX processing or not, which,
  2677. * if consume is true, is equivalent to whether
  2678. * or not the skb was consumed.
  2679. */
  2680. static bool ieee80211_prepare_and_rx_handle(struct ieee80211_rx_data *rx,
  2681. struct sk_buff *skb, bool consume)
  2682. {
  2683. struct ieee80211_local *local = rx->local;
  2684. struct ieee80211_sub_if_data *sdata = rx->sdata;
  2685. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
  2686. struct ieee80211_hdr *hdr = (void *)skb->data;
  2687. int prepares;
  2688. rx->skb = skb;
  2689. status->rx_flags |= IEEE80211_RX_RA_MATCH;
  2690. prepares = prepare_for_handlers(rx, hdr);
  2691. if (!prepares)
  2692. return false;
  2693. if (!consume) {
  2694. skb = skb_copy(skb, GFP_ATOMIC);
  2695. if (!skb) {
  2696. if (net_ratelimit())
  2697. wiphy_debug(local->hw.wiphy,
  2698. "failed to copy skb for %s\n",
  2699. sdata->name);
  2700. return true;
  2701. }
  2702. rx->skb = skb;
  2703. }
  2704. ieee80211_invoke_rx_handlers(rx);
  2705. return true;
  2706. }
  2707. /*
  2708. * This is the actual Rx frames handler. as it blongs to Rx path it must
  2709. * be called with rcu_read_lock protection.
  2710. */
  2711. static void __ieee80211_rx_handle_packet(struct ieee80211_hw *hw,
  2712. struct sk_buff *skb)
  2713. {
  2714. struct ieee80211_local *local = hw_to_local(hw);
  2715. struct ieee80211_sub_if_data *sdata;
  2716. struct ieee80211_hdr *hdr;
  2717. __le16 fc;
  2718. struct ieee80211_rx_data rx;
  2719. struct ieee80211_sub_if_data *prev;
  2720. struct sta_info *sta, *tmp, *prev_sta;
  2721. int err = 0;
  2722. fc = ((struct ieee80211_hdr *)skb->data)->frame_control;
  2723. memset(&rx, 0, sizeof(rx));
  2724. rx.skb = skb;
  2725. rx.local = local;
  2726. if (ieee80211_is_data(fc) || ieee80211_is_mgmt(fc))
  2727. local->dot11ReceivedFragmentCount++;
  2728. if (ieee80211_is_mgmt(fc)) {
  2729. /* drop frame if too short for header */
  2730. if (skb->len < ieee80211_hdrlen(fc))
  2731. err = -ENOBUFS;
  2732. else
  2733. err = skb_linearize(skb);
  2734. } else {
  2735. err = !pskb_may_pull(skb, ieee80211_hdrlen(fc));
  2736. }
  2737. if (err) {
  2738. dev_kfree_skb(skb);
  2739. return;
  2740. }
  2741. hdr = (struct ieee80211_hdr *)skb->data;
  2742. ieee80211_parse_qos(&rx);
  2743. ieee80211_verify_alignment(&rx);
  2744. if (unlikely(ieee80211_is_probe_resp(hdr->frame_control) ||
  2745. ieee80211_is_beacon(hdr->frame_control)))
  2746. ieee80211_scan_rx(local, skb);
  2747. if (ieee80211_is_data(fc)) {
  2748. prev_sta = NULL;
  2749. for_each_sta_info(local, hdr->addr2, sta, tmp) {
  2750. if (!prev_sta) {
  2751. prev_sta = sta;
  2752. continue;
  2753. }
  2754. rx.sta = prev_sta;
  2755. rx.sdata = prev_sta->sdata;
  2756. ieee80211_prepare_and_rx_handle(&rx, skb, false);
  2757. prev_sta = sta;
  2758. }
  2759. if (prev_sta) {
  2760. rx.sta = prev_sta;
  2761. rx.sdata = prev_sta->sdata;
  2762. if (ieee80211_prepare_and_rx_handle(&rx, skb, true))
  2763. return;
  2764. goto out;
  2765. }
  2766. }
  2767. prev = NULL;
  2768. list_for_each_entry_rcu(sdata, &local->interfaces, list) {
  2769. if (!ieee80211_sdata_running(sdata))
  2770. continue;
  2771. if (sdata->vif.type == NL80211_IFTYPE_MONITOR ||
  2772. sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
  2773. continue;
  2774. /*
  2775. * frame is destined for this interface, but if it's
  2776. * not also for the previous one we handle that after
  2777. * the loop to avoid copying the SKB once too much
  2778. */
  2779. if (!prev) {
  2780. prev = sdata;
  2781. continue;
  2782. }
  2783. rx.sta = sta_info_get_bss(prev, hdr->addr2);
  2784. rx.sdata = prev;
  2785. ieee80211_prepare_and_rx_handle(&rx, skb, false);
  2786. prev = sdata;
  2787. }
  2788. if (prev) {
  2789. rx.sta = sta_info_get_bss(prev, hdr->addr2);
  2790. rx.sdata = prev;
  2791. if (ieee80211_prepare_and_rx_handle(&rx, skb, true))
  2792. return;
  2793. }
  2794. out:
  2795. dev_kfree_skb(skb);
  2796. }
  2797. /*
  2798. * This is the receive path handler. It is called by a low level driver when an
  2799. * 802.11 MPDU is received from the hardware.
  2800. */
  2801. void ieee80211_rx(struct ieee80211_hw *hw, struct sk_buff *skb)
  2802. {
  2803. struct ieee80211_local *local = hw_to_local(hw);
  2804. struct ieee80211_rate *rate = NULL;
  2805. struct ieee80211_supported_band *sband;
  2806. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
  2807. WARN_ON_ONCE(softirq_count() == 0);
  2808. if (WARN_ON(status->band >= IEEE80211_NUM_BANDS))
  2809. goto drop;
  2810. sband = local->hw.wiphy->bands[status->band];
  2811. if (WARN_ON(!sband))
  2812. goto drop;
  2813. /*
  2814. * If we're suspending, it is possible although not too likely
  2815. * that we'd be receiving frames after having already partially
  2816. * quiesced the stack. We can't process such frames then since
  2817. * that might, for example, cause stations to be added or other
  2818. * driver callbacks be invoked.
  2819. */
  2820. if (unlikely(local->quiescing || local->suspended))
  2821. goto drop;
  2822. /* We might be during a HW reconfig, prevent Rx for the same reason */
  2823. if (unlikely(local->in_reconfig))
  2824. goto drop;
  2825. /*
  2826. * The same happens when we're not even started,
  2827. * but that's worth a warning.
  2828. */
  2829. if (WARN_ON(!local->started))
  2830. goto drop;
  2831. if (likely(!(status->flag & RX_FLAG_FAILED_PLCP_CRC))) {
  2832. /*
  2833. * Validate the rate, unless a PLCP error means that
  2834. * we probably can't have a valid rate here anyway.
  2835. */
  2836. if (status->flag & RX_FLAG_HT) {
  2837. /*
  2838. * rate_idx is MCS index, which can be [0-76]
  2839. * as documented on:
  2840. *
  2841. * http://wireless.kernel.org/en/developers/Documentation/ieee80211/802.11n
  2842. *
  2843. * Anything else would be some sort of driver or
  2844. * hardware error. The driver should catch hardware
  2845. * errors.
  2846. */
  2847. if (WARN(status->rate_idx > 76,
  2848. "Rate marked as an HT rate but passed "
  2849. "status->rate_idx is not "
  2850. "an MCS index [0-76]: %d (0x%02x)\n",
  2851. status->rate_idx,
  2852. status->rate_idx))
  2853. goto drop;
  2854. } else if (status->flag & RX_FLAG_VHT) {
  2855. if (WARN_ONCE(status->rate_idx > 9 ||
  2856. !status->vht_nss ||
  2857. status->vht_nss > 8,
  2858. "Rate marked as a VHT rate but data is invalid: MCS: %d, NSS: %d\n",
  2859. status->rate_idx, status->vht_nss))
  2860. goto drop;
  2861. } else {
  2862. if (WARN_ON(status->rate_idx >= sband->n_bitrates))
  2863. goto drop;
  2864. rate = &sband->bitrates[status->rate_idx];
  2865. }
  2866. }
  2867. status->rx_flags = 0;
  2868. /*
  2869. * key references and virtual interfaces are protected using RCU
  2870. * and this requires that we are in a read-side RCU section during
  2871. * receive processing
  2872. */
  2873. rcu_read_lock();
  2874. /*
  2875. * Frames with failed FCS/PLCP checksum are not returned,
  2876. * all other frames are returned without radiotap header
  2877. * if it was previously present.
  2878. * Also, frames with less than 16 bytes are dropped.
  2879. */
  2880. skb = ieee80211_rx_monitor(local, skb, rate);
  2881. if (!skb) {
  2882. rcu_read_unlock();
  2883. return;
  2884. }
  2885. ieee80211_tpt_led_trig_rx(local,
  2886. ((struct ieee80211_hdr *)skb->data)->frame_control,
  2887. skb->len);
  2888. __ieee80211_rx_handle_packet(hw, skb);
  2889. rcu_read_unlock();
  2890. return;
  2891. drop:
  2892. kfree_skb(skb);
  2893. }
  2894. EXPORT_SYMBOL(ieee80211_rx);
  2895. /* This is a version of the rx handler that can be called from hard irq
  2896. * context. Post the skb on the queue and schedule the tasklet */
  2897. void ieee80211_rx_irqsafe(struct ieee80211_hw *hw, struct sk_buff *skb)
  2898. {
  2899. struct ieee80211_local *local = hw_to_local(hw);
  2900. BUILD_BUG_ON(sizeof(struct ieee80211_rx_status) > sizeof(skb->cb));
  2901. skb->pkt_type = IEEE80211_RX_MSG;
  2902. skb_queue_tail(&local->skb_queue, skb);
  2903. tasklet_schedule(&local->tasklet);
  2904. }
  2905. EXPORT_SYMBOL(ieee80211_rx_irqsafe);