rx.c 95 KB

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