mlme.c 268 KB

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