rx.c 77 KB

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