rx.c 91 KB

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