rx.c 96 KB

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