rx.c 93 KB

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