rx.c 92 KB

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