rx.c 95 KB

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