rx.c 153 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright 2002-2005, Instant802 Networks, Inc.
  4. * Copyright 2005-2006, Devicescape Software, Inc.
  5. * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz>
  6. * Copyright 2007-2010 Johannes Berg <johannes@sipsolutions.net>
  7. * Copyright 2013-2014 Intel Mobile Communications GmbH
  8. * Copyright(c) 2015 - 2017 Intel Deutschland GmbH
  9. * Copyright (C) 2018-2025 Intel Corporation
  10. */
  11. #include <linux/jiffies.h>
  12. #include <linux/slab.h>
  13. #include <linux/kernel.h>
  14. #include <linux/skbuff.h>
  15. #include <linux/netdevice.h>
  16. #include <linux/etherdevice.h>
  17. #include <linux/rcupdate.h>
  18. #include <linux/export.h>
  19. #include <linux/kcov.h>
  20. #include <linux/bitops.h>
  21. #include <kunit/visibility.h>
  22. #include <net/mac80211.h>
  23. #include <net/ieee80211_radiotap.h>
  24. #include <linux/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. /*
  35. * monitor mode reception
  36. *
  37. * This function cleans up the SKB, i.e. it removes all the stuff
  38. * only useful for monitoring.
  39. */
  40. static struct sk_buff *ieee80211_clean_skb(struct sk_buff *skb,
  41. unsigned int present_fcs_len,
  42. unsigned int rtap_space)
  43. {
  44. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
  45. struct ieee80211_hdr *hdr;
  46. unsigned int hdrlen;
  47. __le16 fc;
  48. if (present_fcs_len)
  49. __pskb_trim(skb, skb->len - present_fcs_len);
  50. pskb_pull(skb, rtap_space);
  51. /* After pulling radiotap header, clear all flags that indicate
  52. * info in skb->data.
  53. */
  54. status->flag &= ~(RX_FLAG_RADIOTAP_TLV_AT_END |
  55. RX_FLAG_RADIOTAP_LSIG |
  56. RX_FLAG_RADIOTAP_HE_MU |
  57. RX_FLAG_RADIOTAP_HE);
  58. hdr = (void *)skb->data;
  59. fc = hdr->frame_control;
  60. /*
  61. * Remove the HT-Control field (if present) on management
  62. * frames after we've sent the frame to monitoring. We
  63. * (currently) don't need it, and don't properly parse
  64. * frames with it present, due to the assumption of a
  65. * fixed management header length.
  66. */
  67. if (likely(!ieee80211_is_mgmt(fc) || !ieee80211_has_order(fc)))
  68. return skb;
  69. hdrlen = ieee80211_hdrlen(fc);
  70. hdr->frame_control &= ~cpu_to_le16(IEEE80211_FCTL_ORDER);
  71. if (!pskb_may_pull(skb, hdrlen)) {
  72. dev_kfree_skb(skb);
  73. return NULL;
  74. }
  75. memmove(skb->data + IEEE80211_HT_CTL_LEN, skb->data,
  76. hdrlen - IEEE80211_HT_CTL_LEN);
  77. pskb_pull(skb, IEEE80211_HT_CTL_LEN);
  78. return skb;
  79. }
  80. static inline bool should_drop_frame(struct sk_buff *skb, int present_fcs_len,
  81. unsigned int rtap_space)
  82. {
  83. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
  84. struct ieee80211_hdr *hdr;
  85. hdr = (void *)(skb->data + rtap_space);
  86. if (status->flag & (RX_FLAG_FAILED_FCS_CRC |
  87. RX_FLAG_FAILED_PLCP_CRC |
  88. RX_FLAG_ONLY_MONITOR |
  89. RX_FLAG_NO_PSDU))
  90. return true;
  91. if (unlikely(skb->len < 16 + present_fcs_len + rtap_space))
  92. return true;
  93. if (ieee80211_is_ctl(hdr->frame_control) &&
  94. !ieee80211_is_pspoll(hdr->frame_control) &&
  95. !ieee80211_is_back_req(hdr->frame_control))
  96. return true;
  97. return false;
  98. }
  99. static int
  100. ieee80211_rx_radiotap_hdrlen(struct ieee80211_local *local,
  101. struct ieee80211_rx_status *status,
  102. struct sk_buff *skb)
  103. {
  104. int len;
  105. /* always present fields */
  106. len = sizeof(struct ieee80211_radiotap_header) + 8;
  107. /* allocate extra bitmaps */
  108. if (status->chains)
  109. len += 4 * hweight8(status->chains);
  110. if (ieee80211_have_rx_timestamp(status)) {
  111. len = ALIGN(len, 8);
  112. len += 8;
  113. }
  114. if (ieee80211_hw_check(&local->hw, SIGNAL_DBM))
  115. len += 1;
  116. /* antenna field, if we don't have per-chain info */
  117. if (!status->chains)
  118. len += 1;
  119. /* padding for RX_FLAGS if necessary */
  120. len = ALIGN(len, 2);
  121. if (status->encoding == RX_ENC_HT) /* HT info */
  122. len += 3;
  123. if (status->flag & RX_FLAG_AMPDU_DETAILS) {
  124. len = ALIGN(len, 4);
  125. len += 8;
  126. }
  127. if (status->encoding == RX_ENC_VHT) {
  128. len = ALIGN(len, 2);
  129. len += 12;
  130. }
  131. if (local->hw.radiotap_timestamp.units_pos >= 0) {
  132. len = ALIGN(len, 8);
  133. len += 12;
  134. }
  135. if (status->encoding == RX_ENC_HE &&
  136. status->flag & RX_FLAG_RADIOTAP_HE) {
  137. len = ALIGN(len, 2);
  138. len += 12;
  139. BUILD_BUG_ON(sizeof(struct ieee80211_radiotap_he) != 12);
  140. }
  141. if (status->encoding == RX_ENC_HE &&
  142. status->flag & RX_FLAG_RADIOTAP_HE_MU) {
  143. len = ALIGN(len, 2);
  144. len += 12;
  145. BUILD_BUG_ON(sizeof(struct ieee80211_radiotap_he_mu) != 12);
  146. }
  147. if (status->flag & RX_FLAG_NO_PSDU)
  148. len += 1;
  149. if (status->flag & RX_FLAG_RADIOTAP_LSIG) {
  150. len = ALIGN(len, 2);
  151. len += 4;
  152. BUILD_BUG_ON(sizeof(struct ieee80211_radiotap_lsig) != 4);
  153. }
  154. if (status->chains) {
  155. /* antenna and antenna signal fields */
  156. len += 2 * hweight8(status->chains);
  157. }
  158. if (status->flag & RX_FLAG_RADIOTAP_TLV_AT_END) {
  159. int tlv_offset = 0;
  160. /*
  161. * The position to look at depends on the existence (or non-
  162. * existence) of other elements, so take that into account...
  163. */
  164. if (status->flag & RX_FLAG_RADIOTAP_HE)
  165. tlv_offset +=
  166. sizeof(struct ieee80211_radiotap_he);
  167. if (status->flag & RX_FLAG_RADIOTAP_HE_MU)
  168. tlv_offset +=
  169. sizeof(struct ieee80211_radiotap_he_mu);
  170. if (status->flag & RX_FLAG_RADIOTAP_LSIG)
  171. tlv_offset +=
  172. sizeof(struct ieee80211_radiotap_lsig);
  173. /* ensure 4 byte alignment for TLV */
  174. len = ALIGN(len, 4);
  175. /* TLVs until the mac header */
  176. len += skb_mac_header(skb) - &skb->data[tlv_offset];
  177. }
  178. return len;
  179. }
  180. static void __ieee80211_queue_skb_to_iface(struct ieee80211_sub_if_data *sdata,
  181. int link_id,
  182. struct sta_info *sta,
  183. struct sk_buff *skb)
  184. {
  185. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
  186. if (link_id >= 0) {
  187. status->link_valid = 1;
  188. status->link_id = link_id;
  189. } else {
  190. status->link_valid = 0;
  191. }
  192. skb_queue_tail(&sdata->skb_queue, skb);
  193. wiphy_work_queue(sdata->local->hw.wiphy, &sdata->work);
  194. if (sta)
  195. sta->deflink.rx_stats.packets++;
  196. }
  197. static void ieee80211_queue_skb_to_iface(struct ieee80211_sub_if_data *sdata,
  198. int link_id,
  199. struct sta_info *sta,
  200. struct sk_buff *skb)
  201. {
  202. skb->protocol = 0;
  203. __ieee80211_queue_skb_to_iface(sdata, link_id, sta, skb);
  204. }
  205. static void ieee80211_handle_mu_mimo_mon(struct ieee80211_sub_if_data *sdata,
  206. struct sk_buff *skb,
  207. int rtap_space)
  208. {
  209. struct {
  210. struct ieee80211_hdr_3addr hdr;
  211. u8 category;
  212. u8 action_code;
  213. } __packed __aligned(2) action;
  214. if (!sdata)
  215. return;
  216. BUILD_BUG_ON(sizeof(action) != IEEE80211_MIN_ACTION_SIZE + 1);
  217. if (skb->len < rtap_space + sizeof(action) +
  218. VHT_MUMIMO_GROUPS_DATA_LEN)
  219. return;
  220. if (!is_valid_ether_addr(sdata->u.mntr.mu_follow_addr))
  221. return;
  222. skb_copy_bits(skb, rtap_space, &action, sizeof(action));
  223. if (!ieee80211_is_action(action.hdr.frame_control))
  224. return;
  225. if (action.category != WLAN_CATEGORY_VHT)
  226. return;
  227. if (action.action_code != WLAN_VHT_ACTION_GROUPID_MGMT)
  228. return;
  229. if (!ether_addr_equal(action.hdr.addr1, sdata->u.mntr.mu_follow_addr))
  230. return;
  231. skb = skb_copy(skb, GFP_ATOMIC);
  232. if (!skb)
  233. return;
  234. ieee80211_queue_skb_to_iface(sdata, -1, NULL, skb);
  235. }
  236. /*
  237. * ieee80211_add_rx_radiotap_header - add radiotap header
  238. *
  239. * add a radiotap header containing all the fields which the hardware provided.
  240. */
  241. static void
  242. ieee80211_add_rx_radiotap_header(struct ieee80211_local *local,
  243. struct sk_buff *skb,
  244. struct ieee80211_rate *rate,
  245. int rtap_len, bool has_fcs)
  246. {
  247. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
  248. struct ieee80211_radiotap_header *rthdr;
  249. unsigned char *pos;
  250. __le32 *it_present;
  251. u32 it_present_val;
  252. u16 rx_flags = 0;
  253. u16 channel_flags = 0;
  254. u32 tlvs_len = 0;
  255. int mpdulen, chain;
  256. unsigned long chains = status->chains;
  257. struct ieee80211_radiotap_he he = {};
  258. struct ieee80211_radiotap_he_mu he_mu = {};
  259. struct ieee80211_radiotap_lsig lsig = {};
  260. if (status->flag & RX_FLAG_RADIOTAP_HE) {
  261. he = *(struct ieee80211_radiotap_he *)skb->data;
  262. skb_pull(skb, sizeof(he));
  263. WARN_ON_ONCE(status->encoding != RX_ENC_HE);
  264. }
  265. if (status->flag & RX_FLAG_RADIOTAP_HE_MU) {
  266. he_mu = *(struct ieee80211_radiotap_he_mu *)skb->data;
  267. skb_pull(skb, sizeof(he_mu));
  268. }
  269. if (status->flag & RX_FLAG_RADIOTAP_LSIG) {
  270. lsig = *(struct ieee80211_radiotap_lsig *)skb->data;
  271. skb_pull(skb, sizeof(lsig));
  272. }
  273. if (status->flag & RX_FLAG_RADIOTAP_TLV_AT_END) {
  274. /* data is pointer at tlv all other info was pulled off */
  275. tlvs_len = skb_mac_header(skb) - skb->data;
  276. }
  277. mpdulen = skb->len;
  278. if (!(has_fcs && ieee80211_hw_check(&local->hw, RX_INCLUDES_FCS)))
  279. mpdulen += FCS_LEN;
  280. rthdr = skb_push(skb, rtap_len - tlvs_len);
  281. memset(rthdr, 0, rtap_len - tlvs_len);
  282. it_present = &rthdr->it_present;
  283. /* radiotap header, set always present flags */
  284. rthdr->it_len = cpu_to_le16(rtap_len);
  285. it_present_val = BIT(IEEE80211_RADIOTAP_FLAGS) |
  286. BIT(IEEE80211_RADIOTAP_CHANNEL) |
  287. BIT(IEEE80211_RADIOTAP_RX_FLAGS);
  288. if (!status->chains)
  289. it_present_val |= BIT(IEEE80211_RADIOTAP_ANTENNA);
  290. for_each_set_bit(chain, &chains, IEEE80211_MAX_CHAINS) {
  291. it_present_val |=
  292. BIT(IEEE80211_RADIOTAP_EXT) |
  293. BIT(IEEE80211_RADIOTAP_RADIOTAP_NAMESPACE);
  294. put_unaligned_le32(it_present_val, it_present);
  295. it_present++;
  296. it_present_val = BIT(IEEE80211_RADIOTAP_ANTENNA) |
  297. BIT(IEEE80211_RADIOTAP_DBM_ANTSIGNAL);
  298. }
  299. if (status->flag & RX_FLAG_RADIOTAP_TLV_AT_END)
  300. it_present_val |= BIT(IEEE80211_RADIOTAP_TLV);
  301. put_unaligned_le32(it_present_val, it_present);
  302. /* This references through an offset into it_optional[] rather
  303. * than via it_present otherwise later uses of pos will cause
  304. * the compiler to think we have walked past the end of the
  305. * struct member.
  306. */
  307. pos = (void *)&rthdr->it_optional[it_present + 1 - rthdr->it_optional];
  308. /* the order of the following fields is important */
  309. /* IEEE80211_RADIOTAP_TSFT */
  310. if (ieee80211_have_rx_timestamp(status)) {
  311. /* padding */
  312. while ((pos - (u8 *)rthdr) & 7)
  313. *pos++ = 0;
  314. put_unaligned_le64(
  315. ieee80211_calculate_rx_timestamp(local, status,
  316. mpdulen, 0),
  317. pos);
  318. rthdr->it_present |= cpu_to_le32(BIT(IEEE80211_RADIOTAP_TSFT));
  319. pos += 8;
  320. }
  321. /* IEEE80211_RADIOTAP_FLAGS */
  322. if (has_fcs && ieee80211_hw_check(&local->hw, RX_INCLUDES_FCS))
  323. *pos |= IEEE80211_RADIOTAP_F_FCS;
  324. if (status->flag & (RX_FLAG_FAILED_FCS_CRC | RX_FLAG_FAILED_PLCP_CRC))
  325. *pos |= IEEE80211_RADIOTAP_F_BADFCS;
  326. if (status->enc_flags & RX_ENC_FLAG_SHORTPRE)
  327. *pos |= IEEE80211_RADIOTAP_F_SHORTPRE;
  328. pos++;
  329. /* IEEE80211_RADIOTAP_RATE */
  330. if (!rate || status->encoding != RX_ENC_LEGACY) {
  331. /*
  332. * Without rate information don't add it. If we have,
  333. * MCS information is a separate field in radiotap,
  334. * added below. The byte here is needed as padding
  335. * for the channel though, so initialise it to 0.
  336. */
  337. *pos = 0;
  338. } else {
  339. int shift = 0;
  340. rthdr->it_present |= cpu_to_le32(BIT(IEEE80211_RADIOTAP_RATE));
  341. if (status->bw == RATE_INFO_BW_10)
  342. shift = 1;
  343. else if (status->bw == RATE_INFO_BW_5)
  344. shift = 2;
  345. *pos = DIV_ROUND_UP(rate->bitrate, 5 * (1 << shift));
  346. }
  347. pos++;
  348. /* IEEE80211_RADIOTAP_CHANNEL */
  349. /* TODO: frequency offset in KHz */
  350. put_unaligned_le16(status->freq, pos);
  351. pos += 2;
  352. if (status->bw == RATE_INFO_BW_10)
  353. channel_flags |= IEEE80211_CHAN_HALF;
  354. else if (status->bw == RATE_INFO_BW_5)
  355. channel_flags |= IEEE80211_CHAN_QUARTER;
  356. if (status->band == NL80211_BAND_5GHZ ||
  357. status->band == NL80211_BAND_6GHZ)
  358. channel_flags |= IEEE80211_CHAN_OFDM | IEEE80211_CHAN_5GHZ;
  359. else if (status->encoding != RX_ENC_LEGACY)
  360. channel_flags |= IEEE80211_CHAN_DYN | IEEE80211_CHAN_2GHZ;
  361. else if (rate && rate->flags & IEEE80211_RATE_ERP_G)
  362. channel_flags |= IEEE80211_CHAN_OFDM | IEEE80211_CHAN_2GHZ;
  363. else if (rate)
  364. channel_flags |= IEEE80211_CHAN_CCK | IEEE80211_CHAN_2GHZ;
  365. else
  366. channel_flags |= IEEE80211_CHAN_2GHZ;
  367. put_unaligned_le16(channel_flags, pos);
  368. pos += 2;
  369. /* IEEE80211_RADIOTAP_DBM_ANTSIGNAL */
  370. if (ieee80211_hw_check(&local->hw, SIGNAL_DBM) &&
  371. !(status->flag & RX_FLAG_NO_SIGNAL_VAL)) {
  372. *pos = status->signal;
  373. rthdr->it_present |=
  374. cpu_to_le32(BIT(IEEE80211_RADIOTAP_DBM_ANTSIGNAL));
  375. pos++;
  376. }
  377. /* IEEE80211_RADIOTAP_LOCK_QUALITY is missing */
  378. if (!status->chains) {
  379. /* IEEE80211_RADIOTAP_ANTENNA */
  380. *pos = status->antenna;
  381. pos++;
  382. }
  383. /* IEEE80211_RADIOTAP_DB_ANTNOISE is not used */
  384. /* IEEE80211_RADIOTAP_RX_FLAGS */
  385. /* ensure 2 byte alignment for the 2 byte field as required */
  386. if ((pos - (u8 *)rthdr) & 1)
  387. *pos++ = 0;
  388. if (status->flag & RX_FLAG_FAILED_PLCP_CRC)
  389. rx_flags |= IEEE80211_RADIOTAP_F_RX_BADPLCP;
  390. put_unaligned_le16(rx_flags, pos);
  391. pos += 2;
  392. if (status->encoding == RX_ENC_HT) {
  393. unsigned int stbc;
  394. rthdr->it_present |= cpu_to_le32(BIT(IEEE80211_RADIOTAP_MCS));
  395. *pos = local->hw.radiotap_mcs_details;
  396. if (status->enc_flags & RX_ENC_FLAG_HT_GF)
  397. *pos |= IEEE80211_RADIOTAP_MCS_HAVE_FMT;
  398. if (status->enc_flags & RX_ENC_FLAG_LDPC)
  399. *pos |= IEEE80211_RADIOTAP_MCS_HAVE_FEC;
  400. pos++;
  401. *pos = 0;
  402. if (status->enc_flags & RX_ENC_FLAG_SHORT_GI)
  403. *pos |= IEEE80211_RADIOTAP_MCS_SGI;
  404. if (status->bw == RATE_INFO_BW_40)
  405. *pos |= IEEE80211_RADIOTAP_MCS_BW_40;
  406. if (status->enc_flags & RX_ENC_FLAG_HT_GF)
  407. *pos |= IEEE80211_RADIOTAP_MCS_FMT_GF;
  408. if (status->enc_flags & RX_ENC_FLAG_LDPC)
  409. *pos |= IEEE80211_RADIOTAP_MCS_FEC_LDPC;
  410. stbc = (status->enc_flags & RX_ENC_FLAG_STBC_MASK) >> RX_ENC_FLAG_STBC_SHIFT;
  411. *pos |= stbc << IEEE80211_RADIOTAP_MCS_STBC_SHIFT;
  412. pos++;
  413. *pos++ = status->rate_idx;
  414. }
  415. if (status->flag & RX_FLAG_AMPDU_DETAILS) {
  416. u16 flags = 0;
  417. /* ensure 4 byte alignment */
  418. while ((pos - (u8 *)rthdr) & 3)
  419. pos++;
  420. rthdr->it_present |=
  421. cpu_to_le32(BIT(IEEE80211_RADIOTAP_AMPDU_STATUS));
  422. put_unaligned_le32(status->ampdu_reference, pos);
  423. pos += 4;
  424. if (status->flag & RX_FLAG_AMPDU_LAST_KNOWN)
  425. flags |= IEEE80211_RADIOTAP_AMPDU_LAST_KNOWN;
  426. if (status->flag & RX_FLAG_AMPDU_IS_LAST)
  427. flags |= IEEE80211_RADIOTAP_AMPDU_IS_LAST;
  428. if (status->flag & RX_FLAG_AMPDU_DELIM_CRC_ERROR)
  429. flags |= IEEE80211_RADIOTAP_AMPDU_DELIM_CRC_ERR;
  430. if (status->flag & RX_FLAG_AMPDU_DELIM_CRC_KNOWN)
  431. flags |= IEEE80211_RADIOTAP_AMPDU_DELIM_CRC_KNOWN;
  432. if (status->flag & RX_FLAG_AMPDU_EOF_BIT_KNOWN)
  433. flags |= IEEE80211_RADIOTAP_AMPDU_EOF_KNOWN;
  434. if (status->flag & RX_FLAG_AMPDU_EOF_BIT)
  435. flags |= IEEE80211_RADIOTAP_AMPDU_EOF;
  436. put_unaligned_le16(flags, pos);
  437. pos += 2;
  438. if (status->flag & RX_FLAG_AMPDU_DELIM_CRC_KNOWN)
  439. *pos++ = status->ampdu_delimiter_crc;
  440. else
  441. *pos++ = 0;
  442. *pos++ = 0;
  443. }
  444. if (status->encoding == RX_ENC_VHT) {
  445. u16 known = local->hw.radiotap_vht_details;
  446. rthdr->it_present |= cpu_to_le32(BIT(IEEE80211_RADIOTAP_VHT));
  447. put_unaligned_le16(known, pos);
  448. pos += 2;
  449. /* flags */
  450. if (status->enc_flags & RX_ENC_FLAG_SHORT_GI)
  451. *pos |= IEEE80211_RADIOTAP_VHT_FLAG_SGI;
  452. /* in VHT, STBC is binary */
  453. if (status->enc_flags & RX_ENC_FLAG_STBC_MASK)
  454. *pos |= IEEE80211_RADIOTAP_VHT_FLAG_STBC;
  455. if (status->enc_flags & RX_ENC_FLAG_BF)
  456. *pos |= IEEE80211_RADIOTAP_VHT_FLAG_BEAMFORMED;
  457. pos++;
  458. /* bandwidth */
  459. switch (status->bw) {
  460. case RATE_INFO_BW_80:
  461. *pos++ = 4;
  462. break;
  463. case RATE_INFO_BW_160:
  464. *pos++ = 11;
  465. break;
  466. case RATE_INFO_BW_40:
  467. *pos++ = 1;
  468. break;
  469. default:
  470. *pos++ = 0;
  471. }
  472. /* MCS/NSS */
  473. *pos = (status->rate_idx << 4) | status->nss;
  474. pos += 4;
  475. /* coding field */
  476. if (status->enc_flags & RX_ENC_FLAG_LDPC)
  477. *pos |= IEEE80211_RADIOTAP_CODING_LDPC_USER0;
  478. pos++;
  479. /* group ID */
  480. pos++;
  481. /* partial_aid */
  482. pos += 2;
  483. }
  484. if (local->hw.radiotap_timestamp.units_pos >= 0) {
  485. u16 accuracy = 0;
  486. u8 flags;
  487. u64 ts;
  488. rthdr->it_present |=
  489. cpu_to_le32(BIT(IEEE80211_RADIOTAP_TIMESTAMP));
  490. /* ensure 8 byte alignment */
  491. while ((pos - (u8 *)rthdr) & 7)
  492. pos++;
  493. if (status->flag & RX_FLAG_MACTIME_IS_RTAP_TS64) {
  494. flags = IEEE80211_RADIOTAP_TIMESTAMP_FLAG_64BIT;
  495. ts = status->mactime;
  496. } else {
  497. flags = IEEE80211_RADIOTAP_TIMESTAMP_FLAG_32BIT;
  498. ts = status->device_timestamp;
  499. }
  500. put_unaligned_le64(ts, pos);
  501. pos += sizeof(u64);
  502. if (local->hw.radiotap_timestamp.accuracy >= 0) {
  503. accuracy = local->hw.radiotap_timestamp.accuracy;
  504. flags |= IEEE80211_RADIOTAP_TIMESTAMP_FLAG_ACCURACY;
  505. }
  506. put_unaligned_le16(accuracy, pos);
  507. pos += sizeof(u16);
  508. *pos++ = local->hw.radiotap_timestamp.units_pos;
  509. *pos++ = flags;
  510. }
  511. if (status->encoding == RX_ENC_HE &&
  512. status->flag & RX_FLAG_RADIOTAP_HE) {
  513. #define HE_PREP(f, val) le16_encode_bits(val, IEEE80211_RADIOTAP_HE_##f)
  514. if (status->enc_flags & RX_ENC_FLAG_STBC_MASK) {
  515. he.data6 |= HE_PREP(DATA6_NSTS,
  516. FIELD_GET(RX_ENC_FLAG_STBC_MASK,
  517. status->enc_flags));
  518. he.data3 |= HE_PREP(DATA3_STBC, 1);
  519. } else {
  520. he.data6 |= HE_PREP(DATA6_NSTS, status->nss);
  521. }
  522. #define CHECK_GI(s) \
  523. BUILD_BUG_ON(IEEE80211_RADIOTAP_HE_DATA5_GI_##s != \
  524. (int)NL80211_RATE_INFO_HE_GI_##s)
  525. CHECK_GI(0_8);
  526. CHECK_GI(1_6);
  527. CHECK_GI(3_2);
  528. he.data3 |= HE_PREP(DATA3_DATA_MCS, status->rate_idx);
  529. he.data3 |= HE_PREP(DATA3_DATA_DCM, status->he_dcm);
  530. he.data3 |= HE_PREP(DATA3_CODING,
  531. !!(status->enc_flags & RX_ENC_FLAG_LDPC));
  532. he.data5 |= HE_PREP(DATA5_GI, status->he_gi);
  533. switch (status->bw) {
  534. case RATE_INFO_BW_20:
  535. he.data5 |= HE_PREP(DATA5_DATA_BW_RU_ALLOC,
  536. IEEE80211_RADIOTAP_HE_DATA5_DATA_BW_RU_ALLOC_20MHZ);
  537. break;
  538. case RATE_INFO_BW_40:
  539. he.data5 |= HE_PREP(DATA5_DATA_BW_RU_ALLOC,
  540. IEEE80211_RADIOTAP_HE_DATA5_DATA_BW_RU_ALLOC_40MHZ);
  541. break;
  542. case RATE_INFO_BW_80:
  543. he.data5 |= HE_PREP(DATA5_DATA_BW_RU_ALLOC,
  544. IEEE80211_RADIOTAP_HE_DATA5_DATA_BW_RU_ALLOC_80MHZ);
  545. break;
  546. case RATE_INFO_BW_160:
  547. he.data5 |= HE_PREP(DATA5_DATA_BW_RU_ALLOC,
  548. IEEE80211_RADIOTAP_HE_DATA5_DATA_BW_RU_ALLOC_160MHZ);
  549. break;
  550. case RATE_INFO_BW_HE_RU:
  551. #define CHECK_RU_ALLOC(s) \
  552. BUILD_BUG_ON(IEEE80211_RADIOTAP_HE_DATA5_DATA_BW_RU_ALLOC_##s##T != \
  553. NL80211_RATE_INFO_HE_RU_ALLOC_##s + 4)
  554. CHECK_RU_ALLOC(26);
  555. CHECK_RU_ALLOC(52);
  556. CHECK_RU_ALLOC(106);
  557. CHECK_RU_ALLOC(242);
  558. CHECK_RU_ALLOC(484);
  559. CHECK_RU_ALLOC(996);
  560. CHECK_RU_ALLOC(2x996);
  561. he.data5 |= HE_PREP(DATA5_DATA_BW_RU_ALLOC,
  562. status->he_ru + 4);
  563. break;
  564. default:
  565. WARN_ONCE(1, "Invalid SU BW %d\n", status->bw);
  566. }
  567. /* ensure 2 byte alignment */
  568. while ((pos - (u8 *)rthdr) & 1)
  569. pos++;
  570. rthdr->it_present |= cpu_to_le32(BIT(IEEE80211_RADIOTAP_HE));
  571. memcpy(pos, &he, sizeof(he));
  572. pos += sizeof(he);
  573. }
  574. if (status->encoding == RX_ENC_HE &&
  575. status->flag & RX_FLAG_RADIOTAP_HE_MU) {
  576. /* ensure 2 byte alignment */
  577. while ((pos - (u8 *)rthdr) & 1)
  578. pos++;
  579. rthdr->it_present |= cpu_to_le32(BIT(IEEE80211_RADIOTAP_HE_MU));
  580. memcpy(pos, &he_mu, sizeof(he_mu));
  581. pos += sizeof(he_mu);
  582. }
  583. if (status->flag & RX_FLAG_NO_PSDU) {
  584. rthdr->it_present |=
  585. cpu_to_le32(BIT(IEEE80211_RADIOTAP_ZERO_LEN_PSDU));
  586. *pos++ = status->zero_length_psdu_type;
  587. }
  588. if (status->flag & RX_FLAG_RADIOTAP_LSIG) {
  589. /* ensure 2 byte alignment */
  590. while ((pos - (u8 *)rthdr) & 1)
  591. pos++;
  592. rthdr->it_present |= cpu_to_le32(BIT(IEEE80211_RADIOTAP_LSIG));
  593. memcpy(pos, &lsig, sizeof(lsig));
  594. pos += sizeof(lsig);
  595. }
  596. for_each_set_bit(chain, &chains, IEEE80211_MAX_CHAINS) {
  597. *pos++ = status->chain_signal[chain];
  598. *pos++ = chain;
  599. }
  600. }
  601. static struct sk_buff *
  602. ieee80211_make_monitor_skb(struct ieee80211_local *local,
  603. struct sk_buff **origskb,
  604. struct ieee80211_rate *rate,
  605. int rtap_space, bool use_origskb)
  606. {
  607. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(*origskb);
  608. int rt_hdrlen, needed_headroom;
  609. struct sk_buff *skb;
  610. /* room for the radiotap header based on driver features */
  611. rt_hdrlen = ieee80211_rx_radiotap_hdrlen(local, status, *origskb);
  612. needed_headroom = rt_hdrlen - rtap_space;
  613. if (use_origskb) {
  614. /* only need to expand headroom if necessary */
  615. skb = *origskb;
  616. *origskb = NULL;
  617. /*
  618. * This shouldn't trigger often because most devices have an
  619. * RX header they pull before we get here, and that should
  620. * be big enough for our radiotap information. We should
  621. * probably export the length to drivers so that we can have
  622. * them allocate enough headroom to start with.
  623. */
  624. if (skb_headroom(skb) < needed_headroom &&
  625. pskb_expand_head(skb, needed_headroom, 0, GFP_ATOMIC)) {
  626. dev_kfree_skb(skb);
  627. return NULL;
  628. }
  629. } else {
  630. /*
  631. * Need to make a copy and possibly remove radiotap header
  632. * and FCS from the original.
  633. */
  634. skb = skb_copy_expand(*origskb, needed_headroom + NET_SKB_PAD,
  635. 0, GFP_ATOMIC);
  636. if (!skb)
  637. return NULL;
  638. }
  639. /* prepend radiotap information */
  640. ieee80211_add_rx_radiotap_header(local, skb, rate, rt_hdrlen, true);
  641. skb_reset_mac_header(skb);
  642. skb->ip_summed = CHECKSUM_UNNECESSARY;
  643. skb->pkt_type = PACKET_OTHERHOST;
  644. skb->protocol = htons(ETH_P_802_2);
  645. return skb;
  646. }
  647. /*
  648. * This function copies a received frame to all monitor interfaces and
  649. * returns a cleaned-up SKB that no longer includes the FCS nor the
  650. * radiotap header the driver might have added.
  651. */
  652. static struct sk_buff *
  653. ieee80211_rx_monitor(struct ieee80211_local *local, struct sk_buff *origskb,
  654. struct ieee80211_rate *rate)
  655. {
  656. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(origskb);
  657. struct ieee80211_sub_if_data *sdata;
  658. struct sk_buff *monskb = NULL;
  659. int present_fcs_len = 0;
  660. unsigned int rtap_space = 0;
  661. struct ieee80211_sub_if_data *monitor_sdata =
  662. rcu_dereference(local->monitor_sdata);
  663. bool only_monitor = false;
  664. unsigned int min_head_len;
  665. if (WARN_ON_ONCE(status->flag & RX_FLAG_RADIOTAP_TLV_AT_END &&
  666. !skb_mac_header_was_set(origskb))) {
  667. /* with this skb no way to know where frame payload starts */
  668. dev_kfree_skb(origskb);
  669. return NULL;
  670. }
  671. if (status->flag & RX_FLAG_RADIOTAP_HE)
  672. rtap_space += sizeof(struct ieee80211_radiotap_he);
  673. if (status->flag & RX_FLAG_RADIOTAP_HE_MU)
  674. rtap_space += sizeof(struct ieee80211_radiotap_he_mu);
  675. if (status->flag & RX_FLAG_RADIOTAP_LSIG)
  676. rtap_space += sizeof(struct ieee80211_radiotap_lsig);
  677. if (status->flag & RX_FLAG_RADIOTAP_TLV_AT_END)
  678. rtap_space += skb_mac_header(origskb) - &origskb->data[rtap_space];
  679. min_head_len = rtap_space;
  680. /*
  681. * First, we may need to make a copy of the skb because
  682. * (1) we need to modify it for radiotap (if not present), and
  683. * (2) the other RX handlers will modify the skb we got.
  684. *
  685. * We don't need to, of course, if we aren't going to return
  686. * the SKB because it has a bad FCS/PLCP checksum.
  687. */
  688. if (!(status->flag & RX_FLAG_NO_PSDU)) {
  689. if (ieee80211_hw_check(&local->hw, RX_INCLUDES_FCS)) {
  690. if (unlikely(origskb->len <= FCS_LEN + rtap_space)) {
  691. /* driver bug */
  692. WARN_ON(1);
  693. dev_kfree_skb(origskb);
  694. return NULL;
  695. }
  696. present_fcs_len = FCS_LEN;
  697. }
  698. /* also consider the hdr->frame_control */
  699. min_head_len += 2;
  700. }
  701. /* ensure that the expected data elements are in skb head */
  702. if (!pskb_may_pull(origskb, min_head_len)) {
  703. dev_kfree_skb(origskb);
  704. return NULL;
  705. }
  706. only_monitor = should_drop_frame(origskb, present_fcs_len, rtap_space);
  707. if (!local->monitors || (status->flag & RX_FLAG_SKIP_MONITOR)) {
  708. if (only_monitor) {
  709. dev_kfree_skb(origskb);
  710. return NULL;
  711. }
  712. return ieee80211_clean_skb(origskb, present_fcs_len,
  713. rtap_space);
  714. }
  715. ieee80211_handle_mu_mimo_mon(monitor_sdata, origskb, rtap_space);
  716. list_for_each_entry_rcu(sdata, &local->mon_list, u.mntr.list) {
  717. bool last_monitor = list_is_last(&sdata->u.mntr.list,
  718. &local->mon_list);
  719. if (!monskb)
  720. monskb = ieee80211_make_monitor_skb(local, &origskb,
  721. rate, rtap_space,
  722. only_monitor &&
  723. last_monitor);
  724. if (monskb) {
  725. struct sk_buff *skb;
  726. if (last_monitor) {
  727. skb = monskb;
  728. monskb = NULL;
  729. } else {
  730. skb = skb_clone(monskb, GFP_ATOMIC);
  731. }
  732. if (skb) {
  733. skb->dev = sdata->dev;
  734. dev_sw_netstats_rx_add(skb->dev, skb->len);
  735. netif_receive_skb(skb);
  736. }
  737. }
  738. if (last_monitor)
  739. break;
  740. }
  741. /* this happens if last_monitor was erroneously false */
  742. dev_kfree_skb(monskb);
  743. /* ditto */
  744. if (!origskb)
  745. return NULL;
  746. return ieee80211_clean_skb(origskb, present_fcs_len, rtap_space);
  747. }
  748. static void ieee80211_parse_qos(struct ieee80211_rx_data *rx)
  749. {
  750. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
  751. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
  752. int tid, seqno_idx, security_idx;
  753. /* does the frame have a qos control field? */
  754. if (ieee80211_is_data_qos(hdr->frame_control)) {
  755. u8 *qc = ieee80211_get_qos_ctl(hdr);
  756. /* frame has qos control */
  757. tid = *qc & IEEE80211_QOS_CTL_TID_MASK;
  758. if (*qc & IEEE80211_QOS_CTL_A_MSDU_PRESENT)
  759. status->rx_flags |= IEEE80211_RX_AMSDU;
  760. seqno_idx = tid;
  761. security_idx = tid;
  762. } else {
  763. /*
  764. * IEEE 802.11-2007, 7.1.3.4.1 ("Sequence Number field"):
  765. *
  766. * Sequence numbers for management frames, QoS data
  767. * frames with a broadcast/multicast address in the
  768. * Address 1 field, and all non-QoS data frames sent
  769. * by QoS STAs are assigned using an additional single
  770. * modulo-4096 counter, [...]
  771. *
  772. * We also use that counter for non-QoS STAs.
  773. */
  774. seqno_idx = IEEE80211_NUM_TIDS;
  775. security_idx = 0;
  776. if (ieee80211_is_mgmt(hdr->frame_control))
  777. security_idx = IEEE80211_NUM_TIDS;
  778. tid = 0;
  779. }
  780. rx->seqno_idx = seqno_idx;
  781. rx->security_idx = security_idx;
  782. /* Set skb->priority to 1d tag if highest order bit of TID is not set.
  783. * For now, set skb->priority to 0 for other cases. */
  784. rx->skb->priority = (tid > 7) ? 0 : tid;
  785. }
  786. /**
  787. * DOC: Packet alignment
  788. *
  789. * Drivers always need to pass packets that are aligned to two-byte boundaries
  790. * to the stack.
  791. *
  792. * Additionally, they should, if possible, align the payload data in a way that
  793. * guarantees that the contained IP header is aligned to a four-byte
  794. * boundary. In the case of regular frames, this simply means aligning the
  795. * payload to a four-byte boundary (because either the IP header is directly
  796. * contained, or IV/RFC1042 headers that have a length divisible by four are
  797. * in front of it). If the payload data is not properly aligned and the
  798. * architecture doesn't support efficient unaligned operations, mac80211
  799. * will align the data.
  800. *
  801. * With A-MSDU frames, however, the payload data address must yield two modulo
  802. * four because there are 14-byte 802.3 headers within the A-MSDU frames that
  803. * push the IP header further back to a multiple of four again. Thankfully, the
  804. * specs were sane enough this time around to require padding each A-MSDU
  805. * subframe to a length that is a multiple of four.
  806. *
  807. * Padding like Atheros hardware adds which is between the 802.11 header and
  808. * the payload is not supported; the driver is required to move the 802.11
  809. * header to be directly in front of the payload in that case.
  810. */
  811. static void ieee80211_verify_alignment(struct ieee80211_rx_data *rx)
  812. {
  813. #ifdef CONFIG_MAC80211_VERBOSE_DEBUG
  814. WARN_ON_ONCE((unsigned long)rx->skb->data & 1);
  815. #endif
  816. }
  817. /* rx handlers */
  818. static int ieee80211_is_unicast_robust_mgmt_frame(struct sk_buff *skb)
  819. {
  820. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
  821. if (is_multicast_ether_addr(hdr->addr1))
  822. return 0;
  823. return ieee80211_is_robust_mgmt_frame(skb);
  824. }
  825. static int ieee80211_is_multicast_robust_mgmt_frame(struct sk_buff *skb)
  826. {
  827. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
  828. if (!is_multicast_ether_addr(hdr->addr1))
  829. return 0;
  830. return ieee80211_is_robust_mgmt_frame(skb);
  831. }
  832. /* Get the BIP key index from MMIE; return -1 if this is not a BIP frame */
  833. static int ieee80211_get_mmie_keyidx(struct sk_buff *skb)
  834. {
  835. struct ieee80211_mgmt *hdr = (struct ieee80211_mgmt *) skb->data;
  836. struct ieee80211_mmie *mmie;
  837. struct ieee80211_mmie_16 *mmie16;
  838. if (skb->len < 24 + sizeof(*mmie) || !is_multicast_ether_addr(hdr->da))
  839. return -1;
  840. if (!ieee80211_is_robust_mgmt_frame(skb) &&
  841. !ieee80211_is_beacon(hdr->frame_control))
  842. return -1; /* not a robust management frame */
  843. mmie = (struct ieee80211_mmie *)
  844. (skb->data + skb->len - sizeof(*mmie));
  845. if (mmie->element_id == WLAN_EID_MMIE &&
  846. mmie->length == sizeof(*mmie) - 2)
  847. return le16_to_cpu(mmie->key_id);
  848. mmie16 = (struct ieee80211_mmie_16 *)
  849. (skb->data + skb->len - sizeof(*mmie16));
  850. if (skb->len >= 24 + sizeof(*mmie16) &&
  851. mmie16->element_id == WLAN_EID_MMIE &&
  852. mmie16->length == sizeof(*mmie16) - 2)
  853. return le16_to_cpu(mmie16->key_id);
  854. return -1;
  855. }
  856. static int ieee80211_get_keyid(struct sk_buff *skb)
  857. {
  858. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
  859. __le16 fc = hdr->frame_control;
  860. int hdrlen = ieee80211_hdrlen(fc);
  861. u8 keyid;
  862. /* WEP, TKIP, CCMP and GCMP */
  863. if (unlikely(skb->len < hdrlen + IEEE80211_WEP_IV_LEN))
  864. return -EINVAL;
  865. skb_copy_bits(skb, hdrlen + 3, &keyid, 1);
  866. keyid >>= 6;
  867. return keyid;
  868. }
  869. static ieee80211_rx_result ieee80211_rx_mesh_check(struct ieee80211_rx_data *rx)
  870. {
  871. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
  872. char *dev_addr = rx->sdata->vif.addr;
  873. if (ieee80211_is_data(hdr->frame_control)) {
  874. if (is_multicast_ether_addr(hdr->addr1)) {
  875. if (ieee80211_has_tods(hdr->frame_control) ||
  876. !ieee80211_has_fromds(hdr->frame_control))
  877. return RX_DROP_MONITOR;
  878. if (ether_addr_equal(hdr->addr3, dev_addr))
  879. return RX_DROP_MONITOR;
  880. } else {
  881. if (!ieee80211_has_a4(hdr->frame_control))
  882. return RX_DROP_MONITOR;
  883. if (ether_addr_equal(hdr->addr4, dev_addr))
  884. return RX_DROP_MONITOR;
  885. }
  886. }
  887. /* If there is not an established peer link and this is not a peer link
  888. * establisment frame, beacon or probe, drop the frame.
  889. */
  890. if (!rx->sta || sta_plink_state(rx->sta) != NL80211_PLINK_ESTAB) {
  891. struct ieee80211_mgmt *mgmt;
  892. if (!ieee80211_is_mgmt(hdr->frame_control))
  893. return RX_DROP_MONITOR;
  894. if (ieee80211_is_action(hdr->frame_control)) {
  895. u8 category;
  896. /* make sure category field is present */
  897. if (rx->skb->len < IEEE80211_MIN_ACTION_SIZE)
  898. return RX_DROP_MONITOR;
  899. mgmt = (struct ieee80211_mgmt *)hdr;
  900. category = mgmt->u.action.category;
  901. if (category != WLAN_CATEGORY_MESH_ACTION &&
  902. category != WLAN_CATEGORY_SELF_PROTECTED)
  903. return RX_DROP_MONITOR;
  904. return RX_CONTINUE;
  905. }
  906. if (ieee80211_is_probe_req(hdr->frame_control) ||
  907. ieee80211_is_probe_resp(hdr->frame_control) ||
  908. ieee80211_is_beacon(hdr->frame_control) ||
  909. ieee80211_is_auth(hdr->frame_control))
  910. return RX_CONTINUE;
  911. return RX_DROP_MONITOR;
  912. }
  913. return RX_CONTINUE;
  914. }
  915. static inline bool ieee80211_rx_reorder_ready(struct tid_ampdu_rx *tid_agg_rx,
  916. int index)
  917. {
  918. struct sk_buff_head *frames = &tid_agg_rx->reorder_buf[index];
  919. struct sk_buff *tail = skb_peek_tail(frames);
  920. struct ieee80211_rx_status *status;
  921. if (tid_agg_rx->reorder_buf_filtered &&
  922. tid_agg_rx->reorder_buf_filtered & BIT_ULL(index))
  923. return true;
  924. if (!tail)
  925. return false;
  926. status = IEEE80211_SKB_RXCB(tail);
  927. if (status->flag & RX_FLAG_AMSDU_MORE)
  928. return false;
  929. return true;
  930. }
  931. static void ieee80211_release_reorder_frame(struct ieee80211_sub_if_data *sdata,
  932. struct tid_ampdu_rx *tid_agg_rx,
  933. int index,
  934. struct sk_buff_head *frames)
  935. {
  936. struct sk_buff_head *skb_list = &tid_agg_rx->reorder_buf[index];
  937. struct sk_buff *skb;
  938. struct ieee80211_rx_status *status;
  939. lockdep_assert_held(&tid_agg_rx->reorder_lock);
  940. if (skb_queue_empty(skb_list))
  941. goto no_frame;
  942. if (!ieee80211_rx_reorder_ready(tid_agg_rx, index)) {
  943. __skb_queue_purge(skb_list);
  944. goto no_frame;
  945. }
  946. /* release frames from the reorder ring buffer */
  947. tid_agg_rx->stored_mpdu_num--;
  948. while ((skb = __skb_dequeue(skb_list))) {
  949. status = IEEE80211_SKB_RXCB(skb);
  950. status->rx_flags |= IEEE80211_RX_DEFERRED_RELEASE;
  951. __skb_queue_tail(frames, skb);
  952. }
  953. no_frame:
  954. if (tid_agg_rx->reorder_buf_filtered)
  955. tid_agg_rx->reorder_buf_filtered &= ~BIT_ULL(index);
  956. tid_agg_rx->head_seq_num = ieee80211_sn_inc(tid_agg_rx->head_seq_num);
  957. }
  958. static void ieee80211_release_reorder_frames(struct ieee80211_sub_if_data *sdata,
  959. struct tid_ampdu_rx *tid_agg_rx,
  960. u16 head_seq_num,
  961. struct sk_buff_head *frames)
  962. {
  963. int index;
  964. lockdep_assert_held(&tid_agg_rx->reorder_lock);
  965. while (ieee80211_sn_less(tid_agg_rx->head_seq_num, head_seq_num)) {
  966. index = tid_agg_rx->head_seq_num % tid_agg_rx->buf_size;
  967. ieee80211_release_reorder_frame(sdata, tid_agg_rx, index,
  968. frames);
  969. }
  970. }
  971. /*
  972. * Timeout (in jiffies) for skb's that are waiting in the RX reorder buffer. If
  973. * the skb was added to the buffer longer than this time ago, the earlier
  974. * frames that have not yet been received are assumed to be lost and the skb
  975. * can be released for processing. This may also release other skb's from the
  976. * reorder buffer if there are no additional gaps between the frames.
  977. *
  978. * Callers must hold tid_agg_rx->reorder_lock.
  979. */
  980. #define HT_RX_REORDER_BUF_TIMEOUT (HZ / 10)
  981. static void ieee80211_sta_reorder_release(struct ieee80211_sub_if_data *sdata,
  982. struct tid_ampdu_rx *tid_agg_rx,
  983. struct sk_buff_head *frames)
  984. {
  985. int index, i, j;
  986. lockdep_assert_held(&tid_agg_rx->reorder_lock);
  987. /* release the buffer until next missing frame */
  988. index = tid_agg_rx->head_seq_num % tid_agg_rx->buf_size;
  989. if (!ieee80211_rx_reorder_ready(tid_agg_rx, index) &&
  990. tid_agg_rx->stored_mpdu_num) {
  991. /*
  992. * No buffers ready to be released, but check whether any
  993. * frames in the reorder buffer have timed out.
  994. */
  995. int skipped = 1;
  996. for (j = (index + 1) % tid_agg_rx->buf_size; j != index;
  997. j = (j + 1) % tid_agg_rx->buf_size) {
  998. if (!ieee80211_rx_reorder_ready(tid_agg_rx, j)) {
  999. skipped++;
  1000. continue;
  1001. }
  1002. if (skipped &&
  1003. !time_after(jiffies, tid_agg_rx->reorder_time[j] +
  1004. HT_RX_REORDER_BUF_TIMEOUT))
  1005. goto set_release_timer;
  1006. /* don't leave incomplete A-MSDUs around */
  1007. for (i = (index + 1) % tid_agg_rx->buf_size; i != j;
  1008. i = (i + 1) % tid_agg_rx->buf_size)
  1009. __skb_queue_purge(&tid_agg_rx->reorder_buf[i]);
  1010. ht_dbg_ratelimited(sdata,
  1011. "release an RX reorder frame due to timeout on earlier frames\n");
  1012. ieee80211_release_reorder_frame(sdata, tid_agg_rx, j,
  1013. frames);
  1014. /*
  1015. * Increment the head seq# also for the skipped slots.
  1016. */
  1017. tid_agg_rx->head_seq_num =
  1018. (tid_agg_rx->head_seq_num +
  1019. skipped) & IEEE80211_SN_MASK;
  1020. skipped = 0;
  1021. }
  1022. } else while (ieee80211_rx_reorder_ready(tid_agg_rx, index)) {
  1023. ieee80211_release_reorder_frame(sdata, tid_agg_rx, index,
  1024. frames);
  1025. index = tid_agg_rx->head_seq_num % tid_agg_rx->buf_size;
  1026. }
  1027. if (tid_agg_rx->stored_mpdu_num) {
  1028. j = index = tid_agg_rx->head_seq_num % tid_agg_rx->buf_size;
  1029. for (; j != (index - 1) % tid_agg_rx->buf_size;
  1030. j = (j + 1) % tid_agg_rx->buf_size) {
  1031. if (ieee80211_rx_reorder_ready(tid_agg_rx, j))
  1032. break;
  1033. }
  1034. set_release_timer:
  1035. if (!tid_agg_rx->removed)
  1036. mod_timer(&tid_agg_rx->reorder_timer,
  1037. tid_agg_rx->reorder_time[j] + 1 +
  1038. HT_RX_REORDER_BUF_TIMEOUT);
  1039. } else {
  1040. del_timer(&tid_agg_rx->reorder_timer);
  1041. }
  1042. }
  1043. /*
  1044. * As this function belongs to the RX path it must be under
  1045. * rcu_read_lock protection. It returns false if the frame
  1046. * can be processed immediately, true if it was consumed.
  1047. */
  1048. static bool ieee80211_sta_manage_reorder_buf(struct ieee80211_sub_if_data *sdata,
  1049. struct tid_ampdu_rx *tid_agg_rx,
  1050. struct sk_buff *skb,
  1051. struct sk_buff_head *frames)
  1052. {
  1053. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
  1054. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
  1055. u16 mpdu_seq_num = ieee80211_get_sn(hdr);
  1056. u16 head_seq_num, buf_size;
  1057. int index;
  1058. bool ret = true;
  1059. spin_lock(&tid_agg_rx->reorder_lock);
  1060. /*
  1061. * Offloaded BA sessions have no known starting sequence number so pick
  1062. * one from first Rxed frame for this tid after BA was started.
  1063. */
  1064. if (unlikely(tid_agg_rx->auto_seq)) {
  1065. tid_agg_rx->auto_seq = false;
  1066. tid_agg_rx->ssn = mpdu_seq_num;
  1067. tid_agg_rx->head_seq_num = mpdu_seq_num;
  1068. }
  1069. buf_size = tid_agg_rx->buf_size;
  1070. head_seq_num = tid_agg_rx->head_seq_num;
  1071. /*
  1072. * If the current MPDU's SN is smaller than the SSN, it shouldn't
  1073. * be reordered.
  1074. */
  1075. if (unlikely(!tid_agg_rx->started)) {
  1076. if (ieee80211_sn_less(mpdu_seq_num, head_seq_num)) {
  1077. ret = false;
  1078. goto out;
  1079. }
  1080. tid_agg_rx->started = true;
  1081. }
  1082. /* frame with out of date sequence number */
  1083. if (ieee80211_sn_less(mpdu_seq_num, head_seq_num)) {
  1084. dev_kfree_skb(skb);
  1085. goto out;
  1086. }
  1087. /*
  1088. * If frame the sequence number exceeds our buffering window
  1089. * size release some previous frames to make room for this one.
  1090. */
  1091. if (!ieee80211_sn_less(mpdu_seq_num, head_seq_num + buf_size)) {
  1092. head_seq_num = ieee80211_sn_inc(
  1093. ieee80211_sn_sub(mpdu_seq_num, buf_size));
  1094. /* release stored frames up to new head to stack */
  1095. ieee80211_release_reorder_frames(sdata, tid_agg_rx,
  1096. head_seq_num, frames);
  1097. }
  1098. /* Now the new frame is always in the range of the reordering buffer */
  1099. index = mpdu_seq_num % tid_agg_rx->buf_size;
  1100. /* check if we already stored this frame */
  1101. if (ieee80211_rx_reorder_ready(tid_agg_rx, index)) {
  1102. dev_kfree_skb(skb);
  1103. goto out;
  1104. }
  1105. /*
  1106. * If the current MPDU is in the right order and nothing else
  1107. * is stored we can process it directly, no need to buffer it.
  1108. * If it is first but there's something stored, we may be able
  1109. * to release frames after this one.
  1110. */
  1111. if (mpdu_seq_num == tid_agg_rx->head_seq_num &&
  1112. tid_agg_rx->stored_mpdu_num == 0) {
  1113. if (!(status->flag & RX_FLAG_AMSDU_MORE))
  1114. tid_agg_rx->head_seq_num =
  1115. ieee80211_sn_inc(tid_agg_rx->head_seq_num);
  1116. ret = false;
  1117. goto out;
  1118. }
  1119. /* put the frame in the reordering buffer */
  1120. __skb_queue_tail(&tid_agg_rx->reorder_buf[index], skb);
  1121. if (!(status->flag & RX_FLAG_AMSDU_MORE)) {
  1122. tid_agg_rx->reorder_time[index] = jiffies;
  1123. tid_agg_rx->stored_mpdu_num++;
  1124. ieee80211_sta_reorder_release(sdata, tid_agg_rx, frames);
  1125. }
  1126. out:
  1127. spin_unlock(&tid_agg_rx->reorder_lock);
  1128. return ret;
  1129. }
  1130. /*
  1131. * Reorder MPDUs from A-MPDUs, keeping them on a buffer. Returns
  1132. * true if the MPDU was buffered, false if it should be processed.
  1133. */
  1134. static void ieee80211_rx_reorder_ampdu(struct ieee80211_rx_data *rx,
  1135. struct sk_buff_head *frames)
  1136. {
  1137. struct sk_buff *skb = rx->skb;
  1138. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *) skb->data;
  1139. struct sta_info *sta = rx->sta;
  1140. struct tid_ampdu_rx *tid_agg_rx;
  1141. u16 sc;
  1142. u8 tid, ack_policy;
  1143. if (!ieee80211_is_data_qos(hdr->frame_control) ||
  1144. is_multicast_ether_addr(hdr->addr1))
  1145. goto dont_reorder;
  1146. /*
  1147. * filter the QoS data rx stream according to
  1148. * STA/TID and check if this STA/TID is on aggregation
  1149. */
  1150. if (!sta)
  1151. goto dont_reorder;
  1152. ack_policy = *ieee80211_get_qos_ctl(hdr) &
  1153. IEEE80211_QOS_CTL_ACK_POLICY_MASK;
  1154. tid = ieee80211_get_tid(hdr);
  1155. tid_agg_rx = rcu_dereference(sta->ampdu_mlme.tid_rx[tid]);
  1156. if (!tid_agg_rx) {
  1157. if (ack_policy == IEEE80211_QOS_CTL_ACK_POLICY_BLOCKACK &&
  1158. !test_bit(tid, rx->sta->ampdu_mlme.agg_session_valid) &&
  1159. !test_and_set_bit(tid, rx->sta->ampdu_mlme.unexpected_agg))
  1160. ieee80211_send_delba(rx->sdata, rx->sta->sta.addr, tid,
  1161. WLAN_BACK_RECIPIENT,
  1162. WLAN_REASON_QSTA_REQUIRE_SETUP);
  1163. goto dont_reorder;
  1164. }
  1165. /* qos null data frames are excluded */
  1166. if (unlikely(hdr->frame_control & cpu_to_le16(IEEE80211_STYPE_NULLFUNC)))
  1167. goto dont_reorder;
  1168. /* not part of a BA session */
  1169. if (ack_policy == IEEE80211_QOS_CTL_ACK_POLICY_NOACK)
  1170. goto dont_reorder;
  1171. /* new, potentially un-ordered, ampdu frame - process it */
  1172. /* reset session timer */
  1173. if (tid_agg_rx->timeout)
  1174. tid_agg_rx->last_rx = jiffies;
  1175. /* if this mpdu is fragmented - terminate rx aggregation session */
  1176. sc = le16_to_cpu(hdr->seq_ctrl);
  1177. if (sc & IEEE80211_SCTL_FRAG) {
  1178. ieee80211_queue_skb_to_iface(rx->sdata, rx->link_id, NULL, skb);
  1179. return;
  1180. }
  1181. /*
  1182. * No locking needed -- we will only ever process one
  1183. * RX packet at a time, and thus own tid_agg_rx. All
  1184. * other code manipulating it needs to (and does) make
  1185. * sure that we cannot get to it any more before doing
  1186. * anything with it.
  1187. */
  1188. if (ieee80211_sta_manage_reorder_buf(rx->sdata, tid_agg_rx, skb,
  1189. frames))
  1190. return;
  1191. dont_reorder:
  1192. __skb_queue_tail(frames, skb);
  1193. }
  1194. static ieee80211_rx_result debug_noinline
  1195. ieee80211_rx_h_check_dup(struct ieee80211_rx_data *rx)
  1196. {
  1197. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
  1198. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
  1199. if (status->flag & RX_FLAG_DUP_VALIDATED)
  1200. return RX_CONTINUE;
  1201. /*
  1202. * Drop duplicate 802.11 retransmissions
  1203. * (IEEE 802.11-2012: 9.3.2.10 "Duplicate detection and recovery")
  1204. */
  1205. if (rx->skb->len < 24)
  1206. return RX_CONTINUE;
  1207. if (ieee80211_is_ctl(hdr->frame_control) ||
  1208. ieee80211_is_any_nullfunc(hdr->frame_control))
  1209. return RX_CONTINUE;
  1210. if (!rx->sta)
  1211. return RX_CONTINUE;
  1212. if (unlikely(is_multicast_ether_addr(hdr->addr1))) {
  1213. struct ieee80211_sub_if_data *sdata = rx->sdata;
  1214. u16 sn = ieee80211_get_sn(hdr);
  1215. if (!ieee80211_is_data_present(hdr->frame_control))
  1216. return RX_CONTINUE;
  1217. if (!ieee80211_vif_is_mld(&sdata->vif) ||
  1218. sdata->vif.type != NL80211_IFTYPE_STATION)
  1219. return RX_CONTINUE;
  1220. if (sdata->u.mgd.mcast_seq_last != IEEE80211_SN_MODULO &&
  1221. ieee80211_sn_less_eq(sn, sdata->u.mgd.mcast_seq_last))
  1222. return RX_DROP_U_DUP;
  1223. sdata->u.mgd.mcast_seq_last = sn;
  1224. return RX_CONTINUE;
  1225. }
  1226. if (unlikely(ieee80211_has_retry(hdr->frame_control) &&
  1227. rx->sta->last_seq_ctrl[rx->seqno_idx] == hdr->seq_ctrl)) {
  1228. I802_DEBUG_INC(rx->local->dot11FrameDuplicateCount);
  1229. rx->link_sta->rx_stats.num_duplicates++;
  1230. return RX_DROP_U_DUP;
  1231. } else if (!(status->flag & RX_FLAG_AMSDU_MORE)) {
  1232. rx->sta->last_seq_ctrl[rx->seqno_idx] = hdr->seq_ctrl;
  1233. }
  1234. return RX_CONTINUE;
  1235. }
  1236. static ieee80211_rx_result debug_noinline
  1237. ieee80211_rx_h_check(struct ieee80211_rx_data *rx)
  1238. {
  1239. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
  1240. /* Drop disallowed frame classes based on STA auth/assoc state;
  1241. * IEEE 802.11, Chap 5.5.
  1242. *
  1243. * mac80211 filters only based on association state, i.e. it drops
  1244. * Class 3 frames from not associated stations. hostapd sends
  1245. * deauth/disassoc frames when needed. In addition, hostapd is
  1246. * responsible for filtering on both auth and assoc states.
  1247. */
  1248. if (ieee80211_vif_is_mesh(&rx->sdata->vif))
  1249. return ieee80211_rx_mesh_check(rx);
  1250. if (unlikely((ieee80211_is_data(hdr->frame_control) ||
  1251. ieee80211_is_pspoll(hdr->frame_control)) &&
  1252. rx->sdata->vif.type != NL80211_IFTYPE_ADHOC &&
  1253. rx->sdata->vif.type != NL80211_IFTYPE_OCB &&
  1254. (!rx->sta || !test_sta_flag(rx->sta, WLAN_STA_ASSOC)))) {
  1255. /*
  1256. * accept port control frames from the AP even when it's not
  1257. * yet marked ASSOC to prevent a race where we don't set the
  1258. * assoc bit quickly enough before it sends the first frame
  1259. */
  1260. if (rx->sta && rx->sdata->vif.type == NL80211_IFTYPE_STATION &&
  1261. ieee80211_is_data_present(hdr->frame_control)) {
  1262. unsigned int hdrlen;
  1263. __be16 ethertype;
  1264. hdrlen = ieee80211_hdrlen(hdr->frame_control);
  1265. if (rx->skb->len < hdrlen + 8)
  1266. return RX_DROP_MONITOR;
  1267. skb_copy_bits(rx->skb, hdrlen + 6, &ethertype, 2);
  1268. if (ethertype == rx->sdata->control_port_protocol)
  1269. return RX_CONTINUE;
  1270. }
  1271. if (rx->sdata->vif.type == NL80211_IFTYPE_AP &&
  1272. cfg80211_rx_spurious_frame(rx->sdata->dev,
  1273. hdr->addr2,
  1274. GFP_ATOMIC))
  1275. return RX_DROP_U_SPURIOUS;
  1276. return RX_DROP_MONITOR;
  1277. }
  1278. return RX_CONTINUE;
  1279. }
  1280. static ieee80211_rx_result debug_noinline
  1281. ieee80211_rx_h_check_more_data(struct ieee80211_rx_data *rx)
  1282. {
  1283. struct ieee80211_local *local;
  1284. struct ieee80211_hdr *hdr;
  1285. struct sk_buff *skb;
  1286. local = rx->local;
  1287. skb = rx->skb;
  1288. hdr = (struct ieee80211_hdr *) skb->data;
  1289. if (!local->pspolling)
  1290. return RX_CONTINUE;
  1291. if (!ieee80211_has_fromds(hdr->frame_control))
  1292. /* this is not from AP */
  1293. return RX_CONTINUE;
  1294. if (!ieee80211_is_data(hdr->frame_control))
  1295. return RX_CONTINUE;
  1296. if (!ieee80211_has_moredata(hdr->frame_control)) {
  1297. /* AP has no more frames buffered for us */
  1298. local->pspolling = false;
  1299. return RX_CONTINUE;
  1300. }
  1301. /* more data bit is set, let's request a new frame from the AP */
  1302. ieee80211_send_pspoll(local, rx->sdata);
  1303. return RX_CONTINUE;
  1304. }
  1305. static void sta_ps_start(struct sta_info *sta)
  1306. {
  1307. struct ieee80211_sub_if_data *sdata = sta->sdata;
  1308. struct ieee80211_local *local = sdata->local;
  1309. struct ps_data *ps;
  1310. int tid;
  1311. if (sta->sdata->vif.type == NL80211_IFTYPE_AP ||
  1312. sta->sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
  1313. ps = &sdata->bss->ps;
  1314. else
  1315. return;
  1316. atomic_inc(&ps->num_sta_ps);
  1317. set_sta_flag(sta, WLAN_STA_PS_STA);
  1318. if (!ieee80211_hw_check(&local->hw, AP_LINK_PS))
  1319. drv_sta_notify(local, sdata, STA_NOTIFY_SLEEP, &sta->sta);
  1320. ps_dbg(sdata, "STA %pM aid %d enters power save mode\n",
  1321. sta->sta.addr, sta->sta.aid);
  1322. ieee80211_clear_fast_xmit(sta);
  1323. for (tid = 0; tid < IEEE80211_NUM_TIDS; tid++) {
  1324. struct ieee80211_txq *txq = sta->sta.txq[tid];
  1325. struct txq_info *txqi = to_txq_info(txq);
  1326. spin_lock(&local->active_txq_lock[txq->ac]);
  1327. if (!list_empty(&txqi->schedule_order))
  1328. list_del_init(&txqi->schedule_order);
  1329. spin_unlock(&local->active_txq_lock[txq->ac]);
  1330. if (txq_has_queue(txq))
  1331. set_bit(tid, &sta->txq_buffered_tids);
  1332. else
  1333. clear_bit(tid, &sta->txq_buffered_tids);
  1334. }
  1335. }
  1336. static void sta_ps_end(struct sta_info *sta)
  1337. {
  1338. ps_dbg(sta->sdata, "STA %pM aid %d exits power save mode\n",
  1339. sta->sta.addr, sta->sta.aid);
  1340. if (test_sta_flag(sta, WLAN_STA_PS_DRIVER)) {
  1341. /*
  1342. * Clear the flag only if the other one is still set
  1343. * so that the TX path won't start TX'ing new frames
  1344. * directly ... In the case that the driver flag isn't
  1345. * set ieee80211_sta_ps_deliver_wakeup() will clear it.
  1346. */
  1347. clear_sta_flag(sta, WLAN_STA_PS_STA);
  1348. ps_dbg(sta->sdata, "STA %pM aid %d driver-ps-blocked\n",
  1349. sta->sta.addr, sta->sta.aid);
  1350. return;
  1351. }
  1352. set_sta_flag(sta, WLAN_STA_PS_DELIVER);
  1353. clear_sta_flag(sta, WLAN_STA_PS_STA);
  1354. ieee80211_sta_ps_deliver_wakeup(sta);
  1355. }
  1356. int ieee80211_sta_ps_transition(struct ieee80211_sta *pubsta, bool start)
  1357. {
  1358. struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
  1359. bool in_ps;
  1360. WARN_ON(!ieee80211_hw_check(&sta->local->hw, AP_LINK_PS));
  1361. /* Don't let the same PS state be set twice */
  1362. in_ps = test_sta_flag(sta, WLAN_STA_PS_STA);
  1363. if ((start && in_ps) || (!start && !in_ps))
  1364. return -EINVAL;
  1365. if (start)
  1366. sta_ps_start(sta);
  1367. else
  1368. sta_ps_end(sta);
  1369. return 0;
  1370. }
  1371. EXPORT_SYMBOL(ieee80211_sta_ps_transition);
  1372. void ieee80211_sta_pspoll(struct ieee80211_sta *pubsta)
  1373. {
  1374. struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
  1375. if (test_sta_flag(sta, WLAN_STA_SP))
  1376. return;
  1377. if (!test_sta_flag(sta, WLAN_STA_PS_DRIVER))
  1378. ieee80211_sta_ps_deliver_poll_response(sta);
  1379. else
  1380. set_sta_flag(sta, WLAN_STA_PSPOLL);
  1381. }
  1382. EXPORT_SYMBOL(ieee80211_sta_pspoll);
  1383. void ieee80211_sta_uapsd_trigger(struct ieee80211_sta *pubsta, u8 tid)
  1384. {
  1385. struct sta_info *sta = container_of(pubsta, struct sta_info, sta);
  1386. int ac = ieee80211_ac_from_tid(tid);
  1387. /*
  1388. * If this AC is not trigger-enabled do nothing unless the
  1389. * driver is calling us after it already checked.
  1390. *
  1391. * NB: This could/should check a separate bitmap of trigger-
  1392. * enabled queues, but for now we only implement uAPSD w/o
  1393. * TSPEC changes to the ACs, so they're always the same.
  1394. */
  1395. if (!(sta->sta.uapsd_queues & ieee80211_ac_to_qos_mask[ac]) &&
  1396. tid != IEEE80211_NUM_TIDS)
  1397. return;
  1398. /* if we are in a service period, do nothing */
  1399. if (test_sta_flag(sta, WLAN_STA_SP))
  1400. return;
  1401. if (!test_sta_flag(sta, WLAN_STA_PS_DRIVER))
  1402. ieee80211_sta_ps_deliver_uapsd(sta);
  1403. else
  1404. set_sta_flag(sta, WLAN_STA_UAPSD);
  1405. }
  1406. EXPORT_SYMBOL(ieee80211_sta_uapsd_trigger);
  1407. static ieee80211_rx_result debug_noinline
  1408. ieee80211_rx_h_uapsd_and_pspoll(struct ieee80211_rx_data *rx)
  1409. {
  1410. struct ieee80211_sub_if_data *sdata = rx->sdata;
  1411. struct ieee80211_hdr *hdr = (void *)rx->skb->data;
  1412. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
  1413. if (!rx->sta)
  1414. return RX_CONTINUE;
  1415. if (sdata->vif.type != NL80211_IFTYPE_AP &&
  1416. sdata->vif.type != NL80211_IFTYPE_AP_VLAN)
  1417. return RX_CONTINUE;
  1418. /*
  1419. * The device handles station powersave, so don't do anything about
  1420. * uAPSD and PS-Poll frames (the latter shouldn't even come up from
  1421. * it to mac80211 since they're handled.)
  1422. */
  1423. if (ieee80211_hw_check(&sdata->local->hw, AP_LINK_PS))
  1424. return RX_CONTINUE;
  1425. /*
  1426. * Don't do anything if the station isn't already asleep. In
  1427. * the uAPSD case, the station will probably be marked asleep,
  1428. * in the PS-Poll case the station must be confused ...
  1429. */
  1430. if (!test_sta_flag(rx->sta, WLAN_STA_PS_STA))
  1431. return RX_CONTINUE;
  1432. if (unlikely(ieee80211_is_pspoll(hdr->frame_control))) {
  1433. ieee80211_sta_pspoll(&rx->sta->sta);
  1434. /* Free PS Poll skb here instead of returning RX_DROP that would
  1435. * count as an dropped frame. */
  1436. dev_kfree_skb(rx->skb);
  1437. return RX_QUEUED;
  1438. } else if (!ieee80211_has_morefrags(hdr->frame_control) &&
  1439. !(status->rx_flags & IEEE80211_RX_DEFERRED_RELEASE) &&
  1440. ieee80211_has_pm(hdr->frame_control) &&
  1441. (ieee80211_is_data_qos(hdr->frame_control) ||
  1442. ieee80211_is_qos_nullfunc(hdr->frame_control))) {
  1443. u8 tid = ieee80211_get_tid(hdr);
  1444. ieee80211_sta_uapsd_trigger(&rx->sta->sta, tid);
  1445. }
  1446. return RX_CONTINUE;
  1447. }
  1448. static ieee80211_rx_result debug_noinline
  1449. ieee80211_rx_h_sta_process(struct ieee80211_rx_data *rx)
  1450. {
  1451. struct sta_info *sta = rx->sta;
  1452. struct link_sta_info *link_sta = rx->link_sta;
  1453. struct sk_buff *skb = rx->skb;
  1454. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
  1455. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
  1456. int i;
  1457. if (!sta || !link_sta)
  1458. return RX_CONTINUE;
  1459. /*
  1460. * Update last_rx only for IBSS packets which are for the current
  1461. * BSSID and for station already AUTHORIZED to avoid keeping the
  1462. * current IBSS network alive in cases where other STAs start
  1463. * using different BSSID. This will also give the station another
  1464. * chance to restart the authentication/authorization in case
  1465. * something went wrong the first time.
  1466. */
  1467. if (rx->sdata->vif.type == NL80211_IFTYPE_ADHOC) {
  1468. u8 *bssid = ieee80211_get_bssid(hdr, rx->skb->len,
  1469. NL80211_IFTYPE_ADHOC);
  1470. if (ether_addr_equal(bssid, rx->sdata->u.ibss.bssid) &&
  1471. test_sta_flag(sta, WLAN_STA_AUTHORIZED)) {
  1472. link_sta->rx_stats.last_rx = jiffies;
  1473. if (ieee80211_is_data_present(hdr->frame_control) &&
  1474. !is_multicast_ether_addr(hdr->addr1))
  1475. link_sta->rx_stats.last_rate =
  1476. sta_stats_encode_rate(status);
  1477. }
  1478. } else if (rx->sdata->vif.type == NL80211_IFTYPE_OCB) {
  1479. link_sta->rx_stats.last_rx = jiffies;
  1480. } else if (!ieee80211_is_s1g_beacon(hdr->frame_control) &&
  1481. !is_multicast_ether_addr(hdr->addr1)) {
  1482. /*
  1483. * Mesh beacons will update last_rx when if they are found to
  1484. * match the current local configuration when processed.
  1485. */
  1486. link_sta->rx_stats.last_rx = jiffies;
  1487. if (ieee80211_is_data_present(hdr->frame_control))
  1488. link_sta->rx_stats.last_rate = sta_stats_encode_rate(status);
  1489. }
  1490. link_sta->rx_stats.fragments++;
  1491. u64_stats_update_begin(&link_sta->rx_stats.syncp);
  1492. link_sta->rx_stats.bytes += rx->skb->len;
  1493. u64_stats_update_end(&link_sta->rx_stats.syncp);
  1494. if (!(status->flag & RX_FLAG_NO_SIGNAL_VAL)) {
  1495. link_sta->rx_stats.last_signal = status->signal;
  1496. ewma_signal_add(&link_sta->rx_stats_avg.signal,
  1497. -status->signal);
  1498. }
  1499. if (status->chains) {
  1500. link_sta->rx_stats.chains = status->chains;
  1501. for (i = 0; i < ARRAY_SIZE(status->chain_signal); i++) {
  1502. int signal = status->chain_signal[i];
  1503. if (!(status->chains & BIT(i)))
  1504. continue;
  1505. link_sta->rx_stats.chain_signal_last[i] = signal;
  1506. ewma_signal_add(&link_sta->rx_stats_avg.chain_signal[i],
  1507. -signal);
  1508. }
  1509. }
  1510. if (ieee80211_is_s1g_beacon(hdr->frame_control))
  1511. return RX_CONTINUE;
  1512. /*
  1513. * Change STA power saving mode only at the end of a frame
  1514. * exchange sequence, and only for a data or management
  1515. * frame as specified in IEEE 802.11-2016 11.2.3.2
  1516. */
  1517. if (!ieee80211_hw_check(&sta->local->hw, AP_LINK_PS) &&
  1518. !ieee80211_has_morefrags(hdr->frame_control) &&
  1519. !is_multicast_ether_addr(hdr->addr1) &&
  1520. (ieee80211_is_mgmt(hdr->frame_control) ||
  1521. ieee80211_is_data(hdr->frame_control)) &&
  1522. !(status->rx_flags & IEEE80211_RX_DEFERRED_RELEASE) &&
  1523. (rx->sdata->vif.type == NL80211_IFTYPE_AP ||
  1524. rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN)) {
  1525. if (test_sta_flag(sta, WLAN_STA_PS_STA)) {
  1526. if (!ieee80211_has_pm(hdr->frame_control))
  1527. sta_ps_end(sta);
  1528. } else {
  1529. if (ieee80211_has_pm(hdr->frame_control))
  1530. sta_ps_start(sta);
  1531. }
  1532. }
  1533. /* mesh power save support */
  1534. if (ieee80211_vif_is_mesh(&rx->sdata->vif))
  1535. ieee80211_mps_rx_h_sta_process(sta, hdr);
  1536. /*
  1537. * Drop (qos-)data::nullfunc frames silently, since they
  1538. * are used only to control station power saving mode.
  1539. */
  1540. if (ieee80211_is_any_nullfunc(hdr->frame_control)) {
  1541. I802_DEBUG_INC(rx->local->rx_handlers_drop_nullfunc);
  1542. /*
  1543. * If we receive a 4-addr nullfunc frame from a STA
  1544. * that was not moved to a 4-addr STA vlan yet send
  1545. * the event to userspace and for older hostapd drop
  1546. * the frame to the monitor interface.
  1547. */
  1548. if (ieee80211_has_a4(hdr->frame_control) &&
  1549. (rx->sdata->vif.type == NL80211_IFTYPE_AP ||
  1550. (rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
  1551. !rx->sdata->u.vlan.sta))) {
  1552. if (!test_and_set_sta_flag(sta, WLAN_STA_4ADDR_EVENT))
  1553. cfg80211_rx_unexpected_4addr_frame(
  1554. rx->sdata->dev, sta->sta.addr,
  1555. GFP_ATOMIC);
  1556. return RX_DROP_M_UNEXPECTED_4ADDR_FRAME;
  1557. }
  1558. /*
  1559. * Update counter and free packet here to avoid
  1560. * counting this as a dropped packed.
  1561. */
  1562. link_sta->rx_stats.packets++;
  1563. dev_kfree_skb(rx->skb);
  1564. return RX_QUEUED;
  1565. }
  1566. return RX_CONTINUE;
  1567. } /* ieee80211_rx_h_sta_process */
  1568. static struct ieee80211_key *
  1569. ieee80211_rx_get_bigtk(struct ieee80211_rx_data *rx, int idx)
  1570. {
  1571. struct ieee80211_key *key = NULL;
  1572. int idx2;
  1573. /* Make sure key gets set if either BIGTK key index is set so that
  1574. * ieee80211_drop_unencrypted_mgmt() can properly drop both unprotected
  1575. * Beacon frames and Beacon frames that claim to use another BIGTK key
  1576. * index (i.e., a key that we do not have).
  1577. */
  1578. if (idx < 0) {
  1579. idx = NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS;
  1580. idx2 = idx + 1;
  1581. } else {
  1582. if (idx == NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS)
  1583. idx2 = idx + 1;
  1584. else
  1585. idx2 = idx - 1;
  1586. }
  1587. if (rx->link_sta)
  1588. key = rcu_dereference(rx->link_sta->gtk[idx]);
  1589. if (!key)
  1590. key = rcu_dereference(rx->link->gtk[idx]);
  1591. if (!key && rx->link_sta)
  1592. key = rcu_dereference(rx->link_sta->gtk[idx2]);
  1593. if (!key)
  1594. key = rcu_dereference(rx->link->gtk[idx2]);
  1595. return key;
  1596. }
  1597. static ieee80211_rx_result debug_noinline
  1598. ieee80211_rx_h_decrypt(struct ieee80211_rx_data *rx)
  1599. {
  1600. struct sk_buff *skb = rx->skb;
  1601. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
  1602. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
  1603. int keyidx;
  1604. ieee80211_rx_result result = RX_DROP_U_DECRYPT_FAIL;
  1605. struct ieee80211_key *sta_ptk = NULL;
  1606. struct ieee80211_key *ptk_idx = NULL;
  1607. int mmie_keyidx = -1;
  1608. __le16 fc;
  1609. if (ieee80211_is_ext(hdr->frame_control))
  1610. return RX_CONTINUE;
  1611. /*
  1612. * Key selection 101
  1613. *
  1614. * There are five types of keys:
  1615. * - GTK (group keys)
  1616. * - IGTK (group keys for management frames)
  1617. * - BIGTK (group keys for Beacon frames)
  1618. * - PTK (pairwise keys)
  1619. * - STK (station-to-station pairwise keys)
  1620. *
  1621. * When selecting a key, we have to distinguish between multicast
  1622. * (including broadcast) and unicast frames, the latter can only
  1623. * use PTKs and STKs while the former always use GTKs, IGTKs, and
  1624. * BIGTKs. Unless, of course, actual WEP keys ("pre-RSNA") are used,
  1625. * then unicast frames can also use key indices like GTKs. Hence, if we
  1626. * don't have a PTK/STK we check the key index for a WEP key.
  1627. *
  1628. * Note that in a regular BSS, multicast frames are sent by the
  1629. * AP only, associated stations unicast the frame to the AP first
  1630. * which then multicasts it on their behalf.
  1631. *
  1632. * There is also a slight problem in IBSS mode: GTKs are negotiated
  1633. * with each station, that is something we don't currently handle.
  1634. * The spec seems to expect that one negotiates the same key with
  1635. * every station but there's no such requirement; VLANs could be
  1636. * possible.
  1637. */
  1638. /* start without a key */
  1639. rx->key = NULL;
  1640. fc = hdr->frame_control;
  1641. if (rx->sta) {
  1642. int keyid = rx->sta->ptk_idx;
  1643. sta_ptk = rcu_dereference(rx->sta->ptk[keyid]);
  1644. if (ieee80211_has_protected(fc) &&
  1645. !(status->flag & RX_FLAG_IV_STRIPPED)) {
  1646. keyid = ieee80211_get_keyid(rx->skb);
  1647. if (unlikely(keyid < 0))
  1648. return RX_DROP_U_NO_KEY_ID;
  1649. ptk_idx = rcu_dereference(rx->sta->ptk[keyid]);
  1650. }
  1651. }
  1652. if (!ieee80211_has_protected(fc))
  1653. mmie_keyidx = ieee80211_get_mmie_keyidx(rx->skb);
  1654. if (!is_multicast_ether_addr(hdr->addr1) && sta_ptk) {
  1655. rx->key = ptk_idx ? ptk_idx : sta_ptk;
  1656. if ((status->flag & RX_FLAG_DECRYPTED) &&
  1657. (status->flag & RX_FLAG_IV_STRIPPED))
  1658. return RX_CONTINUE;
  1659. /* Skip decryption if the frame is not protected. */
  1660. if (!ieee80211_has_protected(fc))
  1661. return RX_CONTINUE;
  1662. } else if (mmie_keyidx >= 0 && ieee80211_is_beacon(fc)) {
  1663. /* Broadcast/multicast robust management frame / BIP */
  1664. if ((status->flag & RX_FLAG_DECRYPTED) &&
  1665. (status->flag & RX_FLAG_IV_STRIPPED))
  1666. return RX_CONTINUE;
  1667. if (mmie_keyidx < NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS ||
  1668. mmie_keyidx >= NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS +
  1669. NUM_DEFAULT_BEACON_KEYS) {
  1670. if (rx->sdata->dev)
  1671. cfg80211_rx_unprot_mlme_mgmt(rx->sdata->dev,
  1672. skb->data,
  1673. skb->len);
  1674. return RX_DROP_M_BAD_BCN_KEYIDX;
  1675. }
  1676. rx->key = ieee80211_rx_get_bigtk(rx, mmie_keyidx);
  1677. if (!rx->key)
  1678. return RX_CONTINUE; /* Beacon protection not in use */
  1679. } else if (mmie_keyidx >= 0) {
  1680. /* Broadcast/multicast robust management frame / BIP */
  1681. if ((status->flag & RX_FLAG_DECRYPTED) &&
  1682. (status->flag & RX_FLAG_IV_STRIPPED))
  1683. return RX_CONTINUE;
  1684. if (mmie_keyidx < NUM_DEFAULT_KEYS ||
  1685. mmie_keyidx >= NUM_DEFAULT_KEYS + NUM_DEFAULT_MGMT_KEYS)
  1686. return RX_DROP_M_BAD_MGMT_KEYIDX; /* unexpected BIP keyidx */
  1687. if (rx->link_sta) {
  1688. if (ieee80211_is_group_privacy_action(skb) &&
  1689. test_sta_flag(rx->sta, WLAN_STA_MFP))
  1690. return RX_DROP_MONITOR;
  1691. rx->key = rcu_dereference(rx->link_sta->gtk[mmie_keyidx]);
  1692. }
  1693. if (!rx->key)
  1694. rx->key = rcu_dereference(rx->link->gtk[mmie_keyidx]);
  1695. } else if (!ieee80211_has_protected(fc)) {
  1696. /*
  1697. * The frame was not protected, so skip decryption. However, we
  1698. * need to set rx->key if there is a key that could have been
  1699. * used so that the frame may be dropped if encryption would
  1700. * have been expected.
  1701. */
  1702. struct ieee80211_key *key = NULL;
  1703. int i;
  1704. if (ieee80211_is_beacon(fc)) {
  1705. key = ieee80211_rx_get_bigtk(rx, -1);
  1706. } else if (ieee80211_is_mgmt(fc) &&
  1707. is_multicast_ether_addr(hdr->addr1)) {
  1708. key = rcu_dereference(rx->link->default_mgmt_key);
  1709. } else {
  1710. if (rx->link_sta) {
  1711. for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
  1712. key = rcu_dereference(rx->link_sta->gtk[i]);
  1713. if (key)
  1714. break;
  1715. }
  1716. }
  1717. if (!key) {
  1718. for (i = 0; i < NUM_DEFAULT_KEYS; i++) {
  1719. key = rcu_dereference(rx->link->gtk[i]);
  1720. if (key)
  1721. break;
  1722. }
  1723. }
  1724. }
  1725. if (key)
  1726. rx->key = key;
  1727. return RX_CONTINUE;
  1728. } else {
  1729. /*
  1730. * The device doesn't give us the IV so we won't be
  1731. * able to look up the key. That's ok though, we
  1732. * don't need to decrypt the frame, we just won't
  1733. * be able to keep statistics accurate.
  1734. * Except for key threshold notifications, should
  1735. * we somehow allow the driver to tell us which key
  1736. * the hardware used if this flag is set?
  1737. */
  1738. if ((status->flag & RX_FLAG_DECRYPTED) &&
  1739. (status->flag & RX_FLAG_IV_STRIPPED))
  1740. return RX_CONTINUE;
  1741. keyidx = ieee80211_get_keyid(rx->skb);
  1742. if (unlikely(keyidx < 0))
  1743. return RX_DROP_U_NO_KEY_ID;
  1744. /* check per-station GTK first, if multicast packet */
  1745. if (is_multicast_ether_addr(hdr->addr1) && rx->link_sta)
  1746. rx->key = rcu_dereference(rx->link_sta->gtk[keyidx]);
  1747. /* if not found, try default key */
  1748. if (!rx->key) {
  1749. if (is_multicast_ether_addr(hdr->addr1))
  1750. rx->key = rcu_dereference(rx->link->gtk[keyidx]);
  1751. if (!rx->key)
  1752. rx->key = rcu_dereference(rx->sdata->keys[keyidx]);
  1753. /*
  1754. * RSNA-protected unicast frames should always be
  1755. * sent with pairwise or station-to-station keys,
  1756. * but for WEP we allow using a key index as well.
  1757. */
  1758. if (rx->key &&
  1759. rx->key->conf.cipher != WLAN_CIPHER_SUITE_WEP40 &&
  1760. rx->key->conf.cipher != WLAN_CIPHER_SUITE_WEP104 &&
  1761. !is_multicast_ether_addr(hdr->addr1))
  1762. rx->key = NULL;
  1763. }
  1764. }
  1765. if (rx->key) {
  1766. if (unlikely(rx->key->flags & KEY_FLAG_TAINTED))
  1767. return RX_DROP_MONITOR;
  1768. /* TODO: add threshold stuff again */
  1769. } else {
  1770. return RX_DROP_MONITOR;
  1771. }
  1772. switch (rx->key->conf.cipher) {
  1773. case WLAN_CIPHER_SUITE_WEP40:
  1774. case WLAN_CIPHER_SUITE_WEP104:
  1775. result = ieee80211_crypto_wep_decrypt(rx);
  1776. break;
  1777. case WLAN_CIPHER_SUITE_TKIP:
  1778. result = ieee80211_crypto_tkip_decrypt(rx);
  1779. break;
  1780. case WLAN_CIPHER_SUITE_CCMP:
  1781. result = ieee80211_crypto_ccmp_decrypt(
  1782. rx, IEEE80211_CCMP_MIC_LEN);
  1783. break;
  1784. case WLAN_CIPHER_SUITE_CCMP_256:
  1785. result = ieee80211_crypto_ccmp_decrypt(
  1786. rx, IEEE80211_CCMP_256_MIC_LEN);
  1787. break;
  1788. case WLAN_CIPHER_SUITE_AES_CMAC:
  1789. result = ieee80211_crypto_aes_cmac_decrypt(rx);
  1790. break;
  1791. case WLAN_CIPHER_SUITE_BIP_CMAC_256:
  1792. result = ieee80211_crypto_aes_cmac_256_decrypt(rx);
  1793. break;
  1794. case WLAN_CIPHER_SUITE_BIP_GMAC_128:
  1795. case WLAN_CIPHER_SUITE_BIP_GMAC_256:
  1796. result = ieee80211_crypto_aes_gmac_decrypt(rx);
  1797. break;
  1798. case WLAN_CIPHER_SUITE_GCMP:
  1799. case WLAN_CIPHER_SUITE_GCMP_256:
  1800. result = ieee80211_crypto_gcmp_decrypt(rx);
  1801. break;
  1802. default:
  1803. result = RX_DROP_U_BAD_CIPHER;
  1804. }
  1805. /* the hdr variable is invalid after the decrypt handlers */
  1806. /* either the frame has been decrypted or will be dropped */
  1807. status->flag |= RX_FLAG_DECRYPTED;
  1808. if (unlikely(ieee80211_is_beacon(fc) && RX_RES_IS_UNUSABLE(result) &&
  1809. rx->sdata->dev))
  1810. cfg80211_rx_unprot_mlme_mgmt(rx->sdata->dev,
  1811. skb->data, skb->len);
  1812. return result;
  1813. }
  1814. void ieee80211_init_frag_cache(struct ieee80211_fragment_cache *cache)
  1815. {
  1816. int i;
  1817. for (i = 0; i < ARRAY_SIZE(cache->entries); i++)
  1818. skb_queue_head_init(&cache->entries[i].skb_list);
  1819. }
  1820. void ieee80211_destroy_frag_cache(struct ieee80211_fragment_cache *cache)
  1821. {
  1822. int i;
  1823. for (i = 0; i < ARRAY_SIZE(cache->entries); i++)
  1824. __skb_queue_purge(&cache->entries[i].skb_list);
  1825. }
  1826. static inline struct ieee80211_fragment_entry *
  1827. ieee80211_reassemble_add(struct ieee80211_fragment_cache *cache,
  1828. unsigned int frag, unsigned int seq, int rx_queue,
  1829. struct sk_buff **skb)
  1830. {
  1831. struct ieee80211_fragment_entry *entry;
  1832. entry = &cache->entries[cache->next++];
  1833. if (cache->next >= IEEE80211_FRAGMENT_MAX)
  1834. cache->next = 0;
  1835. __skb_queue_purge(&entry->skb_list);
  1836. __skb_queue_tail(&entry->skb_list, *skb); /* no need for locking */
  1837. *skb = NULL;
  1838. entry->first_frag_time = jiffies;
  1839. entry->seq = seq;
  1840. entry->rx_queue = rx_queue;
  1841. entry->last_frag = frag;
  1842. entry->check_sequential_pn = false;
  1843. entry->extra_len = 0;
  1844. return entry;
  1845. }
  1846. static inline struct ieee80211_fragment_entry *
  1847. ieee80211_reassemble_find(struct ieee80211_fragment_cache *cache,
  1848. unsigned int frag, unsigned int seq,
  1849. int rx_queue, struct ieee80211_hdr *hdr)
  1850. {
  1851. struct ieee80211_fragment_entry *entry;
  1852. int i, idx;
  1853. idx = cache->next;
  1854. for (i = 0; i < IEEE80211_FRAGMENT_MAX; i++) {
  1855. struct ieee80211_hdr *f_hdr;
  1856. struct sk_buff *f_skb;
  1857. idx--;
  1858. if (idx < 0)
  1859. idx = IEEE80211_FRAGMENT_MAX - 1;
  1860. entry = &cache->entries[idx];
  1861. if (skb_queue_empty(&entry->skb_list) || entry->seq != seq ||
  1862. entry->rx_queue != rx_queue ||
  1863. entry->last_frag + 1 != frag)
  1864. continue;
  1865. f_skb = __skb_peek(&entry->skb_list);
  1866. f_hdr = (struct ieee80211_hdr *) f_skb->data;
  1867. /*
  1868. * Check ftype and addresses are equal, else check next fragment
  1869. */
  1870. if (((hdr->frame_control ^ f_hdr->frame_control) &
  1871. cpu_to_le16(IEEE80211_FCTL_FTYPE)) ||
  1872. !ether_addr_equal(hdr->addr1, f_hdr->addr1) ||
  1873. !ether_addr_equal(hdr->addr2, f_hdr->addr2))
  1874. continue;
  1875. if (time_after(jiffies, entry->first_frag_time + 2 * HZ)) {
  1876. __skb_queue_purge(&entry->skb_list);
  1877. continue;
  1878. }
  1879. return entry;
  1880. }
  1881. return NULL;
  1882. }
  1883. static bool requires_sequential_pn(struct ieee80211_rx_data *rx, __le16 fc)
  1884. {
  1885. return rx->key &&
  1886. (rx->key->conf.cipher == WLAN_CIPHER_SUITE_CCMP ||
  1887. rx->key->conf.cipher == WLAN_CIPHER_SUITE_CCMP_256 ||
  1888. rx->key->conf.cipher == WLAN_CIPHER_SUITE_GCMP ||
  1889. rx->key->conf.cipher == WLAN_CIPHER_SUITE_GCMP_256) &&
  1890. ieee80211_has_protected(fc);
  1891. }
  1892. static ieee80211_rx_result debug_noinline
  1893. ieee80211_rx_h_defragment(struct ieee80211_rx_data *rx)
  1894. {
  1895. struct ieee80211_fragment_cache *cache = &rx->sdata->frags;
  1896. struct ieee80211_hdr *hdr;
  1897. u16 sc;
  1898. __le16 fc;
  1899. unsigned int frag, seq;
  1900. struct ieee80211_fragment_entry *entry;
  1901. struct sk_buff *skb;
  1902. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
  1903. hdr = (struct ieee80211_hdr *)rx->skb->data;
  1904. fc = hdr->frame_control;
  1905. if (ieee80211_is_ctl(fc) || ieee80211_is_ext(fc))
  1906. return RX_CONTINUE;
  1907. sc = le16_to_cpu(hdr->seq_ctrl);
  1908. frag = sc & IEEE80211_SCTL_FRAG;
  1909. if (rx->sta)
  1910. cache = &rx->sta->frags;
  1911. if (likely(!ieee80211_has_morefrags(fc) && frag == 0))
  1912. goto out;
  1913. if (is_multicast_ether_addr(hdr->addr1))
  1914. return RX_DROP_MONITOR;
  1915. I802_DEBUG_INC(rx->local->rx_handlers_fragments);
  1916. if (skb_linearize(rx->skb))
  1917. return RX_DROP_U_OOM;
  1918. /*
  1919. * skb_linearize() might change the skb->data and
  1920. * previously cached variables (in this case, hdr) need to
  1921. * be refreshed with the new data.
  1922. */
  1923. hdr = (struct ieee80211_hdr *)rx->skb->data;
  1924. seq = (sc & IEEE80211_SCTL_SEQ) >> 4;
  1925. if (frag == 0) {
  1926. /* This is the first fragment of a new frame. */
  1927. entry = ieee80211_reassemble_add(cache, frag, seq,
  1928. rx->seqno_idx, &(rx->skb));
  1929. if (requires_sequential_pn(rx, fc)) {
  1930. int queue = rx->security_idx;
  1931. /* Store CCMP/GCMP PN so that we can verify that the
  1932. * next fragment has a sequential PN value.
  1933. */
  1934. entry->check_sequential_pn = true;
  1935. entry->is_protected = true;
  1936. entry->key_color = rx->key->color;
  1937. memcpy(entry->last_pn,
  1938. rx->key->u.ccmp.rx_pn[queue],
  1939. IEEE80211_CCMP_PN_LEN);
  1940. BUILD_BUG_ON(offsetof(struct ieee80211_key,
  1941. u.ccmp.rx_pn) !=
  1942. offsetof(struct ieee80211_key,
  1943. u.gcmp.rx_pn));
  1944. BUILD_BUG_ON(sizeof(rx->key->u.ccmp.rx_pn[queue]) !=
  1945. sizeof(rx->key->u.gcmp.rx_pn[queue]));
  1946. BUILD_BUG_ON(IEEE80211_CCMP_PN_LEN !=
  1947. IEEE80211_GCMP_PN_LEN);
  1948. } else if (rx->key &&
  1949. (ieee80211_has_protected(fc) ||
  1950. (status->flag & RX_FLAG_DECRYPTED))) {
  1951. entry->is_protected = true;
  1952. entry->key_color = rx->key->color;
  1953. }
  1954. return RX_QUEUED;
  1955. }
  1956. /* This is a fragment for a frame that should already be pending in
  1957. * fragment cache. Add this fragment to the end of the pending entry.
  1958. */
  1959. entry = ieee80211_reassemble_find(cache, frag, seq,
  1960. rx->seqno_idx, hdr);
  1961. if (!entry) {
  1962. I802_DEBUG_INC(rx->local->rx_handlers_drop_defrag);
  1963. return RX_DROP_MONITOR;
  1964. }
  1965. /* "The receiver shall discard MSDUs and MMPDUs whose constituent
  1966. * MPDU PN values are not incrementing in steps of 1."
  1967. * see IEEE P802.11-REVmc/D5.0, 12.5.3.4.4, item d (for CCMP)
  1968. * and IEEE P802.11-REVmc/D5.0, 12.5.5.4.4, item d (for GCMP)
  1969. */
  1970. if (entry->check_sequential_pn) {
  1971. int i;
  1972. u8 pn[IEEE80211_CCMP_PN_LEN], *rpn;
  1973. if (!requires_sequential_pn(rx, fc))
  1974. return RX_DROP_U_NONSEQ_PN;
  1975. /* Prevent mixed key and fragment cache attacks */
  1976. if (entry->key_color != rx->key->color)
  1977. return RX_DROP_U_BAD_KEY_COLOR;
  1978. memcpy(pn, entry->last_pn, IEEE80211_CCMP_PN_LEN);
  1979. for (i = IEEE80211_CCMP_PN_LEN - 1; i >= 0; i--) {
  1980. pn[i]++;
  1981. if (pn[i])
  1982. break;
  1983. }
  1984. rpn = rx->ccm_gcm.pn;
  1985. if (memcmp(pn, rpn, IEEE80211_CCMP_PN_LEN))
  1986. return RX_DROP_U_REPLAY;
  1987. memcpy(entry->last_pn, pn, IEEE80211_CCMP_PN_LEN);
  1988. } else if (entry->is_protected &&
  1989. (!rx->key ||
  1990. (!ieee80211_has_protected(fc) &&
  1991. !(status->flag & RX_FLAG_DECRYPTED)) ||
  1992. rx->key->color != entry->key_color)) {
  1993. /* Drop this as a mixed key or fragment cache attack, even
  1994. * if for TKIP Michael MIC should protect us, and WEP is a
  1995. * lost cause anyway.
  1996. */
  1997. return RX_DROP_U_EXPECT_DEFRAG_PROT;
  1998. } else if (entry->is_protected && rx->key &&
  1999. entry->key_color != rx->key->color &&
  2000. (status->flag & RX_FLAG_DECRYPTED)) {
  2001. return RX_DROP_U_BAD_KEY_COLOR;
  2002. }
  2003. skb_pull(rx->skb, ieee80211_hdrlen(fc));
  2004. __skb_queue_tail(&entry->skb_list, rx->skb);
  2005. entry->last_frag = frag;
  2006. entry->extra_len += rx->skb->len;
  2007. if (ieee80211_has_morefrags(fc)) {
  2008. rx->skb = NULL;
  2009. return RX_QUEUED;
  2010. }
  2011. rx->skb = __skb_dequeue(&entry->skb_list);
  2012. if (skb_tailroom(rx->skb) < entry->extra_len) {
  2013. I802_DEBUG_INC(rx->local->rx_expand_skb_head_defrag);
  2014. if (unlikely(pskb_expand_head(rx->skb, 0, entry->extra_len,
  2015. GFP_ATOMIC))) {
  2016. I802_DEBUG_INC(rx->local->rx_handlers_drop_defrag);
  2017. __skb_queue_purge(&entry->skb_list);
  2018. return RX_DROP_U_OOM;
  2019. }
  2020. }
  2021. while ((skb = __skb_dequeue(&entry->skb_list))) {
  2022. skb_put_data(rx->skb, skb->data, skb->len);
  2023. dev_kfree_skb(skb);
  2024. }
  2025. out:
  2026. ieee80211_led_rx(rx->local);
  2027. if (rx->sta)
  2028. rx->link_sta->rx_stats.packets++;
  2029. return RX_CONTINUE;
  2030. }
  2031. static int ieee80211_802_1x_port_control(struct ieee80211_rx_data *rx)
  2032. {
  2033. if (unlikely(!rx->sta || !test_sta_flag(rx->sta, WLAN_STA_AUTHORIZED)))
  2034. return -EACCES;
  2035. return 0;
  2036. }
  2037. static int ieee80211_drop_unencrypted(struct ieee80211_rx_data *rx, __le16 fc)
  2038. {
  2039. struct sk_buff *skb = rx->skb;
  2040. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
  2041. /*
  2042. * Pass through unencrypted frames if the hardware has
  2043. * decrypted them already.
  2044. */
  2045. if (status->flag & RX_FLAG_DECRYPTED)
  2046. return 0;
  2047. /* Drop unencrypted frames if key is set. */
  2048. if (unlikely(!ieee80211_has_protected(fc) &&
  2049. !ieee80211_is_any_nullfunc(fc) &&
  2050. ieee80211_is_data(fc) && rx->key))
  2051. return -EACCES;
  2052. return 0;
  2053. }
  2054. VISIBLE_IF_MAC80211_KUNIT ieee80211_rx_result
  2055. ieee80211_drop_unencrypted_mgmt(struct ieee80211_rx_data *rx)
  2056. {
  2057. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
  2058. struct ieee80211_mgmt *mgmt = (void *)rx->skb->data;
  2059. __le16 fc = mgmt->frame_control;
  2060. /*
  2061. * Pass through unencrypted frames if the hardware has
  2062. * decrypted them already.
  2063. */
  2064. if (status->flag & RX_FLAG_DECRYPTED)
  2065. return RX_CONTINUE;
  2066. /* drop unicast protected dual (that wasn't protected) */
  2067. if (ieee80211_is_action(fc) &&
  2068. mgmt->u.action.category == WLAN_CATEGORY_PROTECTED_DUAL_OF_ACTION)
  2069. return RX_DROP_U_UNPROT_DUAL;
  2070. if (rx->sta && test_sta_flag(rx->sta, WLAN_STA_MFP)) {
  2071. if (unlikely(!ieee80211_has_protected(fc) &&
  2072. ieee80211_is_unicast_robust_mgmt_frame(rx->skb))) {
  2073. if (ieee80211_is_deauth(fc) ||
  2074. ieee80211_is_disassoc(fc)) {
  2075. /*
  2076. * Permit unprotected deauth/disassoc frames
  2077. * during 4-way-HS (key is installed after HS).
  2078. */
  2079. if (!rx->key)
  2080. return RX_CONTINUE;
  2081. cfg80211_rx_unprot_mlme_mgmt(rx->sdata->dev,
  2082. rx->skb->data,
  2083. rx->skb->len);
  2084. }
  2085. return RX_DROP_U_UNPROT_UCAST_MGMT;
  2086. }
  2087. /* BIP does not use Protected field, so need to check MMIE */
  2088. if (unlikely(ieee80211_is_multicast_robust_mgmt_frame(rx->skb) &&
  2089. ieee80211_get_mmie_keyidx(rx->skb) < 0)) {
  2090. if (ieee80211_is_deauth(fc) ||
  2091. ieee80211_is_disassoc(fc))
  2092. cfg80211_rx_unprot_mlme_mgmt(rx->sdata->dev,
  2093. rx->skb->data,
  2094. rx->skb->len);
  2095. return RX_DROP_U_UNPROT_MCAST_MGMT;
  2096. }
  2097. if (unlikely(ieee80211_is_beacon(fc) && rx->key &&
  2098. ieee80211_get_mmie_keyidx(rx->skb) < 0)) {
  2099. cfg80211_rx_unprot_mlme_mgmt(rx->sdata->dev,
  2100. rx->skb->data,
  2101. rx->skb->len);
  2102. return RX_DROP_U_UNPROT_BEACON;
  2103. }
  2104. /*
  2105. * When using MFP, Action frames are not allowed prior to
  2106. * having configured keys.
  2107. */
  2108. if (unlikely(ieee80211_is_action(fc) && !rx->key &&
  2109. ieee80211_is_robust_mgmt_frame(rx->skb)))
  2110. return RX_DROP_U_UNPROT_ACTION;
  2111. /* drop unicast public action frames when using MPF */
  2112. if (is_unicast_ether_addr(mgmt->da) &&
  2113. ieee80211_is_protected_dual_of_public_action(rx->skb))
  2114. return RX_DROP_U_UNPROT_UNICAST_PUB_ACTION;
  2115. }
  2116. /*
  2117. * Drop robust action frames before assoc regardless of MFP state,
  2118. * after assoc we also have decided on MFP or not.
  2119. */
  2120. if (ieee80211_is_action(fc) &&
  2121. ieee80211_is_robust_mgmt_frame(rx->skb) &&
  2122. (!rx->sta || !test_sta_flag(rx->sta, WLAN_STA_ASSOC)))
  2123. return RX_DROP_U_UNPROT_ROBUST_ACTION;
  2124. return RX_CONTINUE;
  2125. }
  2126. EXPORT_SYMBOL_IF_MAC80211_KUNIT(ieee80211_drop_unencrypted_mgmt);
  2127. static ieee80211_rx_result
  2128. __ieee80211_data_to_8023(struct ieee80211_rx_data *rx, bool *port_control)
  2129. {
  2130. struct ieee80211_sub_if_data *sdata = rx->sdata;
  2131. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
  2132. bool check_port_control = false;
  2133. struct ethhdr *ehdr;
  2134. int ret;
  2135. *port_control = false;
  2136. if (ieee80211_has_a4(hdr->frame_control) &&
  2137. sdata->vif.type == NL80211_IFTYPE_AP_VLAN && !sdata->u.vlan.sta)
  2138. return RX_DROP_U_UNEXPECTED_VLAN_4ADDR;
  2139. if (sdata->vif.type == NL80211_IFTYPE_STATION &&
  2140. !!sdata->u.mgd.use_4addr != !!ieee80211_has_a4(hdr->frame_control)) {
  2141. if (!sdata->u.mgd.use_4addr)
  2142. return RX_DROP_U_UNEXPECTED_STA_4ADDR;
  2143. else if (!ether_addr_equal(hdr->addr1, sdata->vif.addr))
  2144. check_port_control = true;
  2145. }
  2146. if (is_multicast_ether_addr(hdr->addr1) &&
  2147. sdata->vif.type == NL80211_IFTYPE_AP_VLAN && sdata->u.vlan.sta)
  2148. return RX_DROP_U_UNEXPECTED_VLAN_MCAST;
  2149. ret = ieee80211_data_to_8023(rx->skb, sdata->vif.addr, sdata->vif.type);
  2150. if (ret < 0)
  2151. return RX_DROP_U_INVALID_8023;
  2152. ehdr = (struct ethhdr *) rx->skb->data;
  2153. if (ehdr->h_proto == rx->sdata->control_port_protocol)
  2154. *port_control = true;
  2155. else if (check_port_control)
  2156. return RX_DROP_U_NOT_PORT_CONTROL;
  2157. return RX_CONTINUE;
  2158. }
  2159. bool ieee80211_is_our_addr(struct ieee80211_sub_if_data *sdata,
  2160. const u8 *addr, int *out_link_id)
  2161. {
  2162. unsigned int link_id;
  2163. /* non-MLO, or MLD address replaced by hardware */
  2164. if (ether_addr_equal(sdata->vif.addr, addr))
  2165. return true;
  2166. if (!ieee80211_vif_is_mld(&sdata->vif))
  2167. return false;
  2168. for (link_id = 0; link_id < ARRAY_SIZE(sdata->vif.link_conf); link_id++) {
  2169. struct ieee80211_bss_conf *conf;
  2170. conf = rcu_dereference(sdata->vif.link_conf[link_id]);
  2171. if (!conf)
  2172. continue;
  2173. if (ether_addr_equal(conf->addr, addr)) {
  2174. if (out_link_id)
  2175. *out_link_id = link_id;
  2176. return true;
  2177. }
  2178. }
  2179. return false;
  2180. }
  2181. /*
  2182. * requires that rx->skb is a frame with ethernet header
  2183. */
  2184. static bool ieee80211_frame_allowed(struct ieee80211_rx_data *rx, __le16 fc)
  2185. {
  2186. static const u8 pae_group_addr[ETH_ALEN] __aligned(2)
  2187. = { 0x01, 0x80, 0xC2, 0x00, 0x00, 0x03 };
  2188. struct ethhdr *ehdr = (struct ethhdr *) rx->skb->data;
  2189. /*
  2190. * Allow EAPOL frames to us/the PAE group address regardless of
  2191. * whether the frame was encrypted or not, and always disallow
  2192. * all other destination addresses for them.
  2193. */
  2194. if (unlikely(ehdr->h_proto == rx->sdata->control_port_protocol))
  2195. return ieee80211_is_our_addr(rx->sdata, ehdr->h_dest, NULL) ||
  2196. ether_addr_equal(ehdr->h_dest, pae_group_addr);
  2197. if (ieee80211_802_1x_port_control(rx) ||
  2198. ieee80211_drop_unencrypted(rx, fc))
  2199. return false;
  2200. return true;
  2201. }
  2202. static void ieee80211_deliver_skb_to_local_stack(struct sk_buff *skb,
  2203. struct ieee80211_rx_data *rx)
  2204. {
  2205. struct ieee80211_sub_if_data *sdata = rx->sdata;
  2206. struct net_device *dev = sdata->dev;
  2207. if (unlikely((skb->protocol == sdata->control_port_protocol ||
  2208. (skb->protocol == cpu_to_be16(ETH_P_PREAUTH) &&
  2209. !sdata->control_port_no_preauth)) &&
  2210. sdata->control_port_over_nl80211)) {
  2211. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
  2212. bool noencrypt = !(status->flag & RX_FLAG_DECRYPTED);
  2213. cfg80211_rx_control_port(dev, skb, noencrypt, rx->link_id);
  2214. dev_kfree_skb(skb);
  2215. } else {
  2216. struct ethhdr *ehdr = (void *)skb_mac_header(skb);
  2217. memset(skb->cb, 0, sizeof(skb->cb));
  2218. /*
  2219. * 802.1X over 802.11 requires that the authenticator address
  2220. * be used for EAPOL frames. However, 802.1X allows the use of
  2221. * the PAE group address instead. If the interface is part of
  2222. * a bridge and we pass the frame with the PAE group address,
  2223. * then the bridge will forward it to the network (even if the
  2224. * client was not associated yet), which isn't supposed to
  2225. * happen.
  2226. * To avoid that, rewrite the destination address to our own
  2227. * address, so that the authenticator (e.g. hostapd) will see
  2228. * the frame, but bridge won't forward it anywhere else. Note
  2229. * that due to earlier filtering, the only other address can
  2230. * be the PAE group address, unless the hardware allowed them
  2231. * through in 802.3 offloaded mode.
  2232. */
  2233. if (unlikely(skb->protocol == sdata->control_port_protocol &&
  2234. !ether_addr_equal(ehdr->h_dest, sdata->vif.addr)))
  2235. ether_addr_copy(ehdr->h_dest, sdata->vif.addr);
  2236. /* deliver to local stack */
  2237. if (rx->list)
  2238. list_add_tail(&skb->list, rx->list);
  2239. else
  2240. netif_receive_skb(skb);
  2241. }
  2242. }
  2243. /*
  2244. * requires that rx->skb is a frame with ethernet header
  2245. */
  2246. static void
  2247. ieee80211_deliver_skb(struct ieee80211_rx_data *rx)
  2248. {
  2249. struct ieee80211_sub_if_data *sdata = rx->sdata;
  2250. struct net_device *dev = sdata->dev;
  2251. struct sk_buff *skb, *xmit_skb;
  2252. struct ethhdr *ehdr = (struct ethhdr *) rx->skb->data;
  2253. struct sta_info *dsta;
  2254. skb = rx->skb;
  2255. xmit_skb = NULL;
  2256. dev_sw_netstats_rx_add(dev, skb->len);
  2257. if (rx->sta) {
  2258. /* The seqno index has the same property as needed
  2259. * for the rx_msdu field, i.e. it is IEEE80211_NUM_TIDS
  2260. * for non-QoS-data frames. Here we know it's a data
  2261. * frame, so count MSDUs.
  2262. */
  2263. u64_stats_update_begin(&rx->link_sta->rx_stats.syncp);
  2264. rx->link_sta->rx_stats.msdu[rx->seqno_idx]++;
  2265. u64_stats_update_end(&rx->link_sta->rx_stats.syncp);
  2266. }
  2267. if ((sdata->vif.type == NL80211_IFTYPE_AP ||
  2268. sdata->vif.type == NL80211_IFTYPE_AP_VLAN) &&
  2269. !(sdata->flags & IEEE80211_SDATA_DONT_BRIDGE_PACKETS) &&
  2270. ehdr->h_proto != rx->sdata->control_port_protocol &&
  2271. (sdata->vif.type != NL80211_IFTYPE_AP_VLAN || !sdata->u.vlan.sta)) {
  2272. if (is_multicast_ether_addr(ehdr->h_dest) &&
  2273. ieee80211_vif_get_num_mcast_if(sdata) != 0) {
  2274. /*
  2275. * send multicast frames both to higher layers in
  2276. * local net stack and back to the wireless medium
  2277. */
  2278. xmit_skb = skb_copy(skb, GFP_ATOMIC);
  2279. if (!xmit_skb)
  2280. net_info_ratelimited("%s: failed to clone multicast frame\n",
  2281. dev->name);
  2282. } else if (!is_multicast_ether_addr(ehdr->h_dest) &&
  2283. !ether_addr_equal(ehdr->h_dest, ehdr->h_source)) {
  2284. dsta = sta_info_get(sdata, ehdr->h_dest);
  2285. if (dsta) {
  2286. /*
  2287. * The destination station is associated to
  2288. * this AP (in this VLAN), so send the frame
  2289. * directly to it and do not pass it to local
  2290. * net stack.
  2291. */
  2292. xmit_skb = skb;
  2293. skb = NULL;
  2294. }
  2295. }
  2296. }
  2297. #ifndef CONFIG_HAVE_EFFICIENT_UNALIGNED_ACCESS
  2298. if (skb) {
  2299. /* 'align' will only take the values 0 or 2 here since all
  2300. * frames are required to be aligned to 2-byte boundaries
  2301. * when being passed to mac80211; the code here works just
  2302. * as well if that isn't true, but mac80211 assumes it can
  2303. * access fields as 2-byte aligned (e.g. for ether_addr_equal)
  2304. */
  2305. int align;
  2306. align = (unsigned long)(skb->data + sizeof(struct ethhdr)) & 3;
  2307. if (align) {
  2308. if (WARN_ON(skb_headroom(skb) < 3)) {
  2309. dev_kfree_skb(skb);
  2310. skb = NULL;
  2311. } else {
  2312. u8 *data = skb->data;
  2313. size_t len = skb_headlen(skb);
  2314. skb->data -= align;
  2315. memmove(skb->data, data, len);
  2316. skb_set_tail_pointer(skb, len);
  2317. }
  2318. }
  2319. }
  2320. #endif
  2321. if (skb) {
  2322. skb->protocol = eth_type_trans(skb, dev);
  2323. ieee80211_deliver_skb_to_local_stack(skb, rx);
  2324. }
  2325. if (xmit_skb) {
  2326. /*
  2327. * Send to wireless media and increase priority by 256 to
  2328. * keep the received priority instead of reclassifying
  2329. * the frame (see cfg80211_classify8021d).
  2330. */
  2331. xmit_skb->priority += 256;
  2332. xmit_skb->protocol = htons(ETH_P_802_3);
  2333. skb_reset_network_header(xmit_skb);
  2334. skb_reset_mac_header(xmit_skb);
  2335. dev_queue_xmit(xmit_skb);
  2336. }
  2337. }
  2338. #ifdef CONFIG_MAC80211_MESH
  2339. static bool
  2340. ieee80211_rx_mesh_fast_forward(struct ieee80211_sub_if_data *sdata,
  2341. struct sk_buff *skb, int hdrlen)
  2342. {
  2343. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  2344. struct ieee80211_mesh_fast_tx_key key = {
  2345. .type = MESH_FAST_TX_TYPE_FORWARDED
  2346. };
  2347. struct ieee80211_mesh_fast_tx *entry;
  2348. struct ieee80211s_hdr *mesh_hdr;
  2349. struct tid_ampdu_tx *tid_tx;
  2350. struct sta_info *sta;
  2351. struct ethhdr eth;
  2352. u8 tid;
  2353. mesh_hdr = (struct ieee80211s_hdr *)(skb->data + sizeof(eth));
  2354. if ((mesh_hdr->flags & MESH_FLAGS_AE) == MESH_FLAGS_AE_A5_A6)
  2355. ether_addr_copy(key.addr, mesh_hdr->eaddr1);
  2356. else if (!(mesh_hdr->flags & MESH_FLAGS_AE))
  2357. ether_addr_copy(key.addr, skb->data);
  2358. else
  2359. return false;
  2360. entry = mesh_fast_tx_get(sdata, &key);
  2361. if (!entry)
  2362. return false;
  2363. sta = rcu_dereference(entry->mpath->next_hop);
  2364. if (!sta)
  2365. return false;
  2366. if (skb_linearize(skb))
  2367. return false;
  2368. tid = skb->priority & IEEE80211_QOS_CTL_TAG1D_MASK;
  2369. tid_tx = rcu_dereference(sta->ampdu_mlme.tid_tx[tid]);
  2370. if (tid_tx) {
  2371. if (!test_bit(HT_AGG_STATE_OPERATIONAL, &tid_tx->state))
  2372. return false;
  2373. if (tid_tx->timeout)
  2374. tid_tx->last_tx = jiffies;
  2375. }
  2376. ieee80211_aggr_check(sdata, sta, skb);
  2377. if (ieee80211_get_8023_tunnel_proto(skb->data + hdrlen,
  2378. &skb->protocol))
  2379. hdrlen += ETH_ALEN;
  2380. else
  2381. skb->protocol = htons(skb->len - hdrlen);
  2382. skb_set_network_header(skb, hdrlen + 2);
  2383. skb->dev = sdata->dev;
  2384. memcpy(&eth, skb->data, ETH_HLEN - 2);
  2385. skb_pull(skb, 2);
  2386. __ieee80211_xmit_fast(sdata, sta, &entry->fast_tx, skb, tid_tx,
  2387. eth.h_dest, eth.h_source);
  2388. IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, fwded_unicast);
  2389. IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, fwded_frames);
  2390. return true;
  2391. }
  2392. #endif
  2393. static ieee80211_rx_result
  2394. ieee80211_rx_mesh_data(struct ieee80211_sub_if_data *sdata, struct sta_info *sta,
  2395. struct sk_buff *skb)
  2396. {
  2397. #ifdef CONFIG_MAC80211_MESH
  2398. struct ieee80211_if_mesh *ifmsh = &sdata->u.mesh;
  2399. struct ieee80211_local *local = sdata->local;
  2400. uint16_t fc = IEEE80211_FTYPE_DATA | IEEE80211_STYPE_QOS_DATA;
  2401. struct ieee80211_hdr hdr = {
  2402. .frame_control = cpu_to_le16(fc)
  2403. };
  2404. struct ieee80211_hdr *fwd_hdr;
  2405. struct ieee80211s_hdr *mesh_hdr;
  2406. struct ieee80211_tx_info *info;
  2407. struct sk_buff *fwd_skb;
  2408. struct ethhdr *eth;
  2409. bool multicast;
  2410. int tailroom = 0;
  2411. int hdrlen, mesh_hdrlen;
  2412. u8 *qos;
  2413. if (!ieee80211_vif_is_mesh(&sdata->vif))
  2414. return RX_CONTINUE;
  2415. if (!pskb_may_pull(skb, sizeof(*eth) + 6))
  2416. return RX_DROP_MONITOR;
  2417. mesh_hdr = (struct ieee80211s_hdr *)(skb->data + sizeof(*eth));
  2418. mesh_hdrlen = ieee80211_get_mesh_hdrlen(mesh_hdr);
  2419. if (!pskb_may_pull(skb, sizeof(*eth) + mesh_hdrlen))
  2420. return RX_DROP_MONITOR;
  2421. eth = (struct ethhdr *)skb->data;
  2422. multicast = is_multicast_ether_addr(eth->h_dest);
  2423. mesh_hdr = (struct ieee80211s_hdr *)(eth + 1);
  2424. if (!mesh_hdr->ttl)
  2425. return RX_DROP_MONITOR;
  2426. /* frame is in RMC, don't forward */
  2427. if (is_multicast_ether_addr(eth->h_dest) &&
  2428. mesh_rmc_check(sdata, eth->h_source, mesh_hdr))
  2429. return RX_DROP_MONITOR;
  2430. /* forward packet */
  2431. if (sdata->crypto_tx_tailroom_needed_cnt)
  2432. tailroom = IEEE80211_ENCRYPT_TAILROOM;
  2433. if (mesh_hdr->flags & MESH_FLAGS_AE) {
  2434. struct mesh_path *mppath;
  2435. char *proxied_addr;
  2436. bool update = false;
  2437. if (multicast)
  2438. proxied_addr = mesh_hdr->eaddr1;
  2439. else if ((mesh_hdr->flags & MESH_FLAGS_AE) == MESH_FLAGS_AE_A5_A6)
  2440. /* has_a4 already checked in ieee80211_rx_mesh_check */
  2441. proxied_addr = mesh_hdr->eaddr2;
  2442. else
  2443. return RX_DROP_MONITOR;
  2444. rcu_read_lock();
  2445. mppath = mpp_path_lookup(sdata, proxied_addr);
  2446. if (!mppath) {
  2447. mpp_path_add(sdata, proxied_addr, eth->h_source);
  2448. } else {
  2449. spin_lock_bh(&mppath->state_lock);
  2450. if (!ether_addr_equal(mppath->mpp, eth->h_source)) {
  2451. memcpy(mppath->mpp, eth->h_source, ETH_ALEN);
  2452. update = true;
  2453. }
  2454. mppath->exp_time = jiffies;
  2455. spin_unlock_bh(&mppath->state_lock);
  2456. }
  2457. /* flush fast xmit cache if the address path changed */
  2458. if (update)
  2459. mesh_fast_tx_flush_addr(sdata, proxied_addr);
  2460. rcu_read_unlock();
  2461. }
  2462. /* Frame has reached destination. Don't forward */
  2463. if (ether_addr_equal(sdata->vif.addr, eth->h_dest))
  2464. goto rx_accept;
  2465. if (!--mesh_hdr->ttl) {
  2466. if (multicast)
  2467. goto rx_accept;
  2468. IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, dropped_frames_ttl);
  2469. return RX_DROP_MONITOR;
  2470. }
  2471. if (!ifmsh->mshcfg.dot11MeshForwarding) {
  2472. if (is_multicast_ether_addr(eth->h_dest))
  2473. goto rx_accept;
  2474. return RX_DROP_MONITOR;
  2475. }
  2476. skb_set_queue_mapping(skb, ieee802_1d_to_ac[skb->priority]);
  2477. if (!multicast &&
  2478. ieee80211_rx_mesh_fast_forward(sdata, skb, mesh_hdrlen))
  2479. return RX_QUEUED;
  2480. ieee80211_fill_mesh_addresses(&hdr, &hdr.frame_control,
  2481. eth->h_dest, eth->h_source);
  2482. hdrlen = ieee80211_hdrlen(hdr.frame_control);
  2483. if (multicast) {
  2484. int extra_head = sizeof(struct ieee80211_hdr) - sizeof(*eth);
  2485. fwd_skb = skb_copy_expand(skb, local->tx_headroom + extra_head +
  2486. IEEE80211_ENCRYPT_HEADROOM,
  2487. tailroom, GFP_ATOMIC);
  2488. if (!fwd_skb)
  2489. goto rx_accept;
  2490. } else {
  2491. fwd_skb = skb;
  2492. skb = NULL;
  2493. if (skb_cow_head(fwd_skb, hdrlen - sizeof(struct ethhdr)))
  2494. return RX_DROP_U_OOM;
  2495. if (skb_linearize(fwd_skb))
  2496. return RX_DROP_U_OOM;
  2497. }
  2498. fwd_hdr = skb_push(fwd_skb, hdrlen - sizeof(struct ethhdr));
  2499. memcpy(fwd_hdr, &hdr, hdrlen - 2);
  2500. qos = ieee80211_get_qos_ctl(fwd_hdr);
  2501. qos[0] = qos[1] = 0;
  2502. skb_reset_mac_header(fwd_skb);
  2503. hdrlen += mesh_hdrlen;
  2504. if (ieee80211_get_8023_tunnel_proto(fwd_skb->data + hdrlen,
  2505. &fwd_skb->protocol))
  2506. hdrlen += ETH_ALEN;
  2507. else
  2508. fwd_skb->protocol = htons(fwd_skb->len - hdrlen);
  2509. skb_set_network_header(fwd_skb, hdrlen + 2);
  2510. info = IEEE80211_SKB_CB(fwd_skb);
  2511. memset(info, 0, sizeof(*info));
  2512. info->control.flags |= IEEE80211_TX_INTCFL_NEED_TXPROCESSING;
  2513. info->control.vif = &sdata->vif;
  2514. info->control.jiffies = jiffies;
  2515. fwd_skb->dev = sdata->dev;
  2516. if (multicast) {
  2517. IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, fwded_mcast);
  2518. memcpy(fwd_hdr->addr2, sdata->vif.addr, ETH_ALEN);
  2519. /* update power mode indication when forwarding */
  2520. ieee80211_mps_set_frame_flags(sdata, NULL, fwd_hdr);
  2521. } else if (!mesh_nexthop_lookup(sdata, fwd_skb)) {
  2522. /* mesh power mode flags updated in mesh_nexthop_lookup */
  2523. IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, fwded_unicast);
  2524. } else {
  2525. /* unable to resolve next hop */
  2526. if (sta)
  2527. mesh_path_error_tx(sdata, ifmsh->mshcfg.element_ttl,
  2528. hdr.addr3, 0,
  2529. WLAN_REASON_MESH_PATH_NOFORWARD,
  2530. sta->sta.addr);
  2531. IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, dropped_frames_no_route);
  2532. kfree_skb(fwd_skb);
  2533. goto rx_accept;
  2534. }
  2535. IEEE80211_IFSTA_MESH_CTR_INC(ifmsh, fwded_frames);
  2536. ieee80211_set_qos_hdr(sdata, fwd_skb);
  2537. ieee80211_add_pending_skb(local, fwd_skb);
  2538. rx_accept:
  2539. if (!skb)
  2540. return RX_QUEUED;
  2541. ieee80211_strip_8023_mesh_hdr(skb);
  2542. #endif
  2543. return RX_CONTINUE;
  2544. }
  2545. static ieee80211_rx_result debug_noinline
  2546. __ieee80211_rx_h_amsdu(struct ieee80211_rx_data *rx, u8 data_offset)
  2547. {
  2548. struct net_device *dev = rx->sdata->dev;
  2549. struct sk_buff *skb = rx->skb;
  2550. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
  2551. __le16 fc = hdr->frame_control;
  2552. struct sk_buff_head frame_list;
  2553. ieee80211_rx_result res;
  2554. struct ethhdr ethhdr;
  2555. const u8 *check_da = ethhdr.h_dest, *check_sa = ethhdr.h_source;
  2556. if (unlikely(ieee80211_has_a4(hdr->frame_control))) {
  2557. check_da = NULL;
  2558. check_sa = NULL;
  2559. } else switch (rx->sdata->vif.type) {
  2560. case NL80211_IFTYPE_AP:
  2561. case NL80211_IFTYPE_AP_VLAN:
  2562. check_da = NULL;
  2563. break;
  2564. case NL80211_IFTYPE_STATION:
  2565. if (!rx->sta ||
  2566. !test_sta_flag(rx->sta, WLAN_STA_TDLS_PEER))
  2567. check_sa = NULL;
  2568. break;
  2569. case NL80211_IFTYPE_MESH_POINT:
  2570. check_sa = NULL;
  2571. check_da = NULL;
  2572. break;
  2573. default:
  2574. break;
  2575. }
  2576. skb->dev = dev;
  2577. __skb_queue_head_init(&frame_list);
  2578. if (ieee80211_data_to_8023_exthdr(skb, &ethhdr,
  2579. rx->sdata->vif.addr,
  2580. rx->sdata->vif.type,
  2581. data_offset, true))
  2582. return RX_DROP_U_BAD_AMSDU;
  2583. if (rx->sta->amsdu_mesh_control < 0) {
  2584. s8 valid = -1;
  2585. int i;
  2586. for (i = 0; i <= 2; i++) {
  2587. if (!ieee80211_is_valid_amsdu(skb, i))
  2588. continue;
  2589. if (valid >= 0) {
  2590. /* ambiguous */
  2591. valid = -1;
  2592. break;
  2593. }
  2594. valid = i;
  2595. }
  2596. rx->sta->amsdu_mesh_control = valid;
  2597. }
  2598. ieee80211_amsdu_to_8023s(skb, &frame_list, dev->dev_addr,
  2599. rx->sdata->vif.type,
  2600. rx->local->hw.extra_tx_headroom,
  2601. check_da, check_sa,
  2602. rx->sta->amsdu_mesh_control);
  2603. while (!skb_queue_empty(&frame_list)) {
  2604. rx->skb = __skb_dequeue(&frame_list);
  2605. res = ieee80211_rx_mesh_data(rx->sdata, rx->sta, rx->skb);
  2606. switch (res) {
  2607. case RX_QUEUED:
  2608. continue;
  2609. case RX_CONTINUE:
  2610. break;
  2611. default:
  2612. goto free;
  2613. }
  2614. if (!ieee80211_frame_allowed(rx, fc))
  2615. goto free;
  2616. ieee80211_deliver_skb(rx);
  2617. continue;
  2618. free:
  2619. dev_kfree_skb(rx->skb);
  2620. }
  2621. return RX_QUEUED;
  2622. }
  2623. static ieee80211_rx_result debug_noinline
  2624. ieee80211_rx_h_amsdu(struct ieee80211_rx_data *rx)
  2625. {
  2626. struct sk_buff *skb = rx->skb;
  2627. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
  2628. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
  2629. __le16 fc = hdr->frame_control;
  2630. if (!(status->rx_flags & IEEE80211_RX_AMSDU))
  2631. return RX_CONTINUE;
  2632. if (unlikely(!ieee80211_is_data(fc)))
  2633. return RX_CONTINUE;
  2634. if (unlikely(!ieee80211_is_data_present(fc)))
  2635. return RX_DROP_MONITOR;
  2636. if (unlikely(ieee80211_has_a4(hdr->frame_control))) {
  2637. switch (rx->sdata->vif.type) {
  2638. case NL80211_IFTYPE_AP_VLAN:
  2639. if (!rx->sdata->u.vlan.sta)
  2640. return RX_DROP_U_BAD_4ADDR;
  2641. break;
  2642. case NL80211_IFTYPE_STATION:
  2643. if (!rx->sdata->u.mgd.use_4addr)
  2644. return RX_DROP_U_BAD_4ADDR;
  2645. break;
  2646. case NL80211_IFTYPE_MESH_POINT:
  2647. break;
  2648. default:
  2649. return RX_DROP_U_BAD_4ADDR;
  2650. }
  2651. }
  2652. if (is_multicast_ether_addr(hdr->addr1) || !rx->sta)
  2653. return RX_DROP_U_BAD_AMSDU;
  2654. if (rx->key) {
  2655. /*
  2656. * We should not receive A-MSDUs on pre-HT connections,
  2657. * and HT connections cannot use old ciphers. Thus drop
  2658. * them, as in those cases we couldn't even have SPP
  2659. * A-MSDUs or such.
  2660. */
  2661. switch (rx->key->conf.cipher) {
  2662. case WLAN_CIPHER_SUITE_WEP40:
  2663. case WLAN_CIPHER_SUITE_WEP104:
  2664. case WLAN_CIPHER_SUITE_TKIP:
  2665. return RX_DROP_U_BAD_AMSDU_CIPHER;
  2666. default:
  2667. break;
  2668. }
  2669. }
  2670. return __ieee80211_rx_h_amsdu(rx, 0);
  2671. }
  2672. static ieee80211_rx_result debug_noinline
  2673. ieee80211_rx_h_data(struct ieee80211_rx_data *rx)
  2674. {
  2675. struct ieee80211_sub_if_data *sdata = rx->sdata;
  2676. struct ieee80211_local *local = rx->local;
  2677. struct net_device *dev = sdata->dev;
  2678. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)rx->skb->data;
  2679. __le16 fc = hdr->frame_control;
  2680. ieee80211_rx_result res;
  2681. bool port_control;
  2682. if (unlikely(!ieee80211_is_data(hdr->frame_control)))
  2683. return RX_CONTINUE;
  2684. if (unlikely(!ieee80211_is_data_present(hdr->frame_control)))
  2685. return RX_DROP_MONITOR;
  2686. /*
  2687. * Send unexpected-4addr-frame event to hostapd. For older versions,
  2688. * also drop the frame to cooked monitor interfaces.
  2689. */
  2690. if (ieee80211_has_a4(hdr->frame_control) &&
  2691. sdata->vif.type == NL80211_IFTYPE_AP) {
  2692. if (rx->sta &&
  2693. !test_and_set_sta_flag(rx->sta, WLAN_STA_4ADDR_EVENT))
  2694. cfg80211_rx_unexpected_4addr_frame(
  2695. rx->sdata->dev, rx->sta->sta.addr, GFP_ATOMIC);
  2696. return RX_DROP_MONITOR;
  2697. }
  2698. res = __ieee80211_data_to_8023(rx, &port_control);
  2699. if (unlikely(res != RX_CONTINUE))
  2700. return res;
  2701. res = ieee80211_rx_mesh_data(rx->sdata, rx->sta, rx->skb);
  2702. if (res != RX_CONTINUE)
  2703. return res;
  2704. if (!ieee80211_frame_allowed(rx, fc))
  2705. return RX_DROP_MONITOR;
  2706. /* directly handle TDLS channel switch requests/responses */
  2707. if (unlikely(((struct ethhdr *)rx->skb->data)->h_proto ==
  2708. cpu_to_be16(ETH_P_TDLS))) {
  2709. struct ieee80211_tdls_data *tf = (void *)rx->skb->data;
  2710. if (pskb_may_pull(rx->skb,
  2711. offsetof(struct ieee80211_tdls_data, u)) &&
  2712. tf->payload_type == WLAN_TDLS_SNAP_RFTYPE &&
  2713. tf->category == WLAN_CATEGORY_TDLS &&
  2714. (tf->action_code == WLAN_TDLS_CHANNEL_SWITCH_REQUEST ||
  2715. tf->action_code == WLAN_TDLS_CHANNEL_SWITCH_RESPONSE)) {
  2716. rx->skb->protocol = cpu_to_be16(ETH_P_TDLS);
  2717. __ieee80211_queue_skb_to_iface(sdata, rx->link_id,
  2718. rx->sta, rx->skb);
  2719. return RX_QUEUED;
  2720. }
  2721. }
  2722. if (rx->sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
  2723. unlikely(port_control) && sdata->bss) {
  2724. sdata = container_of(sdata->bss, struct ieee80211_sub_if_data,
  2725. u.ap);
  2726. dev = sdata->dev;
  2727. rx->sdata = sdata;
  2728. }
  2729. rx->skb->dev = dev;
  2730. if (!ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS) &&
  2731. local->ps_sdata && local->hw.conf.dynamic_ps_timeout > 0 &&
  2732. !is_multicast_ether_addr(
  2733. ((struct ethhdr *)rx->skb->data)->h_dest) &&
  2734. (!local->scanning &&
  2735. !test_bit(SDATA_STATE_OFFCHANNEL, &sdata->state)))
  2736. mod_timer(&local->dynamic_ps_timer, jiffies +
  2737. msecs_to_jiffies(local->hw.conf.dynamic_ps_timeout));
  2738. ieee80211_deliver_skb(rx);
  2739. return RX_QUEUED;
  2740. }
  2741. static ieee80211_rx_result debug_noinline
  2742. ieee80211_rx_h_ctrl(struct ieee80211_rx_data *rx, struct sk_buff_head *frames)
  2743. {
  2744. struct sk_buff *skb = rx->skb;
  2745. struct ieee80211_bar *bar = (struct ieee80211_bar *)skb->data;
  2746. struct tid_ampdu_rx *tid_agg_rx;
  2747. u16 start_seq_num;
  2748. u16 tid;
  2749. if (likely(!ieee80211_is_ctl(bar->frame_control)))
  2750. return RX_CONTINUE;
  2751. if (ieee80211_is_back_req(bar->frame_control)) {
  2752. struct {
  2753. __le16 control, start_seq_num;
  2754. } __packed bar_data;
  2755. struct ieee80211_event event = {
  2756. .type = BAR_RX_EVENT,
  2757. };
  2758. if (!rx->sta)
  2759. return RX_DROP_MONITOR;
  2760. if (skb_copy_bits(skb, offsetof(struct ieee80211_bar, control),
  2761. &bar_data, sizeof(bar_data)))
  2762. return RX_DROP_MONITOR;
  2763. tid = le16_to_cpu(bar_data.control) >> 12;
  2764. if (!test_bit(tid, rx->sta->ampdu_mlme.agg_session_valid) &&
  2765. !test_and_set_bit(tid, rx->sta->ampdu_mlme.unexpected_agg))
  2766. ieee80211_send_delba(rx->sdata, rx->sta->sta.addr, tid,
  2767. WLAN_BACK_RECIPIENT,
  2768. WLAN_REASON_QSTA_REQUIRE_SETUP);
  2769. tid_agg_rx = rcu_dereference(rx->sta->ampdu_mlme.tid_rx[tid]);
  2770. if (!tid_agg_rx)
  2771. return RX_DROP_MONITOR;
  2772. start_seq_num = le16_to_cpu(bar_data.start_seq_num) >> 4;
  2773. event.u.ba.tid = tid;
  2774. event.u.ba.ssn = start_seq_num;
  2775. event.u.ba.sta = &rx->sta->sta;
  2776. /* reset session timer */
  2777. if (tid_agg_rx->timeout)
  2778. mod_timer(&tid_agg_rx->session_timer,
  2779. TU_TO_EXP_TIME(tid_agg_rx->timeout));
  2780. spin_lock(&tid_agg_rx->reorder_lock);
  2781. /* release stored frames up to start of BAR */
  2782. ieee80211_release_reorder_frames(rx->sdata, tid_agg_rx,
  2783. start_seq_num, frames);
  2784. spin_unlock(&tid_agg_rx->reorder_lock);
  2785. drv_event_callback(rx->local, rx->sdata, &event);
  2786. kfree_skb(skb);
  2787. return RX_QUEUED;
  2788. }
  2789. /*
  2790. * After this point, we only want management frames,
  2791. * so we can drop all remaining control frames to
  2792. * cooked monitor interfaces.
  2793. */
  2794. return RX_DROP_MONITOR;
  2795. }
  2796. static void ieee80211_process_sa_query_req(struct ieee80211_sub_if_data *sdata,
  2797. struct ieee80211_mgmt *mgmt,
  2798. size_t len)
  2799. {
  2800. struct ieee80211_local *local = sdata->local;
  2801. struct sk_buff *skb;
  2802. struct ieee80211_mgmt *resp;
  2803. if (!ether_addr_equal(mgmt->da, sdata->vif.addr)) {
  2804. /* Not to own unicast address */
  2805. return;
  2806. }
  2807. if (!ether_addr_equal(mgmt->sa, sdata->vif.cfg.ap_addr) ||
  2808. !ether_addr_equal(mgmt->bssid, sdata->vif.cfg.ap_addr)) {
  2809. /* Not from the current AP or not associated yet. */
  2810. return;
  2811. }
  2812. if (len < 24 + 1 + sizeof(resp->u.action.u.sa_query)) {
  2813. /* Too short SA Query request frame */
  2814. return;
  2815. }
  2816. skb = dev_alloc_skb(sizeof(*resp) + local->hw.extra_tx_headroom);
  2817. if (skb == NULL)
  2818. return;
  2819. skb_reserve(skb, local->hw.extra_tx_headroom);
  2820. resp = skb_put_zero(skb, 24);
  2821. memcpy(resp->da, sdata->vif.cfg.ap_addr, ETH_ALEN);
  2822. memcpy(resp->sa, sdata->vif.addr, ETH_ALEN);
  2823. memcpy(resp->bssid, sdata->vif.cfg.ap_addr, ETH_ALEN);
  2824. resp->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
  2825. IEEE80211_STYPE_ACTION);
  2826. skb_put(skb, 1 + sizeof(resp->u.action.u.sa_query));
  2827. resp->u.action.category = WLAN_CATEGORY_SA_QUERY;
  2828. resp->u.action.u.sa_query.action = WLAN_ACTION_SA_QUERY_RESPONSE;
  2829. memcpy(resp->u.action.u.sa_query.trans_id,
  2830. mgmt->u.action.u.sa_query.trans_id,
  2831. WLAN_SA_QUERY_TR_ID_LEN);
  2832. ieee80211_tx_skb(sdata, skb);
  2833. }
  2834. static void
  2835. ieee80211_rx_check_bss_color_collision(struct ieee80211_rx_data *rx)
  2836. {
  2837. struct ieee80211_mgmt *mgmt = (void *)rx->skb->data;
  2838. struct ieee80211_bss_conf *bss_conf;
  2839. const struct element *ie;
  2840. size_t baselen;
  2841. if (!wiphy_ext_feature_isset(rx->local->hw.wiphy,
  2842. NL80211_EXT_FEATURE_BSS_COLOR))
  2843. return;
  2844. if (ieee80211_hw_check(&rx->local->hw, DETECTS_COLOR_COLLISION))
  2845. return;
  2846. bss_conf = rx->link->conf;
  2847. if (bss_conf->csa_active || bss_conf->color_change_active ||
  2848. !bss_conf->he_bss_color.enabled)
  2849. return;
  2850. baselen = mgmt->u.beacon.variable - rx->skb->data;
  2851. if (baselen > rx->skb->len)
  2852. return;
  2853. ie = cfg80211_find_ext_elem(WLAN_EID_EXT_HE_OPERATION,
  2854. mgmt->u.beacon.variable,
  2855. rx->skb->len - baselen);
  2856. if (ie && ie->datalen >= sizeof(struct ieee80211_he_operation) &&
  2857. ie->datalen >= ieee80211_he_oper_size(ie->data + 1)) {
  2858. const struct ieee80211_he_operation *he_oper;
  2859. u8 color;
  2860. he_oper = (void *)(ie->data + 1);
  2861. if (le32_get_bits(he_oper->he_oper_params,
  2862. IEEE80211_HE_OPERATION_BSS_COLOR_DISABLED))
  2863. return;
  2864. color = le32_get_bits(he_oper->he_oper_params,
  2865. IEEE80211_HE_OPERATION_BSS_COLOR_MASK);
  2866. if (color == bss_conf->he_bss_color.color)
  2867. ieee80211_obss_color_collision_notify(&rx->sdata->vif,
  2868. BIT_ULL(color),
  2869. bss_conf->link_id);
  2870. }
  2871. }
  2872. static ieee80211_rx_result debug_noinline
  2873. ieee80211_rx_h_mgmt_check(struct ieee80211_rx_data *rx)
  2874. {
  2875. struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) rx->skb->data;
  2876. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
  2877. if (ieee80211_is_s1g_beacon(mgmt->frame_control))
  2878. return RX_CONTINUE;
  2879. /*
  2880. * From here on, look only at management frames.
  2881. * Data and control frames are already handled,
  2882. * and unknown (reserved) frames are useless.
  2883. */
  2884. if (rx->skb->len < 24)
  2885. return RX_DROP_MONITOR;
  2886. if (!ieee80211_is_mgmt(mgmt->frame_control))
  2887. return RX_DROP_MONITOR;
  2888. /* drop too small action frames */
  2889. if (ieee80211_is_action(mgmt->frame_control) &&
  2890. rx->skb->len < IEEE80211_MIN_ACTION_SIZE)
  2891. return RX_DROP_U_RUNT_ACTION;
  2892. if (rx->sdata->vif.type == NL80211_IFTYPE_AP &&
  2893. ieee80211_is_beacon(mgmt->frame_control) &&
  2894. !(rx->flags & IEEE80211_RX_BEACON_REPORTED)) {
  2895. int sig = 0;
  2896. /* sw bss color collision detection */
  2897. ieee80211_rx_check_bss_color_collision(rx);
  2898. if (ieee80211_hw_check(&rx->local->hw, SIGNAL_DBM) &&
  2899. !(status->flag & RX_FLAG_NO_SIGNAL_VAL))
  2900. sig = status->signal;
  2901. cfg80211_report_obss_beacon_khz(rx->local->hw.wiphy,
  2902. rx->skb->data, rx->skb->len,
  2903. ieee80211_rx_status_to_khz(status),
  2904. sig);
  2905. rx->flags |= IEEE80211_RX_BEACON_REPORTED;
  2906. }
  2907. return ieee80211_drop_unencrypted_mgmt(rx);
  2908. }
  2909. static bool
  2910. ieee80211_process_rx_twt_action(struct ieee80211_rx_data *rx)
  2911. {
  2912. struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *)rx->skb->data;
  2913. struct ieee80211_sub_if_data *sdata = rx->sdata;
  2914. /* TWT actions are only supported in AP for the moment */
  2915. if (sdata->vif.type != NL80211_IFTYPE_AP)
  2916. return false;
  2917. if (!rx->local->ops->add_twt_setup)
  2918. return false;
  2919. if (!sdata->vif.bss_conf.twt_responder)
  2920. return false;
  2921. if (!rx->sta)
  2922. return false;
  2923. switch (mgmt->u.action.u.s1g.action_code) {
  2924. case WLAN_S1G_TWT_SETUP: {
  2925. struct ieee80211_twt_setup *twt;
  2926. if (rx->skb->len < IEEE80211_MIN_ACTION_SIZE +
  2927. 1 + /* action code */
  2928. sizeof(struct ieee80211_twt_setup) +
  2929. 2 /* TWT req_type agrt */)
  2930. break;
  2931. twt = (void *)mgmt->u.action.u.s1g.variable;
  2932. if (twt->element_id != WLAN_EID_S1G_TWT)
  2933. break;
  2934. if (rx->skb->len < IEEE80211_MIN_ACTION_SIZE +
  2935. 4 + /* action code + token + tlv */
  2936. twt->length)
  2937. break;
  2938. return true; /* queue the frame */
  2939. }
  2940. case WLAN_S1G_TWT_TEARDOWN:
  2941. if (rx->skb->len < IEEE80211_MIN_ACTION_SIZE + 2)
  2942. break;
  2943. return true; /* queue the frame */
  2944. default:
  2945. break;
  2946. }
  2947. return false;
  2948. }
  2949. static ieee80211_rx_result debug_noinline
  2950. ieee80211_rx_h_action(struct ieee80211_rx_data *rx)
  2951. {
  2952. struct ieee80211_local *local = rx->local;
  2953. struct ieee80211_sub_if_data *sdata = rx->sdata;
  2954. struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) rx->skb->data;
  2955. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
  2956. int len = rx->skb->len;
  2957. if (!ieee80211_is_action(mgmt->frame_control))
  2958. return RX_CONTINUE;
  2959. if (!rx->sta && mgmt->u.action.category != WLAN_CATEGORY_PUBLIC &&
  2960. mgmt->u.action.category != WLAN_CATEGORY_SELF_PROTECTED &&
  2961. mgmt->u.action.category != WLAN_CATEGORY_SPECTRUM_MGMT)
  2962. return RX_DROP_U_ACTION_UNKNOWN_SRC;
  2963. switch (mgmt->u.action.category) {
  2964. case WLAN_CATEGORY_HT:
  2965. /* reject HT action frames from stations not supporting HT */
  2966. if (!rx->link_sta->pub->ht_cap.ht_supported)
  2967. goto invalid;
  2968. if (sdata->vif.type != NL80211_IFTYPE_STATION &&
  2969. sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
  2970. sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
  2971. sdata->vif.type != NL80211_IFTYPE_AP &&
  2972. sdata->vif.type != NL80211_IFTYPE_ADHOC)
  2973. break;
  2974. /* verify action & smps_control/chanwidth are present */
  2975. if (len < IEEE80211_MIN_ACTION_SIZE + 2)
  2976. goto invalid;
  2977. switch (mgmt->u.action.u.ht_smps.action) {
  2978. case WLAN_HT_ACTION_SMPS: {
  2979. struct ieee80211_supported_band *sband;
  2980. enum ieee80211_smps_mode smps_mode;
  2981. struct sta_opmode_info sta_opmode = {};
  2982. if (sdata->vif.type != NL80211_IFTYPE_AP &&
  2983. sdata->vif.type != NL80211_IFTYPE_AP_VLAN)
  2984. goto handled;
  2985. /* convert to HT capability */
  2986. switch (mgmt->u.action.u.ht_smps.smps_control) {
  2987. case WLAN_HT_SMPS_CONTROL_DISABLED:
  2988. smps_mode = IEEE80211_SMPS_OFF;
  2989. break;
  2990. case WLAN_HT_SMPS_CONTROL_STATIC:
  2991. smps_mode = IEEE80211_SMPS_STATIC;
  2992. break;
  2993. case WLAN_HT_SMPS_CONTROL_DYNAMIC:
  2994. smps_mode = IEEE80211_SMPS_DYNAMIC;
  2995. break;
  2996. default:
  2997. goto invalid;
  2998. }
  2999. /* if no change do nothing */
  3000. if (rx->link_sta->pub->smps_mode == smps_mode)
  3001. goto handled;
  3002. rx->link_sta->pub->smps_mode = smps_mode;
  3003. sta_opmode.smps_mode =
  3004. ieee80211_smps_mode_to_smps_mode(smps_mode);
  3005. sta_opmode.changed = STA_OPMODE_SMPS_MODE_CHANGED;
  3006. sband = rx->local->hw.wiphy->bands[status->band];
  3007. rate_control_rate_update(local, sband, rx->sta, 0,
  3008. IEEE80211_RC_SMPS_CHANGED);
  3009. cfg80211_sta_opmode_change_notify(sdata->dev,
  3010. rx->sta->addr,
  3011. &sta_opmode,
  3012. GFP_ATOMIC);
  3013. goto handled;
  3014. }
  3015. case WLAN_HT_ACTION_NOTIFY_CHANWIDTH: {
  3016. struct ieee80211_supported_band *sband;
  3017. u8 chanwidth = mgmt->u.action.u.ht_notify_cw.chanwidth;
  3018. enum ieee80211_sta_rx_bandwidth max_bw, new_bw;
  3019. struct sta_opmode_info sta_opmode = {};
  3020. /* If it doesn't support 40 MHz it can't change ... */
  3021. if (!(rx->link_sta->pub->ht_cap.cap &
  3022. IEEE80211_HT_CAP_SUP_WIDTH_20_40))
  3023. goto handled;
  3024. if (chanwidth == IEEE80211_HT_CHANWIDTH_20MHZ)
  3025. max_bw = IEEE80211_STA_RX_BW_20;
  3026. else
  3027. max_bw = ieee80211_sta_cap_rx_bw(rx->link_sta);
  3028. /* set cur_max_bandwidth and recalc sta bw */
  3029. rx->link_sta->cur_max_bandwidth = max_bw;
  3030. new_bw = ieee80211_sta_cur_vht_bw(rx->link_sta);
  3031. if (rx->link_sta->pub->bandwidth == new_bw)
  3032. goto handled;
  3033. rx->link_sta->pub->bandwidth = new_bw;
  3034. sband = rx->local->hw.wiphy->bands[status->band];
  3035. sta_opmode.bw =
  3036. ieee80211_sta_rx_bw_to_chan_width(rx->link_sta);
  3037. sta_opmode.changed = STA_OPMODE_MAX_BW_CHANGED;
  3038. rate_control_rate_update(local, sband, rx->sta, 0,
  3039. IEEE80211_RC_BW_CHANGED);
  3040. cfg80211_sta_opmode_change_notify(sdata->dev,
  3041. rx->sta->addr,
  3042. &sta_opmode,
  3043. GFP_ATOMIC);
  3044. goto handled;
  3045. }
  3046. default:
  3047. goto invalid;
  3048. }
  3049. break;
  3050. case WLAN_CATEGORY_PUBLIC:
  3051. case WLAN_CATEGORY_PROTECTED_DUAL_OF_ACTION:
  3052. if (len < IEEE80211_MIN_ACTION_SIZE + 1)
  3053. goto invalid;
  3054. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  3055. break;
  3056. if (!rx->sta)
  3057. break;
  3058. if (!ether_addr_equal(mgmt->bssid, sdata->deflink.u.mgd.bssid))
  3059. break;
  3060. if (mgmt->u.action.u.ext_chan_switch.action_code !=
  3061. WLAN_PUB_ACTION_EXT_CHANSW_ANN)
  3062. break;
  3063. if (len < offsetof(struct ieee80211_mgmt,
  3064. u.action.u.ext_chan_switch.variable))
  3065. goto invalid;
  3066. goto queue;
  3067. case WLAN_CATEGORY_VHT:
  3068. if (sdata->vif.type != NL80211_IFTYPE_STATION &&
  3069. sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
  3070. sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
  3071. sdata->vif.type != NL80211_IFTYPE_AP &&
  3072. sdata->vif.type != NL80211_IFTYPE_ADHOC)
  3073. break;
  3074. /* verify action code is present */
  3075. if (len < IEEE80211_MIN_ACTION_SIZE + 1)
  3076. goto invalid;
  3077. switch (mgmt->u.action.u.vht_opmode_notif.action_code) {
  3078. case WLAN_VHT_ACTION_OPMODE_NOTIF: {
  3079. /* verify opmode is present */
  3080. if (len < IEEE80211_MIN_ACTION_SIZE + 2)
  3081. goto invalid;
  3082. goto queue;
  3083. }
  3084. case WLAN_VHT_ACTION_GROUPID_MGMT: {
  3085. if (len < IEEE80211_MIN_ACTION_SIZE + 25)
  3086. goto invalid;
  3087. goto queue;
  3088. }
  3089. default:
  3090. break;
  3091. }
  3092. break;
  3093. case WLAN_CATEGORY_BACK:
  3094. if (sdata->vif.type != NL80211_IFTYPE_STATION &&
  3095. sdata->vif.type != NL80211_IFTYPE_MESH_POINT &&
  3096. sdata->vif.type != NL80211_IFTYPE_AP_VLAN &&
  3097. sdata->vif.type != NL80211_IFTYPE_AP &&
  3098. sdata->vif.type != NL80211_IFTYPE_ADHOC)
  3099. break;
  3100. /* verify action_code is present */
  3101. if (len < IEEE80211_MIN_ACTION_SIZE + 1)
  3102. break;
  3103. switch (mgmt->u.action.u.addba_req.action_code) {
  3104. case WLAN_ACTION_ADDBA_REQ:
  3105. if (len < (IEEE80211_MIN_ACTION_SIZE +
  3106. sizeof(mgmt->u.action.u.addba_req)))
  3107. goto invalid;
  3108. break;
  3109. case WLAN_ACTION_ADDBA_RESP:
  3110. if (len < (IEEE80211_MIN_ACTION_SIZE +
  3111. sizeof(mgmt->u.action.u.addba_resp)))
  3112. goto invalid;
  3113. break;
  3114. case WLAN_ACTION_DELBA:
  3115. if (len < (IEEE80211_MIN_ACTION_SIZE +
  3116. sizeof(mgmt->u.action.u.delba)))
  3117. goto invalid;
  3118. break;
  3119. default:
  3120. goto invalid;
  3121. }
  3122. goto queue;
  3123. case WLAN_CATEGORY_SPECTRUM_MGMT:
  3124. /* verify action_code is present */
  3125. if (len < IEEE80211_MIN_ACTION_SIZE + 1)
  3126. break;
  3127. switch (mgmt->u.action.u.measurement.action_code) {
  3128. case WLAN_ACTION_SPCT_MSR_REQ:
  3129. if (status->band != NL80211_BAND_5GHZ)
  3130. break;
  3131. if (len < (IEEE80211_MIN_ACTION_SIZE +
  3132. sizeof(mgmt->u.action.u.measurement)))
  3133. break;
  3134. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  3135. break;
  3136. ieee80211_process_measurement_req(sdata, mgmt, len);
  3137. goto handled;
  3138. case WLAN_ACTION_SPCT_CHL_SWITCH: {
  3139. u8 *bssid;
  3140. if (len < (IEEE80211_MIN_ACTION_SIZE +
  3141. sizeof(mgmt->u.action.u.chan_switch)))
  3142. break;
  3143. if (sdata->vif.type != NL80211_IFTYPE_STATION &&
  3144. sdata->vif.type != NL80211_IFTYPE_ADHOC &&
  3145. sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
  3146. break;
  3147. if (sdata->vif.type == NL80211_IFTYPE_STATION)
  3148. bssid = sdata->deflink.u.mgd.bssid;
  3149. else if (sdata->vif.type == NL80211_IFTYPE_ADHOC)
  3150. bssid = sdata->u.ibss.bssid;
  3151. else if (sdata->vif.type == NL80211_IFTYPE_MESH_POINT)
  3152. bssid = mgmt->sa;
  3153. else
  3154. break;
  3155. if (!ether_addr_equal(mgmt->bssid, bssid))
  3156. break;
  3157. goto queue;
  3158. }
  3159. }
  3160. break;
  3161. case WLAN_CATEGORY_SELF_PROTECTED:
  3162. if (len < (IEEE80211_MIN_ACTION_SIZE +
  3163. sizeof(mgmt->u.action.u.self_prot.action_code)))
  3164. break;
  3165. switch (mgmt->u.action.u.self_prot.action_code) {
  3166. case WLAN_SP_MESH_PEERING_OPEN:
  3167. case WLAN_SP_MESH_PEERING_CLOSE:
  3168. case WLAN_SP_MESH_PEERING_CONFIRM:
  3169. if (!ieee80211_vif_is_mesh(&sdata->vif))
  3170. goto invalid;
  3171. if (sdata->u.mesh.user_mpm)
  3172. /* userspace handles this frame */
  3173. break;
  3174. goto queue;
  3175. case WLAN_SP_MGK_INFORM:
  3176. case WLAN_SP_MGK_ACK:
  3177. if (!ieee80211_vif_is_mesh(&sdata->vif))
  3178. goto invalid;
  3179. break;
  3180. }
  3181. break;
  3182. case WLAN_CATEGORY_MESH_ACTION:
  3183. if (len < (IEEE80211_MIN_ACTION_SIZE +
  3184. sizeof(mgmt->u.action.u.mesh_action.action_code)))
  3185. break;
  3186. if (!ieee80211_vif_is_mesh(&sdata->vif))
  3187. break;
  3188. if (mesh_action_is_path_sel(mgmt) &&
  3189. !mesh_path_sel_is_hwmp(sdata))
  3190. break;
  3191. goto queue;
  3192. case WLAN_CATEGORY_S1G:
  3193. if (len < offsetofend(typeof(*mgmt),
  3194. u.action.u.s1g.action_code))
  3195. break;
  3196. switch (mgmt->u.action.u.s1g.action_code) {
  3197. case WLAN_S1G_TWT_SETUP:
  3198. case WLAN_S1G_TWT_TEARDOWN:
  3199. if (ieee80211_process_rx_twt_action(rx))
  3200. goto queue;
  3201. break;
  3202. default:
  3203. break;
  3204. }
  3205. break;
  3206. case WLAN_CATEGORY_PROTECTED_EHT:
  3207. if (len < offsetofend(typeof(*mgmt),
  3208. u.action.u.ttlm_req.action_code))
  3209. break;
  3210. switch (mgmt->u.action.u.ttlm_req.action_code) {
  3211. case WLAN_PROTECTED_EHT_ACTION_TTLM_REQ:
  3212. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  3213. break;
  3214. if (len < offsetofend(typeof(*mgmt),
  3215. u.action.u.ttlm_req))
  3216. goto invalid;
  3217. goto queue;
  3218. case WLAN_PROTECTED_EHT_ACTION_TTLM_RES:
  3219. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  3220. break;
  3221. if (len < offsetofend(typeof(*mgmt),
  3222. u.action.u.ttlm_res))
  3223. goto invalid;
  3224. goto queue;
  3225. default:
  3226. break;
  3227. }
  3228. break;
  3229. }
  3230. return RX_CONTINUE;
  3231. invalid:
  3232. status->rx_flags |= IEEE80211_RX_MALFORMED_ACTION_FRM;
  3233. /* will return in the next handlers */
  3234. return RX_CONTINUE;
  3235. handled:
  3236. if (rx->sta)
  3237. rx->link_sta->rx_stats.packets++;
  3238. dev_kfree_skb(rx->skb);
  3239. return RX_QUEUED;
  3240. queue:
  3241. ieee80211_queue_skb_to_iface(sdata, rx->link_id, rx->sta, rx->skb);
  3242. return RX_QUEUED;
  3243. }
  3244. static ieee80211_rx_result debug_noinline
  3245. ieee80211_rx_h_userspace_mgmt(struct ieee80211_rx_data *rx)
  3246. {
  3247. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
  3248. struct cfg80211_rx_info info = {
  3249. .freq = ieee80211_rx_status_to_khz(status),
  3250. .buf = rx->skb->data,
  3251. .len = rx->skb->len,
  3252. .link_id = rx->link_id,
  3253. .have_link_id = rx->link_id >= 0,
  3254. };
  3255. /* skip known-bad action frames and return them in the next handler */
  3256. if (status->rx_flags & IEEE80211_RX_MALFORMED_ACTION_FRM)
  3257. return RX_CONTINUE;
  3258. /*
  3259. * Getting here means the kernel doesn't know how to handle
  3260. * it, but maybe userspace does ... include returned frames
  3261. * so userspace can register for those to know whether ones
  3262. * it transmitted were processed or returned.
  3263. */
  3264. if (ieee80211_hw_check(&rx->local->hw, SIGNAL_DBM) &&
  3265. !(status->flag & RX_FLAG_NO_SIGNAL_VAL))
  3266. info.sig_dbm = status->signal;
  3267. if (ieee80211_is_timing_measurement(rx->skb) ||
  3268. ieee80211_is_ftm(rx->skb)) {
  3269. info.rx_tstamp = ktime_to_ns(skb_hwtstamps(rx->skb)->hwtstamp);
  3270. info.ack_tstamp = ktime_to_ns(status->ack_tx_hwtstamp);
  3271. }
  3272. if (cfg80211_rx_mgmt_ext(&rx->sdata->wdev, &info)) {
  3273. if (rx->sta)
  3274. rx->link_sta->rx_stats.packets++;
  3275. dev_kfree_skb(rx->skb);
  3276. return RX_QUEUED;
  3277. }
  3278. return RX_CONTINUE;
  3279. }
  3280. static ieee80211_rx_result debug_noinline
  3281. ieee80211_rx_h_action_post_userspace(struct ieee80211_rx_data *rx)
  3282. {
  3283. struct ieee80211_sub_if_data *sdata = rx->sdata;
  3284. struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) rx->skb->data;
  3285. int len = rx->skb->len;
  3286. if (!ieee80211_is_action(mgmt->frame_control))
  3287. return RX_CONTINUE;
  3288. switch (mgmt->u.action.category) {
  3289. case WLAN_CATEGORY_SA_QUERY:
  3290. if (len < (IEEE80211_MIN_ACTION_SIZE +
  3291. sizeof(mgmt->u.action.u.sa_query)))
  3292. break;
  3293. switch (mgmt->u.action.u.sa_query.action) {
  3294. case WLAN_ACTION_SA_QUERY_REQUEST:
  3295. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  3296. break;
  3297. ieee80211_process_sa_query_req(sdata, mgmt, len);
  3298. goto handled;
  3299. }
  3300. break;
  3301. }
  3302. return RX_CONTINUE;
  3303. handled:
  3304. if (rx->sta)
  3305. rx->link_sta->rx_stats.packets++;
  3306. dev_kfree_skb(rx->skb);
  3307. return RX_QUEUED;
  3308. }
  3309. static ieee80211_rx_result debug_noinline
  3310. ieee80211_rx_h_action_return(struct ieee80211_rx_data *rx)
  3311. {
  3312. struct ieee80211_local *local = rx->local;
  3313. struct ieee80211_mgmt *mgmt = (struct ieee80211_mgmt *) rx->skb->data;
  3314. struct sk_buff *nskb;
  3315. struct ieee80211_sub_if_data *sdata = rx->sdata;
  3316. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
  3317. if (!ieee80211_is_action(mgmt->frame_control))
  3318. return RX_CONTINUE;
  3319. /*
  3320. * For AP mode, hostapd is responsible for handling any action
  3321. * frames that we didn't handle, including returning unknown
  3322. * ones. For all other modes we will return them to the sender,
  3323. * setting the 0x80 bit in the action category, as required by
  3324. * 802.11-2012 9.24.4.
  3325. * Newer versions of hostapd shall also use the management frame
  3326. * registration mechanisms, but older ones still use cooked
  3327. * monitor interfaces so push all frames there.
  3328. */
  3329. if (!(status->rx_flags & IEEE80211_RX_MALFORMED_ACTION_FRM) &&
  3330. (sdata->vif.type == NL80211_IFTYPE_AP ||
  3331. sdata->vif.type == NL80211_IFTYPE_AP_VLAN))
  3332. return RX_DROP_MONITOR;
  3333. if (is_multicast_ether_addr(mgmt->da))
  3334. return RX_DROP_MONITOR;
  3335. /* do not return rejected action frames */
  3336. if (mgmt->u.action.category & 0x80)
  3337. return RX_DROP_U_REJECTED_ACTION_RESPONSE;
  3338. nskb = skb_copy_expand(rx->skb, local->hw.extra_tx_headroom, 0,
  3339. GFP_ATOMIC);
  3340. if (nskb) {
  3341. struct ieee80211_mgmt *nmgmt = (void *)nskb->data;
  3342. nmgmt->u.action.category |= 0x80;
  3343. memcpy(nmgmt->da, nmgmt->sa, ETH_ALEN);
  3344. memcpy(nmgmt->sa, rx->sdata->vif.addr, ETH_ALEN);
  3345. memset(nskb->cb, 0, sizeof(nskb->cb));
  3346. if (rx->sdata->vif.type == NL80211_IFTYPE_P2P_DEVICE) {
  3347. struct ieee80211_tx_info *info = IEEE80211_SKB_CB(nskb);
  3348. info->flags = IEEE80211_TX_CTL_TX_OFFCHAN |
  3349. IEEE80211_TX_INTFL_OFFCHAN_TX_OK |
  3350. IEEE80211_TX_CTL_NO_CCK_RATE;
  3351. if (ieee80211_hw_check(&local->hw, QUEUE_CONTROL))
  3352. info->hw_queue =
  3353. local->hw.offchannel_tx_hw_queue;
  3354. }
  3355. __ieee80211_tx_skb_tid_band(rx->sdata, nskb, 7, -1,
  3356. status->band);
  3357. }
  3358. return RX_DROP_U_UNKNOWN_ACTION_REJECTED;
  3359. }
  3360. static ieee80211_rx_result debug_noinline
  3361. ieee80211_rx_h_ext(struct ieee80211_rx_data *rx)
  3362. {
  3363. struct ieee80211_sub_if_data *sdata = rx->sdata;
  3364. struct ieee80211_hdr *hdr = (void *)rx->skb->data;
  3365. if (!ieee80211_is_ext(hdr->frame_control))
  3366. return RX_CONTINUE;
  3367. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  3368. return RX_DROP_MONITOR;
  3369. /* for now only beacons are ext, so queue them */
  3370. ieee80211_queue_skb_to_iface(sdata, rx->link_id, rx->sta, rx->skb);
  3371. return RX_QUEUED;
  3372. }
  3373. static ieee80211_rx_result debug_noinline
  3374. ieee80211_rx_h_mgmt(struct ieee80211_rx_data *rx)
  3375. {
  3376. struct ieee80211_sub_if_data *sdata = rx->sdata;
  3377. struct ieee80211_mgmt *mgmt = (void *)rx->skb->data;
  3378. __le16 stype;
  3379. stype = mgmt->frame_control & cpu_to_le16(IEEE80211_FCTL_STYPE);
  3380. if (!ieee80211_vif_is_mesh(&sdata->vif) &&
  3381. sdata->vif.type != NL80211_IFTYPE_ADHOC &&
  3382. sdata->vif.type != NL80211_IFTYPE_OCB &&
  3383. sdata->vif.type != NL80211_IFTYPE_STATION)
  3384. return RX_DROP_MONITOR;
  3385. switch (stype) {
  3386. case cpu_to_le16(IEEE80211_STYPE_AUTH):
  3387. case cpu_to_le16(IEEE80211_STYPE_BEACON):
  3388. case cpu_to_le16(IEEE80211_STYPE_PROBE_RESP):
  3389. /* process for all: mesh, mlme, ibss */
  3390. break;
  3391. case cpu_to_le16(IEEE80211_STYPE_DEAUTH):
  3392. if (is_multicast_ether_addr(mgmt->da) &&
  3393. !is_broadcast_ether_addr(mgmt->da))
  3394. return RX_DROP_MONITOR;
  3395. /* process only for station/IBSS */
  3396. if (sdata->vif.type != NL80211_IFTYPE_STATION &&
  3397. sdata->vif.type != NL80211_IFTYPE_ADHOC)
  3398. return RX_DROP_MONITOR;
  3399. break;
  3400. case cpu_to_le16(IEEE80211_STYPE_ASSOC_RESP):
  3401. case cpu_to_le16(IEEE80211_STYPE_REASSOC_RESP):
  3402. case cpu_to_le16(IEEE80211_STYPE_DISASSOC):
  3403. if (is_multicast_ether_addr(mgmt->da) &&
  3404. !is_broadcast_ether_addr(mgmt->da))
  3405. return RX_DROP_MONITOR;
  3406. /* process only for station */
  3407. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  3408. return RX_DROP_MONITOR;
  3409. break;
  3410. case cpu_to_le16(IEEE80211_STYPE_PROBE_REQ):
  3411. /* process only for ibss and mesh */
  3412. if (sdata->vif.type != NL80211_IFTYPE_ADHOC &&
  3413. sdata->vif.type != NL80211_IFTYPE_MESH_POINT)
  3414. return RX_DROP_MONITOR;
  3415. break;
  3416. default:
  3417. return RX_DROP_MONITOR;
  3418. }
  3419. ieee80211_queue_skb_to_iface(sdata, rx->link_id, rx->sta, rx->skb);
  3420. return RX_QUEUED;
  3421. }
  3422. static void ieee80211_rx_cooked_monitor(struct ieee80211_rx_data *rx,
  3423. struct ieee80211_rate *rate,
  3424. ieee80211_rx_result reason)
  3425. {
  3426. struct ieee80211_sub_if_data *sdata;
  3427. struct ieee80211_local *local = rx->local;
  3428. struct sk_buff *skb = rx->skb, *skb2;
  3429. struct net_device *prev_dev = NULL;
  3430. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
  3431. int needed_headroom;
  3432. /*
  3433. * If cooked monitor has been processed already, then
  3434. * don't do it again. If not, set the flag.
  3435. */
  3436. if (rx->flags & IEEE80211_RX_CMNTR)
  3437. goto out_free_skb;
  3438. rx->flags |= IEEE80211_RX_CMNTR;
  3439. /* If there are no cooked monitor interfaces, just free the SKB */
  3440. if (!local->cooked_mntrs)
  3441. goto out_free_skb;
  3442. /* room for the radiotap header based on driver features */
  3443. needed_headroom = ieee80211_rx_radiotap_hdrlen(local, status, skb);
  3444. if (skb_headroom(skb) < needed_headroom &&
  3445. pskb_expand_head(skb, needed_headroom, 0, GFP_ATOMIC))
  3446. goto out_free_skb;
  3447. /* prepend radiotap information */
  3448. ieee80211_add_rx_radiotap_header(local, skb, rate, needed_headroom,
  3449. false);
  3450. skb_reset_mac_header(skb);
  3451. skb->ip_summed = CHECKSUM_UNNECESSARY;
  3452. skb->pkt_type = PACKET_OTHERHOST;
  3453. skb->protocol = htons(ETH_P_802_2);
  3454. list_for_each_entry_rcu(sdata, &local->interfaces, list) {
  3455. if (!ieee80211_sdata_running(sdata))
  3456. continue;
  3457. if (sdata->vif.type != NL80211_IFTYPE_MONITOR ||
  3458. !(sdata->u.mntr.flags & MONITOR_FLAG_COOK_FRAMES))
  3459. continue;
  3460. if (prev_dev) {
  3461. skb2 = skb_clone(skb, GFP_ATOMIC);
  3462. if (skb2) {
  3463. skb2->dev = prev_dev;
  3464. netif_receive_skb(skb2);
  3465. }
  3466. }
  3467. prev_dev = sdata->dev;
  3468. dev_sw_netstats_rx_add(sdata->dev, skb->len);
  3469. }
  3470. if (prev_dev) {
  3471. skb->dev = prev_dev;
  3472. netif_receive_skb(skb);
  3473. return;
  3474. }
  3475. out_free_skb:
  3476. kfree_skb_reason(skb, (__force u32)reason);
  3477. }
  3478. static void ieee80211_rx_handlers_result(struct ieee80211_rx_data *rx,
  3479. ieee80211_rx_result res)
  3480. {
  3481. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
  3482. struct ieee80211_supported_band *sband;
  3483. struct ieee80211_rate *rate = NULL;
  3484. if (res == RX_QUEUED) {
  3485. I802_DEBUG_INC(rx->sdata->local->rx_handlers_queued);
  3486. return;
  3487. }
  3488. if (res != RX_CONTINUE) {
  3489. I802_DEBUG_INC(rx->sdata->local->rx_handlers_drop);
  3490. if (rx->sta)
  3491. rx->link_sta->rx_stats.dropped++;
  3492. }
  3493. if (u32_get_bits((__force u32)res, SKB_DROP_REASON_SUBSYS_MASK) ==
  3494. SKB_DROP_REASON_SUBSYS_MAC80211_UNUSABLE) {
  3495. kfree_skb_reason(rx->skb, (__force u32)res);
  3496. return;
  3497. }
  3498. sband = rx->local->hw.wiphy->bands[status->band];
  3499. if (status->encoding == RX_ENC_LEGACY)
  3500. rate = &sband->bitrates[status->rate_idx];
  3501. ieee80211_rx_cooked_monitor(rx, rate, res);
  3502. }
  3503. static void ieee80211_rx_handlers(struct ieee80211_rx_data *rx,
  3504. struct sk_buff_head *frames)
  3505. {
  3506. ieee80211_rx_result res = RX_DROP_MONITOR;
  3507. struct sk_buff *skb;
  3508. #define CALL_RXH(rxh) \
  3509. do { \
  3510. res = rxh(rx); \
  3511. if (res != RX_CONTINUE) \
  3512. goto rxh_next; \
  3513. } while (0)
  3514. /* Lock here to avoid hitting all of the data used in the RX
  3515. * path (e.g. key data, station data, ...) concurrently when
  3516. * a frame is released from the reorder buffer due to timeout
  3517. * from the timer, potentially concurrently with RX from the
  3518. * driver.
  3519. */
  3520. spin_lock_bh(&rx->local->rx_path_lock);
  3521. while ((skb = __skb_dequeue(frames))) {
  3522. /*
  3523. * all the other fields are valid across frames
  3524. * that belong to an aMPDU since they are on the
  3525. * same TID from the same station
  3526. */
  3527. rx->skb = skb;
  3528. if (WARN_ON_ONCE(!rx->link))
  3529. goto rxh_next;
  3530. CALL_RXH(ieee80211_rx_h_check_more_data);
  3531. CALL_RXH(ieee80211_rx_h_uapsd_and_pspoll);
  3532. CALL_RXH(ieee80211_rx_h_sta_process);
  3533. CALL_RXH(ieee80211_rx_h_decrypt);
  3534. CALL_RXH(ieee80211_rx_h_defragment);
  3535. CALL_RXH(ieee80211_rx_h_michael_mic_verify);
  3536. /* must be after MMIC verify so header is counted in MPDU mic */
  3537. CALL_RXH(ieee80211_rx_h_amsdu);
  3538. CALL_RXH(ieee80211_rx_h_data);
  3539. /* special treatment -- needs the queue */
  3540. res = ieee80211_rx_h_ctrl(rx, frames);
  3541. if (res != RX_CONTINUE)
  3542. goto rxh_next;
  3543. CALL_RXH(ieee80211_rx_h_mgmt_check);
  3544. CALL_RXH(ieee80211_rx_h_action);
  3545. CALL_RXH(ieee80211_rx_h_userspace_mgmt);
  3546. CALL_RXH(ieee80211_rx_h_action_post_userspace);
  3547. CALL_RXH(ieee80211_rx_h_action_return);
  3548. CALL_RXH(ieee80211_rx_h_ext);
  3549. CALL_RXH(ieee80211_rx_h_mgmt);
  3550. rxh_next:
  3551. ieee80211_rx_handlers_result(rx, res);
  3552. #undef CALL_RXH
  3553. }
  3554. spin_unlock_bh(&rx->local->rx_path_lock);
  3555. }
  3556. static void ieee80211_invoke_rx_handlers(struct ieee80211_rx_data *rx)
  3557. {
  3558. struct sk_buff_head reorder_release;
  3559. ieee80211_rx_result res = RX_DROP_MONITOR;
  3560. __skb_queue_head_init(&reorder_release);
  3561. #define CALL_RXH(rxh) \
  3562. do { \
  3563. res = rxh(rx); \
  3564. if (res != RX_CONTINUE) \
  3565. goto rxh_next; \
  3566. } while (0)
  3567. CALL_RXH(ieee80211_rx_h_check_dup);
  3568. CALL_RXH(ieee80211_rx_h_check);
  3569. ieee80211_rx_reorder_ampdu(rx, &reorder_release);
  3570. ieee80211_rx_handlers(rx, &reorder_release);
  3571. return;
  3572. rxh_next:
  3573. ieee80211_rx_handlers_result(rx, res);
  3574. #undef CALL_RXH
  3575. }
  3576. static bool
  3577. ieee80211_rx_is_valid_sta_link_id(struct ieee80211_sta *sta, u8 link_id)
  3578. {
  3579. return !!(sta->valid_links & BIT(link_id));
  3580. }
  3581. static bool ieee80211_rx_data_set_link(struct ieee80211_rx_data *rx,
  3582. u8 link_id)
  3583. {
  3584. rx->link_id = link_id;
  3585. rx->link = rcu_dereference(rx->sdata->link[link_id]);
  3586. if (!rx->sta)
  3587. return rx->link;
  3588. if (!ieee80211_rx_is_valid_sta_link_id(&rx->sta->sta, link_id))
  3589. return false;
  3590. rx->link_sta = rcu_dereference(rx->sta->link[link_id]);
  3591. return rx->link && rx->link_sta;
  3592. }
  3593. static bool ieee80211_rx_data_set_sta(struct ieee80211_rx_data *rx,
  3594. struct sta_info *sta, int link_id)
  3595. {
  3596. rx->link_id = link_id;
  3597. rx->sta = sta;
  3598. if (sta) {
  3599. rx->local = sta->sdata->local;
  3600. if (!rx->sdata)
  3601. rx->sdata = sta->sdata;
  3602. rx->link_sta = &sta->deflink;
  3603. } else {
  3604. rx->link_sta = NULL;
  3605. }
  3606. if (link_id < 0) {
  3607. if (ieee80211_vif_is_mld(&rx->sdata->vif) &&
  3608. sta && !sta->sta.valid_links)
  3609. rx->link =
  3610. rcu_dereference(rx->sdata->link[sta->deflink.link_id]);
  3611. else
  3612. rx->link = &rx->sdata->deflink;
  3613. } else if (!ieee80211_rx_data_set_link(rx, link_id)) {
  3614. return false;
  3615. }
  3616. return true;
  3617. }
  3618. /*
  3619. * This function makes calls into the RX path, therefore
  3620. * it has to be invoked under RCU read lock.
  3621. */
  3622. void ieee80211_release_reorder_timeout(struct sta_info *sta, int tid)
  3623. {
  3624. struct sk_buff_head frames;
  3625. struct ieee80211_rx_data rx = {
  3626. /* This is OK -- must be QoS data frame */
  3627. .security_idx = tid,
  3628. .seqno_idx = tid,
  3629. };
  3630. struct tid_ampdu_rx *tid_agg_rx;
  3631. int link_id = -1;
  3632. /* FIXME: statistics won't be right with this */
  3633. if (sta->sta.valid_links)
  3634. link_id = ffs(sta->sta.valid_links) - 1;
  3635. if (!ieee80211_rx_data_set_sta(&rx, sta, link_id))
  3636. return;
  3637. tid_agg_rx = rcu_dereference(sta->ampdu_mlme.tid_rx[tid]);
  3638. if (!tid_agg_rx)
  3639. return;
  3640. __skb_queue_head_init(&frames);
  3641. spin_lock(&tid_agg_rx->reorder_lock);
  3642. ieee80211_sta_reorder_release(sta->sdata, tid_agg_rx, &frames);
  3643. spin_unlock(&tid_agg_rx->reorder_lock);
  3644. if (!skb_queue_empty(&frames)) {
  3645. struct ieee80211_event event = {
  3646. .type = BA_FRAME_TIMEOUT,
  3647. .u.ba.tid = tid,
  3648. .u.ba.sta = &sta->sta,
  3649. };
  3650. drv_event_callback(rx.local, rx.sdata, &event);
  3651. }
  3652. ieee80211_rx_handlers(&rx, &frames);
  3653. }
  3654. void ieee80211_mark_rx_ba_filtered_frames(struct ieee80211_sta *pubsta, u8 tid,
  3655. u16 ssn, u64 filtered,
  3656. u16 received_mpdus)
  3657. {
  3658. struct ieee80211_local *local;
  3659. struct sta_info *sta;
  3660. struct tid_ampdu_rx *tid_agg_rx;
  3661. struct sk_buff_head frames;
  3662. struct ieee80211_rx_data rx = {
  3663. /* This is OK -- must be QoS data frame */
  3664. .security_idx = tid,
  3665. .seqno_idx = tid,
  3666. };
  3667. int i, diff;
  3668. if (WARN_ON(!pubsta || tid >= IEEE80211_NUM_TIDS))
  3669. return;
  3670. __skb_queue_head_init(&frames);
  3671. sta = container_of(pubsta, struct sta_info, sta);
  3672. local = sta->sdata->local;
  3673. WARN_ONCE(local->hw.max_rx_aggregation_subframes > 64,
  3674. "RX BA marker can't support max_rx_aggregation_subframes %u > 64\n",
  3675. local->hw.max_rx_aggregation_subframes);
  3676. if (!ieee80211_rx_data_set_sta(&rx, sta, -1))
  3677. return;
  3678. rcu_read_lock();
  3679. tid_agg_rx = rcu_dereference(sta->ampdu_mlme.tid_rx[tid]);
  3680. if (!tid_agg_rx)
  3681. goto out;
  3682. spin_lock_bh(&tid_agg_rx->reorder_lock);
  3683. if (received_mpdus >= IEEE80211_SN_MODULO >> 1) {
  3684. int release;
  3685. /* release all frames in the reorder buffer */
  3686. release = (tid_agg_rx->head_seq_num + tid_agg_rx->buf_size) %
  3687. IEEE80211_SN_MODULO;
  3688. ieee80211_release_reorder_frames(sta->sdata, tid_agg_rx,
  3689. release, &frames);
  3690. /* update ssn to match received ssn */
  3691. tid_agg_rx->head_seq_num = ssn;
  3692. } else {
  3693. ieee80211_release_reorder_frames(sta->sdata, tid_agg_rx, ssn,
  3694. &frames);
  3695. }
  3696. /* handle the case that received ssn is behind the mac ssn.
  3697. * it can be tid_agg_rx->buf_size behind and still be valid */
  3698. diff = (tid_agg_rx->head_seq_num - ssn) & IEEE80211_SN_MASK;
  3699. if (diff >= tid_agg_rx->buf_size) {
  3700. tid_agg_rx->reorder_buf_filtered = 0;
  3701. goto release;
  3702. }
  3703. filtered = filtered >> diff;
  3704. ssn += diff;
  3705. /* update bitmap */
  3706. for (i = 0; i < tid_agg_rx->buf_size; i++) {
  3707. int index = (ssn + i) % tid_agg_rx->buf_size;
  3708. tid_agg_rx->reorder_buf_filtered &= ~BIT_ULL(index);
  3709. if (filtered & BIT_ULL(i))
  3710. tid_agg_rx->reorder_buf_filtered |= BIT_ULL(index);
  3711. }
  3712. /* now process also frames that the filter marking released */
  3713. ieee80211_sta_reorder_release(sta->sdata, tid_agg_rx, &frames);
  3714. release:
  3715. spin_unlock_bh(&tid_agg_rx->reorder_lock);
  3716. ieee80211_rx_handlers(&rx, &frames);
  3717. out:
  3718. rcu_read_unlock();
  3719. }
  3720. EXPORT_SYMBOL(ieee80211_mark_rx_ba_filtered_frames);
  3721. /* main receive path */
  3722. static inline int ieee80211_bssid_match(const u8 *raddr, const u8 *addr)
  3723. {
  3724. return ether_addr_equal(raddr, addr) ||
  3725. is_broadcast_ether_addr(raddr);
  3726. }
  3727. static bool ieee80211_accept_frame(struct ieee80211_rx_data *rx)
  3728. {
  3729. struct ieee80211_sub_if_data *sdata = rx->sdata;
  3730. struct sk_buff *skb = rx->skb;
  3731. struct ieee80211_hdr *hdr = (void *)skb->data;
  3732. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
  3733. u8 *bssid = ieee80211_get_bssid(hdr, skb->len, sdata->vif.type);
  3734. bool multicast = is_multicast_ether_addr(hdr->addr1) ||
  3735. ieee80211_is_s1g_beacon(hdr->frame_control);
  3736. switch (sdata->vif.type) {
  3737. case NL80211_IFTYPE_STATION:
  3738. if (!bssid && !sdata->u.mgd.use_4addr)
  3739. return false;
  3740. if (ieee80211_is_first_frag(hdr->seq_ctrl) &&
  3741. ieee80211_is_robust_mgmt_frame(skb) && !rx->sta)
  3742. return false;
  3743. if (multicast)
  3744. return true;
  3745. return ieee80211_is_our_addr(sdata, hdr->addr1, &rx->link_id);
  3746. case NL80211_IFTYPE_ADHOC:
  3747. if (!bssid)
  3748. return false;
  3749. if (ether_addr_equal(sdata->vif.addr, hdr->addr2) ||
  3750. ether_addr_equal(sdata->u.ibss.bssid, hdr->addr2) ||
  3751. !is_valid_ether_addr(hdr->addr2))
  3752. return false;
  3753. if (ieee80211_is_beacon(hdr->frame_control))
  3754. return true;
  3755. if (!ieee80211_bssid_match(bssid, sdata->u.ibss.bssid))
  3756. return false;
  3757. if (!multicast &&
  3758. !ether_addr_equal(sdata->vif.addr, hdr->addr1))
  3759. return false;
  3760. if (!rx->sta) {
  3761. int rate_idx;
  3762. if (status->encoding != RX_ENC_LEGACY)
  3763. rate_idx = 0; /* TODO: HT/VHT rates */
  3764. else
  3765. rate_idx = status->rate_idx;
  3766. ieee80211_ibss_rx_no_sta(sdata, bssid, hdr->addr2,
  3767. BIT(rate_idx));
  3768. }
  3769. return true;
  3770. case NL80211_IFTYPE_OCB:
  3771. if (!bssid)
  3772. return false;
  3773. if (!ieee80211_is_data_present(hdr->frame_control))
  3774. return false;
  3775. if (!is_broadcast_ether_addr(bssid))
  3776. return false;
  3777. if (!multicast &&
  3778. !ether_addr_equal(sdata->dev->dev_addr, hdr->addr1))
  3779. return false;
  3780. /* reject invalid/our STA address */
  3781. if (!is_valid_ether_addr(hdr->addr2) ||
  3782. ether_addr_equal(sdata->dev->dev_addr, hdr->addr2))
  3783. return false;
  3784. if (!rx->sta) {
  3785. int rate_idx;
  3786. if (status->encoding != RX_ENC_LEGACY)
  3787. rate_idx = 0; /* TODO: HT rates */
  3788. else
  3789. rate_idx = status->rate_idx;
  3790. ieee80211_ocb_rx_no_sta(sdata, bssid, hdr->addr2,
  3791. BIT(rate_idx));
  3792. }
  3793. return true;
  3794. case NL80211_IFTYPE_MESH_POINT:
  3795. if (ether_addr_equal(sdata->vif.addr, hdr->addr2))
  3796. return false;
  3797. if (multicast)
  3798. return true;
  3799. return ether_addr_equal(sdata->vif.addr, hdr->addr1);
  3800. case NL80211_IFTYPE_AP_VLAN:
  3801. case NL80211_IFTYPE_AP:
  3802. if (!bssid)
  3803. return ieee80211_is_our_addr(sdata, hdr->addr1,
  3804. &rx->link_id);
  3805. if (!is_broadcast_ether_addr(bssid) &&
  3806. !ieee80211_is_our_addr(sdata, bssid, NULL)) {
  3807. /*
  3808. * Accept public action frames even when the
  3809. * BSSID doesn't match, this is used for P2P
  3810. * and location updates. Note that mac80211
  3811. * itself never looks at these frames.
  3812. */
  3813. if (!multicast &&
  3814. !ieee80211_is_our_addr(sdata, hdr->addr1,
  3815. &rx->link_id))
  3816. return false;
  3817. if (ieee80211_is_public_action(hdr, skb->len))
  3818. return true;
  3819. return ieee80211_is_beacon(hdr->frame_control);
  3820. }
  3821. if (!ieee80211_has_tods(hdr->frame_control)) {
  3822. /* ignore data frames to TDLS-peers */
  3823. if (ieee80211_is_data(hdr->frame_control))
  3824. return false;
  3825. /* ignore action frames to TDLS-peers */
  3826. if (ieee80211_is_action(hdr->frame_control) &&
  3827. !is_broadcast_ether_addr(bssid) &&
  3828. !ether_addr_equal(bssid, hdr->addr1))
  3829. return false;
  3830. }
  3831. /*
  3832. * 802.11-2016 Table 9-26 says that for data frames, A1 must be
  3833. * the BSSID - we've checked that already but may have accepted
  3834. * the wildcard (ff:ff:ff:ff:ff:ff).
  3835. *
  3836. * It also says:
  3837. * The BSSID of the Data frame is determined as follows:
  3838. * a) If the STA is contained within an AP or is associated
  3839. * with an AP, the BSSID is the address currently in use
  3840. * by the STA contained in the AP.
  3841. *
  3842. * So we should not accept data frames with an address that's
  3843. * multicast.
  3844. *
  3845. * Accepting it also opens a security problem because stations
  3846. * could encrypt it with the GTK and inject traffic that way.
  3847. */
  3848. if (ieee80211_is_data(hdr->frame_control) && multicast)
  3849. return false;
  3850. return true;
  3851. case NL80211_IFTYPE_P2P_DEVICE:
  3852. return ieee80211_is_public_action(hdr, skb->len) ||
  3853. ieee80211_is_probe_req(hdr->frame_control) ||
  3854. ieee80211_is_probe_resp(hdr->frame_control) ||
  3855. ieee80211_is_beacon(hdr->frame_control);
  3856. case NL80211_IFTYPE_NAN:
  3857. /* Currently no frames on NAN interface are allowed */
  3858. return false;
  3859. default:
  3860. break;
  3861. }
  3862. WARN_ON_ONCE(1);
  3863. return false;
  3864. }
  3865. void ieee80211_check_fast_rx(struct sta_info *sta)
  3866. {
  3867. struct ieee80211_sub_if_data *sdata = sta->sdata;
  3868. struct ieee80211_local *local = sdata->local;
  3869. struct ieee80211_key *key;
  3870. struct ieee80211_fast_rx fastrx = {
  3871. .dev = sdata->dev,
  3872. .vif_type = sdata->vif.type,
  3873. .control_port_protocol = sdata->control_port_protocol,
  3874. }, *old, *new = NULL;
  3875. u32 offload_flags;
  3876. bool set_offload = false;
  3877. bool assign = false;
  3878. bool offload;
  3879. /* use sparse to check that we don't return without updating */
  3880. __acquire(check_fast_rx);
  3881. BUILD_BUG_ON(sizeof(fastrx.rfc1042_hdr) != sizeof(rfc1042_header));
  3882. BUILD_BUG_ON(sizeof(fastrx.rfc1042_hdr) != ETH_ALEN);
  3883. ether_addr_copy(fastrx.rfc1042_hdr, rfc1042_header);
  3884. ether_addr_copy(fastrx.vif_addr, sdata->vif.addr);
  3885. fastrx.uses_rss = ieee80211_hw_check(&local->hw, USES_RSS);
  3886. /* fast-rx doesn't do reordering */
  3887. if (ieee80211_hw_check(&local->hw, AMPDU_AGGREGATION) &&
  3888. !ieee80211_hw_check(&local->hw, SUPPORTS_REORDERING_BUFFER))
  3889. goto clear;
  3890. switch (sdata->vif.type) {
  3891. case NL80211_IFTYPE_STATION:
  3892. if (sta->sta.tdls) {
  3893. fastrx.da_offs = offsetof(struct ieee80211_hdr, addr1);
  3894. fastrx.sa_offs = offsetof(struct ieee80211_hdr, addr2);
  3895. fastrx.expected_ds_bits = 0;
  3896. } else {
  3897. fastrx.da_offs = offsetof(struct ieee80211_hdr, addr1);
  3898. fastrx.sa_offs = offsetof(struct ieee80211_hdr, addr3);
  3899. fastrx.expected_ds_bits =
  3900. cpu_to_le16(IEEE80211_FCTL_FROMDS);
  3901. }
  3902. if (sdata->u.mgd.use_4addr && !sta->sta.tdls) {
  3903. fastrx.expected_ds_bits |=
  3904. cpu_to_le16(IEEE80211_FCTL_TODS);
  3905. fastrx.da_offs = offsetof(struct ieee80211_hdr, addr3);
  3906. fastrx.sa_offs = offsetof(struct ieee80211_hdr, addr4);
  3907. }
  3908. if (!sdata->u.mgd.powersave)
  3909. break;
  3910. /* software powersave is a huge mess, avoid all of it */
  3911. if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK))
  3912. goto clear;
  3913. if (ieee80211_hw_check(&local->hw, SUPPORTS_PS) &&
  3914. !ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS))
  3915. goto clear;
  3916. break;
  3917. case NL80211_IFTYPE_AP_VLAN:
  3918. case NL80211_IFTYPE_AP:
  3919. /* parallel-rx requires this, at least with calls to
  3920. * ieee80211_sta_ps_transition()
  3921. */
  3922. if (!ieee80211_hw_check(&local->hw, AP_LINK_PS))
  3923. goto clear;
  3924. fastrx.da_offs = offsetof(struct ieee80211_hdr, addr3);
  3925. fastrx.sa_offs = offsetof(struct ieee80211_hdr, addr2);
  3926. fastrx.expected_ds_bits = cpu_to_le16(IEEE80211_FCTL_TODS);
  3927. fastrx.internal_forward =
  3928. !(sdata->flags & IEEE80211_SDATA_DONT_BRIDGE_PACKETS) &&
  3929. (sdata->vif.type != NL80211_IFTYPE_AP_VLAN ||
  3930. !sdata->u.vlan.sta);
  3931. if (sdata->vif.type == NL80211_IFTYPE_AP_VLAN &&
  3932. sdata->u.vlan.sta) {
  3933. fastrx.expected_ds_bits |=
  3934. cpu_to_le16(IEEE80211_FCTL_FROMDS);
  3935. fastrx.sa_offs = offsetof(struct ieee80211_hdr, addr4);
  3936. fastrx.internal_forward = 0;
  3937. }
  3938. break;
  3939. case NL80211_IFTYPE_MESH_POINT:
  3940. fastrx.expected_ds_bits = cpu_to_le16(IEEE80211_FCTL_FROMDS |
  3941. IEEE80211_FCTL_TODS);
  3942. fastrx.da_offs = offsetof(struct ieee80211_hdr, addr3);
  3943. fastrx.sa_offs = offsetof(struct ieee80211_hdr, addr4);
  3944. break;
  3945. default:
  3946. goto clear;
  3947. }
  3948. if (!test_sta_flag(sta, WLAN_STA_AUTHORIZED))
  3949. goto clear;
  3950. rcu_read_lock();
  3951. key = rcu_dereference(sta->ptk[sta->ptk_idx]);
  3952. if (!key)
  3953. key = rcu_dereference(sdata->default_unicast_key);
  3954. if (key) {
  3955. switch (key->conf.cipher) {
  3956. case WLAN_CIPHER_SUITE_TKIP:
  3957. /* we don't want to deal with MMIC in fast-rx */
  3958. goto clear_rcu;
  3959. case WLAN_CIPHER_SUITE_CCMP:
  3960. case WLAN_CIPHER_SUITE_CCMP_256:
  3961. case WLAN_CIPHER_SUITE_GCMP:
  3962. case WLAN_CIPHER_SUITE_GCMP_256:
  3963. break;
  3964. default:
  3965. /* We also don't want to deal with
  3966. * WEP or cipher scheme.
  3967. */
  3968. goto clear_rcu;
  3969. }
  3970. fastrx.key = true;
  3971. fastrx.icv_len = key->conf.icv_len;
  3972. }
  3973. assign = true;
  3974. clear_rcu:
  3975. rcu_read_unlock();
  3976. clear:
  3977. __release(check_fast_rx);
  3978. if (assign)
  3979. new = kmemdup(&fastrx, sizeof(fastrx), GFP_KERNEL);
  3980. offload_flags = get_bss_sdata(sdata)->vif.offload_flags;
  3981. offload = offload_flags & IEEE80211_OFFLOAD_DECAP_ENABLED;
  3982. if (assign && offload)
  3983. set_offload = !test_and_set_sta_flag(sta, WLAN_STA_DECAP_OFFLOAD);
  3984. else
  3985. set_offload = test_and_clear_sta_flag(sta, WLAN_STA_DECAP_OFFLOAD);
  3986. if (set_offload)
  3987. drv_sta_set_decap_offload(local, sdata, &sta->sta, assign);
  3988. spin_lock_bh(&sta->lock);
  3989. old = rcu_dereference_protected(sta->fast_rx, true);
  3990. rcu_assign_pointer(sta->fast_rx, new);
  3991. spin_unlock_bh(&sta->lock);
  3992. if (old)
  3993. kfree_rcu(old, rcu_head);
  3994. }
  3995. void ieee80211_clear_fast_rx(struct sta_info *sta)
  3996. {
  3997. struct ieee80211_fast_rx *old;
  3998. spin_lock_bh(&sta->lock);
  3999. old = rcu_dereference_protected(sta->fast_rx, true);
  4000. RCU_INIT_POINTER(sta->fast_rx, NULL);
  4001. spin_unlock_bh(&sta->lock);
  4002. if (old)
  4003. kfree_rcu(old, rcu_head);
  4004. }
  4005. void __ieee80211_check_fast_rx_iface(struct ieee80211_sub_if_data *sdata)
  4006. {
  4007. struct ieee80211_local *local = sdata->local;
  4008. struct sta_info *sta;
  4009. lockdep_assert_wiphy(local->hw.wiphy);
  4010. list_for_each_entry(sta, &local->sta_list, list) {
  4011. if (sdata != sta->sdata &&
  4012. (!sta->sdata->bss || sta->sdata->bss != sdata->bss))
  4013. continue;
  4014. ieee80211_check_fast_rx(sta);
  4015. }
  4016. }
  4017. void ieee80211_check_fast_rx_iface(struct ieee80211_sub_if_data *sdata)
  4018. {
  4019. struct ieee80211_local *local = sdata->local;
  4020. lockdep_assert_wiphy(local->hw.wiphy);
  4021. __ieee80211_check_fast_rx_iface(sdata);
  4022. }
  4023. static void ieee80211_rx_8023(struct ieee80211_rx_data *rx,
  4024. struct ieee80211_fast_rx *fast_rx,
  4025. int orig_len)
  4026. {
  4027. struct ieee80211_sta_rx_stats *stats;
  4028. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(rx->skb);
  4029. struct sta_info *sta = rx->sta;
  4030. struct link_sta_info *link_sta;
  4031. struct sk_buff *skb = rx->skb;
  4032. void *sa = skb->data + ETH_ALEN;
  4033. void *da = skb->data;
  4034. if (rx->link_id >= 0) {
  4035. link_sta = rcu_dereference(sta->link[rx->link_id]);
  4036. if (WARN_ON_ONCE(!link_sta)) {
  4037. dev_kfree_skb(rx->skb);
  4038. return;
  4039. }
  4040. } else {
  4041. link_sta = &sta->deflink;
  4042. }
  4043. stats = &link_sta->rx_stats;
  4044. if (fast_rx->uses_rss)
  4045. stats = this_cpu_ptr(link_sta->pcpu_rx_stats);
  4046. /* statistics part of ieee80211_rx_h_sta_process() */
  4047. if (!(status->flag & RX_FLAG_NO_SIGNAL_VAL)) {
  4048. stats->last_signal = status->signal;
  4049. if (!fast_rx->uses_rss)
  4050. ewma_signal_add(&link_sta->rx_stats_avg.signal,
  4051. -status->signal);
  4052. }
  4053. if (status->chains) {
  4054. int i;
  4055. stats->chains = status->chains;
  4056. for (i = 0; i < ARRAY_SIZE(status->chain_signal); i++) {
  4057. int signal = status->chain_signal[i];
  4058. if (!(status->chains & BIT(i)))
  4059. continue;
  4060. stats->chain_signal_last[i] = signal;
  4061. if (!fast_rx->uses_rss)
  4062. ewma_signal_add(&link_sta->rx_stats_avg.chain_signal[i],
  4063. -signal);
  4064. }
  4065. }
  4066. /* end of statistics */
  4067. stats->last_rx = jiffies;
  4068. stats->last_rate = sta_stats_encode_rate(status);
  4069. stats->fragments++;
  4070. stats->packets++;
  4071. skb->dev = fast_rx->dev;
  4072. dev_sw_netstats_rx_add(fast_rx->dev, skb->len);
  4073. /* The seqno index has the same property as needed
  4074. * for the rx_msdu field, i.e. it is IEEE80211_NUM_TIDS
  4075. * for non-QoS-data frames. Here we know it's a data
  4076. * frame, so count MSDUs.
  4077. */
  4078. u64_stats_update_begin(&stats->syncp);
  4079. stats->msdu[rx->seqno_idx]++;
  4080. stats->bytes += orig_len;
  4081. u64_stats_update_end(&stats->syncp);
  4082. if (fast_rx->internal_forward) {
  4083. struct sk_buff *xmit_skb = NULL;
  4084. if (is_multicast_ether_addr(da)) {
  4085. xmit_skb = skb_copy(skb, GFP_ATOMIC);
  4086. } else if (!ether_addr_equal(da, sa) &&
  4087. sta_info_get(rx->sdata, da)) {
  4088. xmit_skb = skb;
  4089. skb = NULL;
  4090. }
  4091. if (xmit_skb) {
  4092. /*
  4093. * Send to wireless media and increase priority by 256
  4094. * to keep the received priority instead of
  4095. * reclassifying the frame (see cfg80211_classify8021d).
  4096. */
  4097. xmit_skb->priority += 256;
  4098. xmit_skb->protocol = htons(ETH_P_802_3);
  4099. skb_reset_network_header(xmit_skb);
  4100. skb_reset_mac_header(xmit_skb);
  4101. dev_queue_xmit(xmit_skb);
  4102. }
  4103. if (!skb)
  4104. return;
  4105. }
  4106. /* deliver to local stack */
  4107. skb->protocol = eth_type_trans(skb, fast_rx->dev);
  4108. ieee80211_deliver_skb_to_local_stack(skb, rx);
  4109. }
  4110. static bool ieee80211_invoke_fast_rx(struct ieee80211_rx_data *rx,
  4111. struct ieee80211_fast_rx *fast_rx)
  4112. {
  4113. struct sk_buff *skb = rx->skb;
  4114. struct ieee80211_hdr *hdr = (void *)skb->data;
  4115. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
  4116. static ieee80211_rx_result res;
  4117. int orig_len = skb->len;
  4118. int hdrlen = ieee80211_hdrlen(hdr->frame_control);
  4119. int snap_offs = hdrlen;
  4120. struct {
  4121. u8 snap[sizeof(rfc1042_header)];
  4122. __be16 proto;
  4123. } *payload __aligned(2);
  4124. struct {
  4125. u8 da[ETH_ALEN];
  4126. u8 sa[ETH_ALEN];
  4127. } addrs __aligned(2);
  4128. struct ieee80211_sta_rx_stats *stats;
  4129. /* for parallel-rx, we need to have DUP_VALIDATED, otherwise we write
  4130. * to a common data structure; drivers can implement that per queue
  4131. * but we don't have that information in mac80211
  4132. */
  4133. if (!(status->flag & RX_FLAG_DUP_VALIDATED))
  4134. return false;
  4135. #define FAST_RX_CRYPT_FLAGS (RX_FLAG_PN_VALIDATED | RX_FLAG_DECRYPTED)
  4136. /* If using encryption, we also need to have:
  4137. * - PN_VALIDATED: similar, but the implementation is tricky
  4138. * - DECRYPTED: necessary for PN_VALIDATED
  4139. */
  4140. if (fast_rx->key &&
  4141. (status->flag & FAST_RX_CRYPT_FLAGS) != FAST_RX_CRYPT_FLAGS)
  4142. return false;
  4143. if (unlikely(!ieee80211_is_data_present(hdr->frame_control)))
  4144. return false;
  4145. if (unlikely(ieee80211_is_frag(hdr)))
  4146. return false;
  4147. /* Since our interface address cannot be multicast, this
  4148. * implicitly also rejects multicast frames without the
  4149. * explicit check.
  4150. *
  4151. * We shouldn't get any *data* frames not addressed to us
  4152. * (AP mode will accept multicast *management* frames), but
  4153. * punting here will make it go through the full checks in
  4154. * ieee80211_accept_frame().
  4155. */
  4156. if (!ether_addr_equal(fast_rx->vif_addr, hdr->addr1))
  4157. return false;
  4158. if ((hdr->frame_control & cpu_to_le16(IEEE80211_FCTL_FROMDS |
  4159. IEEE80211_FCTL_TODS)) !=
  4160. fast_rx->expected_ds_bits)
  4161. return false;
  4162. /* assign the key to drop unencrypted frames (later)
  4163. * and strip the IV/MIC if necessary
  4164. */
  4165. if (fast_rx->key && !(status->flag & RX_FLAG_IV_STRIPPED)) {
  4166. /* GCMP header length is the same */
  4167. snap_offs += IEEE80211_CCMP_HDR_LEN;
  4168. }
  4169. if (!ieee80211_vif_is_mesh(&rx->sdata->vif) &&
  4170. !(status->rx_flags & IEEE80211_RX_AMSDU)) {
  4171. if (!pskb_may_pull(skb, snap_offs + sizeof(*payload)))
  4172. return false;
  4173. payload = (void *)(skb->data + snap_offs);
  4174. if (!ether_addr_equal(payload->snap, fast_rx->rfc1042_hdr))
  4175. return false;
  4176. /* Don't handle these here since they require special code.
  4177. * Accept AARP and IPX even though they should come with a
  4178. * bridge-tunnel header - but if we get them this way then
  4179. * there's little point in discarding them.
  4180. */
  4181. if (unlikely(payload->proto == cpu_to_be16(ETH_P_TDLS) ||
  4182. payload->proto == fast_rx->control_port_protocol))
  4183. return false;
  4184. }
  4185. /* after this point, don't punt to the slowpath! */
  4186. if (rx->key && !(status->flag & RX_FLAG_MIC_STRIPPED) &&
  4187. pskb_trim(skb, skb->len - fast_rx->icv_len))
  4188. goto drop;
  4189. if (rx->key && !ieee80211_has_protected(hdr->frame_control))
  4190. goto drop;
  4191. if (status->rx_flags & IEEE80211_RX_AMSDU) {
  4192. if (__ieee80211_rx_h_amsdu(rx, snap_offs - hdrlen) !=
  4193. RX_QUEUED)
  4194. goto drop;
  4195. return true;
  4196. }
  4197. /* do the header conversion - first grab the addresses */
  4198. ether_addr_copy(addrs.da, skb->data + fast_rx->da_offs);
  4199. ether_addr_copy(addrs.sa, skb->data + fast_rx->sa_offs);
  4200. if (ieee80211_vif_is_mesh(&rx->sdata->vif)) {
  4201. skb_pull(skb, snap_offs - 2);
  4202. put_unaligned_be16(skb->len - 2, skb->data);
  4203. } else {
  4204. skb_postpull_rcsum(skb, skb->data + snap_offs,
  4205. sizeof(rfc1042_header) + 2);
  4206. /* remove the SNAP but leave the ethertype */
  4207. skb_pull(skb, snap_offs + sizeof(rfc1042_header));
  4208. }
  4209. /* push the addresses in front */
  4210. memcpy(skb_push(skb, sizeof(addrs)), &addrs, sizeof(addrs));
  4211. res = ieee80211_rx_mesh_data(rx->sdata, rx->sta, rx->skb);
  4212. switch (res) {
  4213. case RX_QUEUED:
  4214. return true;
  4215. case RX_CONTINUE:
  4216. break;
  4217. default:
  4218. goto drop;
  4219. }
  4220. ieee80211_rx_8023(rx, fast_rx, orig_len);
  4221. return true;
  4222. drop:
  4223. dev_kfree_skb(skb);
  4224. if (fast_rx->uses_rss)
  4225. stats = this_cpu_ptr(rx->link_sta->pcpu_rx_stats);
  4226. else
  4227. stats = &rx->link_sta->rx_stats;
  4228. stats->dropped++;
  4229. return true;
  4230. }
  4231. /*
  4232. * This function returns whether or not the SKB
  4233. * was destined for RX processing or not, which,
  4234. * if consume is true, is equivalent to whether
  4235. * or not the skb was consumed.
  4236. */
  4237. static bool ieee80211_prepare_and_rx_handle(struct ieee80211_rx_data *rx,
  4238. struct sk_buff *skb, bool consume)
  4239. {
  4240. struct ieee80211_local *local = rx->local;
  4241. struct ieee80211_sub_if_data *sdata = rx->sdata;
  4242. struct ieee80211_hdr *hdr = (void *)skb->data;
  4243. struct link_sta_info *link_sta = rx->link_sta;
  4244. struct ieee80211_link_data *link = rx->link;
  4245. rx->skb = skb;
  4246. /* See if we can do fast-rx; if we have to copy we already lost,
  4247. * so punt in that case. We should never have to deliver a data
  4248. * frame to multiple interfaces anyway.
  4249. *
  4250. * We skip the ieee80211_accept_frame() call and do the necessary
  4251. * checking inside ieee80211_invoke_fast_rx().
  4252. */
  4253. if (consume && rx->sta) {
  4254. struct ieee80211_fast_rx *fast_rx;
  4255. fast_rx = rcu_dereference(rx->sta->fast_rx);
  4256. if (fast_rx && ieee80211_invoke_fast_rx(rx, fast_rx))
  4257. return true;
  4258. }
  4259. if (!ieee80211_accept_frame(rx))
  4260. return false;
  4261. if (!consume) {
  4262. struct skb_shared_hwtstamps *shwt;
  4263. rx->skb = skb_copy(skb, GFP_ATOMIC);
  4264. if (!rx->skb) {
  4265. if (net_ratelimit())
  4266. wiphy_debug(local->hw.wiphy,
  4267. "failed to copy skb for %s\n",
  4268. sdata->name);
  4269. return true;
  4270. }
  4271. /* skb_copy() does not copy the hw timestamps, so copy it
  4272. * explicitly
  4273. */
  4274. shwt = skb_hwtstamps(rx->skb);
  4275. shwt->hwtstamp = skb_hwtstamps(skb)->hwtstamp;
  4276. /* Update the hdr pointer to the new skb for translation below */
  4277. hdr = (struct ieee80211_hdr *)rx->skb->data;
  4278. }
  4279. if (unlikely(rx->sta && rx->sta->sta.mlo) &&
  4280. is_unicast_ether_addr(hdr->addr1) &&
  4281. !ieee80211_is_probe_resp(hdr->frame_control) &&
  4282. !ieee80211_is_beacon(hdr->frame_control)) {
  4283. /* translate to MLD addresses */
  4284. if (ether_addr_equal(link->conf->addr, hdr->addr1))
  4285. ether_addr_copy(hdr->addr1, rx->sdata->vif.addr);
  4286. if (ether_addr_equal(link_sta->addr, hdr->addr2))
  4287. ether_addr_copy(hdr->addr2, rx->sta->addr);
  4288. /* translate A3 only if it's the BSSID */
  4289. if (!ieee80211_has_tods(hdr->frame_control) &&
  4290. !ieee80211_has_fromds(hdr->frame_control)) {
  4291. if (ether_addr_equal(link_sta->addr, hdr->addr3))
  4292. ether_addr_copy(hdr->addr3, rx->sta->addr);
  4293. else if (ether_addr_equal(link->conf->addr, hdr->addr3))
  4294. ether_addr_copy(hdr->addr3, rx->sdata->vif.addr);
  4295. }
  4296. /* not needed for A4 since it can only carry the SA */
  4297. }
  4298. ieee80211_invoke_rx_handlers(rx);
  4299. return true;
  4300. }
  4301. static void __ieee80211_rx_handle_8023(struct ieee80211_hw *hw,
  4302. struct ieee80211_sta *pubsta,
  4303. struct sk_buff *skb,
  4304. struct list_head *list)
  4305. {
  4306. struct ieee80211_local *local = hw_to_local(hw);
  4307. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
  4308. struct ieee80211_fast_rx *fast_rx;
  4309. struct ieee80211_rx_data rx;
  4310. struct sta_info *sta;
  4311. int link_id = -1;
  4312. memset(&rx, 0, sizeof(rx));
  4313. rx.skb = skb;
  4314. rx.local = local;
  4315. rx.list = list;
  4316. rx.link_id = -1;
  4317. I802_DEBUG_INC(local->dot11ReceivedFragmentCount);
  4318. /* drop frame if too short for header */
  4319. if (skb->len < sizeof(struct ethhdr))
  4320. goto drop;
  4321. if (!pubsta)
  4322. goto drop;
  4323. if (status->link_valid)
  4324. link_id = status->link_id;
  4325. /*
  4326. * TODO: Should the frame be dropped if the right link_id is not
  4327. * available? Or may be it is fine in the current form to proceed with
  4328. * the frame processing because with frame being in 802.3 format,
  4329. * link_id is used only for stats purpose and updating the stats on
  4330. * the deflink is fine?
  4331. */
  4332. sta = container_of(pubsta, struct sta_info, sta);
  4333. if (!ieee80211_rx_data_set_sta(&rx, sta, link_id))
  4334. goto drop;
  4335. fast_rx = rcu_dereference(rx.sta->fast_rx);
  4336. if (!fast_rx)
  4337. goto drop;
  4338. ieee80211_rx_8023(&rx, fast_rx, skb->len);
  4339. return;
  4340. drop:
  4341. dev_kfree_skb(skb);
  4342. }
  4343. static bool ieee80211_rx_for_interface(struct ieee80211_rx_data *rx,
  4344. struct sk_buff *skb, bool consume)
  4345. {
  4346. struct link_sta_info *link_sta;
  4347. struct ieee80211_hdr *hdr = (void *)skb->data;
  4348. struct sta_info *sta;
  4349. int link_id = -1;
  4350. /*
  4351. * Look up link station first, in case there's a
  4352. * chance that they might have a link address that
  4353. * is identical to the MLD address, that way we'll
  4354. * have the link information if needed.
  4355. */
  4356. link_sta = link_sta_info_get_bss(rx->sdata, hdr->addr2);
  4357. if (link_sta) {
  4358. sta = link_sta->sta;
  4359. link_id = link_sta->link_id;
  4360. } else {
  4361. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
  4362. sta = sta_info_get_bss(rx->sdata, hdr->addr2);
  4363. if (status->link_valid)
  4364. link_id = status->link_id;
  4365. }
  4366. if (!ieee80211_rx_data_set_sta(rx, sta, link_id))
  4367. return false;
  4368. return ieee80211_prepare_and_rx_handle(rx, skb, consume);
  4369. }
  4370. /*
  4371. * This is the actual Rx frames handler. as it belongs to Rx path it must
  4372. * be called with rcu_read_lock protection.
  4373. */
  4374. static void __ieee80211_rx_handle_packet(struct ieee80211_hw *hw,
  4375. struct ieee80211_sta *pubsta,
  4376. struct sk_buff *skb,
  4377. struct list_head *list)
  4378. {
  4379. struct ieee80211_local *local = hw_to_local(hw);
  4380. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
  4381. struct ieee80211_sub_if_data *sdata;
  4382. struct ieee80211_hdr *hdr;
  4383. __le16 fc;
  4384. struct ieee80211_rx_data rx;
  4385. struct ieee80211_sub_if_data *prev;
  4386. struct rhlist_head *tmp;
  4387. int err = 0;
  4388. fc = ((struct ieee80211_hdr *)skb->data)->frame_control;
  4389. memset(&rx, 0, sizeof(rx));
  4390. rx.skb = skb;
  4391. rx.local = local;
  4392. rx.list = list;
  4393. rx.link_id = -1;
  4394. if (ieee80211_is_data(fc) || ieee80211_is_mgmt(fc))
  4395. I802_DEBUG_INC(local->dot11ReceivedFragmentCount);
  4396. if (ieee80211_is_mgmt(fc)) {
  4397. /* drop frame if too short for header */
  4398. if (skb->len < ieee80211_hdrlen(fc))
  4399. err = -ENOBUFS;
  4400. else
  4401. err = skb_linearize(skb);
  4402. } else {
  4403. err = !pskb_may_pull(skb, ieee80211_hdrlen(fc));
  4404. }
  4405. if (err) {
  4406. dev_kfree_skb(skb);
  4407. return;
  4408. }
  4409. hdr = (struct ieee80211_hdr *)skb->data;
  4410. ieee80211_parse_qos(&rx);
  4411. ieee80211_verify_alignment(&rx);
  4412. if (unlikely(ieee80211_is_probe_resp(hdr->frame_control) ||
  4413. ieee80211_is_beacon(hdr->frame_control) ||
  4414. ieee80211_is_s1g_beacon(hdr->frame_control)))
  4415. ieee80211_scan_rx(local, skb);
  4416. if (ieee80211_is_data(fc)) {
  4417. struct sta_info *sta, *prev_sta;
  4418. int link_id = -1;
  4419. if (status->link_valid)
  4420. link_id = status->link_id;
  4421. if (pubsta) {
  4422. sta = container_of(pubsta, struct sta_info, sta);
  4423. if (!ieee80211_rx_data_set_sta(&rx, sta, link_id))
  4424. goto out;
  4425. /*
  4426. * In MLO connection, fetch the link_id using addr2
  4427. * when the driver does not pass link_id in status.
  4428. * When the address translation is already performed by
  4429. * driver/hw, the valid link_id must be passed in
  4430. * status.
  4431. */
  4432. if (!status->link_valid && pubsta->mlo) {
  4433. struct link_sta_info *link_sta;
  4434. link_sta = link_sta_info_get_bss(rx.sdata,
  4435. hdr->addr2);
  4436. if (!link_sta)
  4437. goto out;
  4438. ieee80211_rx_data_set_link(&rx, link_sta->link_id);
  4439. }
  4440. if (ieee80211_prepare_and_rx_handle(&rx, skb, true))
  4441. return;
  4442. goto out;
  4443. }
  4444. prev_sta = NULL;
  4445. for_each_sta_info(local, hdr->addr2, sta, tmp) {
  4446. if (!prev_sta) {
  4447. prev_sta = sta;
  4448. continue;
  4449. }
  4450. rx.sdata = prev_sta->sdata;
  4451. if (!status->link_valid && prev_sta->sta.mlo) {
  4452. struct link_sta_info *link_sta;
  4453. link_sta = link_sta_info_get_bss(rx.sdata,
  4454. hdr->addr2);
  4455. if (!link_sta)
  4456. continue;
  4457. link_id = link_sta->link_id;
  4458. }
  4459. if (!ieee80211_rx_data_set_sta(&rx, prev_sta, link_id))
  4460. goto out;
  4461. ieee80211_prepare_and_rx_handle(&rx, skb, false);
  4462. prev_sta = sta;
  4463. }
  4464. if (prev_sta) {
  4465. rx.sdata = prev_sta->sdata;
  4466. if (!status->link_valid && prev_sta->sta.mlo) {
  4467. struct link_sta_info *link_sta;
  4468. link_sta = link_sta_info_get_bss(rx.sdata,
  4469. hdr->addr2);
  4470. if (!link_sta)
  4471. goto out;
  4472. link_id = link_sta->link_id;
  4473. }
  4474. if (!ieee80211_rx_data_set_sta(&rx, prev_sta, link_id))
  4475. goto out;
  4476. if (ieee80211_prepare_and_rx_handle(&rx, skb, true))
  4477. return;
  4478. goto out;
  4479. }
  4480. }
  4481. prev = NULL;
  4482. list_for_each_entry_rcu(sdata, &local->interfaces, list) {
  4483. if (!ieee80211_sdata_running(sdata))
  4484. continue;
  4485. if (sdata->vif.type == NL80211_IFTYPE_MONITOR ||
  4486. sdata->vif.type == NL80211_IFTYPE_AP_VLAN)
  4487. continue;
  4488. /*
  4489. * frame is destined for this interface, but if it's
  4490. * not also for the previous one we handle that after
  4491. * the loop to avoid copying the SKB once too much
  4492. */
  4493. if (!prev) {
  4494. prev = sdata;
  4495. continue;
  4496. }
  4497. rx.sdata = prev;
  4498. ieee80211_rx_for_interface(&rx, skb, false);
  4499. prev = sdata;
  4500. }
  4501. if (prev) {
  4502. rx.sdata = prev;
  4503. if (ieee80211_rx_for_interface(&rx, skb, true))
  4504. return;
  4505. }
  4506. out:
  4507. dev_kfree_skb(skb);
  4508. }
  4509. /*
  4510. * This is the receive path handler. It is called by a low level driver when an
  4511. * 802.11 MPDU is received from the hardware.
  4512. */
  4513. void ieee80211_rx_list(struct ieee80211_hw *hw, struct ieee80211_sta *pubsta,
  4514. struct sk_buff *skb, struct list_head *list)
  4515. {
  4516. struct ieee80211_local *local = hw_to_local(hw);
  4517. struct ieee80211_rate *rate = NULL;
  4518. struct ieee80211_supported_band *sband;
  4519. struct ieee80211_rx_status *status = IEEE80211_SKB_RXCB(skb);
  4520. struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
  4521. WARN_ON_ONCE(softirq_count() == 0);
  4522. if (WARN_ON(status->band >= NUM_NL80211_BANDS))
  4523. goto drop;
  4524. sband = local->hw.wiphy->bands[status->band];
  4525. if (WARN_ON(!sband))
  4526. goto drop;
  4527. /*
  4528. * If we're suspending, it is possible although not too likely
  4529. * that we'd be receiving frames after having already partially
  4530. * quiesced the stack. We can't process such frames then since
  4531. * that might, for example, cause stations to be added or other
  4532. * driver callbacks be invoked.
  4533. */
  4534. if (unlikely(local->quiescing || local->suspended))
  4535. goto drop;
  4536. /* We might be during a HW reconfig, prevent Rx for the same reason */
  4537. if (unlikely(local->in_reconfig))
  4538. goto drop;
  4539. /*
  4540. * The same happens when we're not even started,
  4541. * but that's worth a warning.
  4542. */
  4543. if (WARN_ON(!local->started))
  4544. goto drop;
  4545. if (likely(!(status->flag & RX_FLAG_FAILED_PLCP_CRC))) {
  4546. /*
  4547. * Validate the rate, unless a PLCP error means that
  4548. * we probably can't have a valid rate here anyway.
  4549. */
  4550. switch (status->encoding) {
  4551. case RX_ENC_HT:
  4552. /*
  4553. * rate_idx is MCS index, which can be [0-76]
  4554. * as documented on:
  4555. *
  4556. * https://wireless.wiki.kernel.org/en/developers/Documentation/ieee80211/802.11n
  4557. *
  4558. * Anything else would be some sort of driver or
  4559. * hardware error. The driver should catch hardware
  4560. * errors.
  4561. */
  4562. if (WARN(status->rate_idx > 76,
  4563. "Rate marked as an HT rate but passed "
  4564. "status->rate_idx is not "
  4565. "an MCS index [0-76]: %d (0x%02x)\n",
  4566. status->rate_idx,
  4567. status->rate_idx))
  4568. goto drop;
  4569. break;
  4570. case RX_ENC_VHT:
  4571. if (WARN_ONCE(status->rate_idx > 11 ||
  4572. !status->nss ||
  4573. status->nss > 8,
  4574. "Rate marked as a VHT rate but data is invalid: MCS: %d, NSS: %d\n",
  4575. status->rate_idx, status->nss))
  4576. goto drop;
  4577. break;
  4578. case RX_ENC_HE:
  4579. if (WARN_ONCE(status->rate_idx > 11 ||
  4580. !status->nss ||
  4581. status->nss > 8,
  4582. "Rate marked as an HE rate but data is invalid: MCS: %d, NSS: %d\n",
  4583. status->rate_idx, status->nss))
  4584. goto drop;
  4585. break;
  4586. case RX_ENC_EHT:
  4587. if (WARN_ONCE(status->rate_idx > 15 ||
  4588. !status->nss ||
  4589. status->nss > 8 ||
  4590. status->eht.gi > NL80211_RATE_INFO_EHT_GI_3_2,
  4591. "Rate marked as an EHT rate but data is invalid: MCS:%d, NSS:%d, GI:%d\n",
  4592. status->rate_idx, status->nss, status->eht.gi))
  4593. goto drop;
  4594. break;
  4595. default:
  4596. WARN_ON_ONCE(1);
  4597. fallthrough;
  4598. case RX_ENC_LEGACY:
  4599. if (WARN_ON(status->rate_idx >= sband->n_bitrates))
  4600. goto drop;
  4601. rate = &sband->bitrates[status->rate_idx];
  4602. }
  4603. }
  4604. if (WARN_ON_ONCE(status->link_id >= IEEE80211_LINK_UNSPECIFIED))
  4605. goto drop;
  4606. status->rx_flags = 0;
  4607. kcov_remote_start_common(skb_get_kcov_handle(skb));
  4608. /*
  4609. * Frames with failed FCS/PLCP checksum are not returned,
  4610. * all other frames are returned without radiotap header
  4611. * if it was previously present.
  4612. * Also, frames with less than 16 bytes are dropped.
  4613. */
  4614. if (!(status->flag & RX_FLAG_8023))
  4615. skb = ieee80211_rx_monitor(local, skb, rate);
  4616. if (skb) {
  4617. if ((status->flag & RX_FLAG_8023) ||
  4618. ieee80211_is_data_present(hdr->frame_control))
  4619. ieee80211_tpt_led_trig_rx(local, skb->len);
  4620. if (status->flag & RX_FLAG_8023)
  4621. __ieee80211_rx_handle_8023(hw, pubsta, skb, list);
  4622. else
  4623. __ieee80211_rx_handle_packet(hw, pubsta, skb, list);
  4624. }
  4625. kcov_remote_stop();
  4626. return;
  4627. drop:
  4628. kfree_skb(skb);
  4629. }
  4630. EXPORT_SYMBOL(ieee80211_rx_list);
  4631. void ieee80211_rx_napi(struct ieee80211_hw *hw, struct ieee80211_sta *pubsta,
  4632. struct sk_buff *skb, struct napi_struct *napi)
  4633. {
  4634. struct sk_buff *tmp;
  4635. LIST_HEAD(list);
  4636. /*
  4637. * key references and virtual interfaces are protected using RCU
  4638. * and this requires that we are in a read-side RCU section during
  4639. * receive processing
  4640. */
  4641. rcu_read_lock();
  4642. ieee80211_rx_list(hw, pubsta, skb, &list);
  4643. rcu_read_unlock();
  4644. if (!napi) {
  4645. netif_receive_skb_list(&list);
  4646. return;
  4647. }
  4648. list_for_each_entry_safe(skb, tmp, &list, list) {
  4649. skb_list_del_init(skb);
  4650. napi_gro_receive(napi, skb);
  4651. }
  4652. }
  4653. EXPORT_SYMBOL(ieee80211_rx_napi);
  4654. /* This is a version of the rx handler that can be called from hard irq
  4655. * context. Post the skb on the queue and schedule the tasklet */
  4656. void ieee80211_rx_irqsafe(struct ieee80211_hw *hw, struct sk_buff *skb)
  4657. {
  4658. struct ieee80211_local *local = hw_to_local(hw);
  4659. BUILD_BUG_ON(sizeof(struct ieee80211_rx_status) > sizeof(skb->cb));
  4660. skb->pkt_type = IEEE80211_RX_MSG;
  4661. skb_queue_tail(&local->skb_queue, skb);
  4662. tasklet_schedule(&local->tasklet);
  4663. }
  4664. EXPORT_SYMBOL(ieee80211_rx_irqsafe);