rx.c 93 KB

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