rx.c 93 KB

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