rx.c 121 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363
  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. * Copyright 2013-2014 Intel Mobile Communications GmbH
  7. * Copyright(c) 2015 - 2017 Intel Deutschland GmbH
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2 as
  11. * published by the Free Software Foundation.
  12. */
  13. #include <linux/jiffies.h>
  14. #include <linux/slab.h>
  15. #include <linux/kernel.h>
  16. #include <linux/skbuff.h>
  17. #include <linux/netdevice.h>
  18. #include <linux/etherdevice.h>
  19. #include <linux/rcupdate.h>
  20. #include <linux/export.h>
  21. #include <linux/bitops.h>
  22. #include <net/mac80211.h>
  23. #include <net/ieee80211_radiotap.h>
  24. #include <asm/unaligned.h>
  25. #include "ieee80211_i.h"
  26. #include "driver-ops.h"
  27. #include "led.h"
  28. #include "mesh.h"
  29. #include "wep.h"
  30. #include "wpa.h"
  31. #include "tkip.h"
  32. #include "wme.h"
  33. #include "rate.h"
  34. static inline void ieee80211_rx_stats(struct net_device *dev, u32 len)
  35. {
  36. struct pcpu_sw_netstats *tstats = this_cpu_ptr(dev->tstats);
  37. u64_stats_update_begin(&tstats->syncp);
  38. tstats->rx_packets++;
  39. tstats->rx_bytes += len;
  40. u64_stats_update_end(&tstats->syncp);
  41. }
  42. static u8 *ieee80211_get_bssid(struct ieee80211_hdr *hdr, size_t len,
  43. enum nl80211_iftype type)
  44. {
  45. __le16 fc = hdr->frame_control;
  46. if (ieee80211_is_data(fc)) {
  47. if (len < 24) /* drop incorrect hdr len (data) */
  48. return NULL;
  49. if (ieee80211_has_a4(fc))
  50. return NULL;
  51. if (ieee80211_has_tods(fc))
  52. return hdr->addr1;
  53. if (ieee80211_has_fromds(fc))
  54. return hdr->addr2;
  55. return hdr->addr3;
  56. }
  57. if (ieee80211_is_mgmt(fc)) {
  58. if (len < 24) /* drop incorrect hdr len (mgmt) */
  59. return NULL;
  60. return hdr->addr3;
  61. }
  62. if (ieee80211_is_ctl(fc)) {
  63. if (ieee80211_is_pspoll(fc))
  64. return hdr->addr1;
  65. if (ieee80211_is_back_req(fc)) {
  66. switch (type) {
  67. case NL80211_IFTYPE_STATION:
  68. return hdr->addr2;
  69. case NL80211_IFTYPE_AP:
  70. case NL80211_IFTYPE_AP_VLAN:
  71. return hdr->addr1;
  72. default:
  73. break; /* fall through to the return */
  74. }
  75. }
  76. }
  77. return NULL;
  78. }
  79. /*
  80. * monitor mode reception
  81. *
  82. * This function cleans up the SKB, i.e. it removes all the stuff
  83. * only useful for monitoring.
  84. */
  85. static void remove_monitor_info(struct sk_buff *skb,
  86. unsigned int present_fcs_len,
  87. unsigned int rtap_vendor_space)
  88. {
  89. if (present_fcs_len)
  90. __pskb_trim(skb, skb->len - present_fcs_len);
  91. __pskb_pull(skb, rtap_vendor_space);
  92. }
  93. static inline bool should_drop_frame(struct sk_buff *skb, int present_fcs_len,
  94. unsigned int rtap_vendor_space)
  95. {
  96. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
  97. struct ieee80211_hdr *hdr;
  98. hdr = (void *)(skb->data + rtap_vendor_space);
  99. if (status->flag & (RX_FLAG_FAILED_FCS_CRC |
  100. RX_FLAG_FAILED_PLCP_CRC |
  101. RX_FLAG_ONLY_MONITOR))
  102. return true;
  103. if (unlikely(skb->len < 16 + present_fcs_len + rtap_vendor_space))
  104. return true;
  105. if (ieee80211_is_ctl(hdr->frame_control) &&
  106. !ieee80211_is_pspoll(hdr->frame_control) &&
  107. !ieee80211_is_back_req(hdr->frame_control))
  108. return true;
  109. return false;
  110. }
  111. static int
  112. ieee80211_rx_radiotap_hdrlen(struct ieee80211_local *local,
  113. struct ieee80211_rx_status *status,
  114. struct sk_buff *skb)
  115. {
  116. int len;
  117. /* always present fields */
  118. len = sizeof(struct ieee80211_radiotap_header) + 8;
  119. /* allocate extra bitmaps */
  120. if (status->chains)
  121. len += 4 * hweight8(status->chains);
  122. if (ieee80211_have_rx_timestamp(status)) {
  123. len = ALIGN(len, 8);
  124. len += 8;
  125. }
  126. if (ieee80211_hw_check(&local->hw, SIGNAL_DBM))
  127. len += 1;
  128. /* antenna field, if we don't have per-chain info */
  129. if (!status->chains)
  130. len += 1;
  131. /* padding for RX_FLAGS if necessary */
  132. len = ALIGN(len, 2);
  133. if (status->flag & RX_FLAG_HT) /* HT info */
  134. len += 3;
  135. if (status->flag & RX_FLAG_AMPDU_DETAILS) {
  136. len = ALIGN(len, 4);
  137. len += 8;
  138. }
  139. if (status->flag & RX_FLAG_VHT) {
  140. len = ALIGN(len, 2);
  141. len += 12;
  142. }
  143. if (local->hw.radiotap_timestamp.units_pos >= 0) {
  144. len = ALIGN(len, 8);
  145. len += 12;
  146. }
  147. if (status->chains) {
  148. /* antenna and antenna signal fields */
  149. len += 2 * hweight8(status->chains);
  150. }
  151. if (status->flag & RX_FLAG_RADIOTAP_VENDOR_DATA) {
  152. struct ieee80211_vendor_radiotap *rtap = (void *)skb->data;
  153. /* vendor presence bitmap */
  154. len += 4;
  155. /* alignment for fixed 6-byte vendor data header */
  156. len = ALIGN(len, 2);
  157. /* vendor data header */
  158. len += 6;
  159. if (WARN_ON(rtap->align == 0))
  160. rtap->align = 1;
  161. len = ALIGN(len, rtap->align);
  162. len += rtap->len + rtap->pad;
  163. }
  164. return len;
  165. }
  166. static void ieee80211_handle_mu_mimo_mon(struct ieee80211_sub_if_data *sdata,
  167. struct sk_buff *skb,
  168. int rtap_vendor_space)
  169. {
  170. struct {
  171. struct ieee80211_hdr_3addr hdr;
  172. u8 category;
  173. u8 action_code;
  174. } __packed action;
  175. if (!sdata)
  176. return;
  177. BUILD_BUG_ON(sizeof(action) != IEEE80211_MIN_ACTION_SIZE + 1);
  178. if (skb->len < rtap_vendor_space + sizeof(action) +
  179. VHT_MUMIMO_GROUPS_DATA_LEN)
  180. return;
  181. if (!is_valid_ether_addr(sdata->u.mntr.mu_follow_addr))
  182. return;
  183. skb_copy_bits(skb, rtap_vendor_space, &action, sizeof(action));
  184. if (!ieee80211_is_action(action.hdr.frame_control))
  185. return;
  186. if (action.category != WLAN_CATEGORY_VHT)
  187. return;
  188. if (action.action_code != WLAN_VHT_ACTION_GROUPID_MGMT)
  189. return;
  190. if (!ether_addr_equal(action.hdr.addr1, sdata->u.mntr.mu_follow_addr))
  191. return;
  192. skb = skb_copy(skb, GFP_ATOMIC);
  193. if (!skb)
  194. return;
  195. skb->pkt_type = IEEE80211_SDATA_QUEUE_TYPE_FRAME;
  196. skb_queue_tail(&sdata->skb_queue, skb);
  197. ieee80211_queue_work(&sdata->local->hw, &sdata->work);
  198. }
  199. /*
  200. * ieee80211_add_rx_radiotap_header - add radiotap header
  201. *
  202. * add a radiotap header containing all the fields which the hardware provided.
  203. */
  204. static void
  205. ieee80211_add_rx_radiotap_header(struct ieee80211_local *local,
  206. struct sk_buff *skb,
  207. struct ieee80211_rate *rate,
  208. int rtap_len, bool has_fcs)
  209. {
  210. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
  211. struct ieee80211_radiotap_header *rthdr;
  212. unsigned char *pos;
  213. __le32 *it_present;
  214. u32 it_present_val;
  215. u16 rx_flags = 0;
  216. u16 channel_flags = 0;
  217. int mpdulen, chain;
  218. unsigned long chains = status->chains;
  219. struct ieee80211_vendor_radiotap rtap = {};
  220. if (status->flag & RX_FLAG_RADIOTAP_VENDOR_DATA) {
  221. rtap = *(struct ieee80211_vendor_radiotap *)skb->data;
  222. /* rtap.len and rtap.pad are undone immediately */
  223. skb_pull(skb, sizeof(rtap) + rtap.len + rtap.pad);
  224. }
  225. mpdulen = skb->len;
  226. if (!(has_fcs && ieee80211_hw_check(&local->hw, RX_INCLUDES_FCS)))
  227. mpdulen += FCS_LEN;
  228. rthdr = (struct ieee80211_radiotap_header *)skb_push(skb, rtap_len);
  229. memset(rthdr, 0, rtap_len - rtap.len - rtap.pad);
  230. it_present = &rthdr->it_present;
  231. /* radiotap header, set always present flags */
  232. rthdr->it_len = cpu_to_le16(rtap_len);
  233. it_present_val = BIT(IEEE80211_RADIOTAP_FLAGS) |
  234. BIT(IEEE80211_RADIOTAP_CHANNEL) |
  235. BIT(IEEE80211_RADIOTAP_RX_FLAGS);
  236. if (!status->chains)
  237. it_present_val |= BIT(IEEE80211_RADIOTAP_ANTENNA);
  238. for_each_set_bit(chain, &chains, IEEE80211_MAX_CHAINS) {
  239. it_present_val |=
  240. BIT(IEEE80211_RADIOTAP_EXT) |
  241. BIT(IEEE80211_RADIOTAP_RADIOTAP_NAMESPACE);
  242. put_unaligned_le32(it_present_val, it_present);
  243. it_present++;
  244. it_present_val = BIT(IEEE80211_RADIOTAP_ANTENNA) |
  245. BIT(IEEE80211_RADIOTAP_DBM_ANTSIGNAL);
  246. }
  247. if (status->flag & RX_FLAG_RADIOTAP_VENDOR_DATA) {
  248. it_present_val |= BIT(IEEE80211_RADIOTAP_VENDOR_NAMESPACE) |
  249. BIT(IEEE80211_RADIOTAP_EXT);
  250. put_unaligned_le32(it_present_val, it_present);
  251. it_present++;
  252. it_present_val = rtap.present;
  253. }
  254. put_unaligned_le32(it_present_val, it_present);
  255. pos = (void *)(it_present + 1);
  256. /* the order of the following fields is important */
  257. /* IEEE80211_RADIOTAP_TSFT */
  258. if (ieee80211_have_rx_timestamp(status)) {
  259. /* padding */
  260. while ((pos - (u8 *)rthdr) & 7)
  261. *pos++ = 0;
  262. put_unaligned_le64(
  263. ieee80211_calculate_rx_timestamp(local, status,
  264. mpdulen, 0),
  265. pos);
  266. rthdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_TSFT);
  267. pos += 8;
  268. }
  269. /* IEEE80211_RADIOTAP_FLAGS */
  270. if (has_fcs && ieee80211_hw_check(&local->hw, RX_INCLUDES_FCS))
  271. *pos |= IEEE80211_RADIOTAP_F_FCS;
  272. if (status->flag & (RX_FLAG_FAILED_FCS_CRC | RX_FLAG_FAILED_PLCP_CRC))
  273. *pos |= IEEE80211_RADIOTAP_F_BADFCS;
  274. if (status->flag & RX_FLAG_SHORTPRE)
  275. *pos |= IEEE80211_RADIOTAP_F_SHORTPRE;
  276. pos++;
  277. /* IEEE80211_RADIOTAP_RATE */
  278. if (!rate || status->flag & (RX_FLAG_HT | RX_FLAG_VHT)) {
  279. /*
  280. * Without rate information don't add it. If we have,
  281. * MCS information is a separate field in radiotap,
  282. * added below. The byte here is needed as padding
  283. * for the channel though, so initialise it to 0.
  284. */
  285. *pos = 0;
  286. } else {
  287. int shift = 0;
  288. rthdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_RATE);
  289. if (status->flag & RX_FLAG_10MHZ)
  290. shift = 1;
  291. else if (status->flag & RX_FLAG_5MHZ)
  292. shift = 2;
  293. *pos = DIV_ROUND_UP(rate->bitrate, 5 * (1 << shift));
  294. }
  295. pos++;
  296. /* IEEE80211_RADIOTAP_CHANNEL */
  297. put_unaligned_le16(status->freq, pos);
  298. pos += 2;
  299. if (status->flag & RX_FLAG_10MHZ)
  300. channel_flags |= IEEE80211_CHAN_HALF;
  301. else if (status->flag & RX_FLAG_5MHZ)
  302. channel_flags |= IEEE80211_CHAN_QUARTER;
  303. if (status->band == NL80211_BAND_5GHZ)
  304. channel_flags |= IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ;
  305. else if (status->flag & (RX_FLAG_HT | RX_FLAG_VHT))
  306. channel_flags |= IEEE80211_CHAN_DYN | IEEE80211_CHAN_2GHZ;
  307. else if (rate && rate->flags & IEEE80211_RATE_ERP_G)
  308. channel_flags |= IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ;
  309. else if (rate)
  310. channel_flags |= IEEE80211_CHAN_CCK | IEEE80211_CHAN_2GHZ;
  311. else
  312. channel_flags |= IEEE80211_CHAN_2GHZ;
  313. put_unaligned_le16(channel_flags, pos);
  314. pos += 2;
  315. /* IEEE80211_RADIOTAP_DBM_ANTSIGNAL */
  316. if (ieee80211_hw_check(&local->hw, SIGNAL_DBM) &&
  317. !(status->flag & RX_FLAG_NO_SIGNAL_VAL)) {
  318. *pos = status->signal;
  319. rthdr->it_present |=
  320. cpu_to_le32(1 << IEEE80211_RADIOTAP_DBM_ANTSIGNAL);
  321. pos++;
  322. }
  323. /* IEEE80211_RADIOTAP_LOCK_QUALITY is missing */
  324. if (!status->chains) {
  325. /* IEEE80211_RADIOTAP_ANTENNA */
  326. *pos = status->antenna;
  327. pos++;
  328. }
  329. /* IEEE80211_RADIOTAP_DB_ANTNOISE is not used */
  330. /* IEEE80211_RADIOTAP_RX_FLAGS */
  331. /* ensure 2 byte alignment for the 2 byte field as required */
  332. if ((pos - (u8 *)rthdr) & 1)
  333. *pos++ = 0;
  334. if (status->flag & RX_FLAG_FAILED_PLCP_CRC)
  335. rx_flags |= IEEE80211_RADIOTAP_F_RX_BADPLCP;
  336. put_unaligned_le16(rx_flags, pos);
  337. pos += 2;
  338. if (status->flag & RX_FLAG_HT) {
  339. unsigned int stbc;
  340. rthdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_MCS);
  341. *pos++ = local->hw.radiotap_mcs_details;
  342. *pos = 0;
  343. if (status->flag & RX_FLAG_SHORT_GI)
  344. *pos |= IEEE80211_RADIOTAP_MCS_SGI;
  345. if (status->flag & RX_FLAG_40MHZ)
  346. *pos |= IEEE80211_RADIOTAP_MCS_BW_40;
  347. if (status->flag & RX_FLAG_HT_GF)
  348. *pos |= IEEE80211_RADIOTAP_MCS_FMT_GF;
  349. if (status->flag & RX_FLAG_LDPC)
  350. *pos |= IEEE80211_RADIOTAP_MCS_FEC_LDPC;
  351. stbc = (status->flag & RX_FLAG_STBC_MASK) >> RX_FLAG_STBC_SHIFT;
  352. *pos |= stbc << IEEE80211_RADIOTAP_MCS_STBC_SHIFT;
  353. pos++;
  354. *pos++ = status->rate_idx;
  355. }
  356. if (status->flag & RX_FLAG_AMPDU_DETAILS) {
  357. u16 flags = 0;
  358. /* ensure 4 byte alignment */
  359. while ((pos - (u8 *)rthdr) & 3)
  360. pos++;
  361. rthdr->it_present |=
  362. cpu_to_le32(1 << IEEE80211_RADIOTAP_AMPDU_STATUS);
  363. put_unaligned_le32(status->ampdu_reference, pos);
  364. pos += 4;
  365. if (status->flag & RX_FLAG_AMPDU_LAST_KNOWN)
  366. flags |= IEEE80211_RADIOTAP_AMPDU_LAST_KNOWN;
  367. if (status->flag & RX_FLAG_AMPDU_IS_LAST)
  368. flags |= IEEE80211_RADIOTAP_AMPDU_IS_LAST;
  369. if (status->flag & RX_FLAG_AMPDU_DELIM_CRC_ERROR)
  370. flags |= IEEE80211_RADIOTAP_AMPDU_DELIM_CRC_ERR;
  371. if (status->flag & RX_FLAG_AMPDU_DELIM_CRC_KNOWN)
  372. flags |= IEEE80211_RADIOTAP_AMPDU_DELIM_CRC_KNOWN;
  373. put_unaligned_le16(flags, pos);
  374. pos += 2;
  375. if (status->flag & RX_FLAG_AMPDU_DELIM_CRC_KNOWN)
  376. *pos++ = status->ampdu_delimiter_crc;
  377. else
  378. *pos++ = 0;
  379. *pos++ = 0;
  380. }
  381. if (status->flag & RX_FLAG_VHT) {
  382. u16 known = local->hw.radiotap_vht_details;
  383. rthdr->it_present |= cpu_to_le32(1 << IEEE80211_RADIOTAP_VHT);
  384. put_unaligned_le16(known, pos);
  385. pos += 2;
  386. /* flags */
  387. if (status->flag & RX_FLAG_SHORT_GI)
  388. *pos |= IEEE80211_RADIOTAP_VHT_FLAG_SGI;
  389. /* in VHT, STBC is binary */
  390. if (status->flag & RX_FLAG_STBC_MASK)
  391. *pos |= IEEE80211_RADIOTAP_VHT_FLAG_STBC;
  392. if (status->vht_flag & RX_VHT_FLAG_BF)
  393. *pos |= IEEE80211_RADIOTAP_VHT_FLAG_BEAMFORMED;
  394. pos++;
  395. /* bandwidth */
  396. if (status->vht_flag & RX_VHT_FLAG_80MHZ)
  397. *pos++ = 4;
  398. else if (status->vht_flag & RX_VHT_FLAG_160MHZ)
  399. *pos++ = 11;
  400. else if (status->flag & RX_FLAG_40MHZ)
  401. *pos++ = 1;
  402. else /* 20 MHz */
  403. *pos++ = 0;
  404. /* MCS/NSS */
  405. *pos = (status->rate_idx << 4) | status->vht_nss;
  406. pos += 4;
  407. /* coding field */
  408. if (status->flag & RX_FLAG_LDPC)
  409. *pos |= IEEE80211_RADIOTAP_CODING_LDPC_USER0;
  410. pos++;
  411. /* group ID */
  412. pos++;
  413. /* partial_aid */
  414. pos += 2;
  415. }
  416. if (local->hw.radiotap_timestamp.units_pos >= 0) {
  417. u16 accuracy = 0;
  418. u8 flags = IEEE80211_RADIOTAP_TIMESTAMP_FLAG_32BIT;
  419. rthdr->it_present |=
  420. cpu_to_le32(1 << IEEE80211_RADIOTAP_TIMESTAMP);
  421. /* ensure 8 byte alignment */
  422. while ((pos - (u8 *)rthdr) & 7)
  423. pos++;
  424. put_unaligned_le64(status->device_timestamp, pos);
  425. pos += sizeof(u64);
  426. if (local->hw.radiotap_timestamp.accuracy >= 0) {
  427. accuracy = local->hw.radiotap_timestamp.accuracy;
  428. flags |= IEEE80211_RADIOTAP_TIMESTAMP_FLAG_ACCURACY;
  429. }
  430. put_unaligned_le16(accuracy, pos);
  431. pos += sizeof(u16);
  432. *pos++ = local->hw.radiotap_timestamp.units_pos;
  433. *pos++ = flags;
  434. }
  435. for_each_set_bit(chain, &chains, IEEE80211_MAX_CHAINS) {
  436. *pos++ = status->chain_signal[chain];
  437. *pos++ = chain;
  438. }
  439. if (status->flag & RX_FLAG_RADIOTAP_VENDOR_DATA) {
  440. /* ensure 2 byte alignment for the vendor field as required */
  441. if ((pos - (u8 *)rthdr) & 1)
  442. *pos++ = 0;
  443. *pos++ = rtap.oui[0];
  444. *pos++ = rtap.oui[1];
  445. *pos++ = rtap.oui[2];
  446. *pos++ = rtap.subns;
  447. put_unaligned_le16(rtap.len, pos);
  448. pos += 2;
  449. /* align the actual payload as requested */
  450. while ((pos - (u8 *)rthdr) & (rtap.align - 1))
  451. *pos++ = 0;
  452. /* data (and possible padding) already follows */
  453. }
  454. }
  455. static struct sk_buff *
  456. ieee80211_make_monitor_skb(struct ieee80211_local *local,
  457. struct sk_buff **origskb,
  458. struct ieee80211_rate *rate,
  459. int rtap_vendor_space, bool use_origskb)
  460. {
  461. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(*origskb);
  462. int rt_hdrlen, needed_headroom;
  463. struct sk_buff *skb;
  464. /* room for the radiotap header based on driver features */
  465. rt_hdrlen = ieee80211_rx_radiotap_hdrlen(local, status, *origskb);
  466. needed_headroom = rt_hdrlen - rtap_vendor_space;
  467. if (use_origskb) {
  468. /* only need to expand headroom if necessary */
  469. skb = *origskb;
  470. *origskb = NULL;
  471. /*
  472. * This shouldn't trigger often because most devices have an
  473. * RX header they pull before we get here, and that should
  474. * be big enough for our radiotap information. We should
  475. * probably export the length to drivers so that we can have
  476. * them allocate enough headroom to start with.
  477. */
  478. if (skb_headroom(skb) < needed_headroom &&
  479. pskb_expand_head(skb, needed_headroom, 0, GFP_ATOMIC)) {
  480. dev_kfree_skb(skb);
  481. return NULL;
  482. }
  483. } else {
  484. /*
  485. * Need to make a copy and possibly remove radiotap header
  486. * and FCS from the original.
  487. */
  488. skb = skb_copy_expand(*origskb, needed_headroom, 0, GFP_ATOMIC);
  489. if (!skb)
  490. return NULL;
  491. }
  492. /* prepend radiotap information */
  493. ieee80211_add_rx_radiotap_header(local, skb, rate, rt_hdrlen, true);
  494. skb_reset_mac_header(skb);
  495. skb->ip_summed = CHECKSUM_UNNECESSARY;
  496. skb->pkt_type = PACKET_OTHERHOST;
  497. skb->protocol = htons(ETH_P_802_2);
  498. return skb;
  499. }
  500. /*
  501. * This function copies a received frame to all monitor interfaces and
  502. * returns a cleaned-up SKB that no longer includes the FCS nor the
  503. * radiotap header the driver might have added.
  504. */
  505. static struct sk_buff *
  506. ieee80211_rx_monitor(struct ieee80211_local *local, struct sk_buff *origskb,
  507. struct ieee80211_rate *rate)
  508. {
  509. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(origskb);
  510. struct ieee80211_sub_if_data *sdata;
  511. struct sk_buff *monskb = NULL;
  512. int present_fcs_len = 0;
  513. unsigned int rtap_vendor_space = 0;
  514. struct ieee80211_sub_if_data *monitor_sdata =
  515. rcu_dereference(local->monitor_sdata);
  516. bool only_monitor = false;
  517. if (unlikely(status->flag & RX_FLAG_RADIOTAP_VENDOR_DATA)) {
  518. struct ieee80211_vendor_radiotap *rtap = (void *)origskb->data;
  519. rtap_vendor_space = sizeof(*rtap) + rtap->len + rtap->pad;
  520. }
  521. /*
  522. * First, we may need to make a copy of the skb because
  523. * (1) we need to modify it for radiotap (if not present), and
  524. * (2) the other RX handlers will modify the skb we got.
  525. *
  526. * We don't need to, of course, if we aren't going to return
  527. * the SKB because it has a bad FCS/PLCP checksum.
  528. */
  529. if (ieee80211_hw_check(&local->hw, RX_INCLUDES_FCS)) {
  530. if (unlikely(origskb->len <= FCS_LEN)) {
  531. /* driver bug */
  532. WARN_ON(1);
  533. dev_kfree_skb(origskb);
  534. return NULL;
  535. }
  536. present_fcs_len = FCS_LEN;
  537. }
  538. /* ensure hdr->frame_control and vendor radiotap data are in skb head */
  539. if (!pskb_may_pull(origskb, 2 + rtap_vendor_space)) {
  540. dev_kfree_skb(origskb);
  541. return NULL;
  542. }
  543. only_monitor = should_drop_frame(origskb, present_fcs_len,
  544. rtap_vendor_space);
  545. if (!local->monitors || (status->flag & RX_FLAG_SKIP_MONITOR)) {
  546. if (only_monitor) {
  547. dev_kfree_skb(origskb);
  548. return NULL;
  549. }
  550. remove_monitor_info(origskb, present_fcs_len,
  551. rtap_vendor_space);
  552. return origskb;
  553. }
  554. ieee80211_handle_mu_mimo_mon(monitor_sdata, origskb, rtap_vendor_space);
  555. list_for_each_entry_rcu(sdata, &local->mon_list, u.mntr.list) {
  556. bool last_monitor = list_is_last(&sdata->u.mntr.list,
  557. &local->mon_list);
  558. if (!monskb)
  559. monskb = ieee80211_make_monitor_skb(local, &origskb,
  560. rate,
  561. rtap_vendor_space,
  562. only_monitor &&
  563. last_monitor);
  564. if (monskb) {
  565. struct sk_buff *skb;
  566. if (last_monitor) {
  567. skb = monskb;
  568. monskb = NULL;
  569. } else {
  570. skb = skb_clone(monskb, GFP_ATOMIC);
  571. }
  572. if (skb) {
  573. skb->dev = sdata->dev;
  574. ieee80211_rx_stats(skb->dev, skb->len);
  575. netif_receive_skb(skb);
  576. }
  577. }
  578. if (last_monitor)
  579. break;
  580. }
  581. /* this happens if last_monitor was erroneously false */
  582. dev_kfree_skb(monskb);
  583. /* ditto */
  584. if (!origskb)
  585. return NULL;
  586. remove_monitor_info(origskb, present_fcs_len, rtap_vendor_space);
  587. return origskb;
  588. }
  589. static void ieee80211_parse_qos(struct ieee80211_rx_data *rx)
  590. {
  591. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
  592. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
  593. int tid, seqno_idx, security_idx;
  594. /* does the frame have a qos control field? */
  595. if (ieee80211_is_data_qos(hdr->frame_control)) {
  596. u8 *qc = ieee80211_get_qos_ctl(hdr);
  597. /* frame has qos control */
  598. tid = *qc & IEEE80211_QOS_CTL_TID_MASK;
  599. if (*qc & IEEE80211_QOS_CTL_A_MSDU_PRESENT)
  600. status->rx_flags |= IEEE80211_RX_AMSDU;
  601. seqno_idx = tid;
  602. security_idx = tid;
  603. } else {
  604. /*
  605. * IEEE 802.11-2007, 7.1.3.4.1 ("Sequence Number field"):
  606. *
  607. * Sequence numbers for management frames, QoS data
  608. * frames with a broadcast/multicast address in the
  609. * Address 1 field, and all non-QoS data frames sent
  610. * by QoS STAs are assigned using an additional single
  611. * modulo-4096 counter, [...]
  612. *
  613. * We also use that counter for non-QoS STAs.
  614. */
  615. seqno_idx = IEEE80211_NUM_TIDS;
  616. security_idx = 0;
  617. if (ieee80211_is_mgmt(hdr->frame_control))
  618. security_idx = IEEE80211_NUM_TIDS;
  619. tid = 0;
  620. }
  621. rx->seqno_idx = seqno_idx;
  622. rx->security_idx = security_idx;
  623. /* Set skb->priority to 1d tag if highest order bit of TID is not set.
  624. * For now, set skb->priority to 0 for other cases. */
  625. rx->skb->priority = (tid > 7) ? 0 : tid;
  626. }
  627. /**
  628. * DOC: Packet alignment
  629. *
  630. * Drivers always need to pass packets that are aligned to two-byte boundaries
  631. * to the stack.
  632. *
  633. * Additionally, should, if possible, align the payload data in a way that
  634. * guarantees that the contained IP header is aligned to a four-byte
  635. * boundary. In the case of regular frames, this simply means aligning the
  636. * payload to a four-byte boundary (because either the IP header is directly
  637. * contained, or IV/RFC1042 headers that have a length divisible by four are
  638. * in front of it). If the payload data is not properly aligned and the
  639. * architecture doesn't support efficient unaligned operations, mac80211
  640. * will align the data.
  641. *
  642. * With A-MSDU frames, however, the payload data address must yield two modulo
  643. * four because there are 14-byte 802.3 headers within the A-MSDU frames that
  644. * push the IP header further back to a multiple of four again. Thankfully, the
  645. * specs were sane enough this time around to require padding each A-MSDU
  646. * subframe to a length that is a multiple of four.
  647. *
  648. * Padding like Atheros hardware adds which is between the 802.11 header and
  649. * the payload is not supported, the driver is required to move the 802.11
  650. * header to be directly in front of the payload in that case.
  651. */
  652. static void ieee80211_verify_alignment(struct ieee80211_rx_data *rx)
  653. {
  654. #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
  655. WARN_ON_ONCE((unsigned long)rx->skb->data & 1);
  656. #endif
  657. }
  658. /* rx handlers */
  659. static int ieee80211_is_unicast_robust_mgmt_frame(struct sk_buff *skb)
  660. {
  661. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
  662. if (is_multicast_ether_addr(hdr->addr1))
  663. return 0;
  664. return ieee80211_is_robust_mgmt_frame(skb);
  665. }
  666. static int ieee80211_is_multicast_robust_mgmt_frame(struct sk_buff *skb)
  667. {
  668. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
  669. if (!is_multicast_ether_addr(hdr->addr1))
  670. return 0;
  671. return ieee80211_is_robust_mgmt_frame(skb);
  672. }
  673. /* Get the BIP key index from MMIE; return -1 if this is not a BIP frame */
  674. static int ieee80211_get_mmie_keyidx(struct sk_buff *skb)
  675. {
  676. struct ieee80211_mgmt *hdr = (struct ieee80211_mgmt *) skb->data;
  677. struct ieee80211_mmie *mmie;
  678. struct ieee80211_mmie_16 *mmie16;
  679. if (skb->len < 24 + sizeof(*mmie) || !is_multicast_ether_addr(hdr->da))
  680. return -1;
  681. if (!ieee80211_is_robust_mgmt_frame(skb))
  682. return -1; /* not a robust management frame */
  683. mmie = (struct ieee80211_mmie *)
  684. (skb->data + skb->len - sizeof(*mmie));
  685. if (mmie->element_id == WLAN_EID_MMIE &&
  686. mmie->length == sizeof(*mmie) - 2)
  687. return le16_to_cpu(mmie->key_id);
  688. mmie16 = (struct ieee80211_mmie_16 *)
  689. (skb->data + skb->len - sizeof(*mmie16));
  690. if (skb->len >= 24 + sizeof(*mmie16) &&
  691. mmie16->element_id == WLAN_EID_MMIE &&
  692. mmie16->length == sizeof(*mmie16) - 2)
  693. return le16_to_cpu(mmie16->key_id);
  694. return -1;
  695. }
  696. static int ieee80211_get_cs_keyid(const struct ieee80211_cipher_scheme *cs,
  697. struct sk_buff *skb)
  698. {
  699. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
  700. __le16 fc;
  701. int hdrlen;
  702. u8 keyid;
  703. fc = hdr->frame_control;
  704. hdrlen = ieee80211_hdrlen(fc);
  705. if (skb->len < hdrlen + cs->hdr_len)
  706. return -EINVAL;
  707. skb_copy_bits(skb, hdrlen + cs->key_idx_off, &keyid, 1);
  708. keyid &= cs->key_idx_mask;
  709. keyid >>= cs->key_idx_shift;
  710. return keyid;
  711. }
  712. static ieee80211_rx_result ieee80211_rx_mesh_check(struct ieee80211_rx_data *rx)
  713. {
  714. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
  715. char *dev_addr = rx->sdata->vif.addr;
  716. if (ieee80211_is_data(hdr->frame_control)) {
  717. if (is_multicast_ether_addr(hdr->addr1)) {
  718. if (ieee80211_has_tods(hdr->frame_control) ||
  719. !ieee80211_has_fromds(hdr->frame_control))
  720. return RX_DROP_MONITOR;
  721. if (ether_addr_equal(hdr->addr3, dev_addr))
  722. return RX_DROP_MONITOR;
  723. } else {
  724. if (!ieee80211_has_a4(hdr->frame_control))
  725. return RX_DROP_MONITOR;
  726. if (ether_addr_equal(hdr->addr4, dev_addr))
  727. return RX_DROP_MONITOR;
  728. }
  729. }
  730. /* If there is not an established peer link and this is not a peer link
  731. * establisment frame, beacon or probe, drop the frame.
  732. */
  733. if (!rx->sta || sta_plink_state(rx->sta) != NL80211_PLINK_ESTAB) {
  734. struct ieee80211_mgmt *mgmt;
  735. if (!ieee80211_is_mgmt(hdr->frame_control))
  736. return RX_DROP_MONITOR;
  737. if (ieee80211_is_action(hdr->frame_control)) {
  738. u8 category;
  739. /* make sure category field is present */
  740. if (rx->skb->len < IEEE80211_MIN_ACTION_SIZE)
  741. return RX_DROP_MONITOR;
  742. mgmt = (struct ieee80211_mgmt *)hdr;
  743. category = mgmt->u.action.category;
  744. if (category != WLAN_CATEGORY_MESH_ACTION &&
  745. category != WLAN_CATEGORY_SELF_PROTECTED)
  746. return RX_DROP_MONITOR;
  747. return RX_CONTINUE;
  748. }
  749. if (ieee80211_is_probe_req(hdr->frame_control) ||
  750. ieee80211_is_probe_resp(hdr->frame_control) ||
  751. ieee80211_is_beacon(hdr->frame_control) ||
  752. ieee80211_is_auth(hdr->frame_control))
  753. return RX_CONTINUE;
  754. return RX_DROP_MONITOR;
  755. }
  756. return RX_CONTINUE;
  757. }
  758. static inline bool ieee80211_rx_reorder_ready(struct tid_ampdu_rx *tid_agg_rx,
  759. int index)
  760. {
  761. struct sk_buff_head *frames = &tid_agg_rx->reorder_buf[index];
  762. struct sk_buff *tail = skb_peek_tail(frames);
  763. struct ieee80211_rx_status *status;
  764. if (tid_agg_rx->reorder_buf_filtered & BIT_ULL(index))
  765. return true;
  766. if (!tail)
  767. return false;
  768. status = IEEE80211_SKB_RXCB(tail);
  769. if (status->flag & RX_FLAG_AMSDU_MORE)
  770. return false;
  771. return true;
  772. }
  773. static void ieee80211_release_reorder_frame(struct ieee80211_sub_if_data *sdata,
  774. struct tid_ampdu_rx *tid_agg_rx,
  775. int index,
  776. struct sk_buff_head *frames)
  777. {
  778. struct sk_buff_head *skb_list = &tid_agg_rx->reorder_buf[index];
  779. struct sk_buff *skb;
  780. struct ieee80211_rx_status *status;
  781. lockdep_assert_held(&tid_agg_rx->reorder_lock);
  782. if (skb_queue_empty(skb_list))
  783. goto no_frame;
  784. if (!ieee80211_rx_reorder_ready(tid_agg_rx, index)) {
  785. __skb_queue_purge(skb_list);
  786. goto no_frame;
  787. }
  788. /* release frames from the reorder ring buffer */
  789. tid_agg_rx->stored_mpdu_num--;
  790. while ((skb = __skb_dequeue(skb_list))) {
  791. status = IEEE80211_SKB_RXCB(skb);
  792. status->rx_flags |= IEEE80211_RX_DEFERRED_RELEASE;
  793. __skb_queue_tail(frames, skb);
  794. }
  795. no_frame:
  796. tid_agg_rx->reorder_buf_filtered &= ~BIT_ULL(index);
  797. tid_agg_rx->head_seq_num = ieee80211_sn_inc(tid_agg_rx->head_seq_num);
  798. }
  799. static void ieee80211_release_reorder_frames(struct ieee80211_sub_if_data *sdata,
  800. struct tid_ampdu_rx *tid_agg_rx,
  801. u16 head_seq_num,
  802. struct sk_buff_head *frames)
  803. {
  804. int index;
  805. lockdep_assert_held(&tid_agg_rx->reorder_lock);
  806. while (ieee80211_sn_less(tid_agg_rx->head_seq_num, head_seq_num)) {
  807. index = tid_agg_rx->head_seq_num % tid_agg_rx->buf_size;
  808. ieee80211_release_reorder_frame(sdata, tid_agg_rx, index,
  809. frames);
  810. }
  811. }
  812. /*
  813. * Timeout (in jiffies) for skb's that are waiting in the RX reorder buffer. If
  814. * the skb was added to the buffer longer than this time ago, the earlier
  815. * frames that have not yet been received are assumed to be lost and the skb
  816. * can be released for processing. This may also release other skb's from the
  817. * reorder buffer if there are no additional gaps between the frames.
  818. *
  819. * Callers must hold tid_agg_rx->reorder_lock.
  820. */
  821. #define HT_RX_REORDER_BUF_TIMEOUT (HZ / 10)
  822. static void ieee80211_sta_reorder_release(struct ieee80211_sub_if_data *sdata,
  823. struct tid_ampdu_rx *tid_agg_rx,
  824. struct sk_buff_head *frames)
  825. {
  826. int index, i, j;
  827. lockdep_assert_held(&tid_agg_rx->reorder_lock);
  828. /* release the buffer until next missing frame */
  829. index = tid_agg_rx->head_seq_num % tid_agg_rx->buf_size;
  830. if (!ieee80211_rx_reorder_ready(tid_agg_rx, index) &&
  831. tid_agg_rx->stored_mpdu_num) {
  832. /*
  833. * No buffers ready to be released, but check whether any
  834. * frames in the reorder buffer have timed out.
  835. */
  836. int skipped = 1;
  837. for (j = (index + 1) % tid_agg_rx->buf_size; j != index;
  838. j = (j + 1) % tid_agg_rx->buf_size) {
  839. if (!ieee80211_rx_reorder_ready(tid_agg_rx, j)) {
  840. skipped++;
  841. continue;
  842. }
  843. if (skipped &&
  844. !time_after(jiffies, tid_agg_rx->reorder_time[j] +
  845. HT_RX_REORDER_BUF_TIMEOUT))
  846. goto set_release_timer;
  847. /* don't leave incomplete A-MSDUs around */
  848. for (i = (index + 1) % tid_agg_rx->buf_size; i != j;
  849. i = (i + 1) % tid_agg_rx->buf_size)
  850. __skb_queue_purge(&tid_agg_rx->reorder_buf[i]);
  851. ht_dbg_ratelimited(sdata,
  852. "release an RX reorder frame due to timeout on earlier frames\n");
  853. ieee80211_release_reorder_frame(sdata, tid_agg_rx, j,
  854. frames);
  855. /*
  856. * Increment the head seq# also for the skipped slots.
  857. */
  858. tid_agg_rx->head_seq_num =
  859. (tid_agg_rx->head_seq_num +
  860. skipped) & IEEE80211_SN_MASK;
  861. skipped = 0;
  862. }
  863. } else while (ieee80211_rx_reorder_ready(tid_agg_rx, index)) {
  864. ieee80211_release_reorder_frame(sdata, tid_agg_rx, index,
  865. frames);
  866. index = tid_agg_rx->head_seq_num % tid_agg_rx->buf_size;
  867. }
  868. if (tid_agg_rx->stored_mpdu_num) {
  869. j = index = tid_agg_rx->head_seq_num % tid_agg_rx->buf_size;
  870. for (; j != (index - 1) % tid_agg_rx->buf_size;
  871. j = (j + 1) % tid_agg_rx->buf_size) {
  872. if (ieee80211_rx_reorder_ready(tid_agg_rx, j))
  873. break;
  874. }
  875. set_release_timer:
  876. if (!tid_agg_rx->removed)
  877. mod_timer(&tid_agg_rx->reorder_timer,
  878. tid_agg_rx->reorder_time[j] + 1 +
  879. HT_RX_REORDER_BUF_TIMEOUT);
  880. } else {
  881. del_timer(&tid_agg_rx->reorder_timer);
  882. }
  883. }
  884. /*
  885. * As this function belongs to the RX path it must be under
  886. * rcu_read_lock protection. It returns false if the frame
  887. * can be processed immediately, true if it was consumed.
  888. */
  889. static bool ieee80211_sta_manage_reorder_buf(struct ieee80211_sub_if_data *sdata,
  890. struct tid_ampdu_rx *tid_agg_rx,
  891. struct sk_buff *skb,
  892. struct sk_buff_head *frames)
  893. {
  894. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
  895. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
  896. u16 sc = le16_to_cpu(hdr->seq_ctrl);
  897. u16 mpdu_seq_num = (sc & IEEE80211_SCTL_SEQ) >> 4;
  898. u16 head_seq_num, buf_size;
  899. int index;
  900. bool ret = true;
  901. spin_lock(&tid_agg_rx->reorder_lock);
  902. /*
  903. * Offloaded BA sessions have no known starting sequence number so pick
  904. * one from first Rxed frame for this tid after BA was started.
  905. */
  906. if (unlikely(tid_agg_rx->auto_seq)) {
  907. tid_agg_rx->auto_seq = false;
  908. tid_agg_rx->ssn = mpdu_seq_num;
  909. tid_agg_rx->head_seq_num = mpdu_seq_num;
  910. }
  911. buf_size = tid_agg_rx->buf_size;
  912. head_seq_num = tid_agg_rx->head_seq_num;
  913. /*
  914. * If the current MPDU's SN is smaller than the SSN, it shouldn't
  915. * be reordered.
  916. */
  917. if (unlikely(!tid_agg_rx->started)) {
  918. if (ieee80211_sn_less(mpdu_seq_num, head_seq_num)) {
  919. ret = false;
  920. goto out;
  921. }
  922. tid_agg_rx->started = true;
  923. }
  924. /* frame with out of date sequence number */
  925. if (ieee80211_sn_less(mpdu_seq_num, head_seq_num)) {
  926. dev_kfree_skb(skb);
  927. goto out;
  928. }
  929. /*
  930. * If frame the sequence number exceeds our buffering window
  931. * size release some previous frames to make room for this one.
  932. */
  933. if (!ieee80211_sn_less(mpdu_seq_num, head_seq_num + buf_size)) {
  934. head_seq_num = ieee80211_sn_inc(
  935. ieee80211_sn_sub(mpdu_seq_num, buf_size));
  936. /* release stored frames up to new head to stack */
  937. ieee80211_release_reorder_frames(sdata, tid_agg_rx,
  938. head_seq_num, frames);
  939. }
  940. /* Now the new frame is always in the range of the reordering buffer */
  941. index = mpdu_seq_num % tid_agg_rx->buf_size;
  942. /* check if we already stored this frame */
  943. if (ieee80211_rx_reorder_ready(tid_agg_rx, index)) {
  944. dev_kfree_skb(skb);
  945. goto out;
  946. }
  947. /*
  948. * If the current MPDU is in the right order and nothing else
  949. * is stored we can process it directly, no need to buffer it.
  950. * If it is first but there's something stored, we may be able
  951. * to release frames after this one.
  952. */
  953. if (mpdu_seq_num == tid_agg_rx->head_seq_num &&
  954. tid_agg_rx->stored_mpdu_num == 0) {
  955. if (!(status->flag & RX_FLAG_AMSDU_MORE))
  956. tid_agg_rx->head_seq_num =
  957. ieee80211_sn_inc(tid_agg_rx->head_seq_num);
  958. ret = false;
  959. goto out;
  960. }
  961. /* put the frame in the reordering buffer */
  962. __skb_queue_tail(&tid_agg_rx->reorder_buf[index], skb);
  963. if (!(status->flag & RX_FLAG_AMSDU_MORE)) {
  964. tid_agg_rx->reorder_time[index] = jiffies;
  965. tid_agg_rx->stored_mpdu_num++;
  966. ieee80211_sta_reorder_release(sdata, tid_agg_rx, frames);
  967. }
  968. out:
  969. spin_unlock(&tid_agg_rx->reorder_lock);
  970. return ret;
  971. }
  972. /*
  973. * Reorder MPDUs from A-MPDUs, keeping them on a buffer. Returns
  974. * true if the MPDU was buffered, false if it should be processed.
  975. */
  976. static void ieee80211_rx_reorder_ampdu(struct ieee80211_rx_data *rx,
  977. struct sk_buff_head *frames)
  978. {
  979. struct sk_buff *skb = rx->skb;
  980. struct ieee80211_local *local = rx->local;
  981. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
  982. struct sta_info *sta = rx->sta;
  983. struct tid_ampdu_rx *tid_agg_rx;
  984. u16 sc;
  985. u8 tid, ack_policy;
  986. if (!ieee80211_is_data_qos(hdr->frame_control) ||
  987. is_multicast_ether_addr(hdr->addr1))
  988. goto dont_reorder;
  989. /*
  990. * filter the QoS data rx stream according to
  991. * STA/TID and check if this STA/TID is on aggregation
  992. */
  993. if (!sta)
  994. goto dont_reorder;
  995. ack_policy = *ieee80211_get_qos_ctl(hdr) &
  996. IEEE80211_QOS_CTL_ACK_POLICY_MASK;
  997. tid = *ieee80211_get_qos_ctl(hdr) & IEEE80211_QOS_CTL_TID_MASK;
  998. tid_agg_rx = rcu_dereference(sta->ampdu_mlme.tid_rx[tid]);
  999. if (!tid_agg_rx) {
  1000. if (ack_policy == IEEE80211_QOS_CTL_ACK_POLICY_BLOCKACK &&
  1001. !test_bit(tid, rx->sta->ampdu_mlme.agg_session_valid) &&
  1002. !test_and_set_bit(tid, rx->sta->ampdu_mlme.unexpected_agg))
  1003. ieee80211_send_delba(rx->sdata, rx->sta->sta.addr, tid,
  1004. WLAN_BACK_RECIPIENT,
  1005. WLAN_REASON_QSTA_REQUIRE_SETUP);
  1006. goto dont_reorder;
  1007. }
  1008. /* qos null data frames are excluded */
  1009. if (unlikely(hdr->frame_control & cpu_to_le16(IEEE80211_STYPE_NULLFUNC)))
  1010. goto dont_reorder;
  1011. /* not part of a BA session */
  1012. if (ack_policy != IEEE80211_QOS_CTL_ACK_POLICY_BLOCKACK &&
  1013. ack_policy != IEEE80211_QOS_CTL_ACK_POLICY_NORMAL)
  1014. goto dont_reorder;
  1015. /* new, potentially un-ordered, ampdu frame - process it */
  1016. /* reset session timer */
  1017. if (tid_agg_rx->timeout)
  1018. tid_agg_rx->last_rx = jiffies;
  1019. /* if this mpdu is fragmented - terminate rx aggregation session */
  1020. sc = le16_to_cpu(hdr->seq_ctrl);
  1021. if (sc & IEEE80211_SCTL_FRAG) {
  1022. skb->pkt_type = IEEE80211_SDATA_QUEUE_TYPE_FRAME;
  1023. skb_queue_tail(&rx->sdata->skb_queue, skb);
  1024. ieee80211_queue_work(&local->hw, &rx->sdata->work);
  1025. return;
  1026. }
  1027. /*
  1028. * No locking needed -- we will only ever process one
  1029. * RX packet at a time, and thus own tid_agg_rx. All
  1030. * other code manipulating it needs to (and does) make
  1031. * sure that we cannot get to it any more before doing
  1032. * anything with it.
  1033. */
  1034. if (ieee80211_sta_manage_reorder_buf(rx->sdata, tid_agg_rx, skb,
  1035. frames))
  1036. return;
  1037. dont_reorder:
  1038. __skb_queue_tail(frames, skb);
  1039. }
  1040. static ieee80211_rx_result debug_noinline
  1041. ieee80211_rx_h_check_dup(struct ieee80211_rx_data *rx)
  1042. {
  1043. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
  1044. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
  1045. if (status->flag & RX_FLAG_DUP_VALIDATED)
  1046. return RX_CONTINUE;
  1047. /*
  1048. * Drop duplicate 802.11 retransmissions
  1049. * (IEEE 802.11-2012: 9.3.2.10 "Duplicate detection and recovery")
  1050. */
  1051. if (rx->skb->len < 24)
  1052. return RX_CONTINUE;
  1053. if (ieee80211_is_ctl(hdr->frame_control) ||
  1054. ieee80211_is_qos_nullfunc(hdr->frame_control) ||
  1055. is_multicast_ether_addr(hdr->addr1))
  1056. return RX_CONTINUE;
  1057. if (!rx->sta)
  1058. return RX_CONTINUE;
  1059. if (unlikely(ieee80211_has_retry(hdr->frame_control) &&
  1060. rx->sta->last_seq_ctrl[rx->seqno_idx] == hdr->seq_ctrl)) {
  1061. I802_DEBUG_INC(rx->local->dot11FrameDuplicateCount);
  1062. rx->sta->rx_stats.num_duplicates++;
  1063. return RX_DROP_UNUSABLE;
  1064. } else if (!(status->flag & RX_FLAG_AMSDU_MORE)) {
  1065. rx->sta->last_seq_ctrl[rx->seqno_idx] = hdr->seq_ctrl;
  1066. }
  1067. return RX_CONTINUE;
  1068. }
  1069. static ieee80211_rx_result debug_noinline
  1070. ieee80211_rx_h_check(struct ieee80211_rx_data *rx)
  1071. {
  1072. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
  1073. /* Drop disallowed frame classes based on STA auth/assoc state;
  1074. * IEEE 802.11, Chap 5.5.
  1075. *
  1076. * mac80211 filters only based on association state, i.e. it drops
  1077. * Class 3 frames from not associated stations. hostapd sends
  1078. * deauth/disassoc frames when needed. In addition, hostapd is
  1079. * responsible for filtering on both auth and assoc states.
  1080. */
  1081. if (ieee80211_vif_is_mesh(&rx->sdata->vif))
  1082. return ieee80211_rx_mesh_check(rx);
  1083. if (unlikely((ieee80211_is_data(hdr->frame_control) ||
  1084. ieee80211_is_pspoll(hdr->frame_control)) &&
  1085. rx->sdata->vif.type != NL80211_IFTYPE_ADHOC &&
  1086. rx->sdata->vif.type != NL80211_IFTYPE_WDS &&
  1087. rx->sdata->vif.type != NL80211_IFTYPE_OCB &&
  1088. (!rx->sta || !test_sta_flag(rx->sta, WLAN_STA_ASSOC)))) {
  1089. /*
  1090. * accept port control frames from the AP even when it's not
  1091. * yet marked ASSOC to prevent a race where we don't set the
  1092. * assoc bit quickly enough before it sends the first frame
  1093. */
  1094. if (rx->sta && rx->sdata->vif.type == NL80211_IFTYPE_STATION &&
  1095. ieee80211_is_data_present(hdr->frame_control)) {
  1096. unsigned int hdrlen;
  1097. __be16 ethertype;
  1098. hdrlen = ieee80211_hdrlen(hdr->frame_control);
  1099. if (rx->skb->len < hdrlen + 8)
  1100. return RX_DROP_MONITOR;
  1101. skb_copy_bits(rx->skb, hdrlen + 6, &ethertype, 2);
  1102. if (ethertype == rx->sdata->control_port_protocol)
  1103. return RX_CONTINUE;
  1104. }
  1105. if (rx->sdata->vif.type == NL80211_IFTYPE_AP &&
  1106. cfg80211_rx_spurious_frame(rx->sdata->dev,
  1107. hdr->addr2,
  1108. GFP_ATOMIC))
  1109. return RX_DROP_UNUSABLE;
  1110. return RX_DROP_MONITOR;
  1111. }
  1112. return RX_CONTINUE;
  1113. }
  1114. static ieee80211_rx_result debug_noinline
  1115. ieee80211_rx_h_check_more_data(struct ieee80211_rx_data *rx)
  1116. {
  1117. struct ieee80211_local *local;
  1118. struct ieee80211_hdr *hdr;
  1119. struct sk_buff *skb;
  1120. local = rx->local;
  1121. skb = rx->skb;
  1122. hdr = (struct ieee80211_hdr *) skb->data;
  1123. if (!local->pspolling)
  1124. return RX_CONTINUE;
  1125. if (!ieee80211_has_fromds(hdr->frame_control))
  1126. /* this is not from AP */
  1127. return RX_CONTINUE;
  1128. if (!ieee80211_is_data(hdr->frame_control))
  1129. return RX_CONTINUE;
  1130. if (!ieee80211_has_moredata(hdr->frame_control)) {
  1131. /* AP has no more frames buffered for us */
  1132. local->pspolling = false;
  1133. return RX_CONTINUE;
  1134. }
  1135. /* more data bit is set, let's request a new frame from the AP */
  1136. ieee80211_send_pspoll(local, rx->sdata);
  1137. return RX_CONTINUE;
  1138. }
  1139. static void sta_ps_start(struct sta_info *sta)
  1140. {
  1141. struct ieee80211_sub_if_data *sdata = sta->sdata;
  1142. struct ieee80211_local *local = sdata->local;
  1143. struct ps_data *ps;
  1144. int tid;
  1145. if (sta->sdata->vif.type == NL80211_IFTYPE_AP ||
  1146. sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
  1147. ps = &sdata->bss->ps;
  1148. else
  1149. return;
  1150. atomic_inc(&ps->num_sta_ps);
  1151. set_sta_flag(sta, WLAN_STA_PS_STA);
  1152. if (!ieee80211_hw_check(&local->hw, AP_LINK_PS))
  1153. drv_sta_notify(local, sdata, STA_NOTIFY_SLEEP, &sta->sta);
  1154. ps_dbg(sdata, "STA %pM aid %d enters power save mode\n",
  1155. sta->sta.addr, sta->sta.aid);
  1156. ieee80211_clear_fast_xmit(sta);
  1157. if (!sta->sta.txq[0])
  1158. return;
  1159. for (tid = 0; tid < ARRAY_SIZE(sta->sta.txq); tid++) {
  1160. if (txq_has_queue(sta->sta.txq[tid]))
  1161. set_bit(tid, &sta->txq_buffered_tids);
  1162. else
  1163. clear_bit(tid, &sta->txq_buffered_tids);
  1164. }
  1165. }
  1166. static void sta_ps_end(struct sta_info *sta)
  1167. {
  1168. ps_dbg(sta->sdata, "STA %pM aid %d exits power save mode\n",
  1169. sta->sta.addr, sta->sta.aid);
  1170. if (test_sta_flag(sta, WLAN_STA_PS_DRIVER)) {
  1171. /*
  1172. * Clear the flag only if the other one is still set
  1173. * so that the TX path won't start TX'ing new frames
  1174. * directly ... In the case that the driver flag isn't
  1175. * set ieee80211_sta_ps_deliver_wakeup() will clear it.
  1176. */
  1177. clear_sta_flag(sta, WLAN_STA_PS_STA);
  1178. ps_dbg(sta->sdata, "STA %pM aid %d driver-ps-blocked\n",
  1179. sta->sta.addr, sta->sta.aid);
  1180. return;
  1181. }
  1182. set_sta_flag(sta, WLAN_STA_PS_DELIVER);
  1183. clear_sta_flag(sta, WLAN_STA_PS_STA);
  1184. ieee80211_sta_ps_deliver_wakeup(sta);
  1185. }
  1186. int ieee80211_sta_ps_transition(struct ieee80211_sta *pubsta, bool start)
  1187. {
  1188. struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
  1189. bool in_ps;
  1190. WARN_ON(!ieee80211_hw_check(&sta->local->hw, AP_LINK_PS));
  1191. /* Don't let the same PS state be set twice */
  1192. in_ps = test_sta_flag(sta, WLAN_STA_PS_STA);
  1193. if ((start && in_ps) || (!start && !in_ps))
  1194. return -EINVAL;
  1195. if (start)
  1196. sta_ps_start(sta);
  1197. else
  1198. sta_ps_end(sta);
  1199. return 0;
  1200. }
  1201. EXPORT_SYMBOL(ieee80211_sta_ps_transition);
  1202. void ieee80211_sta_pspoll(struct ieee80211_sta *pubsta)
  1203. {
  1204. struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
  1205. if (test_sta_flag(sta, WLAN_STA_SP))
  1206. return;
  1207. if (!test_sta_flag(sta, WLAN_STA_PS_DRIVER))
  1208. ieee80211_sta_ps_deliver_poll_response(sta);
  1209. else
  1210. set_sta_flag(sta, WLAN_STA_PSPOLL);
  1211. }
  1212. EXPORT_SYMBOL(ieee80211_sta_pspoll);
  1213. void ieee80211_sta_uapsd_trigger(struct ieee80211_sta *pubsta, u8 tid)
  1214. {
  1215. struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
  1216. int ac = ieee80211_ac_from_tid(tid);
  1217. /*
  1218. * If this AC is not trigger-enabled do nothing unless the
  1219. * driver is calling us after it already checked.
  1220. *
  1221. * NB: This could/should check a separate bitmap of trigger-
  1222. * enabled queues, but for now we only implement uAPSD w/o
  1223. * TSPEC changes to the ACs, so they're always the same.
  1224. */
  1225. if (!(sta->sta.uapsd_queues & ieee80211_ac_to_qos_mask[ac]) &&
  1226. tid != IEEE80211_NUM_TIDS)
  1227. return;
  1228. /* if we are in a service period, do nothing */
  1229. if (test_sta_flag(sta, WLAN_STA_SP))
  1230. return;
  1231. if (!test_sta_flag(sta, WLAN_STA_PS_DRIVER))
  1232. ieee80211_sta_ps_deliver_uapsd(sta);
  1233. else
  1234. set_sta_flag(sta, WLAN_STA_UAPSD);
  1235. }
  1236. EXPORT_SYMBOL(ieee80211_sta_uapsd_trigger);
  1237. static ieee80211_rx_result debug_noinline
  1238. ieee80211_rx_h_uapsd_and_pspoll(struct ieee80211_rx_data *rx)
  1239. {
  1240. struct ieee80211_sub_if_data *sdata = rx->sdata;
  1241. struct ieee80211_hdr *hdr = (void *)rx->skb->data;
  1242. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
  1243. if (!rx->sta)
  1244. return RX_CONTINUE;
  1245. if (sdata->vif.type != NL80211_IFTYPE_AP &&
  1246. sdata->vif.type != NL80211_IFTYPE_AP_VLAN)
  1247. return RX_CONTINUE;
  1248. /*
  1249. * The device handles station powersave, so don't do anything about
  1250. * uAPSD and PS-Poll frames (the latter shouldn't even come up from
  1251. * it to mac80211 since they're handled.)
  1252. */
  1253. if (ieee80211_hw_check(&sdata->local->hw, AP_LINK_PS))
  1254. return RX_CONTINUE;
  1255. /*
  1256. * Don't do anything if the station isn't already asleep. In
  1257. * the uAPSD case, the station will probably be marked asleep,
  1258. * in the PS-Poll case the station must be confused ...
  1259. */
  1260. if (!test_sta_flag(rx->sta, WLAN_STA_PS_STA))
  1261. return RX_CONTINUE;
  1262. if (unlikely(ieee80211_is_pspoll(hdr->frame_control))) {
  1263. ieee80211_sta_pspoll(&rx->sta->sta);
  1264. /* Free PS Poll skb here instead of returning RX_DROP that would
  1265. * count as an dropped frame. */
  1266. dev_kfree_skb(rx->skb);
  1267. return RX_QUEUED;
  1268. } else if (!ieee80211_has_morefrags(hdr->frame_control) &&
  1269. !(status->rx_flags & IEEE80211_RX_DEFERRED_RELEASE) &&
  1270. ieee80211_has_pm(hdr->frame_control) &&
  1271. (ieee80211_is_data_qos(hdr->frame_control) ||
  1272. ieee80211_is_qos_nullfunc(hdr->frame_control))) {
  1273. u8 tid;
  1274. tid = *ieee80211_get_qos_ctl(hdr) & IEEE80211_QOS_CTL_TID_MASK;
  1275. ieee80211_sta_uapsd_trigger(&rx->sta->sta, tid);
  1276. }
  1277. return RX_CONTINUE;
  1278. }
  1279. static ieee80211_rx_result debug_noinline
  1280. ieee80211_rx_h_sta_process(struct ieee80211_rx_data *rx)
  1281. {
  1282. struct sta_info *sta = rx->sta;
  1283. struct sk_buff *skb = rx->skb;
  1284. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
  1285. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
  1286. int i;
  1287. if (!sta)
  1288. return RX_CONTINUE;
  1289. /*
  1290. * Update last_rx only for IBSS packets which are for the current
  1291. * BSSID and for station already AUTHORIZED to avoid keeping the
  1292. * current IBSS network alive in cases where other STAs start
  1293. * using different BSSID. This will also give the station another
  1294. * chance to restart the authentication/authorization in case
  1295. * something went wrong the first time.
  1296. */
  1297. if (rx->sdata->vif.type == NL80211_IFTYPE_ADHOC) {
  1298. u8 *bssid = ieee80211_get_bssid(hdr, rx->skb->len,
  1299. NL80211_IFTYPE_ADHOC);
  1300. if (ether_addr_equal(bssid, rx->sdata->u.ibss.bssid) &&
  1301. test_sta_flag(sta, WLAN_STA_AUTHORIZED)) {
  1302. sta->rx_stats.last_rx = jiffies;
  1303. if (ieee80211_is_data(hdr->frame_control) &&
  1304. !is_multicast_ether_addr(hdr->addr1))
  1305. sta->rx_stats.last_rate =
  1306. sta_stats_encode_rate(status);
  1307. }
  1308. } else if (rx->sdata->vif.type == NL80211_IFTYPE_OCB) {
  1309. sta->rx_stats.last_rx = jiffies;
  1310. } else if (!is_multicast_ether_addr(hdr->addr1)) {
  1311. /*
  1312. * Mesh beacons will update last_rx when if they are found to
  1313. * match the current local configuration when processed.
  1314. */
  1315. sta->rx_stats.last_rx = jiffies;
  1316. if (ieee80211_is_data(hdr->frame_control))
  1317. sta->rx_stats.last_rate = sta_stats_encode_rate(status);
  1318. }
  1319. if (rx->sdata->vif.type == NL80211_IFTYPE_STATION)
  1320. ieee80211_sta_rx_notify(rx->sdata, hdr);
  1321. sta->rx_stats.fragments++;
  1322. u64_stats_update_begin(&rx->sta->rx_stats.syncp);
  1323. sta->rx_stats.bytes += rx->skb->len;
  1324. u64_stats_update_end(&rx->sta->rx_stats.syncp);
  1325. if (!(status->flag & RX_FLAG_NO_SIGNAL_VAL)) {
  1326. sta->rx_stats.last_signal = status->signal;
  1327. ewma_signal_add(&sta->rx_stats_avg.signal, -status->signal);
  1328. }
  1329. if (status->chains) {
  1330. sta->rx_stats.chains = status->chains;
  1331. for (i = 0; i < ARRAY_SIZE(status->chain_signal); i++) {
  1332. int signal = status->chain_signal[i];
  1333. if (!(status->chains & BIT(i)))
  1334. continue;
  1335. sta->rx_stats.chain_signal_last[i] = signal;
  1336. ewma_signal_add(&sta->rx_stats_avg.chain_signal[i],
  1337. -signal);
  1338. }
  1339. }
  1340. /*
  1341. * Change STA power saving mode only at the end of a frame
  1342. * exchange sequence.
  1343. */
  1344. if (!ieee80211_hw_check(&sta->local->hw, AP_LINK_PS) &&
  1345. !ieee80211_has_morefrags(hdr->frame_control) &&
  1346. !(status->rx_flags & IEEE80211_RX_DEFERRED_RELEASE) &&
  1347. (rx->sdata->vif.type == NL80211_IFTYPE_AP ||
  1348. rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN) &&
  1349. /* PM bit is only checked in frames where it isn't reserved,
  1350. * in AP mode it's reserved in non-bufferable management frames
  1351. * (cf. IEEE 802.11-2012 8.2.4.1.7 Power Management field)
  1352. */
  1353. (!ieee80211_is_mgmt(hdr->frame_control) ||
  1354. ieee80211_is_bufferable_mmpdu(hdr->frame_control))) {
  1355. if (test_sta_flag(sta, WLAN_STA_PS_STA)) {
  1356. if (!ieee80211_has_pm(hdr->frame_control))
  1357. sta_ps_end(sta);
  1358. } else {
  1359. if (ieee80211_has_pm(hdr->frame_control))
  1360. sta_ps_start(sta);
  1361. }
  1362. }
  1363. /* mesh power save support */
  1364. if (ieee80211_vif_is_mesh(&rx->sdata->vif))
  1365. ieee80211_mps_rx_h_sta_process(sta, hdr);
  1366. /*
  1367. * Drop (qos-)data::nullfunc frames silently, since they
  1368. * are used only to control station power saving mode.
  1369. */
  1370. if (ieee80211_is_nullfunc(hdr->frame_control) ||
  1371. ieee80211_is_qos_nullfunc(hdr->frame_control)) {
  1372. I802_DEBUG_INC(rx->local->rx_handlers_drop_nullfunc);
  1373. /*
  1374. * If we receive a 4-addr nullfunc frame from a STA
  1375. * that was not moved to a 4-addr STA vlan yet send
  1376. * the event to userspace and for older hostapd drop
  1377. * the frame to the monitor interface.
  1378. */
  1379. if (ieee80211_has_a4(hdr->frame_control) &&
  1380. (rx->sdata->vif.type == NL80211_IFTYPE_AP ||
  1381. (rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
  1382. !rx->sdata->u.vlan.sta))) {
  1383. if (!test_and_set_sta_flag(sta, WLAN_STA_4ADDR_EVENT))
  1384. cfg80211_rx_unexpected_4addr_frame(
  1385. rx->sdata->dev, sta->sta.addr,
  1386. GFP_ATOMIC);
  1387. return RX_DROP_MONITOR;
  1388. }
  1389. /*
  1390. * Update counter and free packet here to avoid
  1391. * counting this as a dropped packed.
  1392. */
  1393. sta->rx_stats.packets++;
  1394. dev_kfree_skb(rx->skb);
  1395. return RX_QUEUED;
  1396. }
  1397. return RX_CONTINUE;
  1398. } /* ieee80211_rx_h_sta_process */
  1399. static ieee80211_rx_result debug_noinline
  1400. ieee80211_rx_h_decrypt(struct ieee80211_rx_data *rx)
  1401. {
  1402. struct sk_buff *skb = rx->skb;
  1403. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
  1404. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
  1405. int keyidx;
  1406. int hdrlen;
  1407. ieee80211_rx_result result = RX_DROP_UNUSABLE;
  1408. struct ieee80211_key *sta_ptk = NULL;
  1409. int mmie_keyidx = -1;
  1410. __le16 fc;
  1411. const struct ieee80211_cipher_scheme *cs = NULL;
  1412. /*
  1413. * Key selection 101
  1414. *
  1415. * There are four types of keys:
  1416. * - GTK (group keys)
  1417. * - IGTK (group keys for management frames)
  1418. * - PTK (pairwise keys)
  1419. * - STK (station-to-station pairwise keys)
  1420. *
  1421. * When selecting a key, we have to distinguish between multicast
  1422. * (including broadcast) and unicast frames, the latter can only
  1423. * use PTKs and STKs while the former always use GTKs and IGTKs.
  1424. * Unless, of course, actual WEP keys ("pre-RSNA") are used, then
  1425. * unicast frames can also use key indices like GTKs. Hence, if we
  1426. * don't have a PTK/STK we check the key index for a WEP key.
  1427. *
  1428. * Note that in a regular BSS, multicast frames are sent by the
  1429. * AP only, associated stations unicast the frame to the AP first
  1430. * which then multicasts it on their behalf.
  1431. *
  1432. * There is also a slight problem in IBSS mode: GTKs are negotiated
  1433. * with each station, that is something we don't currently handle.
  1434. * The spec seems to expect that one negotiates the same key with
  1435. * every station but there's no such requirement; VLANs could be
  1436. * possible.
  1437. */
  1438. /* start without a key */
  1439. rx->key = NULL;
  1440. fc = hdr->frame_control;
  1441. if (rx->sta) {
  1442. int keyid = rx->sta->ptk_idx;
  1443. if (ieee80211_has_protected(fc) && rx->sta->cipher_scheme) {
  1444. cs = rx->sta->cipher_scheme;
  1445. keyid = ieee80211_get_cs_keyid(cs, rx->skb);
  1446. if (unlikely(keyid < 0))
  1447. return RX_DROP_UNUSABLE;
  1448. }
  1449. sta_ptk = rcu_dereference(rx->sta->ptk[keyid]);
  1450. }
  1451. if (!ieee80211_has_protected(fc))
  1452. mmie_keyidx = ieee80211_get_mmie_keyidx(rx->skb);
  1453. if (!is_multicast_ether_addr(hdr->addr1) && sta_ptk) {
  1454. rx->key = sta_ptk;
  1455. if ((status->flag & RX_FLAG_DECRYPTED) &&
  1456. (status->flag & RX_FLAG_IV_STRIPPED))
  1457. return RX_CONTINUE;
  1458. /* Skip decryption if the frame is not protected. */
  1459. if (!ieee80211_has_protected(fc))
  1460. return RX_CONTINUE;
  1461. } else if (mmie_keyidx >= 0) {
  1462. /* Broadcast/multicast robust management frame / BIP */
  1463. if ((status->flag & RX_FLAG_DECRYPTED) &&
  1464. (status->flag & RX_FLAG_IV_STRIPPED))
  1465. return RX_CONTINUE;
  1466. if (mmie_keyidx < NUM_DEFAULT_KEYS ||
  1467. mmie_keyidx >= NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS)
  1468. return RX_DROP_MONITOR; /* unexpected BIP keyidx */
  1469. if (rx->sta) {
  1470. if (ieee80211_is_group_privacy_action(skb) &&
  1471. test_sta_flag(rx->sta, WLAN_STA_MFP))
  1472. return RX_DROP_MONITOR;
  1473. rx->key = rcu_dereference(rx->sta->gtk[mmie_keyidx]);
  1474. }
  1475. if (!rx->key)
  1476. rx->key = rcu_dereference(rx->sdata->keys[mmie_keyidx]);
  1477. } else if (!ieee80211_has_protected(fc)) {
  1478. /*
  1479. * The frame was not protected, so skip decryption. However, we
  1480. * need to set rx->key if there is a key that could have been
  1481. * used so that the frame may be dropped if encryption would
  1482. * have been expected.
  1483. */
  1484. struct ieee80211_key *key = NULL;
  1485. struct ieee80211_sub_if_data *sdata = rx->sdata;
  1486. int i;
  1487. if (ieee80211_is_mgmt(fc) &&
  1488. is_multicast_ether_addr(hdr->addr1) &&
  1489. (key = rcu_dereference(rx->sdata->default_mgmt_key)))
  1490. rx->key = key;
  1491. else {
  1492. if (rx->sta) {
  1493. for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
  1494. key = rcu_dereference(rx->sta->gtk[i]);
  1495. if (key)
  1496. break;
  1497. }
  1498. }
  1499. if (!key) {
  1500. for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
  1501. key = rcu_dereference(sdata->keys[i]);
  1502. if (key)
  1503. break;
  1504. }
  1505. }
  1506. if (key)
  1507. rx->key = key;
  1508. }
  1509. return RX_CONTINUE;
  1510. } else {
  1511. u8 keyid;
  1512. /*
  1513. * The device doesn't give us the IV so we won't be
  1514. * able to look up the key. That's ok though, we
  1515. * don't need to decrypt the frame, we just won't
  1516. * be able to keep statistics accurate.
  1517. * Except for key threshold notifications, should
  1518. * we somehow allow the driver to tell us which key
  1519. * the hardware used if this flag is set?
  1520. */
  1521. if ((status->flag & RX_FLAG_DECRYPTED) &&
  1522. (status->flag & RX_FLAG_IV_STRIPPED))
  1523. return RX_CONTINUE;
  1524. hdrlen = ieee80211_hdrlen(fc);
  1525. if (cs) {
  1526. keyidx = ieee80211_get_cs_keyid(cs, rx->skb);
  1527. if (unlikely(keyidx < 0))
  1528. return RX_DROP_UNUSABLE;
  1529. } else {
  1530. if (rx->skb->len < 8 + hdrlen)
  1531. return RX_DROP_UNUSABLE; /* TODO: count this? */
  1532. /*
  1533. * no need to call ieee80211_wep_get_keyidx,
  1534. * it verifies a bunch of things we've done already
  1535. */
  1536. skb_copy_bits(rx->skb, hdrlen + 3, &keyid, 1);
  1537. keyidx = keyid >> 6;
  1538. }
  1539. /* check per-station GTK first, if multicast packet */
  1540. if (is_multicast_ether_addr(hdr->addr1) && rx->sta)
  1541. rx->key = rcu_dereference(rx->sta->gtk[keyidx]);
  1542. /* if not found, try default key */
  1543. if (!rx->key) {
  1544. rx->key = rcu_dereference(rx->sdata->keys[keyidx]);
  1545. /*
  1546. * RSNA-protected unicast frames should always be
  1547. * sent with pairwise or station-to-station keys,
  1548. * but for WEP we allow using a key index as well.
  1549. */
  1550. if (rx->key &&
  1551. rx->key->conf.cipher != WLAN_CIPHER_SUITE_WEP40 &&
  1552. rx->key->conf.cipher != WLAN_CIPHER_SUITE_WEP104 &&
  1553. !is_multicast_ether_addr(hdr->addr1))
  1554. rx->key = NULL;
  1555. }
  1556. }
  1557. if (rx->key) {
  1558. if (unlikely(rx->key->flags & KEY_FLAG_TAINTED))
  1559. return RX_DROP_MONITOR;
  1560. /* TODO: add threshold stuff again */
  1561. } else {
  1562. return RX_DROP_MONITOR;
  1563. }
  1564. switch (rx->key->conf.cipher) {
  1565. case WLAN_CIPHER_SUITE_WEP40:
  1566. case WLAN_CIPHER_SUITE_WEP104:
  1567. result = ieee80211_crypto_wep_decrypt(rx);
  1568. break;
  1569. case WLAN_CIPHER_SUITE_TKIP:
  1570. result = ieee80211_crypto_tkip_decrypt(rx);
  1571. break;
  1572. case WLAN_CIPHER_SUITE_CCMP:
  1573. result = ieee80211_crypto_ccmp_decrypt(
  1574. rx, IEEE80211_CCMP_MIC_LEN);
  1575. break;
  1576. case WLAN_CIPHER_SUITE_CCMP_256:
  1577. result = ieee80211_crypto_ccmp_decrypt(
  1578. rx, IEEE80211_CCMP_256_MIC_LEN);
  1579. break;
  1580. case WLAN_CIPHER_SUITE_AES_CMAC:
  1581. result = ieee80211_crypto_aes_cmac_decrypt(rx);
  1582. break;
  1583. case WLAN_CIPHER_SUITE_BIP_CMAC_256:
  1584. result = ieee80211_crypto_aes_cmac_256_decrypt(rx);
  1585. break;
  1586. case WLAN_CIPHER_SUITE_BIP_GMAC_128:
  1587. case WLAN_CIPHER_SUITE_BIP_GMAC_256:
  1588. result = ieee80211_crypto_aes_gmac_decrypt(rx);
  1589. break;
  1590. case WLAN_CIPHER_SUITE_GCMP:
  1591. case WLAN_CIPHER_SUITE_GCMP_256:
  1592. result = ieee80211_crypto_gcmp_decrypt(rx);
  1593. break;
  1594. default:
  1595. result = ieee80211_crypto_hw_decrypt(rx);
  1596. }
  1597. /* the hdr variable is invalid after the decrypt handlers */
  1598. /* either the frame has been decrypted or will be dropped */
  1599. status->flag |= RX_FLAG_DECRYPTED;
  1600. return result;
  1601. }
  1602. static inline struct ieee80211_fragment_entry *
  1603. ieee80211_reassemble_add(struct ieee80211_sub_if_data *sdata,
  1604. unsigned int frag, unsigned int seq, int rx_queue,
  1605. struct sk_buff **skb)
  1606. {
  1607. struct ieee80211_fragment_entry *entry;
  1608. entry = &sdata->fragments[sdata->fragment_next++];
  1609. if (sdata->fragment_next >= IEEE80211_FRAGMENT_MAX)
  1610. sdata->fragment_next = 0;
  1611. if (!skb_queue_empty(&entry->skb_list))
  1612. __skb_queue_purge(&entry->skb_list);
  1613. __skb_queue_tail(&entry->skb_list, *skb); /* no need for locking */
  1614. *skb = NULL;
  1615. entry->first_frag_time = jiffies;
  1616. entry->seq = seq;
  1617. entry->rx_queue = rx_queue;
  1618. entry->last_frag = frag;
  1619. entry->check_sequential_pn = false;
  1620. entry->extra_len = 0;
  1621. return entry;
  1622. }
  1623. static inline struct ieee80211_fragment_entry *
  1624. ieee80211_reassemble_find(struct ieee80211_sub_if_data *sdata,
  1625. unsigned int frag, unsigned int seq,
  1626. int rx_queue, struct ieee80211_hdr *hdr)
  1627. {
  1628. struct ieee80211_fragment_entry *entry;
  1629. int i, idx;
  1630. idx = sdata->fragment_next;
  1631. for (i = 0; i < IEEE80211_FRAGMENT_MAX; i++) {
  1632. struct ieee80211_hdr *f_hdr;
  1633. idx--;
  1634. if (idx < 0)
  1635. idx = IEEE80211_FRAGMENT_MAX - 1;
  1636. entry = &sdata->fragments[idx];
  1637. if (skb_queue_empty(&entry->skb_list) || entry->seq != seq ||
  1638. entry->rx_queue != rx_queue ||
  1639. entry->last_frag + 1 != frag)
  1640. continue;
  1641. f_hdr = (struct ieee80211_hdr *)entry->skb_list.next->data;
  1642. /*
  1643. * Check ftype and addresses are equal, else check next fragment
  1644. */
  1645. if (((hdr->frame_control ^ f_hdr->frame_control) &
  1646. cpu_to_le16(IEEE80211_FCTL_FTYPE)) ||
  1647. !ether_addr_equal(hdr->addr1, f_hdr->addr1) ||
  1648. !ether_addr_equal(hdr->addr2, f_hdr->addr2))
  1649. continue;
  1650. if (time_after(jiffies, entry->first_frag_time + 2 * HZ)) {
  1651. __skb_queue_purge(&entry->skb_list);
  1652. continue;
  1653. }
  1654. return entry;
  1655. }
  1656. return NULL;
  1657. }
  1658. static ieee80211_rx_result debug_noinline
  1659. ieee80211_rx_h_defragment(struct ieee80211_rx_data *rx)
  1660. {
  1661. struct ieee80211_hdr *hdr;
  1662. u16 sc;
  1663. __le16 fc;
  1664. unsigned int frag, seq;
  1665. struct ieee80211_fragment_entry *entry;
  1666. struct sk_buff *skb;
  1667. hdr = (struct ieee80211_hdr *)rx->skb->data;
  1668. fc = hdr->frame_control;
  1669. if (ieee80211_is_ctl(fc))
  1670. return RX_CONTINUE;
  1671. sc = le16_to_cpu(hdr->seq_ctrl);
  1672. frag = sc & IEEE80211_SCTL_FRAG;
  1673. if (is_multicast_ether_addr(hdr->addr1)) {
  1674. I802_DEBUG_INC(rx->local->dot11MulticastReceivedFrameCount);
  1675. goto out_no_led;
  1676. }
  1677. if (likely(!ieee80211_has_morefrags(fc) && frag == 0))
  1678. goto out;
  1679. I802_DEBUG_INC(rx->local->rx_handlers_fragments);
  1680. if (skb_linearize(rx->skb))
  1681. return RX_DROP_UNUSABLE;
  1682. /*
  1683. * skb_linearize() might change the skb->data and
  1684. * previously cached variables (in this case, hdr) need to
  1685. * be refreshed with the new data.
  1686. */
  1687. hdr = (struct ieee80211_hdr *)rx->skb->data;
  1688. seq = (sc & IEEE80211_SCTL_SEQ) >> 4;
  1689. if (frag == 0) {
  1690. /* This is the first fragment of a new frame. */
  1691. entry = ieee80211_reassemble_add(rx->sdata, frag, seq,
  1692. rx->seqno_idx, &(rx->skb));
  1693. if (rx->key &&
  1694. (rx->key->conf.cipher == WLAN_CIPHER_SUITE_CCMP ||
  1695. rx->key->conf.cipher == WLAN_CIPHER_SUITE_CCMP_256 ||
  1696. rx->key->conf.cipher == WLAN_CIPHER_SUITE_GCMP ||
  1697. rx->key->conf.cipher == WLAN_CIPHER_SUITE_GCMP_256) &&
  1698. ieee80211_has_protected(fc)) {
  1699. int queue = rx->security_idx;
  1700. /* Store CCMP/GCMP PN so that we can verify that the
  1701. * next fragment has a sequential PN value.
  1702. */
  1703. entry->check_sequential_pn = true;
  1704. memcpy(entry->last_pn,
  1705. rx->key->u.ccmp.rx_pn[queue],
  1706. IEEE80211_CCMP_PN_LEN);
  1707. BUILD_BUG_ON(offsetof(struct ieee80211_key,
  1708. u.ccmp.rx_pn) !=
  1709. offsetof(struct ieee80211_key,
  1710. u.gcmp.rx_pn));
  1711. BUILD_BUG_ON(sizeof(rx->key->u.ccmp.rx_pn[queue]) !=
  1712. sizeof(rx->key->u.gcmp.rx_pn[queue]));
  1713. BUILD_BUG_ON(IEEE80211_CCMP_PN_LEN !=
  1714. IEEE80211_GCMP_PN_LEN);
  1715. }
  1716. return RX_QUEUED;
  1717. }
  1718. /* This is a fragment for a frame that should already be pending in
  1719. * fragment cache. Add this fragment to the end of the pending entry.
  1720. */
  1721. entry = ieee80211_reassemble_find(rx->sdata, frag, seq,
  1722. rx->seqno_idx, hdr);
  1723. if (!entry) {
  1724. I802_DEBUG_INC(rx->local->rx_handlers_drop_defrag);
  1725. return RX_DROP_MONITOR;
  1726. }
  1727. /* "The receiver shall discard MSDUs and MMPDUs whose constituent
  1728. * MPDU PN values are not incrementing in steps of 1."
  1729. * see IEEE P802.11-REVmc/D5.0, 12.5.3.4.4, item d (for CCMP)
  1730. * and IEEE P802.11-REVmc/D5.0, 12.5.5.4.4, item d (for GCMP)
  1731. */
  1732. if (entry->check_sequential_pn) {
  1733. int i;
  1734. u8 pn[IEEE80211_CCMP_PN_LEN], *rpn;
  1735. int queue;
  1736. if (!rx->key ||
  1737. (rx->key->conf.cipher != WLAN_CIPHER_SUITE_CCMP &&
  1738. rx->key->conf.cipher != WLAN_CIPHER_SUITE_CCMP_256 &&
  1739. rx->key->conf.cipher != WLAN_CIPHER_SUITE_GCMP &&
  1740. rx->key->conf.cipher != WLAN_CIPHER_SUITE_GCMP_256))
  1741. return RX_DROP_UNUSABLE;
  1742. memcpy(pn, entry->last_pn, IEEE80211_CCMP_PN_LEN);
  1743. for (i = IEEE80211_CCMP_PN_LEN - 1; i >= 0; i--) {
  1744. pn[i]++;
  1745. if (pn[i])
  1746. break;
  1747. }
  1748. queue = rx->security_idx;
  1749. rpn = rx->key->u.ccmp.rx_pn[queue];
  1750. if (memcmp(pn, rpn, IEEE80211_CCMP_PN_LEN))
  1751. return RX_DROP_UNUSABLE;
  1752. memcpy(entry->last_pn, pn, IEEE80211_CCMP_PN_LEN);
  1753. }
  1754. skb_pull(rx->skb, ieee80211_hdrlen(fc));
  1755. __skb_queue_tail(&entry->skb_list, rx->skb);
  1756. entry->last_frag = frag;
  1757. entry->extra_len += rx->skb->len;
  1758. if (ieee80211_has_morefrags(fc)) {
  1759. rx->skb = NULL;
  1760. return RX_QUEUED;
  1761. }
  1762. rx->skb = __skb_dequeue(&entry->skb_list);
  1763. if (skb_tailroom(rx->skb) < entry->extra_len) {
  1764. I802_DEBUG_INC(rx->local->rx_expand_skb_head_defrag);
  1765. if (unlikely(pskb_expand_head(rx->skb, 0, entry->extra_len,
  1766. GFP_ATOMIC))) {
  1767. I802_DEBUG_INC(rx->local->rx_handlers_drop_defrag);
  1768. __skb_queue_purge(&entry->skb_list);
  1769. return RX_DROP_UNUSABLE;
  1770. }
  1771. }
  1772. while ((skb = __skb_dequeue(&entry->skb_list))) {
  1773. memcpy(skb_put(rx->skb, skb->len), skb->data, skb->len);
  1774. dev_kfree_skb(skb);
  1775. }
  1776. out:
  1777. ieee80211_led_rx(rx->local);
  1778. out_no_led:
  1779. if (rx->sta)
  1780. rx->sta->rx_stats.packets++;
  1781. return RX_CONTINUE;
  1782. }
  1783. static int ieee80211_802_1x_port_control(struct ieee80211_rx_data *rx)
  1784. {
  1785. if (unlikely(!rx->sta || !test_sta_flag(rx->sta, WLAN_STA_AUTHORIZED)))
  1786. return -EACCES;
  1787. return 0;
  1788. }
  1789. static int ieee80211_drop_unencrypted(struct ieee80211_rx_data *rx, __le16 fc)
  1790. {
  1791. struct sk_buff *skb = rx->skb;
  1792. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
  1793. /*
  1794. * Pass through unencrypted frames if the hardware has
  1795. * decrypted them already.
  1796. */
  1797. if (status->flag & RX_FLAG_DECRYPTED)
  1798. return 0;
  1799. /* Drop unencrypted frames if key is set. */
  1800. if (unlikely(!ieee80211_has_protected(fc) &&
  1801. !ieee80211_is_nullfunc(fc) &&
  1802. ieee80211_is_data(fc) && rx->key))
  1803. return -EACCES;
  1804. return 0;
  1805. }
  1806. static int ieee80211_drop_unencrypted_mgmt(struct ieee80211_rx_data *rx)
  1807. {
  1808. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
  1809. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
  1810. __le16 fc = hdr->frame_control;
  1811. /*
  1812. * Pass through unencrypted frames if the hardware has
  1813. * decrypted them already.
  1814. */
  1815. if (status->flag & RX_FLAG_DECRYPTED)
  1816. return 0;
  1817. if (rx->sta && test_sta_flag(rx->sta, WLAN_STA_MFP)) {
  1818. if (unlikely(!ieee80211_has_protected(fc) &&
  1819. ieee80211_is_unicast_robust_mgmt_frame(rx->skb) &&
  1820. rx->key)) {
  1821. if (ieee80211_is_deauth(fc) ||
  1822. ieee80211_is_disassoc(fc))
  1823. cfg80211_rx_unprot_mlme_mgmt(rx->sdata->dev,
  1824. rx->skb->data,
  1825. rx->skb->len);
  1826. return -EACCES;
  1827. }
  1828. /* BIP does not use Protected field, so need to check MMIE */
  1829. if (unlikely(ieee80211_is_multicast_robust_mgmt_frame(rx->skb) &&
  1830. ieee80211_get_mmie_keyidx(rx->skb) < 0)) {
  1831. if (ieee80211_is_deauth(fc) ||
  1832. ieee80211_is_disassoc(fc))
  1833. cfg80211_rx_unprot_mlme_mgmt(rx->sdata->dev,
  1834. rx->skb->data,
  1835. rx->skb->len);
  1836. return -EACCES;
  1837. }
  1838. /*
  1839. * When using MFP, Action frames are not allowed prior to
  1840. * having configured keys.
  1841. */
  1842. if (unlikely(ieee80211_is_action(fc) && !rx->key &&
  1843. ieee80211_is_robust_mgmt_frame(rx->skb)))
  1844. return -EACCES;
  1845. }
  1846. return 0;
  1847. }
  1848. static int
  1849. __ieee80211_data_to_8023(struct ieee80211_rx_data *rx, bool *port_control)
  1850. {
  1851. struct ieee80211_sub_if_data *sdata = rx->sdata;
  1852. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
  1853. bool check_port_control = false;
  1854. struct ethhdr *ehdr;
  1855. int ret;
  1856. *port_control = false;
  1857. if (ieee80211_has_a4(hdr->frame_control) &&
  1858. sdata->vif.type == NL80211_IFTYPE_AP_VLAN && !sdata->u.vlan.sta)
  1859. return -1;
  1860. if (sdata->vif.type == NL80211_IFTYPE_STATION &&
  1861. !!sdata->u.mgd.use_4addr != !!ieee80211_has_a4(hdr->frame_control)) {
  1862. if (!sdata->u.mgd.use_4addr)
  1863. return -1;
  1864. else
  1865. check_port_control = true;
  1866. }
  1867. if (is_multicast_ether_addr(hdr->addr1) &&
  1868. sdata->vif.type == NL80211_IFTYPE_AP_VLAN && sdata->u.vlan.sta)
  1869. return -1;
  1870. ret = ieee80211_data_to_8023(rx->skb, sdata->vif.addr, sdata->vif.type);
  1871. if (ret < 0)
  1872. return ret;
  1873. ehdr = (struct ethhdr *) rx->skb->data;
  1874. if (ehdr->h_proto == rx->sdata->control_port_protocol)
  1875. *port_control = true;
  1876. else if (check_port_control)
  1877. return -1;
  1878. return 0;
  1879. }
  1880. /*
  1881. * requires that rx->skb is a frame with ethernet header
  1882. */
  1883. static bool ieee80211_frame_allowed(struct ieee80211_rx_data *rx, __le16 fc)
  1884. {
  1885. static const u8 pae_group_addr[ETH_ALEN] __aligned(2)
  1886. = { 0x01, 0x80, 0xC2, 0x00, 0x00, 0x03 };
  1887. struct ethhdr *ehdr = (struct ethhdr *) rx->skb->data;
  1888. /*
  1889. * Allow EAPOL frames to us/the PAE group address regardless
  1890. * of whether the frame was encrypted or not.
  1891. */
  1892. if (ehdr->h_proto == rx->sdata->control_port_protocol &&
  1893. (ether_addr_equal(ehdr->h_dest, rx->sdata->vif.addr) ||
  1894. ether_addr_equal(ehdr->h_dest, pae_group_addr)))
  1895. return true;
  1896. if (ieee80211_802_1x_port_control(rx) ||
  1897. ieee80211_drop_unencrypted(rx, fc))
  1898. return false;
  1899. return true;
  1900. }
  1901. /*
  1902. * requires that rx->skb is a frame with ethernet header
  1903. */
  1904. static void
  1905. ieee80211_deliver_skb(struct ieee80211_rx_data *rx)
  1906. {
  1907. struct ieee80211_sub_if_data *sdata = rx->sdata;
  1908. struct net_device *dev = sdata->dev;
  1909. struct sk_buff *skb, *xmit_skb;
  1910. struct ethhdr *ehdr = (struct ethhdr *) rx->skb->data;
  1911. struct sta_info *dsta;
  1912. skb = rx->skb;
  1913. xmit_skb = NULL;
  1914. ieee80211_rx_stats(dev, skb->len);
  1915. if (rx->sta) {
  1916. /* The seqno index has the same property as needed
  1917. * for the rx_msdu field, i.e. it is IEEE80211_NUM_TIDS
  1918. * for non-QoS-data frames. Here we know it's a data
  1919. * frame, so count MSDUs.
  1920. */
  1921. u64_stats_update_begin(&rx->sta->rx_stats.syncp);
  1922. rx->sta->rx_stats.msdu[rx->seqno_idx]++;
  1923. u64_stats_update_end(&rx->sta->rx_stats.syncp);
  1924. }
  1925. if ((sdata->vif.type == NL80211_IFTYPE_AP ||
  1926. sdata->vif.type == NL80211_IFTYPE_AP_VLAN) &&
  1927. !(sdata->flags & IEEE80211_SDATA_DONT_BRIDGE_PACKETS) &&
  1928. (sdata->vif.type != NL80211_IFTYPE_AP_VLAN || !sdata->u.vlan.sta)) {
  1929. if (is_multicast_ether_addr(ehdr->h_dest) &&
  1930. ieee80211_vif_get_num_mcast_if(sdata) != 0) {
  1931. /*
  1932. * send multicast frames both to higher layers in
  1933. * local net stack and back to the wireless medium
  1934. */
  1935. xmit_skb = skb_copy(skb, GFP_ATOMIC);
  1936. if (!xmit_skb)
  1937. net_info_ratelimited("%s: failed to clone multicast frame\n",
  1938. dev->name);
  1939. } else if (!is_multicast_ether_addr(ehdr->h_dest)) {
  1940. dsta = sta_info_get(sdata, skb->data);
  1941. if (dsta) {
  1942. /*
  1943. * The destination station is associated to
  1944. * this AP (in this VLAN), so send the frame
  1945. * directly to it and do not pass it to local
  1946. * net stack.
  1947. */
  1948. xmit_skb = skb;
  1949. skb = NULL;
  1950. }
  1951. }
  1952. }
  1953. #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
  1954. if (skb) {
  1955. /* 'align' will only take the values 0 or 2 here since all
  1956. * frames are required to be aligned to 2-byte boundaries
  1957. * when being passed to mac80211; the code here works just
  1958. * as well if that isn't true, but mac80211 assumes it can
  1959. * access fields as 2-byte aligned (e.g. for ether_addr_equal)
  1960. */
  1961. int align;
  1962. align = (unsigned long)(skb->data + sizeof(struct ethhdr)) & 3;
  1963. if (align) {
  1964. if (WARN_ON(skb_headroom(skb) < 3)) {
  1965. dev_kfree_skb(skb);
  1966. skb = NULL;
  1967. } else {
  1968. u8 *data = skb->data;
  1969. size_t len = skb_headlen(skb);
  1970. skb->data -= align;
  1971. memmove(skb->data, data, len);
  1972. skb_set_tail_pointer(skb, len);
  1973. }
  1974. }
  1975. }
  1976. #endif
  1977. if (skb) {
  1978. /* deliver to local stack */
  1979. skb->protocol = eth_type_trans(skb, dev);
  1980. memset(skb->cb, 0, sizeof(skb->cb));
  1981. if (rx->napi)
  1982. napi_gro_receive(rx->napi, skb);
  1983. else
  1984. netif_receive_skb(skb);
  1985. }
  1986. if (xmit_skb) {
  1987. /*
  1988. * Send to wireless media and increase priority by 256 to
  1989. * keep the received priority instead of reclassifying
  1990. * the frame (see cfg80211_classify8021d).
  1991. */
  1992. xmit_skb->priority += 256;
  1993. xmit_skb->protocol = htons(ETH_P_802_3);
  1994. skb_reset_network_header(xmit_skb);
  1995. skb_reset_mac_header(xmit_skb);
  1996. dev_queue_xmit(xmit_skb);
  1997. }
  1998. }
  1999. static ieee80211_rx_result debug_noinline
  2000. ieee80211_rx_h_amsdu(struct ieee80211_rx_data *rx)
  2001. {
  2002. struct net_device *dev = rx->sdata->dev;
  2003. struct sk_buff *skb = rx->skb;
  2004. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
  2005. __le16 fc = hdr->frame_control;
  2006. struct sk_buff_head frame_list;
  2007. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
  2008. struct ethhdr ethhdr;
  2009. const u8 *check_da = ethhdr.h_dest, *check_sa = ethhdr.h_source;
  2010. if (unlikely(!ieee80211_is_data(fc)))
  2011. return RX_CONTINUE;
  2012. if (unlikely(!ieee80211_is_data_present(fc)))
  2013. return RX_DROP_MONITOR;
  2014. if (!(status->rx_flags & IEEE80211_RX_AMSDU))
  2015. return RX_CONTINUE;
  2016. if (unlikely(ieee80211_has_a4(hdr->frame_control))) {
  2017. switch (rx->sdata->vif.type) {
  2018. case NL80211_IFTYPE_AP_VLAN:
  2019. if (!rx->sdata->u.vlan.sta)
  2020. return RX_DROP_UNUSABLE;
  2021. break;
  2022. case NL80211_IFTYPE_STATION:
  2023. if (!rx->sdata->u.mgd.use_4addr)
  2024. return RX_DROP_UNUSABLE;
  2025. break;
  2026. default:
  2027. return RX_DROP_UNUSABLE;
  2028. }
  2029. check_da = NULL;
  2030. check_sa = NULL;
  2031. } else switch (rx->sdata->vif.type) {
  2032. case NL80211_IFTYPE_AP:
  2033. case NL80211_IFTYPE_AP_VLAN:
  2034. check_da = NULL;
  2035. break;
  2036. case NL80211_IFTYPE_STATION:
  2037. if (!rx->sta ||
  2038. !test_sta_flag(rx->sta, WLAN_STA_TDLS_PEER))
  2039. check_sa = NULL;
  2040. break;
  2041. case NL80211_IFTYPE_MESH_POINT:
  2042. check_sa = NULL;
  2043. break;
  2044. default:
  2045. break;
  2046. }
  2047. if (is_multicast_ether_addr(hdr->addr1))
  2048. return RX_DROP_UNUSABLE;
  2049. skb->dev = dev;
  2050. __skb_queue_head_init(&frame_list);
  2051. if (ieee80211_data_to_8023_exthdr(skb, &ethhdr,
  2052. rx->sdata->vif.addr,
  2053. rx->sdata->vif.type))
  2054. return RX_DROP_UNUSABLE;
  2055. ieee80211_amsdu_to_8023s(skb, &frame_list, dev->dev_addr,
  2056. rx->sdata->vif.type,
  2057. rx->local->hw.extra_tx_headroom,
  2058. check_da, check_sa);
  2059. while (!skb_queue_empty(&frame_list)) {
  2060. rx->skb = __skb_dequeue(&frame_list);
  2061. if (!ieee80211_frame_allowed(rx, fc)) {
  2062. dev_kfree_skb(rx->skb);
  2063. continue;
  2064. }
  2065. ieee80211_deliver_skb(rx);
  2066. }
  2067. return RX_QUEUED;
  2068. }
  2069. #ifdef CONFIG_MAC80211_MESH
  2070. static ieee80211_rx_result
  2071. ieee80211_rx_h_mesh_fwding(struct ieee80211_rx_data *rx)
  2072. {
  2073. struct ieee80211_hdr *fwd_hdr, *hdr;
  2074. struct ieee80211_tx_info *info;
  2075. struct ieee80211s_hdr *mesh_hdr;
  2076. struct sk_buff *skb = rx->skb, *fwd_skb;
  2077. struct ieee80211_local *local = rx->local;
  2078. struct ieee80211_sub_if_data *sdata = rx->sdata;
  2079. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  2080. u16 ac, q, hdrlen;
  2081. hdr = (struct ieee80211_hdr *) skb->data;
  2082. hdrlen = ieee80211_hdrlen(hdr->frame_control);
  2083. /* make sure fixed part of mesh header is there, also checks skb len */
  2084. if (!pskb_may_pull(rx->skb, hdrlen + 6))
  2085. return RX_DROP_MONITOR;
  2086. mesh_hdr = (struct ieee80211s_hdr *) (skb->data + hdrlen);
  2087. /* make sure full mesh header is there, also checks skb len */
  2088. if (!pskb_may_pull(rx->skb,
  2089. hdrlen + ieee80211_get_mesh_hdrlen(mesh_hdr)))
  2090. return RX_DROP_MONITOR;
  2091. /* reload pointers */
  2092. hdr = (struct ieee80211_hdr *) skb->data;
  2093. mesh_hdr = (struct ieee80211s_hdr *) (skb->data + hdrlen);
  2094. if (ieee80211_drop_unencrypted(rx, hdr->frame_control))
  2095. return RX_DROP_MONITOR;
  2096. /* frame is in RMC, don't forward */
  2097. if (ieee80211_is_data(hdr->frame_control) &&
  2098. is_multicast_ether_addr(hdr->addr1) &&
  2099. mesh_rmc_check(rx->sdata, hdr->addr3, mesh_hdr))
  2100. return RX_DROP_MONITOR;
  2101. if (!ieee80211_is_data(hdr->frame_control))
  2102. return RX_CONTINUE;
  2103. if (!mesh_hdr->ttl)
  2104. return RX_DROP_MONITOR;
  2105. if (mesh_hdr->flags & MESH_FLAGS_AE) {
  2106. struct mesh_path *mppath;
  2107. char *proxied_addr;
  2108. char *mpp_addr;
  2109. if (is_multicast_ether_addr(hdr->addr1)) {
  2110. mpp_addr = hdr->addr3;
  2111. proxied_addr = mesh_hdr->eaddr1;
  2112. } else if (mesh_hdr->flags & MESH_FLAGS_AE_A5_A6) {
  2113. /* has_a4 already checked in ieee80211_rx_mesh_check */
  2114. mpp_addr = hdr->addr4;
  2115. proxied_addr = mesh_hdr->eaddr2;
  2116. } else {
  2117. return RX_DROP_MONITOR;
  2118. }
  2119. rcu_read_lock();
  2120. mppath = mpp_path_lookup(sdata, proxied_addr);
  2121. if (!mppath) {
  2122. mpp_path_add(sdata, proxied_addr, mpp_addr);
  2123. } else {
  2124. spin_lock_bh(&mppath->state_lock);
  2125. if (!ether_addr_equal(mppath->mpp, mpp_addr))
  2126. memcpy(mppath->mpp, mpp_addr, ETH_ALEN);
  2127. mppath->exp_time = jiffies;
  2128. spin_unlock_bh(&mppath->state_lock);
  2129. }
  2130. rcu_read_unlock();
  2131. }
  2132. /* Frame has reached destination. Don't forward */
  2133. if (!is_multicast_ether_addr(hdr->addr1) &&
  2134. ether_addr_equal(sdata->vif.addr, hdr->addr3))
  2135. return RX_CONTINUE;
  2136. ac = ieee80211_select_queue_80211(sdata, skb, hdr);
  2137. q = sdata->vif.hw_queue[ac];
  2138. if (ieee80211_queue_stopped(&local->hw, q)) {
  2139. IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, dropped_frames_congestion);
  2140. return RX_DROP_MONITOR;
  2141. }
  2142. skb_set_queue_mapping(skb, q);
  2143. if (!--mesh_hdr->ttl) {
  2144. IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, dropped_frames_ttl);
  2145. goto out;
  2146. }
  2147. if (!ifmsh->mshcfg.dot11MeshForwarding)
  2148. goto out;
  2149. fwd_skb = skb_copy_expand(skb, local->tx_headroom +
  2150. sdata->encrypt_headroom, 0, GFP_ATOMIC);
  2151. if (!fwd_skb) {
  2152. net_info_ratelimited("%s: failed to clone mesh frame\n",
  2153. sdata->name);
  2154. goto out;
  2155. }
  2156. fwd_hdr = (struct ieee80211_hdr *) fwd_skb->data;
  2157. fwd_hdr->frame_control &= ~cpu_to_le16(IEEE80211_FCTL_RETRY);
  2158. info = IEEE80211_SKB_CB(fwd_skb);
  2159. memset(info, 0, sizeof(*info));
  2160. info->flags |= IEEE80211_TX_INTFL_NEED_TXPROCESSING;
  2161. info->control.vif = &rx->sdata->vif;
  2162. info->control.jiffies = jiffies;
  2163. if (is_multicast_ether_addr(fwd_hdr->addr1)) {
  2164. IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, fwded_mcast);
  2165. memcpy(fwd_hdr->addr2, sdata->vif.addr, ETH_ALEN);
  2166. /* update power mode indication when forwarding */
  2167. ieee80211_mps_set_frame_flags(sdata, NULL, fwd_hdr);
  2168. } else if (!mesh_nexthop_lookup(sdata, fwd_skb)) {
  2169. /* mesh power mode flags updated in mesh_nexthop_lookup */
  2170. IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, fwded_unicast);
  2171. } else {
  2172. /* unable to resolve next hop */
  2173. mesh_path_error_tx(sdata, ifmsh->mshcfg.element_ttl,
  2174. fwd_hdr->addr3, 0,
  2175. WLAN_REASON_MESH_PATH_NOFORWARD,
  2176. fwd_hdr->addr2);
  2177. IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, dropped_frames_no_route);
  2178. kfree_skb(fwd_skb);
  2179. return RX_DROP_MONITOR;
  2180. }
  2181. IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, fwded_frames);
  2182. ieee80211_add_pending_skb(local, fwd_skb);
  2183. out:
  2184. if (is_multicast_ether_addr(hdr->addr1))
  2185. return RX_CONTINUE;
  2186. return RX_DROP_MONITOR;
  2187. }
  2188. #endif
  2189. static ieee80211_rx_result debug_noinline
  2190. ieee80211_rx_h_data(struct ieee80211_rx_data *rx)
  2191. {
  2192. struct ieee80211_sub_if_data *sdata = rx->sdata;
  2193. struct ieee80211_local *local = rx->local;
  2194. struct net_device *dev = sdata->dev;
  2195. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
  2196. __le16 fc = hdr->frame_control;
  2197. bool port_control;
  2198. int err;
  2199. if (unlikely(!ieee80211_is_data(hdr->frame_control)))
  2200. return RX_CONTINUE;
  2201. if (unlikely(!ieee80211_is_data_present(hdr->frame_control)))
  2202. return RX_DROP_MONITOR;
  2203. /*
  2204. * Send unexpected-4addr-frame event to hostapd. For older versions,
  2205. * also drop the frame to cooked monitor interfaces.
  2206. */
  2207. if (ieee80211_has_a4(hdr->frame_control) &&
  2208. sdata->vif.type == NL80211_IFTYPE_AP) {
  2209. if (rx->sta &&
  2210. !test_and_set_sta_flag(rx->sta, WLAN_STA_4ADDR_EVENT))
  2211. cfg80211_rx_unexpected_4addr_frame(
  2212. rx->sdata->dev, rx->sta->sta.addr, GFP_ATOMIC);
  2213. return RX_DROP_MONITOR;
  2214. }
  2215. err = __ieee80211_data_to_8023(rx, &port_control);
  2216. if (unlikely(err))
  2217. return RX_DROP_UNUSABLE;
  2218. if (!ieee80211_frame_allowed(rx, fc))
  2219. return RX_DROP_MONITOR;
  2220. /* directly handle TDLS channel switch requests/responses */
  2221. if (unlikely(((struct ethhdr *)rx->skb->data)->h_proto ==
  2222. cpu_to_be16(ETH_P_TDLS))) {
  2223. struct ieee80211_tdls_data *tf = (void *)rx->skb->data;
  2224. if (pskb_may_pull(rx->skb,
  2225. offsetof(struct ieee80211_tdls_data, u)) &&
  2226. tf->payload_type == WLAN_TDLS_SNAP_RFTYPE &&
  2227. tf->category == WLAN_CATEGORY_TDLS &&
  2228. (tf->action_code == WLAN_TDLS_CHANNEL_SWITCH_REQUEST ||
  2229. tf->action_code == WLAN_TDLS_CHANNEL_SWITCH_RESPONSE)) {
  2230. skb_queue_tail(&local->skb_queue_tdls_chsw, rx->skb);
  2231. schedule_work(&local->tdls_chsw_work);
  2232. if (rx->sta)
  2233. rx->sta->rx_stats.packets++;
  2234. return RX_QUEUED;
  2235. }
  2236. }
  2237. if (rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
  2238. unlikely(port_control) && sdata->bss) {
  2239. sdata = container_of(sdata->bss, struct ieee80211_sub_if_data,
  2240. u.ap);
  2241. dev = sdata->dev;
  2242. rx->sdata = sdata;
  2243. }
  2244. rx->skb->dev = dev;
  2245. if (!ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS) &&
  2246. local->ps_sdata && local->hw.conf.dynamic_ps_timeout > 0 &&
  2247. !is_multicast_ether_addr(
  2248. ((struct ethhdr *)rx->skb->data)->h_dest) &&
  2249. (!local->scanning &&
  2250. !test_bit(SDATA_STATE_OFFCHANNEL, &sdata->state)))
  2251. mod_timer(&local->dynamic_ps_timer, jiffies +
  2252. msecs_to_jiffies(local->hw.conf.dynamic_ps_timeout));
  2253. ieee80211_deliver_skb(rx);
  2254. return RX_QUEUED;
  2255. }
  2256. static ieee80211_rx_result debug_noinline
  2257. ieee80211_rx_h_ctrl(struct ieee80211_rx_data *rx, struct sk_buff_head *frames)
  2258. {
  2259. struct sk_buff *skb = rx->skb;
  2260. struct ieee80211_bar *bar = (struct ieee80211_bar *)skb->data;
  2261. struct tid_ampdu_rx *tid_agg_rx;
  2262. u16 start_seq_num;
  2263. u16 tid;
  2264. if (likely(!ieee80211_is_ctl(bar->frame_control)))
  2265. return RX_CONTINUE;
  2266. if (ieee80211_is_back_req(bar->frame_control)) {
  2267. struct {
  2268. __le16 control, start_seq_num;
  2269. } __packed bar_data;
  2270. struct ieee80211_event event = {
  2271. .type = BAR_RX_EVENT,
  2272. };
  2273. if (!rx->sta)
  2274. return RX_DROP_MONITOR;
  2275. if (skb_copy_bits(skb, offsetof(struct ieee80211_bar, control),
  2276. &bar_data, sizeof(bar_data)))
  2277. return RX_DROP_MONITOR;
  2278. tid = le16_to_cpu(bar_data.control) >> 12;
  2279. if (!test_bit(tid, rx->sta->ampdu_mlme.agg_session_valid) &&
  2280. !test_and_set_bit(tid, rx->sta->ampdu_mlme.unexpected_agg))
  2281. ieee80211_send_delba(rx->sdata, rx->sta->sta.addr, tid,
  2282. WLAN_BACK_RECIPIENT,
  2283. WLAN_REASON_QSTA_REQUIRE_SETUP);
  2284. tid_agg_rx = rcu_dereference(rx->sta->ampdu_mlme.tid_rx[tid]);
  2285. if (!tid_agg_rx)
  2286. return RX_DROP_MONITOR;
  2287. start_seq_num = le16_to_cpu(bar_data.start_seq_num) >> 4;
  2288. event.u.ba.tid = tid;
  2289. event.u.ba.ssn = start_seq_num;
  2290. event.u.ba.sta = &rx->sta->sta;
  2291. /* reset session timer */
  2292. if (tid_agg_rx->timeout)
  2293. mod_timer(&tid_agg_rx->session_timer,
  2294. TU_TO_EXP_TIME(tid_agg_rx->timeout));
  2295. spin_lock(&tid_agg_rx->reorder_lock);
  2296. /* release stored frames up to start of BAR */
  2297. ieee80211_release_reorder_frames(rx->sdata, tid_agg_rx,
  2298. start_seq_num, frames);
  2299. spin_unlock(&tid_agg_rx->reorder_lock);
  2300. drv_event_callback(rx->local, rx->sdata, &event);
  2301. kfree_skb(skb);
  2302. return RX_QUEUED;
  2303. }
  2304. /*
  2305. * After this point, we only want management frames,
  2306. * so we can drop all remaining control frames to
  2307. * cooked monitor interfaces.
  2308. */
  2309. return RX_DROP_MONITOR;
  2310. }
  2311. static void ieee80211_process_sa_query_req(struct ieee80211_sub_if_data *sdata,
  2312. struct ieee80211_mgmt *mgmt,
  2313. size_t len)
  2314. {
  2315. struct ieee80211_local *local = sdata->local;
  2316. struct sk_buff *skb;
  2317. struct ieee80211_mgmt *resp;
  2318. if (!ether_addr_equal(mgmt->da, sdata->vif.addr)) {
  2319. /* Not to own unicast address */
  2320. return;
  2321. }
  2322. if (!ether_addr_equal(mgmt->sa, sdata->u.mgd.bssid) ||
  2323. !ether_addr_equal(mgmt->bssid, sdata->u.mgd.bssid)) {
  2324. /* Not from the current AP or not associated yet. */
  2325. return;
  2326. }
  2327. if (len < 24 + 1 + sizeof(resp->u.action.u.sa_query)) {
  2328. /* Too short SA Query request frame */
  2329. return;
  2330. }
  2331. skb = dev_alloc_skb(sizeof(*resp) + local->hw.extra_tx_headroom);
  2332. if (skb == NULL)
  2333. return;
  2334. skb_reserve(skb, local->hw.extra_tx_headroom);
  2335. resp = (struct ieee80211_mgmt *) skb_put(skb, 24);
  2336. memset(resp, 0, 24);
  2337. memcpy(resp->da, mgmt->sa, ETH_ALEN);
  2338. memcpy(resp->sa, sdata->vif.addr, ETH_ALEN);
  2339. memcpy(resp->bssid, sdata->u.mgd.bssid, ETH_ALEN);
  2340. resp->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
  2341. IEEE80211_STYPE_ACTION);
  2342. skb_put(skb, 1 + sizeof(resp->u.action.u.sa_query));
  2343. resp->u.action.category = WLAN_CATEGORY_SA_QUERY;
  2344. resp->u.action.u.sa_query.action = WLAN_ACTION_SA_QUERY_RESPONSE;
  2345. memcpy(resp->u.action.u.sa_query.trans_id,
  2346. mgmt->u.action.u.sa_query.trans_id,
  2347. WLAN_SA_QUERY_TR_ID_LEN);
  2348. ieee80211_tx_skb(sdata, skb);
  2349. }
  2350. static ieee80211_rx_result debug_noinline
  2351. ieee80211_rx_h_mgmt_check(struct ieee80211_rx_data *rx)
  2352. {
  2353. struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) rx->skb->data;
  2354. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
  2355. /*
  2356. * From here on, look only at management frames.
  2357. * Data and control frames are already handled,
  2358. * and unknown (reserved) frames are useless.
  2359. */
  2360. if (rx->skb->len < 24)
  2361. return RX_DROP_MONITOR;
  2362. if (!ieee80211_is_mgmt(mgmt->frame_control))
  2363. return RX_DROP_MONITOR;
  2364. if (rx->sdata->vif.type == NL80211_IFTYPE_AP &&
  2365. ieee80211_is_beacon(mgmt->frame_control) &&
  2366. !(rx->flags & IEEE80211_RX_BEACON_REPORTED)) {
  2367. int sig = 0;
  2368. if (ieee80211_hw_check(&rx->local->hw, SIGNAL_DBM))
  2369. sig = status->signal;
  2370. cfg80211_report_obss_beacon(rx->local->hw.wiphy,
  2371. rx->skb->data, rx->skb->len,
  2372. status->freq, sig);
  2373. rx->flags |= IEEE80211_RX_BEACON_REPORTED;
  2374. }
  2375. if (ieee80211_drop_unencrypted_mgmt(rx))
  2376. return RX_DROP_UNUSABLE;
  2377. return RX_CONTINUE;
  2378. }
  2379. static ieee80211_rx_result debug_noinline
  2380. ieee80211_rx_h_action(struct ieee80211_rx_data *rx)
  2381. {
  2382. struct ieee80211_local *local = rx->local;
  2383. struct ieee80211_sub_if_data *sdata = rx->sdata;
  2384. struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) rx->skb->data;
  2385. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
  2386. int len = rx->skb->len;
  2387. if (!ieee80211_is_action(mgmt->frame_control))
  2388. return RX_CONTINUE;
  2389. /* drop too small frames */
  2390. if (len < IEEE80211_MIN_ACTION_SIZE)
  2391. return RX_DROP_UNUSABLE;
  2392. if (!rx->sta && mgmt->u.action.category != WLAN_CATEGORY_PUBLIC &&
  2393. mgmt->u.action.category != WLAN_CATEGORY_SELF_PROTECTED &&
  2394. mgmt->u.action.category != WLAN_CATEGORY_SPECTRUM_MGMT)
  2395. return RX_DROP_UNUSABLE;
  2396. switch (mgmt->u.action.category) {
  2397. case WLAN_CATEGORY_HT:
  2398. /* reject HT action frames from stations not supporting HT */
  2399. if (!rx->sta->sta.ht_cap.ht_supported)
  2400. goto invalid;
  2401. if (sdata->vif.type != NL80211_IFTYPE_STATION &&
  2402. sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
  2403. sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
  2404. sdata->vif.type != NL80211_IFTYPE_AP &&
  2405. sdata->vif.type != NL80211_IFTYPE_ADHOC)
  2406. break;
  2407. /* verify action & smps_control/chanwidth are present */
  2408. if (len < IEEE80211_MIN_ACTION_SIZE + 2)
  2409. goto invalid;
  2410. switch (mgmt->u.action.u.ht_smps.action) {
  2411. case WLAN_HT_ACTION_SMPS: {
  2412. struct ieee80211_supported_band *sband;
  2413. enum ieee80211_smps_mode smps_mode;
  2414. /* convert to HT capability */
  2415. switch (mgmt->u.action.u.ht_smps.smps_control) {
  2416. case WLAN_HT_SMPS_CONTROL_DISABLED:
  2417. smps_mode = IEEE80211_SMPS_OFF;
  2418. break;
  2419. case WLAN_HT_SMPS_CONTROL_STATIC:
  2420. smps_mode = IEEE80211_SMPS_STATIC;
  2421. break;
  2422. case WLAN_HT_SMPS_CONTROL_DYNAMIC:
  2423. smps_mode = IEEE80211_SMPS_DYNAMIC;
  2424. break;
  2425. default:
  2426. goto invalid;
  2427. }
  2428. /* if no change do nothing */
  2429. if (rx->sta->sta.smps_mode == smps_mode)
  2430. goto handled;
  2431. rx->sta->sta.smps_mode = smps_mode;
  2432. sband = rx->local->hw.wiphy->bands[status->band];
  2433. rate_control_rate_update(local, sband, rx->sta,
  2434. IEEE80211_RC_SMPS_CHANGED);
  2435. goto handled;
  2436. }
  2437. case WLAN_HT_ACTION_NOTIFY_CHANWIDTH: {
  2438. struct ieee80211_supported_band *sband;
  2439. u8 chanwidth = mgmt->u.action.u.ht_notify_cw.chanwidth;
  2440. enum ieee80211_sta_rx_bandwidth max_bw, new_bw;
  2441. /* If it doesn't support 40 MHz it can't change ... */
  2442. if (!(rx->sta->sta.ht_cap.cap &
  2443. IEEE80211_HT_CAP_SUP_WIDTH_20_40))
  2444. goto handled;
  2445. if (chanwidth == IEEE80211_HT_CHANWIDTH_20MHZ)
  2446. max_bw = IEEE80211_STA_RX_BW_20;
  2447. else
  2448. max_bw = ieee80211_sta_cap_rx_bw(rx->sta);
  2449. /* set cur_max_bandwidth and recalc sta bw */
  2450. rx->sta->cur_max_bandwidth = max_bw;
  2451. new_bw = ieee80211_sta_cur_vht_bw(rx->sta);
  2452. if (rx->sta->sta.bandwidth == new_bw)
  2453. goto handled;
  2454. rx->sta->sta.bandwidth = new_bw;
  2455. sband = rx->local->hw.wiphy->bands[status->band];
  2456. rate_control_rate_update(local, sband, rx->sta,
  2457. IEEE80211_RC_BW_CHANGED);
  2458. goto handled;
  2459. }
  2460. default:
  2461. goto invalid;
  2462. }
  2463. break;
  2464. case WLAN_CATEGORY_PUBLIC:
  2465. if (len < IEEE80211_MIN_ACTION_SIZE + 1)
  2466. goto invalid;
  2467. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  2468. break;
  2469. if (!rx->sta)
  2470. break;
  2471. if (!ether_addr_equal(mgmt->bssid, sdata->u.mgd.bssid))
  2472. break;
  2473. if (mgmt->u.action.u.ext_chan_switch.action_code !=
  2474. WLAN_PUB_ACTION_EXT_CHANSW_ANN)
  2475. break;
  2476. if (len < offsetof(struct ieee80211_mgmt,
  2477. u.action.u.ext_chan_switch.variable))
  2478. goto invalid;
  2479. goto queue;
  2480. case WLAN_CATEGORY_VHT:
  2481. if (sdata->vif.type != NL80211_IFTYPE_STATION &&
  2482. sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
  2483. sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
  2484. sdata->vif.type != NL80211_IFTYPE_AP &&
  2485. sdata->vif.type != NL80211_IFTYPE_ADHOC)
  2486. break;
  2487. /* verify action code is present */
  2488. if (len < IEEE80211_MIN_ACTION_SIZE + 1)
  2489. goto invalid;
  2490. switch (mgmt->u.action.u.vht_opmode_notif.action_code) {
  2491. case WLAN_VHT_ACTION_OPMODE_NOTIF: {
  2492. /* verify opmode is present */
  2493. if (len < IEEE80211_MIN_ACTION_SIZE + 2)
  2494. goto invalid;
  2495. goto queue;
  2496. }
  2497. case WLAN_VHT_ACTION_GROUPID_MGMT: {
  2498. if (len < IEEE80211_MIN_ACTION_SIZE + 25)
  2499. goto invalid;
  2500. goto queue;
  2501. }
  2502. default:
  2503. break;
  2504. }
  2505. break;
  2506. case WLAN_CATEGORY_BACK:
  2507. if (sdata->vif.type != NL80211_IFTYPE_STATION &&
  2508. sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
  2509. sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
  2510. sdata->vif.type != NL80211_IFTYPE_AP &&
  2511. sdata->vif.type != NL80211_IFTYPE_ADHOC)
  2512. break;
  2513. /* verify action_code is present */
  2514. if (len < IEEE80211_MIN_ACTION_SIZE + 1)
  2515. break;
  2516. switch (mgmt->u.action.u.addba_req.action_code) {
  2517. case WLAN_ACTION_ADDBA_REQ:
  2518. if (len < (IEEE80211_MIN_ACTION_SIZE +
  2519. sizeof(mgmt->u.action.u.addba_req)))
  2520. goto invalid;
  2521. break;
  2522. case WLAN_ACTION_ADDBA_RESP:
  2523. if (len < (IEEE80211_MIN_ACTION_SIZE +
  2524. sizeof(mgmt->u.action.u.addba_resp)))
  2525. goto invalid;
  2526. break;
  2527. case WLAN_ACTION_DELBA:
  2528. if (len < (IEEE80211_MIN_ACTION_SIZE +
  2529. sizeof(mgmt->u.action.u.delba)))
  2530. goto invalid;
  2531. break;
  2532. default:
  2533. goto invalid;
  2534. }
  2535. goto queue;
  2536. case WLAN_CATEGORY_SPECTRUM_MGMT:
  2537. /* verify action_code is present */
  2538. if (len < IEEE80211_MIN_ACTION_SIZE + 1)
  2539. break;
  2540. switch (mgmt->u.action.u.measurement.action_code) {
  2541. case WLAN_ACTION_SPCT_MSR_REQ:
  2542. if (status->band != NL80211_BAND_5GHZ)
  2543. break;
  2544. if (len < (IEEE80211_MIN_ACTION_SIZE +
  2545. sizeof(mgmt->u.action.u.measurement)))
  2546. break;
  2547. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  2548. break;
  2549. ieee80211_process_measurement_req(sdata, mgmt, len);
  2550. goto handled;
  2551. case WLAN_ACTION_SPCT_CHL_SWITCH: {
  2552. u8 *bssid;
  2553. if (len < (IEEE80211_MIN_ACTION_SIZE +
  2554. sizeof(mgmt->u.action.u.chan_switch)))
  2555. break;
  2556. if (sdata->vif.type != NL80211_IFTYPE_STATION &&
  2557. sdata->vif.type != NL80211_IFTYPE_ADHOC &&
  2558. sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
  2559. break;
  2560. if (sdata->vif.type == NL80211_IFTYPE_STATION)
  2561. bssid = sdata->u.mgd.bssid;
  2562. else if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
  2563. bssid = sdata->u.ibss.bssid;
  2564. else if (sdata->vif.type == NL80211_IFTYPE_MESH_POINT)
  2565. bssid = mgmt->sa;
  2566. else
  2567. break;
  2568. if (!ether_addr_equal(mgmt->bssid, bssid))
  2569. break;
  2570. goto queue;
  2571. }
  2572. }
  2573. break;
  2574. case WLAN_CATEGORY_SA_QUERY:
  2575. if (len < (IEEE80211_MIN_ACTION_SIZE +
  2576. sizeof(mgmt->u.action.u.sa_query)))
  2577. break;
  2578. switch (mgmt->u.action.u.sa_query.action) {
  2579. case WLAN_ACTION_SA_QUERY_REQUEST:
  2580. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  2581. break;
  2582. ieee80211_process_sa_query_req(sdata, mgmt, len);
  2583. goto handled;
  2584. }
  2585. break;
  2586. case WLAN_CATEGORY_SELF_PROTECTED:
  2587. if (len < (IEEE80211_MIN_ACTION_SIZE +
  2588. sizeof(mgmt->u.action.u.self_prot.action_code)))
  2589. break;
  2590. switch (mgmt->u.action.u.self_prot.action_code) {
  2591. case WLAN_SP_MESH_PEERING_OPEN:
  2592. case WLAN_SP_MESH_PEERING_CLOSE:
  2593. case WLAN_SP_MESH_PEERING_CONFIRM:
  2594. if (!ieee80211_vif_is_mesh(&sdata->vif))
  2595. goto invalid;
  2596. if (sdata->u.mesh.user_mpm)
  2597. /* userspace handles this frame */
  2598. break;
  2599. goto queue;
  2600. case WLAN_SP_MGK_INFORM:
  2601. case WLAN_SP_MGK_ACK:
  2602. if (!ieee80211_vif_is_mesh(&sdata->vif))
  2603. goto invalid;
  2604. break;
  2605. }
  2606. break;
  2607. case WLAN_CATEGORY_MESH_ACTION:
  2608. if (len < (IEEE80211_MIN_ACTION_SIZE +
  2609. sizeof(mgmt->u.action.u.mesh_action.action_code)))
  2610. break;
  2611. if (!ieee80211_vif_is_mesh(&sdata->vif))
  2612. break;
  2613. if (mesh_action_is_path_sel(mgmt) &&
  2614. !mesh_path_sel_is_hwmp(sdata))
  2615. break;
  2616. goto queue;
  2617. }
  2618. return RX_CONTINUE;
  2619. invalid:
  2620. status->rx_flags |= IEEE80211_RX_MALFORMED_ACTION_FRM;
  2621. /* will return in the next handlers */
  2622. return RX_CONTINUE;
  2623. handled:
  2624. if (rx->sta)
  2625. rx->sta->rx_stats.packets++;
  2626. dev_kfree_skb(rx->skb);
  2627. return RX_QUEUED;
  2628. queue:
  2629. rx->skb->pkt_type = IEEE80211_SDATA_QUEUE_TYPE_FRAME;
  2630. skb_queue_tail(&sdata->skb_queue, rx->skb);
  2631. ieee80211_queue_work(&local->hw, &sdata->work);
  2632. if (rx->sta)
  2633. rx->sta->rx_stats.packets++;
  2634. return RX_QUEUED;
  2635. }
  2636. static ieee80211_rx_result debug_noinline
  2637. ieee80211_rx_h_userspace_mgmt(struct ieee80211_rx_data *rx)
  2638. {
  2639. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
  2640. int sig = 0;
  2641. /* skip known-bad action frames and return them in the next handler */
  2642. if (status->rx_flags & IEEE80211_RX_MALFORMED_ACTION_FRM)
  2643. return RX_CONTINUE;
  2644. /*
  2645. * Getting here means the kernel doesn't know how to handle
  2646. * it, but maybe userspace does ... include returned frames
  2647. * so userspace can register for those to know whether ones
  2648. * it transmitted were processed or returned.
  2649. */
  2650. if (ieee80211_hw_check(&rx->local->hw, SIGNAL_DBM))
  2651. sig = status->signal;
  2652. if (cfg80211_rx_mgmt(&rx->sdata->wdev, status->freq, sig,
  2653. rx->skb->data, rx->skb->len, 0)) {
  2654. if (rx->sta)
  2655. rx->sta->rx_stats.packets++;
  2656. dev_kfree_skb(rx->skb);
  2657. return RX_QUEUED;
  2658. }
  2659. return RX_CONTINUE;
  2660. }
  2661. static ieee80211_rx_result debug_noinline
  2662. ieee80211_rx_h_action_return(struct ieee80211_rx_data *rx)
  2663. {
  2664. struct ieee80211_local *local = rx->local;
  2665. struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) rx->skb->data;
  2666. struct sk_buff *nskb;
  2667. struct ieee80211_sub_if_data *sdata = rx->sdata;
  2668. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
  2669. if (!ieee80211_is_action(mgmt->frame_control))
  2670. return RX_CONTINUE;
  2671. /*
  2672. * For AP mode, hostapd is responsible for handling any action
  2673. * frames that we didn't handle, including returning unknown
  2674. * ones. For all other modes we will return them to the sender,
  2675. * setting the 0x80 bit in the action category, as required by
  2676. * 802.11-2012 9.24.4.
  2677. * Newer versions of hostapd shall also use the management frame
  2678. * registration mechanisms, but older ones still use cooked
  2679. * monitor interfaces so push all frames there.
  2680. */
  2681. if (!(status->rx_flags & IEEE80211_RX_MALFORMED_ACTION_FRM) &&
  2682. (sdata->vif.type == NL80211_IFTYPE_AP ||
  2683. sdata->vif.type == NL80211_IFTYPE_AP_VLAN))
  2684. return RX_DROP_MONITOR;
  2685. if (is_multicast_ether_addr(mgmt->da))
  2686. return RX_DROP_MONITOR;
  2687. /* do not return rejected action frames */
  2688. if (mgmt->u.action.category & 0x80)
  2689. return RX_DROP_UNUSABLE;
  2690. nskb = skb_copy_expand(rx->skb, local->hw.extra_tx_headroom, 0,
  2691. GFP_ATOMIC);
  2692. if (nskb) {
  2693. struct ieee80211_mgmt *nmgmt = (void *)nskb->data;
  2694. nmgmt->u.action.category |= 0x80;
  2695. memcpy(nmgmt->da, nmgmt->sa, ETH_ALEN);
  2696. memcpy(nmgmt->sa, rx->sdata->vif.addr, ETH_ALEN);
  2697. memset(nskb->cb, 0, sizeof(nskb->cb));
  2698. if (rx->sdata->vif.type == NL80211_IFTYPE_P2P_DEVICE) {
  2699. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(nskb);
  2700. info->flags = IEEE80211_TX_CTL_TX_OFFCHAN |
  2701. IEEE80211_TX_INTFL_OFFCHAN_TX_OK |
  2702. IEEE80211_TX_CTL_NO_CCK_RATE;
  2703. if (ieee80211_hw_check(&local->hw, QUEUE_CONTROL))
  2704. info->hw_queue =
  2705. local->hw.offchannel_tx_hw_queue;
  2706. }
  2707. __ieee80211_tx_skb_tid_band(rx->sdata, nskb, 7,
  2708. status->band);
  2709. }
  2710. dev_kfree_skb(rx->skb);
  2711. return RX_QUEUED;
  2712. }
  2713. static ieee80211_rx_result debug_noinline
  2714. ieee80211_rx_h_mgmt(struct ieee80211_rx_data *rx)
  2715. {
  2716. struct ieee80211_sub_if_data *sdata = rx->sdata;
  2717. struct ieee80211_mgmt *mgmt = (void *)rx->skb->data;
  2718. __le16 stype;
  2719. stype = mgmt->frame_control & cpu_to_le16(IEEE80211_FCTL_STYPE);
  2720. if (!ieee80211_vif_is_mesh(&sdata->vif) &&
  2721. sdata->vif.type != NL80211_IFTYPE_ADHOC &&
  2722. sdata->vif.type != NL80211_IFTYPE_OCB &&
  2723. sdata->vif.type != NL80211_IFTYPE_STATION)
  2724. return RX_DROP_MONITOR;
  2725. switch (stype) {
  2726. case cpu_to_le16(IEEE80211_STYPE_AUTH):
  2727. case cpu_to_le16(IEEE80211_STYPE_BEACON):
  2728. case cpu_to_le16(IEEE80211_STYPE_PROBE_RESP):
  2729. /* process for all: mesh, mlme, ibss */
  2730. break;
  2731. case cpu_to_le16(IEEE80211_STYPE_ASSOC_RESP):
  2732. case cpu_to_le16(IEEE80211_STYPE_REASSOC_RESP):
  2733. case cpu_to_le16(IEEE80211_STYPE_DEAUTH):
  2734. case cpu_to_le16(IEEE80211_STYPE_DISASSOC):
  2735. if (is_multicast_ether_addr(mgmt->da) &&
  2736. !is_broadcast_ether_addr(mgmt->da))
  2737. return RX_DROP_MONITOR;
  2738. /* process only for station */
  2739. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  2740. return RX_DROP_MONITOR;
  2741. break;
  2742. case cpu_to_le16(IEEE80211_STYPE_PROBE_REQ):
  2743. /* process only for ibss and mesh */
  2744. if (sdata->vif.type != NL80211_IFTYPE_ADHOC &&
  2745. sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
  2746. return RX_DROP_MONITOR;
  2747. break;
  2748. default:
  2749. return RX_DROP_MONITOR;
  2750. }
  2751. /* queue up frame and kick off work to process it */
  2752. rx->skb->pkt_type = IEEE80211_SDATA_QUEUE_TYPE_FRAME;
  2753. skb_queue_tail(&sdata->skb_queue, rx->skb);
  2754. ieee80211_queue_work(&rx->local->hw, &sdata->work);
  2755. if (rx->sta)
  2756. rx->sta->rx_stats.packets++;
  2757. return RX_QUEUED;
  2758. }
  2759. static void ieee80211_rx_cooked_monitor(struct ieee80211_rx_data *rx,
  2760. struct ieee80211_rate *rate)
  2761. {
  2762. struct ieee80211_sub_if_data *sdata;
  2763. struct ieee80211_local *local = rx->local;
  2764. struct sk_buff *skb = rx->skb, *skb2;
  2765. struct net_device *prev_dev = NULL;
  2766. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
  2767. int needed_headroom;
  2768. /*
  2769. * If cooked monitor has been processed already, then
  2770. * don't do it again. If not, set the flag.
  2771. */
  2772. if (rx->flags & IEEE80211_RX_CMNTR)
  2773. goto out_free_skb;
  2774. rx->flags |= IEEE80211_RX_CMNTR;
  2775. /* If there are no cooked monitor interfaces, just free the SKB */
  2776. if (!local->cooked_mntrs)
  2777. goto out_free_skb;
  2778. /* vendor data is long removed here */
  2779. status->flag &= ~RX_FLAG_RADIOTAP_VENDOR_DATA;
  2780. /* room for the radiotap header based on driver features */
  2781. needed_headroom = ieee80211_rx_radiotap_hdrlen(local, status, skb);
  2782. if (skb_headroom(skb) < needed_headroom &&
  2783. pskb_expand_head(skb, needed_headroom, 0, GFP_ATOMIC))
  2784. goto out_free_skb;
  2785. /* prepend radiotap information */
  2786. ieee80211_add_rx_radiotap_header(local, skb, rate, needed_headroom,
  2787. false);
  2788. skb_reset_mac_header(skb);
  2789. skb->ip_summed = CHECKSUM_UNNECESSARY;
  2790. skb->pkt_type = PACKET_OTHERHOST;
  2791. skb->protocol = htons(ETH_P_802_2);
  2792. list_for_each_entry_rcu(sdata, &local->interfaces, list) {
  2793. if (!ieee80211_sdata_running(sdata))
  2794. continue;
  2795. if (sdata->vif.type != NL80211_IFTYPE_MONITOR ||
  2796. !(sdata->u.mntr.flags & MONITOR_FLAG_COOK_FRAMES))
  2797. continue;
  2798. if (prev_dev) {
  2799. skb2 = skb_clone(skb, GFP_ATOMIC);
  2800. if (skb2) {
  2801. skb2->dev = prev_dev;
  2802. netif_receive_skb(skb2);
  2803. }
  2804. }
  2805. prev_dev = sdata->dev;
  2806. ieee80211_rx_stats(sdata->dev, skb->len);
  2807. }
  2808. if (prev_dev) {
  2809. skb->dev = prev_dev;
  2810. netif_receive_skb(skb);
  2811. return;
  2812. }
  2813. out_free_skb:
  2814. dev_kfree_skb(skb);
  2815. }
  2816. static void ieee80211_rx_handlers_result(struct ieee80211_rx_data *rx,
  2817. ieee80211_rx_result res)
  2818. {
  2819. switch (res) {
  2820. case RX_DROP_MONITOR:
  2821. I802_DEBUG_INC(rx->sdata->local->rx_handlers_drop);
  2822. if (rx->sta)
  2823. rx->sta->rx_stats.dropped++;
  2824. /* fall through */
  2825. case RX_CONTINUE: {
  2826. struct ieee80211_rate *rate = NULL;
  2827. struct ieee80211_supported_band *sband;
  2828. struct ieee80211_rx_status *status;
  2829. status = IEEE80211_SKB_RXCB((rx->skb));
  2830. sband = rx->local->hw.wiphy->bands[status->band];
  2831. if (!(status->flag & RX_FLAG_HT) &&
  2832. !(status->flag & RX_FLAG_VHT))
  2833. rate = &sband->bitrates[status->rate_idx];
  2834. ieee80211_rx_cooked_monitor(rx, rate);
  2835. break;
  2836. }
  2837. case RX_DROP_UNUSABLE:
  2838. I802_DEBUG_INC(rx->sdata->local->rx_handlers_drop);
  2839. if (rx->sta)
  2840. rx->sta->rx_stats.dropped++;
  2841. dev_kfree_skb(rx->skb);
  2842. break;
  2843. case RX_QUEUED:
  2844. I802_DEBUG_INC(rx->sdata->local->rx_handlers_queued);
  2845. break;
  2846. }
  2847. }
  2848. static void ieee80211_rx_handlers(struct ieee80211_rx_data *rx,
  2849. struct sk_buff_head *frames)
  2850. {
  2851. ieee80211_rx_result res = RX_DROP_MONITOR;
  2852. struct sk_buff *skb;
  2853. #define CALL_RXH(rxh) \
  2854. do { \
  2855. res = rxh(rx); \
  2856. if (res != RX_CONTINUE) \
  2857. goto rxh_next; \
  2858. } while (0)
  2859. /* Lock here to avoid hitting all of the data used in the RX
  2860. * path (e.g. key data, station data, ...) concurrently when
  2861. * a frame is released from the reorder buffer due to timeout
  2862. * from the timer, potentially concurrently with RX from the
  2863. * driver.
  2864. */
  2865. spin_lock_bh(&rx->local->rx_path_lock);
  2866. while ((skb = __skb_dequeue(frames))) {
  2867. /*
  2868. * all the other fields are valid across frames
  2869. * that belong to an aMPDU since they are on the
  2870. * same TID from the same station
  2871. */
  2872. rx->skb = skb;
  2873. CALL_RXH(ieee80211_rx_h_check_more_data);
  2874. CALL_RXH(ieee80211_rx_h_uapsd_and_pspoll);
  2875. CALL_RXH(ieee80211_rx_h_sta_process);
  2876. CALL_RXH(ieee80211_rx_h_decrypt);
  2877. CALL_RXH(ieee80211_rx_h_defragment);
  2878. CALL_RXH(ieee80211_rx_h_michael_mic_verify);
  2879. /* must be after MMIC verify so header is counted in MPDU mic */
  2880. #ifdef CONFIG_MAC80211_MESH
  2881. if (ieee80211_vif_is_mesh(&rx->sdata->vif))
  2882. CALL_RXH(ieee80211_rx_h_mesh_fwding);
  2883. #endif
  2884. CALL_RXH(ieee80211_rx_h_amsdu);
  2885. CALL_RXH(ieee80211_rx_h_data);
  2886. /* special treatment -- needs the queue */
  2887. res = ieee80211_rx_h_ctrl(rx, frames);
  2888. if (res != RX_CONTINUE)
  2889. goto rxh_next;
  2890. CALL_RXH(ieee80211_rx_h_mgmt_check);
  2891. CALL_RXH(ieee80211_rx_h_action);
  2892. CALL_RXH(ieee80211_rx_h_userspace_mgmt);
  2893. CALL_RXH(ieee80211_rx_h_action_return);
  2894. CALL_RXH(ieee80211_rx_h_mgmt);
  2895. rxh_next:
  2896. ieee80211_rx_handlers_result(rx, res);
  2897. #undef CALL_RXH
  2898. }
  2899. spin_unlock_bh(&rx->local->rx_path_lock);
  2900. }
  2901. static void ieee80211_invoke_rx_handlers(struct ieee80211_rx_data *rx)
  2902. {
  2903. struct sk_buff_head reorder_release;
  2904. ieee80211_rx_result res = RX_DROP_MONITOR;
  2905. __skb_queue_head_init(&reorder_release);
  2906. #define CALL_RXH(rxh) \
  2907. do { \
  2908. res = rxh(rx); \
  2909. if (res != RX_CONTINUE) \
  2910. goto rxh_next; \
  2911. } while (0)
  2912. CALL_RXH(ieee80211_rx_h_check_dup);
  2913. CALL_RXH(ieee80211_rx_h_check);
  2914. ieee80211_rx_reorder_ampdu(rx, &reorder_release);
  2915. ieee80211_rx_handlers(rx, &reorder_release);
  2916. return;
  2917. rxh_next:
  2918. ieee80211_rx_handlers_result(rx, res);
  2919. #undef CALL_RXH
  2920. }
  2921. /*
  2922. * This function makes calls into the RX path, therefore
  2923. * it has to be invoked under RCU read lock.
  2924. */
  2925. void ieee80211_release_reorder_timeout(struct sta_info *sta, int tid)
  2926. {
  2927. struct sk_buff_head frames;
  2928. struct ieee80211_rx_data rx = {
  2929. .sta = sta,
  2930. .sdata = sta->sdata,
  2931. .local = sta->local,
  2932. /* This is OK -- must be QoS data frame */
  2933. .security_idx = tid,
  2934. .seqno_idx = tid,
  2935. .napi = NULL, /* must be NULL to not have races */
  2936. };
  2937. struct tid_ampdu_rx *tid_agg_rx;
  2938. tid_agg_rx = rcu_dereference(sta->ampdu_mlme.tid_rx[tid]);
  2939. if (!tid_agg_rx)
  2940. return;
  2941. __skb_queue_head_init(&frames);
  2942. spin_lock(&tid_agg_rx->reorder_lock);
  2943. ieee80211_sta_reorder_release(sta->sdata, tid_agg_rx, &frames);
  2944. spin_unlock(&tid_agg_rx->reorder_lock);
  2945. if (!skb_queue_empty(&frames)) {
  2946. struct ieee80211_event event = {
  2947. .type = BA_FRAME_TIMEOUT,
  2948. .u.ba.tid = tid,
  2949. .u.ba.sta = &sta->sta,
  2950. };
  2951. drv_event_callback(rx.local, rx.sdata, &event);
  2952. }
  2953. ieee80211_rx_handlers(&rx, &frames);
  2954. }
  2955. void ieee80211_mark_rx_ba_filtered_frames(struct ieee80211_sta *pubsta, u8 tid,
  2956. u16 ssn, u64 filtered,
  2957. u16 received_mpdus)
  2958. {
  2959. struct sta_info *sta;
  2960. struct tid_ampdu_rx *tid_agg_rx;
  2961. struct sk_buff_head frames;
  2962. struct ieee80211_rx_data rx = {
  2963. /* This is OK -- must be QoS data frame */
  2964. .security_idx = tid,
  2965. .seqno_idx = tid,
  2966. };
  2967. int i, diff;
  2968. if (WARN_ON(!pubsta || tid >= IEEE80211_NUM_TIDS))
  2969. return;
  2970. __skb_queue_head_init(&frames);
  2971. sta = container_of(pubsta, struct sta_info, sta);
  2972. rx.sta = sta;
  2973. rx.sdata = sta->sdata;
  2974. rx.local = sta->local;
  2975. rcu_read_lock();
  2976. tid_agg_rx = rcu_dereference(sta->ampdu_mlme.tid_rx[tid]);
  2977. if (!tid_agg_rx)
  2978. goto out;
  2979. spin_lock_bh(&tid_agg_rx->reorder_lock);
  2980. if (received_mpdus >= IEEE80211_SN_MODULO >> 1) {
  2981. int release;
  2982. /* release all frames in the reorder buffer */
  2983. release = (tid_agg_rx->head_seq_num + tid_agg_rx->buf_size) %
  2984. IEEE80211_SN_MODULO;
  2985. ieee80211_release_reorder_frames(sta->sdata, tid_agg_rx,
  2986. release, &frames);
  2987. /* update ssn to match received ssn */
  2988. tid_agg_rx->head_seq_num = ssn;
  2989. } else {
  2990. ieee80211_release_reorder_frames(sta->sdata, tid_agg_rx, ssn,
  2991. &frames);
  2992. }
  2993. /* handle the case that received ssn is behind the mac ssn.
  2994. * it can be tid_agg_rx->buf_size behind and still be valid */
  2995. diff = (tid_agg_rx->head_seq_num - ssn) & IEEE80211_SN_MASK;
  2996. if (diff >= tid_agg_rx->buf_size) {
  2997. tid_agg_rx->reorder_buf_filtered = 0;
  2998. goto release;
  2999. }
  3000. filtered = filtered >> diff;
  3001. ssn += diff;
  3002. /* update bitmap */
  3003. for (i = 0; i < tid_agg_rx->buf_size; i++) {
  3004. int index = (ssn + i) % tid_agg_rx->buf_size;
  3005. tid_agg_rx->reorder_buf_filtered &= ~BIT_ULL(index);
  3006. if (filtered & BIT_ULL(i))
  3007. tid_agg_rx->reorder_buf_filtered |= BIT_ULL(index);
  3008. }
  3009. /* now process also frames that the filter marking released */
  3010. ieee80211_sta_reorder_release(sta->sdata, tid_agg_rx, &frames);
  3011. release:
  3012. spin_unlock_bh(&tid_agg_rx->reorder_lock);
  3013. ieee80211_rx_handlers(&rx, &frames);
  3014. out:
  3015. rcu_read_unlock();
  3016. }
  3017. EXPORT_SYMBOL(ieee80211_mark_rx_ba_filtered_frames);
  3018. /* main receive path */
  3019. static bool ieee80211_accept_frame(struct ieee80211_rx_data *rx)
  3020. {
  3021. struct ieee80211_sub_if_data *sdata = rx->sdata;
  3022. struct sk_buff *skb = rx->skb;
  3023. struct ieee80211_hdr *hdr = (void *)skb->data;
  3024. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
  3025. u8 *bssid = ieee80211_get_bssid(hdr, skb->len, sdata->vif.type);
  3026. int multicast = is_multicast_ether_addr(hdr->addr1);
  3027. switch (sdata->vif.type) {
  3028. case NL80211_IFTYPE_STATION:
  3029. if (!bssid && !sdata->u.mgd.use_4addr)
  3030. return false;
  3031. if (multicast)
  3032. return true;
  3033. return ether_addr_equal(sdata->vif.addr, hdr->addr1);
  3034. case NL80211_IFTYPE_ADHOC:
  3035. if (!bssid)
  3036. return false;
  3037. if (ether_addr_equal(sdata->vif.addr, hdr->addr2) ||
  3038. ether_addr_equal(sdata->u.ibss.bssid, hdr->addr2))
  3039. return false;
  3040. if (ieee80211_is_beacon(hdr->frame_control))
  3041. return true;
  3042. if (!ieee80211_bssid_match(bssid, sdata->u.ibss.bssid))
  3043. return false;
  3044. if (!multicast &&
  3045. !ether_addr_equal(sdata->vif.addr, hdr->addr1))
  3046. return false;
  3047. if (!rx->sta) {
  3048. int rate_idx;
  3049. if (status->flag & (RX_FLAG_HT | RX_FLAG_VHT))
  3050. rate_idx = 0; /* TODO: HT/VHT rates */
  3051. else
  3052. rate_idx = status->rate_idx;
  3053. ieee80211_ibss_rx_no_sta(sdata, bssid, hdr->addr2,
  3054. BIT(rate_idx));
  3055. }
  3056. return true;
  3057. case NL80211_IFTYPE_OCB:
  3058. if (!bssid)
  3059. return false;
  3060. if (!ieee80211_is_data_present(hdr->frame_control))
  3061. return false;
  3062. if (!is_broadcast_ether_addr(bssid))
  3063. return false;
  3064. if (!multicast &&
  3065. !ether_addr_equal(sdata->dev->dev_addr, hdr->addr1))
  3066. return false;
  3067. if (!rx->sta) {
  3068. int rate_idx;
  3069. if (status->flag & RX_FLAG_HT)
  3070. rate_idx = 0; /* TODO: HT rates */
  3071. else
  3072. rate_idx = status->rate_idx;
  3073. ieee80211_ocb_rx_no_sta(sdata, bssid, hdr->addr2,
  3074. BIT(rate_idx));
  3075. }
  3076. return true;
  3077. case NL80211_IFTYPE_MESH_POINT:
  3078. if (multicast)
  3079. return true;
  3080. return ether_addr_equal(sdata->vif.addr, hdr->addr1);
  3081. case NL80211_IFTYPE_AP_VLAN:
  3082. case NL80211_IFTYPE_AP:
  3083. if (!bssid)
  3084. return ether_addr_equal(sdata->vif.addr, hdr->addr1);
  3085. if (!ieee80211_bssid_match(bssid, sdata->vif.addr)) {
  3086. /*
  3087. * Accept public action frames even when the
  3088. * BSSID doesn't match, this is used for P2P
  3089. * and location updates. Note that mac80211
  3090. * itself never looks at these frames.
  3091. */
  3092. if (!multicast &&
  3093. !ether_addr_equal(sdata->vif.addr, hdr->addr1))
  3094. return false;
  3095. if (ieee80211_is_public_action(hdr, skb->len))
  3096. return true;
  3097. return ieee80211_is_beacon(hdr->frame_control);
  3098. }
  3099. if (!ieee80211_has_tods(hdr->frame_control)) {
  3100. /* ignore data frames to TDLS-peers */
  3101. if (ieee80211_is_data(hdr->frame_control))
  3102. return false;
  3103. /* ignore action frames to TDLS-peers */
  3104. if (ieee80211_is_action(hdr->frame_control) &&
  3105. !is_broadcast_ether_addr(bssid) &&
  3106. !ether_addr_equal(bssid, hdr->addr1))
  3107. return false;
  3108. }
  3109. /*
  3110. * 802.11-2016 Table 9-26 says that for data frames, A1 must be
  3111. * the BSSID - we've checked that already but may have accepted
  3112. * the wildcard (ff:ff:ff:ff:ff:ff).
  3113. *
  3114. * It also says:
  3115. * The BSSID of the Data frame is determined as follows:
  3116. * a) If the STA is contained within an AP or is associated
  3117. * with an AP, the BSSID is the address currently in use
  3118. * by the STA contained in the AP.
  3119. *
  3120. * So we should not accept data frames with an address that's
  3121. * multicast.
  3122. *
  3123. * Accepting it also opens a security problem because stations
  3124. * could encrypt it with the GTK and inject traffic that way.
  3125. */
  3126. if (ieee80211_is_data(hdr->frame_control) && multicast)
  3127. return false;
  3128. return true;
  3129. case NL80211_IFTYPE_WDS:
  3130. if (bssid || !ieee80211_is_data(hdr->frame_control))
  3131. return false;
  3132. return ether_addr_equal(sdata->u.wds.remote_addr, hdr->addr2);
  3133. case NL80211_IFTYPE_P2P_DEVICE:
  3134. return ieee80211_is_public_action(hdr, skb->len) ||
  3135. ieee80211_is_probe_req(hdr->frame_control) ||
  3136. ieee80211_is_probe_resp(hdr->frame_control) ||
  3137. ieee80211_is_beacon(hdr->frame_control);
  3138. case NL80211_IFTYPE_NAN:
  3139. /* Currently no frames on NAN interface are allowed */
  3140. return false;
  3141. default:
  3142. break;
  3143. }
  3144. WARN_ON_ONCE(1);
  3145. return false;
  3146. }
  3147. void ieee80211_check_fast_rx(struct sta_info *sta)
  3148. {
  3149. struct ieee80211_sub_if_data *sdata = sta->sdata;
  3150. struct ieee80211_local *local = sdata->local;
  3151. struct ieee80211_key *key;
  3152. struct ieee80211_fast_rx fastrx = {
  3153. .dev = sdata->dev,
  3154. .vif_type = sdata->vif.type,
  3155. .control_port_protocol = sdata->control_port_protocol,
  3156. }, *old, *new = NULL;
  3157. bool assign = false;
  3158. /* use sparse to check that we don't return without updating */
  3159. __acquire(check_fast_rx);
  3160. BUILD_BUG_ON(sizeof(fastrx.rfc1042_hdr) != sizeof(rfc1042_header));
  3161. BUILD_BUG_ON(sizeof(fastrx.rfc1042_hdr) != ETH_ALEN);
  3162. ether_addr_copy(fastrx.rfc1042_hdr, rfc1042_header);
  3163. ether_addr_copy(fastrx.vif_addr, sdata->vif.addr);
  3164. fastrx.uses_rss = ieee80211_hw_check(&local->hw, USES_RSS);
  3165. /* fast-rx doesn't do reordering */
  3166. if (ieee80211_hw_check(&local->hw, AMPDU_AGGREGATION) &&
  3167. !ieee80211_hw_check(&local->hw, SUPPORTS_REORDERING_BUFFER))
  3168. goto clear;
  3169. switch (sdata->vif.type) {
  3170. case NL80211_IFTYPE_STATION:
  3171. /* 4-addr is harder to deal with, later maybe */
  3172. if (sdata->u.mgd.use_4addr)
  3173. goto clear;
  3174. /* software powersave is a huge mess, avoid all of it */
  3175. if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK))
  3176. goto clear;
  3177. if (ieee80211_hw_check(&local->hw, SUPPORTS_PS) &&
  3178. !ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS))
  3179. goto clear;
  3180. if (sta->sta.tdls) {
  3181. fastrx.da_offs = offsetof(struct ieee80211_hdr, addr1);
  3182. fastrx.sa_offs = offsetof(struct ieee80211_hdr, addr2);
  3183. fastrx.expected_ds_bits = 0;
  3184. } else {
  3185. fastrx.sta_notify = sdata->u.mgd.probe_send_count > 0;
  3186. fastrx.da_offs = offsetof(struct ieee80211_hdr, addr1);
  3187. fastrx.sa_offs = offsetof(struct ieee80211_hdr, addr3);
  3188. fastrx.expected_ds_bits =
  3189. cpu_to_le16(IEEE80211_FCTL_FROMDS);
  3190. }
  3191. break;
  3192. case NL80211_IFTYPE_AP_VLAN:
  3193. case NL80211_IFTYPE_AP:
  3194. /* parallel-rx requires this, at least with calls to
  3195. * ieee80211_sta_ps_transition()
  3196. */
  3197. if (!ieee80211_hw_check(&local->hw, AP_LINK_PS))
  3198. goto clear;
  3199. fastrx.da_offs = offsetof(struct ieee80211_hdr, addr3);
  3200. fastrx.sa_offs = offsetof(struct ieee80211_hdr, addr2);
  3201. fastrx.expected_ds_bits = cpu_to_le16(IEEE80211_FCTL_TODS);
  3202. fastrx.internal_forward =
  3203. !(sdata->flags & IEEE80211_SDATA_DONT_BRIDGE_PACKETS) &&
  3204. (sdata->vif.type != NL80211_IFTYPE_AP_VLAN ||
  3205. !sdata->u.vlan.sta);
  3206. break;
  3207. default:
  3208. goto clear;
  3209. }
  3210. if (!test_sta_flag(sta, WLAN_STA_AUTHORIZED))
  3211. goto clear;
  3212. rcu_read_lock();
  3213. key = rcu_dereference(sta->ptk[sta->ptk_idx]);
  3214. if (key) {
  3215. switch (key->conf.cipher) {
  3216. case WLAN_CIPHER_SUITE_TKIP:
  3217. /* we don't want to deal with MMIC in fast-rx */
  3218. goto clear_rcu;
  3219. case WLAN_CIPHER_SUITE_CCMP:
  3220. case WLAN_CIPHER_SUITE_CCMP_256:
  3221. case WLAN_CIPHER_SUITE_GCMP:
  3222. case WLAN_CIPHER_SUITE_GCMP_256:
  3223. break;
  3224. default:
  3225. /* we also don't want to deal with WEP or cipher scheme
  3226. * since those require looking up the key idx in the
  3227. * frame, rather than assuming the PTK is used
  3228. * (we need to revisit this once we implement the real
  3229. * PTK index, which is now valid in the spec, but we
  3230. * haven't implemented that part yet)
  3231. */
  3232. goto clear_rcu;
  3233. }
  3234. fastrx.key = true;
  3235. fastrx.icv_len = key->conf.icv_len;
  3236. }
  3237. assign = true;
  3238. clear_rcu:
  3239. rcu_read_unlock();
  3240. clear:
  3241. __release(check_fast_rx);
  3242. if (assign)
  3243. new = kmemdup(&fastrx, sizeof(fastrx), GFP_KERNEL);
  3244. spin_lock_bh(&sta->lock);
  3245. old = rcu_dereference_protected(sta->fast_rx, true);
  3246. rcu_assign_pointer(sta->fast_rx, new);
  3247. spin_unlock_bh(&sta->lock);
  3248. if (old)
  3249. kfree_rcu(old, rcu_head);
  3250. }
  3251. void ieee80211_clear_fast_rx(struct sta_info *sta)
  3252. {
  3253. struct ieee80211_fast_rx *old;
  3254. spin_lock_bh(&sta->lock);
  3255. old = rcu_dereference_protected(sta->fast_rx, true);
  3256. RCU_INIT_POINTER(sta->fast_rx, NULL);
  3257. spin_unlock_bh(&sta->lock);
  3258. if (old)
  3259. kfree_rcu(old, rcu_head);
  3260. }
  3261. void __ieee80211_check_fast_rx_iface(struct ieee80211_sub_if_data *sdata)
  3262. {
  3263. struct ieee80211_local *local = sdata->local;
  3264. struct sta_info *sta;
  3265. lockdep_assert_held(&local->sta_mtx);
  3266. list_for_each_entry_rcu(sta, &local->sta_list, list) {
  3267. if (sdata != sta->sdata &&
  3268. (!sta->sdata->bss || sta->sdata->bss != sdata->bss))
  3269. continue;
  3270. ieee80211_check_fast_rx(sta);
  3271. }
  3272. }
  3273. void ieee80211_check_fast_rx_iface(struct ieee80211_sub_if_data *sdata)
  3274. {
  3275. struct ieee80211_local *local = sdata->local;
  3276. mutex_lock(&local->sta_mtx);
  3277. __ieee80211_check_fast_rx_iface(sdata);
  3278. mutex_unlock(&local->sta_mtx);
  3279. }
  3280. static bool ieee80211_invoke_fast_rx(struct ieee80211_rx_data *rx,
  3281. struct ieee80211_fast_rx *fast_rx)
  3282. {
  3283. struct sk_buff *skb = rx->skb;
  3284. struct ieee80211_hdr *hdr = (void *)skb->data;
  3285. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
  3286. struct sta_info *sta = rx->sta;
  3287. int orig_len = skb->len;
  3288. int snap_offs = ieee80211_hdrlen(hdr->frame_control);
  3289. struct {
  3290. u8 snap[sizeof(rfc1042_header)];
  3291. __be16 proto;
  3292. } *payload __aligned(2);
  3293. struct {
  3294. u8 da[ETH_ALEN];
  3295. u8 sa[ETH_ALEN];
  3296. } addrs __aligned(2);
  3297. struct ieee80211_sta_rx_stats *stats = &sta->rx_stats;
  3298. if (fast_rx->uses_rss)
  3299. stats = this_cpu_ptr(sta->pcpu_rx_stats);
  3300. /* for parallel-rx, we need to have DUP_VALIDATED, otherwise we write
  3301. * to a common data structure; drivers can implement that per queue
  3302. * but we don't have that information in mac80211
  3303. */
  3304. if (!(status->flag & RX_FLAG_DUP_VALIDATED))
  3305. return false;
  3306. #define FAST_RX_CRYPT_FLAGS (RX_FLAG_PN_VALIDATED | RX_FLAG_DECRYPTED)
  3307. /* If using encryption, we also need to have:
  3308. * - PN_VALIDATED: similar, but the implementation is tricky
  3309. * - DECRYPTED: necessary for PN_VALIDATED
  3310. */
  3311. if (fast_rx->key &&
  3312. (status->flag & FAST_RX_CRYPT_FLAGS) != FAST_RX_CRYPT_FLAGS)
  3313. return false;
  3314. /* we don't deal with A-MSDU deaggregation here */
  3315. if (status->rx_flags & IEEE80211_RX_AMSDU)
  3316. return false;
  3317. if (unlikely(!ieee80211_is_data_present(hdr->frame_control)))
  3318. return false;
  3319. if (unlikely(ieee80211_is_frag(hdr)))
  3320. return false;
  3321. /* Since our interface address cannot be multicast, this
  3322. * implicitly also rejects multicast frames without the
  3323. * explicit check.
  3324. *
  3325. * We shouldn't get any *data* frames not addressed to us
  3326. * (AP mode will accept multicast *management* frames), but
  3327. * punting here will make it go through the full checks in
  3328. * ieee80211_accept_frame().
  3329. */
  3330. if (!ether_addr_equal(fast_rx->vif_addr, hdr->addr1))
  3331. return false;
  3332. if ((hdr->frame_control & cpu_to_le16(IEEE80211_FCTL_FROMDS |
  3333. IEEE80211_FCTL_TODS)) !=
  3334. fast_rx->expected_ds_bits)
  3335. goto drop;
  3336. /* assign the key to drop unencrypted frames (later)
  3337. * and strip the IV/MIC if necessary
  3338. */
  3339. if (fast_rx->key && !(status->flag & RX_FLAG_IV_STRIPPED)) {
  3340. /* GCMP header length is the same */
  3341. snap_offs += IEEE80211_CCMP_HDR_LEN;
  3342. }
  3343. if (!pskb_may_pull(skb, snap_offs + sizeof(*payload)))
  3344. goto drop;
  3345. payload = (void *)(skb->data + snap_offs);
  3346. if (!ether_addr_equal(payload->snap, fast_rx->rfc1042_hdr))
  3347. return false;
  3348. /* Don't handle these here since they require special code.
  3349. * Accept AARP and IPX even though they should come with a
  3350. * bridge-tunnel header - but if we get them this way then
  3351. * there's little point in discarding them.
  3352. */
  3353. if (unlikely(payload->proto == cpu_to_be16(ETH_P_TDLS) ||
  3354. payload->proto == fast_rx->control_port_protocol))
  3355. return false;
  3356. /* after this point, don't punt to the slowpath! */
  3357. if (rx->key && !(status->flag & RX_FLAG_MIC_STRIPPED) &&
  3358. pskb_trim(skb, skb->len - fast_rx->icv_len))
  3359. goto drop;
  3360. if (unlikely(fast_rx->sta_notify)) {
  3361. ieee80211_sta_rx_notify(rx->sdata, hdr);
  3362. fast_rx->sta_notify = false;
  3363. }
  3364. /* statistics part of ieee80211_rx_h_sta_process() */
  3365. stats->last_rx = jiffies;
  3366. stats->last_rate = sta_stats_encode_rate(status);
  3367. stats->fragments++;
  3368. stats->packets++;
  3369. if (!(status->flag & RX_FLAG_NO_SIGNAL_VAL)) {
  3370. stats->last_signal = status->signal;
  3371. if (!fast_rx->uses_rss)
  3372. ewma_signal_add(&sta->rx_stats_avg.signal,
  3373. -status->signal);
  3374. }
  3375. if (status->chains) {
  3376. int i;
  3377. stats->chains = status->chains;
  3378. for (i = 0; i < ARRAY_SIZE(status->chain_signal); i++) {
  3379. int signal = status->chain_signal[i];
  3380. if (!(status->chains & BIT(i)))
  3381. continue;
  3382. stats->chain_signal_last[i] = signal;
  3383. if (!fast_rx->uses_rss)
  3384. ewma_signal_add(&sta->rx_stats_avg.chain_signal[i],
  3385. -signal);
  3386. }
  3387. }
  3388. /* end of statistics */
  3389. if (rx->key && !ieee80211_has_protected(hdr->frame_control))
  3390. goto drop;
  3391. /* do the header conversion - first grab the addresses */
  3392. ether_addr_copy(addrs.da, skb->data + fast_rx->da_offs);
  3393. ether_addr_copy(addrs.sa, skb->data + fast_rx->sa_offs);
  3394. /* remove the SNAP but leave the ethertype */
  3395. skb_pull(skb, snap_offs + sizeof(rfc1042_header));
  3396. /* push the addresses in front */
  3397. memcpy(skb_push(skb, sizeof(addrs)), &addrs, sizeof(addrs));
  3398. skb->dev = fast_rx->dev;
  3399. ieee80211_rx_stats(fast_rx->dev, skb->len);
  3400. /* The seqno index has the same property as needed
  3401. * for the rx_msdu field, i.e. it is IEEE80211_NUM_TIDS
  3402. * for non-QoS-data frames. Here we know it's a data
  3403. * frame, so count MSDUs.
  3404. */
  3405. u64_stats_update_begin(&stats->syncp);
  3406. stats->msdu[rx->seqno_idx]++;
  3407. stats->bytes += orig_len;
  3408. u64_stats_update_end(&stats->syncp);
  3409. if (fast_rx->internal_forward) {
  3410. struct sk_buff *xmit_skb = NULL;
  3411. bool multicast = is_multicast_ether_addr(skb->data);
  3412. if (multicast) {
  3413. xmit_skb = skb_copy(skb, GFP_ATOMIC);
  3414. } else if (sta_info_get(rx->sdata, skb->data)) {
  3415. xmit_skb = skb;
  3416. skb = NULL;
  3417. }
  3418. if (xmit_skb) {
  3419. /*
  3420. * Send to wireless media and increase priority by 256
  3421. * to keep the received priority instead of
  3422. * reclassifying the frame (see cfg80211_classify8021d).
  3423. */
  3424. xmit_skb->priority += 256;
  3425. xmit_skb->protocol = htons(ETH_P_802_3);
  3426. skb_reset_network_header(xmit_skb);
  3427. skb_reset_mac_header(xmit_skb);
  3428. dev_queue_xmit(xmit_skb);
  3429. }
  3430. if (!skb)
  3431. return true;
  3432. }
  3433. /* deliver to local stack */
  3434. skb->protocol = eth_type_trans(skb, fast_rx->dev);
  3435. memset(skb->cb, 0, sizeof(skb->cb));
  3436. if (rx->napi)
  3437. napi_gro_receive(rx->napi, skb);
  3438. else
  3439. netif_receive_skb(skb);
  3440. return true;
  3441. drop:
  3442. dev_kfree_skb(skb);
  3443. stats->dropped++;
  3444. return true;
  3445. }
  3446. /*
  3447. * This function returns whether or not the SKB
  3448. * was destined for RX processing or not, which,
  3449. * if consume is true, is equivalent to whether
  3450. * or not the skb was consumed.
  3451. */
  3452. static bool ieee80211_prepare_and_rx_handle(struct ieee80211_rx_data *rx,
  3453. struct sk_buff *skb, bool consume)
  3454. {
  3455. struct ieee80211_local *local = rx->local;
  3456. struct ieee80211_sub_if_data *sdata = rx->sdata;
  3457. rx->skb = skb;
  3458. /* See if we can do fast-rx; if we have to copy we already lost,
  3459. * so punt in that case. We should never have to deliver a data
  3460. * frame to multiple interfaces anyway.
  3461. *
  3462. * We skip the ieee80211_accept_frame() call and do the necessary
  3463. * checking inside ieee80211_invoke_fast_rx().
  3464. */
  3465. if (consume && rx->sta) {
  3466. struct ieee80211_fast_rx *fast_rx;
  3467. fast_rx = rcu_dereference(rx->sta->fast_rx);
  3468. if (fast_rx && ieee80211_invoke_fast_rx(rx, fast_rx))
  3469. return true;
  3470. }
  3471. if (!ieee80211_accept_frame(rx))
  3472. return false;
  3473. if (!consume) {
  3474. skb = skb_copy(skb, GFP_ATOMIC);
  3475. if (!skb) {
  3476. if (net_ratelimit())
  3477. wiphy_debug(local->hw.wiphy,
  3478. "failed to copy skb for %s\n",
  3479. sdata->name);
  3480. return true;
  3481. }
  3482. rx->skb = skb;
  3483. }
  3484. ieee80211_invoke_rx_handlers(rx);
  3485. return true;
  3486. }
  3487. /*
  3488. * This is the actual Rx frames handler. as it belongs to Rx path it must
  3489. * be called with rcu_read_lock protection.
  3490. */
  3491. static void __ieee80211_rx_handle_packet(struct ieee80211_hw *hw,
  3492. struct ieee80211_sta *pubsta,
  3493. struct sk_buff *skb,
  3494. struct napi_struct *napi)
  3495. {
  3496. struct ieee80211_local *local = hw_to_local(hw);
  3497. struct ieee80211_sub_if_data *sdata;
  3498. struct ieee80211_hdr *hdr;
  3499. __le16 fc;
  3500. struct ieee80211_rx_data rx;
  3501. struct ieee80211_sub_if_data *prev;
  3502. struct rhlist_head *tmp;
  3503. int err = 0;
  3504. fc = ((struct ieee80211_hdr *)skb->data)->frame_control;
  3505. memset(&rx, 0, sizeof(rx));
  3506. rx.skb = skb;
  3507. rx.local = local;
  3508. rx.napi = napi;
  3509. if (ieee80211_is_data(fc) || ieee80211_is_mgmt(fc))
  3510. I802_DEBUG_INC(local->dot11ReceivedFragmentCount);
  3511. if (ieee80211_is_mgmt(fc)) {
  3512. /* drop frame if too short for header */
  3513. if (skb->len < ieee80211_hdrlen(fc))
  3514. err = -ENOBUFS;
  3515. else
  3516. err = skb_linearize(skb);
  3517. } else {
  3518. err = !pskb_may_pull(skb, ieee80211_hdrlen(fc));
  3519. }
  3520. if (err) {
  3521. dev_kfree_skb(skb);
  3522. return;
  3523. }
  3524. hdr = (struct ieee80211_hdr *)skb->data;
  3525. ieee80211_parse_qos(&rx);
  3526. ieee80211_verify_alignment(&rx);
  3527. if (unlikely(ieee80211_is_probe_resp(hdr->frame_control) ||
  3528. ieee80211_is_beacon(hdr->frame_control)))
  3529. ieee80211_scan_rx(local, skb);
  3530. if (ieee80211_is_data(fc)) {
  3531. struct sta_info *sta, *prev_sta;
  3532. if (pubsta) {
  3533. rx.sta = container_of(pubsta, struct sta_info, sta);
  3534. rx.sdata = rx.sta->sdata;
  3535. if (ieee80211_prepare_and_rx_handle(&rx, skb, true))
  3536. return;
  3537. goto out;
  3538. }
  3539. prev_sta = NULL;
  3540. for_each_sta_info(local, hdr->addr2, sta, tmp) {
  3541. if (!prev_sta) {
  3542. prev_sta = sta;
  3543. continue;
  3544. }
  3545. rx.sta = prev_sta;
  3546. rx.sdata = prev_sta->sdata;
  3547. ieee80211_prepare_and_rx_handle(&rx, skb, false);
  3548. prev_sta = sta;
  3549. }
  3550. if (prev_sta) {
  3551. rx.sta = prev_sta;
  3552. rx.sdata = prev_sta->sdata;
  3553. if (ieee80211_prepare_and_rx_handle(&rx, skb, true))
  3554. return;
  3555. goto out;
  3556. }
  3557. }
  3558. prev = NULL;
  3559. list_for_each_entry_rcu(sdata, &local->interfaces, list) {
  3560. if (!ieee80211_sdata_running(sdata))
  3561. continue;
  3562. if (sdata->vif.type == NL80211_IFTYPE_MONITOR ||
  3563. sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
  3564. continue;
  3565. /*
  3566. * frame is destined for this interface, but if it's
  3567. * not also for the previous one we handle that after
  3568. * the loop to avoid copying the SKB once too much
  3569. */
  3570. if (!prev) {
  3571. prev = sdata;
  3572. continue;
  3573. }
  3574. rx.sta = sta_info_get_bss(prev, hdr->addr2);
  3575. rx.sdata = prev;
  3576. ieee80211_prepare_and_rx_handle(&rx, skb, false);
  3577. prev = sdata;
  3578. }
  3579. if (prev) {
  3580. rx.sta = sta_info_get_bss(prev, hdr->addr2);
  3581. rx.sdata = prev;
  3582. if (ieee80211_prepare_and_rx_handle(&rx, skb, true))
  3583. return;
  3584. }
  3585. out:
  3586. dev_kfree_skb(skb);
  3587. }
  3588. /*
  3589. * This is the receive path handler. It is called by a low level driver when an
  3590. * 802.11 MPDU is received from the hardware.
  3591. */
  3592. void ieee80211_rx_napi(struct ieee80211_hw *hw, struct ieee80211_sta *pubsta,
  3593. struct sk_buff *skb, struct napi_struct *napi)
  3594. {
  3595. struct ieee80211_local *local = hw_to_local(hw);
  3596. struct ieee80211_rate *rate = NULL;
  3597. struct ieee80211_supported_band *sband;
  3598. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
  3599. WARN_ON_ONCE(softirq_count() == 0);
  3600. if (WARN_ON(status->band >= NUM_NL80211_BANDS))
  3601. goto drop;
  3602. sband = local->hw.wiphy->bands[status->band];
  3603. if (WARN_ON(!sband))
  3604. goto drop;
  3605. /*
  3606. * If we're suspending, it is possible although not too likely
  3607. * that we'd be receiving frames after having already partially
  3608. * quiesced the stack. We can't process such frames then since
  3609. * that might, for example, cause stations to be added or other
  3610. * driver callbacks be invoked.
  3611. */
  3612. if (unlikely(local->quiescing || local->suspended))
  3613. goto drop;
  3614. /* We might be during a HW reconfig, prevent Rx for the same reason */
  3615. if (unlikely(local->in_reconfig))
  3616. goto drop;
  3617. /*
  3618. * The same happens when we're not even started,
  3619. * but that's worth a warning.
  3620. */
  3621. if (WARN_ON(!local->started))
  3622. goto drop;
  3623. if (likely(!(status->flag & RX_FLAG_FAILED_PLCP_CRC))) {
  3624. /*
  3625. * Validate the rate, unless a PLCP error means that
  3626. * we probably can't have a valid rate here anyway.
  3627. */
  3628. if (status->flag & RX_FLAG_HT) {
  3629. /*
  3630. * rate_idx is MCS index, which can be [0-76]
  3631. * as documented on:
  3632. *
  3633. * http://wireless.kernel.org/en/developers/Documentation/ieee80211/802.11n
  3634. *
  3635. * Anything else would be some sort of driver or
  3636. * hardware error. The driver should catch hardware
  3637. * errors.
  3638. */
  3639. if (WARN(status->rate_idx > 76,
  3640. "Rate marked as an HT rate but passed "
  3641. "status->rate_idx is not "
  3642. "an MCS index [0-76]: %d (0x%02x)\n",
  3643. status->rate_idx,
  3644. status->rate_idx))
  3645. goto drop;
  3646. } else if (status->flag & RX_FLAG_VHT) {
  3647. if (WARN_ONCE(status->rate_idx > 9 ||
  3648. !status->vht_nss ||
  3649. status->vht_nss > 8,
  3650. "Rate marked as a VHT rate but data is invalid: MCS: %d, NSS: %d\n",
  3651. status->rate_idx, status->vht_nss))
  3652. goto drop;
  3653. } else {
  3654. if (WARN_ON(status->rate_idx >= sband->n_bitrates))
  3655. goto drop;
  3656. rate = &sband->bitrates[status->rate_idx];
  3657. }
  3658. }
  3659. status->rx_flags = 0;
  3660. /*
  3661. * key references and virtual interfaces are protected using RCU
  3662. * and this requires that we are in a read-side RCU section during
  3663. * receive processing
  3664. */
  3665. rcu_read_lock();
  3666. /*
  3667. * Frames with failed FCS/PLCP checksum are not returned,
  3668. * all other frames are returned without radiotap header
  3669. * if it was previously present.
  3670. * Also, frames with less than 16 bytes are dropped.
  3671. */
  3672. skb = ieee80211_rx_monitor(local, skb, rate);
  3673. if (!skb) {
  3674. rcu_read_unlock();
  3675. return;
  3676. }
  3677. ieee80211_tpt_led_trig_rx(local,
  3678. ((struct ieee80211_hdr *)skb->data)->frame_control,
  3679. skb->len);
  3680. __ieee80211_rx_handle_packet(hw, pubsta, skb, napi);
  3681. rcu_read_unlock();
  3682. return;
  3683. drop:
  3684. kfree_skb(skb);
  3685. }
  3686. EXPORT_SYMBOL(ieee80211_rx_napi);
  3687. /* This is a version of the rx handler that can be called from hard irq
  3688. * context. Post the skb on the queue and schedule the tasklet */
  3689. void ieee80211_rx_irqsafe(struct ieee80211_hw *hw, struct sk_buff *skb)
  3690. {
  3691. struct ieee80211_local *local = hw_to_local(hw);
  3692. BUILD_BUG_ON(sizeof(struct ieee80211_rx_status) > sizeof(skb->cb));
  3693. skb->pkt_type = IEEE80211_RX_MSG;
  3694. skb_queue_tail(&local->skb_queue, skb);
  3695. tasklet_schedule(&local->tasklet);
  3696. }
  3697. EXPORT_SYMBOL(ieee80211_rx_irqsafe);