mlme.c 320 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424942594269427942894299430943194329433943494359436943794389439944094419442944394449445944694479448944994509451945294539454945594569457945894599460946194629463946494659466946794689469947094719472947394749475947694779478947994809481948294839484948594869487948894899490949194929493949494959496949794989499950095019502950395049505950695079508950995109511951295139514951595169517951895199520952195229523952495259526952795289529953095319532953395349535953695379538953995409541954295439544954595469547954895499550955195529553955495559556955795589559956095619562956395649565956695679568956995709571957295739574957595769577957895799580958195829583958495859586958795889589959095919592959395949595959695979598959996009601960296039604960596069607960896099610961196129613961496159616961796189619962096219622962396249625962696279628962996309631963296339634963596369637963896399640964196429643964496459646964796489649965096519652965396549655965696579658965996609661966296639664966596669667966896699670967196729673967496759676967796789679968096819682968396849685968696879688968996909691969296939694969596969697969896999700970197029703970497059706970797089709971097119712971397149715971697179718971997209721972297239724972597269727972897299730973197329733973497359736973797389739974097419742974397449745974697479748974997509751975297539754975597569757975897599760976197629763976497659766976797689769977097719772977397749775977697779778977997809781978297839784978597869787978897899790979197929793979497959796979797989799980098019802980398049805980698079808980998109811981298139814981598169817981898199820982198229823982498259826982798289829983098319832983398349835983698379838983998409841984298439844984598469847984898499850985198529853985498559856985798589859986098619862986398649865986698679868986998709871987298739874987598769877987898799880988198829883988498859886988798889889989098919892989398949895989698979898989999009901990299039904990599069907990899099910991199129913991499159916991799189919992099219922992399249925992699279928992999309931993299339934993599369937993899399940994199429943994499459946994799489949995099519952995399549955995699579958995999609961996299639964996599669967996899699970997199729973997499759976997799789979998099819982998399849985998699879988998999909991999299939994999599969997999899991000010001100021000310004100051000610007100081000910010100111001210013100141001510016100171001810019100201002110022100231002410025100261002710028100291003010031100321003310034100351003610037100381003910040100411004210043100441004510046100471004810049100501005110052100531005410055100561005710058100591006010061100621006310064100651006610067100681006910070100711007210073100741007510076100771007810079100801008110082100831008410085100861008710088100891009010091100921009310094100951009610097100981009910100101011010210103101041010510106101071010810109101101011110112101131011410115101161011710118101191012010121101221012310124101251012610127101281012910130101311013210133101341013510136101371013810139101401014110142101431014410145101461014710148101491015010151101521015310154101551015610157101581015910160101611016210163101641016510166101671016810169101701017110172101731017410175101761017710178101791018010181101821018310184101851018610187101881018910190101911019210193101941019510196101971019810199102001020110202102031020410205102061020710208102091021010211102121021310214102151021610217102181021910220102211022210223102241022510226102271022810229102301023110232102331023410235102361023710238102391024010241102421024310244102451024610247102481024910250102511025210253102541025510256102571025810259102601026110262102631026410265102661026710268102691027010271102721027310274102751027610277102781027910280102811028210283102841028510286102871028810289102901029110292102931029410295102961029710298102991030010301103021030310304103051030610307103081030910310103111031210313103141031510316103171031810319103201032110322103231032410325103261032710328103291033010331103321033310334103351033610337103381033910340103411034210343103441034510346103471034810349103501035110352103531035410355103561035710358103591036010361103621036310364103651036610367103681036910370103711037210373103741037510376103771037810379103801038110382103831038410385103861038710388103891039010391103921039310394103951039610397103981039910400104011040210403104041040510406104071040810409104101041110412104131041410415104161041710418104191042010421104221042310424104251042610427104281042910430104311043210433104341043510436104371043810439104401044110442104431044410445104461044710448104491045010451104521045310454104551045610457104581045910460104611046210463104641046510466104671046810469104701047110472104731047410475104761047710478104791048010481104821048310484104851048610487104881048910490104911049210493104941049510496104971049810499105001050110502105031050410505105061050710508105091051010511105121051310514105151051610517105181051910520105211052210523105241052510526105271052810529105301053110532105331053410535105361053710538105391054010541105421054310544105451054610547105481054910550105511055210553105541055510556105571055810559105601056110562105631056410565105661056710568105691057010571105721057310574105751057610577105781057910580105811058210583105841058510586105871058810589105901059110592105931059410595105961059710598105991060010601106021060310604106051060610607106081060910610106111061210613106141061510616106171061810619106201062110622106231062410625106261062710628106291063010631106321063310634106351063610637106381063910640106411064210643106441064510646106471064810649106501065110652106531065410655106561065710658106591066010661106621066310664106651066610667106681066910670106711067210673106741067510676106771067810679106801068110682106831068410685106861068710688106891069010691106921069310694106951069610697106981069910700107011070210703107041070510706107071070810709107101071110712107131071410715107161071710718107191072010721107221072310724107251072610727107281072910730107311073210733107341073510736107371073810739107401074110742107431074410745107461074710748107491075010751107521075310754107551075610757107581075910760107611076210763107641076510766107671076810769107701077110772107731077410775107761077710778107791078010781107821078310784107851078610787107881078910790107911079210793107941079510796107971079810799108001080110802108031080410805108061080710808108091081010811108121081310814108151081610817108181081910820108211082210823108241082510826108271082810829108301083110832108331083410835108361083710838108391084010841108421084310844108451084610847108481084910850108511085210853108541085510856108571085810859108601086110862108631086410865108661086710868108691087010871108721087310874108751087610877108781087910880108811088210883108841088510886108871088810889108901089110892108931089410895108961089710898108991090010901109021090310904109051090610907109081090910910109111091210913109141091510916109171091810919109201092110922109231092410925109261092710928109291093010931109321093310934109351093610937109381093910940109411094210943109441094510946109471094810949109501095110952109531095410955109561095710958109591096010961109621096310964109651096610967109681096910970109711097210973109741097510976109771097810979109801098110982109831098410985109861098710988109891099010991109921099310994109951099610997109981099911000110011100211003110041100511006110071100811009110101101111012110131101411015110161101711018110191102011021110221102311024110251102611027110281102911030110311103211033110341103511036110371103811039110401104111042110431104411045110461104711048110491105011051110521105311054110551105611057110581105911060110611106211063110641106511066110671106811069110701107111072110731107411075110761107711078110791108011081110821108311084110851108611087110881108911090110911109211093110941109511096110971109811099111001110111102111031110411105111061110711108111091111011111111121111311114111151111611117111181111911120111211112211123111241112511126111271112811129111301113111132111331113411135111361113711138111391114011141111421114311144111451114611147111481114911150111511115211153111541115511156111571115811159111601116111162111631116411165111661116711168111691117011171111721117311174111751117611177111781117911180111811118211183111841118511186111871118811189111901119111192111931119411195111961119711198111991120011201112021120311204112051120611207112081120911210112111121211213112141121511216112171121811219112201122111222112231122411225112261122711228
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * BSS client mode implementation
  4. * Copyright 2003-2008, Jouni Malinen <j@w1.fi>
  5. * Copyright 2004, Instant802 Networks, Inc.
  6. * Copyright 2005, Devicescape Software, Inc.
  7. * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz>
  8. * Copyright 2007, Michael Wu <flamingice@sourmilk.net>
  9. * Copyright 2013-2014 Intel Mobile Communications GmbH
  10. * Copyright (C) 2015 - 2017 Intel Deutschland GmbH
  11. * Copyright (C) 2018 - 2026 Intel Corporation
  12. */
  13. #include <linux/delay.h>
  14. #include <linux/fips.h>
  15. #include <linux/if_ether.h>
  16. #include <linux/skbuff.h>
  17. #include <linux/if_arp.h>
  18. #include <linux/etherdevice.h>
  19. #include <linux/moduleparam.h>
  20. #include <linux/rtnetlink.h>
  21. #include <linux/crc32.h>
  22. #include <linux/slab.h>
  23. #include <linux/export.h>
  24. #include <net/mac80211.h>
  25. #include <linux/unaligned.h>
  26. #include "ieee80211_i.h"
  27. #include "driver-ops.h"
  28. #include "rate.h"
  29. #include "led.h"
  30. #include "fils_aead.h"
  31. #include <kunit/static_stub.h>
  32. #define IEEE80211_AUTH_TIMEOUT (HZ / 5)
  33. #define IEEE80211_AUTH_TIMEOUT_LONG (HZ / 2)
  34. #define IEEE80211_AUTH_TIMEOUT_SHORT (HZ / 10)
  35. #define IEEE80211_AUTH_TIMEOUT_SAE (HZ * 2)
  36. #define IEEE80211_AUTH_MAX_TRIES 3
  37. #define IEEE80211_AUTH_WAIT_ASSOC (HZ * 5)
  38. #define IEEE80211_AUTH_WAIT_SAE_RETRY (HZ * 2)
  39. #define IEEE80211_ASSOC_TIMEOUT (HZ / 5)
  40. #define IEEE80211_ASSOC_TIMEOUT_LONG (HZ / 2)
  41. #define IEEE80211_ASSOC_TIMEOUT_SHORT (HZ / 10)
  42. #define IEEE80211_ASSOC_MAX_TRIES 3
  43. #define IEEE80211_ADV_TTLM_SAFETY_BUFFER_MS (100 * USEC_PER_MSEC)
  44. #define IEEE80211_ADV_TTLM_ST_UNDERFLOW 0xff00
  45. #define IEEE80211_NEG_TTLM_REQ_TIMEOUT (HZ / 5)
  46. static int max_nullfunc_tries = 2;
  47. module_param(max_nullfunc_tries, int, 0644);
  48. MODULE_PARM_DESC(max_nullfunc_tries,
  49. "Maximum nullfunc tx tries before disconnecting (reason 4).");
  50. static int max_probe_tries = 5;
  51. module_param(max_probe_tries, int, 0644);
  52. MODULE_PARM_DESC(max_probe_tries,
  53. "Maximum probe tries before disconnecting (reason 4).");
  54. /*
  55. * Beacon loss timeout is calculated as N frames times the
  56. * advertised beacon interval. This may need to be somewhat
  57. * higher than what hardware might detect to account for
  58. * delays in the host processing frames. But since we also
  59. * probe on beacon miss before declaring the connection lost
  60. * default to what we want.
  61. */
  62. static int beacon_loss_count = 7;
  63. module_param(beacon_loss_count, int, 0644);
  64. MODULE_PARM_DESC(beacon_loss_count,
  65. "Number of beacon intervals before we decide beacon was lost.");
  66. /*
  67. * Time the connection can be idle before we probe
  68. * it to see if we can still talk to the AP.
  69. */
  70. #define IEEE80211_CONNECTION_IDLE_TIME (30 * HZ)
  71. /*
  72. * Time we wait for a probe response after sending
  73. * a probe request because of beacon loss or for
  74. * checking the connection still works.
  75. */
  76. static int probe_wait_ms = 500;
  77. module_param(probe_wait_ms, int, 0644);
  78. MODULE_PARM_DESC(probe_wait_ms,
  79. "Maximum time(ms) to wait for probe response"
  80. " before disconnecting (reason 4).");
  81. /*
  82. * How many Beacon frames need to have been used in average signal strength
  83. * before starting to indicate signal change events.
  84. */
  85. #define IEEE80211_SIGNAL_AVE_MIN_COUNT 4
  86. /*
  87. * We can have multiple work items (and connection probing)
  88. * scheduling this timer, but we need to take care to only
  89. * reschedule it when it should fire _earlier_ than it was
  90. * asked for before, or if it's not pending right now. This
  91. * function ensures that. Note that it then is required to
  92. * run this function for all timeouts after the first one
  93. * has happened -- the work that runs from this timer will
  94. * do that.
  95. */
  96. static void run_again(struct ieee80211_sub_if_data *sdata,
  97. unsigned long timeout)
  98. {
  99. lockdep_assert_wiphy(sdata->local->hw.wiphy);
  100. if (!timer_pending(&sdata->u.mgd.timer) ||
  101. time_before(timeout, sdata->u.mgd.timer.expires))
  102. mod_timer(&sdata->u.mgd.timer, timeout);
  103. }
  104. void ieee80211_sta_reset_beacon_monitor(struct ieee80211_sub_if_data *sdata)
  105. {
  106. if (sdata->vif.driver_flags & IEEE80211_VIF_BEACON_FILTER)
  107. return;
  108. if (ieee80211_hw_check(&sdata->local->hw, CONNECTION_MONITOR))
  109. return;
  110. mod_timer(&sdata->u.mgd.bcn_mon_timer,
  111. round_jiffies_up(jiffies + sdata->u.mgd.beacon_timeout));
  112. }
  113. void ieee80211_sta_reset_conn_monitor(struct ieee80211_sub_if_data *sdata)
  114. {
  115. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  116. if (unlikely(!ifmgd->associated))
  117. return;
  118. if (ifmgd->probe_send_count)
  119. ifmgd->probe_send_count = 0;
  120. if (ieee80211_hw_check(&sdata->local->hw, CONNECTION_MONITOR))
  121. return;
  122. mod_timer(&ifmgd->conn_mon_timer,
  123. round_jiffies_up(jiffies + IEEE80211_CONNECTION_IDLE_TIME));
  124. }
  125. static int ecw2cw(int ecw)
  126. {
  127. return (1 << ecw) - 1;
  128. }
  129. static enum ieee80211_conn_mode
  130. ieee80211_determine_ap_chan(struct ieee80211_sub_if_data *sdata,
  131. struct ieee80211_channel *channel,
  132. u32 vht_cap_info,
  133. const struct ieee802_11_elems *elems,
  134. bool ignore_ht_channel_mismatch,
  135. const struct ieee80211_conn_settings *conn,
  136. struct cfg80211_chan_def *chandef)
  137. {
  138. const struct ieee80211_ht_operation *ht_oper = elems->ht_operation;
  139. const struct ieee80211_vht_operation *vht_oper = elems->vht_operation;
  140. const struct ieee80211_he_operation *he_oper = elems->he_operation;
  141. const struct ieee80211_eht_operation *eht_oper = elems->eht_operation;
  142. const struct ieee80211_uhr_operation *uhr_oper = elems->uhr_operation;
  143. struct ieee80211_supported_band *sband =
  144. sdata->local->hw.wiphy->bands[channel->band];
  145. struct cfg80211_chan_def vht_chandef;
  146. bool no_vht = false;
  147. u32 ht_cfreq;
  148. if (ieee80211_hw_check(&sdata->local->hw, STRICT))
  149. ignore_ht_channel_mismatch = false;
  150. *chandef = (struct cfg80211_chan_def) {
  151. .chan = channel,
  152. .width = NL80211_CHAN_WIDTH_20_NOHT,
  153. .center_freq1 = channel->center_freq,
  154. .freq1_offset = channel->freq_offset,
  155. };
  156. /* get special S1G case out of the way */
  157. if (sband->band == NL80211_BAND_S1GHZ) {
  158. if (!ieee80211_chandef_s1g_oper(sdata->local, elems->s1g_oper,
  159. chandef)) {
  160. /* Fallback to default 1MHz */
  161. chandef->width = NL80211_CHAN_WIDTH_1;
  162. chandef->s1g_primary_2mhz = false;
  163. }
  164. return IEEE80211_CONN_MODE_S1G;
  165. }
  166. /* get special 6 GHz case out of the way */
  167. if (sband->band == NL80211_BAND_6GHZ) {
  168. enum ieee80211_conn_mode mode = IEEE80211_CONN_MODE_HIGHEST;
  169. /* this is an error */
  170. if (conn->mode < IEEE80211_CONN_MODE_HE)
  171. return IEEE80211_CONN_MODE_LEGACY;
  172. if (!elems->he_6ghz_capa || !elems->he_cap) {
  173. sdata_info(sdata,
  174. "HE 6 GHz AP is missing HE/HE 6 GHz band capability\n");
  175. return IEEE80211_CONN_MODE_LEGACY;
  176. }
  177. if (!eht_oper || !elems->eht_cap) {
  178. eht_oper = NULL;
  179. mode = IEEE80211_CONN_MODE_HE;
  180. }
  181. if (!ieee80211_chandef_he_6ghz_oper(sdata->local, he_oper,
  182. eht_oper, chandef)) {
  183. sdata_info(sdata, "bad HE/EHT 6 GHz operation\n");
  184. return IEEE80211_CONN_MODE_LEGACY;
  185. }
  186. if (mode <= IEEE80211_CONN_MODE_EHT)
  187. return mode;
  188. goto check_uhr;
  189. }
  190. /* now we have the progression HT, VHT, ... */
  191. if (conn->mode < IEEE80211_CONN_MODE_HT)
  192. return IEEE80211_CONN_MODE_LEGACY;
  193. if (!ht_oper || !elems->ht_cap_elem)
  194. return IEEE80211_CONN_MODE_LEGACY;
  195. chandef->width = NL80211_CHAN_WIDTH_20;
  196. ht_cfreq = ieee80211_channel_to_frequency(ht_oper->primary_chan,
  197. channel->band);
  198. /* check that channel matches the right operating channel */
  199. if (!ignore_ht_channel_mismatch && channel->center_freq != ht_cfreq) {
  200. /*
  201. * It's possible that some APs are confused here;
  202. * Netgear WNDR3700 sometimes reports 4 higher than
  203. * the actual channel in association responses, but
  204. * since we look at probe response/beacon data here
  205. * it should be OK.
  206. */
  207. sdata_info(sdata,
  208. "Wrong control channel: center-freq: %d ht-cfreq: %d ht->primary_chan: %d band: %d - Disabling HT\n",
  209. channel->center_freq, ht_cfreq,
  210. ht_oper->primary_chan, channel->band);
  211. return IEEE80211_CONN_MODE_LEGACY;
  212. }
  213. ieee80211_chandef_ht_oper(ht_oper, chandef);
  214. if (conn->mode < IEEE80211_CONN_MODE_VHT)
  215. return IEEE80211_CONN_MODE_HT;
  216. vht_chandef = *chandef;
  217. /*
  218. * having he_cap/he_oper parsed out implies we're at
  219. * least operating as HE STA
  220. */
  221. if (elems->he_cap && he_oper &&
  222. he_oper->he_oper_params & cpu_to_le32(IEEE80211_HE_OPERATION_VHT_OPER_INFO)) {
  223. struct ieee80211_vht_operation he_oper_vht_cap;
  224. /*
  225. * Set only first 3 bytes (other 2 aren't used in
  226. * ieee80211_chandef_vht_oper() anyway)
  227. */
  228. memcpy(&he_oper_vht_cap, he_oper->optional, 3);
  229. he_oper_vht_cap.basic_mcs_set = cpu_to_le16(0);
  230. if (!ieee80211_chandef_vht_oper(&sdata->local->hw, vht_cap_info,
  231. &he_oper_vht_cap, ht_oper,
  232. &vht_chandef)) {
  233. sdata_info(sdata,
  234. "HE AP VHT information is invalid, disabling HE\n");
  235. /* this will cause us to re-parse as VHT STA */
  236. return IEEE80211_CONN_MODE_VHT;
  237. }
  238. } else if (!vht_oper || !elems->vht_cap_elem) {
  239. if (sband->band == NL80211_BAND_5GHZ)
  240. return IEEE80211_CONN_MODE_HT;
  241. no_vht = true;
  242. } else if (sband->band == NL80211_BAND_2GHZ) {
  243. no_vht = true;
  244. } else if (!ieee80211_chandef_vht_oper(&sdata->local->hw,
  245. vht_cap_info,
  246. vht_oper, ht_oper,
  247. &vht_chandef)) {
  248. sdata_info(sdata,
  249. "AP VHT information is invalid, disabling VHT\n");
  250. return IEEE80211_CONN_MODE_HT;
  251. }
  252. if (!cfg80211_chandef_compatible(chandef, &vht_chandef)) {
  253. sdata_info(sdata,
  254. "AP VHT information doesn't match HT, disabling VHT\n");
  255. return IEEE80211_CONN_MODE_HT;
  256. }
  257. *chandef = vht_chandef;
  258. /* stick to current max mode if we or the AP don't have HE */
  259. if (conn->mode < IEEE80211_CONN_MODE_HE ||
  260. !elems->he_operation || !elems->he_cap) {
  261. if (no_vht)
  262. return IEEE80211_CONN_MODE_HT;
  263. return IEEE80211_CONN_MODE_VHT;
  264. }
  265. /* stick to HE if we or the AP don't have EHT */
  266. if (conn->mode < IEEE80211_CONN_MODE_EHT ||
  267. !eht_oper || !elems->eht_cap)
  268. return IEEE80211_CONN_MODE_HE;
  269. /*
  270. * handle the case that the EHT operation indicates that it holds EHT
  271. * operation information (in case that the channel width differs from
  272. * the channel width reported in HT/VHT/HE).
  273. */
  274. if (eht_oper->params & IEEE80211_EHT_OPER_INFO_PRESENT) {
  275. struct cfg80211_chan_def eht_chandef = *chandef;
  276. ieee80211_chandef_eht_oper((const void *)eht_oper->optional,
  277. &eht_chandef);
  278. eht_chandef.punctured =
  279. ieee80211_eht_oper_dis_subchan_bitmap(eht_oper);
  280. if (!cfg80211_chandef_valid(&eht_chandef)) {
  281. sdata_info(sdata,
  282. "AP EHT information is invalid, disabling EHT\n");
  283. return IEEE80211_CONN_MODE_HE;
  284. }
  285. if (!cfg80211_chandef_compatible(chandef, &eht_chandef)) {
  286. sdata_info(sdata,
  287. "AP EHT information doesn't match HT/VHT/HE, disabling EHT\n");
  288. return IEEE80211_CONN_MODE_HE;
  289. }
  290. *chandef = eht_chandef;
  291. }
  292. check_uhr:
  293. if (conn->mode < IEEE80211_CONN_MODE_UHR || !uhr_oper)
  294. return IEEE80211_CONN_MODE_EHT;
  295. /*
  296. * In beacons we don't have all the data - but we know the size was OK,
  297. * so if the size is valid as a non-beacon case, we have more data and
  298. * can validate the NPCA parameters.
  299. */
  300. if (ieee80211_uhr_oper_size_ok((const void *)uhr_oper,
  301. elems->uhr_operation_len,
  302. false)) {
  303. struct cfg80211_chan_def npca_chandef = *chandef;
  304. const struct ieee80211_uhr_npca_info *npca;
  305. const __le16 *dis_subch_bmap;
  306. u16 punct = chandef->punctured, npca_punct;
  307. npca = ieee80211_uhr_npca_info(uhr_oper);
  308. if (npca) {
  309. int width = cfg80211_chandef_get_width(chandef);
  310. u8 offs = le32_get_bits(npca->params,
  311. IEEE80211_UHR_NPCA_PARAMS_PRIMARY_CHAN_OFFS);
  312. u32 cf1 = chandef->center_freq1;
  313. bool pri_upper, npca_upper;
  314. pri_upper = chandef->chan->center_freq > cf1;
  315. npca_upper = 20 * offs >= width / 2;
  316. if (20 * offs >= cfg80211_chandef_get_width(chandef) ||
  317. pri_upper == npca_upper) {
  318. sdata_info(sdata,
  319. "AP UHR NPCA primary channel invalid, disabling UHR\n");
  320. return IEEE80211_CONN_MODE_EHT;
  321. }
  322. }
  323. dis_subch_bmap = ieee80211_uhr_npca_dis_subch_bitmap(uhr_oper);
  324. if (dis_subch_bmap) {
  325. npca_punct = get_unaligned_le16(dis_subch_bmap);
  326. npca_chandef.punctured = npca_punct;
  327. }
  328. /*
  329. * must be a valid puncturing pattern for this channel as
  330. * well as puncturing all subchannels that are already in
  331. * the disabled subchannel bitmap on the primary channel
  332. */
  333. if (!cfg80211_chandef_valid(&npca_chandef) ||
  334. ((punct & npca_punct) != punct)) {
  335. sdata_info(sdata,
  336. "AP UHR NPCA disabled subchannel bitmap invalid, disabling UHR\n");
  337. return IEEE80211_CONN_MODE_EHT;
  338. }
  339. }
  340. return IEEE80211_CONN_MODE_UHR;
  341. }
  342. static bool
  343. ieee80211_verify_sta_ht_mcs_support(struct ieee80211_sub_if_data *sdata,
  344. struct ieee80211_supported_band *sband,
  345. const struct ieee80211_ht_operation *ht_op)
  346. {
  347. struct ieee80211_sta_ht_cap sta_ht_cap;
  348. int i;
  349. if (sband->band == NL80211_BAND_6GHZ)
  350. return true;
  351. if (!ht_op)
  352. return false;
  353. memcpy(&sta_ht_cap, &sband->ht_cap, sizeof(sta_ht_cap));
  354. ieee80211_apply_htcap_overrides(sdata, &sta_ht_cap);
  355. /*
  356. * P802.11REVme/D7.0 - 6.5.4.2.4
  357. * ...
  358. * If the MLME of an HT STA receives an MLME-JOIN.request primitive
  359. * with the SelectedBSS parameter containing a Basic HT-MCS Set field
  360. * in the HT Operation parameter that contains any unsupported MCSs,
  361. * the MLME response in the resulting MLME-JOIN.confirm primitive shall
  362. * contain a ResultCode parameter that is not set to the value SUCCESS.
  363. * ...
  364. */
  365. /* Simply check that all basic rates are in the STA RX mask */
  366. for (i = 0; i < IEEE80211_HT_MCS_MASK_LEN; i++) {
  367. if ((ht_op->basic_set[i] & sta_ht_cap.mcs.rx_mask[i]) !=
  368. ht_op->basic_set[i])
  369. return false;
  370. }
  371. return true;
  372. }
  373. static bool
  374. ieee80211_verify_sta_vht_mcs_support(struct ieee80211_sub_if_data *sdata,
  375. int link_id,
  376. struct ieee80211_supported_band *sband,
  377. const struct ieee80211_vht_operation *vht_op)
  378. {
  379. struct ieee80211_sta_vht_cap sta_vht_cap;
  380. u16 ap_min_req_set, sta_rx_mcs_map, sta_tx_mcs_map;
  381. int nss;
  382. if (sband->band != NL80211_BAND_5GHZ)
  383. return true;
  384. if (!vht_op)
  385. return false;
  386. memcpy(&sta_vht_cap, &sband->vht_cap, sizeof(sta_vht_cap));
  387. ieee80211_apply_vhtcap_overrides(sdata, &sta_vht_cap);
  388. ap_min_req_set = le16_to_cpu(vht_op->basic_mcs_set);
  389. sta_rx_mcs_map = le16_to_cpu(sta_vht_cap.vht_mcs.rx_mcs_map);
  390. sta_tx_mcs_map = le16_to_cpu(sta_vht_cap.vht_mcs.tx_mcs_map);
  391. /*
  392. * Many APs are incorrectly advertising an all-zero value here,
  393. * which really means MCS 0-7 are required for 1-8 streams, but
  394. * they don't really mean it that way.
  395. * Some other APs are incorrectly advertising 3 spatial streams
  396. * with MCS 0-7 are required, but don't really mean it that way
  397. * and we'll connect only with HT, rather than even HE.
  398. * As a result, unfortunately the VHT basic MCS/NSS set cannot
  399. * be used at all, so check it only in strict mode.
  400. */
  401. if (!ieee80211_hw_check(&sdata->local->hw, STRICT))
  402. return true;
  403. /*
  404. * P802.11REVme/D7.0 - 6.5.4.2.4
  405. * ...
  406. * If the MLME of a VHT STA receives an MLME-JOIN.request primitive
  407. * with a SelectedBSS parameter containing a Basic VHT-MCS And NSS Set
  408. * field in the VHT Operation parameter that contains any unsupported
  409. * <VHT-MCS, NSS> tuple, the MLME response in the resulting
  410. * MLME-JOIN.confirm primitive shall contain a ResultCode parameter
  411. * that is not set to the value SUCCESS.
  412. * ...
  413. */
  414. for (nss = 8; nss > 0; nss--) {
  415. u8 ap_op_val = (ap_min_req_set >> (2 * (nss - 1))) & 3;
  416. u8 sta_rx_val;
  417. u8 sta_tx_val;
  418. if (ap_op_val == IEEE80211_HE_MCS_NOT_SUPPORTED)
  419. continue;
  420. sta_rx_val = (sta_rx_mcs_map >> (2 * (nss - 1))) & 3;
  421. sta_tx_val = (sta_tx_mcs_map >> (2 * (nss - 1))) & 3;
  422. if (sta_rx_val == IEEE80211_HE_MCS_NOT_SUPPORTED ||
  423. sta_tx_val == IEEE80211_HE_MCS_NOT_SUPPORTED ||
  424. sta_rx_val < ap_op_val || sta_tx_val < ap_op_val) {
  425. link_id_info(sdata, link_id,
  426. "Missing mandatory rates for %d Nss, rx %d, tx %d oper %d, disable VHT\n",
  427. nss, sta_rx_val, sta_tx_val, ap_op_val);
  428. return false;
  429. }
  430. }
  431. return true;
  432. }
  433. static bool
  434. ieee80211_verify_peer_he_mcs_support(struct ieee80211_sub_if_data *sdata,
  435. int link_id,
  436. const struct ieee80211_he_cap_elem *he_cap,
  437. const struct ieee80211_he_operation *he_op)
  438. {
  439. struct ieee80211_he_mcs_nss_supp *he_mcs_nss_supp;
  440. u16 mcs_80_map_tx, mcs_80_map_rx;
  441. u16 ap_min_req_set;
  442. int nss;
  443. if (!he_cap)
  444. return false;
  445. /* mcs_nss is right after he_cap info */
  446. he_mcs_nss_supp = (void *)(he_cap + 1);
  447. mcs_80_map_tx = le16_to_cpu(he_mcs_nss_supp->tx_mcs_80);
  448. mcs_80_map_rx = le16_to_cpu(he_mcs_nss_supp->rx_mcs_80);
  449. /* P802.11-REVme/D0.3
  450. * 27.1.1 Introduction to the HE PHY
  451. * ...
  452. * An HE STA shall support the following features:
  453. * ...
  454. * Single spatial stream HE-MCSs 0 to 7 (transmit and receive) in all
  455. * supported channel widths for HE SU PPDUs
  456. */
  457. if ((mcs_80_map_tx & 0x3) == IEEE80211_HE_MCS_NOT_SUPPORTED ||
  458. (mcs_80_map_rx & 0x3) == IEEE80211_HE_MCS_NOT_SUPPORTED) {
  459. link_id_info(sdata, link_id,
  460. "Missing mandatory rates for 1 Nss, rx 0x%x, tx 0x%x, disable HE\n",
  461. mcs_80_map_tx, mcs_80_map_rx);
  462. return false;
  463. }
  464. if (!he_op)
  465. return true;
  466. ap_min_req_set = le16_to_cpu(he_op->he_mcs_nss_set);
  467. /*
  468. * Apparently iPhone 13 (at least iOS version 15.3.1) sets this to all
  469. * zeroes, which is nonsense, and completely inconsistent with itself
  470. * (it doesn't have 8 streams). Accept the settings in this case anyway.
  471. */
  472. if (!ieee80211_hw_check(&sdata->local->hw, STRICT) && !ap_min_req_set)
  473. return true;
  474. /* make sure the AP is consistent with itself
  475. *
  476. * P802.11-REVme/D0.3
  477. * 26.17.1 Basic HE BSS operation
  478. *
  479. * A STA that is operating in an HE BSS shall be able to receive and
  480. * transmit at each of the <HE-MCS, NSS> tuple values indicated by the
  481. * Basic HE-MCS And NSS Set field of the HE Operation parameter of the
  482. * MLME-START.request primitive and shall be able to receive at each of
  483. * the <HE-MCS, NSS> tuple values indicated by the Supported HE-MCS and
  484. * NSS Set field in the HE Capabilities parameter of the MLMESTART.request
  485. * primitive
  486. */
  487. for (nss = 8; nss > 0; nss--) {
  488. u8 ap_op_val = (ap_min_req_set >> (2 * (nss - 1))) & 3;
  489. u8 ap_rx_val;
  490. u8 ap_tx_val;
  491. if (ap_op_val == IEEE80211_HE_MCS_NOT_SUPPORTED)
  492. continue;
  493. ap_rx_val = (mcs_80_map_rx >> (2 * (nss - 1))) & 3;
  494. ap_tx_val = (mcs_80_map_tx >> (2 * (nss - 1))) & 3;
  495. if (ap_rx_val == IEEE80211_HE_MCS_NOT_SUPPORTED ||
  496. ap_tx_val == IEEE80211_HE_MCS_NOT_SUPPORTED ||
  497. ap_rx_val < ap_op_val || ap_tx_val < ap_op_val) {
  498. link_id_info(sdata, link_id,
  499. "Invalid rates for %d Nss, rx %d, tx %d oper %d, disable HE\n",
  500. nss, ap_rx_val, ap_tx_val, ap_op_val);
  501. return false;
  502. }
  503. }
  504. return true;
  505. }
  506. static bool
  507. ieee80211_verify_sta_he_mcs_support(struct ieee80211_sub_if_data *sdata,
  508. struct ieee80211_supported_band *sband,
  509. const struct ieee80211_he_operation *he_op)
  510. {
  511. const struct ieee80211_sta_he_cap *sta_he_cap =
  512. ieee80211_get_he_iftype_cap_vif(sband, &sdata->vif);
  513. u16 ap_min_req_set;
  514. int i;
  515. if (!sta_he_cap || !he_op)
  516. return false;
  517. ap_min_req_set = le16_to_cpu(he_op->he_mcs_nss_set);
  518. /*
  519. * Apparently iPhone 13 (at least iOS version 15.3.1) sets this to all
  520. * zeroes, which is nonsense, and completely inconsistent with itself
  521. * (it doesn't have 8 streams). Accept the settings in this case anyway.
  522. */
  523. if (!ieee80211_hw_check(&sdata->local->hw, STRICT) && !ap_min_req_set)
  524. return true;
  525. /* Need to go over for 80MHz, 160MHz and for 80+80 */
  526. for (i = 0; i < 3; i++) {
  527. const struct ieee80211_he_mcs_nss_supp *sta_mcs_nss_supp =
  528. &sta_he_cap->he_mcs_nss_supp;
  529. u16 sta_mcs_map_rx =
  530. le16_to_cpu(((__le16 *)sta_mcs_nss_supp)[2 * i]);
  531. u16 sta_mcs_map_tx =
  532. le16_to_cpu(((__le16 *)sta_mcs_nss_supp)[2 * i + 1]);
  533. u8 nss;
  534. bool verified = true;
  535. /*
  536. * For each band there is a maximum of 8 spatial streams
  537. * possible. Each of the sta_mcs_map_* is a 16-bit struct built
  538. * of 2 bits per NSS (1-8), with the values defined in enum
  539. * ieee80211_he_mcs_support. Need to make sure STA TX and RX
  540. * capabilities aren't less than the AP's minimum requirements
  541. * for this HE BSS per SS.
  542. * It is enough to find one such band that meets the reqs.
  543. */
  544. for (nss = 8; nss > 0; nss--) {
  545. u8 sta_rx_val = (sta_mcs_map_rx >> (2 * (nss - 1))) & 3;
  546. u8 sta_tx_val = (sta_mcs_map_tx >> (2 * (nss - 1))) & 3;
  547. u8 ap_val = (ap_min_req_set >> (2 * (nss - 1))) & 3;
  548. if (ap_val == IEEE80211_HE_MCS_NOT_SUPPORTED)
  549. continue;
  550. /*
  551. * Make sure the HE AP doesn't require MCSs that aren't
  552. * supported by the client as required by spec
  553. *
  554. * P802.11-REVme/D0.3
  555. * 26.17.1 Basic HE BSS operation
  556. *
  557. * An HE STA shall not attempt to join * (MLME-JOIN.request primitive)
  558. * a BSS, unless it supports (i.e., is able to both transmit and
  559. * receive using) all of the <HE-MCS, NSS> tuples in the basic
  560. * HE-MCS and NSS set.
  561. */
  562. if (sta_rx_val == IEEE80211_HE_MCS_NOT_SUPPORTED ||
  563. sta_tx_val == IEEE80211_HE_MCS_NOT_SUPPORTED ||
  564. (ap_val > sta_rx_val) || (ap_val > sta_tx_val)) {
  565. verified = false;
  566. break;
  567. }
  568. }
  569. if (verified)
  570. return true;
  571. }
  572. /* If here, STA doesn't meet AP's HE min requirements */
  573. return false;
  574. }
  575. static u8
  576. ieee80211_get_eht_cap_mcs_nss(const struct ieee80211_sta_he_cap *sta_he_cap,
  577. const struct ieee80211_sta_eht_cap *sta_eht_cap,
  578. unsigned int idx, int bw)
  579. {
  580. u8 he_phy_cap0 = sta_he_cap->he_cap_elem.phy_cap_info[0];
  581. u8 eht_phy_cap0 = sta_eht_cap->eht_cap_elem.phy_cap_info[0];
  582. /* handle us being a 20 MHz-only EHT STA - with four values
  583. * for MCS 0-7, 8-9, 10-11, 12-13.
  584. */
  585. if (!(he_phy_cap0 & IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_MASK_ALL))
  586. return sta_eht_cap->eht_mcs_nss_supp.only_20mhz.rx_tx_max_nss[idx];
  587. /* the others have MCS 0-9 together, rather than separately from 0-7 */
  588. if (idx > 0)
  589. idx--;
  590. switch (bw) {
  591. case 0:
  592. return sta_eht_cap->eht_mcs_nss_supp.bw._80.rx_tx_max_nss[idx];
  593. case 1:
  594. if (!(he_phy_cap0 &
  595. (IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G |
  596. IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_80PLUS80_MHZ_IN_5G)))
  597. return 0xff; /* pass check */
  598. return sta_eht_cap->eht_mcs_nss_supp.bw._160.rx_tx_max_nss[idx];
  599. case 2:
  600. if (!(eht_phy_cap0 & IEEE80211_EHT_PHY_CAP0_320MHZ_IN_6GHZ))
  601. return 0xff; /* pass check */
  602. return sta_eht_cap->eht_mcs_nss_supp.bw._320.rx_tx_max_nss[idx];
  603. }
  604. WARN_ON(1);
  605. return 0;
  606. }
  607. static bool
  608. ieee80211_verify_sta_eht_mcs_support(struct ieee80211_sub_if_data *sdata,
  609. struct ieee80211_supported_band *sband,
  610. const struct ieee80211_eht_operation *eht_op)
  611. {
  612. const struct ieee80211_sta_he_cap *sta_he_cap =
  613. ieee80211_get_he_iftype_cap_vif(sband, &sdata->vif);
  614. const struct ieee80211_sta_eht_cap *sta_eht_cap =
  615. ieee80211_get_eht_iftype_cap_vif(sband, &sdata->vif);
  616. const struct ieee80211_eht_mcs_nss_supp_20mhz_only *req;
  617. unsigned int i;
  618. if (!sta_he_cap || !sta_eht_cap || !eht_op)
  619. return false;
  620. req = &eht_op->basic_mcs_nss;
  621. for (i = 0; i < ARRAY_SIZE(req->rx_tx_max_nss); i++) {
  622. u8 req_rx_nss, req_tx_nss;
  623. unsigned int bw;
  624. req_rx_nss = u8_get_bits(req->rx_tx_max_nss[i],
  625. IEEE80211_EHT_MCS_NSS_RX);
  626. req_tx_nss = u8_get_bits(req->rx_tx_max_nss[i],
  627. IEEE80211_EHT_MCS_NSS_TX);
  628. for (bw = 0; bw < 3; bw++) {
  629. u8 have, have_rx_nss, have_tx_nss;
  630. have = ieee80211_get_eht_cap_mcs_nss(sta_he_cap,
  631. sta_eht_cap,
  632. i, bw);
  633. have_rx_nss = u8_get_bits(have,
  634. IEEE80211_EHT_MCS_NSS_RX);
  635. have_tx_nss = u8_get_bits(have,
  636. IEEE80211_EHT_MCS_NSS_TX);
  637. if (req_rx_nss > have_rx_nss ||
  638. req_tx_nss > have_tx_nss)
  639. return false;
  640. }
  641. }
  642. return true;
  643. }
  644. static void ieee80211_get_rates(struct ieee80211_supported_band *sband,
  645. const u8 *supp_rates,
  646. unsigned int supp_rates_len,
  647. const u8 *ext_supp_rates,
  648. unsigned int ext_supp_rates_len,
  649. u32 *rates, u32 *basic_rates,
  650. unsigned long *unknown_rates_selectors,
  651. bool *have_higher_than_11mbit,
  652. int *min_rate, int *min_rate_index)
  653. {
  654. int i, j;
  655. for (i = 0; i < supp_rates_len + ext_supp_rates_len; i++) {
  656. u8 supp_rate = i < supp_rates_len ?
  657. supp_rates[i] :
  658. ext_supp_rates[i - supp_rates_len];
  659. int rate = supp_rate & 0x7f;
  660. bool is_basic = !!(supp_rate & 0x80);
  661. if ((rate * 5) > 110 && have_higher_than_11mbit)
  662. *have_higher_than_11mbit = true;
  663. /*
  664. * Skip membership selectors since they're not rates.
  665. *
  666. * Note: Even though the membership selector and the basic
  667. * rate flag share the same bit, they are not exactly
  668. * the same.
  669. */
  670. if (is_basic && rate >= BSS_MEMBERSHIP_SELECTOR_MIN) {
  671. if (unknown_rates_selectors)
  672. set_bit(rate, unknown_rates_selectors);
  673. continue;
  674. }
  675. for (j = 0; j < sband->n_bitrates; j++) {
  676. struct ieee80211_rate *br;
  677. int brate;
  678. br = &sband->bitrates[j];
  679. brate = DIV_ROUND_UP(br->bitrate, 5);
  680. if (brate == rate) {
  681. if (rates)
  682. *rates |= BIT(j);
  683. if (is_basic && basic_rates)
  684. *basic_rates |= BIT(j);
  685. if (min_rate && (rate * 5) < *min_rate) {
  686. *min_rate = rate * 5;
  687. if (min_rate_index)
  688. *min_rate_index = j;
  689. }
  690. break;
  691. }
  692. }
  693. /* Handle an unknown entry as if it is an unknown selector */
  694. if (is_basic && unknown_rates_selectors && j == sband->n_bitrates)
  695. set_bit(rate, unknown_rates_selectors);
  696. }
  697. }
  698. static bool ieee80211_chandef_usable(struct ieee80211_sub_if_data *sdata,
  699. const struct cfg80211_chan_def *chandef,
  700. u32 prohibited_flags)
  701. {
  702. if (!cfg80211_chandef_usable(sdata->local->hw.wiphy,
  703. chandef, prohibited_flags))
  704. return false;
  705. if (chandef->punctured &&
  706. ieee80211_hw_check(&sdata->local->hw, DISALLOW_PUNCTURING))
  707. return false;
  708. return true;
  709. }
  710. static int ieee80211_chandef_num_subchans(const struct cfg80211_chan_def *c)
  711. {
  712. if (c->width == NL80211_CHAN_WIDTH_80P80)
  713. return 4 + 4;
  714. return cfg80211_chandef_get_width(c) / 20;
  715. }
  716. static int ieee80211_chandef_num_widths(const struct cfg80211_chan_def *c)
  717. {
  718. switch (c->width) {
  719. case NL80211_CHAN_WIDTH_20:
  720. case NL80211_CHAN_WIDTH_20_NOHT:
  721. return 1;
  722. case NL80211_CHAN_WIDTH_40:
  723. return 2;
  724. case NL80211_CHAN_WIDTH_80P80:
  725. case NL80211_CHAN_WIDTH_80:
  726. return 3;
  727. case NL80211_CHAN_WIDTH_160:
  728. return 4;
  729. case NL80211_CHAN_WIDTH_320:
  730. return 5;
  731. default:
  732. WARN_ON(1);
  733. return 0;
  734. }
  735. }
  736. VISIBLE_IF_MAC80211_KUNIT int
  737. ieee80211_calc_chandef_subchan_offset(const struct cfg80211_chan_def *ap,
  738. u8 n_partial_subchans)
  739. {
  740. int n = ieee80211_chandef_num_subchans(ap);
  741. struct cfg80211_chan_def tmp = *ap;
  742. int offset = 0;
  743. /*
  744. * Given a chandef (in this context, it's the AP's) and a number
  745. * of subchannels that we want to look at ('n_partial_subchans'),
  746. * calculate the offset in number of subchannels between the full
  747. * and the subset with the desired width.
  748. */
  749. /* same number of subchannels means no offset, obviously */
  750. if (n == n_partial_subchans)
  751. return 0;
  752. /* don't WARN - misconfigured APs could cause this if their N > width */
  753. if (n < n_partial_subchans)
  754. return 0;
  755. while (ieee80211_chandef_num_subchans(&tmp) > n_partial_subchans) {
  756. u32 prev = tmp.center_freq1;
  757. ieee80211_chandef_downgrade(&tmp, NULL);
  758. /*
  759. * if center_freq moved up, half the original channels
  760. * are gone now but were below, so increase offset
  761. */
  762. if (prev < tmp.center_freq1)
  763. offset += ieee80211_chandef_num_subchans(&tmp);
  764. }
  765. /*
  766. * 80+80 with secondary 80 below primary - four subchannels for it
  767. * (we cannot downgrade *to* 80+80, so no need to consider 'tmp')
  768. */
  769. if (ap->width == NL80211_CHAN_WIDTH_80P80 &&
  770. ap->center_freq2 < ap->center_freq1)
  771. offset += 4;
  772. return offset;
  773. }
  774. EXPORT_SYMBOL_IF_MAC80211_KUNIT(ieee80211_calc_chandef_subchan_offset);
  775. VISIBLE_IF_MAC80211_KUNIT void
  776. ieee80211_rearrange_tpe_psd(struct ieee80211_parsed_tpe_psd *psd,
  777. const struct cfg80211_chan_def *ap,
  778. const struct cfg80211_chan_def *used)
  779. {
  780. u8 needed = ieee80211_chandef_num_subchans(used);
  781. u8 have = ieee80211_chandef_num_subchans(ap);
  782. u8 tmp[IEEE80211_TPE_PSD_ENTRIES_320MHZ];
  783. u8 offset;
  784. if (!psd->valid)
  785. return;
  786. /* if N is zero, all defaults were used, no point in rearranging */
  787. if (!psd->n)
  788. goto out;
  789. BUILD_BUG_ON(sizeof(tmp) != sizeof(psd->power));
  790. /*
  791. * This assumes that 'N' is consistent with the HE channel, as
  792. * it should be (otherwise the AP is broken).
  793. *
  794. * In psd->power we have values in the order 0..N, 0..K, where
  795. * N+K should cover the entire channel per 'ap', but even if it
  796. * doesn't then we've pre-filled 'unlimited' as defaults.
  797. *
  798. * But this is all the wrong order, we want to have them in the
  799. * order of the 'used' channel.
  800. *
  801. * So for example, we could have a 320 MHz EHT AP, which has the
  802. * HE channel as 80 MHz (e.g. due to puncturing, which doesn't
  803. * seem to be considered for the TPE), as follows:
  804. *
  805. * EHT 320: | | | | | | | | | | | | | | | | |
  806. * HE 80: | | | | |
  807. * used 160: | | | | | | | | |
  808. *
  809. * N entries: |--|--|--|--|
  810. * K entries: |--|--|--|--|--|--|--|--| |--|--|--|--|
  811. * power idx: 4 5 6 7 8 9 10 11 0 1 2 3 12 13 14 15
  812. * full chan: 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
  813. * used chan: 0 1 2 3 4 5 6 7
  814. *
  815. * The idx in the power array ('power idx') is like this since it
  816. * comes directly from the element's N and K entries in their
  817. * element order, and those are this way for HE compatibility.
  818. *
  819. * Rearrange them as desired here, first by putting them into the
  820. * 'full chan' order, and then selecting the necessary subset for
  821. * the 'used chan'.
  822. */
  823. /* first reorder according to AP channel */
  824. offset = ieee80211_calc_chandef_subchan_offset(ap, psd->n);
  825. for (int i = 0; i < have; i++) {
  826. if (i < offset)
  827. tmp[i] = psd->power[i + psd->n];
  828. else if (i < offset + psd->n)
  829. tmp[i] = psd->power[i - offset];
  830. else
  831. tmp[i] = psd->power[i];
  832. }
  833. /*
  834. * and then select the subset for the used channel
  835. * (set everything to defaults first in case a driver is confused)
  836. */
  837. memset(psd->power, IEEE80211_TPE_PSD_NO_LIMIT, sizeof(psd->power));
  838. offset = ieee80211_calc_chandef_subchan_offset(ap, needed);
  839. for (int i = 0; i < needed; i++)
  840. psd->power[i] = tmp[offset + i];
  841. out:
  842. /* limit, but don't lie if there are defaults in the data */
  843. if (needed < psd->count)
  844. psd->count = needed;
  845. }
  846. EXPORT_SYMBOL_IF_MAC80211_KUNIT(ieee80211_rearrange_tpe_psd);
  847. static void ieee80211_rearrange_tpe(struct ieee80211_parsed_tpe *tpe,
  848. const struct cfg80211_chan_def *ap,
  849. const struct cfg80211_chan_def *used)
  850. {
  851. /* ignore this completely for narrow/invalid channels */
  852. if (!ieee80211_chandef_num_subchans(ap) ||
  853. !ieee80211_chandef_num_subchans(used)) {
  854. ieee80211_clear_tpe(tpe);
  855. return;
  856. }
  857. for (int i = 0; i < 2; i++) {
  858. int needed_pwr_count;
  859. ieee80211_rearrange_tpe_psd(&tpe->psd_local[i], ap, used);
  860. ieee80211_rearrange_tpe_psd(&tpe->psd_reg_client[i], ap, used);
  861. /* limit this to the widths we actually need */
  862. needed_pwr_count = ieee80211_chandef_num_widths(used);
  863. if (needed_pwr_count < tpe->max_local[i].count)
  864. tpe->max_local[i].count = needed_pwr_count;
  865. if (needed_pwr_count < tpe->max_reg_client[i].count)
  866. tpe->max_reg_client[i].count = needed_pwr_count;
  867. }
  868. }
  869. /*
  870. * The AP part of the channel request is used to distinguish settings
  871. * to the device used for wider bandwidth OFDMA. This is used in the
  872. * channel context code to assign two channel contexts even if they're
  873. * both for the same channel, if the AP bandwidths are incompatible.
  874. * If not EHT (or driver override) then ap.chan == NULL indicates that
  875. * there's no wider BW OFDMA used.
  876. */
  877. static void ieee80211_set_chanreq_ap(struct ieee80211_sub_if_data *sdata,
  878. struct ieee80211_chan_req *chanreq,
  879. struct ieee80211_conn_settings *conn,
  880. struct cfg80211_chan_def *ap_chandef)
  881. {
  882. chanreq->ap.chan = NULL;
  883. if (conn->mode < IEEE80211_CONN_MODE_EHT)
  884. return;
  885. if (sdata->vif.driver_flags & IEEE80211_VIF_IGNORE_OFDMA_WIDER_BW)
  886. return;
  887. chanreq->ap = *ap_chandef;
  888. }
  889. VISIBLE_IF_MAC80211_KUNIT struct ieee802_11_elems *
  890. ieee80211_determine_chan_mode(struct ieee80211_sub_if_data *sdata,
  891. struct ieee80211_conn_settings *conn,
  892. struct cfg80211_bss *cbss, int link_id,
  893. struct ieee80211_chan_req *chanreq,
  894. struct cfg80211_chan_def *ap_chandef,
  895. unsigned long *userspace_selectors)
  896. {
  897. const struct cfg80211_bss_ies *ies = rcu_dereference(cbss->ies);
  898. struct ieee80211_bss *bss = (void *)cbss->priv;
  899. struct ieee80211_channel *channel = cbss->channel;
  900. struct ieee80211_elems_parse_params parse_params = {
  901. .link_id = -1,
  902. .from_ap = true,
  903. .start = ies->data,
  904. .len = ies->len,
  905. .type = ies->from_beacon ?
  906. IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_BEACON :
  907. IEEE80211_FTYPE_MGMT | IEEE80211_STYPE_PROBE_RESP,
  908. };
  909. struct ieee802_11_elems *elems;
  910. struct ieee80211_supported_band *sband;
  911. enum ieee80211_conn_mode ap_mode;
  912. unsigned long unknown_rates_selectors[BITS_TO_LONGS(128)] = {};
  913. unsigned long sta_selectors[BITS_TO_LONGS(128)] = {};
  914. int ret;
  915. again:
  916. parse_params.mode = conn->mode;
  917. elems = ieee802_11_parse_elems_full(&parse_params);
  918. if (!elems)
  919. return ERR_PTR(-ENOMEM);
  920. ap_mode = ieee80211_determine_ap_chan(sdata, channel, bss->vht_cap_info,
  921. elems, false, conn, ap_chandef);
  922. /* this should be impossible since parsing depends on our mode */
  923. if (WARN_ON(ap_mode > conn->mode)) {
  924. ret = -EINVAL;
  925. goto free;
  926. }
  927. if (conn->mode != ap_mode) {
  928. conn->mode = ap_mode;
  929. kfree(elems);
  930. goto again;
  931. }
  932. mlme_link_id_dbg(sdata, link_id, "determined AP %pM to be %s\n",
  933. cbss->bssid, ieee80211_conn_mode_str(ap_mode));
  934. sband = sdata->local->hw.wiphy->bands[channel->band];
  935. ieee80211_get_rates(sband, elems->supp_rates, elems->supp_rates_len,
  936. elems->ext_supp_rates, elems->ext_supp_rates_len,
  937. NULL, NULL, unknown_rates_selectors, NULL, NULL,
  938. NULL);
  939. switch (channel->band) {
  940. case NL80211_BAND_S1GHZ:
  941. if (WARN_ON(ap_mode != IEEE80211_CONN_MODE_S1G)) {
  942. ret = -EINVAL;
  943. goto free;
  944. }
  945. chanreq->oper = *ap_chandef;
  946. if (!cfg80211_chandef_usable(sdata->wdev.wiphy, &chanreq->oper,
  947. IEEE80211_CHAN_DISABLED)) {
  948. ret = -EINVAL;
  949. goto free;
  950. }
  951. return elems;
  952. case NL80211_BAND_6GHZ:
  953. if (ap_mode < IEEE80211_CONN_MODE_HE) {
  954. link_id_info(sdata, link_id,
  955. "Rejecting non-HE 6/7 GHz connection");
  956. ret = -EINVAL;
  957. goto free;
  958. }
  959. break;
  960. default:
  961. if (WARN_ON(ap_mode == IEEE80211_CONN_MODE_S1G)) {
  962. ret = -EINVAL;
  963. goto free;
  964. }
  965. }
  966. switch (ap_mode) {
  967. case IEEE80211_CONN_MODE_S1G:
  968. WARN_ON(1);
  969. ret = -EINVAL;
  970. goto free;
  971. case IEEE80211_CONN_MODE_LEGACY:
  972. conn->bw_limit = IEEE80211_CONN_BW_LIMIT_20;
  973. break;
  974. case IEEE80211_CONN_MODE_HT:
  975. conn->bw_limit = min_t(enum ieee80211_conn_bw_limit,
  976. conn->bw_limit,
  977. IEEE80211_CONN_BW_LIMIT_40);
  978. break;
  979. case IEEE80211_CONN_MODE_VHT:
  980. case IEEE80211_CONN_MODE_HE:
  981. conn->bw_limit = min_t(enum ieee80211_conn_bw_limit,
  982. conn->bw_limit,
  983. IEEE80211_CONN_BW_LIMIT_160);
  984. break;
  985. case IEEE80211_CONN_MODE_EHT:
  986. case IEEE80211_CONN_MODE_UHR:
  987. conn->bw_limit = min_t(enum ieee80211_conn_bw_limit,
  988. conn->bw_limit,
  989. IEEE80211_CONN_BW_LIMIT_320);
  990. break;
  991. }
  992. chanreq->oper = *ap_chandef;
  993. bitmap_copy(sta_selectors, userspace_selectors, 128);
  994. if (conn->mode >= IEEE80211_CONN_MODE_HT)
  995. set_bit(BSS_MEMBERSHIP_SELECTOR_HT_PHY, sta_selectors);
  996. if (conn->mode >= IEEE80211_CONN_MODE_VHT)
  997. set_bit(BSS_MEMBERSHIP_SELECTOR_VHT_PHY, sta_selectors);
  998. if (conn->mode >= IEEE80211_CONN_MODE_HE)
  999. set_bit(BSS_MEMBERSHIP_SELECTOR_HE_PHY, sta_selectors);
  1000. if (conn->mode >= IEEE80211_CONN_MODE_EHT)
  1001. set_bit(BSS_MEMBERSHIP_SELECTOR_EHT_PHY, sta_selectors);
  1002. if (conn->mode >= IEEE80211_CONN_MODE_UHR)
  1003. set_bit(BSS_MEMBERSHIP_SELECTOR_UHR_PHY, sta_selectors);
  1004. /*
  1005. * We do not support EPD or GLK so never add them.
  1006. * SAE_H2E is handled through userspace_selectors.
  1007. */
  1008. /* Check if we support all required features */
  1009. if (!bitmap_subset(unknown_rates_selectors, sta_selectors, 128)) {
  1010. link_id_info(sdata, link_id,
  1011. "required basic rate or BSS membership selectors not supported or disabled, rejecting connection\n");
  1012. ret = -EINVAL;
  1013. goto free;
  1014. }
  1015. ieee80211_set_chanreq_ap(sdata, chanreq, conn, ap_chandef);
  1016. while (!ieee80211_chandef_usable(sdata, &chanreq->oper,
  1017. IEEE80211_CHAN_DISABLED)) {
  1018. if (chanreq->oper.width == NL80211_CHAN_WIDTH_20_NOHT) {
  1019. link_id_info(sdata, link_id,
  1020. "unusable channel (%d MHz) for connection\n",
  1021. chanreq->oper.chan->center_freq);
  1022. ret = -EINVAL;
  1023. goto free;
  1024. }
  1025. ieee80211_chanreq_downgrade(chanreq, conn);
  1026. }
  1027. if (conn->mode >= IEEE80211_CONN_MODE_HE &&
  1028. !cfg80211_chandef_usable(sdata->wdev.wiphy, &chanreq->oper,
  1029. IEEE80211_CHAN_NO_HE)) {
  1030. conn->mode = IEEE80211_CONN_MODE_VHT;
  1031. conn->bw_limit = min_t(enum ieee80211_conn_bw_limit,
  1032. conn->bw_limit,
  1033. IEEE80211_CONN_BW_LIMIT_160);
  1034. }
  1035. if (conn->mode >= IEEE80211_CONN_MODE_EHT &&
  1036. !cfg80211_chandef_usable(sdata->wdev.wiphy, &chanreq->oper,
  1037. IEEE80211_CHAN_NO_EHT)) {
  1038. conn->mode = IEEE80211_CONN_MODE_HE;
  1039. conn->bw_limit = min_t(enum ieee80211_conn_bw_limit,
  1040. conn->bw_limit,
  1041. IEEE80211_CONN_BW_LIMIT_160);
  1042. }
  1043. if (conn->mode >= IEEE80211_CONN_MODE_UHR &&
  1044. !cfg80211_chandef_usable(sdata->wdev.wiphy, &chanreq->oper,
  1045. IEEE80211_CHAN_NO_UHR))
  1046. conn->mode = IEEE80211_CONN_MODE_EHT;
  1047. if (chanreq->oper.width != ap_chandef->width || ap_mode != conn->mode)
  1048. link_id_info(sdata, link_id,
  1049. "regulatory prevented using AP config, downgraded\n");
  1050. if (conn->mode >= IEEE80211_CONN_MODE_HT &&
  1051. !ieee80211_verify_sta_ht_mcs_support(sdata, sband,
  1052. elems->ht_operation)) {
  1053. conn->mode = IEEE80211_CONN_MODE_LEGACY;
  1054. conn->bw_limit = IEEE80211_CONN_BW_LIMIT_20;
  1055. link_id_info(sdata, link_id,
  1056. "required MCSes not supported, disabling HT\n");
  1057. }
  1058. if (conn->mode >= IEEE80211_CONN_MODE_VHT &&
  1059. !ieee80211_verify_sta_vht_mcs_support(sdata, link_id, sband,
  1060. elems->vht_operation)) {
  1061. conn->mode = IEEE80211_CONN_MODE_HT;
  1062. conn->bw_limit = min_t(enum ieee80211_conn_bw_limit,
  1063. conn->bw_limit,
  1064. IEEE80211_CONN_BW_LIMIT_40);
  1065. link_id_info(sdata, link_id,
  1066. "required MCSes not supported, disabling VHT\n");
  1067. }
  1068. if (conn->mode >= IEEE80211_CONN_MODE_HE &&
  1069. (!ieee80211_verify_peer_he_mcs_support(sdata, link_id,
  1070. (void *)elems->he_cap,
  1071. elems->he_operation) ||
  1072. !ieee80211_verify_sta_he_mcs_support(sdata, sband,
  1073. elems->he_operation))) {
  1074. conn->mode = IEEE80211_CONN_MODE_VHT;
  1075. link_id_info(sdata, link_id,
  1076. "required MCSes not supported, disabling HE\n");
  1077. }
  1078. if (conn->mode >= IEEE80211_CONN_MODE_EHT &&
  1079. !ieee80211_verify_sta_eht_mcs_support(sdata, sband,
  1080. elems->eht_operation)) {
  1081. conn->mode = IEEE80211_CONN_MODE_HE;
  1082. conn->bw_limit = min_t(enum ieee80211_conn_bw_limit,
  1083. conn->bw_limit,
  1084. IEEE80211_CONN_BW_LIMIT_160);
  1085. link_id_info(sdata, link_id,
  1086. "required MCSes not supported, disabling EHT\n");
  1087. }
  1088. if (conn->mode >= IEEE80211_CONN_MODE_EHT &&
  1089. channel->band != NL80211_BAND_2GHZ &&
  1090. conn->bw_limit == IEEE80211_CONN_BW_LIMIT_40) {
  1091. conn->mode = IEEE80211_CONN_MODE_HE;
  1092. link_id_info(sdata, link_id,
  1093. "required bandwidth not supported, disabling EHT\n");
  1094. }
  1095. /* the mode can only decrease, so this must terminate */
  1096. if (ap_mode != conn->mode) {
  1097. kfree(elems);
  1098. goto again;
  1099. }
  1100. mlme_link_id_dbg(sdata, link_id,
  1101. "connecting with %s mode, max bandwidth %d MHz\n",
  1102. ieee80211_conn_mode_str(conn->mode),
  1103. 20 * (1 << conn->bw_limit));
  1104. if (WARN_ON_ONCE(!cfg80211_chandef_valid(&chanreq->oper))) {
  1105. ret = -EINVAL;
  1106. goto free;
  1107. }
  1108. return elems;
  1109. free:
  1110. kfree(elems);
  1111. return ERR_PTR(ret);
  1112. }
  1113. EXPORT_SYMBOL_IF_MAC80211_KUNIT(ieee80211_determine_chan_mode);
  1114. static int ieee80211_config_bw(struct ieee80211_link_data *link,
  1115. struct ieee802_11_elems *elems,
  1116. bool update, u64 *changed, u16 stype)
  1117. {
  1118. struct ieee80211_channel *channel = link->conf->chanreq.oper.chan;
  1119. struct ieee80211_sub_if_data *sdata = link->sdata;
  1120. struct ieee80211_chan_req chanreq = {};
  1121. struct cfg80211_chan_def ap_chandef;
  1122. enum ieee80211_conn_mode ap_mode;
  1123. const char *frame;
  1124. u32 vht_cap_info = 0;
  1125. u16 ht_opmode;
  1126. int ret;
  1127. switch (stype) {
  1128. case IEEE80211_STYPE_BEACON:
  1129. frame = "beacon";
  1130. break;
  1131. case IEEE80211_STYPE_ASSOC_RESP:
  1132. frame = "assoc response";
  1133. break;
  1134. case IEEE80211_STYPE_REASSOC_RESP:
  1135. frame = "reassoc response";
  1136. break;
  1137. case IEEE80211_STYPE_ACTION:
  1138. /* the only action frame that gets here */
  1139. frame = "ML reconf response";
  1140. break;
  1141. default:
  1142. return -EINVAL;
  1143. }
  1144. /* don't track any bandwidth changes in legacy/S1G modes */
  1145. if (link->u.mgd.conn.mode == IEEE80211_CONN_MODE_LEGACY ||
  1146. link->u.mgd.conn.mode == IEEE80211_CONN_MODE_S1G)
  1147. return 0;
  1148. if (elems->vht_cap_elem)
  1149. vht_cap_info = le32_to_cpu(elems->vht_cap_elem->vht_cap_info);
  1150. ap_mode = ieee80211_determine_ap_chan(sdata, channel, vht_cap_info,
  1151. elems, true, &link->u.mgd.conn,
  1152. &ap_chandef);
  1153. if (ap_mode != link->u.mgd.conn.mode) {
  1154. link_info(link,
  1155. "AP %pM appears to change mode (expected %s, found %s) in %s, disconnect\n",
  1156. link->u.mgd.bssid,
  1157. ieee80211_conn_mode_str(link->u.mgd.conn.mode),
  1158. ieee80211_conn_mode_str(ap_mode), frame);
  1159. return -EINVAL;
  1160. }
  1161. chanreq.oper = ap_chandef;
  1162. ieee80211_set_chanreq_ap(sdata, &chanreq, &link->u.mgd.conn,
  1163. &ap_chandef);
  1164. /*
  1165. * if HT operation mode changed store the new one -
  1166. * this may be applicable even if channel is identical
  1167. */
  1168. if (elems->ht_operation) {
  1169. ht_opmode = le16_to_cpu(elems->ht_operation->operation_mode);
  1170. if (link->conf->ht_operation_mode != ht_opmode) {
  1171. *changed |= BSS_CHANGED_HT;
  1172. link->conf->ht_operation_mode = ht_opmode;
  1173. }
  1174. }
  1175. /*
  1176. * Downgrade the new channel if we associated with restricted
  1177. * bandwidth capabilities. For example, if we associated as a
  1178. * 20 MHz STA to a 40 MHz AP (due to regulatory, capabilities
  1179. * or config reasons) then switching to a 40 MHz channel now
  1180. * won't do us any good -- we couldn't use it with the AP.
  1181. */
  1182. while (link->u.mgd.conn.bw_limit <
  1183. ieee80211_min_bw_limit_from_chandef(&chanreq.oper))
  1184. ieee80211_chandef_downgrade(&chanreq.oper, NULL);
  1185. /* TPE element is not present in (re)assoc/ML reconfig response */
  1186. if (stype == IEEE80211_STYPE_BEACON &&
  1187. ap_chandef.chan->band == NL80211_BAND_6GHZ &&
  1188. link->u.mgd.conn.mode >= IEEE80211_CONN_MODE_HE) {
  1189. ieee80211_rearrange_tpe(&elems->tpe, &ap_chandef,
  1190. &chanreq.oper);
  1191. if (memcmp(&link->conf->tpe, &elems->tpe, sizeof(elems->tpe))) {
  1192. link->conf->tpe = elems->tpe;
  1193. *changed |= BSS_CHANGED_TPE;
  1194. }
  1195. }
  1196. if (ieee80211_chanreq_identical(&chanreq, &link->conf->chanreq))
  1197. return 0;
  1198. link_info(link,
  1199. "AP %pM changed bandwidth in %s, new used config is %d.%03d MHz, width %d (%d.%03d/%d MHz)\n",
  1200. link->u.mgd.bssid, frame, chanreq.oper.chan->center_freq,
  1201. chanreq.oper.chan->freq_offset, chanreq.oper.width,
  1202. chanreq.oper.center_freq1, chanreq.oper.freq1_offset,
  1203. chanreq.oper.center_freq2);
  1204. if (!cfg80211_chandef_valid(&chanreq.oper)) {
  1205. sdata_info(sdata,
  1206. "AP %pM changed caps/bw in %s in a way we can't support - disconnect\n",
  1207. link->u.mgd.bssid, frame);
  1208. return -EINVAL;
  1209. }
  1210. if (!update) {
  1211. link->conf->chanreq = chanreq;
  1212. return 0;
  1213. }
  1214. /*
  1215. * We're tracking the current AP here, so don't do any further checks
  1216. * here. This keeps us from playing ping-pong with regulatory, without
  1217. * it the following can happen (for example):
  1218. * - connect to an AP with 80 MHz, world regdom allows 80 MHz
  1219. * - AP advertises regdom US
  1220. * - CRDA loads regdom US with 80 MHz prohibited (old database)
  1221. * - we detect an unsupported channel and disconnect
  1222. * - disconnect causes CRDA to reload world regdomain and the game
  1223. * starts anew.
  1224. * (see https://bugzilla.kernel.org/show_bug.cgi?id=70881)
  1225. *
  1226. * It seems possible that there are still scenarios with CSA or real
  1227. * bandwidth changes where a this could happen, but those cases are
  1228. * less common and wouldn't completely prevent using the AP.
  1229. */
  1230. ret = ieee80211_link_change_chanreq(link, &chanreq, changed);
  1231. if (ret) {
  1232. sdata_info(sdata,
  1233. "AP %pM changed bandwidth in %s to incompatible one - disconnect\n",
  1234. link->u.mgd.bssid, frame);
  1235. return ret;
  1236. }
  1237. cfg80211_schedule_channels_check(&sdata->wdev);
  1238. return 0;
  1239. }
  1240. /* frame sending functions */
  1241. static void ieee80211_add_ht_ie(struct ieee80211_sub_if_data *sdata,
  1242. struct sk_buff *skb, u8 ap_ht_param,
  1243. struct ieee80211_supported_band *sband,
  1244. struct ieee80211_channel *channel,
  1245. enum ieee80211_smps_mode smps,
  1246. const struct ieee80211_conn_settings *conn)
  1247. {
  1248. u8 *pos;
  1249. u32 flags = channel->flags;
  1250. u16 cap;
  1251. struct ieee80211_sta_ht_cap ht_cap;
  1252. BUILD_BUG_ON(sizeof(ht_cap) != sizeof(sband->ht_cap));
  1253. memcpy(&ht_cap, &sband->ht_cap, sizeof(ht_cap));
  1254. ieee80211_apply_htcap_overrides(sdata, &ht_cap);
  1255. /* determine capability flags */
  1256. cap = ht_cap.cap;
  1257. switch (ap_ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET) {
  1258. case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
  1259. if (flags & IEEE80211_CHAN_NO_HT40PLUS) {
  1260. cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
  1261. cap &= ~IEEE80211_HT_CAP_SGI_40;
  1262. }
  1263. break;
  1264. case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
  1265. if (flags & IEEE80211_CHAN_NO_HT40MINUS) {
  1266. cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
  1267. cap &= ~IEEE80211_HT_CAP_SGI_40;
  1268. }
  1269. break;
  1270. }
  1271. /*
  1272. * If 40 MHz was disabled associate as though we weren't
  1273. * capable of 40 MHz -- some broken APs will never fall
  1274. * back to trying to transmit in 20 MHz.
  1275. */
  1276. if (conn->bw_limit <= IEEE80211_CONN_BW_LIMIT_20) {
  1277. cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
  1278. cap &= ~IEEE80211_HT_CAP_SGI_40;
  1279. }
  1280. /* set SM PS mode properly */
  1281. cap &= ~IEEE80211_HT_CAP_SM_PS;
  1282. switch (smps) {
  1283. case IEEE80211_SMPS_AUTOMATIC:
  1284. case IEEE80211_SMPS_NUM_MODES:
  1285. WARN_ON(1);
  1286. fallthrough;
  1287. case IEEE80211_SMPS_OFF:
  1288. cap |= WLAN_HT_CAP_SM_PS_DISABLED <<
  1289. IEEE80211_HT_CAP_SM_PS_SHIFT;
  1290. break;
  1291. case IEEE80211_SMPS_STATIC:
  1292. cap |= WLAN_HT_CAP_SM_PS_STATIC <<
  1293. IEEE80211_HT_CAP_SM_PS_SHIFT;
  1294. break;
  1295. case IEEE80211_SMPS_DYNAMIC:
  1296. cap |= WLAN_HT_CAP_SM_PS_DYNAMIC <<
  1297. IEEE80211_HT_CAP_SM_PS_SHIFT;
  1298. break;
  1299. }
  1300. /* reserve and fill IE */
  1301. pos = skb_put(skb, sizeof(struct ieee80211_ht_cap) + 2);
  1302. ieee80211_ie_build_ht_cap(pos, &ht_cap, cap);
  1303. }
  1304. /* This function determines vht capability flags for the association
  1305. * and builds the IE.
  1306. * Note - the function returns true to own the MU-MIMO capability
  1307. */
  1308. static bool ieee80211_add_vht_ie(struct ieee80211_sub_if_data *sdata,
  1309. struct sk_buff *skb,
  1310. struct ieee80211_supported_band *sband,
  1311. struct ieee80211_vht_cap *ap_vht_cap,
  1312. const struct ieee80211_conn_settings *conn)
  1313. {
  1314. struct ieee80211_local *local = sdata->local;
  1315. u8 *pos;
  1316. u32 cap;
  1317. struct ieee80211_sta_vht_cap vht_cap;
  1318. u32 mask, ap_bf_sts, our_bf_sts;
  1319. bool mu_mimo_owner = false;
  1320. BUILD_BUG_ON(sizeof(vht_cap) != sizeof(sband->vht_cap));
  1321. memcpy(&vht_cap, &sband->vht_cap, sizeof(vht_cap));
  1322. ieee80211_apply_vhtcap_overrides(sdata, &vht_cap);
  1323. /* determine capability flags */
  1324. cap = vht_cap.cap;
  1325. if (conn->bw_limit <= IEEE80211_CONN_BW_LIMIT_80) {
  1326. cap &= ~IEEE80211_VHT_CAP_SHORT_GI_160;
  1327. cap &= ~IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK;
  1328. }
  1329. /*
  1330. * Some APs apparently get confused if our capabilities are better
  1331. * than theirs, so restrict what we advertise in the assoc request.
  1332. */
  1333. if (!ieee80211_hw_check(&local->hw, STRICT)) {
  1334. if (!(ap_vht_cap->vht_cap_info &
  1335. cpu_to_le32(IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)))
  1336. cap &= ~(IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
  1337. IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE);
  1338. else if (!(ap_vht_cap->vht_cap_info &
  1339. cpu_to_le32(IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)))
  1340. cap &= ~IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
  1341. }
  1342. /*
  1343. * If some other vif is using the MU-MIMO capability we cannot associate
  1344. * using MU-MIMO - this will lead to contradictions in the group-id
  1345. * mechanism.
  1346. * Ownership is defined since association request, in order to avoid
  1347. * simultaneous associations with MU-MIMO.
  1348. */
  1349. if (cap & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE) {
  1350. bool disable_mu_mimo = false;
  1351. struct ieee80211_sub_if_data *other;
  1352. list_for_each_entry(other, &local->interfaces, list) {
  1353. if (other->vif.bss_conf.mu_mimo_owner) {
  1354. disable_mu_mimo = true;
  1355. break;
  1356. }
  1357. }
  1358. if (disable_mu_mimo)
  1359. cap &= ~IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
  1360. else
  1361. mu_mimo_owner = true;
  1362. }
  1363. mask = IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK;
  1364. ap_bf_sts = le32_to_cpu(ap_vht_cap->vht_cap_info) & mask;
  1365. our_bf_sts = cap & mask;
  1366. if (ap_bf_sts < our_bf_sts) {
  1367. cap &= ~mask;
  1368. cap |= ap_bf_sts;
  1369. }
  1370. /* reserve and fill IE */
  1371. pos = skb_put(skb, sizeof(struct ieee80211_vht_cap) + 2);
  1372. ieee80211_ie_build_vht_cap(pos, &vht_cap, cap);
  1373. return mu_mimo_owner;
  1374. }
  1375. static void ieee80211_assoc_add_rates(struct ieee80211_local *local,
  1376. struct sk_buff *skb,
  1377. enum nl80211_chan_width width,
  1378. struct ieee80211_supported_band *sband,
  1379. struct ieee80211_mgd_assoc_data *assoc_data)
  1380. {
  1381. u32 rates;
  1382. if (assoc_data->supp_rates_len &&
  1383. !ieee80211_hw_check(&local->hw, STRICT)) {
  1384. /*
  1385. * Get all rates supported by the device and the AP as
  1386. * some APs don't like getting a superset of their rates
  1387. * in the association request (e.g. D-Link DAP 1353 in
  1388. * b-only mode)...
  1389. */
  1390. ieee80211_parse_bitrates(sband,
  1391. assoc_data->supp_rates,
  1392. assoc_data->supp_rates_len,
  1393. &rates);
  1394. } else {
  1395. /*
  1396. * In case AP not provide any supported rates information
  1397. * before association, we send information element(s) with
  1398. * all rates that we support.
  1399. */
  1400. rates = ~0;
  1401. }
  1402. ieee80211_put_srates_elem(skb, sband, 0, ~rates,
  1403. WLAN_EID_SUPP_RATES);
  1404. ieee80211_put_srates_elem(skb, sband, 0, ~rates,
  1405. WLAN_EID_EXT_SUPP_RATES);
  1406. }
  1407. static size_t ieee80211_add_before_ht_elems(struct sk_buff *skb,
  1408. const u8 *elems,
  1409. size_t elems_len,
  1410. size_t offset)
  1411. {
  1412. size_t noffset;
  1413. static const u8 before_ht[] = {
  1414. WLAN_EID_SSID,
  1415. WLAN_EID_SUPP_RATES,
  1416. WLAN_EID_EXT_SUPP_RATES,
  1417. WLAN_EID_PWR_CAPABILITY,
  1418. WLAN_EID_SUPPORTED_CHANNELS,
  1419. WLAN_EID_RSN,
  1420. WLAN_EID_QOS_CAPA,
  1421. WLAN_EID_RRM_ENABLED_CAPABILITIES,
  1422. WLAN_EID_MOBILITY_DOMAIN,
  1423. WLAN_EID_FAST_BSS_TRANSITION, /* reassoc only */
  1424. WLAN_EID_RIC_DATA, /* reassoc only */
  1425. WLAN_EID_SUPPORTED_REGULATORY_CLASSES,
  1426. };
  1427. static const u8 after_ric[] = {
  1428. WLAN_EID_SUPPORTED_REGULATORY_CLASSES,
  1429. WLAN_EID_HT_CAPABILITY,
  1430. WLAN_EID_BSS_COEX_2040,
  1431. /* luckily this is almost always there */
  1432. WLAN_EID_EXT_CAPABILITY,
  1433. WLAN_EID_QOS_TRAFFIC_CAPA,
  1434. WLAN_EID_TIM_BCAST_REQ,
  1435. WLAN_EID_INTERWORKING,
  1436. /* 60 GHz (Multi-band, DMG, MMS) can't happen */
  1437. WLAN_EID_VHT_CAPABILITY,
  1438. WLAN_EID_OPMODE_NOTIF,
  1439. };
  1440. if (!elems_len)
  1441. return offset;
  1442. noffset = ieee80211_ie_split_ric(elems, elems_len,
  1443. before_ht,
  1444. ARRAY_SIZE(before_ht),
  1445. after_ric,
  1446. ARRAY_SIZE(after_ric),
  1447. offset);
  1448. skb_put_data(skb, elems + offset, noffset - offset);
  1449. return noffset;
  1450. }
  1451. static size_t ieee80211_add_before_vht_elems(struct sk_buff *skb,
  1452. const u8 *elems,
  1453. size_t elems_len,
  1454. size_t offset)
  1455. {
  1456. static const u8 before_vht[] = {
  1457. /*
  1458. * no need to list the ones split off before HT
  1459. * or generated here
  1460. */
  1461. WLAN_EID_BSS_COEX_2040,
  1462. WLAN_EID_EXT_CAPABILITY,
  1463. WLAN_EID_QOS_TRAFFIC_CAPA,
  1464. WLAN_EID_TIM_BCAST_REQ,
  1465. WLAN_EID_INTERWORKING,
  1466. /* 60 GHz (Multi-band, DMG, MMS) can't happen */
  1467. };
  1468. size_t noffset;
  1469. if (!elems_len)
  1470. return offset;
  1471. /* RIC already taken care of in ieee80211_add_before_ht_elems() */
  1472. noffset = ieee80211_ie_split(elems, elems_len,
  1473. before_vht, ARRAY_SIZE(before_vht),
  1474. offset);
  1475. skb_put_data(skb, elems + offset, noffset - offset);
  1476. return noffset;
  1477. }
  1478. static size_t ieee80211_add_before_he_elems(struct sk_buff *skb,
  1479. const u8 *elems,
  1480. size_t elems_len,
  1481. size_t offset)
  1482. {
  1483. static const u8 before_he[] = {
  1484. /*
  1485. * no need to list the ones split off before VHT
  1486. * or generated here
  1487. */
  1488. WLAN_EID_OPMODE_NOTIF,
  1489. WLAN_EID_EXTENSION, WLAN_EID_EXT_FUTURE_CHAN_GUIDANCE,
  1490. /* 11ai elements */
  1491. WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_SESSION,
  1492. WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_PUBLIC_KEY,
  1493. WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_KEY_CONFIRM,
  1494. WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_HLP_CONTAINER,
  1495. WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_IP_ADDR_ASSIGN,
  1496. /* TODO: add 11ah/11aj/11ak elements */
  1497. };
  1498. size_t noffset;
  1499. if (!elems_len)
  1500. return offset;
  1501. /* RIC already taken care of in ieee80211_add_before_ht_elems() */
  1502. noffset = ieee80211_ie_split(elems, elems_len,
  1503. before_he, ARRAY_SIZE(before_he),
  1504. offset);
  1505. skb_put_data(skb, elems + offset, noffset - offset);
  1506. return noffset;
  1507. }
  1508. static size_t ieee80211_add_before_reg_conn(struct sk_buff *skb,
  1509. const u8 *elems, size_t elems_len,
  1510. size_t offset)
  1511. {
  1512. static const u8 before_reg_conn[] = {
  1513. /*
  1514. * no need to list the ones split off before HE
  1515. * or generated here
  1516. */
  1517. WLAN_EID_EXTENSION, WLAN_EID_EXT_DH_PARAMETER,
  1518. WLAN_EID_EXTENSION, WLAN_EID_EXT_KNOWN_STA_IDENTIFCATION,
  1519. };
  1520. size_t noffset;
  1521. if (!elems_len)
  1522. return offset;
  1523. noffset = ieee80211_ie_split(elems, elems_len, before_reg_conn,
  1524. ARRAY_SIZE(before_reg_conn), offset);
  1525. skb_put_data(skb, elems + offset, noffset - offset);
  1526. return noffset;
  1527. }
  1528. #define PRESENT_ELEMS_MAX 8
  1529. #define PRESENT_ELEM_EXT_OFFS 0x100
  1530. static void
  1531. ieee80211_assoc_add_ml_elem(struct ieee80211_sub_if_data *sdata,
  1532. struct sk_buff *skb, u16 capab,
  1533. const struct element *ext_capa,
  1534. const u16 *present_elems,
  1535. struct ieee80211_mgd_assoc_data *assoc_data);
  1536. static size_t
  1537. ieee80211_add_link_elems(struct ieee80211_sub_if_data *sdata,
  1538. struct sk_buff *skb, u16 *capab,
  1539. const struct element *ext_capa,
  1540. const u8 *extra_elems,
  1541. size_t extra_elems_len,
  1542. unsigned int link_id,
  1543. struct ieee80211_link_data *link,
  1544. u16 *present_elems,
  1545. struct ieee80211_mgd_assoc_data *assoc_data)
  1546. {
  1547. enum nl80211_iftype iftype = ieee80211_vif_type_p2p(&sdata->vif);
  1548. struct cfg80211_bss *cbss = assoc_data->link[link_id].bss;
  1549. struct ieee80211_channel *chan = cbss->channel;
  1550. const struct ieee80211_sband_iftype_data *iftd;
  1551. struct ieee80211_local *local = sdata->local;
  1552. struct ieee80211_supported_band *sband;
  1553. enum nl80211_chan_width width = NL80211_CHAN_WIDTH_20;
  1554. struct ieee80211_chanctx_conf *chanctx_conf;
  1555. enum ieee80211_smps_mode smps_mode;
  1556. u16 orig_capab = *capab;
  1557. size_t offset = 0;
  1558. int present_elems_len = 0;
  1559. u8 *pos;
  1560. int i;
  1561. #define ADD_PRESENT_ELEM(id) do { \
  1562. /* need a last for termination - we use 0 == SSID */ \
  1563. if (!WARN_ON(present_elems_len >= PRESENT_ELEMS_MAX - 1)) \
  1564. present_elems[present_elems_len++] = (id); \
  1565. } while (0)
  1566. #define ADD_PRESENT_EXT_ELEM(id) ADD_PRESENT_ELEM(PRESENT_ELEM_EXT_OFFS | (id))
  1567. if (link)
  1568. smps_mode = link->smps_mode;
  1569. else if (sdata->u.mgd.powersave)
  1570. smps_mode = IEEE80211_SMPS_DYNAMIC;
  1571. else
  1572. smps_mode = IEEE80211_SMPS_OFF;
  1573. if (link) {
  1574. /*
  1575. * 5/10 MHz scenarios are only viable without MLO, in which
  1576. * case this pointer should be used ... All of this is a bit
  1577. * unclear though, not sure this even works at all.
  1578. */
  1579. rcu_read_lock();
  1580. chanctx_conf = rcu_dereference(link->conf->chanctx_conf);
  1581. if (chanctx_conf)
  1582. width = chanctx_conf->def.width;
  1583. rcu_read_unlock();
  1584. }
  1585. sband = local->hw.wiphy->bands[chan->band];
  1586. iftd = ieee80211_get_sband_iftype_data(sband, iftype);
  1587. if (sband->band == NL80211_BAND_2GHZ) {
  1588. *capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
  1589. *capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
  1590. }
  1591. if ((cbss->capability & WLAN_CAPABILITY_SPECTRUM_MGMT) &&
  1592. ieee80211_hw_check(&local->hw, SPECTRUM_MGMT))
  1593. *capab |= WLAN_CAPABILITY_SPECTRUM_MGMT;
  1594. if (sband->band != NL80211_BAND_S1GHZ)
  1595. ieee80211_assoc_add_rates(local, skb, width, sband, assoc_data);
  1596. if (*capab & WLAN_CAPABILITY_SPECTRUM_MGMT ||
  1597. *capab & WLAN_CAPABILITY_RADIO_MEASURE) {
  1598. struct cfg80211_chan_def chandef = {
  1599. .width = width,
  1600. .chan = chan,
  1601. };
  1602. pos = skb_put(skb, 4);
  1603. *pos++ = WLAN_EID_PWR_CAPABILITY;
  1604. *pos++ = 2;
  1605. *pos++ = 0; /* min tx power */
  1606. /* max tx power */
  1607. *pos++ = ieee80211_chandef_max_power(&chandef);
  1608. ADD_PRESENT_ELEM(WLAN_EID_PWR_CAPABILITY);
  1609. }
  1610. /*
  1611. * Per spec, we shouldn't include the list of channels if we advertise
  1612. * support for extended channel switching, but we've always done that;
  1613. * (for now?) apply this restriction only on the (new) 6 GHz band.
  1614. */
  1615. if (*capab & WLAN_CAPABILITY_SPECTRUM_MGMT &&
  1616. (sband->band != NL80211_BAND_6GHZ ||
  1617. !ext_capa || ext_capa->datalen < 1 ||
  1618. !(ext_capa->data[0] & WLAN_EXT_CAPA1_EXT_CHANNEL_SWITCHING))) {
  1619. /* TODO: get this in reg domain format */
  1620. pos = skb_put(skb, 2 * sband->n_channels + 2);
  1621. *pos++ = WLAN_EID_SUPPORTED_CHANNELS;
  1622. *pos++ = 2 * sband->n_channels;
  1623. for (i = 0; i < sband->n_channels; i++) {
  1624. int cf = sband->channels[i].center_freq;
  1625. *pos++ = ieee80211_frequency_to_channel(cf);
  1626. *pos++ = 1; /* one channel in the subband*/
  1627. }
  1628. ADD_PRESENT_ELEM(WLAN_EID_SUPPORTED_CHANNELS);
  1629. }
  1630. /* if present, add any custom IEs that go before HT */
  1631. offset = ieee80211_add_before_ht_elems(skb, extra_elems,
  1632. extra_elems_len,
  1633. offset);
  1634. if (sband->band != NL80211_BAND_6GHZ &&
  1635. assoc_data->link[link_id].conn.mode >= IEEE80211_CONN_MODE_HT) {
  1636. ieee80211_add_ht_ie(sdata, skb,
  1637. assoc_data->link[link_id].ap_ht_param,
  1638. sband, chan, smps_mode,
  1639. &assoc_data->link[link_id].conn);
  1640. ADD_PRESENT_ELEM(WLAN_EID_HT_CAPABILITY);
  1641. }
  1642. /* if present, add any custom IEs that go before VHT */
  1643. offset = ieee80211_add_before_vht_elems(skb, extra_elems,
  1644. extra_elems_len,
  1645. offset);
  1646. if (sband->band != NL80211_BAND_6GHZ &&
  1647. assoc_data->link[link_id].conn.mode >= IEEE80211_CONN_MODE_VHT &&
  1648. sband->vht_cap.vht_supported) {
  1649. bool mu_mimo_owner =
  1650. ieee80211_add_vht_ie(sdata, skb, sband,
  1651. &assoc_data->link[link_id].ap_vht_cap,
  1652. &assoc_data->link[link_id].conn);
  1653. if (link)
  1654. link->conf->mu_mimo_owner = mu_mimo_owner;
  1655. ADD_PRESENT_ELEM(WLAN_EID_VHT_CAPABILITY);
  1656. }
  1657. /* if present, add any custom IEs that go before HE */
  1658. offset = ieee80211_add_before_he_elems(skb, extra_elems,
  1659. extra_elems_len,
  1660. offset);
  1661. if (assoc_data->link[link_id].conn.mode >= IEEE80211_CONN_MODE_HE) {
  1662. ieee80211_put_he_cap(skb, sdata, sband,
  1663. &assoc_data->link[link_id].conn);
  1664. ADD_PRESENT_EXT_ELEM(WLAN_EID_EXT_HE_CAPABILITY);
  1665. if (sband->band == NL80211_BAND_6GHZ)
  1666. ieee80211_put_he_6ghz_cap(skb, sdata, smps_mode);
  1667. }
  1668. /*
  1669. * if present, add any custom IEs that go before regulatory
  1670. * connectivity element
  1671. */
  1672. offset = ieee80211_add_before_reg_conn(skb, extra_elems,
  1673. extra_elems_len, offset);
  1674. if (sband->band == NL80211_BAND_6GHZ) {
  1675. /*
  1676. * as per Section E.2.7 of IEEE 802.11 REVme D7.0, non-AP STA
  1677. * capable of operating on the 6 GHz band shall transmit
  1678. * regulatory connectivity element.
  1679. */
  1680. ieee80211_put_reg_conn(skb, chan->flags);
  1681. }
  1682. /*
  1683. * careful - need to know about all the present elems before
  1684. * calling ieee80211_assoc_add_ml_elem(), so add these if
  1685. * we're going to put them after the ML element
  1686. */
  1687. if (assoc_data->link[link_id].conn.mode >= IEEE80211_CONN_MODE_EHT)
  1688. ADD_PRESENT_EXT_ELEM(WLAN_EID_EXT_EHT_CAPABILITY);
  1689. if (assoc_data->link[link_id].conn.mode >= IEEE80211_CONN_MODE_UHR)
  1690. ADD_PRESENT_EXT_ELEM(WLAN_EID_EXT_UHR_CAPA);
  1691. if (link_id == assoc_data->assoc_link_id)
  1692. ieee80211_assoc_add_ml_elem(sdata, skb, orig_capab, ext_capa,
  1693. present_elems, assoc_data);
  1694. /* crash if somebody gets it wrong */
  1695. present_elems = NULL;
  1696. if (assoc_data->link[link_id].conn.mode >= IEEE80211_CONN_MODE_EHT)
  1697. ieee80211_put_eht_cap(skb, sdata, sband,
  1698. &assoc_data->link[link_id].conn);
  1699. if (assoc_data->link[link_id].conn.mode >= IEEE80211_CONN_MODE_UHR)
  1700. ieee80211_put_uhr_cap(skb, sdata, sband);
  1701. if (sband->band == NL80211_BAND_S1GHZ) {
  1702. ieee80211_add_aid_request_ie(sdata, skb);
  1703. ieee80211_add_s1g_capab_ie(sdata, &sband->s1g_cap, skb);
  1704. }
  1705. if (iftd && iftd->vendor_elems.data && iftd->vendor_elems.len)
  1706. skb_put_data(skb, iftd->vendor_elems.data, iftd->vendor_elems.len);
  1707. return offset;
  1708. }
  1709. static void ieee80211_add_non_inheritance_elem(struct sk_buff *skb,
  1710. const u16 *outer,
  1711. const u16 *inner)
  1712. {
  1713. unsigned int skb_len = skb->len;
  1714. bool at_extension = false;
  1715. bool added = false;
  1716. int i, j;
  1717. u8 *len, *list_len = NULL;
  1718. skb_put_u8(skb, WLAN_EID_EXTENSION);
  1719. len = skb_put(skb, 1);
  1720. skb_put_u8(skb, WLAN_EID_EXT_NON_INHERITANCE);
  1721. for (i = 0; i < PRESENT_ELEMS_MAX && outer[i]; i++) {
  1722. u16 elem = outer[i];
  1723. bool have_inner = false;
  1724. /* should at least be sorted in the sense of normal -> ext */
  1725. WARN_ON(at_extension && elem < PRESENT_ELEM_EXT_OFFS);
  1726. /* switch to extension list */
  1727. if (!at_extension && elem >= PRESENT_ELEM_EXT_OFFS) {
  1728. at_extension = true;
  1729. if (!list_len)
  1730. skb_put_u8(skb, 0);
  1731. list_len = NULL;
  1732. }
  1733. for (j = 0; j < PRESENT_ELEMS_MAX && inner[j]; j++) {
  1734. if (elem == inner[j]) {
  1735. have_inner = true;
  1736. break;
  1737. }
  1738. }
  1739. if (have_inner)
  1740. continue;
  1741. if (!list_len) {
  1742. list_len = skb_put(skb, 1);
  1743. *list_len = 0;
  1744. }
  1745. *list_len += 1;
  1746. skb_put_u8(skb, (u8)elem);
  1747. added = true;
  1748. }
  1749. /* if we added a list but no extension list, make a zero-len one */
  1750. if (added && (!at_extension || !list_len))
  1751. skb_put_u8(skb, 0);
  1752. /* if nothing added remove extension element completely */
  1753. if (!added)
  1754. skb_trim(skb, skb_len);
  1755. else
  1756. *len = skb->len - skb_len - 2;
  1757. }
  1758. static void
  1759. ieee80211_assoc_add_ml_elem(struct ieee80211_sub_if_data *sdata,
  1760. struct sk_buff *skb, u16 capab,
  1761. const struct element *ext_capa,
  1762. const u16 *outer_present_elems,
  1763. struct ieee80211_mgd_assoc_data *assoc_data)
  1764. {
  1765. struct ieee80211_local *local = sdata->local;
  1766. struct ieee80211_multi_link_elem *ml_elem;
  1767. struct ieee80211_mle_basic_common_info *common;
  1768. const struct wiphy_iftype_ext_capab *ift_ext_capa;
  1769. __le16 eml_capa = 0, mld_capa_ops = 0;
  1770. unsigned int link_id;
  1771. u8 *ml_elem_len;
  1772. void *capab_pos;
  1773. if (!ieee80211_vif_is_mld(&sdata->vif))
  1774. return;
  1775. ift_ext_capa = cfg80211_get_iftype_ext_capa(local->hw.wiphy,
  1776. ieee80211_vif_type_p2p(&sdata->vif));
  1777. if (ift_ext_capa) {
  1778. eml_capa = cpu_to_le16(ift_ext_capa->eml_capabilities);
  1779. mld_capa_ops = cpu_to_le16(ift_ext_capa->mld_capa_and_ops);
  1780. }
  1781. skb_put_u8(skb, WLAN_EID_EXTENSION);
  1782. ml_elem_len = skb_put(skb, 1);
  1783. skb_put_u8(skb, WLAN_EID_EXT_EHT_MULTI_LINK);
  1784. ml_elem = skb_put(skb, sizeof(*ml_elem));
  1785. ml_elem->control =
  1786. cpu_to_le16(IEEE80211_ML_CONTROL_TYPE_BASIC |
  1787. IEEE80211_MLC_BASIC_PRES_MLD_CAPA_OP);
  1788. common = skb_put(skb, sizeof(*common));
  1789. common->len = sizeof(*common) +
  1790. 2; /* MLD capa/ops */
  1791. memcpy(common->mld_mac_addr, sdata->vif.addr, ETH_ALEN);
  1792. /* add EML_CAPA only if needed, see Draft P802.11be_D2.1, 35.3.17 */
  1793. if (eml_capa &
  1794. cpu_to_le16((IEEE80211_EML_CAP_EMLSR_SUPP |
  1795. IEEE80211_EML_CAP_EMLMR_SUPPORT))) {
  1796. common->len += 2; /* EML capabilities */
  1797. ml_elem->control |=
  1798. cpu_to_le16(IEEE80211_MLC_BASIC_PRES_EML_CAPA);
  1799. skb_put_data(skb, &eml_capa, sizeof(eml_capa));
  1800. }
  1801. skb_put_data(skb, &mld_capa_ops, sizeof(mld_capa_ops));
  1802. if (assoc_data->ext_mld_capa_ops) {
  1803. ml_elem->control |=
  1804. cpu_to_le16(IEEE80211_MLC_BASIC_PRES_EXT_MLD_CAPA_OP);
  1805. common->len += 2;
  1806. skb_put_data(skb, &assoc_data->ext_mld_capa_ops,
  1807. sizeof(assoc_data->ext_mld_capa_ops));
  1808. }
  1809. for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS; link_id++) {
  1810. u16 link_present_elems[PRESENT_ELEMS_MAX] = {};
  1811. const u8 *extra_elems;
  1812. size_t extra_elems_len;
  1813. size_t extra_used;
  1814. u8 *subelem_len = NULL;
  1815. __le16 ctrl;
  1816. if (!assoc_data->link[link_id].bss ||
  1817. link_id == assoc_data->assoc_link_id)
  1818. continue;
  1819. extra_elems = assoc_data->link[link_id].elems;
  1820. extra_elems_len = assoc_data->link[link_id].elems_len;
  1821. skb_put_u8(skb, IEEE80211_MLE_SUBELEM_PER_STA_PROFILE);
  1822. subelem_len = skb_put(skb, 1);
  1823. ctrl = cpu_to_le16(link_id |
  1824. IEEE80211_MLE_STA_CONTROL_COMPLETE_PROFILE |
  1825. IEEE80211_MLE_STA_CONTROL_STA_MAC_ADDR_PRESENT);
  1826. skb_put_data(skb, &ctrl, sizeof(ctrl));
  1827. skb_put_u8(skb, 1 + ETH_ALEN); /* STA Info Length */
  1828. skb_put_data(skb, assoc_data->link[link_id].addr,
  1829. ETH_ALEN);
  1830. /*
  1831. * Now add the contents of the (re)association request,
  1832. * but the "listen interval" and "current AP address"
  1833. * (if applicable) are skipped. So we only have
  1834. * the capability field (remember the position and fill
  1835. * later), followed by the elements added below by
  1836. * calling ieee80211_add_link_elems().
  1837. */
  1838. capab_pos = skb_put(skb, 2);
  1839. extra_used = ieee80211_add_link_elems(sdata, skb, &capab,
  1840. ext_capa,
  1841. extra_elems,
  1842. extra_elems_len,
  1843. link_id, NULL,
  1844. link_present_elems,
  1845. assoc_data);
  1846. if (extra_elems)
  1847. skb_put_data(skb, extra_elems + extra_used,
  1848. extra_elems_len - extra_used);
  1849. put_unaligned_le16(capab, capab_pos);
  1850. ieee80211_add_non_inheritance_elem(skb, outer_present_elems,
  1851. link_present_elems);
  1852. ieee80211_fragment_element(skb, subelem_len,
  1853. IEEE80211_MLE_SUBELEM_FRAGMENT);
  1854. }
  1855. ieee80211_fragment_element(skb, ml_elem_len, WLAN_EID_FRAGMENT);
  1856. }
  1857. static int
  1858. ieee80211_link_common_elems_size(struct ieee80211_sub_if_data *sdata,
  1859. enum nl80211_iftype iftype,
  1860. struct cfg80211_bss *cbss,
  1861. size_t elems_len)
  1862. {
  1863. struct ieee80211_local *local = sdata->local;
  1864. const struct ieee80211_sband_iftype_data *iftd;
  1865. struct ieee80211_supported_band *sband;
  1866. size_t size = 0;
  1867. if (!cbss)
  1868. return size;
  1869. sband = local->hw.wiphy->bands[cbss->channel->band];
  1870. /* add STA profile elements length */
  1871. size += elems_len;
  1872. /* and supported rates length */
  1873. size += 4 + sband->n_bitrates;
  1874. /* supported channels */
  1875. size += 2 + 2 * sband->n_channels;
  1876. iftd = ieee80211_get_sband_iftype_data(sband, iftype);
  1877. if (iftd)
  1878. size += iftd->vendor_elems.len;
  1879. /* power capability */
  1880. size += 4;
  1881. /* HT, VHT, HE, EHT */
  1882. size += 2 + sizeof(struct ieee80211_ht_cap);
  1883. size += 2 + sizeof(struct ieee80211_vht_cap);
  1884. size += 2 + 1 + sizeof(struct ieee80211_he_cap_elem) +
  1885. sizeof(struct ieee80211_he_mcs_nss_supp) +
  1886. IEEE80211_HE_PPE_THRES_MAX_LEN;
  1887. if (sband->band == NL80211_BAND_6GHZ) {
  1888. size += 2 + 1 + sizeof(struct ieee80211_he_6ghz_capa);
  1889. /* reg connection */
  1890. size += 4;
  1891. }
  1892. size += 2 + 1 + sizeof(struct ieee80211_eht_cap_elem) +
  1893. sizeof(struct ieee80211_eht_mcs_nss_supp) +
  1894. IEEE80211_EHT_PPE_THRES_MAX_LEN;
  1895. size += 2 + 1 + sizeof(struct ieee80211_uhr_cap) +
  1896. sizeof(struct ieee80211_uhr_cap_phy);
  1897. return size;
  1898. }
  1899. static int ieee80211_send_assoc(struct ieee80211_sub_if_data *sdata)
  1900. {
  1901. struct ieee80211_local *local = sdata->local;
  1902. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  1903. struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;
  1904. struct ieee80211_link_data *link;
  1905. struct sk_buff *skb;
  1906. struct ieee80211_mgmt *mgmt;
  1907. u8 *pos, qos_info, *ie_start;
  1908. size_t offset, noffset;
  1909. u16 capab = 0, link_capab;
  1910. __le16 listen_int;
  1911. struct element *ext_capa = NULL;
  1912. enum nl80211_iftype iftype = ieee80211_vif_type_p2p(&sdata->vif);
  1913. struct ieee80211_prep_tx_info info = {};
  1914. unsigned int link_id, n_links = 0;
  1915. u16 present_elems[PRESENT_ELEMS_MAX] = {};
  1916. struct sta_info *sta;
  1917. bool assoc_encrypt;
  1918. void *capab_pos;
  1919. size_t size;
  1920. int ret;
  1921. /* we know it's writable, cast away the const */
  1922. if (assoc_data->ie_len)
  1923. ext_capa = (void *)cfg80211_find_elem(WLAN_EID_EXT_CAPABILITY,
  1924. assoc_data->ie,
  1925. assoc_data->ie_len);
  1926. lockdep_assert_wiphy(sdata->local->hw.wiphy);
  1927. size = local->hw.extra_tx_headroom +
  1928. sizeof(*mgmt) + /* bit too much but doesn't matter */
  1929. 2 + assoc_data->ssid_len + /* SSID */
  1930. assoc_data->ie_len + /* extra IEs */
  1931. (assoc_data->fils_kek_len ? 16 /* AES-SIV */ : 0) +
  1932. 9; /* WMM */
  1933. for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS; link_id++) {
  1934. struct cfg80211_bss *cbss = assoc_data->link[link_id].bss;
  1935. size_t elems_len = assoc_data->link[link_id].elems_len;
  1936. if (!cbss)
  1937. continue;
  1938. n_links++;
  1939. size += ieee80211_link_common_elems_size(sdata, iftype, cbss,
  1940. elems_len);
  1941. /* non-inheritance element */
  1942. size += 2 + 2 + PRESENT_ELEMS_MAX;
  1943. /* should be the same across all BSSes */
  1944. if (cbss->capability & WLAN_CAPABILITY_PRIVACY)
  1945. capab |= WLAN_CAPABILITY_PRIVACY;
  1946. }
  1947. if (ieee80211_vif_is_mld(&sdata->vif)) {
  1948. /* consider the multi-link element with STA profile */
  1949. size += sizeof(struct ieee80211_multi_link_elem);
  1950. /* max common info field in basic multi-link element */
  1951. size += sizeof(struct ieee80211_mle_basic_common_info) +
  1952. 2 + /* capa & op */
  1953. 2 + /* ext capa & op */
  1954. 2; /* EML capa */
  1955. /* The capability elements were already considered above */
  1956. size += (n_links - 1) *
  1957. (1 + 1 + /* subelement ID/length */
  1958. 2 + /* STA control */
  1959. 1 + ETH_ALEN + 2 /* STA Info field */);
  1960. }
  1961. link = sdata_dereference(sdata->link[assoc_data->assoc_link_id], sdata);
  1962. if (WARN_ON(!link))
  1963. return -EINVAL;
  1964. if (WARN_ON(!assoc_data->link[assoc_data->assoc_link_id].bss))
  1965. return -EINVAL;
  1966. skb = alloc_skb(size, GFP_KERNEL);
  1967. if (!skb)
  1968. return -ENOMEM;
  1969. skb_reserve(skb, local->hw.extra_tx_headroom);
  1970. if (ifmgd->flags & IEEE80211_STA_ENABLE_RRM)
  1971. capab |= WLAN_CAPABILITY_RADIO_MEASURE;
  1972. /* Set MBSSID support for HE AP if needed */
  1973. if (ieee80211_hw_check(&local->hw, SUPPORTS_ONLY_HE_MULTI_BSSID) &&
  1974. link->u.mgd.conn.mode >= IEEE80211_CONN_MODE_HE &&
  1975. ext_capa && ext_capa->datalen >= 3)
  1976. ext_capa->data[2] |= WLAN_EXT_CAPA3_MULTI_BSSID_SUPPORT;
  1977. mgmt = skb_put_zero(skb, 24);
  1978. memcpy(mgmt->da, sdata->vif.cfg.ap_addr, ETH_ALEN);
  1979. memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
  1980. memcpy(mgmt->bssid, sdata->vif.cfg.ap_addr, ETH_ALEN);
  1981. listen_int = cpu_to_le16(assoc_data->s1g ?
  1982. ieee80211_encode_usf(local->hw.conf.listen_interval) :
  1983. local->hw.conf.listen_interval);
  1984. if (!is_zero_ether_addr(assoc_data->prev_ap_addr)) {
  1985. skb_put(skb, 10);
  1986. mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
  1987. IEEE80211_STYPE_REASSOC_REQ);
  1988. capab_pos = &mgmt->u.reassoc_req.capab_info;
  1989. mgmt->u.reassoc_req.listen_interval = listen_int;
  1990. memcpy(mgmt->u.reassoc_req.current_ap,
  1991. assoc_data->prev_ap_addr, ETH_ALEN);
  1992. info.subtype = IEEE80211_STYPE_REASSOC_REQ;
  1993. } else {
  1994. skb_put(skb, 4);
  1995. mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
  1996. IEEE80211_STYPE_ASSOC_REQ);
  1997. capab_pos = &mgmt->u.assoc_req.capab_info;
  1998. mgmt->u.assoc_req.listen_interval = listen_int;
  1999. info.subtype = IEEE80211_STYPE_ASSOC_REQ;
  2000. }
  2001. /* SSID */
  2002. pos = skb_put(skb, 2 + assoc_data->ssid_len);
  2003. ie_start = pos;
  2004. *pos++ = WLAN_EID_SSID;
  2005. *pos++ = assoc_data->ssid_len;
  2006. memcpy(pos, assoc_data->ssid, assoc_data->ssid_len);
  2007. /*
  2008. * This bit is technically reserved, so it shouldn't matter for either
  2009. * the AP or us, but it also means we shouldn't set it. However, we've
  2010. * always set it in the past, and apparently some EHT APs check that
  2011. * we don't set it. To avoid interoperability issues with old APs that
  2012. * for some reason check it and want it to be set, set the bit for all
  2013. * pre-EHT connections as we used to do.
  2014. */
  2015. if (link->u.mgd.conn.mode < IEEE80211_CONN_MODE_EHT &&
  2016. !ieee80211_hw_check(&local->hw, STRICT))
  2017. capab |= WLAN_CAPABILITY_ESS;
  2018. /* add the elements for the assoc (main) link */
  2019. link_capab = capab;
  2020. offset = ieee80211_add_link_elems(sdata, skb, &link_capab,
  2021. ext_capa,
  2022. assoc_data->ie,
  2023. assoc_data->ie_len,
  2024. assoc_data->assoc_link_id, link,
  2025. present_elems, assoc_data);
  2026. put_unaligned_le16(link_capab, capab_pos);
  2027. /* if present, add any custom non-vendor IEs */
  2028. if (assoc_data->ie_len) {
  2029. noffset = ieee80211_ie_split_vendor(assoc_data->ie,
  2030. assoc_data->ie_len,
  2031. offset);
  2032. skb_put_data(skb, assoc_data->ie + offset, noffset - offset);
  2033. offset = noffset;
  2034. }
  2035. if (assoc_data->wmm) {
  2036. if (assoc_data->uapsd) {
  2037. qos_info = ifmgd->uapsd_queues;
  2038. qos_info |= (ifmgd->uapsd_max_sp_len <<
  2039. IEEE80211_WMM_IE_STA_QOSINFO_SP_SHIFT);
  2040. } else {
  2041. qos_info = 0;
  2042. }
  2043. pos = ieee80211_add_wmm_info_ie(skb_put(skb, 9), qos_info);
  2044. }
  2045. /* add any remaining custom (i.e. vendor specific here) IEs */
  2046. if (assoc_data->ie_len) {
  2047. noffset = assoc_data->ie_len;
  2048. skb_put_data(skb, assoc_data->ie + offset, noffset - offset);
  2049. }
  2050. if (assoc_data->fils_kek_len) {
  2051. ret = fils_encrypt_assoc_req(skb, assoc_data);
  2052. if (ret < 0) {
  2053. dev_kfree_skb(skb);
  2054. return ret;
  2055. }
  2056. }
  2057. pos = skb_tail_pointer(skb);
  2058. kfree(ifmgd->assoc_req_ies);
  2059. ifmgd->assoc_req_ies = kmemdup(ie_start, pos - ie_start, GFP_ATOMIC);
  2060. if (!ifmgd->assoc_req_ies) {
  2061. dev_kfree_skb(skb);
  2062. return -ENOMEM;
  2063. }
  2064. ifmgd->assoc_req_ies_len = pos - ie_start;
  2065. info.link_id = assoc_data->assoc_link_id;
  2066. drv_mgd_prepare_tx(local, sdata, &info);
  2067. sta = sta_info_get_bss(sdata, sdata->vif.cfg.ap_addr);
  2068. assoc_encrypt = sta && sta->sta.epp_peer &&
  2069. wiphy_dereference(sdata->local->hw.wiphy,
  2070. sta->ptk[sta->ptk_idx]);
  2071. if (!assoc_encrypt)
  2072. IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
  2073. if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
  2074. IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS |
  2075. IEEE80211_TX_INTFL_MLME_CONN_TX;
  2076. ieee80211_tx_skb(sdata, skb);
  2077. return 0;
  2078. }
  2079. void ieee80211_send_pspoll(struct ieee80211_local *local,
  2080. struct ieee80211_sub_if_data *sdata)
  2081. {
  2082. struct ieee80211_pspoll *pspoll;
  2083. struct sk_buff *skb;
  2084. skb = ieee80211_pspoll_get(&local->hw, &sdata->vif);
  2085. if (!skb)
  2086. return;
  2087. pspoll = (struct ieee80211_pspoll *) skb->data;
  2088. pspoll->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
  2089. IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
  2090. ieee80211_tx_skb(sdata, skb);
  2091. }
  2092. void ieee80211_send_nullfunc(struct ieee80211_local *local,
  2093. struct ieee80211_sub_if_data *sdata,
  2094. bool powersave)
  2095. {
  2096. struct sk_buff *skb;
  2097. struct ieee80211_hdr_3addr *nullfunc;
  2098. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  2099. skb = ieee80211_nullfunc_get(&local->hw, &sdata->vif, -1,
  2100. !ieee80211_hw_check(&local->hw,
  2101. DOESNT_SUPPORT_QOS_NDP));
  2102. if (!skb)
  2103. return;
  2104. nullfunc = (struct ieee80211_hdr_3addr *) skb->data;
  2105. if (powersave)
  2106. nullfunc->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
  2107. IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT |
  2108. IEEE80211_TX_INTFL_OFFCHAN_TX_OK;
  2109. if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
  2110. IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS;
  2111. if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL)
  2112. IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_USE_MINRATE;
  2113. ieee80211_tx_skb(sdata, skb);
  2114. }
  2115. void ieee80211_send_4addr_nullfunc(struct ieee80211_local *local,
  2116. struct ieee80211_sub_if_data *sdata)
  2117. {
  2118. struct sk_buff *skb;
  2119. struct ieee80211_hdr *nullfunc;
  2120. __le16 fc;
  2121. if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
  2122. return;
  2123. skb = dev_alloc_skb(local->hw.extra_tx_headroom + 30);
  2124. if (!skb)
  2125. return;
  2126. skb_reserve(skb, local->hw.extra_tx_headroom);
  2127. nullfunc = skb_put_zero(skb, 30);
  2128. fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_NULLFUNC |
  2129. IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS);
  2130. nullfunc->frame_control = fc;
  2131. memcpy(nullfunc->addr1, sdata->deflink.u.mgd.bssid, ETH_ALEN);
  2132. memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
  2133. memcpy(nullfunc->addr3, sdata->deflink.u.mgd.bssid, ETH_ALEN);
  2134. memcpy(nullfunc->addr4, sdata->vif.addr, ETH_ALEN);
  2135. IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
  2136. IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_USE_MINRATE;
  2137. ieee80211_tx_skb(sdata, skb);
  2138. }
  2139. /* spectrum management related things */
  2140. static void ieee80211_csa_switch_work(struct wiphy *wiphy,
  2141. struct wiphy_work *work)
  2142. {
  2143. struct ieee80211_link_data *link =
  2144. container_of(work, struct ieee80211_link_data,
  2145. u.mgd.csa.switch_work.work);
  2146. struct ieee80211_sub_if_data *sdata = link->sdata;
  2147. struct ieee80211_local *local = sdata->local;
  2148. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  2149. int ret;
  2150. if (!ieee80211_sdata_running(sdata))
  2151. return;
  2152. lockdep_assert_wiphy(local->hw.wiphy);
  2153. if (!ifmgd->associated)
  2154. return;
  2155. if (!link->conf->csa_active)
  2156. return;
  2157. /*
  2158. * If the link isn't active (now), we cannot wait for beacons, won't
  2159. * have a reserved chanctx, etc. Just switch over the chandef and
  2160. * update cfg80211 directly.
  2161. */
  2162. if (!ieee80211_vif_link_active(&sdata->vif, link->link_id)) {
  2163. struct link_sta_info *link_sta;
  2164. struct sta_info *ap_sta;
  2165. link->conf->chanreq = link->csa.chanreq;
  2166. cfg80211_ch_switch_notify(sdata->dev, &link->csa.chanreq.oper,
  2167. link->link_id);
  2168. link->conf->csa_active = false;
  2169. ap_sta = sta_info_get(sdata, sdata->vif.cfg.ap_addr);
  2170. if (WARN_ON(!ap_sta))
  2171. return;
  2172. link_sta = wiphy_dereference(wiphy,
  2173. ap_sta->link[link->link_id]);
  2174. if (WARN_ON(!link_sta))
  2175. return;
  2176. link_sta->pub->bandwidth =
  2177. _ieee80211_sta_cur_vht_bw(link_sta,
  2178. &link->csa.chanreq.oper);
  2179. return;
  2180. }
  2181. /*
  2182. * using reservation isn't immediate as it may be deferred until later
  2183. * with multi-vif. once reservation is complete it will re-schedule the
  2184. * work with no reserved_chanctx so verify chandef to check if it
  2185. * completed successfully
  2186. */
  2187. if (link->reserved_chanctx) {
  2188. /*
  2189. * with multi-vif csa driver may call ieee80211_csa_finish()
  2190. * many times while waiting for other interfaces to use their
  2191. * reservations
  2192. */
  2193. if (link->reserved_ready)
  2194. return;
  2195. ret = ieee80211_link_use_reserved_context(link);
  2196. if (ret) {
  2197. link_info(link,
  2198. "failed to use reserved channel context, disconnecting (err=%d)\n",
  2199. ret);
  2200. wiphy_work_queue(sdata->local->hw.wiphy,
  2201. &ifmgd->csa_connection_drop_work);
  2202. }
  2203. return;
  2204. }
  2205. if (!ieee80211_chanreq_identical(&link->conf->chanreq,
  2206. &link->csa.chanreq)) {
  2207. link_info(link,
  2208. "failed to finalize channel switch, disconnecting\n");
  2209. wiphy_work_queue(sdata->local->hw.wiphy,
  2210. &ifmgd->csa_connection_drop_work);
  2211. return;
  2212. }
  2213. link->u.mgd.csa.waiting_bcn = true;
  2214. /*
  2215. * The next beacon really should always be different, so this should
  2216. * have no effect whatsoever. However, some APs (we observed this in
  2217. * an Asus AXE11000), the beacon after the CSA might be identical to
  2218. * the last beacon on the old channel - in this case we'd ignore it.
  2219. * Resetting the CRC will lead us to handle it better (albeit with a
  2220. * disconnect, but clearly the AP is broken.)
  2221. */
  2222. link->u.mgd.beacon_crc_valid = false;
  2223. /* apply new TPE restrictions immediately on the new channel */
  2224. if (link->u.mgd.csa.ap_chandef.chan->band == NL80211_BAND_6GHZ &&
  2225. link->u.mgd.conn.mode >= IEEE80211_CONN_MODE_HE) {
  2226. ieee80211_rearrange_tpe(&link->u.mgd.csa.tpe,
  2227. &link->u.mgd.csa.ap_chandef,
  2228. &link->conf->chanreq.oper);
  2229. if (memcmp(&link->conf->tpe, &link->u.mgd.csa.tpe,
  2230. sizeof(link->u.mgd.csa.tpe))) {
  2231. link->conf->tpe = link->u.mgd.csa.tpe;
  2232. ieee80211_link_info_change_notify(sdata, link,
  2233. BSS_CHANGED_TPE);
  2234. }
  2235. }
  2236. /*
  2237. * It is not necessary to reset these timers if any link does not
  2238. * have an active CSA and that link still receives the beacons
  2239. * when other links have active CSA.
  2240. */
  2241. for_each_link_data(sdata, link) {
  2242. if (!link->conf->csa_active)
  2243. return;
  2244. }
  2245. /*
  2246. * Reset the beacon monitor and connection monitor timers when CSA
  2247. * is active for all links in MLO when channel switch occurs in all
  2248. * the links.
  2249. */
  2250. ieee80211_sta_reset_beacon_monitor(sdata);
  2251. ieee80211_sta_reset_conn_monitor(sdata);
  2252. }
  2253. static void ieee80211_chswitch_post_beacon(struct ieee80211_link_data *link)
  2254. {
  2255. struct ieee80211_sub_if_data *sdata = link->sdata;
  2256. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  2257. int ret;
  2258. lockdep_assert_wiphy(sdata->local->hw.wiphy);
  2259. WARN_ON(!link->conf->csa_active);
  2260. ieee80211_vif_unblock_queues_csa(sdata);
  2261. link->conf->csa_active = false;
  2262. link->u.mgd.csa.blocked_tx = false;
  2263. link->u.mgd.csa.waiting_bcn = false;
  2264. ret = drv_post_channel_switch(link);
  2265. if (ret) {
  2266. link_info(link,
  2267. "driver post channel switch failed, disconnecting\n");
  2268. wiphy_work_queue(sdata->local->hw.wiphy,
  2269. &ifmgd->csa_connection_drop_work);
  2270. return;
  2271. }
  2272. cfg80211_ch_switch_notify(sdata->dev, &link->conf->chanreq.oper,
  2273. link->link_id);
  2274. }
  2275. void ieee80211_chswitch_done(struct ieee80211_vif *vif, bool success,
  2276. unsigned int link_id)
  2277. {
  2278. struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
  2279. trace_api_chswitch_done(sdata, success, link_id);
  2280. rcu_read_lock();
  2281. if (!success) {
  2282. sdata_info(sdata,
  2283. "driver channel switch failed (link %d), disconnecting\n",
  2284. link_id);
  2285. wiphy_work_queue(sdata->local->hw.wiphy,
  2286. &sdata->u.mgd.csa_connection_drop_work);
  2287. } else {
  2288. struct ieee80211_link_data *link =
  2289. rcu_dereference(sdata->link[link_id]);
  2290. if (WARN_ON(!link)) {
  2291. rcu_read_unlock();
  2292. return;
  2293. }
  2294. wiphy_hrtimer_work_queue(sdata->local->hw.wiphy,
  2295. &link->u.mgd.csa.switch_work, 0);
  2296. }
  2297. rcu_read_unlock();
  2298. }
  2299. EXPORT_SYMBOL(ieee80211_chswitch_done);
  2300. static void
  2301. ieee80211_sta_abort_chanswitch(struct ieee80211_link_data *link)
  2302. {
  2303. struct ieee80211_sub_if_data *sdata = link->sdata;
  2304. struct ieee80211_local *local = sdata->local;
  2305. lockdep_assert_wiphy(local->hw.wiphy);
  2306. if (!local->ops->abort_channel_switch)
  2307. return;
  2308. if (rcu_access_pointer(link->conf->chanctx_conf))
  2309. ieee80211_link_unreserve_chanctx(link);
  2310. ieee80211_vif_unblock_queues_csa(sdata);
  2311. link->conf->csa_active = false;
  2312. link->u.mgd.csa.blocked_tx = false;
  2313. drv_abort_channel_switch(link);
  2314. }
  2315. struct sta_csa_rnr_iter_data {
  2316. struct ieee80211_link_data *link;
  2317. struct ieee80211_channel *chan;
  2318. u8 mld_id;
  2319. };
  2320. static enum cfg80211_rnr_iter_ret
  2321. ieee80211_sta_csa_rnr_iter(void *_data, u8 type,
  2322. const struct ieee80211_neighbor_ap_info *info,
  2323. const u8 *tbtt_info, u8 tbtt_info_len)
  2324. {
  2325. struct sta_csa_rnr_iter_data *data = _data;
  2326. struct ieee80211_link_data *link = data->link;
  2327. struct ieee80211_sub_if_data *sdata = link->sdata;
  2328. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  2329. const struct ieee80211_tbtt_info_ge_11 *ti;
  2330. enum nl80211_band band;
  2331. unsigned int center_freq;
  2332. int link_id;
  2333. if (type != IEEE80211_TBTT_INFO_TYPE_TBTT)
  2334. return RNR_ITER_CONTINUE;
  2335. if (tbtt_info_len < sizeof(*ti))
  2336. return RNR_ITER_CONTINUE;
  2337. ti = (const void *)tbtt_info;
  2338. if (ti->mld_params.mld_id != data->mld_id)
  2339. return RNR_ITER_CONTINUE;
  2340. link_id = le16_get_bits(ti->mld_params.params,
  2341. IEEE80211_RNR_MLD_PARAMS_LINK_ID);
  2342. if (link_id != data->link->link_id)
  2343. return RNR_ITER_CONTINUE;
  2344. /* we found the entry for our link! */
  2345. /* this AP is confused, it had this right before ... just disconnect */
  2346. if (!ieee80211_operating_class_to_band(info->op_class, &band)) {
  2347. link_info(link,
  2348. "AP now has invalid operating class in RNR, disconnect\n");
  2349. wiphy_work_queue(sdata->local->hw.wiphy,
  2350. &ifmgd->csa_connection_drop_work);
  2351. return RNR_ITER_BREAK;
  2352. }
  2353. center_freq = ieee80211_channel_to_frequency(info->channel, band);
  2354. data->chan = ieee80211_get_channel(sdata->local->hw.wiphy, center_freq);
  2355. return RNR_ITER_BREAK;
  2356. }
  2357. static void
  2358. ieee80211_sta_other_link_csa_disappeared(struct ieee80211_link_data *link,
  2359. struct ieee802_11_elems *elems)
  2360. {
  2361. struct ieee80211_sub_if_data *sdata = link->sdata;
  2362. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  2363. struct sta_csa_rnr_iter_data data = {
  2364. .link = link,
  2365. };
  2366. /*
  2367. * If we get here, we see a beacon from another link without
  2368. * CSA still being reported for it, so now we have to check
  2369. * if the CSA was aborted or completed. This may not even be
  2370. * perfectly possible if the CSA was only done for changing
  2371. * the puncturing, but in that case if the link in inactive
  2372. * we don't really care, and if it's an active link (or when
  2373. * it's activated later) we'll get a beacon and adjust.
  2374. */
  2375. if (WARN_ON(!elems->ml_basic))
  2376. return;
  2377. data.mld_id = ieee80211_mle_get_mld_id((const void *)elems->ml_basic);
  2378. /*
  2379. * So in order to do this, iterate the RNR element(s) and see
  2380. * what channel is reported now.
  2381. */
  2382. cfg80211_iter_rnr(elems->ie_start, elems->total_len,
  2383. ieee80211_sta_csa_rnr_iter, &data);
  2384. if (!data.chan) {
  2385. link_info(link,
  2386. "couldn't find (valid) channel in RNR for CSA, disconnect\n");
  2387. wiphy_work_queue(sdata->local->hw.wiphy,
  2388. &ifmgd->csa_connection_drop_work);
  2389. return;
  2390. }
  2391. /*
  2392. * If it doesn't match the CSA, then assume it aborted. This
  2393. * may erroneously detect that it was _not_ aborted when it
  2394. * was in fact aborted, but only changed the bandwidth or the
  2395. * puncturing configuration, but we don't have enough data to
  2396. * detect that.
  2397. */
  2398. if (data.chan != link->csa.chanreq.oper.chan)
  2399. ieee80211_sta_abort_chanswitch(link);
  2400. }
  2401. enum ieee80211_csa_source {
  2402. IEEE80211_CSA_SOURCE_BEACON,
  2403. IEEE80211_CSA_SOURCE_OTHER_LINK,
  2404. IEEE80211_CSA_SOURCE_PROT_ACTION,
  2405. IEEE80211_CSA_SOURCE_UNPROT_ACTION,
  2406. };
  2407. static void
  2408. ieee80211_sta_process_chanswitch(struct ieee80211_link_data *link,
  2409. u64 timestamp, u32 device_timestamp,
  2410. struct ieee802_11_elems *full_elems,
  2411. struct ieee802_11_elems *csa_elems,
  2412. enum ieee80211_csa_source source)
  2413. {
  2414. struct ieee80211_sub_if_data *sdata = link->sdata;
  2415. struct ieee80211_local *local = sdata->local;
  2416. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  2417. struct ieee80211_chanctx *chanctx = NULL;
  2418. struct ieee80211_chanctx_conf *conf;
  2419. struct ieee80211_csa_ie csa_ie = {};
  2420. struct ieee80211_channel_switch ch_switch = {
  2421. .link_id = link->link_id,
  2422. .timestamp = timestamp,
  2423. .device_timestamp = device_timestamp,
  2424. };
  2425. u32 csa_time_tu;
  2426. ktime_t now;
  2427. int res;
  2428. lockdep_assert_wiphy(local->hw.wiphy);
  2429. if (csa_elems) {
  2430. struct cfg80211_bss *cbss = link->conf->bss;
  2431. enum nl80211_band current_band;
  2432. struct ieee80211_bss *bss;
  2433. if (WARN_ON(!cbss))
  2434. return;
  2435. current_band = cbss->channel->band;
  2436. bss = (void *)cbss->priv;
  2437. res = ieee80211_parse_ch_switch_ie(sdata, csa_elems,
  2438. current_band,
  2439. bss->vht_cap_info,
  2440. &link->u.mgd.conn,
  2441. link->u.mgd.bssid,
  2442. source == IEEE80211_CSA_SOURCE_UNPROT_ACTION,
  2443. &csa_ie);
  2444. if (res == 0) {
  2445. ch_switch.block_tx = csa_ie.mode;
  2446. ch_switch.chandef = csa_ie.chanreq.oper;
  2447. ch_switch.count = csa_ie.count;
  2448. ch_switch.delay = csa_ie.max_switch_time;
  2449. }
  2450. link->u.mgd.csa.tpe = csa_elems->csa_tpe;
  2451. } else {
  2452. /*
  2453. * If there was no per-STA profile for this link, we
  2454. * get called with csa_elems == NULL. This of course means
  2455. * there are no CSA elements, so set res=1 indicating
  2456. * no more CSA.
  2457. */
  2458. res = 1;
  2459. }
  2460. if (res < 0) {
  2461. /* ignore this case, not a protected frame */
  2462. if (source == IEEE80211_CSA_SOURCE_UNPROT_ACTION)
  2463. return;
  2464. goto drop_connection;
  2465. }
  2466. if (link->conf->csa_active) {
  2467. switch (source) {
  2468. case IEEE80211_CSA_SOURCE_PROT_ACTION:
  2469. case IEEE80211_CSA_SOURCE_UNPROT_ACTION:
  2470. /* already processing - disregard action frames */
  2471. return;
  2472. case IEEE80211_CSA_SOURCE_BEACON:
  2473. if (link->u.mgd.csa.waiting_bcn) {
  2474. ieee80211_chswitch_post_beacon(link);
  2475. /*
  2476. * If the CSA is still present after the switch
  2477. * we need to consider it as a new CSA (possibly
  2478. * to self). This happens by not returning here
  2479. * so we'll get to the check below.
  2480. */
  2481. } else if (res) {
  2482. ieee80211_sta_abort_chanswitch(link);
  2483. return;
  2484. } else {
  2485. drv_channel_switch_rx_beacon(sdata, &ch_switch);
  2486. return;
  2487. }
  2488. break;
  2489. case IEEE80211_CSA_SOURCE_OTHER_LINK:
  2490. /* active link: we want to see the beacon to continue */
  2491. if (ieee80211_vif_link_active(&sdata->vif,
  2492. link->link_id))
  2493. return;
  2494. /* switch work ran, so just complete the process */
  2495. if (link->u.mgd.csa.waiting_bcn) {
  2496. ieee80211_chswitch_post_beacon(link);
  2497. /*
  2498. * If the CSA is still present after the switch
  2499. * we need to consider it as a new CSA (possibly
  2500. * to self). This happens by not returning here
  2501. * so we'll get to the check below.
  2502. */
  2503. break;
  2504. }
  2505. /* link still has CSA but we already know, do nothing */
  2506. if (!res)
  2507. return;
  2508. /* check in the RNR if the CSA aborted */
  2509. ieee80211_sta_other_link_csa_disappeared(link,
  2510. full_elems);
  2511. return;
  2512. }
  2513. }
  2514. /* no active CSA nor a new one */
  2515. if (res) {
  2516. /*
  2517. * However, we may have stopped queues when receiving a public
  2518. * action frame that couldn't be protected, if it had the quiet
  2519. * bit set. This is a trade-off, we want to be quiet as soon as
  2520. * possible, but also don't trust the public action frame much,
  2521. * as it can't be protected.
  2522. */
  2523. if (unlikely(link->u.mgd.csa.blocked_tx)) {
  2524. link->u.mgd.csa.blocked_tx = false;
  2525. ieee80211_vif_unblock_queues_csa(sdata);
  2526. }
  2527. return;
  2528. }
  2529. /*
  2530. * We don't really trust public action frames, but block queues (go to
  2531. * quiet mode) for them anyway, we should get a beacon soon to either
  2532. * know what the CSA really is, or figure out the public action frame
  2533. * was actually an attack.
  2534. */
  2535. if (source == IEEE80211_CSA_SOURCE_UNPROT_ACTION) {
  2536. if (csa_ie.mode) {
  2537. link->u.mgd.csa.blocked_tx = true;
  2538. ieee80211_vif_block_queues_csa(sdata);
  2539. }
  2540. return;
  2541. }
  2542. if (link->conf->chanreq.oper.chan->band !=
  2543. csa_ie.chanreq.oper.chan->band) {
  2544. link_info(link,
  2545. "AP %pM switches to different band (%d MHz, width:%d, CF1/2: %d/%d MHz), disconnecting\n",
  2546. link->u.mgd.bssid,
  2547. csa_ie.chanreq.oper.chan->center_freq,
  2548. csa_ie.chanreq.oper.width,
  2549. csa_ie.chanreq.oper.center_freq1,
  2550. csa_ie.chanreq.oper.center_freq2);
  2551. goto drop_connection;
  2552. }
  2553. if (!cfg80211_chandef_usable(local->hw.wiphy, &csa_ie.chanreq.oper,
  2554. IEEE80211_CHAN_DISABLED)) {
  2555. link_info(link,
  2556. "AP %pM switches to unsupported channel (%d.%03d MHz, width:%d, CF1/2: %d.%03d/%d MHz), disconnecting\n",
  2557. link->u.mgd.bssid,
  2558. csa_ie.chanreq.oper.chan->center_freq,
  2559. csa_ie.chanreq.oper.chan->freq_offset,
  2560. csa_ie.chanreq.oper.width,
  2561. csa_ie.chanreq.oper.center_freq1,
  2562. csa_ie.chanreq.oper.freq1_offset,
  2563. csa_ie.chanreq.oper.center_freq2);
  2564. goto drop_connection;
  2565. }
  2566. if (cfg80211_chandef_identical(&csa_ie.chanreq.oper,
  2567. &link->conf->chanreq.oper) &&
  2568. (!csa_ie.mode || source != IEEE80211_CSA_SOURCE_BEACON)) {
  2569. if (link->u.mgd.csa.ignored_same_chan)
  2570. return;
  2571. link_info(link,
  2572. "AP %pM tries to chanswitch to same channel, ignore\n",
  2573. link->u.mgd.bssid);
  2574. link->u.mgd.csa.ignored_same_chan = true;
  2575. return;
  2576. }
  2577. /*
  2578. * Drop all TDLS peers on the affected link - either we disconnect or
  2579. * move to a different channel from this point on. There's no telling
  2580. * what our peer will do.
  2581. * The TDLS WIDER_BW scenario is also problematic, as peers might now
  2582. * have an incompatible wider chandef.
  2583. */
  2584. ieee80211_teardown_tdls_peers(link);
  2585. conf = rcu_dereference_protected(link->conf->chanctx_conf,
  2586. lockdep_is_held(&local->hw.wiphy->mtx));
  2587. if (ieee80211_vif_link_active(&sdata->vif, link->link_id) && !conf) {
  2588. link_info(link,
  2589. "no channel context assigned to vif?, disconnecting\n");
  2590. goto drop_connection;
  2591. }
  2592. if (conf)
  2593. chanctx = container_of(conf, struct ieee80211_chanctx, conf);
  2594. if (!ieee80211_hw_check(&local->hw, CHANCTX_STA_CSA)) {
  2595. link_info(link,
  2596. "driver doesn't support chan-switch with channel contexts\n");
  2597. goto drop_connection;
  2598. }
  2599. if (drv_pre_channel_switch(sdata, &ch_switch)) {
  2600. link_info(link,
  2601. "preparing for channel switch failed, disconnecting\n");
  2602. goto drop_connection;
  2603. }
  2604. link->u.mgd.csa.ap_chandef = csa_ie.chanreq.ap;
  2605. link->csa.chanreq.oper = csa_ie.chanreq.oper;
  2606. ieee80211_set_chanreq_ap(sdata, &link->csa.chanreq, &link->u.mgd.conn,
  2607. &csa_ie.chanreq.ap);
  2608. if (chanctx) {
  2609. res = ieee80211_link_reserve_chanctx(link, &link->csa.chanreq,
  2610. chanctx->mode, false);
  2611. if (res) {
  2612. link_info(link,
  2613. "failed to reserve channel context for channel switch, disconnecting (err=%d)\n",
  2614. res);
  2615. goto drop_connection;
  2616. }
  2617. }
  2618. link->conf->csa_active = true;
  2619. link->u.mgd.csa.ignored_same_chan = false;
  2620. link->u.mgd.beacon_crc_valid = false;
  2621. link->u.mgd.csa.blocked_tx = csa_ie.mode;
  2622. if (csa_ie.mode)
  2623. ieee80211_vif_block_queues_csa(sdata);
  2624. cfg80211_ch_switch_started_notify(sdata->dev, &csa_ie.chanreq.oper,
  2625. link->link_id, csa_ie.count,
  2626. csa_ie.mode);
  2627. /* we may have to handle timeout for deactivated link in software */
  2628. now = ktime_get_boottime();
  2629. csa_time_tu = (max_t(int, csa_ie.count, 1) - 1) * link->conf->beacon_int;
  2630. link->u.mgd.csa.time = now + us_to_ktime(ieee80211_tu_to_usec(csa_time_tu));
  2631. if (ieee80211_vif_link_active(&sdata->vif, link->link_id) &&
  2632. local->ops->channel_switch) {
  2633. /*
  2634. * Use driver's channel switch callback, the driver will
  2635. * later call ieee80211_chswitch_done(). It may deactivate
  2636. * the link as well, we handle that elsewhere and queue
  2637. * the csa.switch_work for the calculated time then.
  2638. */
  2639. drv_channel_switch(local, sdata, &ch_switch);
  2640. return;
  2641. }
  2642. /* channel switch handled in software */
  2643. wiphy_hrtimer_work_queue(local->hw.wiphy,
  2644. &link->u.mgd.csa.switch_work,
  2645. link->u.mgd.csa.time - now);
  2646. return;
  2647. drop_connection:
  2648. /*
  2649. * This is just so that the disconnect flow will know that
  2650. * we were trying to switch channel and failed. In case the
  2651. * mode is 1 (we are not allowed to Tx), we will know not to
  2652. * send a deauthentication frame. Those two fields will be
  2653. * reset when the disconnection worker runs.
  2654. */
  2655. link->conf->csa_active = true;
  2656. link->u.mgd.csa.blocked_tx = csa_ie.mode;
  2657. wiphy_work_queue(sdata->local->hw.wiphy,
  2658. &ifmgd->csa_connection_drop_work);
  2659. }
  2660. struct sta_bss_param_ch_cnt_data {
  2661. struct ieee80211_sub_if_data *sdata;
  2662. u8 reporting_link_id;
  2663. u8 mld_id;
  2664. };
  2665. static enum cfg80211_rnr_iter_ret
  2666. ieee80211_sta_bss_param_ch_cnt_iter(void *_data, u8 type,
  2667. const struct ieee80211_neighbor_ap_info *info,
  2668. const u8 *tbtt_info, u8 tbtt_info_len)
  2669. {
  2670. struct sta_bss_param_ch_cnt_data *data = _data;
  2671. struct ieee80211_sub_if_data *sdata = data->sdata;
  2672. const struct ieee80211_tbtt_info_ge_11 *ti;
  2673. u8 bss_param_ch_cnt;
  2674. int link_id;
  2675. if (type != IEEE80211_TBTT_INFO_TYPE_TBTT)
  2676. return RNR_ITER_CONTINUE;
  2677. if (tbtt_info_len < sizeof(*ti))
  2678. return RNR_ITER_CONTINUE;
  2679. ti = (const void *)tbtt_info;
  2680. if (ti->mld_params.mld_id != data->mld_id)
  2681. return RNR_ITER_CONTINUE;
  2682. link_id = le16_get_bits(ti->mld_params.params,
  2683. IEEE80211_RNR_MLD_PARAMS_LINK_ID);
  2684. bss_param_ch_cnt =
  2685. le16_get_bits(ti->mld_params.params,
  2686. IEEE80211_RNR_MLD_PARAMS_BSS_CHANGE_COUNT);
  2687. if (bss_param_ch_cnt != 255 &&
  2688. link_id < ARRAY_SIZE(sdata->link)) {
  2689. struct ieee80211_link_data *link =
  2690. sdata_dereference(sdata->link[link_id], sdata);
  2691. if (link && link->conf->bss_param_ch_cnt != bss_param_ch_cnt) {
  2692. link->conf->bss_param_ch_cnt = bss_param_ch_cnt;
  2693. link->conf->bss_param_ch_cnt_link_id =
  2694. data->reporting_link_id;
  2695. }
  2696. }
  2697. return RNR_ITER_CONTINUE;
  2698. }
  2699. static void
  2700. ieee80211_mgd_update_bss_param_ch_cnt(struct ieee80211_sub_if_data *sdata,
  2701. struct ieee80211_bss_conf *bss_conf,
  2702. struct ieee802_11_elems *elems)
  2703. {
  2704. struct sta_bss_param_ch_cnt_data data = {
  2705. .reporting_link_id = bss_conf->link_id,
  2706. .sdata = sdata,
  2707. };
  2708. int bss_param_ch_cnt;
  2709. if (!elems->ml_basic)
  2710. return;
  2711. data.mld_id = ieee80211_mle_get_mld_id((const void *)elems->ml_basic);
  2712. cfg80211_iter_rnr(elems->ie_start, elems->total_len,
  2713. ieee80211_sta_bss_param_ch_cnt_iter, &data);
  2714. bss_param_ch_cnt =
  2715. ieee80211_mle_get_bss_param_ch_cnt((const void *)elems->ml_basic);
  2716. /*
  2717. * Update bss_param_ch_cnt_link_id even if bss_param_ch_cnt
  2718. * didn't change to indicate that we got a beacon on our own
  2719. * link.
  2720. */
  2721. if (bss_param_ch_cnt >= 0 && bss_param_ch_cnt != 255) {
  2722. bss_conf->bss_param_ch_cnt = bss_param_ch_cnt;
  2723. bss_conf->bss_param_ch_cnt_link_id =
  2724. bss_conf->link_id;
  2725. }
  2726. }
  2727. static bool
  2728. ieee80211_find_80211h_pwr_constr(struct ieee80211_channel *channel,
  2729. const u8 *country_ie, u8 country_ie_len,
  2730. const u8 *pwr_constr_elem,
  2731. int *chan_pwr, int *pwr_reduction)
  2732. {
  2733. struct ieee80211_country_ie_triplet *triplet;
  2734. int chan = ieee80211_frequency_to_channel(channel->center_freq);
  2735. int i, chan_increment;
  2736. bool have_chan_pwr = false;
  2737. /* Invalid IE */
  2738. if (country_ie_len % 2 || country_ie_len < IEEE80211_COUNTRY_IE_MIN_LEN)
  2739. return false;
  2740. triplet = (void *)(country_ie + 3);
  2741. country_ie_len -= 3;
  2742. switch (channel->band) {
  2743. default:
  2744. WARN_ON_ONCE(1);
  2745. fallthrough;
  2746. case NL80211_BAND_2GHZ:
  2747. case NL80211_BAND_60GHZ:
  2748. case NL80211_BAND_LC:
  2749. chan_increment = 1;
  2750. break;
  2751. case NL80211_BAND_5GHZ:
  2752. chan_increment = 4;
  2753. break;
  2754. case NL80211_BAND_6GHZ:
  2755. /*
  2756. * In the 6 GHz band, the "maximum transmit power level"
  2757. * field in the triplets is reserved, and thus will be
  2758. * zero and we shouldn't use it to control TX power.
  2759. * The actual TX power will be given in the transmit
  2760. * power envelope element instead.
  2761. */
  2762. return false;
  2763. }
  2764. /* find channel */
  2765. while (country_ie_len >= 3) {
  2766. u8 first_channel = triplet->chans.first_channel;
  2767. if (first_channel >= IEEE80211_COUNTRY_EXTENSION_ID)
  2768. goto next;
  2769. for (i = 0; i < triplet->chans.num_channels; i++) {
  2770. if (first_channel + i * chan_increment == chan) {
  2771. have_chan_pwr = true;
  2772. *chan_pwr = triplet->chans.max_power;
  2773. break;
  2774. }
  2775. }
  2776. if (have_chan_pwr)
  2777. break;
  2778. next:
  2779. triplet++;
  2780. country_ie_len -= 3;
  2781. }
  2782. if (have_chan_pwr && pwr_constr_elem)
  2783. *pwr_reduction = *pwr_constr_elem;
  2784. else
  2785. *pwr_reduction = 0;
  2786. return have_chan_pwr;
  2787. }
  2788. static void ieee80211_find_cisco_dtpc(struct ieee80211_channel *channel,
  2789. const u8 *cisco_dtpc_ie,
  2790. int *pwr_level)
  2791. {
  2792. /* From practical testing, the first data byte of the DTPC element
  2793. * seems to contain the requested dBm level, and the CLI on Cisco
  2794. * APs clearly state the range is -127 to 127 dBm, which indicates
  2795. * a signed byte, although it seemingly never actually goes negative.
  2796. * The other byte seems to always be zero.
  2797. */
  2798. *pwr_level = (__s8)cisco_dtpc_ie[4];
  2799. }
  2800. static u64 ieee80211_handle_pwr_constr(struct ieee80211_link_data *link,
  2801. struct ieee80211_channel *channel,
  2802. struct ieee80211_mgmt *mgmt,
  2803. const u8 *country_ie, u8 country_ie_len,
  2804. const u8 *pwr_constr_ie,
  2805. const u8 *cisco_dtpc_ie)
  2806. {
  2807. struct ieee80211_sub_if_data *sdata = link->sdata;
  2808. bool has_80211h_pwr = false, has_cisco_pwr = false;
  2809. int chan_pwr = 0, pwr_reduction_80211h = 0;
  2810. int pwr_level_cisco, pwr_level_80211h;
  2811. int new_ap_level;
  2812. __le16 capab = mgmt->u.probe_resp.capab_info;
  2813. if (ieee80211_is_s1g_beacon(mgmt->frame_control))
  2814. return 0; /* TODO */
  2815. if (country_ie &&
  2816. (capab & cpu_to_le16(WLAN_CAPABILITY_SPECTRUM_MGMT) ||
  2817. capab & cpu_to_le16(WLAN_CAPABILITY_RADIO_MEASURE))) {
  2818. has_80211h_pwr = ieee80211_find_80211h_pwr_constr(
  2819. channel, country_ie, country_ie_len,
  2820. pwr_constr_ie, &chan_pwr, &pwr_reduction_80211h);
  2821. pwr_level_80211h =
  2822. max_t(int, 0, chan_pwr - pwr_reduction_80211h);
  2823. }
  2824. if (cisco_dtpc_ie) {
  2825. ieee80211_find_cisco_dtpc(
  2826. channel, cisco_dtpc_ie, &pwr_level_cisco);
  2827. has_cisco_pwr = true;
  2828. }
  2829. if (!has_80211h_pwr && !has_cisco_pwr)
  2830. return 0;
  2831. /* If we have both 802.11h and Cisco DTPC, apply both limits
  2832. * by picking the smallest of the two power levels advertised.
  2833. */
  2834. if (has_80211h_pwr &&
  2835. (!has_cisco_pwr || pwr_level_80211h <= pwr_level_cisco)) {
  2836. new_ap_level = pwr_level_80211h;
  2837. if (link->ap_power_level == new_ap_level)
  2838. return 0;
  2839. sdata_dbg(sdata,
  2840. "Limiting TX power to %d (%d - %d) dBm as advertised by %pM\n",
  2841. pwr_level_80211h, chan_pwr, pwr_reduction_80211h,
  2842. link->u.mgd.bssid);
  2843. } else { /* has_cisco_pwr is always true here. */
  2844. new_ap_level = pwr_level_cisco;
  2845. if (link->ap_power_level == new_ap_level)
  2846. return 0;
  2847. sdata_dbg(sdata,
  2848. "Limiting TX power to %d dBm as advertised by %pM\n",
  2849. pwr_level_cisco, link->u.mgd.bssid);
  2850. }
  2851. link->ap_power_level = new_ap_level;
  2852. if (__ieee80211_recalc_txpower(link))
  2853. return BSS_CHANGED_TXPOWER;
  2854. return 0;
  2855. }
  2856. /* powersave */
  2857. static void ieee80211_enable_ps(struct ieee80211_local *local,
  2858. struct ieee80211_sub_if_data *sdata)
  2859. {
  2860. struct ieee80211_conf *conf = &local->hw.conf;
  2861. /*
  2862. * If we are scanning right now then the parameters will
  2863. * take effect when scan finishes.
  2864. */
  2865. if (local->scanning)
  2866. return;
  2867. if (conf->dynamic_ps_timeout > 0 &&
  2868. !ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS)) {
  2869. mod_timer(&local->dynamic_ps_timer, jiffies +
  2870. msecs_to_jiffies(conf->dynamic_ps_timeout));
  2871. } else {
  2872. if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK))
  2873. ieee80211_send_nullfunc(local, sdata, true);
  2874. if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK) &&
  2875. ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
  2876. return;
  2877. conf->flags |= IEEE80211_CONF_PS;
  2878. ieee80211_hw_config(local, -1, IEEE80211_CONF_CHANGE_PS);
  2879. }
  2880. }
  2881. static void ieee80211_change_ps(struct ieee80211_local *local)
  2882. {
  2883. struct ieee80211_conf *conf = &local->hw.conf;
  2884. if (local->ps_sdata) {
  2885. ieee80211_enable_ps(local, local->ps_sdata);
  2886. } else if (conf->flags & IEEE80211_CONF_PS) {
  2887. conf->flags &= ~IEEE80211_CONF_PS;
  2888. ieee80211_hw_config(local, -1, IEEE80211_CONF_CHANGE_PS);
  2889. timer_delete_sync(&local->dynamic_ps_timer);
  2890. wiphy_work_cancel(local->hw.wiphy,
  2891. &local->dynamic_ps_enable_work);
  2892. }
  2893. }
  2894. static bool ieee80211_powersave_allowed(struct ieee80211_sub_if_data *sdata)
  2895. {
  2896. struct ieee80211_local *local = sdata->local;
  2897. struct ieee80211_if_managed *mgd = &sdata->u.mgd;
  2898. struct sta_info *sta = NULL;
  2899. bool authorized = false;
  2900. if (!mgd->powersave)
  2901. return false;
  2902. if (mgd->broken_ap)
  2903. return false;
  2904. if (!mgd->associated)
  2905. return false;
  2906. if (mgd->flags & IEEE80211_STA_CONNECTION_POLL)
  2907. return false;
  2908. if (!(local->hw.wiphy->flags & WIPHY_FLAG_SUPPORTS_MLO) &&
  2909. !sdata->deflink.u.mgd.have_beacon)
  2910. return false;
  2911. rcu_read_lock();
  2912. sta = sta_info_get(sdata, sdata->vif.cfg.ap_addr);
  2913. if (sta)
  2914. authorized = test_sta_flag(sta, WLAN_STA_AUTHORIZED);
  2915. rcu_read_unlock();
  2916. return authorized;
  2917. }
  2918. /* need to hold RTNL or interface lock */
  2919. void ieee80211_recalc_ps(struct ieee80211_local *local)
  2920. {
  2921. struct ieee80211_sub_if_data *sdata, *found = NULL;
  2922. int count = 0;
  2923. int timeout;
  2924. if (!ieee80211_hw_check(&local->hw, SUPPORTS_PS) ||
  2925. ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS)) {
  2926. local->ps_sdata = NULL;
  2927. return;
  2928. }
  2929. list_for_each_entry(sdata, &local->interfaces, list) {
  2930. if (!ieee80211_sdata_running(sdata))
  2931. continue;
  2932. if (sdata->vif.type == NL80211_IFTYPE_AP) {
  2933. /* If an AP vif is found, then disable PS
  2934. * by setting the count to zero thereby setting
  2935. * ps_sdata to NULL.
  2936. */
  2937. count = 0;
  2938. break;
  2939. }
  2940. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  2941. continue;
  2942. found = sdata;
  2943. count++;
  2944. }
  2945. if (count == 1 && ieee80211_powersave_allowed(found)) {
  2946. u8 dtimper = found->deflink.u.mgd.dtim_period;
  2947. timeout = local->dynamic_ps_forced_timeout;
  2948. if (timeout < 0)
  2949. timeout = 100;
  2950. local->hw.conf.dynamic_ps_timeout = timeout;
  2951. /* If the TIM IE is invalid, pretend the value is 1 */
  2952. if (!dtimper)
  2953. dtimper = 1;
  2954. local->hw.conf.ps_dtim_period = dtimper;
  2955. local->ps_sdata = found;
  2956. } else {
  2957. local->ps_sdata = NULL;
  2958. }
  2959. ieee80211_change_ps(local);
  2960. }
  2961. void ieee80211_recalc_ps_vif(struct ieee80211_sub_if_data *sdata)
  2962. {
  2963. bool ps_allowed = ieee80211_powersave_allowed(sdata);
  2964. if (sdata->vif.cfg.ps != ps_allowed) {
  2965. sdata->vif.cfg.ps = ps_allowed;
  2966. ieee80211_vif_cfg_change_notify(sdata, BSS_CHANGED_PS);
  2967. }
  2968. }
  2969. void ieee80211_dynamic_ps_disable_work(struct wiphy *wiphy,
  2970. struct wiphy_work *work)
  2971. {
  2972. struct ieee80211_local *local =
  2973. container_of(work, struct ieee80211_local,
  2974. dynamic_ps_disable_work);
  2975. if (local->hw.conf.flags & IEEE80211_CONF_PS) {
  2976. local->hw.conf.flags &= ~IEEE80211_CONF_PS;
  2977. ieee80211_hw_config(local, -1, IEEE80211_CONF_CHANGE_PS);
  2978. }
  2979. ieee80211_wake_queues_by_reason(&local->hw,
  2980. IEEE80211_MAX_QUEUE_MAP,
  2981. IEEE80211_QUEUE_STOP_REASON_PS,
  2982. false);
  2983. }
  2984. void ieee80211_dynamic_ps_enable_work(struct wiphy *wiphy,
  2985. struct wiphy_work *work)
  2986. {
  2987. struct ieee80211_local *local =
  2988. container_of(work, struct ieee80211_local,
  2989. dynamic_ps_enable_work);
  2990. struct ieee80211_sub_if_data *sdata = local->ps_sdata;
  2991. struct ieee80211_if_managed *ifmgd;
  2992. unsigned long flags;
  2993. int q;
  2994. /* can only happen when PS was just disabled anyway */
  2995. if (!sdata)
  2996. return;
  2997. ifmgd = &sdata->u.mgd;
  2998. if (local->hw.conf.flags & IEEE80211_CONF_PS)
  2999. return;
  3000. if (local->hw.conf.dynamic_ps_timeout > 0) {
  3001. /* don't enter PS if TX frames are pending */
  3002. if (drv_tx_frames_pending(local)) {
  3003. mod_timer(&local->dynamic_ps_timer, jiffies +
  3004. msecs_to_jiffies(
  3005. local->hw.conf.dynamic_ps_timeout));
  3006. return;
  3007. }
  3008. /*
  3009. * transmission can be stopped by others which leads to
  3010. * dynamic_ps_timer expiry. Postpone the ps timer if it
  3011. * is not the actual idle state.
  3012. */
  3013. spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
  3014. for (q = 0; q < local->hw.queues; q++) {
  3015. if (local->queue_stop_reasons[q]) {
  3016. spin_unlock_irqrestore(&local->queue_stop_reason_lock,
  3017. flags);
  3018. mod_timer(&local->dynamic_ps_timer, jiffies +
  3019. msecs_to_jiffies(
  3020. local->hw.conf.dynamic_ps_timeout));
  3021. return;
  3022. }
  3023. }
  3024. spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
  3025. }
  3026. if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK) &&
  3027. !(ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED)) {
  3028. if (drv_tx_frames_pending(local)) {
  3029. mod_timer(&local->dynamic_ps_timer, jiffies +
  3030. msecs_to_jiffies(
  3031. local->hw.conf.dynamic_ps_timeout));
  3032. } else {
  3033. ieee80211_send_nullfunc(local, sdata, true);
  3034. /* Flush to get the tx status of nullfunc frame */
  3035. ieee80211_flush_queues(local, sdata, false);
  3036. }
  3037. }
  3038. if (!(ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS) &&
  3039. ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK)) ||
  3040. (ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED)) {
  3041. ifmgd->flags &= ~IEEE80211_STA_NULLFUNC_ACKED;
  3042. local->hw.conf.flags |= IEEE80211_CONF_PS;
  3043. ieee80211_hw_config(local, -1, IEEE80211_CONF_CHANGE_PS);
  3044. }
  3045. }
  3046. void ieee80211_dynamic_ps_timer(struct timer_list *t)
  3047. {
  3048. struct ieee80211_local *local = timer_container_of(local, t,
  3049. dynamic_ps_timer);
  3050. wiphy_work_queue(local->hw.wiphy, &local->dynamic_ps_enable_work);
  3051. }
  3052. void ieee80211_dfs_cac_timer_work(struct wiphy *wiphy, struct wiphy_work *work)
  3053. {
  3054. struct ieee80211_link_data *link =
  3055. container_of(work, struct ieee80211_link_data,
  3056. dfs_cac_timer_work.work);
  3057. struct cfg80211_chan_def chandef = link->conf->chanreq.oper;
  3058. struct ieee80211_sub_if_data *sdata = link->sdata;
  3059. lockdep_assert_wiphy(sdata->local->hw.wiphy);
  3060. if (sdata->wdev.links[link->link_id].cac_started) {
  3061. ieee80211_link_release_channel(link);
  3062. cfg80211_cac_event(sdata->dev, &chandef,
  3063. NL80211_RADAR_CAC_FINISHED,
  3064. GFP_KERNEL, link->link_id);
  3065. }
  3066. }
  3067. static bool
  3068. __ieee80211_sta_handle_tspec_ac_params(struct ieee80211_sub_if_data *sdata)
  3069. {
  3070. struct ieee80211_local *local = sdata->local;
  3071. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  3072. bool ret = false;
  3073. int ac;
  3074. if (local->hw.queues < IEEE80211_NUM_ACS)
  3075. return false;
  3076. for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
  3077. struct ieee80211_sta_tx_tspec *tx_tspec = &ifmgd->tx_tspec[ac];
  3078. int non_acm_ac;
  3079. unsigned long now = jiffies;
  3080. if (tx_tspec->action == TX_TSPEC_ACTION_NONE &&
  3081. tx_tspec->admitted_time &&
  3082. time_after(now, tx_tspec->time_slice_start + HZ)) {
  3083. tx_tspec->consumed_tx_time = 0;
  3084. tx_tspec->time_slice_start = now;
  3085. if (tx_tspec->downgraded)
  3086. tx_tspec->action =
  3087. TX_TSPEC_ACTION_STOP_DOWNGRADE;
  3088. }
  3089. switch (tx_tspec->action) {
  3090. case TX_TSPEC_ACTION_STOP_DOWNGRADE:
  3091. /* take the original parameters */
  3092. if (drv_conf_tx(local, &sdata->deflink, ac,
  3093. &sdata->deflink.tx_conf[ac]))
  3094. link_err(&sdata->deflink,
  3095. "failed to set TX queue parameters for queue %d\n",
  3096. ac);
  3097. tx_tspec->action = TX_TSPEC_ACTION_NONE;
  3098. tx_tspec->downgraded = false;
  3099. ret = true;
  3100. break;
  3101. case TX_TSPEC_ACTION_DOWNGRADE:
  3102. if (time_after(now, tx_tspec->time_slice_start + HZ)) {
  3103. tx_tspec->action = TX_TSPEC_ACTION_NONE;
  3104. ret = true;
  3105. break;
  3106. }
  3107. /* downgrade next lower non-ACM AC */
  3108. for (non_acm_ac = ac + 1;
  3109. non_acm_ac < IEEE80211_NUM_ACS;
  3110. non_acm_ac++)
  3111. if (!(sdata->wmm_acm & BIT(7 - 2 * non_acm_ac)))
  3112. break;
  3113. /* Usually the loop will result in using BK even if it
  3114. * requires admission control, but such a configuration
  3115. * makes no sense and we have to transmit somehow - the
  3116. * AC selection does the same thing.
  3117. * If we started out trying to downgrade from BK, then
  3118. * the extra condition here might be needed.
  3119. */
  3120. if (non_acm_ac >= IEEE80211_NUM_ACS)
  3121. non_acm_ac = IEEE80211_AC_BK;
  3122. if (drv_conf_tx(local, &sdata->deflink, ac,
  3123. &sdata->deflink.tx_conf[non_acm_ac]))
  3124. link_err(&sdata->deflink,
  3125. "failed to set TX queue parameters for queue %d\n",
  3126. ac);
  3127. tx_tspec->action = TX_TSPEC_ACTION_NONE;
  3128. ret = true;
  3129. wiphy_delayed_work_queue(local->hw.wiphy,
  3130. &ifmgd->tx_tspec_wk,
  3131. tx_tspec->time_slice_start +
  3132. HZ - now + 1);
  3133. break;
  3134. case TX_TSPEC_ACTION_NONE:
  3135. /* nothing now */
  3136. break;
  3137. }
  3138. }
  3139. return ret;
  3140. }
  3141. void ieee80211_sta_handle_tspec_ac_params(struct ieee80211_sub_if_data *sdata)
  3142. {
  3143. if (__ieee80211_sta_handle_tspec_ac_params(sdata))
  3144. ieee80211_link_info_change_notify(sdata, &sdata->deflink,
  3145. BSS_CHANGED_QOS);
  3146. }
  3147. static void ieee80211_sta_handle_tspec_ac_params_wk(struct wiphy *wiphy,
  3148. struct wiphy_work *work)
  3149. {
  3150. struct ieee80211_sub_if_data *sdata;
  3151. sdata = container_of(work, struct ieee80211_sub_if_data,
  3152. u.mgd.tx_tspec_wk.work);
  3153. ieee80211_sta_handle_tspec_ac_params(sdata);
  3154. }
  3155. void ieee80211_mgd_set_link_qos_params(struct ieee80211_link_data *link)
  3156. {
  3157. struct ieee80211_sub_if_data *sdata = link->sdata;
  3158. struct ieee80211_local *local = sdata->local;
  3159. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  3160. struct ieee80211_tx_queue_params *params = link->tx_conf;
  3161. u8 ac;
  3162. for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
  3163. mlme_dbg(sdata,
  3164. "WMM AC=%d acm=%d aifs=%d cWmin=%d cWmax=%d txop=%d uapsd=%d, downgraded=%d\n",
  3165. ac, params[ac].acm,
  3166. params[ac].aifs, params[ac].cw_min, params[ac].cw_max,
  3167. params[ac].txop, params[ac].uapsd,
  3168. ifmgd->tx_tspec[ac].downgraded);
  3169. if (!ifmgd->tx_tspec[ac].downgraded &&
  3170. drv_conf_tx(local, link, ac, &params[ac]))
  3171. link_err(link,
  3172. "failed to set TX queue parameters for AC %d\n",
  3173. ac);
  3174. }
  3175. }
  3176. /* MLME */
  3177. static bool
  3178. _ieee80211_sta_wmm_params(struct ieee80211_local *local,
  3179. struct ieee80211_link_data *link,
  3180. const u8 *wmm_param, size_t wmm_param_len,
  3181. const struct ieee80211_mu_edca_param_set *mu_edca)
  3182. {
  3183. struct ieee80211_sub_if_data *sdata = link->sdata;
  3184. struct ieee80211_tx_queue_params params[IEEE80211_NUM_ACS];
  3185. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  3186. size_t left;
  3187. int count, mu_edca_count, ac;
  3188. const u8 *pos;
  3189. u8 uapsd_queues = 0;
  3190. if (!local->ops->conf_tx)
  3191. return false;
  3192. if (local->hw.queues < IEEE80211_NUM_ACS)
  3193. return false;
  3194. if (!wmm_param)
  3195. return false;
  3196. if (wmm_param_len < 8 || wmm_param[5] /* version */ != 1)
  3197. return false;
  3198. if (ifmgd->flags & IEEE80211_STA_UAPSD_ENABLED)
  3199. uapsd_queues = ifmgd->uapsd_queues;
  3200. count = wmm_param[6] & 0x0f;
  3201. /* -1 is the initial value of ifmgd->mu_edca_last_param_set.
  3202. * if mu_edca was preset before and now it disappeared tell
  3203. * the driver about it.
  3204. */
  3205. mu_edca_count = mu_edca ? mu_edca->mu_qos_info & 0x0f : -1;
  3206. if (count == link->u.mgd.wmm_last_param_set &&
  3207. mu_edca_count == link->u.mgd.mu_edca_last_param_set)
  3208. return false;
  3209. link->u.mgd.wmm_last_param_set = count;
  3210. link->u.mgd.mu_edca_last_param_set = mu_edca_count;
  3211. pos = wmm_param + 8;
  3212. left = wmm_param_len - 8;
  3213. memset(&params, 0, sizeof(params));
  3214. sdata->wmm_acm = 0;
  3215. for (; left >= 4; left -= 4, pos += 4) {
  3216. int aci = (pos[0] >> 5) & 0x03;
  3217. int acm = (pos[0] >> 4) & 0x01;
  3218. bool uapsd = false;
  3219. switch (aci) {
  3220. case 1: /* AC_BK */
  3221. ac = IEEE80211_AC_BK;
  3222. if (acm)
  3223. sdata->wmm_acm |= BIT(1) | BIT(2); /* BK/- */
  3224. if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
  3225. uapsd = true;
  3226. params[ac].mu_edca = !!mu_edca;
  3227. if (mu_edca)
  3228. params[ac].mu_edca_param_rec = mu_edca->ac_bk;
  3229. break;
  3230. case 2: /* AC_VI */
  3231. ac = IEEE80211_AC_VI;
  3232. if (acm)
  3233. sdata->wmm_acm |= BIT(4) | BIT(5); /* CL/VI */
  3234. if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
  3235. uapsd = true;
  3236. params[ac].mu_edca = !!mu_edca;
  3237. if (mu_edca)
  3238. params[ac].mu_edca_param_rec = mu_edca->ac_vi;
  3239. break;
  3240. case 3: /* AC_VO */
  3241. ac = IEEE80211_AC_VO;
  3242. if (acm)
  3243. sdata->wmm_acm |= BIT(6) | BIT(7); /* VO/NC */
  3244. if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
  3245. uapsd = true;
  3246. params[ac].mu_edca = !!mu_edca;
  3247. if (mu_edca)
  3248. params[ac].mu_edca_param_rec = mu_edca->ac_vo;
  3249. break;
  3250. case 0: /* AC_BE */
  3251. default:
  3252. ac = IEEE80211_AC_BE;
  3253. if (acm)
  3254. sdata->wmm_acm |= BIT(0) | BIT(3); /* BE/EE */
  3255. if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
  3256. uapsd = true;
  3257. params[ac].mu_edca = !!mu_edca;
  3258. if (mu_edca)
  3259. params[ac].mu_edca_param_rec = mu_edca->ac_be;
  3260. break;
  3261. }
  3262. params[ac].aifs = pos[0] & 0x0f;
  3263. if (params[ac].aifs < 2) {
  3264. link_info(link,
  3265. "AP has invalid WMM params (AIFSN=%d for ACI %d), will use 2\n",
  3266. params[ac].aifs, aci);
  3267. params[ac].aifs = 2;
  3268. }
  3269. params[ac].cw_max = ecw2cw((pos[1] & 0xf0) >> 4);
  3270. params[ac].cw_min = ecw2cw(pos[1] & 0x0f);
  3271. params[ac].txop = get_unaligned_le16(pos + 2);
  3272. params[ac].acm = acm;
  3273. params[ac].uapsd = uapsd;
  3274. if (params[ac].cw_min == 0 ||
  3275. params[ac].cw_min > params[ac].cw_max) {
  3276. link_info(link,
  3277. "AP has invalid WMM params (CWmin/max=%d/%d for ACI %d), using defaults\n",
  3278. params[ac].cw_min, params[ac].cw_max, aci);
  3279. return false;
  3280. }
  3281. ieee80211_regulatory_limit_wmm_params(sdata, &params[ac], ac);
  3282. }
  3283. /* WMM specification requires all 4 ACIs. */
  3284. for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
  3285. if (params[ac].cw_min == 0) {
  3286. link_info(link,
  3287. "AP has invalid WMM params (missing AC %d), using defaults\n",
  3288. ac);
  3289. return false;
  3290. }
  3291. }
  3292. for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
  3293. link->tx_conf[ac] = params[ac];
  3294. return true;
  3295. }
  3296. static bool
  3297. ieee80211_sta_wmm_params(struct ieee80211_local *local,
  3298. struct ieee80211_link_data *link,
  3299. const u8 *wmm_param, size_t wmm_param_len,
  3300. const struct ieee80211_mu_edca_param_set *mu_edca)
  3301. {
  3302. if (!_ieee80211_sta_wmm_params(local, link, wmm_param, wmm_param_len,
  3303. mu_edca))
  3304. return false;
  3305. ieee80211_mgd_set_link_qos_params(link);
  3306. /* enable WMM or activate new settings */
  3307. link->conf->qos = true;
  3308. return true;
  3309. }
  3310. static void __ieee80211_stop_poll(struct ieee80211_sub_if_data *sdata)
  3311. {
  3312. lockdep_assert_wiphy(sdata->local->hw.wiphy);
  3313. sdata->u.mgd.flags &= ~IEEE80211_STA_CONNECTION_POLL;
  3314. ieee80211_run_deferred_scan(sdata->local);
  3315. }
  3316. static void ieee80211_stop_poll(struct ieee80211_sub_if_data *sdata)
  3317. {
  3318. lockdep_assert_wiphy(sdata->local->hw.wiphy);
  3319. __ieee80211_stop_poll(sdata);
  3320. }
  3321. static u64 ieee80211_handle_bss_capability(struct ieee80211_link_data *link,
  3322. u16 capab, bool erp_valid, u8 erp)
  3323. {
  3324. struct ieee80211_bss_conf *bss_conf = link->conf;
  3325. struct ieee80211_supported_band *sband;
  3326. u64 changed = 0;
  3327. bool use_protection;
  3328. bool use_short_preamble;
  3329. bool use_short_slot;
  3330. sband = ieee80211_get_link_sband(link);
  3331. if (!sband)
  3332. return changed;
  3333. if (erp_valid) {
  3334. use_protection = (erp & WLAN_ERP_USE_PROTECTION) != 0;
  3335. use_short_preamble = (erp & WLAN_ERP_BARKER_PREAMBLE) == 0;
  3336. } else {
  3337. use_protection = false;
  3338. use_short_preamble = !!(capab & WLAN_CAPABILITY_SHORT_PREAMBLE);
  3339. }
  3340. use_short_slot = !!(capab & WLAN_CAPABILITY_SHORT_SLOT_TIME);
  3341. if (sband->band == NL80211_BAND_5GHZ ||
  3342. sband->band == NL80211_BAND_6GHZ)
  3343. use_short_slot = true;
  3344. if (use_protection != bss_conf->use_cts_prot) {
  3345. bss_conf->use_cts_prot = use_protection;
  3346. changed |= BSS_CHANGED_ERP_CTS_PROT;
  3347. }
  3348. if (use_short_preamble != bss_conf->use_short_preamble) {
  3349. bss_conf->use_short_preamble = use_short_preamble;
  3350. changed |= BSS_CHANGED_ERP_PREAMBLE;
  3351. }
  3352. if (use_short_slot != bss_conf->use_short_slot) {
  3353. bss_conf->use_short_slot = use_short_slot;
  3354. changed |= BSS_CHANGED_ERP_SLOT;
  3355. }
  3356. return changed;
  3357. }
  3358. static u64 ieee80211_link_set_associated(struct ieee80211_link_data *link,
  3359. struct cfg80211_bss *cbss)
  3360. {
  3361. struct ieee80211_sub_if_data *sdata = link->sdata;
  3362. struct ieee80211_bss_conf *bss_conf = link->conf;
  3363. struct ieee80211_bss *bss = (void *)cbss->priv;
  3364. u64 changed = BSS_CHANGED_QOS;
  3365. /* not really used in MLO */
  3366. sdata->u.mgd.beacon_timeout =
  3367. usecs_to_jiffies(ieee80211_tu_to_usec(beacon_loss_count *
  3368. bss_conf->beacon_int));
  3369. changed |= ieee80211_handle_bss_capability(link,
  3370. bss_conf->assoc_capability,
  3371. bss->has_erp_value,
  3372. bss->erp_value);
  3373. ieee80211_check_rate_mask(link);
  3374. link->conf->bss = cbss;
  3375. memcpy(link->u.mgd.bssid, cbss->bssid, ETH_ALEN);
  3376. if (sdata->vif.p2p ||
  3377. sdata->vif.driver_flags & IEEE80211_VIF_GET_NOA_UPDATE) {
  3378. const struct cfg80211_bss_ies *ies;
  3379. rcu_read_lock();
  3380. ies = rcu_dereference(cbss->ies);
  3381. if (ies) {
  3382. int ret;
  3383. ret = cfg80211_get_p2p_attr(
  3384. ies->data, ies->len,
  3385. IEEE80211_P2P_ATTR_ABSENCE_NOTICE,
  3386. (u8 *) &bss_conf->p2p_noa_attr,
  3387. sizeof(bss_conf->p2p_noa_attr));
  3388. if (ret >= 2) {
  3389. link->u.mgd.p2p_noa_index =
  3390. bss_conf->p2p_noa_attr.index;
  3391. changed |= BSS_CHANGED_P2P_PS;
  3392. }
  3393. }
  3394. rcu_read_unlock();
  3395. }
  3396. if (link->u.mgd.have_beacon) {
  3397. bss_conf->beacon_rate = bss->beacon_rate;
  3398. changed |= BSS_CHANGED_BEACON_INFO;
  3399. } else {
  3400. bss_conf->beacon_rate = NULL;
  3401. }
  3402. /* Tell the driver to monitor connection quality (if supported) */
  3403. if (sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI &&
  3404. bss_conf->cqm_rssi_thold)
  3405. changed |= BSS_CHANGED_CQM;
  3406. return changed;
  3407. }
  3408. static void ieee80211_set_associated(struct ieee80211_sub_if_data *sdata,
  3409. struct ieee80211_mgd_assoc_data *assoc_data,
  3410. u64 changed[IEEE80211_MLD_MAX_NUM_LINKS])
  3411. {
  3412. struct ieee80211_local *local = sdata->local;
  3413. struct ieee80211_vif_cfg *vif_cfg = &sdata->vif.cfg;
  3414. u64 vif_changed = BSS_CHANGED_ASSOC;
  3415. unsigned int link_id;
  3416. lockdep_assert_wiphy(local->hw.wiphy);
  3417. sdata->u.mgd.associated = true;
  3418. for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS; link_id++) {
  3419. struct cfg80211_bss *cbss = assoc_data->link[link_id].bss;
  3420. struct ieee80211_link_data *link;
  3421. if (!cbss ||
  3422. assoc_data->link[link_id].status != WLAN_STATUS_SUCCESS)
  3423. continue;
  3424. if (ieee80211_vif_is_mld(&sdata->vif) &&
  3425. !(ieee80211_vif_usable_links(&sdata->vif) & BIT(link_id)))
  3426. continue;
  3427. link = sdata_dereference(sdata->link[link_id], sdata);
  3428. if (WARN_ON(!link))
  3429. return;
  3430. changed[link_id] |= ieee80211_link_set_associated(link, cbss);
  3431. }
  3432. /* just to be sure */
  3433. ieee80211_stop_poll(sdata);
  3434. ieee80211_led_assoc(local, 1);
  3435. vif_cfg->assoc = 1;
  3436. /* Enable ARP filtering */
  3437. if (vif_cfg->arp_addr_cnt)
  3438. vif_changed |= BSS_CHANGED_ARP_FILTER;
  3439. if (ieee80211_vif_is_mld(&sdata->vif)) {
  3440. for (link_id = 0;
  3441. link_id < IEEE80211_MLD_MAX_NUM_LINKS;
  3442. link_id++) {
  3443. struct ieee80211_link_data *link;
  3444. struct cfg80211_bss *cbss = assoc_data->link[link_id].bss;
  3445. if (!cbss ||
  3446. !(BIT(link_id) &
  3447. ieee80211_vif_usable_links(&sdata->vif)) ||
  3448. assoc_data->link[link_id].status != WLAN_STATUS_SUCCESS)
  3449. continue;
  3450. link = sdata_dereference(sdata->link[link_id], sdata);
  3451. if (WARN_ON(!link))
  3452. return;
  3453. ieee80211_link_info_change_notify(sdata, link,
  3454. changed[link_id]);
  3455. ieee80211_recalc_smps(sdata, link);
  3456. }
  3457. ieee80211_vif_cfg_change_notify(sdata, vif_changed);
  3458. } else {
  3459. ieee80211_bss_info_change_notify(sdata,
  3460. vif_changed | changed[0]);
  3461. }
  3462. ieee80211_recalc_ps(local);
  3463. /* leave this here to not change ordering in non-MLO cases */
  3464. if (!ieee80211_vif_is_mld(&sdata->vif))
  3465. ieee80211_recalc_smps(sdata, &sdata->deflink);
  3466. ieee80211_recalc_ps_vif(sdata);
  3467. netif_carrier_on(sdata->dev);
  3468. }
  3469. static void ieee80211_ml_reconf_reset(struct ieee80211_sub_if_data *sdata)
  3470. {
  3471. struct ieee80211_mgd_assoc_data *add_links_data =
  3472. sdata->u.mgd.reconf.add_links_data;
  3473. if (!ieee80211_vif_is_mld(&sdata->vif) ||
  3474. !(sdata->u.mgd.reconf.added_links |
  3475. sdata->u.mgd.reconf.removed_links))
  3476. return;
  3477. wiphy_delayed_work_cancel(sdata->local->hw.wiphy,
  3478. &sdata->u.mgd.reconf.wk);
  3479. sdata->u.mgd.reconf.added_links = 0;
  3480. sdata->u.mgd.reconf.removed_links = 0;
  3481. sdata->u.mgd.reconf.dialog_token = 0;
  3482. if (add_links_data) {
  3483. struct cfg80211_mlo_reconf_done_data done_data = {};
  3484. u8 link_id;
  3485. for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS;
  3486. link_id++)
  3487. done_data.links[link_id].bss =
  3488. add_links_data->link[link_id].bss;
  3489. cfg80211_mlo_reconf_add_done(sdata->dev, &done_data);
  3490. kfree(sdata->u.mgd.reconf.add_links_data);
  3491. sdata->u.mgd.reconf.add_links_data = NULL;
  3492. }
  3493. }
  3494. static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata,
  3495. u16 stype, u16 reason, bool tx,
  3496. u8 *frame_buf)
  3497. {
  3498. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  3499. struct ieee80211_local *local = sdata->local;
  3500. struct sta_info *ap_sta = sta_info_get(sdata, sdata->vif.cfg.ap_addr);
  3501. unsigned int link_id;
  3502. u64 changed = 0;
  3503. struct ieee80211_prep_tx_info info = {
  3504. .subtype = stype,
  3505. .was_assoc = true,
  3506. .link_id = ffs(sdata->vif.active_links) - 1,
  3507. };
  3508. lockdep_assert_wiphy(local->hw.wiphy);
  3509. if (frame_buf)
  3510. memset(frame_buf, 0, IEEE80211_DEAUTH_FRAME_LEN);
  3511. if (WARN_ON(!ap_sta))
  3512. return;
  3513. if (WARN_ON_ONCE(tx && !frame_buf))
  3514. return;
  3515. if (WARN_ON(!ifmgd->associated))
  3516. return;
  3517. ieee80211_stop_poll(sdata);
  3518. ifmgd->associated = false;
  3519. if (tx) {
  3520. bool tx_link_found = false;
  3521. for (link_id = 0;
  3522. link_id < ARRAY_SIZE(sdata->link);
  3523. link_id++) {
  3524. struct ieee80211_link_data *link;
  3525. if (!ieee80211_vif_link_active(&sdata->vif, link_id))
  3526. continue;
  3527. link = sdata_dereference(sdata->link[link_id], sdata);
  3528. if (WARN_ON_ONCE(!link))
  3529. continue;
  3530. if (link->u.mgd.csa.blocked_tx)
  3531. continue;
  3532. tx_link_found = true;
  3533. break;
  3534. }
  3535. tx = tx_link_found;
  3536. }
  3537. /* other links will be destroyed */
  3538. sdata->deflink.conf->bss = NULL;
  3539. sdata->deflink.conf->epcs_support = false;
  3540. sdata->deflink.smps_mode = IEEE80211_SMPS_OFF;
  3541. netif_carrier_off(sdata->dev);
  3542. /*
  3543. * if we want to get out of ps before disassoc (why?) we have
  3544. * to do it before sending disassoc, as otherwise the null-packet
  3545. * won't be valid.
  3546. */
  3547. if (local->hw.conf.flags & IEEE80211_CONF_PS) {
  3548. local->hw.conf.flags &= ~IEEE80211_CONF_PS;
  3549. ieee80211_hw_config(local, -1, IEEE80211_CONF_CHANGE_PS);
  3550. }
  3551. local->ps_sdata = NULL;
  3552. /* disable per-vif ps */
  3553. ieee80211_recalc_ps_vif(sdata);
  3554. /* make sure ongoing transmission finishes */
  3555. synchronize_net();
  3556. /*
  3557. * drop any frame before deauth/disassoc, this can be data or
  3558. * management frame. Since we are disconnecting, we should not
  3559. * insist sending these frames which can take time and delay
  3560. * the disconnection and possible the roaming.
  3561. */
  3562. ieee80211_flush_queues(local, sdata, true);
  3563. if (tx) {
  3564. drv_mgd_prepare_tx(sdata->local, sdata, &info);
  3565. ieee80211_send_deauth_disassoc(sdata, sdata->vif.cfg.ap_addr,
  3566. sdata->vif.cfg.ap_addr, stype,
  3567. reason, true, frame_buf);
  3568. /* flush out frame - make sure the deauth was actually sent */
  3569. ieee80211_flush_queues(local, sdata, false);
  3570. drv_mgd_complete_tx(sdata->local, sdata, &info);
  3571. } else if (frame_buf) {
  3572. ieee80211_send_deauth_disassoc(sdata, sdata->vif.cfg.ap_addr,
  3573. sdata->vif.cfg.ap_addr, stype,
  3574. reason, false, frame_buf);
  3575. }
  3576. /* clear AP addr only after building the needed mgmt frames */
  3577. eth_zero_addr(sdata->deflink.u.mgd.bssid);
  3578. eth_zero_addr(sdata->vif.cfg.ap_addr);
  3579. sdata->vif.cfg.ssid_len = 0;
  3580. /* Remove TDLS peers */
  3581. __sta_info_flush(sdata, false, -1, ap_sta);
  3582. if (sdata->vif.driver_flags & IEEE80211_VIF_REMOVE_AP_AFTER_DISASSOC) {
  3583. /* Only move the AP state */
  3584. sta_info_move_state(ap_sta, IEEE80211_STA_NONE);
  3585. } else {
  3586. /* Remove AP peer */
  3587. sta_info_flush(sdata, -1);
  3588. }
  3589. /* finally reset all BSS / config parameters */
  3590. if (!ieee80211_vif_is_mld(&sdata->vif))
  3591. changed |= ieee80211_reset_erp_info(sdata);
  3592. ieee80211_led_assoc(local, 0);
  3593. changed |= BSS_CHANGED_ASSOC;
  3594. sdata->vif.cfg.assoc = false;
  3595. sdata->deflink.u.mgd.p2p_noa_index = -1;
  3596. memset(&sdata->vif.bss_conf.p2p_noa_attr, 0,
  3597. sizeof(sdata->vif.bss_conf.p2p_noa_attr));
  3598. /* on the next assoc, re-program HT/VHT parameters */
  3599. memset(&ifmgd->ht_capa, 0, sizeof(ifmgd->ht_capa));
  3600. memset(&ifmgd->ht_capa_mask, 0, sizeof(ifmgd->ht_capa_mask));
  3601. memset(&ifmgd->vht_capa, 0, sizeof(ifmgd->vht_capa));
  3602. memset(&ifmgd->vht_capa_mask, 0, sizeof(ifmgd->vht_capa_mask));
  3603. /*
  3604. * reset MU-MIMO ownership and group data in default link,
  3605. * if used, other links are destroyed
  3606. */
  3607. memset(sdata->vif.bss_conf.mu_group.membership, 0,
  3608. sizeof(sdata->vif.bss_conf.mu_group.membership));
  3609. memset(sdata->vif.bss_conf.mu_group.position, 0,
  3610. sizeof(sdata->vif.bss_conf.mu_group.position));
  3611. if (!ieee80211_vif_is_mld(&sdata->vif))
  3612. changed |= BSS_CHANGED_MU_GROUPS;
  3613. sdata->vif.bss_conf.mu_mimo_owner = false;
  3614. sdata->deflink.ap_power_level = IEEE80211_UNSET_POWER_LEVEL;
  3615. timer_delete_sync(&local->dynamic_ps_timer);
  3616. wiphy_work_cancel(local->hw.wiphy, &local->dynamic_ps_enable_work);
  3617. /* Disable ARP filtering */
  3618. if (sdata->vif.cfg.arp_addr_cnt)
  3619. changed |= BSS_CHANGED_ARP_FILTER;
  3620. sdata->vif.bss_conf.qos = false;
  3621. if (!ieee80211_vif_is_mld(&sdata->vif)) {
  3622. changed |= BSS_CHANGED_QOS;
  3623. /* The BSSID (not really interesting) and HT changed */
  3624. changed |= BSS_CHANGED_BSSID | BSS_CHANGED_HT;
  3625. ieee80211_bss_info_change_notify(sdata, changed);
  3626. } else {
  3627. ieee80211_vif_cfg_change_notify(sdata, changed);
  3628. }
  3629. if (sdata->vif.driver_flags & IEEE80211_VIF_REMOVE_AP_AFTER_DISASSOC) {
  3630. /*
  3631. * After notifying the driver about the disassoc,
  3632. * remove the ap sta.
  3633. */
  3634. sta_info_flush(sdata, -1);
  3635. }
  3636. /* disassociated - set to defaults now */
  3637. ieee80211_set_wmm_default(&sdata->deflink, false, false);
  3638. timer_delete_sync(&sdata->u.mgd.conn_mon_timer);
  3639. timer_delete_sync(&sdata->u.mgd.bcn_mon_timer);
  3640. timer_delete_sync(&sdata->u.mgd.timer);
  3641. sdata->vif.bss_conf.dtim_period = 0;
  3642. sdata->vif.bss_conf.beacon_rate = NULL;
  3643. sdata->deflink.u.mgd.have_beacon = false;
  3644. sdata->deflink.u.mgd.tracking_signal_avg = false;
  3645. sdata->deflink.u.mgd.disable_wmm_tracking = false;
  3646. ifmgd->flags = 0;
  3647. for (link_id = 0; link_id < ARRAY_SIZE(sdata->link); link_id++) {
  3648. struct ieee80211_link_data *link;
  3649. link = sdata_dereference(sdata->link[link_id], sdata);
  3650. if (!link)
  3651. continue;
  3652. ieee80211_link_release_channel(link);
  3653. }
  3654. sdata->vif.bss_conf.csa_active = false;
  3655. sdata->deflink.u.mgd.csa.blocked_tx = false;
  3656. sdata->deflink.u.mgd.csa.waiting_bcn = false;
  3657. sdata->deflink.u.mgd.csa.ignored_same_chan = false;
  3658. ieee80211_vif_unblock_queues_csa(sdata);
  3659. /* existing TX TSPEC sessions no longer exist */
  3660. memset(ifmgd->tx_tspec, 0, sizeof(ifmgd->tx_tspec));
  3661. wiphy_delayed_work_cancel(local->hw.wiphy, &ifmgd->tx_tspec_wk);
  3662. sdata->vif.bss_conf.power_type = IEEE80211_REG_UNSET_AP;
  3663. sdata->vif.bss_conf.pwr_reduction = 0;
  3664. ieee80211_clear_tpe(&sdata->vif.bss_conf.tpe);
  3665. sdata->vif.cfg.eml_cap = 0;
  3666. sdata->vif.cfg.eml_med_sync_delay = 0;
  3667. sdata->vif.cfg.mld_capa_op = 0;
  3668. memset(&sdata->u.mgd.ttlm_info, 0,
  3669. sizeof(sdata->u.mgd.ttlm_info));
  3670. wiphy_hrtimer_work_cancel(sdata->local->hw.wiphy, &ifmgd->ttlm_work);
  3671. memset(&sdata->vif.neg_ttlm, 0, sizeof(sdata->vif.neg_ttlm));
  3672. wiphy_delayed_work_cancel(sdata->local->hw.wiphy,
  3673. &ifmgd->neg_ttlm_timeout_work);
  3674. sdata->u.mgd.removed_links = 0;
  3675. wiphy_hrtimer_work_cancel(sdata->local->hw.wiphy,
  3676. &sdata->u.mgd.ml_reconf_work);
  3677. wiphy_work_cancel(sdata->local->hw.wiphy,
  3678. &ifmgd->teardown_ttlm_work);
  3679. /* if disconnection happens in the middle of the ML reconfiguration
  3680. * flow, cfg80211 must called to release the BSS references obtained
  3681. * when the flow started.
  3682. */
  3683. ieee80211_ml_reconf_reset(sdata);
  3684. ieee80211_vif_set_links(sdata, 0, 0);
  3685. ifmgd->mcast_seq_last = IEEE80211_SN_MODULO;
  3686. ifmgd->epcs.enabled = false;
  3687. ifmgd->epcs.dialog_token = 0;
  3688. memset(ifmgd->userspace_selectors, 0,
  3689. sizeof(ifmgd->userspace_selectors));
  3690. }
  3691. static void ieee80211_reset_ap_probe(struct ieee80211_sub_if_data *sdata)
  3692. {
  3693. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  3694. struct ieee80211_local *local = sdata->local;
  3695. lockdep_assert_wiphy(local->hw.wiphy);
  3696. if (!(ifmgd->flags & IEEE80211_STA_CONNECTION_POLL))
  3697. return;
  3698. __ieee80211_stop_poll(sdata);
  3699. ieee80211_recalc_ps(local);
  3700. if (ieee80211_hw_check(&sdata->local->hw, CONNECTION_MONITOR))
  3701. return;
  3702. /*
  3703. * We've received a probe response, but are not sure whether
  3704. * we have or will be receiving any beacons or data, so let's
  3705. * schedule the timers again, just in case.
  3706. */
  3707. ieee80211_sta_reset_beacon_monitor(sdata);
  3708. mod_timer(&ifmgd->conn_mon_timer,
  3709. round_jiffies_up(jiffies +
  3710. IEEE80211_CONNECTION_IDLE_TIME));
  3711. }
  3712. static void ieee80211_sta_tx_wmm_ac_notify(struct ieee80211_sub_if_data *sdata,
  3713. struct ieee80211_hdr *hdr,
  3714. u16 tx_time)
  3715. {
  3716. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  3717. u16 tid;
  3718. int ac;
  3719. struct ieee80211_sta_tx_tspec *tx_tspec;
  3720. unsigned long now = jiffies;
  3721. if (!ieee80211_is_data_qos(hdr->frame_control))
  3722. return;
  3723. tid = ieee80211_get_tid(hdr);
  3724. ac = ieee80211_ac_from_tid(tid);
  3725. tx_tspec = &ifmgd->tx_tspec[ac];
  3726. if (likely(!tx_tspec->admitted_time))
  3727. return;
  3728. if (time_after(now, tx_tspec->time_slice_start + HZ)) {
  3729. tx_tspec->consumed_tx_time = 0;
  3730. tx_tspec->time_slice_start = now;
  3731. if (tx_tspec->downgraded) {
  3732. tx_tspec->action = TX_TSPEC_ACTION_STOP_DOWNGRADE;
  3733. wiphy_delayed_work_queue(sdata->local->hw.wiphy,
  3734. &ifmgd->tx_tspec_wk, 0);
  3735. }
  3736. }
  3737. if (tx_tspec->downgraded)
  3738. return;
  3739. tx_tspec->consumed_tx_time += tx_time;
  3740. if (tx_tspec->consumed_tx_time >= tx_tspec->admitted_time) {
  3741. tx_tspec->downgraded = true;
  3742. tx_tspec->action = TX_TSPEC_ACTION_DOWNGRADE;
  3743. wiphy_delayed_work_queue(sdata->local->hw.wiphy,
  3744. &ifmgd->tx_tspec_wk, 0);
  3745. }
  3746. }
  3747. void ieee80211_sta_tx_notify(struct ieee80211_sub_if_data *sdata,
  3748. struct ieee80211_hdr *hdr, bool ack, u16 tx_time)
  3749. {
  3750. ieee80211_sta_tx_wmm_ac_notify(sdata, hdr, tx_time);
  3751. if (!ieee80211_is_any_nullfunc(hdr->frame_control) ||
  3752. !sdata->u.mgd.probe_send_count)
  3753. return;
  3754. if (ack)
  3755. sdata->u.mgd.probe_send_count = 0;
  3756. else
  3757. sdata->u.mgd.nullfunc_failed = true;
  3758. wiphy_work_queue(sdata->local->hw.wiphy, &sdata->work);
  3759. }
  3760. static void ieee80211_mlme_send_probe_req(struct ieee80211_sub_if_data *sdata,
  3761. const u8 *src, const u8 *dst,
  3762. const u8 *ssid, size_t ssid_len,
  3763. struct ieee80211_channel *channel)
  3764. {
  3765. struct sk_buff *skb;
  3766. skb = ieee80211_build_probe_req(sdata, src, dst, (u32)-1, channel,
  3767. ssid, ssid_len, NULL, 0,
  3768. IEEE80211_PROBE_FLAG_DIRECTED);
  3769. if (skb)
  3770. ieee80211_tx_skb(sdata, skb);
  3771. }
  3772. static void ieee80211_mgd_probe_ap_send(struct ieee80211_sub_if_data *sdata)
  3773. {
  3774. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  3775. u8 *dst = sdata->vif.cfg.ap_addr;
  3776. u8 unicast_limit = max(1, max_probe_tries - 3);
  3777. struct sta_info *sta;
  3778. lockdep_assert_wiphy(sdata->local->hw.wiphy);
  3779. /*
  3780. * Try sending broadcast probe requests for the last three
  3781. * probe requests after the first ones failed since some
  3782. * buggy APs only support broadcast probe requests.
  3783. */
  3784. if (ifmgd->probe_send_count >= unicast_limit)
  3785. dst = NULL;
  3786. /*
  3787. * When the hardware reports an accurate Tx ACK status, it's
  3788. * better to send a nullfunc frame instead of a probe request,
  3789. * as it will kick us off the AP quickly if we aren't associated
  3790. * anymore. The timeout will be reset if the frame is ACKed by
  3791. * the AP.
  3792. */
  3793. ifmgd->probe_send_count++;
  3794. if (dst) {
  3795. sta = sta_info_get(sdata, dst);
  3796. if (!WARN_ON(!sta))
  3797. ieee80211_check_fast_rx(sta);
  3798. }
  3799. if (ieee80211_hw_check(&sdata->local->hw, REPORTS_TX_ACK_STATUS)) {
  3800. ifmgd->nullfunc_failed = false;
  3801. ieee80211_send_nullfunc(sdata->local, sdata, false);
  3802. } else {
  3803. ieee80211_mlme_send_probe_req(sdata, sdata->vif.addr, dst,
  3804. sdata->vif.cfg.ssid,
  3805. sdata->vif.cfg.ssid_len,
  3806. sdata->deflink.conf->bss->channel);
  3807. }
  3808. ifmgd->probe_timeout = jiffies + msecs_to_jiffies(probe_wait_ms);
  3809. run_again(sdata, ifmgd->probe_timeout);
  3810. }
  3811. static void ieee80211_mgd_probe_ap(struct ieee80211_sub_if_data *sdata,
  3812. bool beacon)
  3813. {
  3814. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  3815. bool already = false;
  3816. lockdep_assert_wiphy(sdata->local->hw.wiphy);
  3817. if (!ieee80211_sdata_running(sdata))
  3818. return;
  3819. if (!ifmgd->associated)
  3820. return;
  3821. if (sdata->local->tmp_channel || sdata->local->scanning)
  3822. return;
  3823. if (sdata->local->suspending) {
  3824. /* reschedule after resume */
  3825. ieee80211_reset_ap_probe(sdata);
  3826. return;
  3827. }
  3828. if (beacon) {
  3829. mlme_dbg_ratelimited(sdata,
  3830. "detected beacon loss from AP (missed %d beacons) - probing\n",
  3831. beacon_loss_count);
  3832. ieee80211_cqm_beacon_loss_notify(&sdata->vif, GFP_KERNEL);
  3833. }
  3834. /*
  3835. * The driver/our work has already reported this event or the
  3836. * connection monitoring has kicked in and we have already sent
  3837. * a probe request. Or maybe the AP died and the driver keeps
  3838. * reporting until we disassociate...
  3839. *
  3840. * In either case we have to ignore the current call to this
  3841. * function (except for setting the correct probe reason bit)
  3842. * because otherwise we would reset the timer every time and
  3843. * never check whether we received a probe response!
  3844. */
  3845. if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL)
  3846. already = true;
  3847. ifmgd->flags |= IEEE80211_STA_CONNECTION_POLL;
  3848. if (already)
  3849. return;
  3850. ieee80211_recalc_ps(sdata->local);
  3851. ifmgd->probe_send_count = 0;
  3852. ieee80211_mgd_probe_ap_send(sdata);
  3853. }
  3854. struct sk_buff *ieee80211_ap_probereq_get(struct ieee80211_hw *hw,
  3855. struct ieee80211_vif *vif)
  3856. {
  3857. struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
  3858. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  3859. struct cfg80211_bss *cbss;
  3860. struct sk_buff *skb;
  3861. const struct element *ssid;
  3862. int ssid_len;
  3863. lockdep_assert_wiphy(sdata->local->hw.wiphy);
  3864. if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION ||
  3865. ieee80211_vif_is_mld(&sdata->vif)))
  3866. return NULL;
  3867. if (ifmgd->associated)
  3868. cbss = sdata->deflink.conf->bss;
  3869. else if (ifmgd->auth_data)
  3870. cbss = ifmgd->auth_data->bss;
  3871. else if (ifmgd->assoc_data && ifmgd->assoc_data->link[0].bss)
  3872. cbss = ifmgd->assoc_data->link[0].bss;
  3873. else
  3874. return NULL;
  3875. rcu_read_lock();
  3876. ssid = ieee80211_bss_get_elem(cbss, WLAN_EID_SSID);
  3877. if (WARN_ONCE(!ssid || ssid->datalen > IEEE80211_MAX_SSID_LEN,
  3878. "invalid SSID element (len=%d)",
  3879. ssid ? ssid->datalen : -1))
  3880. ssid_len = 0;
  3881. else
  3882. ssid_len = ssid->datalen;
  3883. skb = ieee80211_build_probe_req(sdata, sdata->vif.addr, cbss->bssid,
  3884. (u32) -1, cbss->channel,
  3885. ssid->data, ssid_len,
  3886. NULL, 0, IEEE80211_PROBE_FLAG_DIRECTED);
  3887. rcu_read_unlock();
  3888. return skb;
  3889. }
  3890. EXPORT_SYMBOL(ieee80211_ap_probereq_get);
  3891. static void ieee80211_report_disconnect(struct ieee80211_sub_if_data *sdata,
  3892. const u8 *buf, size_t len, bool tx,
  3893. u16 reason, bool reconnect)
  3894. {
  3895. struct ieee80211_event event = {
  3896. .type = MLME_EVENT,
  3897. .u.mlme.data = tx ? DEAUTH_TX_EVENT : DEAUTH_RX_EVENT,
  3898. .u.mlme.reason = reason,
  3899. };
  3900. if (tx)
  3901. cfg80211_tx_mlme_mgmt(sdata->dev, buf, len, reconnect);
  3902. else
  3903. cfg80211_rx_mlme_mgmt(sdata->dev, buf, len);
  3904. drv_event_callback(sdata->local, sdata, &event);
  3905. }
  3906. static void __ieee80211_disconnect(struct ieee80211_sub_if_data *sdata)
  3907. {
  3908. struct ieee80211_local *local = sdata->local;
  3909. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  3910. u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
  3911. lockdep_assert_wiphy(local->hw.wiphy);
  3912. if (!ifmgd->associated)
  3913. return;
  3914. if (!ifmgd->driver_disconnect) {
  3915. unsigned int link_id;
  3916. /*
  3917. * AP is probably out of range (or not reachable for another
  3918. * reason) so remove the bss structs for that AP. In the case
  3919. * of multi-link, it's not clear that all of them really are
  3920. * out of range, but if they weren't the driver likely would
  3921. * have switched to just have a single link active?
  3922. */
  3923. for (link_id = 0;
  3924. link_id < ARRAY_SIZE(sdata->link);
  3925. link_id++) {
  3926. struct ieee80211_link_data *link;
  3927. link = sdata_dereference(sdata->link[link_id], sdata);
  3928. if (!link || !link->conf->bss)
  3929. continue;
  3930. cfg80211_unlink_bss(local->hw.wiphy, link->conf->bss);
  3931. link->conf->bss = NULL;
  3932. }
  3933. }
  3934. ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
  3935. ifmgd->driver_disconnect ?
  3936. WLAN_REASON_DEAUTH_LEAVING :
  3937. WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY,
  3938. true, frame_buf);
  3939. /* the other links will be destroyed */
  3940. sdata->vif.bss_conf.csa_active = false;
  3941. sdata->deflink.u.mgd.csa.waiting_bcn = false;
  3942. sdata->deflink.u.mgd.csa.blocked_tx = false;
  3943. ieee80211_vif_unblock_queues_csa(sdata);
  3944. ieee80211_report_disconnect(sdata, frame_buf, sizeof(frame_buf), true,
  3945. WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY,
  3946. ifmgd->reconnect);
  3947. ifmgd->reconnect = false;
  3948. }
  3949. static void ieee80211_beacon_connection_loss_work(struct wiphy *wiphy,
  3950. struct wiphy_work *work)
  3951. {
  3952. struct ieee80211_sub_if_data *sdata =
  3953. container_of(work, struct ieee80211_sub_if_data,
  3954. u.mgd.beacon_connection_loss_work);
  3955. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  3956. if (ifmgd->connection_loss) {
  3957. sdata_info(sdata, "Connection to AP %pM lost\n",
  3958. sdata->vif.cfg.ap_addr);
  3959. __ieee80211_disconnect(sdata);
  3960. ifmgd->connection_loss = false;
  3961. } else if (ifmgd->driver_disconnect) {
  3962. sdata_info(sdata,
  3963. "Driver requested disconnection from AP %pM\n",
  3964. sdata->vif.cfg.ap_addr);
  3965. __ieee80211_disconnect(sdata);
  3966. ifmgd->driver_disconnect = false;
  3967. } else {
  3968. if (ifmgd->associated)
  3969. sdata->deflink.u.mgd.beacon_loss_count++;
  3970. ieee80211_mgd_probe_ap(sdata, true);
  3971. }
  3972. }
  3973. static void ieee80211_csa_connection_drop_work(struct wiphy *wiphy,
  3974. struct wiphy_work *work)
  3975. {
  3976. struct ieee80211_sub_if_data *sdata =
  3977. container_of(work, struct ieee80211_sub_if_data,
  3978. u.mgd.csa_connection_drop_work);
  3979. __ieee80211_disconnect(sdata);
  3980. }
  3981. void ieee80211_beacon_loss(struct ieee80211_vif *vif)
  3982. {
  3983. struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
  3984. struct ieee80211_hw *hw = &sdata->local->hw;
  3985. trace_api_beacon_loss(sdata);
  3986. sdata->u.mgd.connection_loss = false;
  3987. wiphy_work_queue(hw->wiphy, &sdata->u.mgd.beacon_connection_loss_work);
  3988. }
  3989. EXPORT_SYMBOL(ieee80211_beacon_loss);
  3990. void ieee80211_connection_loss(struct ieee80211_vif *vif)
  3991. {
  3992. struct ieee80211_sub_if_data *sdata;
  3993. struct ieee80211_hw *hw;
  3994. KUNIT_STATIC_STUB_REDIRECT(ieee80211_connection_loss, vif);
  3995. sdata = vif_to_sdata(vif);
  3996. hw = &sdata->local->hw;
  3997. trace_api_connection_loss(sdata);
  3998. sdata->u.mgd.connection_loss = true;
  3999. wiphy_work_queue(hw->wiphy, &sdata->u.mgd.beacon_connection_loss_work);
  4000. }
  4001. EXPORT_SYMBOL(ieee80211_connection_loss);
  4002. void ieee80211_disconnect(struct ieee80211_vif *vif, bool reconnect)
  4003. {
  4004. struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
  4005. struct ieee80211_hw *hw = &sdata->local->hw;
  4006. trace_api_disconnect(sdata, reconnect);
  4007. if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
  4008. return;
  4009. sdata->u.mgd.driver_disconnect = true;
  4010. sdata->u.mgd.reconnect = reconnect;
  4011. wiphy_work_queue(hw->wiphy, &sdata->u.mgd.beacon_connection_loss_work);
  4012. }
  4013. EXPORT_SYMBOL(ieee80211_disconnect);
  4014. static void ieee80211_destroy_auth_data(struct ieee80211_sub_if_data *sdata,
  4015. bool assoc)
  4016. {
  4017. struct ieee80211_mgd_auth_data *auth_data = sdata->u.mgd.auth_data;
  4018. lockdep_assert_wiphy(sdata->local->hw.wiphy);
  4019. sdata->u.mgd.auth_data = NULL;
  4020. if (!assoc) {
  4021. /*
  4022. * we are not authenticated yet, the only timer that could be
  4023. * running is the timeout for the authentication response which
  4024. * which is not relevant anymore.
  4025. */
  4026. timer_delete_sync(&sdata->u.mgd.timer);
  4027. sta_info_destroy_addr(sdata, auth_data->ap_addr);
  4028. /* other links are destroyed */
  4029. eth_zero_addr(sdata->deflink.u.mgd.bssid);
  4030. ieee80211_link_info_change_notify(sdata, &sdata->deflink,
  4031. BSS_CHANGED_BSSID);
  4032. sdata->u.mgd.flags = 0;
  4033. ieee80211_link_release_channel(&sdata->deflink);
  4034. ieee80211_vif_set_links(sdata, 0, 0);
  4035. }
  4036. cfg80211_put_bss(sdata->local->hw.wiphy, auth_data->bss);
  4037. kfree(auth_data);
  4038. }
  4039. enum assoc_status {
  4040. ASSOC_SUCCESS,
  4041. ASSOC_REJECTED,
  4042. ASSOC_TIMEOUT,
  4043. ASSOC_ABANDON,
  4044. };
  4045. static void ieee80211_destroy_assoc_data(struct ieee80211_sub_if_data *sdata,
  4046. enum assoc_status status)
  4047. {
  4048. struct ieee80211_mgd_assoc_data *assoc_data = sdata->u.mgd.assoc_data;
  4049. lockdep_assert_wiphy(sdata->local->hw.wiphy);
  4050. sdata->u.mgd.assoc_data = NULL;
  4051. if (status != ASSOC_SUCCESS) {
  4052. /*
  4053. * we are not associated yet, the only timer that could be
  4054. * running is the timeout for the association response which
  4055. * which is not relevant anymore.
  4056. */
  4057. timer_delete_sync(&sdata->u.mgd.timer);
  4058. sta_info_destroy_addr(sdata, assoc_data->ap_addr);
  4059. eth_zero_addr(sdata->deflink.u.mgd.bssid);
  4060. ieee80211_link_info_change_notify(sdata, &sdata->deflink,
  4061. BSS_CHANGED_BSSID);
  4062. sdata->u.mgd.flags = 0;
  4063. sdata->vif.bss_conf.mu_mimo_owner = false;
  4064. if (status != ASSOC_REJECTED) {
  4065. struct cfg80211_assoc_failure data = {
  4066. .timeout = status == ASSOC_TIMEOUT,
  4067. };
  4068. int i;
  4069. BUILD_BUG_ON(ARRAY_SIZE(data.bss) !=
  4070. ARRAY_SIZE(assoc_data->link));
  4071. for (i = 0; i < ARRAY_SIZE(data.bss); i++)
  4072. data.bss[i] = assoc_data->link[i].bss;
  4073. if (ieee80211_vif_is_mld(&sdata->vif))
  4074. data.ap_mld_addr = assoc_data->ap_addr;
  4075. cfg80211_assoc_failure(sdata->dev, &data);
  4076. }
  4077. ieee80211_link_release_channel(&sdata->deflink);
  4078. ieee80211_vif_set_links(sdata, 0, 0);
  4079. }
  4080. kfree(assoc_data);
  4081. }
  4082. static void ieee80211_auth_challenge(struct ieee80211_sub_if_data *sdata,
  4083. struct ieee80211_mgmt *mgmt, size_t len)
  4084. {
  4085. struct ieee80211_local *local = sdata->local;
  4086. struct ieee80211_mgd_auth_data *auth_data = sdata->u.mgd.auth_data;
  4087. const struct element *challenge;
  4088. u8 *pos;
  4089. u32 tx_flags = 0;
  4090. struct ieee80211_prep_tx_info info = {
  4091. .subtype = IEEE80211_STYPE_AUTH,
  4092. .link_id = auth_data->link_id,
  4093. };
  4094. pos = mgmt->u.auth.variable;
  4095. challenge = cfg80211_find_elem(WLAN_EID_CHALLENGE, pos,
  4096. len - (pos - (u8 *)mgmt));
  4097. if (!challenge)
  4098. return;
  4099. auth_data->expected_transaction = 4;
  4100. drv_mgd_prepare_tx(sdata->local, sdata, &info);
  4101. if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
  4102. tx_flags = IEEE80211_TX_CTL_REQ_TX_STATUS |
  4103. IEEE80211_TX_INTFL_MLME_CONN_TX;
  4104. ieee80211_send_auth(sdata, 3, auth_data->algorithm, 0,
  4105. (void *)challenge,
  4106. challenge->datalen + sizeof(*challenge),
  4107. auth_data->ap_addr, auth_data->ap_addr,
  4108. auth_data->key, auth_data->key_len,
  4109. auth_data->key_idx, tx_flags);
  4110. }
  4111. static bool ieee80211_mark_sta_auth(struct ieee80211_sub_if_data *sdata)
  4112. {
  4113. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  4114. const u8 *ap_addr = ifmgd->auth_data->ap_addr;
  4115. struct sta_info *sta;
  4116. lockdep_assert_wiphy(sdata->local->hw.wiphy);
  4117. sdata_info(sdata, "authenticated\n");
  4118. ifmgd->auth_data->done = true;
  4119. ifmgd->auth_data->timeout = jiffies + IEEE80211_AUTH_WAIT_ASSOC;
  4120. ifmgd->auth_data->timeout_started = true;
  4121. run_again(sdata, ifmgd->auth_data->timeout);
  4122. /* move station state to auth */
  4123. sta = sta_info_get(sdata, ap_addr);
  4124. if (!sta) {
  4125. WARN_ONCE(1, "%s: STA %pM not found", sdata->name, ap_addr);
  4126. return false;
  4127. }
  4128. if (sta_info_move_state(sta, IEEE80211_STA_AUTH)) {
  4129. sdata_info(sdata, "failed moving %pM to auth\n", ap_addr);
  4130. return false;
  4131. }
  4132. return true;
  4133. }
  4134. static void ieee80211_rx_mgmt_auth(struct ieee80211_sub_if_data *sdata,
  4135. struct ieee80211_mgmt *mgmt, size_t len)
  4136. {
  4137. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  4138. u16 auth_alg, auth_transaction, status_code;
  4139. struct ieee80211_event event = {
  4140. .type = MLME_EVENT,
  4141. .u.mlme.data = AUTH_EVENT,
  4142. };
  4143. struct ieee80211_prep_tx_info info = {
  4144. .subtype = IEEE80211_STYPE_AUTH,
  4145. };
  4146. bool sae_need_confirm = false;
  4147. lockdep_assert_wiphy(sdata->local->hw.wiphy);
  4148. if (len < 24 + 6)
  4149. return;
  4150. if (!ifmgd->auth_data || ifmgd->auth_data->done)
  4151. return;
  4152. if (!ether_addr_equal(ifmgd->auth_data->ap_addr, mgmt->bssid))
  4153. return;
  4154. auth_alg = le16_to_cpu(mgmt->u.auth.auth_alg);
  4155. auth_transaction = le16_to_cpu(mgmt->u.auth.auth_transaction);
  4156. status_code = le16_to_cpu(mgmt->u.auth.status_code);
  4157. info.link_id = ifmgd->auth_data->link_id;
  4158. if (auth_alg != ifmgd->auth_data->algorithm ||
  4159. (auth_alg != WLAN_AUTH_SAE &&
  4160. auth_transaction != ifmgd->auth_data->expected_transaction) ||
  4161. (auth_alg == WLAN_AUTH_SAE &&
  4162. (auth_transaction < ifmgd->auth_data->expected_transaction ||
  4163. auth_transaction > 2))) {
  4164. sdata_info(sdata, "%pM unexpected authentication state: alg %d (expected %d) transact %d (expected %d)\n",
  4165. mgmt->sa, auth_alg, ifmgd->auth_data->algorithm,
  4166. auth_transaction,
  4167. ifmgd->auth_data->expected_transaction);
  4168. goto notify_driver;
  4169. }
  4170. if (status_code != WLAN_STATUS_SUCCESS) {
  4171. cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len);
  4172. if (auth_alg == WLAN_AUTH_SAE &&
  4173. (status_code == WLAN_STATUS_ANTI_CLOG_REQUIRED ||
  4174. (auth_transaction == 1 &&
  4175. (status_code == WLAN_STATUS_SAE_HASH_TO_ELEMENT ||
  4176. status_code == WLAN_STATUS_SAE_PK)))) {
  4177. /* waiting for userspace now */
  4178. ifmgd->auth_data->waiting = true;
  4179. ifmgd->auth_data->timeout =
  4180. jiffies + IEEE80211_AUTH_WAIT_SAE_RETRY;
  4181. ifmgd->auth_data->timeout_started = true;
  4182. run_again(sdata, ifmgd->auth_data->timeout);
  4183. if (auth_transaction == 1)
  4184. sae_need_confirm = true;
  4185. goto notify_driver;
  4186. }
  4187. sdata_info(sdata, "%pM denied authentication (status %d)\n",
  4188. mgmt->sa, status_code);
  4189. ieee80211_destroy_auth_data(sdata, false);
  4190. event.u.mlme.status = MLME_DENIED;
  4191. event.u.mlme.reason = status_code;
  4192. drv_event_callback(sdata->local, sdata, &event);
  4193. goto notify_driver;
  4194. }
  4195. switch (ifmgd->auth_data->algorithm) {
  4196. case WLAN_AUTH_OPEN:
  4197. case WLAN_AUTH_LEAP:
  4198. case WLAN_AUTH_FT:
  4199. case WLAN_AUTH_SAE:
  4200. case WLAN_AUTH_FILS_SK:
  4201. case WLAN_AUTH_FILS_SK_PFS:
  4202. case WLAN_AUTH_FILS_PK:
  4203. case WLAN_AUTH_EPPKE:
  4204. break;
  4205. case WLAN_AUTH_SHARED_KEY:
  4206. if (ifmgd->auth_data->expected_transaction != 4) {
  4207. ieee80211_auth_challenge(sdata, mgmt, len);
  4208. /* need another frame */
  4209. return;
  4210. }
  4211. break;
  4212. default:
  4213. WARN_ONCE(1, "invalid auth alg %d",
  4214. ifmgd->auth_data->algorithm);
  4215. goto notify_driver;
  4216. }
  4217. event.u.mlme.status = MLME_SUCCESS;
  4218. info.success = 1;
  4219. drv_event_callback(sdata->local, sdata, &event);
  4220. if (ifmgd->auth_data->algorithm != WLAN_AUTH_SAE ||
  4221. (auth_transaction == 2 &&
  4222. ifmgd->auth_data->expected_transaction == 2)) {
  4223. if (!ieee80211_mark_sta_auth(sdata))
  4224. return; /* ignore frame -- wait for timeout */
  4225. } else if (ifmgd->auth_data->algorithm == WLAN_AUTH_SAE &&
  4226. auth_transaction == 1) {
  4227. sae_need_confirm = true;
  4228. } else if (ifmgd->auth_data->algorithm == WLAN_AUTH_SAE &&
  4229. auth_transaction == 2) {
  4230. sdata_info(sdata, "SAE peer confirmed\n");
  4231. ifmgd->auth_data->peer_confirmed = true;
  4232. }
  4233. cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len);
  4234. notify_driver:
  4235. if (!sae_need_confirm)
  4236. drv_mgd_complete_tx(sdata->local, sdata, &info);
  4237. }
  4238. #define case_WLAN(type) \
  4239. case WLAN_REASON_##type: return #type
  4240. const char *ieee80211_get_reason_code_string(u16 reason_code)
  4241. {
  4242. switch (reason_code) {
  4243. case_WLAN(UNSPECIFIED);
  4244. case_WLAN(PREV_AUTH_NOT_VALID);
  4245. case_WLAN(DEAUTH_LEAVING);
  4246. case_WLAN(DISASSOC_DUE_TO_INACTIVITY);
  4247. case_WLAN(DISASSOC_AP_BUSY);
  4248. case_WLAN(CLASS2_FRAME_FROM_NONAUTH_STA);
  4249. case_WLAN(CLASS3_FRAME_FROM_NONASSOC_STA);
  4250. case_WLAN(DISASSOC_STA_HAS_LEFT);
  4251. case_WLAN(STA_REQ_ASSOC_WITHOUT_AUTH);
  4252. case_WLAN(DISASSOC_BAD_POWER);
  4253. case_WLAN(DISASSOC_BAD_SUPP_CHAN);
  4254. case_WLAN(INVALID_IE);
  4255. case_WLAN(MIC_FAILURE);
  4256. case_WLAN(4WAY_HANDSHAKE_TIMEOUT);
  4257. case_WLAN(GROUP_KEY_HANDSHAKE_TIMEOUT);
  4258. case_WLAN(IE_DIFFERENT);
  4259. case_WLAN(INVALID_GROUP_CIPHER);
  4260. case_WLAN(INVALID_PAIRWISE_CIPHER);
  4261. case_WLAN(INVALID_AKMP);
  4262. case_WLAN(UNSUPP_RSN_VERSION);
  4263. case_WLAN(INVALID_RSN_IE_CAP);
  4264. case_WLAN(IEEE8021X_FAILED);
  4265. case_WLAN(CIPHER_SUITE_REJECTED);
  4266. case_WLAN(DISASSOC_UNSPECIFIED_QOS);
  4267. case_WLAN(DISASSOC_QAP_NO_BANDWIDTH);
  4268. case_WLAN(DISASSOC_LOW_ACK);
  4269. case_WLAN(DISASSOC_QAP_EXCEED_TXOP);
  4270. case_WLAN(QSTA_LEAVE_QBSS);
  4271. case_WLAN(QSTA_NOT_USE);
  4272. case_WLAN(QSTA_REQUIRE_SETUP);
  4273. case_WLAN(QSTA_TIMEOUT);
  4274. case_WLAN(QSTA_CIPHER_NOT_SUPP);
  4275. case_WLAN(MESH_PEER_CANCELED);
  4276. case_WLAN(MESH_MAX_PEERS);
  4277. case_WLAN(MESH_CONFIG);
  4278. case_WLAN(MESH_CLOSE);
  4279. case_WLAN(MESH_MAX_RETRIES);
  4280. case_WLAN(MESH_CONFIRM_TIMEOUT);
  4281. case_WLAN(MESH_INVALID_GTK);
  4282. case_WLAN(MESH_INCONSISTENT_PARAM);
  4283. case_WLAN(MESH_INVALID_SECURITY);
  4284. case_WLAN(MESH_PATH_ERROR);
  4285. case_WLAN(MESH_PATH_NOFORWARD);
  4286. case_WLAN(MESH_PATH_DEST_UNREACHABLE);
  4287. case_WLAN(MAC_EXISTS_IN_MBSS);
  4288. case_WLAN(MESH_CHAN_REGULATORY);
  4289. case_WLAN(MESH_CHAN);
  4290. default: return "<unknown>";
  4291. }
  4292. }
  4293. static void ieee80211_rx_mgmt_deauth(struct ieee80211_sub_if_data *sdata,
  4294. struct ieee80211_mgmt *mgmt, size_t len)
  4295. {
  4296. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  4297. u16 reason_code = le16_to_cpu(mgmt->u.deauth.reason_code);
  4298. lockdep_assert_wiphy(sdata->local->hw.wiphy);
  4299. if (len < 24 + 2)
  4300. return;
  4301. if (!ether_addr_equal(mgmt->bssid, mgmt->sa)) {
  4302. ieee80211_tdls_handle_disconnect(sdata, mgmt->sa, reason_code);
  4303. return;
  4304. }
  4305. if (ifmgd->associated &&
  4306. ether_addr_equal(mgmt->bssid, sdata->vif.cfg.ap_addr)) {
  4307. sdata_info(sdata, "deauthenticated from %pM (Reason: %u=%s)\n",
  4308. sdata->vif.cfg.ap_addr, reason_code,
  4309. ieee80211_get_reason_code_string(reason_code));
  4310. ieee80211_set_disassoc(sdata, 0, 0, false, NULL);
  4311. ieee80211_report_disconnect(sdata, (u8 *)mgmt, len, false,
  4312. reason_code, false);
  4313. return;
  4314. }
  4315. if (ifmgd->assoc_data &&
  4316. ether_addr_equal(mgmt->bssid, ifmgd->assoc_data->ap_addr)) {
  4317. sdata_info(sdata,
  4318. "deauthenticated from %pM while associating (Reason: %u=%s)\n",
  4319. ifmgd->assoc_data->ap_addr, reason_code,
  4320. ieee80211_get_reason_code_string(reason_code));
  4321. ieee80211_destroy_assoc_data(sdata, ASSOC_ABANDON);
  4322. cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len);
  4323. return;
  4324. }
  4325. }
  4326. static void ieee80211_rx_mgmt_disassoc(struct ieee80211_sub_if_data *sdata,
  4327. struct ieee80211_mgmt *mgmt, size_t len)
  4328. {
  4329. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  4330. u16 reason_code;
  4331. lockdep_assert_wiphy(sdata->local->hw.wiphy);
  4332. if (len < 24 + 2)
  4333. return;
  4334. if (!ifmgd->associated ||
  4335. !ether_addr_equal(mgmt->bssid, sdata->vif.cfg.ap_addr))
  4336. return;
  4337. reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code);
  4338. if (!ether_addr_equal(mgmt->bssid, mgmt->sa)) {
  4339. ieee80211_tdls_handle_disconnect(sdata, mgmt->sa, reason_code);
  4340. return;
  4341. }
  4342. sdata_info(sdata, "disassociated from %pM (Reason: %u=%s)\n",
  4343. sdata->vif.cfg.ap_addr, reason_code,
  4344. ieee80211_get_reason_code_string(reason_code));
  4345. ieee80211_set_disassoc(sdata, 0, 0, false, NULL);
  4346. ieee80211_report_disconnect(sdata, (u8 *)mgmt, len, false, reason_code,
  4347. false);
  4348. }
  4349. static bool ieee80211_twt_req_supported(struct ieee80211_sub_if_data *sdata,
  4350. struct ieee80211_supported_band *sband,
  4351. const struct link_sta_info *link_sta,
  4352. const struct ieee802_11_elems *elems)
  4353. {
  4354. const struct ieee80211_sta_he_cap *own_he_cap =
  4355. ieee80211_get_he_iftype_cap_vif(sband, &sdata->vif);
  4356. if (elems->ext_capab_len < 10)
  4357. return false;
  4358. if (!(elems->ext_capab[9] & WLAN_EXT_CAPA10_TWT_RESPONDER_SUPPORT))
  4359. return false;
  4360. return link_sta->pub->he_cap.he_cap_elem.mac_cap_info[0] &
  4361. IEEE80211_HE_MAC_CAP0_TWT_RES &&
  4362. own_he_cap &&
  4363. (own_he_cap->he_cap_elem.mac_cap_info[0] &
  4364. IEEE80211_HE_MAC_CAP0_TWT_REQ);
  4365. }
  4366. static u64 ieee80211_recalc_twt_req(struct ieee80211_sub_if_data *sdata,
  4367. struct ieee80211_supported_band *sband,
  4368. struct ieee80211_link_data *link,
  4369. struct link_sta_info *link_sta,
  4370. struct ieee802_11_elems *elems)
  4371. {
  4372. bool twt = ieee80211_twt_req_supported(sdata, sband, link_sta, elems);
  4373. if (link->conf->twt_requester != twt) {
  4374. link->conf->twt_requester = twt;
  4375. return BSS_CHANGED_TWT;
  4376. }
  4377. return 0;
  4378. }
  4379. static bool ieee80211_twt_bcast_support(struct ieee80211_sub_if_data *sdata,
  4380. struct ieee80211_bss_conf *bss_conf,
  4381. struct ieee80211_supported_band *sband,
  4382. struct link_sta_info *link_sta)
  4383. {
  4384. const struct ieee80211_sta_he_cap *own_he_cap =
  4385. ieee80211_get_he_iftype_cap_vif(sband, &sdata->vif);
  4386. return bss_conf->he_support &&
  4387. (link_sta->pub->he_cap.he_cap_elem.mac_cap_info[2] &
  4388. IEEE80211_HE_MAC_CAP2_BCAST_TWT) &&
  4389. own_he_cap &&
  4390. (own_he_cap->he_cap_elem.mac_cap_info[2] &
  4391. IEEE80211_HE_MAC_CAP2_BCAST_TWT);
  4392. }
  4393. static void ieee80211_epcs_changed(struct ieee80211_sub_if_data *sdata,
  4394. bool enabled)
  4395. {
  4396. /* in any case this is called, dialog token should be reset */
  4397. sdata->u.mgd.epcs.dialog_token = 0;
  4398. if (sdata->u.mgd.epcs.enabled == enabled)
  4399. return;
  4400. sdata->u.mgd.epcs.enabled = enabled;
  4401. cfg80211_epcs_changed(sdata->dev, enabled);
  4402. }
  4403. static void ieee80211_epcs_teardown(struct ieee80211_sub_if_data *sdata)
  4404. {
  4405. struct ieee80211_local *local = sdata->local;
  4406. u8 link_id;
  4407. if (!sdata->u.mgd.epcs.enabled)
  4408. return;
  4409. lockdep_assert_wiphy(local->hw.wiphy);
  4410. for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS; link_id++) {
  4411. struct ieee802_11_elems *elems;
  4412. struct ieee80211_link_data *link;
  4413. const struct cfg80211_bss_ies *ies;
  4414. bool ret;
  4415. rcu_read_lock();
  4416. link = sdata_dereference(sdata->link[link_id], sdata);
  4417. if (!link || !link->conf || !link->conf->bss) {
  4418. rcu_read_unlock();
  4419. continue;
  4420. }
  4421. if (link->u.mgd.disable_wmm_tracking) {
  4422. rcu_read_unlock();
  4423. ieee80211_set_wmm_default(link, false, false);
  4424. continue;
  4425. }
  4426. ies = rcu_dereference(link->conf->bss->beacon_ies);
  4427. if (!ies) {
  4428. rcu_read_unlock();
  4429. ieee80211_set_wmm_default(link, false, false);
  4430. continue;
  4431. }
  4432. elems = ieee802_11_parse_elems(ies->data, ies->len,
  4433. IEEE80211_FTYPE_MGMT |
  4434. IEEE80211_STYPE_BEACON,
  4435. NULL);
  4436. if (!elems) {
  4437. rcu_read_unlock();
  4438. ieee80211_set_wmm_default(link, false, false);
  4439. continue;
  4440. }
  4441. ret = _ieee80211_sta_wmm_params(local, link,
  4442. elems->wmm_param,
  4443. elems->wmm_param_len,
  4444. elems->mu_edca_param_set);
  4445. kfree(elems);
  4446. rcu_read_unlock();
  4447. if (!ret) {
  4448. ieee80211_set_wmm_default(link, false, false);
  4449. continue;
  4450. }
  4451. ieee80211_mgd_set_link_qos_params(link);
  4452. ieee80211_link_info_change_notify(sdata, link, BSS_CHANGED_QOS);
  4453. }
  4454. }
  4455. static bool ieee80211_assoc_config_link(struct ieee80211_link_data *link,
  4456. struct link_sta_info *link_sta,
  4457. struct cfg80211_bss *cbss,
  4458. struct ieee80211_mgmt *mgmt,
  4459. const u8 *elem_start,
  4460. unsigned int elem_len,
  4461. u64 *changed)
  4462. {
  4463. struct ieee80211_sub_if_data *sdata = link->sdata;
  4464. struct ieee80211_mgd_assoc_data *assoc_data =
  4465. sdata->u.mgd.assoc_data ?: sdata->u.mgd.reconf.add_links_data;
  4466. struct ieee80211_bss_conf *bss_conf = link->conf;
  4467. struct ieee80211_local *local = sdata->local;
  4468. unsigned int link_id = link->link_id;
  4469. struct ieee80211_elems_parse_params parse_params = {
  4470. .mode = link->u.mgd.conn.mode,
  4471. .start = elem_start,
  4472. .len = elem_len,
  4473. .link_id = link_id == assoc_data->assoc_link_id ? -1 : link_id,
  4474. .from_ap = true,
  4475. .type = le16_to_cpu(mgmt->frame_control) & IEEE80211_FCTL_TYPE,
  4476. };
  4477. bool is_5ghz = cbss->channel->band == NL80211_BAND_5GHZ;
  4478. bool is_6ghz = cbss->channel->band == NL80211_BAND_6GHZ;
  4479. bool is_s1g = cbss->channel->band == NL80211_BAND_S1GHZ;
  4480. const struct cfg80211_bss_ies *bss_ies = NULL;
  4481. struct ieee80211_supported_band *sband;
  4482. struct ieee802_11_elems *elems;
  4483. const __le16 prof_bss_param_ch_present =
  4484. cpu_to_le16(IEEE80211_MLE_STA_CONTROL_BSS_PARAM_CHANGE_CNT_PRESENT);
  4485. u16 capab_info;
  4486. bool ret;
  4487. elems = ieee802_11_parse_elems_full(&parse_params);
  4488. if (!elems)
  4489. return false;
  4490. if (link_id == assoc_data->assoc_link_id) {
  4491. capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
  4492. /*
  4493. * we should not get to this flow unless the association was
  4494. * successful, so set the status directly to success
  4495. */
  4496. assoc_data->link[link_id].status = WLAN_STATUS_SUCCESS;
  4497. if (elems->ml_basic) {
  4498. int bss_param_ch_cnt =
  4499. ieee80211_mle_get_bss_param_ch_cnt((const void *)elems->ml_basic);
  4500. if (bss_param_ch_cnt < 0) {
  4501. ret = false;
  4502. goto out;
  4503. }
  4504. bss_conf->bss_param_ch_cnt = bss_param_ch_cnt;
  4505. bss_conf->bss_param_ch_cnt_link_id = link_id;
  4506. }
  4507. } else if (elems->parse_error & IEEE80211_PARSE_ERR_DUP_NEST_ML_BASIC ||
  4508. !elems->prof ||
  4509. !(elems->prof->control & prof_bss_param_ch_present)) {
  4510. ret = false;
  4511. goto out;
  4512. } else {
  4513. const u8 *ptr = elems->prof->variable +
  4514. elems->prof->sta_info_len - 1;
  4515. int bss_param_ch_cnt;
  4516. /*
  4517. * During parsing, we validated that these fields exist,
  4518. * otherwise elems->prof would have been set to NULL.
  4519. */
  4520. capab_info = get_unaligned_le16(ptr);
  4521. assoc_data->link[link_id].status = get_unaligned_le16(ptr + 2);
  4522. bss_param_ch_cnt =
  4523. ieee80211_mle_basic_sta_prof_bss_param_ch_cnt(elems->prof);
  4524. bss_conf->bss_param_ch_cnt = bss_param_ch_cnt;
  4525. bss_conf->bss_param_ch_cnt_link_id = link_id;
  4526. if (assoc_data->link[link_id].status != WLAN_STATUS_SUCCESS) {
  4527. link_info(link, "association response status code=%u\n",
  4528. assoc_data->link[link_id].status);
  4529. ret = true;
  4530. goto out;
  4531. }
  4532. }
  4533. if (!is_s1g && !elems->supp_rates) {
  4534. sdata_info(sdata, "no SuppRates element in AssocResp\n");
  4535. ret = false;
  4536. goto out;
  4537. }
  4538. link->u.mgd.tdls_chan_switch_prohibited =
  4539. elems->ext_capab && elems->ext_capab_len >= 5 &&
  4540. (elems->ext_capab[4] & WLAN_EXT_CAPA5_TDLS_CH_SW_PROHIBITED);
  4541. /*
  4542. * Some APs are erroneously not including some information in their
  4543. * (re)association response frames. Try to recover by using the data
  4544. * from the beacon or probe response. This seems to afflict mobile
  4545. * 2G/3G/4G wifi routers, reported models include the "Onda PN51T",
  4546. * "Vodafone PocketWiFi 2", "ZTE MF60" and a similar T-Mobile device.
  4547. */
  4548. if (!ieee80211_hw_check(&local->hw, STRICT) && !is_6ghz &&
  4549. ((assoc_data->wmm && !elems->wmm_param) ||
  4550. (link->u.mgd.conn.mode >= IEEE80211_CONN_MODE_HT &&
  4551. (!elems->ht_cap_elem || !elems->ht_operation)) ||
  4552. (is_5ghz && link->u.mgd.conn.mode >= IEEE80211_CONN_MODE_VHT &&
  4553. (!elems->vht_cap_elem || !elems->vht_operation)))) {
  4554. const struct cfg80211_bss_ies *ies;
  4555. struct ieee802_11_elems *bss_elems;
  4556. rcu_read_lock();
  4557. ies = rcu_dereference(cbss->ies);
  4558. if (ies)
  4559. bss_ies = kmemdup(ies, sizeof(*ies) + ies->len,
  4560. GFP_ATOMIC);
  4561. rcu_read_unlock();
  4562. if (!bss_ies) {
  4563. ret = false;
  4564. goto out;
  4565. }
  4566. parse_params.start = bss_ies->data;
  4567. parse_params.len = bss_ies->len;
  4568. parse_params.bss = cbss;
  4569. parse_params.link_id = -1;
  4570. bss_elems = ieee802_11_parse_elems_full(&parse_params);
  4571. if (!bss_elems) {
  4572. ret = false;
  4573. goto out;
  4574. }
  4575. if (assoc_data->wmm &&
  4576. !elems->wmm_param && bss_elems->wmm_param) {
  4577. elems->wmm_param = bss_elems->wmm_param;
  4578. sdata_info(sdata,
  4579. "AP bug: WMM param missing from AssocResp\n");
  4580. }
  4581. /*
  4582. * Also check if we requested HT/VHT, otherwise the AP doesn't
  4583. * have to include the IEs in the (re)association response.
  4584. */
  4585. if (!elems->ht_cap_elem && bss_elems->ht_cap_elem &&
  4586. link->u.mgd.conn.mode >= IEEE80211_CONN_MODE_HT) {
  4587. elems->ht_cap_elem = bss_elems->ht_cap_elem;
  4588. sdata_info(sdata,
  4589. "AP bug: HT capability missing from AssocResp\n");
  4590. }
  4591. if (!elems->ht_operation && bss_elems->ht_operation &&
  4592. link->u.mgd.conn.mode >= IEEE80211_CONN_MODE_HT) {
  4593. elems->ht_operation = bss_elems->ht_operation;
  4594. sdata_info(sdata,
  4595. "AP bug: HT operation missing from AssocResp\n");
  4596. }
  4597. if (is_5ghz) {
  4598. if (!elems->vht_cap_elem && bss_elems->vht_cap_elem &&
  4599. link->u.mgd.conn.mode >= IEEE80211_CONN_MODE_VHT) {
  4600. elems->vht_cap_elem = bss_elems->vht_cap_elem;
  4601. sdata_info(sdata,
  4602. "AP bug: VHT capa missing from AssocResp\n");
  4603. }
  4604. if (!elems->vht_operation && bss_elems->vht_operation &&
  4605. link->u.mgd.conn.mode >= IEEE80211_CONN_MODE_VHT) {
  4606. elems->vht_operation = bss_elems->vht_operation;
  4607. sdata_info(sdata,
  4608. "AP bug: VHT operation missing from AssocResp\n");
  4609. }
  4610. }
  4611. kfree(bss_elems);
  4612. }
  4613. /*
  4614. * We previously checked these in the beacon/probe response, so
  4615. * they should be present here. This is just a safety net.
  4616. * Note that the ieee80211_config_bw() below would also check
  4617. * for this (and more), but this has better error reporting.
  4618. */
  4619. if (!is_6ghz && link->u.mgd.conn.mode >= IEEE80211_CONN_MODE_HT &&
  4620. (!elems->wmm_param || !elems->ht_cap_elem || !elems->ht_operation)) {
  4621. sdata_info(sdata,
  4622. "HT AP is missing WMM params or HT capability/operation\n");
  4623. ret = false;
  4624. goto out;
  4625. }
  4626. if (is_5ghz && link->u.mgd.conn.mode >= IEEE80211_CONN_MODE_VHT &&
  4627. (!elems->vht_cap_elem || !elems->vht_operation)) {
  4628. sdata_info(sdata,
  4629. "VHT AP is missing VHT capability/operation\n");
  4630. ret = false;
  4631. goto out;
  4632. }
  4633. /* check/update if AP changed anything in assoc response vs. scan */
  4634. if (ieee80211_config_bw(link, elems,
  4635. link_id == assoc_data->assoc_link_id,
  4636. changed,
  4637. le16_to_cpu(mgmt->frame_control) &
  4638. IEEE80211_FCTL_STYPE)) {
  4639. ret = false;
  4640. goto out;
  4641. }
  4642. if (WARN_ON(!link->conf->chanreq.oper.chan)) {
  4643. ret = false;
  4644. goto out;
  4645. }
  4646. sband = local->hw.wiphy->bands[link->conf->chanreq.oper.chan->band];
  4647. /* Set up internal HT/VHT capabilities */
  4648. if (elems->ht_cap_elem && link->u.mgd.conn.mode >= IEEE80211_CONN_MODE_HT)
  4649. ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
  4650. elems->ht_cap_elem,
  4651. link_sta);
  4652. if (elems->vht_cap_elem &&
  4653. link->u.mgd.conn.mode >= IEEE80211_CONN_MODE_VHT) {
  4654. const struct ieee80211_vht_cap *bss_vht_cap = NULL;
  4655. const struct cfg80211_bss_ies *ies;
  4656. /*
  4657. * Cisco AP module 9115 with FW 17.3 has a bug and sends a
  4658. * too large maximum MPDU length in the association response
  4659. * (indicating 12k) that it cannot actually process ...
  4660. * Work around that.
  4661. */
  4662. rcu_read_lock();
  4663. ies = rcu_dereference(cbss->ies);
  4664. if (ies) {
  4665. const struct element *elem;
  4666. elem = cfg80211_find_elem(WLAN_EID_VHT_CAPABILITY,
  4667. ies->data, ies->len);
  4668. if (elem && elem->datalen >= sizeof(*bss_vht_cap))
  4669. bss_vht_cap = (const void *)elem->data;
  4670. }
  4671. if (ieee80211_hw_check(&local->hw, STRICT) &&
  4672. (!bss_vht_cap || memcmp(bss_vht_cap, elems->vht_cap_elem,
  4673. sizeof(*bss_vht_cap)))) {
  4674. rcu_read_unlock();
  4675. ret = false;
  4676. link_info(link, "VHT capabilities mismatch\n");
  4677. goto out;
  4678. }
  4679. ieee80211_vht_cap_ie_to_sta_vht_cap(sdata, sband,
  4680. elems->vht_cap_elem,
  4681. bss_vht_cap, link_sta);
  4682. rcu_read_unlock();
  4683. }
  4684. if (elems->he_operation &&
  4685. link->u.mgd.conn.mode >= IEEE80211_CONN_MODE_HE &&
  4686. elems->he_cap) {
  4687. ieee80211_he_cap_ie_to_sta_he_cap(sdata, sband,
  4688. elems->he_cap,
  4689. elems->he_cap_len,
  4690. elems->he_6ghz_capa,
  4691. link_sta);
  4692. bss_conf->he_support = link_sta->pub->he_cap.has_he;
  4693. if (elems->rsnx && elems->rsnx_len &&
  4694. (elems->rsnx[0] & WLAN_RSNX_CAPA_PROTECTED_TWT) &&
  4695. wiphy_ext_feature_isset(local->hw.wiphy,
  4696. NL80211_EXT_FEATURE_PROTECTED_TWT))
  4697. bss_conf->twt_protected = true;
  4698. else
  4699. bss_conf->twt_protected = false;
  4700. *changed |= ieee80211_recalc_twt_req(sdata, sband, link,
  4701. link_sta, elems);
  4702. if (elems->eht_operation && elems->eht_cap &&
  4703. link->u.mgd.conn.mode >= IEEE80211_CONN_MODE_EHT) {
  4704. ieee80211_eht_cap_ie_to_sta_eht_cap(sdata, sband,
  4705. elems->he_cap,
  4706. elems->he_cap_len,
  4707. elems->eht_cap,
  4708. elems->eht_cap_len,
  4709. link_sta);
  4710. bss_conf->eht_support = link_sta->pub->eht_cap.has_eht;
  4711. bss_conf->epcs_support = bss_conf->eht_support &&
  4712. !!(elems->eht_cap->fixed.mac_cap_info[0] &
  4713. IEEE80211_EHT_MAC_CAP0_EPCS_PRIO_ACCESS);
  4714. /* EPCS might be already enabled but a new added link
  4715. * does not support EPCS. This should not really happen
  4716. * in practice.
  4717. */
  4718. if (sdata->u.mgd.epcs.enabled &&
  4719. !bss_conf->epcs_support)
  4720. ieee80211_epcs_teardown(sdata);
  4721. } else {
  4722. bss_conf->eht_support = false;
  4723. bss_conf->epcs_support = false;
  4724. }
  4725. } else {
  4726. bss_conf->he_support = false;
  4727. bss_conf->twt_requester = false;
  4728. bss_conf->twt_protected = false;
  4729. bss_conf->eht_support = false;
  4730. bss_conf->epcs_support = false;
  4731. }
  4732. if (elems->uhr_operation && elems->uhr_cap &&
  4733. link->u.mgd.conn.mode >= IEEE80211_CONN_MODE_UHR) {
  4734. ieee80211_uhr_cap_ie_to_sta_uhr_cap(sdata, sband,
  4735. elems->uhr_cap,
  4736. elems->uhr_cap_len,
  4737. link_sta);
  4738. bss_conf->uhr_support = link_sta->pub->uhr_cap.has_uhr;
  4739. } else {
  4740. bss_conf->uhr_support = false;
  4741. }
  4742. if (elems->s1g_oper &&
  4743. link->u.mgd.conn.mode == IEEE80211_CONN_MODE_S1G &&
  4744. elems->s1g_capab)
  4745. ieee80211_s1g_cap_to_sta_s1g_cap(sdata, elems->s1g_capab,
  4746. link_sta);
  4747. bss_conf->twt_broadcast =
  4748. ieee80211_twt_bcast_support(sdata, bss_conf, sband, link_sta);
  4749. if (bss_conf->he_support) {
  4750. bss_conf->he_bss_color.color =
  4751. le32_get_bits(elems->he_operation->he_oper_params,
  4752. IEEE80211_HE_OPERATION_BSS_COLOR_MASK);
  4753. bss_conf->he_bss_color.partial =
  4754. le32_get_bits(elems->he_operation->he_oper_params,
  4755. IEEE80211_HE_OPERATION_PARTIAL_BSS_COLOR);
  4756. bss_conf->he_bss_color.enabled =
  4757. !le32_get_bits(elems->he_operation->he_oper_params,
  4758. IEEE80211_HE_OPERATION_BSS_COLOR_DISABLED);
  4759. if (bss_conf->he_bss_color.enabled)
  4760. *changed |= BSS_CHANGED_HE_BSS_COLOR;
  4761. bss_conf->htc_trig_based_pkt_ext =
  4762. le32_get_bits(elems->he_operation->he_oper_params,
  4763. IEEE80211_HE_OPERATION_DFLT_PE_DURATION_MASK);
  4764. bss_conf->frame_time_rts_th =
  4765. le32_get_bits(elems->he_operation->he_oper_params,
  4766. IEEE80211_HE_OPERATION_RTS_THRESHOLD_MASK);
  4767. bss_conf->uora_exists = !!elems->uora_element;
  4768. if (elems->uora_element)
  4769. bss_conf->uora_ocw_range = elems->uora_element[0];
  4770. ieee80211_he_op_ie_to_bss_conf(&sdata->vif, elems->he_operation);
  4771. ieee80211_he_spr_ie_to_bss_conf(&sdata->vif, elems->he_spr);
  4772. /* TODO: OPEN: what happens if BSS color disable is set? */
  4773. }
  4774. if (cbss->transmitted_bss) {
  4775. bss_conf->nontransmitted = true;
  4776. ether_addr_copy(bss_conf->transmitter_bssid,
  4777. cbss->transmitted_bss->bssid);
  4778. bss_conf->bssid_indicator = cbss->max_bssid_indicator;
  4779. bss_conf->bssid_index = cbss->bssid_index;
  4780. }
  4781. /*
  4782. * Some APs, e.g. Netgear WNDR3700, report invalid HT operation data
  4783. * in their association response, so ignore that data for our own
  4784. * configuration. If it changed since the last beacon, we'll get the
  4785. * next beacon and update then.
  4786. */
  4787. /*
  4788. * If an operating mode notification IE is present, override the
  4789. * NSS calculation (that would be done in rate_control_rate_init())
  4790. * and use the # of streams from that element.
  4791. */
  4792. if (elems->opmode_notif &&
  4793. !(*elems->opmode_notif & IEEE80211_OPMODE_NOTIF_RX_NSS_TYPE_BF)) {
  4794. u8 nss;
  4795. nss = *elems->opmode_notif & IEEE80211_OPMODE_NOTIF_RX_NSS_MASK;
  4796. nss >>= IEEE80211_OPMODE_NOTIF_RX_NSS_SHIFT;
  4797. nss += 1;
  4798. link_sta->pub->rx_nss = nss;
  4799. }
  4800. /*
  4801. * Always handle WMM once after association regardless
  4802. * of the first value the AP uses. Setting -1 here has
  4803. * that effect because the AP values is an unsigned
  4804. * 4-bit value.
  4805. */
  4806. link->u.mgd.wmm_last_param_set = -1;
  4807. link->u.mgd.mu_edca_last_param_set = -1;
  4808. if (link->u.mgd.disable_wmm_tracking) {
  4809. ieee80211_set_wmm_default(link, false, false);
  4810. } else if (!ieee80211_sta_wmm_params(local, link, elems->wmm_param,
  4811. elems->wmm_param_len,
  4812. elems->mu_edca_param_set)) {
  4813. /* still enable QoS since we might have HT/VHT */
  4814. ieee80211_set_wmm_default(link, false, true);
  4815. /* disable WMM tracking in this case to disable
  4816. * tracking WMM parameter changes in the beacon if
  4817. * the parameters weren't actually valid. Doing so
  4818. * avoids changing parameters very strangely when
  4819. * the AP is going back and forth between valid and
  4820. * invalid parameters.
  4821. */
  4822. link->u.mgd.disable_wmm_tracking = true;
  4823. }
  4824. if (elems->max_idle_period_ie) {
  4825. bss_conf->max_idle_period =
  4826. le16_to_cpu(elems->max_idle_period_ie->max_idle_period);
  4827. bss_conf->protected_keep_alive =
  4828. !!(elems->max_idle_period_ie->idle_options &
  4829. WLAN_IDLE_OPTIONS_PROTECTED_KEEP_ALIVE);
  4830. *changed |= BSS_CHANGED_KEEP_ALIVE;
  4831. } else {
  4832. bss_conf->max_idle_period = 0;
  4833. bss_conf->protected_keep_alive = false;
  4834. }
  4835. /* set assoc capability (AID was already set earlier),
  4836. * ieee80211_set_associated() will tell the driver */
  4837. bss_conf->assoc_capability = capab_info;
  4838. ret = true;
  4839. out:
  4840. kfree(elems);
  4841. kfree(bss_ies);
  4842. return ret;
  4843. }
  4844. static int ieee80211_mgd_setup_link_sta(struct ieee80211_link_data *link,
  4845. struct sta_info *sta,
  4846. struct link_sta_info *link_sta,
  4847. struct cfg80211_bss *cbss)
  4848. {
  4849. struct ieee80211_sub_if_data *sdata = link->sdata;
  4850. struct ieee80211_local *local = sdata->local;
  4851. struct ieee80211_bss *bss = (void *)cbss->priv;
  4852. u32 rates = 0, basic_rates = 0;
  4853. bool have_higher_than_11mbit = false;
  4854. int min_rate = INT_MAX, min_rate_index = -1;
  4855. struct ieee80211_supported_band *sband;
  4856. memcpy(link_sta->addr, cbss->bssid, ETH_ALEN);
  4857. memcpy(link_sta->pub->addr, cbss->bssid, ETH_ALEN);
  4858. /* TODO: S1G Basic Rate Set is expressed elsewhere */
  4859. if (cbss->channel->band == NL80211_BAND_S1GHZ) {
  4860. ieee80211_s1g_sta_rate_init(sta);
  4861. return 0;
  4862. }
  4863. sband = local->hw.wiphy->bands[cbss->channel->band];
  4864. ieee80211_get_rates(sband, bss->supp_rates, bss->supp_rates_len,
  4865. NULL, 0,
  4866. &rates, &basic_rates, NULL,
  4867. &have_higher_than_11mbit,
  4868. &min_rate, &min_rate_index);
  4869. /*
  4870. * This used to be a workaround for basic rates missing
  4871. * in the association response frame. Now that we no
  4872. * longer use the basic rates from there, it probably
  4873. * doesn't happen any more, but keep the workaround so
  4874. * in case some *other* APs are buggy in different ways
  4875. * we can connect -- with a warning.
  4876. * Allow this workaround only in case the AP provided at least
  4877. * one rate.
  4878. */
  4879. if (min_rate_index < 0) {
  4880. link_info(link, "No legacy rates in association response\n");
  4881. return -EINVAL;
  4882. } else if (!basic_rates) {
  4883. link_info(link, "No basic rates, using min rate instead\n");
  4884. basic_rates = BIT(min_rate_index);
  4885. }
  4886. if (rates)
  4887. link_sta->pub->supp_rates[cbss->channel->band] = rates;
  4888. else
  4889. link_info(link, "No rates found, keeping mandatory only\n");
  4890. link->conf->basic_rates = basic_rates;
  4891. /* cf. IEEE 802.11 9.2.12 */
  4892. link->operating_11g_mode = sband->band == NL80211_BAND_2GHZ &&
  4893. have_higher_than_11mbit;
  4894. return 0;
  4895. }
  4896. static u8 ieee80211_max_rx_chains(struct ieee80211_link_data *link,
  4897. struct cfg80211_bss *cbss)
  4898. {
  4899. struct ieee80211_he_mcs_nss_supp *he_mcs_nss_supp;
  4900. const struct element *ht_cap_elem, *vht_cap_elem;
  4901. const struct cfg80211_bss_ies *ies;
  4902. const struct ieee80211_ht_cap *ht_cap;
  4903. const struct ieee80211_vht_cap *vht_cap;
  4904. const struct ieee80211_he_cap_elem *he_cap;
  4905. const struct element *he_cap_elem;
  4906. u16 mcs_80_map, mcs_160_map;
  4907. int i, mcs_nss_size;
  4908. bool support_160;
  4909. u8 chains = 1;
  4910. if (link->u.mgd.conn.mode < IEEE80211_CONN_MODE_HT)
  4911. return chains;
  4912. ht_cap_elem = ieee80211_bss_get_elem(cbss, WLAN_EID_HT_CAPABILITY);
  4913. if (ht_cap_elem && ht_cap_elem->datalen >= sizeof(*ht_cap)) {
  4914. ht_cap = (void *)ht_cap_elem->data;
  4915. chains = ieee80211_mcs_to_chains(&ht_cap->mcs);
  4916. /*
  4917. * TODO: use "Tx Maximum Number Spatial Streams Supported" and
  4918. * "Tx Unequal Modulation Supported" fields.
  4919. */
  4920. }
  4921. if (link->u.mgd.conn.mode < IEEE80211_CONN_MODE_VHT)
  4922. return chains;
  4923. vht_cap_elem = ieee80211_bss_get_elem(cbss, WLAN_EID_VHT_CAPABILITY);
  4924. if (vht_cap_elem && vht_cap_elem->datalen >= sizeof(*vht_cap)) {
  4925. u8 nss;
  4926. u16 tx_mcs_map;
  4927. vht_cap = (void *)vht_cap_elem->data;
  4928. tx_mcs_map = le16_to_cpu(vht_cap->supp_mcs.tx_mcs_map);
  4929. for (nss = 8; nss > 0; nss--) {
  4930. if (((tx_mcs_map >> (2 * (nss - 1))) & 3) !=
  4931. IEEE80211_VHT_MCS_NOT_SUPPORTED)
  4932. break;
  4933. }
  4934. /* TODO: use "Tx Highest Supported Long GI Data Rate" field? */
  4935. chains = max(chains, nss);
  4936. }
  4937. if (link->u.mgd.conn.mode < IEEE80211_CONN_MODE_HE)
  4938. return chains;
  4939. ies = rcu_dereference(cbss->ies);
  4940. he_cap_elem = cfg80211_find_ext_elem(WLAN_EID_EXT_HE_CAPABILITY,
  4941. ies->data, ies->len);
  4942. if (!he_cap_elem || he_cap_elem->datalen < sizeof(*he_cap) + 1)
  4943. return chains;
  4944. /* skip one byte ext_tag_id */
  4945. he_cap = (void *)(he_cap_elem->data + 1);
  4946. mcs_nss_size = ieee80211_he_mcs_nss_size(he_cap);
  4947. /* invalid HE IE */
  4948. if (he_cap_elem->datalen < 1 + mcs_nss_size + sizeof(*he_cap))
  4949. return chains;
  4950. /* mcs_nss is right after he_cap info */
  4951. he_mcs_nss_supp = (void *)(he_cap + 1);
  4952. mcs_80_map = le16_to_cpu(he_mcs_nss_supp->tx_mcs_80);
  4953. for (i = 7; i >= 0; i--) {
  4954. u8 mcs_80 = mcs_80_map >> (2 * i) & 3;
  4955. if (mcs_80 != IEEE80211_VHT_MCS_NOT_SUPPORTED) {
  4956. chains = max_t(u8, chains, i + 1);
  4957. break;
  4958. }
  4959. }
  4960. support_160 = he_cap->phy_cap_info[0] &
  4961. IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G;
  4962. if (!support_160)
  4963. return chains;
  4964. mcs_160_map = le16_to_cpu(he_mcs_nss_supp->tx_mcs_160);
  4965. for (i = 7; i >= 0; i--) {
  4966. u8 mcs_160 = mcs_160_map >> (2 * i) & 3;
  4967. if (mcs_160 != IEEE80211_VHT_MCS_NOT_SUPPORTED) {
  4968. chains = max_t(u8, chains, i + 1);
  4969. break;
  4970. }
  4971. }
  4972. return chains;
  4973. }
  4974. static void
  4975. ieee80211_determine_our_sta_mode(struct ieee80211_sub_if_data *sdata,
  4976. struct ieee80211_supported_band *sband,
  4977. struct cfg80211_assoc_request *req,
  4978. bool wmm_used, int link_id,
  4979. struct ieee80211_conn_settings *conn)
  4980. {
  4981. struct ieee80211_sta_ht_cap sta_ht_cap = sband->ht_cap;
  4982. bool is_5ghz = sband->band == NL80211_BAND_5GHZ;
  4983. bool is_6ghz = sband->band == NL80211_BAND_6GHZ;
  4984. const struct ieee80211_sta_he_cap *he_cap;
  4985. const struct ieee80211_sta_eht_cap *eht_cap;
  4986. const struct ieee80211_sta_uhr_cap *uhr_cap;
  4987. struct ieee80211_sta_vht_cap vht_cap;
  4988. if (sband->band == NL80211_BAND_S1GHZ) {
  4989. conn->mode = IEEE80211_CONN_MODE_S1G;
  4990. conn->bw_limit = IEEE80211_CONN_BW_LIMIT_20;
  4991. mlme_dbg(sdata, "operating as S1G STA\n");
  4992. return;
  4993. }
  4994. conn->mode = IEEE80211_CONN_MODE_LEGACY;
  4995. conn->bw_limit = IEEE80211_CONN_BW_LIMIT_20;
  4996. ieee80211_apply_htcap_overrides(sdata, &sta_ht_cap);
  4997. if (req && req->flags & ASSOC_REQ_DISABLE_HT) {
  4998. mlme_link_id_dbg(sdata, link_id,
  4999. "HT disabled by flag, limiting to legacy\n");
  5000. goto out;
  5001. }
  5002. if (!wmm_used) {
  5003. mlme_link_id_dbg(sdata, link_id,
  5004. "WMM/QoS not supported, limiting to legacy\n");
  5005. goto out;
  5006. }
  5007. if (req) {
  5008. unsigned int i;
  5009. for (i = 0; i < req->crypto.n_ciphers_pairwise; i++) {
  5010. if (req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP40 ||
  5011. req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_TKIP ||
  5012. req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP104) {
  5013. netdev_info(sdata->dev,
  5014. "WEP/TKIP use, limiting to legacy\n");
  5015. goto out;
  5016. }
  5017. }
  5018. }
  5019. if (!sta_ht_cap.ht_supported && !is_6ghz) {
  5020. mlme_link_id_dbg(sdata, link_id,
  5021. "HT not supported (and not on 6 GHz), limiting to legacy\n");
  5022. goto out;
  5023. }
  5024. /* HT is fine */
  5025. conn->mode = IEEE80211_CONN_MODE_HT;
  5026. conn->bw_limit = sta_ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40 ?
  5027. IEEE80211_CONN_BW_LIMIT_40 :
  5028. IEEE80211_CONN_BW_LIMIT_20;
  5029. memcpy(&vht_cap, &sband->vht_cap, sizeof(vht_cap));
  5030. ieee80211_apply_vhtcap_overrides(sdata, &vht_cap);
  5031. if (req && req->flags & ASSOC_REQ_DISABLE_VHT) {
  5032. mlme_link_id_dbg(sdata, link_id,
  5033. "VHT disabled by flag, limiting to HT\n");
  5034. goto out;
  5035. }
  5036. if (vht_cap.vht_supported && is_5ghz) {
  5037. bool have_80mhz = false;
  5038. unsigned int i;
  5039. if (conn->bw_limit == IEEE80211_CONN_BW_LIMIT_20) {
  5040. mlme_link_id_dbg(sdata, link_id,
  5041. "no 40 MHz support on 5 GHz, limiting to HT\n");
  5042. goto out;
  5043. }
  5044. /* Allow VHT if at least one channel on the sband supports 80 MHz */
  5045. for (i = 0; i < sband->n_channels; i++) {
  5046. if (sband->channels[i].flags & (IEEE80211_CHAN_DISABLED |
  5047. IEEE80211_CHAN_NO_80MHZ))
  5048. continue;
  5049. have_80mhz = true;
  5050. break;
  5051. }
  5052. if (!have_80mhz) {
  5053. mlme_link_id_dbg(sdata, link_id,
  5054. "no 80 MHz channel support on 5 GHz, limiting to HT\n");
  5055. goto out;
  5056. }
  5057. } else if (is_5ghz) { /* !vht_supported but on 5 GHz */
  5058. mlme_link_id_dbg(sdata, link_id,
  5059. "no VHT support on 5 GHz, limiting to HT\n");
  5060. goto out;
  5061. }
  5062. /* VHT - if we have - is fine, including 80 MHz, check 160 below again */
  5063. if (sband->band != NL80211_BAND_2GHZ) {
  5064. conn->mode = IEEE80211_CONN_MODE_VHT;
  5065. conn->bw_limit = IEEE80211_CONN_BW_LIMIT_160;
  5066. }
  5067. if (is_5ghz &&
  5068. !(vht_cap.cap & (IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ |
  5069. IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ))) {
  5070. conn->bw_limit = IEEE80211_CONN_BW_LIMIT_80;
  5071. mlme_link_id_dbg(sdata, link_id,
  5072. "no VHT 160 MHz capability on 5 GHz, limiting to 80 MHz");
  5073. }
  5074. if (req && req->flags & ASSOC_REQ_DISABLE_HE) {
  5075. mlme_link_id_dbg(sdata, link_id,
  5076. "HE disabled by flag, limiting to HT/VHT\n");
  5077. goto out;
  5078. }
  5079. he_cap = ieee80211_get_he_iftype_cap_vif(sband, &sdata->vif);
  5080. if (!he_cap) {
  5081. WARN_ON(is_6ghz);
  5082. mlme_link_id_dbg(sdata, link_id,
  5083. "no HE support, limiting to HT/VHT\n");
  5084. goto out;
  5085. }
  5086. /* so we have HE */
  5087. conn->mode = IEEE80211_CONN_MODE_HE;
  5088. /* check bandwidth */
  5089. switch (sband->band) {
  5090. default:
  5091. case NL80211_BAND_2GHZ:
  5092. if (he_cap->he_cap_elem.phy_cap_info[0] &
  5093. IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_IN_2G)
  5094. break;
  5095. conn->bw_limit = IEEE80211_CONN_BW_LIMIT_20;
  5096. mlme_link_id_dbg(sdata, link_id,
  5097. "no 40 MHz HE cap in 2.4 GHz, limiting to 20 MHz\n");
  5098. break;
  5099. case NL80211_BAND_5GHZ:
  5100. if (!(he_cap->he_cap_elem.phy_cap_info[0] &
  5101. IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_40MHZ_80MHZ_IN_5G)) {
  5102. conn->bw_limit = IEEE80211_CONN_BW_LIMIT_20;
  5103. mlme_link_id_dbg(sdata, link_id,
  5104. "no 40/80 MHz HE cap in 5 GHz, limiting to 20 MHz\n");
  5105. break;
  5106. }
  5107. if (!(he_cap->he_cap_elem.phy_cap_info[0] &
  5108. IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G)) {
  5109. conn->bw_limit = min_t(enum ieee80211_conn_bw_limit,
  5110. conn->bw_limit,
  5111. IEEE80211_CONN_BW_LIMIT_80);
  5112. mlme_link_id_dbg(sdata, link_id,
  5113. "no 160 MHz HE cap in 5 GHz, limiting to 80 MHz\n");
  5114. }
  5115. break;
  5116. case NL80211_BAND_6GHZ:
  5117. if (he_cap->he_cap_elem.phy_cap_info[0] &
  5118. IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G)
  5119. break;
  5120. conn->bw_limit = min_t(enum ieee80211_conn_bw_limit,
  5121. conn->bw_limit,
  5122. IEEE80211_CONN_BW_LIMIT_80);
  5123. mlme_link_id_dbg(sdata, link_id,
  5124. "no 160 MHz HE cap in 6 GHz, limiting to 80 MHz\n");
  5125. break;
  5126. }
  5127. if (req && req->flags & ASSOC_REQ_DISABLE_EHT) {
  5128. mlme_link_id_dbg(sdata, link_id,
  5129. "EHT disabled by flag, limiting to HE\n");
  5130. goto out;
  5131. }
  5132. eht_cap = ieee80211_get_eht_iftype_cap_vif(sband, &sdata->vif);
  5133. if (!eht_cap) {
  5134. mlme_link_id_dbg(sdata, link_id,
  5135. "no EHT support, limiting to HE\n");
  5136. goto out;
  5137. }
  5138. conn->mode = IEEE80211_CONN_MODE_EHT;
  5139. /* check bandwidth */
  5140. if (is_6ghz &&
  5141. eht_cap->eht_cap_elem.phy_cap_info[0] & IEEE80211_EHT_PHY_CAP0_320MHZ_IN_6GHZ)
  5142. conn->bw_limit = IEEE80211_CONN_BW_LIMIT_320;
  5143. else if (is_6ghz)
  5144. mlme_link_id_dbg(sdata, link_id,
  5145. "no EHT 320 MHz cap in 6 GHz, limiting to 160 MHz\n");
  5146. if (req && req->flags & ASSOC_REQ_DISABLE_UHR) {
  5147. mlme_link_id_dbg(sdata, link_id,
  5148. "UHR disabled by flag, limiting to EHT\n");
  5149. goto out;
  5150. }
  5151. uhr_cap = ieee80211_get_uhr_iftype_cap_vif(sband, &sdata->vif);
  5152. if (!uhr_cap) {
  5153. mlme_link_id_dbg(sdata, link_id,
  5154. "no UHR support, limiting to EHT\n");
  5155. goto out;
  5156. }
  5157. conn->mode = IEEE80211_CONN_MODE_UHR;
  5158. out:
  5159. mlme_link_id_dbg(sdata, link_id,
  5160. "determined local STA to be %s, BW limited to %d MHz\n",
  5161. ieee80211_conn_mode_str(conn->mode),
  5162. 20 * (1 << conn->bw_limit));
  5163. }
  5164. static void
  5165. ieee80211_determine_our_sta_mode_auth(struct ieee80211_sub_if_data *sdata,
  5166. struct ieee80211_supported_band *sband,
  5167. struct cfg80211_auth_request *req,
  5168. bool wmm_used,
  5169. struct ieee80211_conn_settings *conn)
  5170. {
  5171. ieee80211_determine_our_sta_mode(sdata, sband, NULL, wmm_used,
  5172. req->link_id > 0 ? req->link_id : 0,
  5173. conn);
  5174. }
  5175. static void
  5176. ieee80211_determine_our_sta_mode_assoc(struct ieee80211_sub_if_data *sdata,
  5177. struct ieee80211_supported_band *sband,
  5178. struct cfg80211_assoc_request *req,
  5179. bool wmm_used, int link_id,
  5180. struct ieee80211_conn_settings *conn)
  5181. {
  5182. struct ieee80211_conn_settings tmp;
  5183. WARN_ON(!req);
  5184. ieee80211_determine_our_sta_mode(sdata, sband, req, wmm_used, link_id,
  5185. &tmp);
  5186. conn->mode = min_t(enum ieee80211_conn_mode,
  5187. conn->mode, tmp.mode);
  5188. conn->bw_limit = min_t(enum ieee80211_conn_bw_limit,
  5189. conn->bw_limit, tmp.bw_limit);
  5190. }
  5191. static int ieee80211_prep_channel(struct ieee80211_sub_if_data *sdata,
  5192. struct ieee80211_link_data *link,
  5193. int link_id,
  5194. struct cfg80211_bss *cbss, bool mlo,
  5195. struct ieee80211_conn_settings *conn,
  5196. unsigned long *userspace_selectors)
  5197. {
  5198. struct ieee80211_local *local = sdata->local;
  5199. bool is_6ghz = cbss->channel->band == NL80211_BAND_6GHZ;
  5200. struct ieee80211_chan_req chanreq = {};
  5201. struct cfg80211_chan_def ap_chandef;
  5202. struct ieee802_11_elems *elems;
  5203. int ret;
  5204. lockdep_assert_wiphy(local->hw.wiphy);
  5205. rcu_read_lock();
  5206. elems = ieee80211_determine_chan_mode(sdata, conn, cbss, link_id,
  5207. &chanreq, &ap_chandef,
  5208. userspace_selectors);
  5209. if (IS_ERR(elems)) {
  5210. rcu_read_unlock();
  5211. return PTR_ERR(elems);
  5212. }
  5213. if (mlo && !elems->ml_basic) {
  5214. sdata_info(sdata, "Rejecting MLO as it is not supported by AP\n");
  5215. rcu_read_unlock();
  5216. kfree(elems);
  5217. return -EINVAL;
  5218. }
  5219. if (link && is_6ghz && conn->mode >= IEEE80211_CONN_MODE_HE) {
  5220. const struct ieee80211_he_6ghz_oper *he_6ghz_oper;
  5221. if (elems->pwr_constr_elem)
  5222. link->conf->pwr_reduction = *elems->pwr_constr_elem;
  5223. he_6ghz_oper = ieee80211_he_6ghz_oper(elems->he_operation);
  5224. if (he_6ghz_oper)
  5225. link->conf->power_type =
  5226. cfg80211_6ghz_power_type(he_6ghz_oper->control,
  5227. cbss->channel->flags);
  5228. else
  5229. link_info(link,
  5230. "HE 6 GHz operation missing (on %d MHz), expect issues\n",
  5231. cbss->channel->center_freq);
  5232. link->conf->tpe = elems->tpe;
  5233. ieee80211_rearrange_tpe(&link->conf->tpe, &ap_chandef,
  5234. &chanreq.oper);
  5235. }
  5236. rcu_read_unlock();
  5237. /* the element data was RCU protected so no longer valid anyway */
  5238. kfree(elems);
  5239. elems = NULL;
  5240. if (!link)
  5241. return 0;
  5242. rcu_read_lock();
  5243. link->needed_rx_chains = min(ieee80211_max_rx_chains(link, cbss),
  5244. local->rx_chains);
  5245. rcu_read_unlock();
  5246. /*
  5247. * If this fails (possibly due to channel context sharing
  5248. * on incompatible channels, e.g. 80+80 and 160 sharing the
  5249. * same control channel) try to use a smaller bandwidth.
  5250. */
  5251. ret = ieee80211_link_use_channel(link, &chanreq,
  5252. IEEE80211_CHANCTX_SHARED);
  5253. /* don't downgrade for 5/10/S1G MHz channels, though. */
  5254. if (chanreq.oper.width == NL80211_CHAN_WIDTH_5 ||
  5255. chanreq.oper.width == NL80211_CHAN_WIDTH_10 ||
  5256. cfg80211_chandef_is_s1g(&chanreq.oper))
  5257. return ret;
  5258. while (ret && chanreq.oper.width != NL80211_CHAN_WIDTH_20_NOHT) {
  5259. ieee80211_chanreq_downgrade(&chanreq, conn);
  5260. ret = ieee80211_link_use_channel(link, &chanreq,
  5261. IEEE80211_CHANCTX_SHARED);
  5262. }
  5263. return ret;
  5264. }
  5265. static bool ieee80211_get_dtim(const struct cfg80211_bss_ies *ies,
  5266. u8 *dtim_count, u8 *dtim_period)
  5267. {
  5268. const u8 *tim_ie = cfg80211_find_ie(WLAN_EID_TIM, ies->data, ies->len);
  5269. const u8 *idx_ie = cfg80211_find_ie(WLAN_EID_MULTI_BSSID_IDX, ies->data,
  5270. ies->len);
  5271. const struct ieee80211_tim_ie *tim = NULL;
  5272. const struct ieee80211_bssid_index *idx;
  5273. bool valid = tim_ie && tim_ie[1] >= 2;
  5274. if (valid)
  5275. tim = (void *)(tim_ie + 2);
  5276. if (dtim_count)
  5277. *dtim_count = valid ? tim->dtim_count : 0;
  5278. if (dtim_period)
  5279. *dtim_period = valid ? tim->dtim_period : 0;
  5280. /* Check if value is overridden by non-transmitted profile */
  5281. if (!idx_ie || idx_ie[1] < 3)
  5282. return valid;
  5283. idx = (void *)(idx_ie + 2);
  5284. if (dtim_count)
  5285. *dtim_count = idx->dtim_count;
  5286. if (dtim_period)
  5287. *dtim_period = idx->dtim_period;
  5288. return true;
  5289. }
  5290. static u16 ieee80211_get_ttlm(u8 bm_size, u8 *data)
  5291. {
  5292. if (bm_size == 1)
  5293. return *data;
  5294. return get_unaligned_le16(data);
  5295. }
  5296. static int
  5297. ieee80211_parse_adv_t2l(struct ieee80211_sub_if_data *sdata,
  5298. const struct ieee80211_ttlm_elem *ttlm,
  5299. struct ieee80211_adv_ttlm_info *ttlm_info)
  5300. {
  5301. /* The element size was already validated in
  5302. * ieee80211_tid_to_link_map_size_ok()
  5303. */
  5304. u8 control, link_map_presence, map_size, tid;
  5305. u8 *pos;
  5306. memset(ttlm_info, 0, sizeof(*ttlm_info));
  5307. pos = (void *)ttlm->optional;
  5308. control = ttlm->control;
  5309. if ((control & IEEE80211_TTLM_CONTROL_DIRECTION) !=
  5310. IEEE80211_TTLM_DIRECTION_BOTH) {
  5311. sdata_info(sdata, "Invalid advertised T2L map direction\n");
  5312. return -EINVAL;
  5313. }
  5314. if (!(control & IEEE80211_TTLM_CONTROL_DEF_LINK_MAP)) {
  5315. link_map_presence = *pos;
  5316. pos++;
  5317. }
  5318. if (control & IEEE80211_TTLM_CONTROL_SWITCH_TIME_PRESENT) {
  5319. ttlm_info->switch_time = get_unaligned_le16(pos);
  5320. /* Since ttlm_info->switch_time == 0 means no switch time, bump
  5321. * it by 1.
  5322. */
  5323. if (!ttlm_info->switch_time)
  5324. ttlm_info->switch_time = 1;
  5325. pos += 2;
  5326. }
  5327. if (control & IEEE80211_TTLM_CONTROL_EXPECTED_DUR_PRESENT) {
  5328. ttlm_info->duration = pos[0] | pos[1] << 8 | pos[2] << 16;
  5329. pos += 3;
  5330. }
  5331. if (control & IEEE80211_TTLM_CONTROL_DEF_LINK_MAP) {
  5332. ttlm_info->map = 0xffff;
  5333. return 0;
  5334. }
  5335. if (control & IEEE80211_TTLM_CONTROL_LINK_MAP_SIZE)
  5336. map_size = 1;
  5337. else
  5338. map_size = 2;
  5339. /* According to Draft P802.11be_D3.0 clause 35.3.7.1.7, an AP MLD shall
  5340. * not advertise a TID-to-link mapping that does not map all TIDs to the
  5341. * same link set, reject frame if not all links have mapping
  5342. */
  5343. if (link_map_presence != 0xff) {
  5344. sdata_info(sdata,
  5345. "Invalid advertised T2L mapping presence indicator\n");
  5346. return -EINVAL;
  5347. }
  5348. ttlm_info->map = ieee80211_get_ttlm(map_size, pos);
  5349. if (!ttlm_info->map) {
  5350. sdata_info(sdata,
  5351. "Invalid advertised T2L map for TID 0\n");
  5352. return -EINVAL;
  5353. }
  5354. pos += map_size;
  5355. for (tid = 1; tid < 8; tid++) {
  5356. u16 map = ieee80211_get_ttlm(map_size, pos);
  5357. if (map != ttlm_info->map) {
  5358. sdata_info(sdata, "Invalid advertised T2L map for tid %d\n",
  5359. tid);
  5360. return -EINVAL;
  5361. }
  5362. pos += map_size;
  5363. }
  5364. return 0;
  5365. }
  5366. static bool ieee80211_assoc_success(struct ieee80211_sub_if_data *sdata,
  5367. struct ieee80211_mgmt *mgmt,
  5368. struct ieee802_11_elems *elems,
  5369. const u8 *elem_start, unsigned int elem_len)
  5370. {
  5371. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  5372. struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;
  5373. struct ieee80211_local *local = sdata->local;
  5374. unsigned int link_id;
  5375. struct sta_info *sta;
  5376. u64 changed[IEEE80211_MLD_MAX_NUM_LINKS] = {};
  5377. u16 valid_links = 0, dormant_links = 0;
  5378. int err;
  5379. lockdep_assert_wiphy(sdata->local->hw.wiphy);
  5380. /*
  5381. * station info was already allocated and inserted before
  5382. * the association and should be available to us
  5383. */
  5384. sta = sta_info_get(sdata, assoc_data->ap_addr);
  5385. if (WARN_ON(!sta))
  5386. goto out_err;
  5387. sta->sta.spp_amsdu = assoc_data->spp_amsdu;
  5388. if (ieee80211_vif_is_mld(&sdata->vif)) {
  5389. for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS; link_id++) {
  5390. if (!assoc_data->link[link_id].bss)
  5391. continue;
  5392. valid_links |= BIT(link_id);
  5393. if (link_id != assoc_data->assoc_link_id) {
  5394. err = ieee80211_sta_allocate_link(sta, link_id);
  5395. if (err)
  5396. goto out_err;
  5397. }
  5398. }
  5399. /*
  5400. * We do not support setting a negotiated TTLM during
  5401. * association. As such, we can assume that if there is a TTLM,
  5402. * then it is the currently active advertised TTLM.
  5403. * In that case, there must be exactly one TTLM that does not
  5404. * have a switch time set. This mapping should also leave us
  5405. * with at least one usable link.
  5406. */
  5407. if (elems->ttlm_num > 1) {
  5408. sdata_info(sdata,
  5409. "More than one advertised TTLM in association response\n");
  5410. goto out_err;
  5411. } else if (elems->ttlm_num == 1) {
  5412. if (ieee80211_parse_adv_t2l(sdata, elems->ttlm[0],
  5413. &sdata->u.mgd.ttlm_info) ||
  5414. sdata->u.mgd.ttlm_info.switch_time != 0 ||
  5415. !(valid_links & sdata->u.mgd.ttlm_info.map)) {
  5416. sdata_info(sdata,
  5417. "Invalid advertised TTLM in association response\n");
  5418. goto out_err;
  5419. }
  5420. sdata->u.mgd.ttlm_info.active = true;
  5421. dormant_links =
  5422. valid_links & ~sdata->u.mgd.ttlm_info.map;
  5423. }
  5424. ieee80211_vif_set_links(sdata, valid_links, dormant_links);
  5425. }
  5426. for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS; link_id++) {
  5427. struct cfg80211_bss *cbss = assoc_data->link[link_id].bss;
  5428. struct ieee80211_link_data *link;
  5429. struct link_sta_info *link_sta;
  5430. if (!cbss)
  5431. continue;
  5432. link = sdata_dereference(sdata->link[link_id], sdata);
  5433. if (WARN_ON(!link))
  5434. goto out_err;
  5435. if (ieee80211_vif_is_mld(&sdata->vif))
  5436. link_info(link,
  5437. "local address %pM, AP link address %pM%s\n",
  5438. link->conf->addr,
  5439. assoc_data->link[link_id].bss->bssid,
  5440. link_id == assoc_data->assoc_link_id ?
  5441. " (assoc)" : "");
  5442. link_sta = rcu_dereference_protected(sta->link[link_id],
  5443. lockdep_is_held(&local->hw.wiphy->mtx));
  5444. if (WARN_ON(!link_sta))
  5445. goto out_err;
  5446. if (!link->u.mgd.have_beacon) {
  5447. const struct cfg80211_bss_ies *ies;
  5448. rcu_read_lock();
  5449. ies = rcu_dereference(cbss->beacon_ies);
  5450. if (ies)
  5451. link->u.mgd.have_beacon = true;
  5452. else
  5453. ies = rcu_dereference(cbss->ies);
  5454. ieee80211_get_dtim(ies,
  5455. &link->conf->sync_dtim_count,
  5456. &link->u.mgd.dtim_period);
  5457. link->conf->beacon_int = cbss->beacon_interval;
  5458. rcu_read_unlock();
  5459. }
  5460. link->conf->dtim_period = link->u.mgd.dtim_period ?: 1;
  5461. if (link_id != assoc_data->assoc_link_id) {
  5462. link->u.mgd.conn = assoc_data->link[link_id].conn;
  5463. err = ieee80211_prep_channel(sdata, link, link_id, cbss,
  5464. true, &link->u.mgd.conn,
  5465. sdata->u.mgd.userspace_selectors);
  5466. if (err) {
  5467. link_info(link, "prep_channel failed\n");
  5468. goto out_err;
  5469. }
  5470. }
  5471. err = ieee80211_mgd_setup_link_sta(link, sta, link_sta,
  5472. assoc_data->link[link_id].bss);
  5473. if (err)
  5474. goto out_err;
  5475. if (!ieee80211_assoc_config_link(link, link_sta,
  5476. assoc_data->link[link_id].bss,
  5477. mgmt, elem_start, elem_len,
  5478. &changed[link_id]))
  5479. goto out_err;
  5480. if (assoc_data->link[link_id].status != WLAN_STATUS_SUCCESS) {
  5481. valid_links &= ~BIT(link_id);
  5482. ieee80211_sta_remove_link(sta, link_id);
  5483. continue;
  5484. }
  5485. if (link_id != assoc_data->assoc_link_id) {
  5486. err = ieee80211_sta_activate_link(sta, link_id);
  5487. if (err)
  5488. goto out_err;
  5489. }
  5490. }
  5491. /* links might have changed due to rejected ones, set them again */
  5492. ieee80211_vif_set_links(sdata, valid_links, dormant_links);
  5493. rate_control_rate_init_all_links(sta);
  5494. if (ifmgd->flags & IEEE80211_STA_MFP_ENABLED) {
  5495. set_sta_flag(sta, WLAN_STA_MFP);
  5496. sta->sta.mfp = true;
  5497. } else {
  5498. sta->sta.mfp = false;
  5499. }
  5500. ieee80211_sta_set_max_amsdu_subframes(sta, elems->ext_capab,
  5501. elems->ext_capab_len);
  5502. sta->sta.wme = (elems->wmm_param || elems->s1g_capab) &&
  5503. local->hw.queues >= IEEE80211_NUM_ACS;
  5504. err = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
  5505. if (!err && !(ifmgd->flags & IEEE80211_STA_CONTROL_PORT))
  5506. err = sta_info_move_state(sta, IEEE80211_STA_AUTHORIZED);
  5507. if (err) {
  5508. sdata_info(sdata,
  5509. "failed to move station %pM to desired state\n",
  5510. sta->sta.addr);
  5511. WARN_ON(__sta_info_destroy(sta));
  5512. goto out_err;
  5513. }
  5514. if (sdata->wdev.use_4addr)
  5515. drv_sta_set_4addr(local, sdata, &sta->sta, true);
  5516. ieee80211_set_associated(sdata, assoc_data, changed);
  5517. /*
  5518. * If we're using 4-addr mode, let the AP know that we're
  5519. * doing so, so that it can create the STA VLAN on its side
  5520. */
  5521. if (ifmgd->use_4addr)
  5522. ieee80211_send_4addr_nullfunc(local, sdata);
  5523. /*
  5524. * Start timer to probe the connection to the AP now.
  5525. * Also start the timer that will detect beacon loss.
  5526. */
  5527. ieee80211_sta_reset_beacon_monitor(sdata);
  5528. ieee80211_sta_reset_conn_monitor(sdata);
  5529. return true;
  5530. out_err:
  5531. eth_zero_addr(sdata->vif.cfg.ap_addr);
  5532. return false;
  5533. }
  5534. static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
  5535. struct ieee80211_mgmt *mgmt,
  5536. size_t len)
  5537. {
  5538. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  5539. struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;
  5540. u16 capab_info, status_code, aid;
  5541. struct ieee80211_elems_parse_params parse_params = {
  5542. .bss = NULL,
  5543. .link_id = -1,
  5544. .from_ap = true,
  5545. .type = le16_to_cpu(mgmt->frame_control) & IEEE80211_FCTL_TYPE,
  5546. };
  5547. struct ieee802_11_elems *elems;
  5548. int ac;
  5549. const u8 *elem_start;
  5550. unsigned int elem_len;
  5551. bool reassoc;
  5552. struct ieee80211_event event = {
  5553. .type = MLME_EVENT,
  5554. .u.mlme.data = ASSOC_EVENT,
  5555. };
  5556. struct ieee80211_prep_tx_info info = {};
  5557. struct cfg80211_rx_assoc_resp_data resp = {
  5558. .uapsd_queues = -1,
  5559. };
  5560. u8 ap_mld_addr[ETH_ALEN] __aligned(2);
  5561. unsigned int link_id;
  5562. u16 max_aid = IEEE80211_MAX_AID;
  5563. lockdep_assert_wiphy(sdata->local->hw.wiphy);
  5564. if (!assoc_data)
  5565. return;
  5566. info.link_id = assoc_data->assoc_link_id;
  5567. parse_params.mode =
  5568. assoc_data->link[assoc_data->assoc_link_id].conn.mode;
  5569. if (!ether_addr_equal(assoc_data->ap_addr, mgmt->bssid) ||
  5570. !ether_addr_equal(assoc_data->ap_addr, mgmt->sa))
  5571. return;
  5572. /*
  5573. * AssocResp and ReassocResp have identical structure, so process both
  5574. * of them in this function.
  5575. */
  5576. if (len < 24 + 6)
  5577. return;
  5578. reassoc = ieee80211_is_reassoc_resp(mgmt->frame_control);
  5579. capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
  5580. status_code = le16_to_cpu(mgmt->u.assoc_resp.status_code);
  5581. if (assoc_data->s1g) {
  5582. elem_start = mgmt->u.s1g_assoc_resp.variable;
  5583. max_aid = IEEE80211_MAX_SUPPORTED_S1G_AID;
  5584. } else {
  5585. elem_start = mgmt->u.assoc_resp.variable;
  5586. }
  5587. /*
  5588. * Note: this may not be perfect, AP might misbehave - if
  5589. * anyone needs to rely on perfect complete notification
  5590. * with the exact right subtype, then we need to track what
  5591. * we actually transmitted.
  5592. */
  5593. info.subtype = reassoc ? IEEE80211_STYPE_REASSOC_REQ :
  5594. IEEE80211_STYPE_ASSOC_REQ;
  5595. if (assoc_data->fils_kek_len &&
  5596. fils_decrypt_assoc_resp(sdata, (u8 *)mgmt, &len, assoc_data) < 0)
  5597. return;
  5598. elem_len = len - (elem_start - (u8 *)mgmt);
  5599. parse_params.start = elem_start;
  5600. parse_params.len = elem_len;
  5601. elems = ieee802_11_parse_elems_full(&parse_params);
  5602. if (!elems)
  5603. goto notify_driver;
  5604. if (elems->aid_resp)
  5605. aid = le16_to_cpu(elems->aid_resp->aid);
  5606. else
  5607. aid = le16_to_cpu(mgmt->u.assoc_resp.aid);
  5608. /*
  5609. * The 5 MSB of the AID field are reserved for a non-S1G STA. For
  5610. * an S1G STA the 3 MSBs are reserved.
  5611. * (802.11-2016 9.4.1.8 AID field).
  5612. */
  5613. aid &= assoc_data->s1g ? 0x1fff : 0x7ff;
  5614. sdata_info(sdata,
  5615. "RX %sssocResp from %pM (capab=0x%x status=%d aid=%d)\n",
  5616. reassoc ? "Rea" : "A", assoc_data->ap_addr,
  5617. capab_info, status_code, (u16)(aid & ~(BIT(15) | BIT(14))));
  5618. ifmgd->broken_ap = false;
  5619. if (status_code == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY &&
  5620. elems->timeout_int &&
  5621. elems->timeout_int->type == WLAN_TIMEOUT_ASSOC_COMEBACK) {
  5622. u32 tu, ms;
  5623. cfg80211_assoc_comeback(sdata->dev, assoc_data->ap_addr,
  5624. le32_to_cpu(elems->timeout_int->value));
  5625. tu = le32_to_cpu(elems->timeout_int->value);
  5626. ms = tu * 1024 / 1000;
  5627. sdata_info(sdata,
  5628. "%pM rejected association temporarily; comeback duration %u TU (%u ms)\n",
  5629. assoc_data->ap_addr, tu, ms);
  5630. assoc_data->timeout = jiffies + msecs_to_jiffies(ms);
  5631. assoc_data->timeout_started = true;
  5632. assoc_data->comeback = true;
  5633. if (ms > IEEE80211_ASSOC_TIMEOUT)
  5634. run_again(sdata, assoc_data->timeout);
  5635. goto notify_driver;
  5636. }
  5637. if (status_code != WLAN_STATUS_SUCCESS) {
  5638. sdata_info(sdata, "%pM denied association (code=%d)\n",
  5639. assoc_data->ap_addr, status_code);
  5640. event.u.mlme.status = MLME_DENIED;
  5641. event.u.mlme.reason = status_code;
  5642. drv_event_callback(sdata->local, sdata, &event);
  5643. } else {
  5644. if (aid == 0 || aid > max_aid) {
  5645. sdata_info(sdata,
  5646. "invalid AID value %d (out of range), turn off PS\n",
  5647. aid);
  5648. aid = 0;
  5649. ifmgd->broken_ap = true;
  5650. }
  5651. if (ieee80211_vif_is_mld(&sdata->vif)) {
  5652. struct ieee80211_mle_basic_common_info *common;
  5653. if (!elems->ml_basic) {
  5654. sdata_info(sdata,
  5655. "MLO association with %pM but no (basic) multi-link element in response!\n",
  5656. assoc_data->ap_addr);
  5657. goto abandon_assoc;
  5658. }
  5659. common = (void *)elems->ml_basic->variable;
  5660. if (memcmp(assoc_data->ap_addr,
  5661. common->mld_mac_addr, ETH_ALEN)) {
  5662. sdata_info(sdata,
  5663. "AP MLD MAC address mismatch: got %pM expected %pM\n",
  5664. common->mld_mac_addr,
  5665. assoc_data->ap_addr);
  5666. goto abandon_assoc;
  5667. }
  5668. sdata->vif.cfg.eml_cap =
  5669. ieee80211_mle_get_eml_cap((const void *)elems->ml_basic);
  5670. sdata->vif.cfg.eml_med_sync_delay =
  5671. ieee80211_mle_get_eml_med_sync_delay((const void *)elems->ml_basic);
  5672. sdata->vif.cfg.mld_capa_op =
  5673. ieee80211_mle_get_mld_capa_op((const void *)elems->ml_basic);
  5674. }
  5675. sdata->vif.cfg.aid = aid;
  5676. sdata->vif.cfg.s1g = assoc_data->s1g;
  5677. if (!ieee80211_assoc_success(sdata, mgmt, elems,
  5678. elem_start, elem_len)) {
  5679. /* oops -- internal error -- send timeout for now */
  5680. ieee80211_destroy_assoc_data(sdata, ASSOC_TIMEOUT);
  5681. goto notify_driver;
  5682. }
  5683. event.u.mlme.status = MLME_SUCCESS;
  5684. drv_event_callback(sdata->local, sdata, &event);
  5685. sdata_info(sdata, "associated\n");
  5686. info.success = 1;
  5687. }
  5688. for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS; link_id++) {
  5689. struct ieee80211_link_data *link;
  5690. if (!assoc_data->link[link_id].bss)
  5691. continue;
  5692. resp.links[link_id].bss = assoc_data->link[link_id].bss;
  5693. ether_addr_copy(resp.links[link_id].addr,
  5694. assoc_data->link[link_id].addr);
  5695. resp.links[link_id].status = assoc_data->link[link_id].status;
  5696. link = sdata_dereference(sdata->link[link_id], sdata);
  5697. if (!link)
  5698. continue;
  5699. /* get uapsd queues configuration - same for all links */
  5700. resp.uapsd_queues = 0;
  5701. for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
  5702. if (link->tx_conf[ac].uapsd)
  5703. resp.uapsd_queues |= ieee80211_ac_to_qos_mask[ac];
  5704. }
  5705. if (ieee80211_vif_is_mld(&sdata->vif)) {
  5706. ether_addr_copy(ap_mld_addr, sdata->vif.cfg.ap_addr);
  5707. resp.ap_mld_addr = ap_mld_addr;
  5708. }
  5709. ieee80211_destroy_assoc_data(sdata,
  5710. status_code == WLAN_STATUS_SUCCESS ?
  5711. ASSOC_SUCCESS :
  5712. ASSOC_REJECTED);
  5713. resp.buf = (u8 *)mgmt;
  5714. resp.len = len;
  5715. resp.req_ies = ifmgd->assoc_req_ies;
  5716. resp.req_ies_len = ifmgd->assoc_req_ies_len;
  5717. cfg80211_rx_assoc_resp(sdata->dev, &resp);
  5718. notify_driver:
  5719. drv_mgd_complete_tx(sdata->local, sdata, &info);
  5720. kfree(elems);
  5721. return;
  5722. abandon_assoc:
  5723. ieee80211_destroy_assoc_data(sdata, ASSOC_ABANDON);
  5724. goto notify_driver;
  5725. }
  5726. static void ieee80211_rx_bss_info(struct ieee80211_link_data *link,
  5727. struct ieee80211_mgmt *mgmt, size_t len,
  5728. struct ieee80211_rx_status *rx_status)
  5729. {
  5730. struct ieee80211_sub_if_data *sdata = link->sdata;
  5731. struct ieee80211_local *local = sdata->local;
  5732. struct ieee80211_bss *bss;
  5733. struct ieee80211_channel *channel;
  5734. lockdep_assert_wiphy(sdata->local->hw.wiphy);
  5735. channel = ieee80211_get_channel_khz(local->hw.wiphy,
  5736. ieee80211_rx_status_to_khz(rx_status));
  5737. if (!channel)
  5738. return;
  5739. bss = ieee80211_bss_info_update(local, rx_status, mgmt, len, channel);
  5740. if (bss) {
  5741. link->conf->beacon_rate = bss->beacon_rate;
  5742. ieee80211_rx_bss_put(local, bss);
  5743. }
  5744. }
  5745. static void ieee80211_rx_mgmt_probe_resp(struct ieee80211_link_data *link,
  5746. struct sk_buff *skb)
  5747. {
  5748. struct ieee80211_sub_if_data *sdata = link->sdata;
  5749. struct ieee80211_mgmt *mgmt = (void *)skb->data;
  5750. struct ieee80211_if_managed *ifmgd;
  5751. struct ieee80211_rx_status *rx_status = (void *) skb->cb;
  5752. struct ieee80211_channel *channel;
  5753. size_t baselen, len = skb->len;
  5754. ifmgd = &sdata->u.mgd;
  5755. lockdep_assert_wiphy(sdata->local->hw.wiphy);
  5756. /*
  5757. * According to Draft P802.11ax D6.0 clause 26.17.2.3.2:
  5758. * "If a 6 GHz AP receives a Probe Request frame and responds with
  5759. * a Probe Response frame [..], the Address 1 field of the Probe
  5760. * Response frame shall be set to the broadcast address [..]"
  5761. * So, on 6GHz band we should also accept broadcast responses.
  5762. */
  5763. channel = ieee80211_get_channel_khz(sdata->local->hw.wiphy,
  5764. ieee80211_rx_status_to_khz(rx_status));
  5765. if (!channel)
  5766. return;
  5767. if (!ether_addr_equal(mgmt->da, sdata->vif.addr) &&
  5768. (channel->band != NL80211_BAND_6GHZ ||
  5769. !is_broadcast_ether_addr(mgmt->da)))
  5770. return; /* ignore ProbeResp to foreign address */
  5771. baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt;
  5772. if (baselen > len)
  5773. return;
  5774. ieee80211_rx_bss_info(link, mgmt, len, rx_status);
  5775. if (ifmgd->associated &&
  5776. ether_addr_equal(mgmt->bssid, link->u.mgd.bssid))
  5777. ieee80211_reset_ap_probe(sdata);
  5778. }
  5779. /*
  5780. * This is the canonical list of information elements we care about,
  5781. * the filter code also gives us all changes to the Microsoft OUI
  5782. * (00:50:F2) vendor IE which is used for WMM which we need to track,
  5783. * as well as the DTPC IE (part of the Cisco OUI) used for signaling
  5784. * changes to requested client power.
  5785. *
  5786. * We implement beacon filtering in software since that means we can
  5787. * avoid processing the frame here and in cfg80211, and userspace
  5788. * will not be able to tell whether the hardware supports it or not.
  5789. *
  5790. * XXX: This list needs to be dynamic -- userspace needs to be able to
  5791. * add items it requires. It also needs to be able to tell us to
  5792. * look out for other vendor IEs.
  5793. */
  5794. static const u64 care_about_ies =
  5795. (1ULL << WLAN_EID_COUNTRY) |
  5796. (1ULL << WLAN_EID_ERP_INFO) |
  5797. (1ULL << WLAN_EID_CHANNEL_SWITCH) |
  5798. (1ULL << WLAN_EID_PWR_CONSTRAINT) |
  5799. (1ULL << WLAN_EID_HT_CAPABILITY) |
  5800. (1ULL << WLAN_EID_HT_OPERATION) |
  5801. (1ULL << WLAN_EID_EXT_CHANSWITCH_ANN);
  5802. static void ieee80211_handle_beacon_sig(struct ieee80211_link_data *link,
  5803. struct ieee80211_if_managed *ifmgd,
  5804. struct ieee80211_bss_conf *bss_conf,
  5805. struct ieee80211_local *local,
  5806. struct ieee80211_rx_status *rx_status)
  5807. {
  5808. struct ieee80211_sub_if_data *sdata = link->sdata;
  5809. /* Track average RSSI from the Beacon frames of the current AP */
  5810. if (!link->u.mgd.tracking_signal_avg) {
  5811. link->u.mgd.tracking_signal_avg = true;
  5812. ewma_beacon_signal_init(&link->u.mgd.ave_beacon_signal);
  5813. link->u.mgd.last_cqm_event_signal = 0;
  5814. link->u.mgd.count_beacon_signal = 1;
  5815. link->u.mgd.last_ave_beacon_signal = 0;
  5816. } else {
  5817. link->u.mgd.count_beacon_signal++;
  5818. }
  5819. ewma_beacon_signal_add(&link->u.mgd.ave_beacon_signal,
  5820. -rx_status->signal);
  5821. if (ifmgd->rssi_min_thold != ifmgd->rssi_max_thold &&
  5822. link->u.mgd.count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT) {
  5823. int sig = -ewma_beacon_signal_read(&link->u.mgd.ave_beacon_signal);
  5824. int last_sig = link->u.mgd.last_ave_beacon_signal;
  5825. struct ieee80211_event event = {
  5826. .type = RSSI_EVENT,
  5827. };
  5828. /*
  5829. * if signal crosses either of the boundaries, invoke callback
  5830. * with appropriate parameters
  5831. */
  5832. if (sig > ifmgd->rssi_max_thold &&
  5833. (last_sig <= ifmgd->rssi_min_thold || last_sig == 0)) {
  5834. link->u.mgd.last_ave_beacon_signal = sig;
  5835. event.u.rssi.data = RSSI_EVENT_HIGH;
  5836. drv_event_callback(local, sdata, &event);
  5837. } else if (sig < ifmgd->rssi_min_thold &&
  5838. (last_sig >= ifmgd->rssi_max_thold ||
  5839. last_sig == 0)) {
  5840. link->u.mgd.last_ave_beacon_signal = sig;
  5841. event.u.rssi.data = RSSI_EVENT_LOW;
  5842. drv_event_callback(local, sdata, &event);
  5843. }
  5844. }
  5845. if (bss_conf->cqm_rssi_thold &&
  5846. link->u.mgd.count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT &&
  5847. !(sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)) {
  5848. int sig = -ewma_beacon_signal_read(&link->u.mgd.ave_beacon_signal);
  5849. int last_event = link->u.mgd.last_cqm_event_signal;
  5850. int thold = bss_conf->cqm_rssi_thold;
  5851. int hyst = bss_conf->cqm_rssi_hyst;
  5852. if (sig < thold &&
  5853. (last_event == 0 || sig < last_event - hyst)) {
  5854. link->u.mgd.last_cqm_event_signal = sig;
  5855. ieee80211_cqm_rssi_notify(
  5856. &sdata->vif,
  5857. NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW,
  5858. sig, GFP_KERNEL);
  5859. } else if (sig > thold &&
  5860. (last_event == 0 || sig > last_event + hyst)) {
  5861. link->u.mgd.last_cqm_event_signal = sig;
  5862. ieee80211_cqm_rssi_notify(
  5863. &sdata->vif,
  5864. NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH,
  5865. sig, GFP_KERNEL);
  5866. }
  5867. }
  5868. if (bss_conf->cqm_rssi_low &&
  5869. link->u.mgd.count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT) {
  5870. int sig = -ewma_beacon_signal_read(&link->u.mgd.ave_beacon_signal);
  5871. int last_event = link->u.mgd.last_cqm_event_signal;
  5872. int low = bss_conf->cqm_rssi_low;
  5873. int high = bss_conf->cqm_rssi_high;
  5874. if (sig < low &&
  5875. (last_event == 0 || last_event >= low)) {
  5876. link->u.mgd.last_cqm_event_signal = sig;
  5877. ieee80211_cqm_rssi_notify(
  5878. &sdata->vif,
  5879. NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW,
  5880. sig, GFP_KERNEL);
  5881. } else if (sig > high &&
  5882. (last_event == 0 || last_event <= high)) {
  5883. link->u.mgd.last_cqm_event_signal = sig;
  5884. ieee80211_cqm_rssi_notify(
  5885. &sdata->vif,
  5886. NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH,
  5887. sig, GFP_KERNEL);
  5888. }
  5889. }
  5890. }
  5891. static bool ieee80211_rx_our_beacon(const u8 *tx_bssid,
  5892. struct cfg80211_bss *bss)
  5893. {
  5894. if (ether_addr_equal(tx_bssid, bss->bssid))
  5895. return true;
  5896. if (!bss->transmitted_bss)
  5897. return false;
  5898. return ether_addr_equal(tx_bssid, bss->transmitted_bss->bssid);
  5899. }
  5900. static void ieee80211_ml_reconf_work(struct wiphy *wiphy,
  5901. struct wiphy_work *work)
  5902. {
  5903. struct ieee80211_sub_if_data *sdata =
  5904. container_of(work, struct ieee80211_sub_if_data,
  5905. u.mgd.ml_reconf_work.work);
  5906. u16 new_valid_links, new_active_links, new_dormant_links;
  5907. int ret;
  5908. if (!sdata->u.mgd.removed_links)
  5909. return;
  5910. sdata_info(sdata,
  5911. "MLO Reconfiguration: work: valid=0x%x, removed=0x%x\n",
  5912. sdata->vif.valid_links, sdata->u.mgd.removed_links);
  5913. new_valid_links = sdata->vif.valid_links & ~sdata->u.mgd.removed_links;
  5914. if (new_valid_links == sdata->vif.valid_links)
  5915. return;
  5916. if (!new_valid_links ||
  5917. !(new_valid_links & ~sdata->vif.dormant_links)) {
  5918. sdata_info(sdata, "No valid links after reconfiguration\n");
  5919. ret = -EINVAL;
  5920. goto out;
  5921. }
  5922. new_active_links = sdata->vif.active_links & ~sdata->u.mgd.removed_links;
  5923. if (new_active_links != sdata->vif.active_links) {
  5924. if (!new_active_links)
  5925. new_active_links =
  5926. BIT(ffs(new_valid_links &
  5927. ~sdata->vif.dormant_links) - 1);
  5928. ret = ieee80211_set_active_links(&sdata->vif, new_active_links);
  5929. if (ret) {
  5930. sdata_info(sdata,
  5931. "Failed setting active links\n");
  5932. goto out;
  5933. }
  5934. }
  5935. new_dormant_links = sdata->vif.dormant_links & ~sdata->u.mgd.removed_links;
  5936. ret = ieee80211_vif_set_links(sdata, new_valid_links,
  5937. new_dormant_links);
  5938. if (ret)
  5939. sdata_info(sdata, "Failed setting valid links\n");
  5940. ieee80211_vif_cfg_change_notify(sdata, BSS_CHANGED_MLD_VALID_LINKS);
  5941. out:
  5942. if (!ret)
  5943. cfg80211_links_removed(sdata->dev, sdata->u.mgd.removed_links);
  5944. else
  5945. __ieee80211_disconnect(sdata);
  5946. sdata->u.mgd.removed_links = 0;
  5947. }
  5948. static void ieee80211_ml_reconfiguration(struct ieee80211_sub_if_data *sdata,
  5949. struct ieee802_11_elems *elems)
  5950. {
  5951. const struct element *sub;
  5952. unsigned long removed_links = 0;
  5953. u16 link_removal_timeout[IEEE80211_MLD_MAX_NUM_LINKS] = {};
  5954. u8 link_id;
  5955. u32 delay;
  5956. if (!ieee80211_vif_is_mld(&sdata->vif) || !elems->ml_reconf)
  5957. return;
  5958. /* Directly parse the sub elements as the common information doesn't
  5959. * hold any useful information.
  5960. */
  5961. for_each_mle_subelement(sub, (const u8 *)elems->ml_reconf,
  5962. elems->ml_reconf_len) {
  5963. struct ieee80211_mle_per_sta_profile *prof = (void *)sub->data;
  5964. u8 *pos = prof->variable;
  5965. u16 control;
  5966. if (sub->id != IEEE80211_MLE_SUBELEM_PER_STA_PROFILE)
  5967. continue;
  5968. if (!ieee80211_mle_reconf_sta_prof_size_ok(sub->data,
  5969. sub->datalen))
  5970. return;
  5971. control = le16_to_cpu(prof->control);
  5972. link_id = control & IEEE80211_MLE_STA_RECONF_CONTROL_LINK_ID;
  5973. if (link_id >= IEEE80211_MLD_MAX_NUM_LINKS)
  5974. continue;
  5975. removed_links |= BIT(link_id);
  5976. /* the MAC address should not be included, but handle it */
  5977. if (control &
  5978. IEEE80211_MLE_STA_RECONF_CONTROL_STA_MAC_ADDR_PRESENT)
  5979. pos += 6;
  5980. /* According to Draft P802.11be_D3.0, the control should
  5981. * include the AP Removal Timer present. If the AP Removal Timer
  5982. * is not present assume immediate removal.
  5983. */
  5984. if (control &
  5985. IEEE80211_MLE_STA_RECONF_CONTROL_AP_REM_TIMER_PRESENT)
  5986. link_removal_timeout[link_id] = get_unaligned_le16(pos);
  5987. }
  5988. removed_links &= sdata->vif.valid_links;
  5989. if (!removed_links) {
  5990. /* In case the removal was cancelled, abort it */
  5991. if (sdata->u.mgd.removed_links) {
  5992. sdata->u.mgd.removed_links = 0;
  5993. wiphy_hrtimer_work_cancel(sdata->local->hw.wiphy,
  5994. &sdata->u.mgd.ml_reconf_work);
  5995. }
  5996. return;
  5997. }
  5998. delay = 0;
  5999. for_each_set_bit(link_id, &removed_links, IEEE80211_MLD_MAX_NUM_LINKS) {
  6000. struct ieee80211_bss_conf *link_conf =
  6001. sdata_dereference(sdata->vif.link_conf[link_id], sdata);
  6002. u32 link_delay;
  6003. if (!link_conf) {
  6004. removed_links &= ~BIT(link_id);
  6005. continue;
  6006. }
  6007. if (link_removal_timeout[link_id] < 1)
  6008. link_delay = 0;
  6009. else
  6010. link_delay = link_conf->beacon_int *
  6011. (link_removal_timeout[link_id] - 1);
  6012. if (!delay)
  6013. delay = link_delay;
  6014. else
  6015. delay = min(delay, link_delay);
  6016. }
  6017. sdata->u.mgd.removed_links = removed_links;
  6018. wiphy_hrtimer_work_queue(sdata->local->hw.wiphy,
  6019. &sdata->u.mgd.ml_reconf_work,
  6020. us_to_ktime(ieee80211_tu_to_usec(delay)));
  6021. }
  6022. static int ieee80211_ttlm_set_links(struct ieee80211_sub_if_data *sdata,
  6023. u16 active_links, u16 dormant_links,
  6024. u16 suspended_links)
  6025. {
  6026. u64 changed = 0;
  6027. int ret;
  6028. if (!active_links) {
  6029. ret = -EINVAL;
  6030. goto out;
  6031. }
  6032. /* If there is an active negotiated TTLM, it should be discarded by
  6033. * the new negotiated/advertised TTLM.
  6034. */
  6035. if (sdata->vif.neg_ttlm.valid) {
  6036. memset(&sdata->vif.neg_ttlm, 0, sizeof(sdata->vif.neg_ttlm));
  6037. sdata->vif.suspended_links = 0;
  6038. changed = BSS_CHANGED_MLD_TTLM;
  6039. }
  6040. if (sdata->vif.active_links != active_links) {
  6041. /* usable links are affected when active_links are changed,
  6042. * so notify the driver about the status change
  6043. */
  6044. changed |= BSS_CHANGED_MLD_VALID_LINKS;
  6045. active_links &= sdata->vif.active_links;
  6046. if (!active_links)
  6047. active_links =
  6048. BIT(__ffs(sdata->vif.valid_links &
  6049. ~dormant_links));
  6050. ret = ieee80211_set_active_links(&sdata->vif, active_links);
  6051. if (ret) {
  6052. sdata_info(sdata, "Failed to set TTLM active links\n");
  6053. goto out;
  6054. }
  6055. }
  6056. ret = ieee80211_vif_set_links(sdata, sdata->vif.valid_links,
  6057. dormant_links);
  6058. if (ret) {
  6059. sdata_info(sdata, "Failed to set TTLM dormant links\n");
  6060. goto out;
  6061. }
  6062. sdata->vif.suspended_links = suspended_links;
  6063. if (sdata->vif.suspended_links)
  6064. changed |= BSS_CHANGED_MLD_TTLM;
  6065. ieee80211_vif_cfg_change_notify(sdata, changed);
  6066. out:
  6067. if (ret)
  6068. ieee80211_disconnect(&sdata->vif, false);
  6069. return ret;
  6070. }
  6071. static void ieee80211_tid_to_link_map_work(struct wiphy *wiphy,
  6072. struct wiphy_work *work)
  6073. {
  6074. u16 new_active_links, new_dormant_links;
  6075. struct ieee80211_sub_if_data *sdata =
  6076. container_of(work, struct ieee80211_sub_if_data,
  6077. u.mgd.ttlm_work.work);
  6078. new_active_links = sdata->u.mgd.ttlm_info.map &
  6079. sdata->vif.valid_links;
  6080. new_dormant_links = ~sdata->u.mgd.ttlm_info.map &
  6081. sdata->vif.valid_links;
  6082. ieee80211_vif_set_links(sdata, sdata->vif.valid_links, 0);
  6083. if (ieee80211_ttlm_set_links(sdata, new_active_links, new_dormant_links,
  6084. 0))
  6085. return;
  6086. sdata->u.mgd.ttlm_info.active = true;
  6087. sdata->u.mgd.ttlm_info.switch_time = 0;
  6088. }
  6089. static void ieee80211_process_adv_ttlm(struct ieee80211_sub_if_data *sdata,
  6090. struct ieee802_11_elems *elems,
  6091. u64 beacon_ts)
  6092. {
  6093. u8 i;
  6094. int ret;
  6095. if (!ieee80211_vif_is_mld(&sdata->vif))
  6096. return;
  6097. if (!elems->ttlm_num) {
  6098. if (sdata->u.mgd.ttlm_info.switch_time) {
  6099. /* if a planned TID-to-link mapping was cancelled -
  6100. * abort it
  6101. */
  6102. wiphy_hrtimer_work_cancel(sdata->local->hw.wiphy,
  6103. &sdata->u.mgd.ttlm_work);
  6104. } else if (sdata->u.mgd.ttlm_info.active) {
  6105. /* if no TID-to-link element, set to default mapping in
  6106. * which all TIDs are mapped to all setup links
  6107. */
  6108. ret = ieee80211_vif_set_links(sdata,
  6109. sdata->vif.valid_links,
  6110. 0);
  6111. if (ret) {
  6112. sdata_info(sdata, "Failed setting valid/dormant links\n");
  6113. return;
  6114. }
  6115. ieee80211_vif_cfg_change_notify(sdata,
  6116. BSS_CHANGED_MLD_VALID_LINKS);
  6117. }
  6118. memset(&sdata->u.mgd.ttlm_info, 0,
  6119. sizeof(sdata->u.mgd.ttlm_info));
  6120. return;
  6121. }
  6122. for (i = 0; i < elems->ttlm_num; i++) {
  6123. struct ieee80211_adv_ttlm_info ttlm_info;
  6124. u32 res;
  6125. res = ieee80211_parse_adv_t2l(sdata, elems->ttlm[i],
  6126. &ttlm_info);
  6127. if (res) {
  6128. __ieee80211_disconnect(sdata);
  6129. return;
  6130. }
  6131. if (ttlm_info.switch_time) {
  6132. u16 beacon_ts_tu, st_tu, delay;
  6133. u64 delay_usec;
  6134. u64 mask;
  6135. /* The t2l map switch time is indicated with a partial
  6136. * TSF value (bits 10 to 25), get the partial beacon TS
  6137. * as well, and calc the delay to the start time.
  6138. */
  6139. mask = GENMASK_ULL(25, 10);
  6140. beacon_ts_tu = (beacon_ts & mask) >> 10;
  6141. st_tu = ttlm_info.switch_time;
  6142. delay = st_tu - beacon_ts_tu;
  6143. /*
  6144. * If the switch time is far in the future, then it
  6145. * could also be the previous switch still being
  6146. * announced.
  6147. * We can simply ignore it for now, if it is a future
  6148. * switch the AP will continue to announce it anyway.
  6149. */
  6150. if (delay > IEEE80211_ADV_TTLM_ST_UNDERFLOW)
  6151. return;
  6152. delay_usec = ieee80211_tu_to_usec(delay);
  6153. /* Link switching can take time, so schedule it
  6154. * 100ms before to be ready on time
  6155. */
  6156. if (delay_usec > IEEE80211_ADV_TTLM_SAFETY_BUFFER_MS)
  6157. delay_usec -=
  6158. IEEE80211_ADV_TTLM_SAFETY_BUFFER_MS;
  6159. else
  6160. delay_usec = 0;
  6161. sdata->u.mgd.ttlm_info = ttlm_info;
  6162. wiphy_hrtimer_work_cancel(sdata->local->hw.wiphy,
  6163. &sdata->u.mgd.ttlm_work);
  6164. wiphy_hrtimer_work_queue(sdata->local->hw.wiphy,
  6165. &sdata->u.mgd.ttlm_work,
  6166. us_to_ktime(delay_usec));
  6167. return;
  6168. }
  6169. }
  6170. }
  6171. static void
  6172. ieee80211_mgd_check_cross_link_csa(struct ieee80211_sub_if_data *sdata,
  6173. int reporting_link_id,
  6174. struct ieee802_11_elems *elems)
  6175. {
  6176. const struct element *sta_profiles[IEEE80211_MLD_MAX_NUM_LINKS] = {};
  6177. ssize_t sta_profiles_len[IEEE80211_MLD_MAX_NUM_LINKS] = {};
  6178. const struct element *sub;
  6179. const u8 *subelems;
  6180. size_t subelems_len;
  6181. u8 common_size;
  6182. int link_id;
  6183. if (!ieee80211_mle_size_ok((u8 *)elems->ml_basic, elems->ml_basic_len))
  6184. return;
  6185. common_size = ieee80211_mle_common_size((u8 *)elems->ml_basic);
  6186. subelems = (u8 *)elems->ml_basic + common_size;
  6187. subelems_len = elems->ml_basic_len - common_size;
  6188. for_each_element_id(sub, IEEE80211_MLE_SUBELEM_PER_STA_PROFILE,
  6189. subelems, subelems_len) {
  6190. struct ieee80211_mle_per_sta_profile *prof = (void *)sub->data;
  6191. struct ieee80211_link_data *link;
  6192. ssize_t len;
  6193. if (!ieee80211_mle_basic_sta_prof_size_ok(sub->data,
  6194. sub->datalen))
  6195. continue;
  6196. link_id = le16_get_bits(prof->control,
  6197. IEEE80211_MLE_STA_CONTROL_LINK_ID);
  6198. /* need a valid link ID, but also not our own, both AP bugs */
  6199. if (link_id == reporting_link_id ||
  6200. link_id >= IEEE80211_MLD_MAX_NUM_LINKS)
  6201. continue;
  6202. link = sdata_dereference(sdata->link[link_id], sdata);
  6203. if (!link)
  6204. continue;
  6205. len = cfg80211_defragment_element(sub, subelems, subelems_len,
  6206. NULL, 0,
  6207. IEEE80211_MLE_SUBELEM_FRAGMENT);
  6208. if (WARN_ON(len < 0))
  6209. continue;
  6210. sta_profiles[link_id] = sub;
  6211. sta_profiles_len[link_id] = len;
  6212. }
  6213. for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS; link_id++) {
  6214. struct ieee80211_mle_per_sta_profile *prof;
  6215. struct ieee802_11_elems *prof_elems;
  6216. struct ieee80211_link_data *link;
  6217. ssize_t len;
  6218. if (link_id == reporting_link_id)
  6219. continue;
  6220. link = sdata_dereference(sdata->link[link_id], sdata);
  6221. if (!link)
  6222. continue;
  6223. if (!sta_profiles[link_id]) {
  6224. prof_elems = NULL;
  6225. goto handle;
  6226. }
  6227. /* we can defragment in-place, won't use the buffer again */
  6228. len = cfg80211_defragment_element(sta_profiles[link_id],
  6229. subelems, subelems_len,
  6230. (void *)sta_profiles[link_id],
  6231. sta_profiles_len[link_id],
  6232. IEEE80211_MLE_SUBELEM_FRAGMENT);
  6233. if (WARN_ON(len != sta_profiles_len[link_id]))
  6234. continue;
  6235. prof = (void *)sta_profiles[link_id];
  6236. prof_elems = ieee802_11_parse_elems(prof->variable +
  6237. (prof->sta_info_len - 1),
  6238. len -
  6239. (prof->sta_info_len - 1),
  6240. IEEE80211_FTYPE_MGMT |
  6241. IEEE80211_STYPE_BEACON,
  6242. NULL);
  6243. /* memory allocation failed - let's hope that's transient */
  6244. if (!prof_elems)
  6245. continue;
  6246. handle:
  6247. /*
  6248. * FIXME: the timings here are obviously incorrect,
  6249. * but only older Intel drivers seem to care, and
  6250. * those don't have MLO. If you really need this,
  6251. * the problem is having to calculate it with the
  6252. * TSF offset etc. The device_timestamp is still
  6253. * correct, of course.
  6254. */
  6255. ieee80211_sta_process_chanswitch(link, 0, 0, elems, prof_elems,
  6256. IEEE80211_CSA_SOURCE_OTHER_LINK);
  6257. kfree(prof_elems);
  6258. }
  6259. }
  6260. static bool ieee80211_mgd_ssid_mismatch(struct ieee80211_sub_if_data *sdata,
  6261. const struct ieee802_11_elems *elems)
  6262. {
  6263. struct ieee80211_vif_cfg *cfg = &sdata->vif.cfg;
  6264. static u8 zero_ssid[IEEE80211_MAX_SSID_LEN];
  6265. if (!elems->ssid)
  6266. return false;
  6267. /* hidden SSID: zero length */
  6268. if (elems->ssid_len == 0)
  6269. return false;
  6270. if (elems->ssid_len != cfg->ssid_len)
  6271. return true;
  6272. /* hidden SSID: zeroed out */
  6273. if (!memcmp(elems->ssid, zero_ssid, elems->ssid_len))
  6274. return false;
  6275. return memcmp(elems->ssid, cfg->ssid, cfg->ssid_len);
  6276. }
  6277. static bool
  6278. ieee80211_rx_beacon_freq_valid(struct ieee80211_local *local,
  6279. struct ieee80211_mgmt *mgmt,
  6280. struct ieee80211_rx_status *rx_status,
  6281. struct ieee80211_chanctx_conf *chanctx)
  6282. {
  6283. u32 pri_2mhz_khz;
  6284. struct ieee80211_channel *s1g_sibling_1mhz;
  6285. u32 pri_khz = ieee80211_channel_to_khz(chanctx->def.chan);
  6286. u32 rx_khz = ieee80211_rx_status_to_khz(rx_status);
  6287. if (rx_khz == pri_khz)
  6288. return true;
  6289. if (!chanctx->def.s1g_primary_2mhz)
  6290. return false;
  6291. /*
  6292. * If we have an S1G interface with a 2MHz primary, beacons are
  6293. * sent on the center frequency of the 2MHz primary. Find the sibling
  6294. * 1MHz channel and calculate the 2MHz primary center frequency.
  6295. */
  6296. s1g_sibling_1mhz = cfg80211_s1g_get_primary_sibling(local->hw.wiphy,
  6297. &chanctx->def);
  6298. if (!s1g_sibling_1mhz)
  6299. return false;
  6300. pri_2mhz_khz =
  6301. (pri_khz + ieee80211_channel_to_khz(s1g_sibling_1mhz)) / 2;
  6302. return rx_khz == pri_2mhz_khz;
  6303. }
  6304. static void ieee80211_rx_mgmt_beacon(struct ieee80211_link_data *link,
  6305. struct ieee80211_hdr *hdr, size_t len,
  6306. struct ieee80211_rx_status *rx_status)
  6307. {
  6308. struct ieee80211_sub_if_data *sdata = link->sdata;
  6309. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  6310. struct ieee80211_bss_conf *bss_conf = link->conf;
  6311. struct ieee80211_vif_cfg *vif_cfg = &sdata->vif.cfg;
  6312. struct ieee80211_mgmt *mgmt = (void *) hdr;
  6313. struct ieee80211_ext *ext = NULL;
  6314. size_t baselen;
  6315. struct ieee802_11_elems *elems;
  6316. struct ieee80211_local *local = sdata->local;
  6317. struct ieee80211_chanctx_conf *chanctx_conf;
  6318. struct ieee80211_supported_band *sband;
  6319. struct ieee80211_channel *chan;
  6320. struct link_sta_info *link_sta;
  6321. struct sta_info *sta;
  6322. u64 changed = 0;
  6323. bool erp_valid;
  6324. u8 erp_value = 0;
  6325. u32 ncrc = 0;
  6326. u8 *bssid, *variable = mgmt->u.beacon.variable;
  6327. u8 deauth_buf[IEEE80211_DEAUTH_FRAME_LEN];
  6328. struct ieee80211_elems_parse_params parse_params = {
  6329. .mode = link->u.mgd.conn.mode,
  6330. .link_id = -1,
  6331. .from_ap = true,
  6332. .type = le16_to_cpu(mgmt->frame_control) & IEEE80211_FCTL_TYPE,
  6333. };
  6334. lockdep_assert_wiphy(local->hw.wiphy);
  6335. /* Process beacon from the current BSS */
  6336. bssid = ieee80211_get_bssid(hdr, len, sdata->vif.type);
  6337. if (ieee80211_is_s1g_beacon(mgmt->frame_control)) {
  6338. ext = (void *)mgmt;
  6339. variable = ext->u.s1g_beacon.variable +
  6340. ieee80211_s1g_optional_len(ext->frame_control);
  6341. }
  6342. baselen = (u8 *) variable - (u8 *) mgmt;
  6343. if (baselen > len)
  6344. return;
  6345. parse_params.start = variable;
  6346. parse_params.len = len - baselen;
  6347. rcu_read_lock();
  6348. chanctx_conf = rcu_dereference(bss_conf->chanctx_conf);
  6349. if (!chanctx_conf) {
  6350. rcu_read_unlock();
  6351. return;
  6352. }
  6353. if (!ieee80211_rx_beacon_freq_valid(local, mgmt, rx_status,
  6354. chanctx_conf)) {
  6355. rcu_read_unlock();
  6356. return;
  6357. }
  6358. chan = chanctx_conf->def.chan;
  6359. rcu_read_unlock();
  6360. if (ifmgd->assoc_data && ifmgd->assoc_data->need_beacon &&
  6361. !WARN_ON(ieee80211_vif_is_mld(&sdata->vif)) &&
  6362. ieee80211_rx_our_beacon(bssid, ifmgd->assoc_data->link[0].bss)) {
  6363. parse_params.bss = ifmgd->assoc_data->link[0].bss;
  6364. elems = ieee802_11_parse_elems_full(&parse_params);
  6365. if (!elems)
  6366. return;
  6367. ieee80211_rx_bss_info(link, mgmt, len, rx_status);
  6368. if (elems->dtim_period)
  6369. link->u.mgd.dtim_period = elems->dtim_period;
  6370. link->u.mgd.have_beacon = true;
  6371. ifmgd->assoc_data->need_beacon = false;
  6372. if (ieee80211_hw_check(&local->hw, TIMING_BEACON_ONLY) &&
  6373. !ieee80211_is_s1g_beacon(hdr->frame_control)) {
  6374. bss_conf->sync_tsf =
  6375. le64_to_cpu(mgmt->u.beacon.timestamp);
  6376. bss_conf->sync_device_ts =
  6377. rx_status->device_timestamp;
  6378. bss_conf->sync_dtim_count = elems->dtim_count;
  6379. }
  6380. if (elems->mbssid_config_ie)
  6381. bss_conf->profile_periodicity =
  6382. elems->mbssid_config_ie->profile_periodicity;
  6383. else
  6384. bss_conf->profile_periodicity = 0;
  6385. if (elems->ext_capab_len >= 11 &&
  6386. (elems->ext_capab[10] & WLAN_EXT_CAPA11_EMA_SUPPORT))
  6387. bss_conf->ema_ap = true;
  6388. else
  6389. bss_conf->ema_ap = false;
  6390. /* continue assoc process */
  6391. ifmgd->assoc_data->timeout = jiffies;
  6392. ifmgd->assoc_data->timeout_started = true;
  6393. run_again(sdata, ifmgd->assoc_data->timeout);
  6394. kfree(elems);
  6395. return;
  6396. }
  6397. if (!ifmgd->associated ||
  6398. !ieee80211_rx_our_beacon(bssid, bss_conf->bss))
  6399. return;
  6400. bssid = link->u.mgd.bssid;
  6401. if (!(rx_status->flag & RX_FLAG_NO_SIGNAL_VAL))
  6402. ieee80211_handle_beacon_sig(link, ifmgd, bss_conf,
  6403. local, rx_status);
  6404. if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL) {
  6405. mlme_dbg_ratelimited(sdata,
  6406. "cancelling AP probe due to a received beacon\n");
  6407. ieee80211_reset_ap_probe(sdata);
  6408. }
  6409. /*
  6410. * Push the beacon loss detection into the future since
  6411. * we are processing a beacon from the AP just now.
  6412. */
  6413. ieee80211_sta_reset_beacon_monitor(sdata);
  6414. /* TODO: CRC urrently not calculated on S1G Beacon Compatibility
  6415. * element (which carries the beacon interval). Don't forget to add a
  6416. * bit to care_about_ies[] above if mac80211 is interested in a
  6417. * changing S1G element.
  6418. */
  6419. if (!ieee80211_is_s1g_beacon(hdr->frame_control))
  6420. ncrc = crc32_be(0, (void *)&mgmt->u.beacon.beacon_int, 4);
  6421. parse_params.bss = bss_conf->bss;
  6422. parse_params.filter = care_about_ies;
  6423. parse_params.crc = ncrc;
  6424. elems = ieee802_11_parse_elems_full(&parse_params);
  6425. if (!elems)
  6426. return;
  6427. if (rx_status->flag & RX_FLAG_DECRYPTED &&
  6428. ieee80211_mgd_ssid_mismatch(sdata, elems)) {
  6429. sdata_info(sdata, "SSID mismatch for AP %pM, disconnect\n",
  6430. sdata->vif.cfg.ap_addr);
  6431. __ieee80211_disconnect(sdata);
  6432. return;
  6433. }
  6434. ncrc = elems->crc;
  6435. if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK) &&
  6436. ieee80211_check_tim(elems->tim, elems->tim_len, vif_cfg->aid,
  6437. vif_cfg->s1g)) {
  6438. if (local->hw.conf.dynamic_ps_timeout > 0) {
  6439. if (local->hw.conf.flags & IEEE80211_CONF_PS) {
  6440. local->hw.conf.flags &= ~IEEE80211_CONF_PS;
  6441. ieee80211_hw_config(local, -1,
  6442. IEEE80211_CONF_CHANGE_PS);
  6443. }
  6444. ieee80211_send_nullfunc(local, sdata, false);
  6445. } else if (!local->pspolling && sdata->u.mgd.powersave) {
  6446. local->pspolling = true;
  6447. /*
  6448. * Here is assumed that the driver will be
  6449. * able to send ps-poll frame and receive a
  6450. * response even though power save mode is
  6451. * enabled, but some drivers might require
  6452. * to disable power save here. This needs
  6453. * to be investigated.
  6454. */
  6455. ieee80211_send_pspoll(local, sdata);
  6456. }
  6457. }
  6458. if (sdata->vif.p2p ||
  6459. sdata->vif.driver_flags & IEEE80211_VIF_GET_NOA_UPDATE) {
  6460. struct ieee80211_p2p_noa_attr noa = {};
  6461. int ret;
  6462. ret = cfg80211_get_p2p_attr(variable,
  6463. len - baselen,
  6464. IEEE80211_P2P_ATTR_ABSENCE_NOTICE,
  6465. (u8 *) &noa, sizeof(noa));
  6466. if (ret >= 2) {
  6467. if (link->u.mgd.p2p_noa_index != noa.index) {
  6468. /* valid noa_attr and index changed */
  6469. link->u.mgd.p2p_noa_index = noa.index;
  6470. memcpy(&bss_conf->p2p_noa_attr, &noa, sizeof(noa));
  6471. changed |= BSS_CHANGED_P2P_PS;
  6472. /*
  6473. * make sure we update all information, the CRC
  6474. * mechanism doesn't look at P2P attributes.
  6475. */
  6476. link->u.mgd.beacon_crc_valid = false;
  6477. }
  6478. } else if (link->u.mgd.p2p_noa_index != -1) {
  6479. /* noa_attr not found and we had valid noa_attr before */
  6480. link->u.mgd.p2p_noa_index = -1;
  6481. memset(&bss_conf->p2p_noa_attr, 0, sizeof(bss_conf->p2p_noa_attr));
  6482. changed |= BSS_CHANGED_P2P_PS;
  6483. link->u.mgd.beacon_crc_valid = false;
  6484. }
  6485. }
  6486. /*
  6487. * Update beacon timing and dtim count on every beacon appearance. This
  6488. * will allow the driver to use the most updated values. Do it before
  6489. * comparing this one with last received beacon.
  6490. * IMPORTANT: These parameters would possibly be out of sync by the time
  6491. * the driver will use them. The synchronized view is currently
  6492. * guaranteed only in certain callbacks.
  6493. */
  6494. if (ieee80211_hw_check(&local->hw, TIMING_BEACON_ONLY) &&
  6495. !ieee80211_is_s1g_beacon(hdr->frame_control)) {
  6496. bss_conf->sync_tsf =
  6497. le64_to_cpu(mgmt->u.beacon.timestamp);
  6498. bss_conf->sync_device_ts =
  6499. rx_status->device_timestamp;
  6500. bss_conf->sync_dtim_count = elems->dtim_count;
  6501. }
  6502. if ((ncrc == link->u.mgd.beacon_crc && link->u.mgd.beacon_crc_valid) ||
  6503. (ext && ieee80211_is_s1g_short_beacon(ext->frame_control,
  6504. parse_params.start,
  6505. parse_params.len)))
  6506. goto free;
  6507. link->u.mgd.beacon_crc = ncrc;
  6508. link->u.mgd.beacon_crc_valid = true;
  6509. ieee80211_rx_bss_info(link, mgmt, len, rx_status);
  6510. ieee80211_sta_process_chanswitch(link, rx_status->mactime,
  6511. rx_status->device_timestamp,
  6512. elems, elems,
  6513. IEEE80211_CSA_SOURCE_BEACON);
  6514. /* note that after this elems->ml_basic can no longer be used fully */
  6515. ieee80211_mgd_check_cross_link_csa(sdata, rx_status->link_id, elems);
  6516. ieee80211_mgd_update_bss_param_ch_cnt(sdata, bss_conf, elems);
  6517. if (!sdata->u.mgd.epcs.enabled &&
  6518. !link->u.mgd.disable_wmm_tracking &&
  6519. ieee80211_sta_wmm_params(local, link, elems->wmm_param,
  6520. elems->wmm_param_len,
  6521. elems->mu_edca_param_set))
  6522. changed |= BSS_CHANGED_QOS;
  6523. /*
  6524. * If we haven't had a beacon before, tell the driver about the
  6525. * DTIM period (and beacon timing if desired) now.
  6526. */
  6527. if (!link->u.mgd.have_beacon) {
  6528. /* a few bogus AP send dtim_period = 0 or no TIM IE */
  6529. bss_conf->dtim_period = elems->dtim_period ?: 1;
  6530. changed |= BSS_CHANGED_BEACON_INFO;
  6531. link->u.mgd.have_beacon = true;
  6532. ieee80211_recalc_ps(local);
  6533. ieee80211_recalc_ps_vif(sdata);
  6534. }
  6535. if (elems->erp_info) {
  6536. erp_valid = true;
  6537. erp_value = elems->erp_info[0];
  6538. } else {
  6539. erp_valid = false;
  6540. }
  6541. if (!ieee80211_is_s1g_beacon(hdr->frame_control))
  6542. changed |= ieee80211_handle_bss_capability(link,
  6543. le16_to_cpu(mgmt->u.beacon.capab_info),
  6544. erp_valid, erp_value);
  6545. sta = sta_info_get(sdata, sdata->vif.cfg.ap_addr);
  6546. if (WARN_ON(!sta)) {
  6547. goto free;
  6548. }
  6549. link_sta = rcu_dereference_protected(sta->link[link->link_id],
  6550. lockdep_is_held(&local->hw.wiphy->mtx));
  6551. if (WARN_ON(!link_sta)) {
  6552. goto free;
  6553. }
  6554. if (WARN_ON(!bss_conf->chanreq.oper.chan))
  6555. goto free;
  6556. sband = local->hw.wiphy->bands[bss_conf->chanreq.oper.chan->band];
  6557. changed |= ieee80211_recalc_twt_req(sdata, sband, link, link_sta, elems);
  6558. if (ieee80211_config_bw(link, elems, true, &changed,
  6559. IEEE80211_STYPE_BEACON)) {
  6560. ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
  6561. WLAN_REASON_DEAUTH_LEAVING,
  6562. true, deauth_buf);
  6563. ieee80211_report_disconnect(sdata, deauth_buf,
  6564. sizeof(deauth_buf), true,
  6565. WLAN_REASON_DEAUTH_LEAVING,
  6566. false);
  6567. goto free;
  6568. }
  6569. if (elems->opmode_notif)
  6570. ieee80211_vht_handle_opmode(sdata, link_sta,
  6571. *elems->opmode_notif,
  6572. rx_status->band);
  6573. changed |= ieee80211_handle_pwr_constr(link, chan, mgmt,
  6574. elems->country_elem,
  6575. elems->country_elem_len,
  6576. elems->pwr_constr_elem,
  6577. elems->cisco_dtpc_elem);
  6578. ieee80211_ml_reconfiguration(sdata, elems);
  6579. ieee80211_process_adv_ttlm(sdata, elems,
  6580. le64_to_cpu(mgmt->u.beacon.timestamp));
  6581. ieee80211_link_info_change_notify(sdata, link, changed);
  6582. free:
  6583. kfree(elems);
  6584. }
  6585. static void ieee80211_apply_neg_ttlm(struct ieee80211_sub_if_data *sdata,
  6586. struct ieee80211_neg_ttlm neg_ttlm)
  6587. {
  6588. u16 new_active_links, new_dormant_links, new_suspended_links, map = 0;
  6589. u8 i;
  6590. for (i = 0; i < IEEE80211_TTLM_NUM_TIDS; i++)
  6591. map |= neg_ttlm.downlink[i] | neg_ttlm.uplink[i];
  6592. /* If there is an active TTLM, unset previously suspended links */
  6593. if (sdata->vif.neg_ttlm.valid)
  6594. sdata->vif.dormant_links &= ~sdata->vif.suspended_links;
  6595. /* exclude links that are already disabled by advertised TTLM */
  6596. new_active_links =
  6597. map & sdata->vif.valid_links & ~sdata->vif.dormant_links;
  6598. new_suspended_links =
  6599. (~map & sdata->vif.valid_links) & ~sdata->vif.dormant_links;
  6600. new_dormant_links = sdata->vif.dormant_links | new_suspended_links;
  6601. if (ieee80211_ttlm_set_links(sdata, new_active_links,
  6602. new_dormant_links, new_suspended_links))
  6603. return;
  6604. sdata->vif.neg_ttlm = neg_ttlm;
  6605. sdata->vif.neg_ttlm.valid = true;
  6606. }
  6607. static void ieee80211_neg_ttlm_timeout_work(struct wiphy *wiphy,
  6608. struct wiphy_work *work)
  6609. {
  6610. struct ieee80211_sub_if_data *sdata =
  6611. container_of(work, struct ieee80211_sub_if_data,
  6612. u.mgd.neg_ttlm_timeout_work.work);
  6613. sdata_info(sdata,
  6614. "No negotiated TTLM response from AP, disconnecting.\n");
  6615. __ieee80211_disconnect(sdata);
  6616. }
  6617. static void
  6618. ieee80211_neg_ttlm_add_suggested_map(struct sk_buff *skb,
  6619. struct ieee80211_neg_ttlm *neg_ttlm)
  6620. {
  6621. u8 i, direction[IEEE80211_TTLM_MAX_CNT];
  6622. if (memcmp(neg_ttlm->downlink, neg_ttlm->uplink,
  6623. sizeof(neg_ttlm->downlink))) {
  6624. direction[0] = IEEE80211_TTLM_DIRECTION_DOWN;
  6625. direction[1] = IEEE80211_TTLM_DIRECTION_UP;
  6626. } else {
  6627. direction[0] = IEEE80211_TTLM_DIRECTION_BOTH;
  6628. }
  6629. for (i = 0; i < ARRAY_SIZE(direction); i++) {
  6630. u8 tid, len, map_ind = 0, *len_pos, *map_ind_pos, *pos;
  6631. __le16 map;
  6632. len = sizeof(struct ieee80211_ttlm_elem) + 1 + 1;
  6633. pos = skb_put(skb, len + 2);
  6634. *pos++ = WLAN_EID_EXTENSION;
  6635. len_pos = pos++;
  6636. *pos++ = WLAN_EID_EXT_TID_TO_LINK_MAPPING;
  6637. *pos++ = direction[i];
  6638. map_ind_pos = pos++;
  6639. for (tid = 0; tid < IEEE80211_TTLM_NUM_TIDS; tid++) {
  6640. map = direction[i] == IEEE80211_TTLM_DIRECTION_UP ?
  6641. cpu_to_le16(neg_ttlm->uplink[tid]) :
  6642. cpu_to_le16(neg_ttlm->downlink[tid]);
  6643. if (!map)
  6644. continue;
  6645. len += 2;
  6646. map_ind |= BIT(tid);
  6647. skb_put_data(skb, &map, sizeof(map));
  6648. }
  6649. *map_ind_pos = map_ind;
  6650. *len_pos = len;
  6651. if (direction[i] == IEEE80211_TTLM_DIRECTION_BOTH)
  6652. break;
  6653. }
  6654. }
  6655. static void
  6656. ieee80211_send_neg_ttlm_req(struct ieee80211_sub_if_data *sdata,
  6657. struct ieee80211_neg_ttlm *neg_ttlm,
  6658. u8 dialog_token)
  6659. {
  6660. struct ieee80211_local *local = sdata->local;
  6661. struct ieee80211_mgmt *mgmt;
  6662. struct sk_buff *skb;
  6663. int hdr_len = offsetofend(struct ieee80211_mgmt, u.action.u.ttlm_req);
  6664. int ttlm_max_len = 2 + 1 + sizeof(struct ieee80211_ttlm_elem) + 1 +
  6665. 2 * 2 * IEEE80211_TTLM_NUM_TIDS;
  6666. skb = dev_alloc_skb(local->tx_headroom + hdr_len + ttlm_max_len);
  6667. if (!skb)
  6668. return;
  6669. skb_reserve(skb, local->tx_headroom);
  6670. mgmt = skb_put_zero(skb, hdr_len);
  6671. mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
  6672. IEEE80211_STYPE_ACTION);
  6673. memcpy(mgmt->da, sdata->vif.cfg.ap_addr, ETH_ALEN);
  6674. memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
  6675. memcpy(mgmt->bssid, sdata->vif.cfg.ap_addr, ETH_ALEN);
  6676. mgmt->u.action.category = WLAN_CATEGORY_PROTECTED_EHT;
  6677. mgmt->u.action.u.ttlm_req.action_code =
  6678. WLAN_PROTECTED_EHT_ACTION_TTLM_REQ;
  6679. mgmt->u.action.u.ttlm_req.dialog_token = dialog_token;
  6680. ieee80211_neg_ttlm_add_suggested_map(skb, neg_ttlm);
  6681. ieee80211_tx_skb(sdata, skb);
  6682. }
  6683. int ieee80211_req_neg_ttlm(struct ieee80211_sub_if_data *sdata,
  6684. struct cfg80211_ttlm_params *params)
  6685. {
  6686. struct ieee80211_neg_ttlm neg_ttlm = {};
  6687. u8 i;
  6688. if (!ieee80211_vif_is_mld(&sdata->vif) ||
  6689. !(sdata->vif.cfg.mld_capa_op &
  6690. IEEE80211_MLD_CAP_OP_TID_TO_LINK_MAP_NEG_SUPP))
  6691. return -EINVAL;
  6692. for (i = 0; i < IEEE80211_TTLM_NUM_TIDS; i++) {
  6693. if ((params->dlink[i] & ~sdata->vif.valid_links) ||
  6694. (params->ulink[i] & ~sdata->vif.valid_links))
  6695. return -EINVAL;
  6696. neg_ttlm.downlink[i] = params->dlink[i];
  6697. neg_ttlm.uplink[i] = params->ulink[i];
  6698. }
  6699. if (drv_can_neg_ttlm(sdata->local, sdata, &neg_ttlm) !=
  6700. NEG_TTLM_RES_ACCEPT)
  6701. return -EINVAL;
  6702. ieee80211_apply_neg_ttlm(sdata, neg_ttlm);
  6703. sdata->u.mgd.dialog_token_alloc++;
  6704. ieee80211_send_neg_ttlm_req(sdata, &sdata->vif.neg_ttlm,
  6705. sdata->u.mgd.dialog_token_alloc);
  6706. wiphy_delayed_work_cancel(sdata->local->hw.wiphy,
  6707. &sdata->u.mgd.neg_ttlm_timeout_work);
  6708. wiphy_delayed_work_queue(sdata->local->hw.wiphy,
  6709. &sdata->u.mgd.neg_ttlm_timeout_work,
  6710. IEEE80211_NEG_TTLM_REQ_TIMEOUT);
  6711. return 0;
  6712. }
  6713. static void
  6714. ieee80211_send_neg_ttlm_res(struct ieee80211_sub_if_data *sdata,
  6715. enum ieee80211_neg_ttlm_res ttlm_res,
  6716. u8 dialog_token,
  6717. struct ieee80211_neg_ttlm *neg_ttlm)
  6718. {
  6719. struct ieee80211_local *local = sdata->local;
  6720. struct ieee80211_mgmt *mgmt;
  6721. struct sk_buff *skb;
  6722. int hdr_len = offsetofend(struct ieee80211_mgmt, u.action.u.ttlm_res);
  6723. int ttlm_max_len = 2 + 1 + sizeof(struct ieee80211_ttlm_elem) + 1 +
  6724. 2 * 2 * IEEE80211_TTLM_NUM_TIDS;
  6725. u16 status_code;
  6726. skb = dev_alloc_skb(local->tx_headroom + hdr_len + ttlm_max_len);
  6727. if (!skb)
  6728. return;
  6729. skb_reserve(skb, local->tx_headroom);
  6730. mgmt = skb_put_zero(skb, hdr_len);
  6731. mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
  6732. IEEE80211_STYPE_ACTION);
  6733. memcpy(mgmt->da, sdata->vif.cfg.ap_addr, ETH_ALEN);
  6734. memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
  6735. memcpy(mgmt->bssid, sdata->vif.cfg.ap_addr, ETH_ALEN);
  6736. mgmt->u.action.category = WLAN_CATEGORY_PROTECTED_EHT;
  6737. mgmt->u.action.u.ttlm_res.action_code =
  6738. WLAN_PROTECTED_EHT_ACTION_TTLM_RES;
  6739. mgmt->u.action.u.ttlm_res.dialog_token = dialog_token;
  6740. switch (ttlm_res) {
  6741. default:
  6742. WARN_ON(1);
  6743. fallthrough;
  6744. case NEG_TTLM_RES_REJECT:
  6745. status_code = WLAN_STATUS_DENIED_TID_TO_LINK_MAPPING;
  6746. break;
  6747. case NEG_TTLM_RES_ACCEPT:
  6748. status_code = WLAN_STATUS_SUCCESS;
  6749. break;
  6750. case NEG_TTLM_RES_SUGGEST_PREFERRED:
  6751. status_code = WLAN_STATUS_PREF_TID_TO_LINK_MAPPING_SUGGESTED;
  6752. ieee80211_neg_ttlm_add_suggested_map(skb, neg_ttlm);
  6753. break;
  6754. }
  6755. mgmt->u.action.u.ttlm_res.status_code = cpu_to_le16(status_code);
  6756. ieee80211_tx_skb(sdata, skb);
  6757. }
  6758. static int
  6759. ieee80211_parse_neg_ttlm(struct ieee80211_sub_if_data *sdata,
  6760. const struct ieee80211_ttlm_elem *ttlm,
  6761. struct ieee80211_neg_ttlm *neg_ttlm,
  6762. u8 *direction)
  6763. {
  6764. u8 control, link_map_presence, map_size, tid;
  6765. u8 *pos;
  6766. /* The element size was already validated in
  6767. * ieee80211_tid_to_link_map_size_ok()
  6768. */
  6769. pos = (void *)ttlm->optional;
  6770. control = ttlm->control;
  6771. /* mapping switch time and expected duration fields are not expected
  6772. * in case of negotiated TTLM
  6773. */
  6774. if (control & (IEEE80211_TTLM_CONTROL_SWITCH_TIME_PRESENT |
  6775. IEEE80211_TTLM_CONTROL_EXPECTED_DUR_PRESENT)) {
  6776. mlme_dbg(sdata,
  6777. "Invalid TTLM element in negotiated TTLM request\n");
  6778. return -EINVAL;
  6779. }
  6780. if (control & IEEE80211_TTLM_CONTROL_DEF_LINK_MAP) {
  6781. for (tid = 0; tid < IEEE80211_TTLM_NUM_TIDS; tid++) {
  6782. neg_ttlm->downlink[tid] = sdata->vif.valid_links;
  6783. neg_ttlm->uplink[tid] = sdata->vif.valid_links;
  6784. }
  6785. *direction = IEEE80211_TTLM_DIRECTION_BOTH;
  6786. return 0;
  6787. }
  6788. *direction = u8_get_bits(control, IEEE80211_TTLM_CONTROL_DIRECTION);
  6789. if (*direction != IEEE80211_TTLM_DIRECTION_DOWN &&
  6790. *direction != IEEE80211_TTLM_DIRECTION_UP &&
  6791. *direction != IEEE80211_TTLM_DIRECTION_BOTH)
  6792. return -EINVAL;
  6793. link_map_presence = *pos;
  6794. pos++;
  6795. if (control & IEEE80211_TTLM_CONTROL_LINK_MAP_SIZE)
  6796. map_size = 1;
  6797. else
  6798. map_size = 2;
  6799. for (tid = 0; tid < IEEE80211_TTLM_NUM_TIDS; tid++) {
  6800. u16 map;
  6801. if (link_map_presence & BIT(tid)) {
  6802. map = ieee80211_get_ttlm(map_size, pos);
  6803. if (!map) {
  6804. mlme_dbg(sdata,
  6805. "No active links for TID %d", tid);
  6806. return -EINVAL;
  6807. }
  6808. } else {
  6809. map = 0;
  6810. }
  6811. switch (*direction) {
  6812. case IEEE80211_TTLM_DIRECTION_BOTH:
  6813. neg_ttlm->downlink[tid] = map;
  6814. neg_ttlm->uplink[tid] = map;
  6815. break;
  6816. case IEEE80211_TTLM_DIRECTION_DOWN:
  6817. neg_ttlm->downlink[tid] = map;
  6818. break;
  6819. case IEEE80211_TTLM_DIRECTION_UP:
  6820. neg_ttlm->uplink[tid] = map;
  6821. break;
  6822. default:
  6823. return -EINVAL;
  6824. }
  6825. pos += map_size;
  6826. }
  6827. return 0;
  6828. }
  6829. void ieee80211_process_neg_ttlm_req(struct ieee80211_sub_if_data *sdata,
  6830. struct ieee80211_mgmt *mgmt, size_t len)
  6831. {
  6832. u8 dialog_token, direction[IEEE80211_TTLM_MAX_CNT] = {}, i;
  6833. size_t ies_len;
  6834. enum ieee80211_neg_ttlm_res ttlm_res = NEG_TTLM_RES_ACCEPT;
  6835. struct ieee802_11_elems *elems = NULL;
  6836. struct ieee80211_neg_ttlm neg_ttlm = {};
  6837. BUILD_BUG_ON(ARRAY_SIZE(direction) != ARRAY_SIZE(elems->ttlm));
  6838. if (!ieee80211_vif_is_mld(&sdata->vif))
  6839. return;
  6840. dialog_token = mgmt->u.action.u.ttlm_req.dialog_token;
  6841. ies_len = len - offsetof(struct ieee80211_mgmt,
  6842. u.action.u.ttlm_req.variable);
  6843. elems = ieee802_11_parse_elems(mgmt->u.action.u.ttlm_req.variable,
  6844. ies_len,
  6845. IEEE80211_FTYPE_MGMT |
  6846. IEEE80211_STYPE_ACTION,
  6847. NULL);
  6848. if (!elems) {
  6849. ttlm_res = NEG_TTLM_RES_REJECT;
  6850. goto out;
  6851. }
  6852. for (i = 0; i < elems->ttlm_num; i++) {
  6853. if (ieee80211_parse_neg_ttlm(sdata, elems->ttlm[i],
  6854. &neg_ttlm, &direction[i]) ||
  6855. (direction[i] == IEEE80211_TTLM_DIRECTION_BOTH &&
  6856. elems->ttlm_num != 1)) {
  6857. ttlm_res = NEG_TTLM_RES_REJECT;
  6858. goto out;
  6859. }
  6860. }
  6861. if (!elems->ttlm_num ||
  6862. (elems->ttlm_num == 2 && direction[0] == direction[1])) {
  6863. ttlm_res = NEG_TTLM_RES_REJECT;
  6864. goto out;
  6865. }
  6866. for (i = 0; i < IEEE80211_TTLM_NUM_TIDS; i++) {
  6867. if ((neg_ttlm.downlink[i] &&
  6868. (neg_ttlm.downlink[i] & ~sdata->vif.valid_links)) ||
  6869. (neg_ttlm.uplink[i] &&
  6870. (neg_ttlm.uplink[i] & ~sdata->vif.valid_links))) {
  6871. ttlm_res = NEG_TTLM_RES_REJECT;
  6872. goto out;
  6873. }
  6874. }
  6875. ttlm_res = drv_can_neg_ttlm(sdata->local, sdata, &neg_ttlm);
  6876. if (ttlm_res != NEG_TTLM_RES_ACCEPT)
  6877. goto out;
  6878. ieee80211_apply_neg_ttlm(sdata, neg_ttlm);
  6879. out:
  6880. kfree(elems);
  6881. ieee80211_send_neg_ttlm_res(sdata, ttlm_res, dialog_token, &neg_ttlm);
  6882. }
  6883. void ieee80211_process_neg_ttlm_res(struct ieee80211_sub_if_data *sdata,
  6884. struct ieee80211_mgmt *mgmt, size_t len)
  6885. {
  6886. if (!ieee80211_vif_is_mld(&sdata->vif) ||
  6887. mgmt->u.action.u.ttlm_req.dialog_token !=
  6888. sdata->u.mgd.dialog_token_alloc)
  6889. return;
  6890. wiphy_delayed_work_cancel(sdata->local->hw.wiphy,
  6891. &sdata->u.mgd.neg_ttlm_timeout_work);
  6892. /* MLD station sends a TID to link mapping request, mainly to handle
  6893. * BTM (BSS transition management) request, in which case it needs to
  6894. * restrict the active links set.
  6895. * In this case it's not expected that the MLD AP will reject the
  6896. * negotiated TTLM request.
  6897. * This can be better implemented in the future, to handle request
  6898. * rejections.
  6899. */
  6900. if (le16_to_cpu(mgmt->u.action.u.ttlm_res.status_code) != WLAN_STATUS_SUCCESS)
  6901. __ieee80211_disconnect(sdata);
  6902. }
  6903. void ieee80211_process_ttlm_teardown(struct ieee80211_sub_if_data *sdata)
  6904. {
  6905. u16 new_dormant_links;
  6906. if (!sdata->vif.neg_ttlm.valid)
  6907. return;
  6908. memset(&sdata->vif.neg_ttlm, 0, sizeof(sdata->vif.neg_ttlm));
  6909. new_dormant_links =
  6910. sdata->vif.dormant_links & ~sdata->vif.suspended_links;
  6911. sdata->vif.suspended_links = 0;
  6912. ieee80211_vif_set_links(sdata, sdata->vif.valid_links,
  6913. new_dormant_links);
  6914. ieee80211_vif_cfg_change_notify(sdata, BSS_CHANGED_MLD_TTLM |
  6915. BSS_CHANGED_MLD_VALID_LINKS);
  6916. }
  6917. static void ieee80211_teardown_ttlm_work(struct wiphy *wiphy,
  6918. struct wiphy_work *work)
  6919. {
  6920. struct ieee80211_sub_if_data *sdata =
  6921. container_of(work, struct ieee80211_sub_if_data,
  6922. u.mgd.teardown_ttlm_work);
  6923. ieee80211_process_ttlm_teardown(sdata);
  6924. }
  6925. void ieee80211_send_teardown_neg_ttlm(struct ieee80211_vif *vif)
  6926. {
  6927. struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
  6928. struct ieee80211_local *local = sdata->local;
  6929. struct ieee80211_mgmt *mgmt;
  6930. struct sk_buff *skb;
  6931. int frame_len = offsetofend(struct ieee80211_mgmt,
  6932. u.action.u.ttlm_tear_down);
  6933. struct ieee80211_tx_info *info;
  6934. skb = dev_alloc_skb(local->hw.extra_tx_headroom + frame_len);
  6935. if (!skb)
  6936. return;
  6937. skb_reserve(skb, local->hw.extra_tx_headroom);
  6938. mgmt = skb_put_zero(skb, frame_len);
  6939. mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
  6940. IEEE80211_STYPE_ACTION);
  6941. memcpy(mgmt->da, sdata->vif.cfg.ap_addr, ETH_ALEN);
  6942. memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
  6943. memcpy(mgmt->bssid, sdata->vif.cfg.ap_addr, ETH_ALEN);
  6944. mgmt->u.action.category = WLAN_CATEGORY_PROTECTED_EHT;
  6945. mgmt->u.action.u.ttlm_tear_down.action_code =
  6946. WLAN_PROTECTED_EHT_ACTION_TTLM_TEARDOWN;
  6947. info = IEEE80211_SKB_CB(skb);
  6948. info->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS;
  6949. info->status_data = IEEE80211_STATUS_TYPE_NEG_TTLM;
  6950. ieee80211_tx_skb(sdata, skb);
  6951. }
  6952. EXPORT_SYMBOL(ieee80211_send_teardown_neg_ttlm);
  6953. void ieee80211_sta_rx_queued_ext(struct ieee80211_sub_if_data *sdata,
  6954. struct sk_buff *skb)
  6955. {
  6956. struct ieee80211_link_data *link = &sdata->deflink;
  6957. struct ieee80211_rx_status *rx_status;
  6958. struct ieee80211_hdr *hdr;
  6959. u16 fc;
  6960. lockdep_assert_wiphy(sdata->local->hw.wiphy);
  6961. rx_status = (struct ieee80211_rx_status *) skb->cb;
  6962. hdr = (struct ieee80211_hdr *) skb->data;
  6963. fc = le16_to_cpu(hdr->frame_control);
  6964. switch (fc & IEEE80211_FCTL_STYPE) {
  6965. case IEEE80211_STYPE_S1G_BEACON:
  6966. ieee80211_rx_mgmt_beacon(link, hdr, skb->len, rx_status);
  6967. break;
  6968. }
  6969. }
  6970. void ieee80211_sta_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
  6971. struct sk_buff *skb)
  6972. {
  6973. struct ieee80211_link_data *link = &sdata->deflink;
  6974. struct ieee80211_rx_status *rx_status;
  6975. struct ieee802_11_elems *elems;
  6976. struct ieee80211_mgmt *mgmt;
  6977. u16 fc;
  6978. int ies_len;
  6979. lockdep_assert_wiphy(sdata->local->hw.wiphy);
  6980. rx_status = (struct ieee80211_rx_status *) skb->cb;
  6981. mgmt = (struct ieee80211_mgmt *) skb->data;
  6982. fc = le16_to_cpu(mgmt->frame_control);
  6983. if (rx_status->link_valid) {
  6984. link = sdata_dereference(sdata->link[rx_status->link_id],
  6985. sdata);
  6986. if (!link)
  6987. return;
  6988. }
  6989. switch (fc & IEEE80211_FCTL_STYPE) {
  6990. case IEEE80211_STYPE_BEACON:
  6991. ieee80211_rx_mgmt_beacon(link, (void *)mgmt,
  6992. skb->len, rx_status);
  6993. break;
  6994. case IEEE80211_STYPE_PROBE_RESP:
  6995. ieee80211_rx_mgmt_probe_resp(link, skb);
  6996. break;
  6997. case IEEE80211_STYPE_AUTH:
  6998. ieee80211_rx_mgmt_auth(sdata, mgmt, skb->len);
  6999. break;
  7000. case IEEE80211_STYPE_DEAUTH:
  7001. ieee80211_rx_mgmt_deauth(sdata, mgmt, skb->len);
  7002. break;
  7003. case IEEE80211_STYPE_DISASSOC:
  7004. ieee80211_rx_mgmt_disassoc(sdata, mgmt, skb->len);
  7005. break;
  7006. case IEEE80211_STYPE_ASSOC_RESP:
  7007. case IEEE80211_STYPE_REASSOC_RESP:
  7008. ieee80211_rx_mgmt_assoc_resp(sdata, mgmt, skb->len);
  7009. break;
  7010. case IEEE80211_STYPE_ACTION:
  7011. if (!sdata->u.mgd.associated ||
  7012. !ether_addr_equal(mgmt->bssid, sdata->vif.cfg.ap_addr))
  7013. break;
  7014. switch (mgmt->u.action.category) {
  7015. case WLAN_CATEGORY_SPECTRUM_MGMT:
  7016. ies_len = skb->len -
  7017. offsetof(struct ieee80211_mgmt,
  7018. u.action.u.chan_switch.variable);
  7019. if (ies_len < 0)
  7020. break;
  7021. /* CSA IE cannot be overridden, no need for BSSID */
  7022. elems = ieee802_11_parse_elems(mgmt->u.action.u.chan_switch.variable,
  7023. ies_len,
  7024. IEEE80211_FTYPE_MGMT |
  7025. IEEE80211_STYPE_ACTION,
  7026. NULL);
  7027. if (elems && !elems->parse_error) {
  7028. enum ieee80211_csa_source src =
  7029. IEEE80211_CSA_SOURCE_PROT_ACTION;
  7030. ieee80211_sta_process_chanswitch(link,
  7031. rx_status->mactime,
  7032. rx_status->device_timestamp,
  7033. elems, elems,
  7034. src);
  7035. }
  7036. kfree(elems);
  7037. break;
  7038. case WLAN_CATEGORY_PUBLIC:
  7039. case WLAN_CATEGORY_PROTECTED_DUAL_OF_ACTION:
  7040. ies_len = skb->len -
  7041. offsetof(struct ieee80211_mgmt,
  7042. u.action.u.ext_chan_switch.variable);
  7043. if (ies_len < 0)
  7044. break;
  7045. /*
  7046. * extended CSA IE can't be overridden, no need for
  7047. * BSSID
  7048. */
  7049. elems = ieee802_11_parse_elems(mgmt->u.action.u.ext_chan_switch.variable,
  7050. ies_len,
  7051. IEEE80211_FTYPE_MGMT |
  7052. IEEE80211_STYPE_ACTION,
  7053. NULL);
  7054. if (elems && !elems->parse_error) {
  7055. enum ieee80211_csa_source src;
  7056. if (mgmt->u.action.category ==
  7057. WLAN_CATEGORY_PROTECTED_DUAL_OF_ACTION)
  7058. src = IEEE80211_CSA_SOURCE_PROT_ACTION;
  7059. else
  7060. src = IEEE80211_CSA_SOURCE_UNPROT_ACTION;
  7061. /* for the handling code pretend it was an IE */
  7062. elems->ext_chansw_ie =
  7063. &mgmt->u.action.u.ext_chan_switch.data;
  7064. ieee80211_sta_process_chanswitch(link,
  7065. rx_status->mactime,
  7066. rx_status->device_timestamp,
  7067. elems, elems,
  7068. src);
  7069. }
  7070. kfree(elems);
  7071. break;
  7072. }
  7073. break;
  7074. }
  7075. }
  7076. static void ieee80211_sta_timer(struct timer_list *t)
  7077. {
  7078. struct ieee80211_sub_if_data *sdata =
  7079. timer_container_of(sdata, t, u.mgd.timer);
  7080. wiphy_work_queue(sdata->local->hw.wiphy, &sdata->work);
  7081. }
  7082. void ieee80211_sta_connection_lost(struct ieee80211_sub_if_data *sdata,
  7083. u8 reason, bool tx)
  7084. {
  7085. u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
  7086. ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH, reason,
  7087. tx, frame_buf);
  7088. ieee80211_report_disconnect(sdata, frame_buf, sizeof(frame_buf), true,
  7089. reason, false);
  7090. }
  7091. static int ieee80211_auth(struct ieee80211_sub_if_data *sdata)
  7092. {
  7093. struct ieee80211_local *local = sdata->local;
  7094. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  7095. struct ieee80211_mgd_auth_data *auth_data = ifmgd->auth_data;
  7096. u32 tx_flags = 0;
  7097. u16 trans = 1;
  7098. u16 status = 0;
  7099. struct ieee80211_prep_tx_info info = {
  7100. .subtype = IEEE80211_STYPE_AUTH,
  7101. };
  7102. lockdep_assert_wiphy(sdata->local->hw.wiphy);
  7103. if (WARN_ON_ONCE(!auth_data))
  7104. return -EINVAL;
  7105. if (auth_data->algorithm == WLAN_AUTH_EPPKE &&
  7106. ieee80211_vif_is_mld(&sdata->vif) &&
  7107. !cfg80211_find_ext_elem(WLAN_EID_EXT_EHT_MULTI_LINK,
  7108. auth_data->data, auth_data->data_len))
  7109. return -EINVAL;
  7110. auth_data->tries++;
  7111. if (auth_data->tries > IEEE80211_AUTH_MAX_TRIES) {
  7112. sdata_info(sdata, "authentication with %pM timed out\n",
  7113. auth_data->ap_addr);
  7114. /*
  7115. * Most likely AP is not in the range so remove the
  7116. * bss struct for that AP.
  7117. */
  7118. cfg80211_unlink_bss(local->hw.wiphy, auth_data->bss);
  7119. return -ETIMEDOUT;
  7120. }
  7121. if (auth_data->algorithm == WLAN_AUTH_SAE)
  7122. info.duration = jiffies_to_msecs(IEEE80211_AUTH_TIMEOUT_SAE);
  7123. info.link_id = auth_data->link_id;
  7124. drv_mgd_prepare_tx(local, sdata, &info);
  7125. sdata_info(sdata, "send auth to %pM (try %d/%d)\n",
  7126. auth_data->ap_addr, auth_data->tries,
  7127. IEEE80211_AUTH_MAX_TRIES);
  7128. auth_data->expected_transaction = 2;
  7129. if (auth_data->algorithm == WLAN_AUTH_SAE) {
  7130. trans = auth_data->trans;
  7131. status = auth_data->status;
  7132. auth_data->expected_transaction = trans;
  7133. } else if (auth_data->algorithm == WLAN_AUTH_EPPKE) {
  7134. trans = auth_data->trans;
  7135. status = auth_data->status;
  7136. }
  7137. if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
  7138. tx_flags = IEEE80211_TX_CTL_REQ_TX_STATUS |
  7139. IEEE80211_TX_INTFL_MLME_CONN_TX;
  7140. ieee80211_send_auth(sdata, trans, auth_data->algorithm, status,
  7141. auth_data->data, auth_data->data_len,
  7142. auth_data->ap_addr, auth_data->ap_addr,
  7143. NULL, 0, 0, tx_flags);
  7144. if (tx_flags == 0) {
  7145. if (auth_data->algorithm == WLAN_AUTH_SAE)
  7146. auth_data->timeout = jiffies +
  7147. IEEE80211_AUTH_TIMEOUT_SAE;
  7148. else
  7149. auth_data->timeout = jiffies + IEEE80211_AUTH_TIMEOUT;
  7150. } else {
  7151. auth_data->timeout =
  7152. round_jiffies_up(jiffies + IEEE80211_AUTH_TIMEOUT_LONG);
  7153. }
  7154. auth_data->timeout_started = true;
  7155. run_again(sdata, auth_data->timeout);
  7156. return 0;
  7157. }
  7158. static int ieee80211_do_assoc(struct ieee80211_sub_if_data *sdata)
  7159. {
  7160. struct ieee80211_mgd_assoc_data *assoc_data = sdata->u.mgd.assoc_data;
  7161. struct ieee80211_local *local = sdata->local;
  7162. int ret;
  7163. lockdep_assert_wiphy(sdata->local->hw.wiphy);
  7164. assoc_data->tries++;
  7165. assoc_data->comeback = false;
  7166. if (assoc_data->tries > IEEE80211_ASSOC_MAX_TRIES) {
  7167. sdata_info(sdata, "association with %pM timed out\n",
  7168. assoc_data->ap_addr);
  7169. /*
  7170. * Most likely AP is not in the range so remove the
  7171. * bss struct for that AP.
  7172. */
  7173. cfg80211_unlink_bss(local->hw.wiphy,
  7174. assoc_data->link[assoc_data->assoc_link_id].bss);
  7175. return -ETIMEDOUT;
  7176. }
  7177. sdata_info(sdata, "associate with %pM (try %d/%d)\n",
  7178. assoc_data->ap_addr, assoc_data->tries,
  7179. IEEE80211_ASSOC_MAX_TRIES);
  7180. ret = ieee80211_send_assoc(sdata);
  7181. if (ret)
  7182. return ret;
  7183. if (!ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) {
  7184. assoc_data->timeout = jiffies + IEEE80211_ASSOC_TIMEOUT;
  7185. assoc_data->timeout_started = true;
  7186. run_again(sdata, assoc_data->timeout);
  7187. } else {
  7188. assoc_data->timeout =
  7189. round_jiffies_up(jiffies +
  7190. IEEE80211_ASSOC_TIMEOUT_LONG);
  7191. assoc_data->timeout_started = true;
  7192. run_again(sdata, assoc_data->timeout);
  7193. }
  7194. return 0;
  7195. }
  7196. void ieee80211_mgd_conn_tx_status(struct ieee80211_sub_if_data *sdata,
  7197. __le16 fc, bool acked)
  7198. {
  7199. struct ieee80211_local *local = sdata->local;
  7200. sdata->u.mgd.status_fc = fc;
  7201. sdata->u.mgd.status_acked = acked;
  7202. sdata->u.mgd.status_received = true;
  7203. wiphy_work_queue(local->hw.wiphy, &sdata->work);
  7204. }
  7205. void ieee80211_sta_work(struct ieee80211_sub_if_data *sdata)
  7206. {
  7207. struct ieee80211_local *local = sdata->local;
  7208. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  7209. lockdep_assert_wiphy(sdata->local->hw.wiphy);
  7210. if (ifmgd->status_received) {
  7211. __le16 fc = ifmgd->status_fc;
  7212. bool status_acked = ifmgd->status_acked;
  7213. ifmgd->status_received = false;
  7214. if (ifmgd->auth_data && ieee80211_is_auth(fc)) {
  7215. if (status_acked) {
  7216. if (ifmgd->auth_data->algorithm ==
  7217. WLAN_AUTH_SAE)
  7218. ifmgd->auth_data->timeout =
  7219. jiffies +
  7220. IEEE80211_AUTH_TIMEOUT_SAE;
  7221. else
  7222. ifmgd->auth_data->timeout =
  7223. jiffies +
  7224. IEEE80211_AUTH_TIMEOUT_SHORT;
  7225. run_again(sdata, ifmgd->auth_data->timeout);
  7226. } else {
  7227. ifmgd->auth_data->timeout = jiffies - 1;
  7228. }
  7229. ifmgd->auth_data->timeout_started = true;
  7230. } else if (ifmgd->assoc_data &&
  7231. !ifmgd->assoc_data->comeback &&
  7232. (ieee80211_is_assoc_req(fc) ||
  7233. ieee80211_is_reassoc_req(fc))) {
  7234. /*
  7235. * Update association timeout based on the TX status
  7236. * for the (Re)Association Request frame. Skip this if
  7237. * we have already processed a (Re)Association Response
  7238. * frame that indicated need for association comeback
  7239. * at a specific time in the future. This could happen
  7240. * if the TX status information is delayed enough for
  7241. * the response to be received and processed first.
  7242. */
  7243. if (status_acked) {
  7244. ifmgd->assoc_data->timeout =
  7245. jiffies + IEEE80211_ASSOC_TIMEOUT_SHORT;
  7246. run_again(sdata, ifmgd->assoc_data->timeout);
  7247. } else {
  7248. ifmgd->assoc_data->timeout = jiffies - 1;
  7249. }
  7250. ifmgd->assoc_data->timeout_started = true;
  7251. }
  7252. }
  7253. if (ifmgd->auth_data && ifmgd->auth_data->timeout_started &&
  7254. time_after(jiffies, ifmgd->auth_data->timeout)) {
  7255. if (ifmgd->auth_data->done || ifmgd->auth_data->waiting) {
  7256. /*
  7257. * ok ... we waited for assoc or continuation but
  7258. * userspace didn't do it, so kill the auth data
  7259. */
  7260. ieee80211_destroy_auth_data(sdata, false);
  7261. } else if (ieee80211_auth(sdata)) {
  7262. u8 ap_addr[ETH_ALEN];
  7263. struct ieee80211_event event = {
  7264. .type = MLME_EVENT,
  7265. .u.mlme.data = AUTH_EVENT,
  7266. .u.mlme.status = MLME_TIMEOUT,
  7267. };
  7268. memcpy(ap_addr, ifmgd->auth_data->ap_addr, ETH_ALEN);
  7269. ieee80211_destroy_auth_data(sdata, false);
  7270. cfg80211_auth_timeout(sdata->dev, ap_addr);
  7271. drv_event_callback(sdata->local, sdata, &event);
  7272. }
  7273. } else if (ifmgd->auth_data && ifmgd->auth_data->timeout_started)
  7274. run_again(sdata, ifmgd->auth_data->timeout);
  7275. if (ifmgd->assoc_data && ifmgd->assoc_data->timeout_started &&
  7276. time_after(jiffies, ifmgd->assoc_data->timeout)) {
  7277. if ((ifmgd->assoc_data->need_beacon &&
  7278. !sdata->deflink.u.mgd.have_beacon) ||
  7279. ieee80211_do_assoc(sdata)) {
  7280. struct ieee80211_event event = {
  7281. .type = MLME_EVENT,
  7282. .u.mlme.data = ASSOC_EVENT,
  7283. .u.mlme.status = MLME_TIMEOUT,
  7284. };
  7285. ieee80211_destroy_assoc_data(sdata, ASSOC_TIMEOUT);
  7286. drv_event_callback(sdata->local, sdata, &event);
  7287. }
  7288. } else if (ifmgd->assoc_data && ifmgd->assoc_data->timeout_started)
  7289. run_again(sdata, ifmgd->assoc_data->timeout);
  7290. if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL &&
  7291. ifmgd->associated) {
  7292. u8 *bssid = sdata->deflink.u.mgd.bssid;
  7293. int max_tries;
  7294. if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
  7295. max_tries = max_nullfunc_tries;
  7296. else
  7297. max_tries = max_probe_tries;
  7298. /* ACK received for nullfunc probing frame */
  7299. if (!ifmgd->probe_send_count)
  7300. ieee80211_reset_ap_probe(sdata);
  7301. else if (ifmgd->nullfunc_failed) {
  7302. if (ifmgd->probe_send_count < max_tries) {
  7303. mlme_dbg(sdata,
  7304. "No ack for nullfunc frame to AP %pM, try %d/%i\n",
  7305. bssid, ifmgd->probe_send_count,
  7306. max_tries);
  7307. ieee80211_mgd_probe_ap_send(sdata);
  7308. } else {
  7309. mlme_dbg(sdata,
  7310. "No ack for nullfunc frame to AP %pM, disconnecting.\n",
  7311. bssid);
  7312. ieee80211_sta_connection_lost(sdata,
  7313. WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY,
  7314. false);
  7315. }
  7316. } else if (time_is_after_jiffies(ifmgd->probe_timeout))
  7317. run_again(sdata, ifmgd->probe_timeout);
  7318. else if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) {
  7319. mlme_dbg(sdata,
  7320. "Failed to send nullfunc to AP %pM after %dms, disconnecting\n",
  7321. bssid, probe_wait_ms);
  7322. ieee80211_sta_connection_lost(sdata,
  7323. WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY, false);
  7324. } else if (ifmgd->probe_send_count < max_tries) {
  7325. mlme_dbg(sdata,
  7326. "No probe response from AP %pM after %dms, try %d/%i\n",
  7327. bssid, probe_wait_ms,
  7328. ifmgd->probe_send_count, max_tries);
  7329. ieee80211_mgd_probe_ap_send(sdata);
  7330. } else {
  7331. /*
  7332. * We actually lost the connection ... or did we?
  7333. * Let's make sure!
  7334. */
  7335. mlme_dbg(sdata,
  7336. "No probe response from AP %pM after %dms, disconnecting.\n",
  7337. bssid, probe_wait_ms);
  7338. ieee80211_sta_connection_lost(sdata,
  7339. WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY, false);
  7340. }
  7341. }
  7342. }
  7343. static bool
  7344. ieee80211_is_csa_in_progress(struct ieee80211_sub_if_data *sdata)
  7345. {
  7346. /*
  7347. * In MLO, check the CSA flags 'active' and 'waiting_bcn' for all
  7348. * the links.
  7349. */
  7350. struct ieee80211_link_data *link;
  7351. guard(rcu)();
  7352. for_each_link_data_rcu(sdata, link) {
  7353. if (!(link->conf->csa_active &&
  7354. !link->u.mgd.csa.waiting_bcn))
  7355. return false;
  7356. }
  7357. return true;
  7358. }
  7359. static void ieee80211_sta_bcn_mon_timer(struct timer_list *t)
  7360. {
  7361. struct ieee80211_sub_if_data *sdata =
  7362. timer_container_of(sdata, t, u.mgd.bcn_mon_timer);
  7363. if (ieee80211_is_csa_in_progress(sdata))
  7364. return;
  7365. if (sdata->vif.driver_flags & IEEE80211_VIF_BEACON_FILTER)
  7366. return;
  7367. sdata->u.mgd.connection_loss = false;
  7368. wiphy_work_queue(sdata->local->hw.wiphy,
  7369. &sdata->u.mgd.beacon_connection_loss_work);
  7370. }
  7371. static unsigned long
  7372. ieee80211_latest_active_link_conn_timeout(struct ieee80211_sub_if_data *sdata)
  7373. {
  7374. unsigned long latest_timeout = jiffies;
  7375. unsigned int link_id;
  7376. struct sta_info *sta;
  7377. guard(rcu)();
  7378. sta = sta_info_get(sdata, sdata->vif.cfg.ap_addr);
  7379. if (!sta)
  7380. return 0;
  7381. for (link_id = 0; link_id < ARRAY_SIZE(sta->link);
  7382. link_id++) {
  7383. struct link_sta_info *link_sta;
  7384. unsigned long timeout;
  7385. link_sta = rcu_dereference(sta->link[link_id]);
  7386. if (!link_sta)
  7387. continue;
  7388. timeout = link_sta->status_stats.last_ack;
  7389. if (time_before(timeout, link_sta->rx_stats.last_rx))
  7390. timeout = link_sta->rx_stats.last_rx;
  7391. timeout += IEEE80211_CONNECTION_IDLE_TIME;
  7392. /*
  7393. * latest_timeout holds the timeout of the link
  7394. * that will expire last among all links in an
  7395. * non-AP MLD STA. This ensures that the connection
  7396. * monitor timer is only reset if at least one link
  7397. * is still active, and it is scheduled to fire at
  7398. * the latest possible timeout.
  7399. */
  7400. if (time_after(timeout, latest_timeout))
  7401. latest_timeout = timeout;
  7402. }
  7403. return latest_timeout;
  7404. }
  7405. static void ieee80211_sta_conn_mon_timer(struct timer_list *t)
  7406. {
  7407. struct ieee80211_sub_if_data *sdata =
  7408. timer_container_of(sdata, t, u.mgd.conn_mon_timer);
  7409. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  7410. struct ieee80211_local *local = sdata->local;
  7411. unsigned long latest_timeout;
  7412. if (ieee80211_is_csa_in_progress(sdata))
  7413. return;
  7414. latest_timeout = ieee80211_latest_active_link_conn_timeout(sdata);
  7415. /*
  7416. * If latest timeout is after now, then update timer to fire at
  7417. * the later date, but do not actually probe at this time.
  7418. */
  7419. if (time_is_after_jiffies(latest_timeout)) {
  7420. mod_timer(&ifmgd->conn_mon_timer,
  7421. round_jiffies_up(latest_timeout));
  7422. return;
  7423. }
  7424. wiphy_work_queue(local->hw.wiphy, &sdata->u.mgd.monitor_work);
  7425. }
  7426. static void ieee80211_sta_monitor_work(struct wiphy *wiphy,
  7427. struct wiphy_work *work)
  7428. {
  7429. struct ieee80211_sub_if_data *sdata =
  7430. container_of(work, struct ieee80211_sub_if_data,
  7431. u.mgd.monitor_work);
  7432. ieee80211_mgd_probe_ap(sdata, false);
  7433. }
  7434. static void ieee80211_restart_sta_timer(struct ieee80211_sub_if_data *sdata)
  7435. {
  7436. if (sdata->vif.type == NL80211_IFTYPE_STATION) {
  7437. __ieee80211_stop_poll(sdata);
  7438. /* let's probe the connection once */
  7439. if (!ieee80211_hw_check(&sdata->local->hw, CONNECTION_MONITOR))
  7440. wiphy_work_queue(sdata->local->hw.wiphy,
  7441. &sdata->u.mgd.monitor_work);
  7442. }
  7443. }
  7444. #ifdef CONFIG_PM
  7445. void ieee80211_mgd_quiesce(struct ieee80211_sub_if_data *sdata)
  7446. {
  7447. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  7448. u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
  7449. lockdep_assert_wiphy(sdata->local->hw.wiphy);
  7450. if (ifmgd->auth_data || ifmgd->assoc_data) {
  7451. const u8 *ap_addr = ifmgd->auth_data ?
  7452. ifmgd->auth_data->ap_addr :
  7453. ifmgd->assoc_data->ap_addr;
  7454. /*
  7455. * If we are trying to authenticate / associate while suspending,
  7456. * cfg80211 won't know and won't actually abort those attempts,
  7457. * thus we need to do that ourselves.
  7458. */
  7459. ieee80211_send_deauth_disassoc(sdata, ap_addr, ap_addr,
  7460. IEEE80211_STYPE_DEAUTH,
  7461. WLAN_REASON_DEAUTH_LEAVING,
  7462. false, frame_buf);
  7463. if (ifmgd->assoc_data)
  7464. ieee80211_destroy_assoc_data(sdata, ASSOC_ABANDON);
  7465. if (ifmgd->auth_data)
  7466. ieee80211_destroy_auth_data(sdata, false);
  7467. cfg80211_tx_mlme_mgmt(sdata->dev, frame_buf,
  7468. IEEE80211_DEAUTH_FRAME_LEN,
  7469. false);
  7470. }
  7471. /* This is a bit of a hack - we should find a better and more generic
  7472. * solution to this. Normally when suspending, cfg80211 will in fact
  7473. * deauthenticate. However, it doesn't (and cannot) stop an ongoing
  7474. * auth (not so important) or assoc (this is the problem) process.
  7475. *
  7476. * As a consequence, it can happen that we are in the process of both
  7477. * associating and suspending, and receive an association response
  7478. * after cfg80211 has checked if it needs to disconnect, but before
  7479. * we actually set the flag to drop incoming frames. This will then
  7480. * cause the workqueue flush to process the association response in
  7481. * the suspend, resulting in a successful association just before it
  7482. * tries to remove the interface from the driver, which now though
  7483. * has a channel context assigned ... this results in issues.
  7484. *
  7485. * To work around this (for now) simply deauth here again if we're
  7486. * now connected.
  7487. */
  7488. if (ifmgd->associated && !sdata->local->wowlan) {
  7489. u8 bssid[ETH_ALEN];
  7490. struct cfg80211_deauth_request req = {
  7491. .reason_code = WLAN_REASON_DEAUTH_LEAVING,
  7492. .bssid = bssid,
  7493. };
  7494. memcpy(bssid, sdata->vif.cfg.ap_addr, ETH_ALEN);
  7495. ieee80211_mgd_deauth(sdata, &req);
  7496. }
  7497. }
  7498. #endif
  7499. void ieee80211_sta_restart(struct ieee80211_sub_if_data *sdata)
  7500. {
  7501. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  7502. lockdep_assert_wiphy(sdata->local->hw.wiphy);
  7503. if (!ifmgd->associated)
  7504. return;
  7505. if (sdata->flags & IEEE80211_SDATA_DISCONNECT_RESUME) {
  7506. sdata->flags &= ~IEEE80211_SDATA_DISCONNECT_RESUME;
  7507. mlme_dbg(sdata, "driver requested disconnect after resume\n");
  7508. ieee80211_sta_connection_lost(sdata,
  7509. WLAN_REASON_UNSPECIFIED,
  7510. true);
  7511. return;
  7512. }
  7513. if (sdata->flags & IEEE80211_SDATA_DISCONNECT_HW_RESTART) {
  7514. sdata->flags &= ~IEEE80211_SDATA_DISCONNECT_HW_RESTART;
  7515. mlme_dbg(sdata, "driver requested disconnect after hardware restart\n");
  7516. ieee80211_sta_connection_lost(sdata,
  7517. WLAN_REASON_UNSPECIFIED,
  7518. true);
  7519. return;
  7520. }
  7521. }
  7522. static void ieee80211_request_smps_mgd_work(struct wiphy *wiphy,
  7523. struct wiphy_work *work)
  7524. {
  7525. struct ieee80211_link_data *link =
  7526. container_of(work, struct ieee80211_link_data,
  7527. u.mgd.request_smps_work);
  7528. __ieee80211_request_smps_mgd(link->sdata, link,
  7529. link->u.mgd.driver_smps_mode);
  7530. }
  7531. static void ieee80211_ml_sta_reconf_timeout(struct wiphy *wiphy,
  7532. struct wiphy_work *work)
  7533. {
  7534. struct ieee80211_sub_if_data *sdata =
  7535. container_of(work, struct ieee80211_sub_if_data,
  7536. u.mgd.reconf.wk.work);
  7537. if (!sdata->u.mgd.reconf.added_links &&
  7538. !sdata->u.mgd.reconf.removed_links)
  7539. return;
  7540. sdata_info(sdata,
  7541. "mlo: reconf: timeout: added=0x%x, removed=0x%x\n",
  7542. sdata->u.mgd.reconf.added_links,
  7543. sdata->u.mgd.reconf.removed_links);
  7544. __ieee80211_disconnect(sdata);
  7545. }
  7546. /* interface setup */
  7547. void ieee80211_sta_setup_sdata(struct ieee80211_sub_if_data *sdata)
  7548. {
  7549. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  7550. wiphy_work_init(&ifmgd->monitor_work, ieee80211_sta_monitor_work);
  7551. wiphy_work_init(&ifmgd->beacon_connection_loss_work,
  7552. ieee80211_beacon_connection_loss_work);
  7553. wiphy_work_init(&ifmgd->csa_connection_drop_work,
  7554. ieee80211_csa_connection_drop_work);
  7555. wiphy_delayed_work_init(&ifmgd->tdls_peer_del_work,
  7556. ieee80211_tdls_peer_del_work);
  7557. wiphy_hrtimer_work_init(&ifmgd->ml_reconf_work,
  7558. ieee80211_ml_reconf_work);
  7559. wiphy_delayed_work_init(&ifmgd->reconf.wk,
  7560. ieee80211_ml_sta_reconf_timeout);
  7561. timer_setup(&ifmgd->timer, ieee80211_sta_timer, 0);
  7562. timer_setup(&ifmgd->bcn_mon_timer, ieee80211_sta_bcn_mon_timer, 0);
  7563. timer_setup(&ifmgd->conn_mon_timer, ieee80211_sta_conn_mon_timer, 0);
  7564. wiphy_delayed_work_init(&ifmgd->tx_tspec_wk,
  7565. ieee80211_sta_handle_tspec_ac_params_wk);
  7566. wiphy_hrtimer_work_init(&ifmgd->ttlm_work,
  7567. ieee80211_tid_to_link_map_work);
  7568. wiphy_delayed_work_init(&ifmgd->neg_ttlm_timeout_work,
  7569. ieee80211_neg_ttlm_timeout_work);
  7570. wiphy_work_init(&ifmgd->teardown_ttlm_work,
  7571. ieee80211_teardown_ttlm_work);
  7572. ifmgd->flags = 0;
  7573. ifmgd->powersave = sdata->wdev.ps;
  7574. ifmgd->uapsd_queues = sdata->local->hw.uapsd_queues;
  7575. ifmgd->uapsd_max_sp_len = sdata->local->hw.uapsd_max_sp_len;
  7576. /* Setup TDLS data */
  7577. spin_lock_init(&ifmgd->teardown_lock);
  7578. ifmgd->teardown_skb = NULL;
  7579. ifmgd->orig_teardown_skb = NULL;
  7580. ifmgd->mcast_seq_last = IEEE80211_SN_MODULO;
  7581. }
  7582. static void ieee80211_recalc_smps_work(struct wiphy *wiphy,
  7583. struct wiphy_work *work)
  7584. {
  7585. struct ieee80211_link_data *link =
  7586. container_of(work, struct ieee80211_link_data,
  7587. u.mgd.recalc_smps);
  7588. ieee80211_recalc_smps(link->sdata, link);
  7589. }
  7590. void ieee80211_mgd_setup_link(struct ieee80211_link_data *link)
  7591. {
  7592. struct ieee80211_sub_if_data *sdata = link->sdata;
  7593. struct ieee80211_local *local = sdata->local;
  7594. unsigned int link_id = link->link_id;
  7595. link->u.mgd.p2p_noa_index = -1;
  7596. link->conf->bssid = link->u.mgd.bssid;
  7597. link->smps_mode = IEEE80211_SMPS_OFF;
  7598. wiphy_work_init(&link->u.mgd.request_smps_work,
  7599. ieee80211_request_smps_mgd_work);
  7600. wiphy_work_init(&link->u.mgd.recalc_smps,
  7601. ieee80211_recalc_smps_work);
  7602. if (local->hw.wiphy->features & NL80211_FEATURE_DYNAMIC_SMPS)
  7603. link->u.mgd.req_smps = IEEE80211_SMPS_AUTOMATIC;
  7604. else
  7605. link->u.mgd.req_smps = IEEE80211_SMPS_OFF;
  7606. wiphy_hrtimer_work_init(&link->u.mgd.csa.switch_work,
  7607. ieee80211_csa_switch_work);
  7608. ieee80211_clear_tpe(&link->conf->tpe);
  7609. if (sdata->u.mgd.assoc_data)
  7610. ether_addr_copy(link->conf->addr,
  7611. sdata->u.mgd.assoc_data->link[link_id].addr);
  7612. else if (sdata->u.mgd.reconf.add_links_data)
  7613. ether_addr_copy(link->conf->addr,
  7614. sdata->u.mgd.reconf.add_links_data->link[link_id].addr);
  7615. else if (!is_valid_ether_addr(link->conf->addr))
  7616. eth_random_addr(link->conf->addr);
  7617. }
  7618. /* scan finished notification */
  7619. void ieee80211_mlme_notify_scan_completed(struct ieee80211_local *local)
  7620. {
  7621. struct ieee80211_sub_if_data *sdata;
  7622. /* Restart STA timers */
  7623. rcu_read_lock();
  7624. list_for_each_entry_rcu(sdata, &local->interfaces, list) {
  7625. if (ieee80211_sdata_running(sdata))
  7626. ieee80211_restart_sta_timer(sdata);
  7627. }
  7628. rcu_read_unlock();
  7629. }
  7630. static int ieee80211_prep_connection(struct ieee80211_sub_if_data *sdata,
  7631. struct cfg80211_bss *cbss, s8 link_id,
  7632. const u8 *ap_mld_addr, bool assoc,
  7633. struct ieee80211_conn_settings *conn,
  7634. bool override,
  7635. unsigned long *userspace_selectors)
  7636. {
  7637. struct ieee80211_local *local = sdata->local;
  7638. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  7639. struct ieee80211_bss *bss = (void *)cbss->priv;
  7640. struct sta_info *new_sta = NULL;
  7641. struct ieee80211_link_data *link;
  7642. bool have_sta = false;
  7643. bool mlo;
  7644. int err;
  7645. u16 new_links;
  7646. if (link_id >= 0) {
  7647. mlo = true;
  7648. if (WARN_ON(!ap_mld_addr))
  7649. return -EINVAL;
  7650. new_links = BIT(link_id);
  7651. } else {
  7652. if (WARN_ON(ap_mld_addr))
  7653. return -EINVAL;
  7654. ap_mld_addr = cbss->bssid;
  7655. new_links = 0;
  7656. link_id = 0;
  7657. mlo = false;
  7658. }
  7659. if (assoc) {
  7660. rcu_read_lock();
  7661. have_sta = sta_info_get(sdata, ap_mld_addr);
  7662. rcu_read_unlock();
  7663. }
  7664. if (mlo && !have_sta &&
  7665. WARN_ON(sdata->vif.valid_links || sdata->vif.active_links))
  7666. return -EINVAL;
  7667. err = ieee80211_vif_set_links(sdata, new_links, 0);
  7668. if (err)
  7669. return err;
  7670. link = sdata_dereference(sdata->link[link_id], sdata);
  7671. if (WARN_ON(!link)) {
  7672. err = -ENOLINK;
  7673. goto out_err;
  7674. }
  7675. if (WARN_ON(!ifmgd->auth_data && !ifmgd->assoc_data)) {
  7676. err = -EINVAL;
  7677. goto out_err;
  7678. }
  7679. /* If a reconfig is happening, bail out */
  7680. if (local->in_reconfig) {
  7681. err = -EBUSY;
  7682. goto out_err;
  7683. }
  7684. if (!have_sta) {
  7685. if (mlo)
  7686. new_sta = sta_info_alloc_with_link(sdata, ap_mld_addr,
  7687. link_id, cbss->bssid,
  7688. GFP_KERNEL);
  7689. else
  7690. new_sta = sta_info_alloc(sdata, ap_mld_addr, GFP_KERNEL);
  7691. if (!new_sta) {
  7692. err = -ENOMEM;
  7693. goto out_err;
  7694. }
  7695. if (ifmgd->auth_data &&
  7696. ifmgd->auth_data->algorithm == WLAN_AUTH_EPPKE)
  7697. new_sta->sta.epp_peer = true;
  7698. new_sta->sta.mlo = mlo;
  7699. }
  7700. /*
  7701. * Set up the information for the new channel before setting the
  7702. * new channel. We can't - completely race-free - change the basic
  7703. * rates bitmap and the channel (sband) that it refers to, but if
  7704. * we set it up before we at least avoid calling into the driver's
  7705. * bss_info_changed() method with invalid information (since we do
  7706. * call that from changing the channel - only for IDLE and perhaps
  7707. * some others, but ...).
  7708. *
  7709. * So to avoid that, just set up all the new information before the
  7710. * channel, but tell the driver to apply it only afterwards, since
  7711. * it might need the new channel for that.
  7712. */
  7713. if (new_sta) {
  7714. const struct cfg80211_bss_ies *ies;
  7715. struct link_sta_info *link_sta;
  7716. rcu_read_lock();
  7717. link_sta = rcu_dereference(new_sta->link[link_id]);
  7718. if (WARN_ON(!link_sta)) {
  7719. rcu_read_unlock();
  7720. sta_info_free(local, new_sta);
  7721. err = -EINVAL;
  7722. goto out_err;
  7723. }
  7724. err = ieee80211_mgd_setup_link_sta(link, new_sta,
  7725. link_sta, cbss);
  7726. if (err) {
  7727. rcu_read_unlock();
  7728. sta_info_free(local, new_sta);
  7729. goto out_err;
  7730. }
  7731. memcpy(link->u.mgd.bssid, cbss->bssid, ETH_ALEN);
  7732. /* set timing information */
  7733. link->conf->beacon_int = cbss->beacon_interval;
  7734. ies = rcu_dereference(cbss->beacon_ies);
  7735. if (ies) {
  7736. link->conf->sync_tsf = ies->tsf;
  7737. link->conf->sync_device_ts =
  7738. bss->device_ts_beacon;
  7739. ieee80211_get_dtim(ies,
  7740. &link->conf->sync_dtim_count,
  7741. NULL);
  7742. } else if (!ieee80211_hw_check(&sdata->local->hw,
  7743. TIMING_BEACON_ONLY)) {
  7744. ies = rcu_dereference(cbss->proberesp_ies);
  7745. /* must be non-NULL since beacon IEs were NULL */
  7746. link->conf->sync_tsf = ies->tsf;
  7747. link->conf->sync_device_ts =
  7748. bss->device_ts_presp;
  7749. link->conf->sync_dtim_count = 0;
  7750. } else {
  7751. link->conf->sync_tsf = 0;
  7752. link->conf->sync_device_ts = 0;
  7753. link->conf->sync_dtim_count = 0;
  7754. }
  7755. rcu_read_unlock();
  7756. }
  7757. if (new_sta || override) {
  7758. /*
  7759. * Only set this if we're also going to calculate the AP
  7760. * settings etc., otherwise this was set before in a
  7761. * previous call. Note override is set to %true in assoc
  7762. * if the settings were changed.
  7763. */
  7764. link->u.mgd.conn = *conn;
  7765. err = ieee80211_prep_channel(sdata, link, link->link_id, cbss,
  7766. mlo, &link->u.mgd.conn,
  7767. userspace_selectors);
  7768. if (err) {
  7769. if (new_sta)
  7770. sta_info_free(local, new_sta);
  7771. goto out_err;
  7772. }
  7773. /* pass out for use in assoc */
  7774. *conn = link->u.mgd.conn;
  7775. }
  7776. if (new_sta) {
  7777. /*
  7778. * tell driver about BSSID, basic rates and timing
  7779. * this was set up above, before setting the channel
  7780. */
  7781. ieee80211_link_info_change_notify(sdata, link,
  7782. BSS_CHANGED_BSSID |
  7783. BSS_CHANGED_BASIC_RATES |
  7784. BSS_CHANGED_BEACON_INT);
  7785. if (assoc)
  7786. sta_info_pre_move_state(new_sta, IEEE80211_STA_AUTH);
  7787. err = sta_info_insert(new_sta);
  7788. new_sta = NULL;
  7789. if (err) {
  7790. sdata_info(sdata,
  7791. "failed to insert STA entry for the AP (error %d)\n",
  7792. err);
  7793. goto out_release_chan;
  7794. }
  7795. } else
  7796. WARN_ON_ONCE(!ether_addr_equal(link->u.mgd.bssid, cbss->bssid));
  7797. /* Cancel scan to ensure that nothing interferes with connection */
  7798. if (local->scanning)
  7799. ieee80211_scan_cancel(local);
  7800. return 0;
  7801. out_release_chan:
  7802. ieee80211_link_release_channel(link);
  7803. out_err:
  7804. ieee80211_vif_set_links(sdata, 0, 0);
  7805. return err;
  7806. }
  7807. static bool ieee80211_mgd_csa_present(struct ieee80211_sub_if_data *sdata,
  7808. const struct cfg80211_bss_ies *ies,
  7809. u8 cur_channel, bool ignore_ecsa)
  7810. {
  7811. const struct element *csa_elem, *ecsa_elem;
  7812. struct ieee80211_channel_sw_ie *csa = NULL;
  7813. struct ieee80211_ext_chansw_ie *ecsa = NULL;
  7814. if (!ies)
  7815. return false;
  7816. csa_elem = cfg80211_find_elem(WLAN_EID_CHANNEL_SWITCH,
  7817. ies->data, ies->len);
  7818. if (csa_elem && csa_elem->datalen == sizeof(*csa))
  7819. csa = (void *)csa_elem->data;
  7820. ecsa_elem = cfg80211_find_elem(WLAN_EID_EXT_CHANSWITCH_ANN,
  7821. ies->data, ies->len);
  7822. if (ecsa_elem && ecsa_elem->datalen == sizeof(*ecsa))
  7823. ecsa = (void *)ecsa_elem->data;
  7824. if (csa && csa->count == 0)
  7825. csa = NULL;
  7826. if (csa && !csa->mode && csa->new_ch_num == cur_channel)
  7827. csa = NULL;
  7828. if (ecsa && ecsa->count == 0)
  7829. ecsa = NULL;
  7830. if (ecsa && !ecsa->mode && ecsa->new_ch_num == cur_channel)
  7831. ecsa = NULL;
  7832. if (ignore_ecsa && ecsa) {
  7833. sdata_info(sdata,
  7834. "Ignoring ECSA in probe response - was considered stuck!\n");
  7835. return csa;
  7836. }
  7837. return csa || ecsa;
  7838. }
  7839. static bool ieee80211_mgd_csa_in_process(struct ieee80211_sub_if_data *sdata,
  7840. struct cfg80211_bss *bss)
  7841. {
  7842. u8 cur_channel;
  7843. bool ret;
  7844. cur_channel = ieee80211_frequency_to_channel(bss->channel->center_freq);
  7845. rcu_read_lock();
  7846. if (ieee80211_mgd_csa_present(sdata,
  7847. rcu_dereference(bss->beacon_ies),
  7848. cur_channel, false)) {
  7849. ret = true;
  7850. goto out;
  7851. }
  7852. if (ieee80211_mgd_csa_present(sdata,
  7853. rcu_dereference(bss->proberesp_ies),
  7854. cur_channel, bss->proberesp_ecsa_stuck)) {
  7855. ret = true;
  7856. goto out;
  7857. }
  7858. ret = false;
  7859. out:
  7860. rcu_read_unlock();
  7861. return ret;
  7862. }
  7863. static void ieee80211_parse_cfg_selectors(unsigned long *userspace_selectors,
  7864. const u8 *supported_selectors,
  7865. u8 supported_selectors_len)
  7866. {
  7867. if (supported_selectors) {
  7868. for (int i = 0; i < supported_selectors_len; i++) {
  7869. set_bit(supported_selectors[i],
  7870. userspace_selectors);
  7871. }
  7872. } else {
  7873. /* Assume SAE_H2E support for backward compatibility. */
  7874. set_bit(BSS_MEMBERSHIP_SELECTOR_SAE_H2E,
  7875. userspace_selectors);
  7876. }
  7877. }
  7878. /* config hooks */
  7879. int ieee80211_mgd_auth(struct ieee80211_sub_if_data *sdata,
  7880. struct cfg80211_auth_request *req)
  7881. {
  7882. struct ieee80211_local *local = sdata->local;
  7883. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  7884. struct ieee80211_mgd_auth_data *auth_data;
  7885. struct ieee80211_conn_settings conn;
  7886. struct ieee80211_link_data *link;
  7887. struct ieee80211_supported_band *sband;
  7888. struct ieee80211_bss *bss;
  7889. u16 auth_alg;
  7890. int err;
  7891. bool cont_auth, wmm_used;
  7892. lockdep_assert_wiphy(sdata->local->hw.wiphy);
  7893. /* prepare auth data structure */
  7894. switch (req->auth_type) {
  7895. case NL80211_AUTHTYPE_OPEN_SYSTEM:
  7896. auth_alg = WLAN_AUTH_OPEN;
  7897. break;
  7898. case NL80211_AUTHTYPE_SHARED_KEY:
  7899. if (fips_enabled)
  7900. return -EOPNOTSUPP;
  7901. auth_alg = WLAN_AUTH_SHARED_KEY;
  7902. break;
  7903. case NL80211_AUTHTYPE_FT:
  7904. auth_alg = WLAN_AUTH_FT;
  7905. break;
  7906. case NL80211_AUTHTYPE_NETWORK_EAP:
  7907. auth_alg = WLAN_AUTH_LEAP;
  7908. break;
  7909. case NL80211_AUTHTYPE_SAE:
  7910. auth_alg = WLAN_AUTH_SAE;
  7911. break;
  7912. case NL80211_AUTHTYPE_FILS_SK:
  7913. auth_alg = WLAN_AUTH_FILS_SK;
  7914. break;
  7915. case NL80211_AUTHTYPE_FILS_SK_PFS:
  7916. auth_alg = WLAN_AUTH_FILS_SK_PFS;
  7917. break;
  7918. case NL80211_AUTHTYPE_FILS_PK:
  7919. auth_alg = WLAN_AUTH_FILS_PK;
  7920. break;
  7921. case NL80211_AUTHTYPE_EPPKE:
  7922. auth_alg = WLAN_AUTH_EPPKE;
  7923. break;
  7924. default:
  7925. return -EOPNOTSUPP;
  7926. }
  7927. if (ifmgd->assoc_data)
  7928. return -EBUSY;
  7929. if (ieee80211_mgd_csa_in_process(sdata, req->bss)) {
  7930. sdata_info(sdata, "AP is in CSA process, reject auth\n");
  7931. return -EINVAL;
  7932. }
  7933. auth_data = kzalloc(sizeof(*auth_data) + req->auth_data_len +
  7934. req->ie_len, GFP_KERNEL);
  7935. if (!auth_data)
  7936. return -ENOMEM;
  7937. memcpy(auth_data->ap_addr,
  7938. req->ap_mld_addr ?: req->bss->bssid,
  7939. ETH_ALEN);
  7940. auth_data->bss = req->bss;
  7941. auth_data->link_id = req->link_id;
  7942. if (req->auth_data_len >= 4) {
  7943. if (req->auth_type == NL80211_AUTHTYPE_SAE ||
  7944. req->auth_type == NL80211_AUTHTYPE_EPPKE) {
  7945. __le16 *pos = (__le16 *) req->auth_data;
  7946. auth_data->trans = le16_to_cpu(pos[0]);
  7947. auth_data->status = le16_to_cpu(pos[1]);
  7948. }
  7949. memcpy(auth_data->data, req->auth_data + 4,
  7950. req->auth_data_len - 4);
  7951. auth_data->data_len += req->auth_data_len - 4;
  7952. }
  7953. /* Check if continuing authentication or trying to authenticate with the
  7954. * same BSS that we were in the process of authenticating with and avoid
  7955. * removal and re-addition of the STA entry in
  7956. * ieee80211_prep_connection().
  7957. */
  7958. cont_auth = ifmgd->auth_data && req->bss == ifmgd->auth_data->bss &&
  7959. ifmgd->auth_data->link_id == req->link_id;
  7960. if (req->ie && req->ie_len) {
  7961. memcpy(&auth_data->data[auth_data->data_len],
  7962. req->ie, req->ie_len);
  7963. auth_data->data_len += req->ie_len;
  7964. }
  7965. if (req->key && req->key_len) {
  7966. auth_data->key_len = req->key_len;
  7967. auth_data->key_idx = req->key_idx;
  7968. memcpy(auth_data->key, req->key, req->key_len);
  7969. }
  7970. ieee80211_parse_cfg_selectors(auth_data->userspace_selectors,
  7971. req->supported_selectors,
  7972. req->supported_selectors_len);
  7973. auth_data->algorithm = auth_alg;
  7974. /* try to authenticate/probe */
  7975. if (ifmgd->auth_data) {
  7976. if (cont_auth && req->auth_type == NL80211_AUTHTYPE_SAE) {
  7977. auth_data->peer_confirmed =
  7978. ifmgd->auth_data->peer_confirmed;
  7979. }
  7980. ieee80211_destroy_auth_data(sdata, cont_auth);
  7981. }
  7982. /* prep auth_data so we don't go into idle on disassoc */
  7983. ifmgd->auth_data = auth_data;
  7984. /* If this is continuation of an ongoing SAE authentication exchange
  7985. * (i.e., request to send SAE Confirm) and the peer has already
  7986. * confirmed, mark authentication completed since we are about to send
  7987. * out SAE Confirm.
  7988. */
  7989. if (cont_auth && req->auth_type == NL80211_AUTHTYPE_SAE &&
  7990. auth_data->peer_confirmed && auth_data->trans == 2)
  7991. ieee80211_mark_sta_auth(sdata);
  7992. if (cont_auth && req->auth_type == NL80211_AUTHTYPE_EPPKE &&
  7993. auth_data->trans == 3)
  7994. ieee80211_mark_sta_auth(sdata);
  7995. if (ifmgd->associated) {
  7996. u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
  7997. sdata_info(sdata,
  7998. "disconnect from AP %pM for new auth to %pM\n",
  7999. sdata->vif.cfg.ap_addr, auth_data->ap_addr);
  8000. ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
  8001. WLAN_REASON_UNSPECIFIED,
  8002. false, frame_buf);
  8003. ieee80211_report_disconnect(sdata, frame_buf,
  8004. sizeof(frame_buf), true,
  8005. WLAN_REASON_UNSPECIFIED,
  8006. false);
  8007. }
  8008. /* needed for transmitting the auth frame(s) properly */
  8009. memcpy(sdata->vif.cfg.ap_addr, auth_data->ap_addr, ETH_ALEN);
  8010. bss = (void *)req->bss->priv;
  8011. wmm_used = bss->wmm_used && (local->hw.queues >= IEEE80211_NUM_ACS);
  8012. sband = local->hw.wiphy->bands[req->bss->channel->band];
  8013. ieee80211_determine_our_sta_mode_auth(sdata, sband, req, wmm_used,
  8014. &conn);
  8015. err = ieee80211_prep_connection(sdata, req->bss, req->link_id,
  8016. req->ap_mld_addr, cont_auth,
  8017. &conn, false,
  8018. auth_data->userspace_selectors);
  8019. if (err)
  8020. goto err_clear;
  8021. if (req->link_id >= 0)
  8022. link = sdata_dereference(sdata->link[req->link_id], sdata);
  8023. else
  8024. link = &sdata->deflink;
  8025. if (WARN_ON(!link)) {
  8026. err = -ENOLINK;
  8027. goto err_clear;
  8028. }
  8029. sdata_info(sdata, "authenticate with %pM (local address=%pM)\n",
  8030. auth_data->ap_addr, link->conf->addr);
  8031. err = ieee80211_auth(sdata);
  8032. if (err) {
  8033. sta_info_destroy_addr(sdata, auth_data->ap_addr);
  8034. goto err_clear;
  8035. }
  8036. /* hold our own reference */
  8037. cfg80211_ref_bss(local->hw.wiphy, auth_data->bss);
  8038. return 0;
  8039. err_clear:
  8040. if (!ieee80211_vif_is_mld(&sdata->vif)) {
  8041. eth_zero_addr(sdata->deflink.u.mgd.bssid);
  8042. ieee80211_link_info_change_notify(sdata, &sdata->deflink,
  8043. BSS_CHANGED_BSSID);
  8044. ieee80211_link_release_channel(&sdata->deflink);
  8045. }
  8046. ifmgd->auth_data = NULL;
  8047. kfree(auth_data);
  8048. return err;
  8049. }
  8050. static void
  8051. ieee80211_setup_assoc_link(struct ieee80211_sub_if_data *sdata,
  8052. struct ieee80211_mgd_assoc_data *assoc_data,
  8053. struct cfg80211_assoc_request *req,
  8054. struct ieee80211_conn_settings *conn,
  8055. unsigned int link_id)
  8056. {
  8057. struct ieee80211_local *local = sdata->local;
  8058. const struct cfg80211_bss_ies *bss_ies;
  8059. struct ieee80211_supported_band *sband;
  8060. struct ieee80211_link_data *link;
  8061. struct cfg80211_bss *cbss;
  8062. struct ieee80211_bss *bss;
  8063. cbss = assoc_data->link[link_id].bss;
  8064. if (WARN_ON(!cbss))
  8065. return;
  8066. bss = (void *)cbss->priv;
  8067. sband = local->hw.wiphy->bands[cbss->channel->band];
  8068. if (WARN_ON(!sband))
  8069. return;
  8070. link = sdata_dereference(sdata->link[link_id], sdata);
  8071. if (WARN_ON(!link))
  8072. return;
  8073. /* for MLO connections assume advertising all rates is OK */
  8074. if (!req->ap_mld_addr) {
  8075. assoc_data->supp_rates = bss->supp_rates;
  8076. assoc_data->supp_rates_len = bss->supp_rates_len;
  8077. }
  8078. /* copy and link elems for the STA profile */
  8079. if (req->links[link_id].elems_len) {
  8080. memcpy(assoc_data->ie_pos, req->links[link_id].elems,
  8081. req->links[link_id].elems_len);
  8082. assoc_data->link[link_id].elems = assoc_data->ie_pos;
  8083. assoc_data->link[link_id].elems_len = req->links[link_id].elems_len;
  8084. assoc_data->ie_pos += req->links[link_id].elems_len;
  8085. }
  8086. link->u.mgd.beacon_crc_valid = false;
  8087. link->u.mgd.dtim_period = 0;
  8088. link->u.mgd.have_beacon = false;
  8089. /* override HT configuration only if the AP and we support it */
  8090. if (conn->mode >= IEEE80211_CONN_MODE_HT) {
  8091. struct ieee80211_sta_ht_cap sta_ht_cap;
  8092. memcpy(&sta_ht_cap, &sband->ht_cap, sizeof(sta_ht_cap));
  8093. ieee80211_apply_htcap_overrides(sdata, &sta_ht_cap);
  8094. }
  8095. rcu_read_lock();
  8096. bss_ies = rcu_dereference(cbss->beacon_ies);
  8097. if (bss_ies) {
  8098. u8 dtim_count = 0;
  8099. ieee80211_get_dtim(bss_ies, &dtim_count,
  8100. &link->u.mgd.dtim_period);
  8101. sdata->deflink.u.mgd.have_beacon = true;
  8102. if (ieee80211_hw_check(&local->hw, TIMING_BEACON_ONLY)) {
  8103. link->conf->sync_tsf = bss_ies->tsf;
  8104. link->conf->sync_device_ts = bss->device_ts_beacon;
  8105. link->conf->sync_dtim_count = dtim_count;
  8106. }
  8107. } else {
  8108. bss_ies = rcu_dereference(cbss->ies);
  8109. }
  8110. if (bss_ies) {
  8111. const struct element *elem;
  8112. elem = cfg80211_find_ext_elem(WLAN_EID_EXT_MULTIPLE_BSSID_CONFIGURATION,
  8113. bss_ies->data, bss_ies->len);
  8114. if (elem && elem->datalen >= 3)
  8115. link->conf->profile_periodicity = elem->data[2];
  8116. else
  8117. link->conf->profile_periodicity = 0;
  8118. elem = cfg80211_find_elem(WLAN_EID_EXT_CAPABILITY,
  8119. bss_ies->data, bss_ies->len);
  8120. if (elem && elem->datalen >= 11 &&
  8121. (elem->data[10] & WLAN_EXT_CAPA11_EMA_SUPPORT))
  8122. link->conf->ema_ap = true;
  8123. else
  8124. link->conf->ema_ap = false;
  8125. }
  8126. rcu_read_unlock();
  8127. if (bss->corrupt_data) {
  8128. char *corrupt_type = "data";
  8129. if (bss->corrupt_data & IEEE80211_BSS_CORRUPT_BEACON) {
  8130. if (bss->corrupt_data & IEEE80211_BSS_CORRUPT_PROBE_RESP)
  8131. corrupt_type = "beacon and probe response";
  8132. else
  8133. corrupt_type = "beacon";
  8134. } else if (bss->corrupt_data & IEEE80211_BSS_CORRUPT_PROBE_RESP) {
  8135. corrupt_type = "probe response";
  8136. }
  8137. sdata_info(sdata, "associating to AP %pM with corrupt %s\n",
  8138. cbss->bssid, corrupt_type);
  8139. }
  8140. if (link->u.mgd.req_smps == IEEE80211_SMPS_AUTOMATIC) {
  8141. if (sdata->u.mgd.powersave)
  8142. link->smps_mode = IEEE80211_SMPS_DYNAMIC;
  8143. else
  8144. link->smps_mode = IEEE80211_SMPS_OFF;
  8145. } else {
  8146. link->smps_mode = link->u.mgd.req_smps;
  8147. }
  8148. }
  8149. static int
  8150. ieee80211_mgd_get_ap_ht_vht_capa(struct ieee80211_sub_if_data *sdata,
  8151. struct ieee80211_mgd_assoc_data *assoc_data,
  8152. int link_id)
  8153. {
  8154. struct cfg80211_bss *cbss = assoc_data->link[link_id].bss;
  8155. enum nl80211_band band = cbss->channel->band;
  8156. struct ieee80211_supported_band *sband;
  8157. const struct element *elem;
  8158. int err;
  8159. /* neither HT nor VHT elements used on 6 GHz */
  8160. if (band == NL80211_BAND_6GHZ)
  8161. return 0;
  8162. if (assoc_data->link[link_id].conn.mode < IEEE80211_CONN_MODE_HT)
  8163. return 0;
  8164. rcu_read_lock();
  8165. elem = ieee80211_bss_get_elem(cbss, WLAN_EID_HT_OPERATION);
  8166. if (!elem || elem->datalen < sizeof(struct ieee80211_ht_operation)) {
  8167. mlme_link_id_dbg(sdata, link_id, "no HT operation on BSS %pM\n",
  8168. cbss->bssid);
  8169. err = -EINVAL;
  8170. goto out_rcu;
  8171. }
  8172. assoc_data->link[link_id].ap_ht_param =
  8173. ((struct ieee80211_ht_operation *)(elem->data))->ht_param;
  8174. rcu_read_unlock();
  8175. if (assoc_data->link[link_id].conn.mode < IEEE80211_CONN_MODE_VHT)
  8176. return 0;
  8177. /* some drivers want to support VHT on 2.4 GHz even */
  8178. sband = sdata->local->hw.wiphy->bands[band];
  8179. if (!sband->vht_cap.vht_supported)
  8180. return 0;
  8181. rcu_read_lock();
  8182. elem = ieee80211_bss_get_elem(cbss, WLAN_EID_VHT_CAPABILITY);
  8183. /* but even then accept it not being present on the AP */
  8184. if (!elem && band == NL80211_BAND_2GHZ) {
  8185. err = 0;
  8186. goto out_rcu;
  8187. }
  8188. if (!elem || elem->datalen < sizeof(struct ieee80211_vht_cap)) {
  8189. mlme_link_id_dbg(sdata, link_id, "no VHT capa on BSS %pM\n",
  8190. cbss->bssid);
  8191. err = -EINVAL;
  8192. goto out_rcu;
  8193. }
  8194. memcpy(&assoc_data->link[link_id].ap_vht_cap, elem->data,
  8195. sizeof(struct ieee80211_vht_cap));
  8196. rcu_read_unlock();
  8197. return 0;
  8198. out_rcu:
  8199. rcu_read_unlock();
  8200. return err;
  8201. }
  8202. static bool
  8203. ieee80211_mgd_assoc_bss_has_mld_ext_capa_ops(struct cfg80211_assoc_request *req)
  8204. {
  8205. const struct cfg80211_bss_ies *ies;
  8206. struct cfg80211_bss *bss;
  8207. const struct element *ml;
  8208. /* not an MLO connection if link_id < 0, so irrelevant */
  8209. if (req->link_id < 0)
  8210. return false;
  8211. bss = req->links[req->link_id].bss;
  8212. guard(rcu)();
  8213. ies = rcu_dereference(bss->ies);
  8214. for_each_element_extid(ml, WLAN_EID_EXT_EHT_MULTI_LINK,
  8215. ies->data, ies->len) {
  8216. const struct ieee80211_multi_link_elem *mle;
  8217. if (!ieee80211_mle_type_ok(ml->data + 1,
  8218. IEEE80211_ML_CONTROL_TYPE_BASIC,
  8219. ml->datalen - 1))
  8220. continue;
  8221. mle = (void *)(ml->data + 1);
  8222. if (mle->control & cpu_to_le16(IEEE80211_MLC_BASIC_PRES_EXT_MLD_CAPA_OP))
  8223. return true;
  8224. }
  8225. return false;
  8226. }
  8227. int ieee80211_mgd_assoc(struct ieee80211_sub_if_data *sdata,
  8228. struct cfg80211_assoc_request *req)
  8229. {
  8230. unsigned int assoc_link_id = req->link_id < 0 ? 0 : req->link_id;
  8231. struct ieee80211_local *local = sdata->local;
  8232. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  8233. struct ieee80211_mgd_assoc_data *assoc_data;
  8234. const struct element *ssid_elem;
  8235. struct ieee80211_vif_cfg *vif_cfg = &sdata->vif.cfg;
  8236. struct ieee80211_link_data *link;
  8237. struct cfg80211_bss *cbss;
  8238. bool override, uapsd_supported;
  8239. bool match_auth;
  8240. int i, err;
  8241. size_t size = sizeof(*assoc_data) + req->ie_len;
  8242. for (i = 0; i < IEEE80211_MLD_MAX_NUM_LINKS; i++)
  8243. size += req->links[i].elems_len;
  8244. /* FIXME: no support for 4-addr MLO yet */
  8245. if (sdata->u.mgd.use_4addr && req->link_id >= 0)
  8246. return -EOPNOTSUPP;
  8247. assoc_data = kzalloc(size, GFP_KERNEL);
  8248. if (!assoc_data)
  8249. return -ENOMEM;
  8250. cbss = req->link_id < 0 ? req->bss : req->links[req->link_id].bss;
  8251. if (ieee80211_mgd_csa_in_process(sdata, cbss)) {
  8252. sdata_info(sdata, "AP is in CSA process, reject assoc\n");
  8253. err = -EINVAL;
  8254. goto err_free;
  8255. }
  8256. rcu_read_lock();
  8257. ssid_elem = ieee80211_bss_get_elem(cbss, WLAN_EID_SSID);
  8258. if (!ssid_elem || ssid_elem->datalen > sizeof(assoc_data->ssid)) {
  8259. rcu_read_unlock();
  8260. err = -EINVAL;
  8261. goto err_free;
  8262. }
  8263. memcpy(assoc_data->ssid, ssid_elem->data, ssid_elem->datalen);
  8264. assoc_data->ssid_len = ssid_elem->datalen;
  8265. rcu_read_unlock();
  8266. if (req->ap_mld_addr)
  8267. memcpy(assoc_data->ap_addr, req->ap_mld_addr, ETH_ALEN);
  8268. else
  8269. memcpy(assoc_data->ap_addr, cbss->bssid, ETH_ALEN);
  8270. /*
  8271. * Many APs have broken parsing of the extended MLD capa/ops field,
  8272. * dropping (re-)association request frames or replying with association
  8273. * response with a failure status if it's present.
  8274. * Set our value from the userspace request only in strict mode or if
  8275. * the AP also had that field present.
  8276. */
  8277. if (ieee80211_hw_check(&local->hw, STRICT) ||
  8278. ieee80211_mgd_assoc_bss_has_mld_ext_capa_ops(req))
  8279. assoc_data->ext_mld_capa_ops =
  8280. cpu_to_le16(req->ext_mld_capa_ops);
  8281. if (ifmgd->associated) {
  8282. u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
  8283. sdata_info(sdata,
  8284. "disconnect from AP %pM for new assoc to %pM\n",
  8285. sdata->vif.cfg.ap_addr, assoc_data->ap_addr);
  8286. ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
  8287. WLAN_REASON_UNSPECIFIED,
  8288. false, frame_buf);
  8289. ieee80211_report_disconnect(sdata, frame_buf,
  8290. sizeof(frame_buf), true,
  8291. WLAN_REASON_UNSPECIFIED,
  8292. false);
  8293. }
  8294. memset(sdata->u.mgd.userspace_selectors, 0,
  8295. sizeof(sdata->u.mgd.userspace_selectors));
  8296. ieee80211_parse_cfg_selectors(sdata->u.mgd.userspace_selectors,
  8297. req->supported_selectors,
  8298. req->supported_selectors_len);
  8299. memcpy(&ifmgd->ht_capa, &req->ht_capa, sizeof(ifmgd->ht_capa));
  8300. memcpy(&ifmgd->ht_capa_mask, &req->ht_capa_mask,
  8301. sizeof(ifmgd->ht_capa_mask));
  8302. memcpy(&ifmgd->vht_capa, &req->vht_capa, sizeof(ifmgd->vht_capa));
  8303. memcpy(&ifmgd->vht_capa_mask, &req->vht_capa_mask,
  8304. sizeof(ifmgd->vht_capa_mask));
  8305. memcpy(&ifmgd->s1g_capa, &req->s1g_capa, sizeof(ifmgd->s1g_capa));
  8306. memcpy(&ifmgd->s1g_capa_mask, &req->s1g_capa_mask,
  8307. sizeof(ifmgd->s1g_capa_mask));
  8308. /* keep some setup (AP STA, channel, ...) if matching */
  8309. match_auth = ifmgd->auth_data &&
  8310. ether_addr_equal(ifmgd->auth_data->ap_addr,
  8311. assoc_data->ap_addr) &&
  8312. ifmgd->auth_data->link_id == req->link_id;
  8313. if (req->ap_mld_addr) {
  8314. uapsd_supported = true;
  8315. if (req->flags & (ASSOC_REQ_DISABLE_HT |
  8316. ASSOC_REQ_DISABLE_VHT |
  8317. ASSOC_REQ_DISABLE_HE |
  8318. ASSOC_REQ_DISABLE_EHT)) {
  8319. err = -EINVAL;
  8320. goto err_free;
  8321. }
  8322. for (i = 0; i < IEEE80211_MLD_MAX_NUM_LINKS; i++) {
  8323. struct ieee80211_supported_band *sband;
  8324. struct cfg80211_bss *link_cbss = req->links[i].bss;
  8325. struct ieee80211_bss *bss;
  8326. if (!link_cbss)
  8327. continue;
  8328. bss = (void *)link_cbss->priv;
  8329. if (!bss->wmm_used) {
  8330. err = -EINVAL;
  8331. req->links[i].error = err;
  8332. goto err_free;
  8333. }
  8334. if (link_cbss->channel->band == NL80211_BAND_S1GHZ) {
  8335. err = -EINVAL;
  8336. req->links[i].error = err;
  8337. goto err_free;
  8338. }
  8339. link = sdata_dereference(sdata->link[i], sdata);
  8340. if (link)
  8341. ether_addr_copy(assoc_data->link[i].addr,
  8342. link->conf->addr);
  8343. else
  8344. eth_random_addr(assoc_data->link[i].addr);
  8345. sband = local->hw.wiphy->bands[link_cbss->channel->band];
  8346. if (match_auth && i == assoc_link_id && link)
  8347. assoc_data->link[i].conn = link->u.mgd.conn;
  8348. else
  8349. assoc_data->link[i].conn =
  8350. ieee80211_conn_settings_unlimited;
  8351. ieee80211_determine_our_sta_mode_assoc(sdata, sband,
  8352. req, true, i,
  8353. &assoc_data->link[i].conn);
  8354. assoc_data->link[i].bss = link_cbss;
  8355. if (!bss->uapsd_supported)
  8356. uapsd_supported = false;
  8357. if (assoc_data->link[i].conn.mode < IEEE80211_CONN_MODE_EHT) {
  8358. err = -EINVAL;
  8359. req->links[i].error = err;
  8360. goto err_free;
  8361. }
  8362. err = ieee80211_mgd_get_ap_ht_vht_capa(sdata,
  8363. assoc_data, i);
  8364. if (err) {
  8365. err = -EINVAL;
  8366. req->links[i].error = err;
  8367. goto err_free;
  8368. }
  8369. }
  8370. assoc_data->wmm = true;
  8371. } else {
  8372. struct ieee80211_supported_band *sband;
  8373. struct ieee80211_bss *bss = (void *)cbss->priv;
  8374. memcpy(assoc_data->link[0].addr, sdata->vif.addr, ETH_ALEN);
  8375. assoc_data->s1g = cbss->channel->band == NL80211_BAND_S1GHZ;
  8376. assoc_data->wmm = bss->wmm_used &&
  8377. (local->hw.queues >= IEEE80211_NUM_ACS);
  8378. if (cbss->channel->band == NL80211_BAND_6GHZ &&
  8379. req->flags & (ASSOC_REQ_DISABLE_HT |
  8380. ASSOC_REQ_DISABLE_VHT |
  8381. ASSOC_REQ_DISABLE_HE)) {
  8382. err = -EINVAL;
  8383. goto err_free;
  8384. }
  8385. sband = local->hw.wiphy->bands[cbss->channel->band];
  8386. assoc_data->link[0].bss = cbss;
  8387. if (match_auth)
  8388. assoc_data->link[0].conn = sdata->deflink.u.mgd.conn;
  8389. else
  8390. assoc_data->link[0].conn =
  8391. ieee80211_conn_settings_unlimited;
  8392. ieee80211_determine_our_sta_mode_assoc(sdata, sband, req,
  8393. assoc_data->wmm, 0,
  8394. &assoc_data->link[0].conn);
  8395. uapsd_supported = bss->uapsd_supported;
  8396. err = ieee80211_mgd_get_ap_ht_vht_capa(sdata, assoc_data, 0);
  8397. if (err)
  8398. goto err_free;
  8399. }
  8400. assoc_data->spp_amsdu = req->flags & ASSOC_REQ_SPP_AMSDU;
  8401. if (ifmgd->auth_data && !ifmgd->auth_data->done) {
  8402. err = -EBUSY;
  8403. goto err_free;
  8404. }
  8405. if (ifmgd->assoc_data) {
  8406. err = -EBUSY;
  8407. goto err_free;
  8408. }
  8409. /* Cleanup is delayed if auth_data matches */
  8410. if (ifmgd->auth_data && !match_auth)
  8411. ieee80211_destroy_auth_data(sdata, false);
  8412. if (req->ie && req->ie_len) {
  8413. memcpy(assoc_data->ie, req->ie, req->ie_len);
  8414. assoc_data->ie_len = req->ie_len;
  8415. assoc_data->ie_pos = assoc_data->ie + assoc_data->ie_len;
  8416. } else {
  8417. assoc_data->ie_pos = assoc_data->ie;
  8418. }
  8419. if (req->fils_kek) {
  8420. /* should already be checked in cfg80211 - so warn */
  8421. if (WARN_ON(req->fils_kek_len > FILS_MAX_KEK_LEN)) {
  8422. err = -EINVAL;
  8423. goto err_free;
  8424. }
  8425. memcpy(assoc_data->fils_kek, req->fils_kek,
  8426. req->fils_kek_len);
  8427. assoc_data->fils_kek_len = req->fils_kek_len;
  8428. }
  8429. if (req->fils_nonces)
  8430. memcpy(assoc_data->fils_nonces, req->fils_nonces,
  8431. 2 * FILS_NONCE_LEN);
  8432. /* default timeout */
  8433. assoc_data->timeout = jiffies;
  8434. assoc_data->timeout_started = true;
  8435. assoc_data->assoc_link_id = assoc_link_id;
  8436. if (req->ap_mld_addr) {
  8437. /* if there was no authentication, set up the link */
  8438. err = ieee80211_vif_set_links(sdata, BIT(assoc_link_id), 0);
  8439. if (err)
  8440. goto err_clear;
  8441. }
  8442. link = sdata_dereference(sdata->link[assoc_link_id], sdata);
  8443. if (WARN_ON(!link)) {
  8444. err = -EINVAL;
  8445. goto err_clear;
  8446. }
  8447. override = link->u.mgd.conn.mode !=
  8448. assoc_data->link[assoc_link_id].conn.mode ||
  8449. link->u.mgd.conn.bw_limit !=
  8450. assoc_data->link[assoc_link_id].conn.bw_limit;
  8451. link->u.mgd.conn = assoc_data->link[assoc_link_id].conn;
  8452. ieee80211_setup_assoc_link(sdata, assoc_data, req, &link->u.mgd.conn,
  8453. assoc_link_id);
  8454. if (WARN((sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_UAPSD) &&
  8455. ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK),
  8456. "U-APSD not supported with HW_PS_NULLFUNC_STACK\n"))
  8457. sdata->vif.driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD;
  8458. if (assoc_data->wmm && uapsd_supported &&
  8459. (sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_UAPSD)) {
  8460. assoc_data->uapsd = true;
  8461. ifmgd->flags |= IEEE80211_STA_UAPSD_ENABLED;
  8462. } else {
  8463. assoc_data->uapsd = false;
  8464. ifmgd->flags &= ~IEEE80211_STA_UAPSD_ENABLED;
  8465. }
  8466. if (req->prev_bssid)
  8467. memcpy(assoc_data->prev_ap_addr, req->prev_bssid, ETH_ALEN);
  8468. if (req->use_mfp) {
  8469. ifmgd->mfp = IEEE80211_MFP_REQUIRED;
  8470. ifmgd->flags |= IEEE80211_STA_MFP_ENABLED;
  8471. } else {
  8472. ifmgd->mfp = IEEE80211_MFP_DISABLED;
  8473. ifmgd->flags &= ~IEEE80211_STA_MFP_ENABLED;
  8474. }
  8475. if (req->flags & ASSOC_REQ_USE_RRM)
  8476. ifmgd->flags |= IEEE80211_STA_ENABLE_RRM;
  8477. else
  8478. ifmgd->flags &= ~IEEE80211_STA_ENABLE_RRM;
  8479. if (req->crypto.control_port)
  8480. ifmgd->flags |= IEEE80211_STA_CONTROL_PORT;
  8481. else
  8482. ifmgd->flags &= ~IEEE80211_STA_CONTROL_PORT;
  8483. sdata->control_port_protocol = req->crypto.control_port_ethertype;
  8484. sdata->control_port_no_encrypt = req->crypto.control_port_no_encrypt;
  8485. sdata->control_port_over_nl80211 =
  8486. req->crypto.control_port_over_nl80211;
  8487. sdata->control_port_no_preauth = req->crypto.control_port_no_preauth;
  8488. /* kick off associate process */
  8489. ifmgd->assoc_data = assoc_data;
  8490. for (i = 0; i < ARRAY_SIZE(assoc_data->link); i++) {
  8491. if (!assoc_data->link[i].bss)
  8492. continue;
  8493. if (i == assoc_data->assoc_link_id)
  8494. continue;
  8495. /* only calculate the mode, hence link == NULL */
  8496. err = ieee80211_prep_channel(sdata, NULL, i,
  8497. assoc_data->link[i].bss, true,
  8498. &assoc_data->link[i].conn,
  8499. sdata->u.mgd.userspace_selectors);
  8500. if (err) {
  8501. req->links[i].error = err;
  8502. goto err_clear;
  8503. }
  8504. }
  8505. memcpy(vif_cfg->ssid, assoc_data->ssid, assoc_data->ssid_len);
  8506. vif_cfg->ssid_len = assoc_data->ssid_len;
  8507. /* needed for transmitting the assoc frames properly */
  8508. memcpy(sdata->vif.cfg.ap_addr, assoc_data->ap_addr, ETH_ALEN);
  8509. err = ieee80211_prep_connection(sdata, cbss, req->link_id,
  8510. req->ap_mld_addr, true,
  8511. &assoc_data->link[assoc_link_id].conn,
  8512. override,
  8513. sdata->u.mgd.userspace_selectors);
  8514. if (err)
  8515. goto err_clear;
  8516. if (ieee80211_hw_check(&sdata->local->hw, NEED_DTIM_BEFORE_ASSOC)) {
  8517. const struct cfg80211_bss_ies *beacon_ies;
  8518. rcu_read_lock();
  8519. beacon_ies = rcu_dereference(req->bss->beacon_ies);
  8520. if (!beacon_ies) {
  8521. /*
  8522. * Wait up to one beacon interval ...
  8523. * should this be more if we miss one?
  8524. */
  8525. sdata_info(sdata, "waiting for beacon from %pM\n",
  8526. link->u.mgd.bssid);
  8527. assoc_data->timeout = TU_TO_EXP_TIME(req->bss->beacon_interval);
  8528. assoc_data->timeout_started = true;
  8529. assoc_data->need_beacon = true;
  8530. }
  8531. rcu_read_unlock();
  8532. }
  8533. run_again(sdata, assoc_data->timeout);
  8534. /* We are associating, clean up auth_data */
  8535. if (ifmgd->auth_data)
  8536. ieee80211_destroy_auth_data(sdata, true);
  8537. return 0;
  8538. err_clear:
  8539. if (!ifmgd->auth_data) {
  8540. eth_zero_addr(sdata->deflink.u.mgd.bssid);
  8541. ieee80211_link_info_change_notify(sdata, &sdata->deflink,
  8542. BSS_CHANGED_BSSID);
  8543. }
  8544. ifmgd->assoc_data = NULL;
  8545. err_free:
  8546. kfree(assoc_data);
  8547. return err;
  8548. }
  8549. int ieee80211_mgd_deauth(struct ieee80211_sub_if_data *sdata,
  8550. struct cfg80211_deauth_request *req)
  8551. {
  8552. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  8553. u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
  8554. bool tx = !req->local_state_change;
  8555. struct ieee80211_prep_tx_info info = {
  8556. .subtype = IEEE80211_STYPE_DEAUTH,
  8557. };
  8558. if (ifmgd->auth_data &&
  8559. ether_addr_equal(ifmgd->auth_data->ap_addr, req->bssid)) {
  8560. sdata_info(sdata,
  8561. "aborting authentication with %pM by local choice (Reason: %u=%s)\n",
  8562. req->bssid, req->reason_code,
  8563. ieee80211_get_reason_code_string(req->reason_code));
  8564. info.link_id = ifmgd->auth_data->link_id;
  8565. drv_mgd_prepare_tx(sdata->local, sdata, &info);
  8566. ieee80211_send_deauth_disassoc(sdata, req->bssid, req->bssid,
  8567. IEEE80211_STYPE_DEAUTH,
  8568. req->reason_code, tx,
  8569. frame_buf);
  8570. ieee80211_destroy_auth_data(sdata, false);
  8571. ieee80211_report_disconnect(sdata, frame_buf,
  8572. sizeof(frame_buf), true,
  8573. req->reason_code, false);
  8574. drv_mgd_complete_tx(sdata->local, sdata, &info);
  8575. return 0;
  8576. }
  8577. if (ifmgd->assoc_data &&
  8578. ether_addr_equal(ifmgd->assoc_data->ap_addr, req->bssid)) {
  8579. sdata_info(sdata,
  8580. "aborting association with %pM by local choice (Reason: %u=%s)\n",
  8581. req->bssid, req->reason_code,
  8582. ieee80211_get_reason_code_string(req->reason_code));
  8583. info.link_id = ifmgd->assoc_data->assoc_link_id;
  8584. drv_mgd_prepare_tx(sdata->local, sdata, &info);
  8585. ieee80211_send_deauth_disassoc(sdata, req->bssid, req->bssid,
  8586. IEEE80211_STYPE_DEAUTH,
  8587. req->reason_code, tx,
  8588. frame_buf);
  8589. ieee80211_destroy_assoc_data(sdata, ASSOC_ABANDON);
  8590. ieee80211_report_disconnect(sdata, frame_buf,
  8591. sizeof(frame_buf), true,
  8592. req->reason_code, false);
  8593. drv_mgd_complete_tx(sdata->local, sdata, &info);
  8594. return 0;
  8595. }
  8596. if (ifmgd->associated &&
  8597. ether_addr_equal(sdata->vif.cfg.ap_addr, req->bssid)) {
  8598. sdata_info(sdata,
  8599. "deauthenticating from %pM by local choice (Reason: %u=%s)\n",
  8600. req->bssid, req->reason_code,
  8601. ieee80211_get_reason_code_string(req->reason_code));
  8602. ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
  8603. req->reason_code, tx, frame_buf);
  8604. ieee80211_report_disconnect(sdata, frame_buf,
  8605. sizeof(frame_buf), true,
  8606. req->reason_code, false);
  8607. return 0;
  8608. }
  8609. return -ENOTCONN;
  8610. }
  8611. int ieee80211_mgd_disassoc(struct ieee80211_sub_if_data *sdata,
  8612. struct cfg80211_disassoc_request *req)
  8613. {
  8614. u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
  8615. if (!sdata->u.mgd.associated ||
  8616. memcmp(sdata->vif.cfg.ap_addr, req->ap_addr, ETH_ALEN))
  8617. return -ENOTCONN;
  8618. sdata_info(sdata,
  8619. "disassociating from %pM by local choice (Reason: %u=%s)\n",
  8620. req->ap_addr, req->reason_code,
  8621. ieee80211_get_reason_code_string(req->reason_code));
  8622. ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DISASSOC,
  8623. req->reason_code, !req->local_state_change,
  8624. frame_buf);
  8625. ieee80211_report_disconnect(sdata, frame_buf, sizeof(frame_buf), true,
  8626. req->reason_code, false);
  8627. return 0;
  8628. }
  8629. void ieee80211_mgd_stop_link(struct ieee80211_link_data *link)
  8630. {
  8631. wiphy_work_cancel(link->sdata->local->hw.wiphy,
  8632. &link->u.mgd.request_smps_work);
  8633. wiphy_work_cancel(link->sdata->local->hw.wiphy,
  8634. &link->u.mgd.recalc_smps);
  8635. wiphy_hrtimer_work_cancel(link->sdata->local->hw.wiphy,
  8636. &link->u.mgd.csa.switch_work);
  8637. }
  8638. void ieee80211_mgd_stop(struct ieee80211_sub_if_data *sdata)
  8639. {
  8640. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  8641. /*
  8642. * Make sure some work items will not run after this,
  8643. * they will not do anything but might not have been
  8644. * cancelled when disconnecting.
  8645. */
  8646. wiphy_work_cancel(sdata->local->hw.wiphy,
  8647. &ifmgd->monitor_work);
  8648. wiphy_work_cancel(sdata->local->hw.wiphy,
  8649. &ifmgd->beacon_connection_loss_work);
  8650. wiphy_work_cancel(sdata->local->hw.wiphy,
  8651. &ifmgd->csa_connection_drop_work);
  8652. wiphy_delayed_work_cancel(sdata->local->hw.wiphy,
  8653. &ifmgd->tdls_peer_del_work);
  8654. if (ifmgd->assoc_data)
  8655. ieee80211_destroy_assoc_data(sdata, ASSOC_TIMEOUT);
  8656. if (ifmgd->auth_data)
  8657. ieee80211_destroy_auth_data(sdata, false);
  8658. spin_lock_bh(&ifmgd->teardown_lock);
  8659. if (ifmgd->teardown_skb) {
  8660. kfree_skb(ifmgd->teardown_skb);
  8661. ifmgd->teardown_skb = NULL;
  8662. ifmgd->orig_teardown_skb = NULL;
  8663. }
  8664. kfree(ifmgd->assoc_req_ies);
  8665. ifmgd->assoc_req_ies = NULL;
  8666. ifmgd->assoc_req_ies_len = 0;
  8667. spin_unlock_bh(&ifmgd->teardown_lock);
  8668. timer_delete_sync(&ifmgd->timer);
  8669. }
  8670. void ieee80211_cqm_rssi_notify(struct ieee80211_vif *vif,
  8671. enum nl80211_cqm_rssi_threshold_event rssi_event,
  8672. s32 rssi_level,
  8673. gfp_t gfp)
  8674. {
  8675. struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
  8676. trace_api_cqm_rssi_notify(sdata, rssi_event, rssi_level);
  8677. cfg80211_cqm_rssi_notify(sdata->dev, rssi_event, rssi_level, gfp);
  8678. }
  8679. EXPORT_SYMBOL(ieee80211_cqm_rssi_notify);
  8680. void ieee80211_cqm_beacon_loss_notify(struct ieee80211_vif *vif, gfp_t gfp)
  8681. {
  8682. struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
  8683. trace_api_cqm_beacon_loss_notify(sdata->local, sdata);
  8684. cfg80211_cqm_beacon_loss_notify(sdata->dev, gfp);
  8685. }
  8686. EXPORT_SYMBOL(ieee80211_cqm_beacon_loss_notify);
  8687. static void _ieee80211_enable_rssi_reports(struct ieee80211_sub_if_data *sdata,
  8688. int rssi_min_thold,
  8689. int rssi_max_thold)
  8690. {
  8691. trace_api_enable_rssi_reports(sdata, rssi_min_thold, rssi_max_thold);
  8692. if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
  8693. return;
  8694. /*
  8695. * Scale up threshold values before storing it, as the RSSI averaging
  8696. * algorithm uses a scaled up value as well. Change this scaling
  8697. * factor if the RSSI averaging algorithm changes.
  8698. */
  8699. sdata->u.mgd.rssi_min_thold = rssi_min_thold*16;
  8700. sdata->u.mgd.rssi_max_thold = rssi_max_thold*16;
  8701. }
  8702. void ieee80211_enable_rssi_reports(struct ieee80211_vif *vif,
  8703. int rssi_min_thold,
  8704. int rssi_max_thold)
  8705. {
  8706. struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
  8707. WARN_ON(rssi_min_thold == rssi_max_thold ||
  8708. rssi_min_thold > rssi_max_thold);
  8709. _ieee80211_enable_rssi_reports(sdata, rssi_min_thold,
  8710. rssi_max_thold);
  8711. }
  8712. EXPORT_SYMBOL(ieee80211_enable_rssi_reports);
  8713. void ieee80211_disable_rssi_reports(struct ieee80211_vif *vif)
  8714. {
  8715. struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
  8716. _ieee80211_enable_rssi_reports(sdata, 0, 0);
  8717. }
  8718. EXPORT_SYMBOL(ieee80211_disable_rssi_reports);
  8719. void ieee80211_process_ml_reconf_resp(struct ieee80211_sub_if_data *sdata,
  8720. struct ieee80211_mgmt *mgmt, size_t len)
  8721. {
  8722. struct ieee80211_local *local = sdata->local;
  8723. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  8724. struct ieee80211_mgd_assoc_data *add_links_data =
  8725. ifmgd->reconf.add_links_data;
  8726. struct sta_info *sta;
  8727. struct cfg80211_mlo_reconf_done_data done_data = {};
  8728. u16 sta_changed_links = sdata->u.mgd.reconf.added_links |
  8729. sdata->u.mgd.reconf.removed_links;
  8730. u16 link_mask, valid_links;
  8731. unsigned int link_id;
  8732. size_t orig_len = len;
  8733. u8 i, group_key_data_len;
  8734. u8 *pos;
  8735. if (!ieee80211_vif_is_mld(&sdata->vif) ||
  8736. len < offsetofend(typeof(*mgmt), u.action.u.ml_reconf_resp) ||
  8737. mgmt->u.action.u.ml_reconf_resp.dialog_token !=
  8738. sdata->u.mgd.reconf.dialog_token ||
  8739. !sta_changed_links)
  8740. return;
  8741. pos = mgmt->u.action.u.ml_reconf_resp.variable;
  8742. len -= offsetofend(typeof(*mgmt), u.action.u.ml_reconf_resp);
  8743. /* each status duple is 3 octets */
  8744. if (len < mgmt->u.action.u.ml_reconf_resp.count * 3) {
  8745. sdata_info(sdata,
  8746. "mlo: reconf: unexpected len=%zu, count=%u\n",
  8747. len, mgmt->u.action.u.ml_reconf_resp.count);
  8748. goto disconnect;
  8749. }
  8750. link_mask = sta_changed_links;
  8751. for (i = 0; i < mgmt->u.action.u.ml_reconf_resp.count; i++) {
  8752. u16 status = get_unaligned_le16(pos + 1);
  8753. link_id = *pos;
  8754. if (!(link_mask & BIT(link_id))) {
  8755. sdata_info(sdata,
  8756. "mlo: reconf: unexpected link: %u, changed=0x%x\n",
  8757. link_id, sta_changed_links);
  8758. goto disconnect;
  8759. }
  8760. /* clear the corresponding link, to detect the case that
  8761. * the same link was included more than one time
  8762. */
  8763. link_mask &= ~BIT(link_id);
  8764. /* Handle failure to remove links here. Failure to remove added
  8765. * links will be done later in the flow.
  8766. */
  8767. if (status != WLAN_STATUS_SUCCESS) {
  8768. sdata_info(sdata,
  8769. "mlo: reconf: failed on link=%u, status=%u\n",
  8770. link_id, status);
  8771. /* The AP MLD failed to remove a link that was already
  8772. * removed locally. As this is not expected behavior,
  8773. * disconnect
  8774. */
  8775. if (sdata->u.mgd.reconf.removed_links & BIT(link_id))
  8776. goto disconnect;
  8777. /* The AP MLD failed to add a link. Remove it from the
  8778. * added links.
  8779. */
  8780. sdata->u.mgd.reconf.added_links &= ~BIT(link_id);
  8781. }
  8782. pos += 3;
  8783. len -= 3;
  8784. }
  8785. if (link_mask) {
  8786. sdata_info(sdata,
  8787. "mlo: reconf: no response for links=0x%x\n",
  8788. link_mask);
  8789. goto disconnect;
  8790. }
  8791. if (!sdata->u.mgd.reconf.added_links)
  8792. goto out;
  8793. if (len < 1 || len < 1 + *pos) {
  8794. sdata_info(sdata,
  8795. "mlo: reconf: invalid group key data length");
  8796. goto disconnect;
  8797. }
  8798. /* The Group Key Data field must be present when links are added. This
  8799. * field should be processed by userland.
  8800. */
  8801. group_key_data_len = *pos++;
  8802. pos += group_key_data_len;
  8803. len -= group_key_data_len + 1;
  8804. /* Process the information for the added links */
  8805. sta = sta_info_get(sdata, sdata->vif.cfg.ap_addr);
  8806. if (WARN_ON(!sta))
  8807. goto disconnect;
  8808. valid_links = sdata->vif.valid_links;
  8809. for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS; link_id++) {
  8810. if (!add_links_data->link[link_id].bss ||
  8811. !(sdata->u.mgd.reconf.added_links & BIT(link_id)))
  8812. continue;
  8813. valid_links |= BIT(link_id);
  8814. if (ieee80211_sta_allocate_link(sta, link_id))
  8815. goto disconnect;
  8816. }
  8817. ieee80211_vif_set_links(sdata, valid_links, sdata->vif.dormant_links);
  8818. link_mask = 0;
  8819. for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS; link_id++) {
  8820. struct cfg80211_bss *cbss = add_links_data->link[link_id].bss;
  8821. struct ieee80211_link_data *link;
  8822. struct link_sta_info *link_sta;
  8823. u64 changed = 0;
  8824. if (!cbss)
  8825. continue;
  8826. link = sdata_dereference(sdata->link[link_id], sdata);
  8827. if (WARN_ON(!link))
  8828. goto disconnect;
  8829. link_info(link,
  8830. "mlo: reconf: local address %pM, AP link address %pM\n",
  8831. add_links_data->link[link_id].addr,
  8832. add_links_data->link[link_id].bss->bssid);
  8833. link_sta = rcu_dereference_protected(sta->link[link_id],
  8834. lockdep_is_held(&local->hw.wiphy->mtx));
  8835. if (WARN_ON(!link_sta))
  8836. goto disconnect;
  8837. if (!link->u.mgd.have_beacon) {
  8838. const struct cfg80211_bss_ies *ies;
  8839. rcu_read_lock();
  8840. ies = rcu_dereference(cbss->beacon_ies);
  8841. if (ies)
  8842. link->u.mgd.have_beacon = true;
  8843. else
  8844. ies = rcu_dereference(cbss->ies);
  8845. ieee80211_get_dtim(ies,
  8846. &link->conf->sync_dtim_count,
  8847. &link->u.mgd.dtim_period);
  8848. link->conf->beacon_int = cbss->beacon_interval;
  8849. rcu_read_unlock();
  8850. }
  8851. link->conf->dtim_period = link->u.mgd.dtim_period ?: 1;
  8852. link->u.mgd.conn = add_links_data->link[link_id].conn;
  8853. if (ieee80211_prep_channel(sdata, link, link_id, cbss,
  8854. true, &link->u.mgd.conn,
  8855. sdata->u.mgd.userspace_selectors)) {
  8856. link_info(link, "mlo: reconf: prep_channel failed\n");
  8857. goto disconnect;
  8858. }
  8859. if (ieee80211_mgd_setup_link_sta(link, sta, link_sta,
  8860. add_links_data->link[link_id].bss))
  8861. goto disconnect;
  8862. if (!ieee80211_assoc_config_link(link, link_sta,
  8863. add_links_data->link[link_id].bss,
  8864. mgmt, pos, len,
  8865. &changed))
  8866. goto disconnect;
  8867. /* The AP MLD indicated success for this link, but the station
  8868. * profile status indicated otherwise. Since there is an
  8869. * inconsistency in the ML reconfiguration response, disconnect
  8870. */
  8871. if (add_links_data->link[link_id].status != WLAN_STATUS_SUCCESS)
  8872. goto disconnect;
  8873. ieee80211_sta_init_nss(link_sta);
  8874. if (ieee80211_sta_activate_link(sta, link_id))
  8875. goto disconnect;
  8876. changed |= ieee80211_link_set_associated(link, cbss);
  8877. ieee80211_link_info_change_notify(sdata, link, changed);
  8878. ieee80211_recalc_smps(sdata, link);
  8879. link_mask |= BIT(link_id);
  8880. }
  8881. sdata_info(sdata,
  8882. "mlo: reconf: current valid_links=0x%x, added=0x%x\n",
  8883. valid_links, link_mask);
  8884. /* links might have changed due to rejected ones, set them again */
  8885. ieee80211_vif_set_links(sdata, valid_links, sdata->vif.dormant_links);
  8886. ieee80211_vif_cfg_change_notify(sdata, BSS_CHANGED_MLD_VALID_LINKS);
  8887. ieee80211_recalc_ps(local);
  8888. ieee80211_recalc_ps_vif(sdata);
  8889. done_data.buf = (const u8 *)mgmt;
  8890. done_data.len = orig_len;
  8891. done_data.added_links = link_mask;
  8892. for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS; link_id++) {
  8893. done_data.links[link_id].bss = add_links_data->link[link_id].bss;
  8894. done_data.links[link_id].addr =
  8895. add_links_data->link[link_id].addr;
  8896. }
  8897. cfg80211_mlo_reconf_add_done(sdata->dev, &done_data);
  8898. kfree(sdata->u.mgd.reconf.add_links_data);
  8899. sdata->u.mgd.reconf.add_links_data = NULL;
  8900. out:
  8901. ieee80211_ml_reconf_reset(sdata);
  8902. return;
  8903. disconnect:
  8904. __ieee80211_disconnect(sdata);
  8905. }
  8906. static struct sk_buff *
  8907. ieee80211_build_ml_reconf_req(struct ieee80211_sub_if_data *sdata,
  8908. struct ieee80211_mgd_assoc_data *add_links_data,
  8909. u16 removed_links, __le16 ext_mld_capa_ops)
  8910. {
  8911. struct ieee80211_local *local = sdata->local;
  8912. struct ieee80211_mgmt *mgmt;
  8913. struct ieee80211_multi_link_elem *ml_elem;
  8914. struct ieee80211_mle_basic_common_info *common;
  8915. enum nl80211_iftype iftype = ieee80211_vif_type_p2p(&sdata->vif);
  8916. struct sk_buff *skb;
  8917. size_t size;
  8918. unsigned int link_id;
  8919. __le16 eml_capa = 0, mld_capa_ops = 0;
  8920. struct ieee80211_tx_info *info;
  8921. u8 common_size, var_common_size;
  8922. u8 *ml_elem_len;
  8923. u16 capab = 0;
  8924. size = local->hw.extra_tx_headroom + sizeof(*mgmt);
  8925. /* Consider the maximal length of the reconfiguration ML element */
  8926. size += sizeof(struct ieee80211_multi_link_elem);
  8927. /* The Basic ML element and the Reconfiguration ML element have the same
  8928. * fixed common information fields in the context of ML reconfiguration
  8929. * action frame. The AP MLD MAC address must always be present
  8930. */
  8931. common_size = sizeof(*common);
  8932. /* when adding links, the MLD capabilities must be present */
  8933. var_common_size = 0;
  8934. if (add_links_data) {
  8935. const struct wiphy_iftype_ext_capab *ift_ext_capa =
  8936. cfg80211_get_iftype_ext_capa(local->hw.wiphy,
  8937. ieee80211_vif_type_p2p(&sdata->vif));
  8938. if (ift_ext_capa) {
  8939. eml_capa = cpu_to_le16(ift_ext_capa->eml_capabilities);
  8940. mld_capa_ops =
  8941. cpu_to_le16(ift_ext_capa->mld_capa_and_ops);
  8942. }
  8943. /* MLD capabilities and operation */
  8944. var_common_size += 2;
  8945. /* EML capabilities */
  8946. if (eml_capa & cpu_to_le16((IEEE80211_EML_CAP_EMLSR_SUPP |
  8947. IEEE80211_EML_CAP_EMLMR_SUPPORT)))
  8948. var_common_size += 2;
  8949. }
  8950. if (ext_mld_capa_ops)
  8951. var_common_size += 2;
  8952. /* Add the common information length */
  8953. size += common_size + var_common_size;
  8954. for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS; link_id++) {
  8955. struct cfg80211_bss *cbss;
  8956. size_t elems_len;
  8957. if (removed_links & BIT(link_id)) {
  8958. size += sizeof(struct ieee80211_mle_per_sta_profile) +
  8959. ETH_ALEN;
  8960. continue;
  8961. }
  8962. if (!add_links_data || !add_links_data->link[link_id].bss)
  8963. continue;
  8964. elems_len = add_links_data->link[link_id].elems_len;
  8965. cbss = add_links_data->link[link_id].bss;
  8966. /* should be the same across all BSSes */
  8967. if (cbss->capability & WLAN_CAPABILITY_PRIVACY)
  8968. capab |= WLAN_CAPABILITY_PRIVACY;
  8969. size += 2 + sizeof(struct ieee80211_mle_per_sta_profile) +
  8970. ETH_ALEN;
  8971. /* WMM */
  8972. size += 9;
  8973. size += ieee80211_link_common_elems_size(sdata, iftype, cbss,
  8974. elems_len);
  8975. }
  8976. skb = alloc_skb(size, GFP_KERNEL);
  8977. if (!skb)
  8978. return NULL;
  8979. skb_reserve(skb, local->hw.extra_tx_headroom);
  8980. mgmt = skb_put_zero(skb, offsetofend(struct ieee80211_mgmt,
  8981. u.action.u.ml_reconf_req));
  8982. /* Add the MAC header */
  8983. mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
  8984. IEEE80211_STYPE_ACTION);
  8985. memcpy(mgmt->da, sdata->vif.cfg.ap_addr, ETH_ALEN);
  8986. memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
  8987. memcpy(mgmt->bssid, sdata->vif.cfg.ap_addr, ETH_ALEN);
  8988. /* Add the action frame fixed fields */
  8989. mgmt->u.action.category = WLAN_CATEGORY_PROTECTED_EHT;
  8990. mgmt->u.action.u.ml_reconf_req.action_code =
  8991. WLAN_PROTECTED_EHT_ACTION_LINK_RECONFIG_REQ;
  8992. /* allocate a dialog token and store it */
  8993. sdata->u.mgd.reconf.dialog_token = ++sdata->u.mgd.dialog_token_alloc;
  8994. mgmt->u.action.u.ml_reconf_req.dialog_token =
  8995. sdata->u.mgd.reconf.dialog_token;
  8996. /* Add the ML reconfiguration element and the common information */
  8997. skb_put_u8(skb, WLAN_EID_EXTENSION);
  8998. ml_elem_len = skb_put(skb, 1);
  8999. skb_put_u8(skb, WLAN_EID_EXT_EHT_MULTI_LINK);
  9000. ml_elem = skb_put(skb, sizeof(*ml_elem));
  9001. ml_elem->control =
  9002. cpu_to_le16(IEEE80211_ML_CONTROL_TYPE_RECONF |
  9003. IEEE80211_MLC_RECONF_PRES_MLD_MAC_ADDR);
  9004. common = skb_put(skb, common_size);
  9005. common->len = common_size + var_common_size;
  9006. memcpy(common->mld_mac_addr, sdata->vif.addr, ETH_ALEN);
  9007. if (add_links_data) {
  9008. if (eml_capa &
  9009. cpu_to_le16((IEEE80211_EML_CAP_EMLSR_SUPP |
  9010. IEEE80211_EML_CAP_EMLMR_SUPPORT))) {
  9011. ml_elem->control |=
  9012. cpu_to_le16(IEEE80211_MLC_RECONF_PRES_EML_CAPA);
  9013. skb_put_data(skb, &eml_capa, sizeof(eml_capa));
  9014. }
  9015. ml_elem->control |=
  9016. cpu_to_le16(IEEE80211_MLC_RECONF_PRES_MLD_CAPA_OP);
  9017. skb_put_data(skb, &mld_capa_ops, sizeof(mld_capa_ops));
  9018. }
  9019. if (ext_mld_capa_ops) {
  9020. ml_elem->control |=
  9021. cpu_to_le16(IEEE80211_MLC_RECONF_PRES_EXT_MLD_CAPA_OP);
  9022. skb_put_data(skb, &ext_mld_capa_ops, sizeof(ext_mld_capa_ops));
  9023. }
  9024. if (sdata->u.mgd.flags & IEEE80211_STA_ENABLE_RRM)
  9025. capab |= WLAN_CAPABILITY_RADIO_MEASURE;
  9026. /* Add the per station profile */
  9027. for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS; link_id++) {
  9028. u8 *subelem_len = NULL;
  9029. u16 ctrl;
  9030. const u8 *addr;
  9031. /* Skip links that are not changing */
  9032. if (!(removed_links & BIT(link_id)) &&
  9033. (!add_links_data || !add_links_data->link[link_id].bss))
  9034. continue;
  9035. ctrl = link_id |
  9036. IEEE80211_MLE_STA_RECONF_CONTROL_STA_MAC_ADDR_PRESENT;
  9037. if (removed_links & BIT(link_id)) {
  9038. struct ieee80211_bss_conf *conf =
  9039. sdata_dereference(sdata->vif.link_conf[link_id],
  9040. sdata);
  9041. if (!conf)
  9042. continue;
  9043. addr = conf->addr;
  9044. ctrl |= u16_encode_bits(IEEE80211_MLE_STA_RECONF_CONTROL_OPERATION_TYPE_DEL_LINK,
  9045. IEEE80211_MLE_STA_RECONF_CONTROL_OPERATION_TYPE);
  9046. } else {
  9047. addr = add_links_data->link[link_id].addr;
  9048. ctrl |= IEEE80211_MLE_STA_RECONF_CONTROL_COMPLETE_PROFILE |
  9049. u16_encode_bits(IEEE80211_MLE_STA_RECONF_CONTROL_OPERATION_TYPE_ADD_LINK,
  9050. IEEE80211_MLE_STA_RECONF_CONTROL_OPERATION_TYPE);
  9051. }
  9052. skb_put_u8(skb, IEEE80211_MLE_SUBELEM_PER_STA_PROFILE);
  9053. subelem_len = skb_put(skb, 1);
  9054. put_unaligned_le16(ctrl, skb_put(skb, sizeof(ctrl)));
  9055. skb_put_u8(skb, 1 + ETH_ALEN);
  9056. skb_put_data(skb, addr, ETH_ALEN);
  9057. if (!(removed_links & BIT(link_id))) {
  9058. u16 link_present_elems[PRESENT_ELEMS_MAX] = {};
  9059. size_t extra_used;
  9060. void *capab_pos;
  9061. u8 qos_info;
  9062. capab_pos = skb_put(skb, 2);
  9063. extra_used =
  9064. ieee80211_add_link_elems(sdata, skb, &capab, NULL,
  9065. add_links_data->link[link_id].elems,
  9066. add_links_data->link[link_id].elems_len,
  9067. link_id, NULL,
  9068. link_present_elems,
  9069. add_links_data);
  9070. if (add_links_data->link[link_id].elems)
  9071. skb_put_data(skb,
  9072. add_links_data->link[link_id].elems +
  9073. extra_used,
  9074. add_links_data->link[link_id].elems_len -
  9075. extra_used);
  9076. if (sdata->u.mgd.flags & IEEE80211_STA_UAPSD_ENABLED) {
  9077. qos_info = sdata->u.mgd.uapsd_queues;
  9078. qos_info |= (sdata->u.mgd.uapsd_max_sp_len <<
  9079. IEEE80211_WMM_IE_STA_QOSINFO_SP_SHIFT);
  9080. } else {
  9081. qos_info = 0;
  9082. }
  9083. ieee80211_add_wmm_info_ie(skb_put(skb, 9), qos_info);
  9084. put_unaligned_le16(capab, capab_pos);
  9085. }
  9086. ieee80211_fragment_element(skb, subelem_len,
  9087. IEEE80211_MLE_SUBELEM_FRAGMENT);
  9088. }
  9089. ieee80211_fragment_element(skb, ml_elem_len, WLAN_EID_FRAGMENT);
  9090. info = IEEE80211_SKB_CB(skb);
  9091. info->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS;
  9092. return skb;
  9093. }
  9094. int ieee80211_mgd_assoc_ml_reconf(struct ieee80211_sub_if_data *sdata,
  9095. struct cfg80211_ml_reconf_req *req)
  9096. {
  9097. struct ieee80211_local *local = sdata->local;
  9098. struct ieee80211_mgd_assoc_data *data = NULL;
  9099. struct sta_info *sta;
  9100. struct sk_buff *skb;
  9101. u16 added_links, new_valid_links;
  9102. int link_id, err;
  9103. if (!ieee80211_vif_is_mld(&sdata->vif) ||
  9104. !(sdata->vif.cfg.mld_capa_op &
  9105. IEEE80211_MLD_CAP_OP_LINK_RECONF_SUPPORT))
  9106. return -EINVAL;
  9107. /* No support for concurrent ML reconfiguration operation */
  9108. if (sdata->u.mgd.reconf.added_links ||
  9109. sdata->u.mgd.reconf.removed_links)
  9110. return -EBUSY;
  9111. added_links = 0;
  9112. for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS; link_id++) {
  9113. if (!req->add_links[link_id].bss)
  9114. continue;
  9115. added_links |= BIT(link_id);
  9116. }
  9117. sta = sta_info_get(sdata, sdata->vif.cfg.ap_addr);
  9118. if (WARN_ON(!sta))
  9119. return -ENOLINK;
  9120. /* Adding links to the set of valid link is done only after a successful
  9121. * ML reconfiguration frame exchange. Here prepare the data for the ML
  9122. * reconfiguration frame construction and allocate the required
  9123. * resources
  9124. */
  9125. if (added_links) {
  9126. bool uapsd_supported;
  9127. data = kzalloc_obj(*data);
  9128. if (!data)
  9129. return -ENOMEM;
  9130. data->assoc_link_id = -1;
  9131. data->wmm = true;
  9132. uapsd_supported = true;
  9133. for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS;
  9134. link_id++) {
  9135. struct ieee80211_supported_band *sband;
  9136. struct cfg80211_bss *link_cbss =
  9137. req->add_links[link_id].bss;
  9138. struct ieee80211_bss *bss;
  9139. if (!link_cbss)
  9140. continue;
  9141. bss = (void *)link_cbss->priv;
  9142. if (!bss->wmm_used) {
  9143. err = -EINVAL;
  9144. goto err_free;
  9145. }
  9146. if (link_cbss->channel->band == NL80211_BAND_S1GHZ) {
  9147. err = -EINVAL;
  9148. goto err_free;
  9149. }
  9150. eth_random_addr(data->link[link_id].addr);
  9151. data->link[link_id].conn =
  9152. ieee80211_conn_settings_unlimited;
  9153. sband =
  9154. local->hw.wiphy->bands[link_cbss->channel->band];
  9155. ieee80211_determine_our_sta_mode(sdata, sband,
  9156. NULL, true, link_id,
  9157. &data->link[link_id].conn);
  9158. data->link[link_id].bss = link_cbss;
  9159. data->link[link_id].elems =
  9160. (u8 *)req->add_links[link_id].elems;
  9161. data->link[link_id].elems_len =
  9162. req->add_links[link_id].elems_len;
  9163. if (!bss->uapsd_supported)
  9164. uapsd_supported = false;
  9165. if (data->link[link_id].conn.mode <
  9166. IEEE80211_CONN_MODE_EHT) {
  9167. err = -EINVAL;
  9168. goto err_free;
  9169. }
  9170. err = ieee80211_mgd_get_ap_ht_vht_capa(sdata, data,
  9171. link_id);
  9172. if (err) {
  9173. err = -EINVAL;
  9174. goto err_free;
  9175. }
  9176. }
  9177. /* Require U-APSD support if we enabled it */
  9178. if (sdata->u.mgd.flags & IEEE80211_STA_UAPSD_ENABLED &&
  9179. !uapsd_supported) {
  9180. err = -EINVAL;
  9181. sdata_info(sdata, "U-APSD on but not available on (all) new links\n");
  9182. goto err_free;
  9183. }
  9184. for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS;
  9185. link_id++) {
  9186. if (!data->link[link_id].bss)
  9187. continue;
  9188. /* only used to verify the mode, nothing is allocated */
  9189. err = ieee80211_prep_channel(sdata, NULL, link_id,
  9190. data->link[link_id].bss,
  9191. true,
  9192. &data->link[link_id].conn,
  9193. sdata->u.mgd.userspace_selectors);
  9194. if (err)
  9195. goto err_free;
  9196. }
  9197. }
  9198. /* link removal is done before the ML reconfiguration frame exchange so
  9199. * that these links will not be used between their removal by the AP MLD
  9200. * and before the station got the ML reconfiguration response. Based on
  9201. * Section 35.3.6.4 in Draft P802.11be_D7.0 the AP MLD should accept the
  9202. * link removal request.
  9203. */
  9204. if (req->rem_links) {
  9205. u16 new_active_links =
  9206. sdata->vif.active_links & ~req->rem_links;
  9207. new_valid_links = sdata->vif.valid_links & ~req->rem_links;
  9208. /* Should not be left with no valid links to perform the
  9209. * ML reconfiguration
  9210. */
  9211. if (!new_valid_links ||
  9212. !(new_valid_links & ~sdata->vif.dormant_links)) {
  9213. sdata_info(sdata, "mlo: reconf: no valid links\n");
  9214. err = -EINVAL;
  9215. goto err_free;
  9216. }
  9217. if (new_active_links != sdata->vif.active_links) {
  9218. if (!new_active_links)
  9219. new_active_links =
  9220. BIT(__ffs(new_valid_links &
  9221. ~sdata->vif.dormant_links));
  9222. err = ieee80211_set_active_links(&sdata->vif,
  9223. new_active_links);
  9224. if (err) {
  9225. sdata_info(sdata,
  9226. "mlo: reconf: failed set active links\n");
  9227. goto err_free;
  9228. }
  9229. }
  9230. }
  9231. /* Build the SKB before the link removal as the construction of the
  9232. * station info for removed links requires the local address.
  9233. * Invalidate the removed links, so that the transmission of the ML
  9234. * reconfiguration request frame would not be done using them, as the AP
  9235. * is expected to send the ML reconfiguration response frame on the link
  9236. * on which the request was received.
  9237. */
  9238. skb = ieee80211_build_ml_reconf_req(sdata, data, req->rem_links,
  9239. cpu_to_le16(req->ext_mld_capa_ops));
  9240. if (!skb) {
  9241. err = -ENOMEM;
  9242. goto err_free;
  9243. }
  9244. if (req->rem_links) {
  9245. u16 new_dormant_links =
  9246. sdata->vif.dormant_links & ~req->rem_links;
  9247. err = ieee80211_vif_set_links(sdata, new_valid_links,
  9248. new_dormant_links);
  9249. if (err) {
  9250. sdata_info(sdata,
  9251. "mlo: reconf: failed set valid links\n");
  9252. kfree_skb(skb);
  9253. goto err_free;
  9254. }
  9255. for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS;
  9256. link_id++) {
  9257. if (!(req->rem_links & BIT(link_id)))
  9258. continue;
  9259. ieee80211_sta_remove_link(sta, link_id);
  9260. }
  9261. /* notify the driver and upper layers */
  9262. ieee80211_vif_cfg_change_notify(sdata,
  9263. BSS_CHANGED_MLD_VALID_LINKS);
  9264. cfg80211_links_removed(sdata->dev, req->rem_links);
  9265. }
  9266. sdata_info(sdata, "mlo: reconf: adding=0x%x, removed=0x%x\n",
  9267. added_links, req->rem_links);
  9268. ieee80211_tx_skb(sdata, skb);
  9269. sdata->u.mgd.reconf.added_links = added_links;
  9270. sdata->u.mgd.reconf.add_links_data = data;
  9271. sdata->u.mgd.reconf.removed_links = req->rem_links;
  9272. wiphy_delayed_work_queue(sdata->local->hw.wiphy,
  9273. &sdata->u.mgd.reconf.wk,
  9274. IEEE80211_ASSOC_TIMEOUT_SHORT);
  9275. return 0;
  9276. err_free:
  9277. kfree(data);
  9278. return err;
  9279. }
  9280. static bool ieee80211_mgd_epcs_supp(struct ieee80211_sub_if_data *sdata)
  9281. {
  9282. unsigned long valid_links = sdata->vif.valid_links;
  9283. u8 link_id;
  9284. lockdep_assert_wiphy(sdata->local->hw.wiphy);
  9285. if (!ieee80211_vif_is_mld(&sdata->vif))
  9286. return false;
  9287. for_each_set_bit(link_id, &valid_links, IEEE80211_MLD_MAX_NUM_LINKS) {
  9288. struct ieee80211_bss_conf *bss_conf =
  9289. sdata_dereference(sdata->vif.link_conf[link_id], sdata);
  9290. if (WARN_ON(!bss_conf) || !bss_conf->epcs_support)
  9291. return false;
  9292. }
  9293. return true;
  9294. }
  9295. int ieee80211_mgd_set_epcs(struct ieee80211_sub_if_data *sdata, bool enable)
  9296. {
  9297. struct ieee80211_local *local = sdata->local;
  9298. struct ieee80211_mgmt *mgmt;
  9299. struct sk_buff *skb;
  9300. int frame_len = offsetofend(struct ieee80211_mgmt,
  9301. u.action.u.epcs) + (enable ? 1 : 0);
  9302. if (!ieee80211_mgd_epcs_supp(sdata))
  9303. return -EINVAL;
  9304. if (sdata->u.mgd.epcs.enabled == enable &&
  9305. !sdata->u.mgd.epcs.dialog_token)
  9306. return 0;
  9307. /* Do not allow enabling EPCS if the AP didn't respond yet.
  9308. * However, allow disabling EPCS in such a case.
  9309. */
  9310. if (sdata->u.mgd.epcs.dialog_token && enable)
  9311. return -EALREADY;
  9312. skb = dev_alloc_skb(local->hw.extra_tx_headroom + frame_len);
  9313. if (!skb)
  9314. return -ENOBUFS;
  9315. skb_reserve(skb, local->hw.extra_tx_headroom);
  9316. mgmt = skb_put_zero(skb, frame_len);
  9317. mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
  9318. IEEE80211_STYPE_ACTION);
  9319. memcpy(mgmt->da, sdata->vif.cfg.ap_addr, ETH_ALEN);
  9320. memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
  9321. memcpy(mgmt->bssid, sdata->vif.cfg.ap_addr, ETH_ALEN);
  9322. mgmt->u.action.category = WLAN_CATEGORY_PROTECTED_EHT;
  9323. if (enable) {
  9324. u8 *pos = mgmt->u.action.u.epcs.variable;
  9325. mgmt->u.action.u.epcs.action_code =
  9326. WLAN_PROTECTED_EHT_ACTION_EPCS_ENABLE_REQ;
  9327. *pos = ++sdata->u.mgd.dialog_token_alloc;
  9328. sdata->u.mgd.epcs.dialog_token = *pos;
  9329. } else {
  9330. mgmt->u.action.u.epcs.action_code =
  9331. WLAN_PROTECTED_EHT_ACTION_EPCS_ENABLE_TEARDOWN;
  9332. ieee80211_epcs_teardown(sdata);
  9333. ieee80211_epcs_changed(sdata, false);
  9334. }
  9335. ieee80211_tx_skb(sdata, skb);
  9336. return 0;
  9337. }
  9338. static void ieee80211_ml_epcs(struct ieee80211_sub_if_data *sdata,
  9339. struct ieee802_11_elems *elems)
  9340. {
  9341. const struct element *sub;
  9342. size_t scratch_len = elems->ml_epcs_len;
  9343. u8 *scratch __free(kfree) = kzalloc(scratch_len, GFP_KERNEL);
  9344. lockdep_assert_wiphy(sdata->local->hw.wiphy);
  9345. if (!ieee80211_vif_is_mld(&sdata->vif) || !elems->ml_epcs)
  9346. return;
  9347. if (WARN_ON(!scratch))
  9348. return;
  9349. /* Directly parse the sub elements as the common information doesn't
  9350. * hold any useful information.
  9351. */
  9352. for_each_mle_subelement(sub, (const u8 *)elems->ml_epcs,
  9353. elems->ml_epcs_len) {
  9354. struct ieee802_11_elems *link_elems __free(kfree) = NULL;
  9355. struct ieee80211_link_data *link;
  9356. u8 *pos = (void *)sub->data;
  9357. u16 control;
  9358. ssize_t len;
  9359. u8 link_id;
  9360. if (sub->id != IEEE80211_MLE_SUBELEM_PER_STA_PROFILE)
  9361. continue;
  9362. if (sub->datalen < sizeof(control))
  9363. break;
  9364. control = get_unaligned_le16(pos);
  9365. link_id = control & IEEE80211_MLE_STA_EPCS_CONTROL_LINK_ID;
  9366. link = sdata_dereference(sdata->link[link_id], sdata);
  9367. if (!link)
  9368. continue;
  9369. len = cfg80211_defragment_element(sub, (u8 *)elems->ml_epcs,
  9370. elems->ml_epcs_len,
  9371. scratch, scratch_len,
  9372. IEEE80211_MLE_SUBELEM_FRAGMENT);
  9373. if (len < (ssize_t)sizeof(control))
  9374. continue;
  9375. pos = scratch + sizeof(control);
  9376. len -= sizeof(control);
  9377. link_elems = ieee802_11_parse_elems(pos, len,
  9378. IEEE80211_FTYPE_MGMT |
  9379. IEEE80211_STYPE_ACTION,
  9380. NULL);
  9381. if (!link_elems)
  9382. continue;
  9383. if (ieee80211_sta_wmm_params(sdata->local, link,
  9384. link_elems->wmm_param,
  9385. link_elems->wmm_param_len,
  9386. link_elems->mu_edca_param_set))
  9387. ieee80211_link_info_change_notify(sdata, link,
  9388. BSS_CHANGED_QOS);
  9389. }
  9390. }
  9391. void ieee80211_process_epcs_ena_resp(struct ieee80211_sub_if_data *sdata,
  9392. struct ieee80211_mgmt *mgmt, size_t len)
  9393. {
  9394. struct ieee802_11_elems *elems __free(kfree) = NULL;
  9395. size_t ies_len;
  9396. u16 status_code;
  9397. u8 *pos, dialog_token;
  9398. if (!ieee80211_mgd_epcs_supp(sdata))
  9399. return;
  9400. /* Handle dialog token and status code */
  9401. pos = mgmt->u.action.u.epcs.variable;
  9402. dialog_token = *pos;
  9403. status_code = get_unaligned_le16(pos + 1);
  9404. /* An EPCS enable response with dialog token == 0 is an unsolicited
  9405. * notification from the AP MLD. In such a case, EPCS should already be
  9406. * enabled and status must be success
  9407. */
  9408. if (!dialog_token &&
  9409. (!sdata->u.mgd.epcs.enabled ||
  9410. status_code != WLAN_STATUS_SUCCESS))
  9411. return;
  9412. if (sdata->u.mgd.epcs.dialog_token != dialog_token)
  9413. return;
  9414. sdata->u.mgd.epcs.dialog_token = 0;
  9415. if (status_code != WLAN_STATUS_SUCCESS)
  9416. return;
  9417. pos += IEEE80211_EPCS_ENA_RESP_BODY_LEN;
  9418. ies_len = len - offsetof(struct ieee80211_mgmt,
  9419. u.action.u.epcs.variable) -
  9420. IEEE80211_EPCS_ENA_RESP_BODY_LEN;
  9421. elems = ieee802_11_parse_elems(pos, ies_len,
  9422. IEEE80211_FTYPE_MGMT |
  9423. IEEE80211_STYPE_ACTION,
  9424. NULL);
  9425. if (!elems)
  9426. return;
  9427. ieee80211_ml_epcs(sdata, elems);
  9428. ieee80211_epcs_changed(sdata, true);
  9429. }
  9430. void ieee80211_process_epcs_teardown(struct ieee80211_sub_if_data *sdata,
  9431. struct ieee80211_mgmt *mgmt, size_t len)
  9432. {
  9433. if (!ieee80211_vif_is_mld(&sdata->vif) ||
  9434. !sdata->u.mgd.epcs.enabled)
  9435. return;
  9436. ieee80211_epcs_teardown(sdata);
  9437. ieee80211_epcs_changed(sdata, false);
  9438. }