mlme.c 214 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * BSS client mode implementation
  4. * Copyright 2003-2008, Jouni Malinen <[email protected]>
  5. * Copyright 2004, Instant802 Networks, Inc.
  6. * Copyright 2005, Devicescape Software, Inc.
  7. * Copyright 2006-2007 Jiri Benc <[email protected]>
  8. * Copyright 2007, Michael Wu <[email protected]>
  9. * Copyright 2013-2014 Intel Mobile Communications GmbH
  10. * Copyright (C) 2015 - 2017 Intel Deutschland GmbH
  11. * Copyright (C) 2018 - 2022 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 <asm/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. static int max_nullfunc_tries = 2;
  43. module_param(max_nullfunc_tries, int, 0644);
  44. MODULE_PARM_DESC(max_nullfunc_tries,
  45. "Maximum nullfunc tx tries before disconnecting (reason 4).");
  46. static int max_probe_tries = 5;
  47. module_param(max_probe_tries, int, 0644);
  48. MODULE_PARM_DESC(max_probe_tries,
  49. "Maximum probe tries before disconnecting (reason 4).");
  50. /*
  51. * Beacon loss timeout is calculated as N frames times the
  52. * advertised beacon interval. This may need to be somewhat
  53. * higher than what hardware might detect to account for
  54. * delays in the host processing frames. But since we also
  55. * probe on beacon miss before declaring the connection lost
  56. * default to what we want.
  57. */
  58. static int beacon_loss_count = 7;
  59. module_param(beacon_loss_count, int, 0644);
  60. MODULE_PARM_DESC(beacon_loss_count,
  61. "Number of beacon intervals before we decide beacon was lost.");
  62. /*
  63. * Time the connection can be idle before we probe
  64. * it to see if we can still talk to the AP.
  65. */
  66. #define IEEE80211_CONNECTION_IDLE_TIME (30 * HZ)
  67. /*
  68. * Time we wait for a probe response after sending
  69. * a probe request because of beacon loss or for
  70. * checking the connection still works.
  71. */
  72. static int probe_wait_ms = 500;
  73. module_param(probe_wait_ms, int, 0644);
  74. MODULE_PARM_DESC(probe_wait_ms,
  75. "Maximum time(ms) to wait for probe response"
  76. " before disconnecting (reason 4).");
  77. /*
  78. * How many Beacon frames need to have been used in average signal strength
  79. * before starting to indicate signal change events.
  80. */
  81. #define IEEE80211_SIGNAL_AVE_MIN_COUNT 4
  82. /*
  83. * We can have multiple work items (and connection probing)
  84. * scheduling this timer, but we need to take care to only
  85. * reschedule it when it should fire _earlier_ than it was
  86. * asked for before, or if it's not pending right now. This
  87. * function ensures that. Note that it then is required to
  88. * run this function for all timeouts after the first one
  89. * has happened -- the work that runs from this timer will
  90. * do that.
  91. */
  92. static void run_again(struct ieee80211_sub_if_data *sdata,
  93. unsigned long timeout)
  94. {
  95. sdata_assert_lock(sdata);
  96. if (!timer_pending(&sdata->u.mgd.timer) ||
  97. time_before(timeout, sdata->u.mgd.timer.expires))
  98. mod_timer(&sdata->u.mgd.timer, timeout);
  99. }
  100. void ieee80211_sta_reset_beacon_monitor(struct ieee80211_sub_if_data *sdata)
  101. {
  102. if (sdata->vif.driver_flags & IEEE80211_VIF_BEACON_FILTER)
  103. return;
  104. if (ieee80211_hw_check(&sdata->local->hw, CONNECTION_MONITOR))
  105. return;
  106. mod_timer(&sdata->u.mgd.bcn_mon_timer,
  107. round_jiffies_up(jiffies + sdata->u.mgd.beacon_timeout));
  108. }
  109. void ieee80211_sta_reset_conn_monitor(struct ieee80211_sub_if_data *sdata)
  110. {
  111. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  112. if (unlikely(!ifmgd->associated))
  113. return;
  114. if (ifmgd->probe_send_count)
  115. ifmgd->probe_send_count = 0;
  116. if (ieee80211_hw_check(&sdata->local->hw, CONNECTION_MONITOR))
  117. return;
  118. mod_timer(&ifmgd->conn_mon_timer,
  119. round_jiffies_up(jiffies + IEEE80211_CONNECTION_IDLE_TIME));
  120. }
  121. static int ecw2cw(int ecw)
  122. {
  123. return (1 << ecw) - 1;
  124. }
  125. static ieee80211_conn_flags_t
  126. ieee80211_determine_chantype(struct ieee80211_sub_if_data *sdata,
  127. struct ieee80211_link_data *link,
  128. ieee80211_conn_flags_t conn_flags,
  129. struct ieee80211_supported_band *sband,
  130. struct ieee80211_channel *channel,
  131. u32 vht_cap_info,
  132. const struct ieee80211_ht_operation *ht_oper,
  133. const struct ieee80211_vht_operation *vht_oper,
  134. const struct ieee80211_he_operation *he_oper,
  135. const struct ieee80211_eht_operation *eht_oper,
  136. const struct ieee80211_s1g_oper_ie *s1g_oper,
  137. struct cfg80211_chan_def *chandef, bool tracking)
  138. {
  139. struct cfg80211_chan_def vht_chandef;
  140. struct ieee80211_sta_ht_cap sta_ht_cap;
  141. ieee80211_conn_flags_t ret;
  142. u32 ht_cfreq;
  143. memset(chandef, 0, sizeof(struct cfg80211_chan_def));
  144. chandef->chan = channel;
  145. chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
  146. chandef->center_freq1 = channel->center_freq;
  147. chandef->freq1_offset = channel->freq_offset;
  148. if (channel->band == NL80211_BAND_6GHZ) {
  149. if (!ieee80211_chandef_he_6ghz_oper(sdata, he_oper, eht_oper,
  150. chandef)) {
  151. mlme_dbg(sdata,
  152. "bad 6 GHz operation, disabling HT/VHT/HE/EHT\n");
  153. ret = IEEE80211_CONN_DISABLE_HT |
  154. IEEE80211_CONN_DISABLE_VHT |
  155. IEEE80211_CONN_DISABLE_HE |
  156. IEEE80211_CONN_DISABLE_EHT;
  157. } else {
  158. ret = 0;
  159. }
  160. vht_chandef = *chandef;
  161. goto out;
  162. } else if (sband->band == NL80211_BAND_S1GHZ) {
  163. if (!ieee80211_chandef_s1g_oper(s1g_oper, chandef)) {
  164. sdata_info(sdata,
  165. "Missing S1G Operation Element? Trying operating == primary\n");
  166. chandef->width = ieee80211_s1g_channel_width(channel);
  167. }
  168. ret = IEEE80211_CONN_DISABLE_HT | IEEE80211_CONN_DISABLE_40MHZ |
  169. IEEE80211_CONN_DISABLE_VHT |
  170. IEEE80211_CONN_DISABLE_80P80MHZ |
  171. IEEE80211_CONN_DISABLE_160MHZ;
  172. goto out;
  173. }
  174. memcpy(&sta_ht_cap, &sband->ht_cap, sizeof(sta_ht_cap));
  175. ieee80211_apply_htcap_overrides(sdata, &sta_ht_cap);
  176. if (!ht_oper || !sta_ht_cap.ht_supported) {
  177. mlme_dbg(sdata, "HT operation missing / HT not supported\n");
  178. ret = IEEE80211_CONN_DISABLE_HT |
  179. IEEE80211_CONN_DISABLE_VHT |
  180. IEEE80211_CONN_DISABLE_HE |
  181. IEEE80211_CONN_DISABLE_EHT;
  182. goto out;
  183. }
  184. chandef->width = NL80211_CHAN_WIDTH_20;
  185. ht_cfreq = ieee80211_channel_to_frequency(ht_oper->primary_chan,
  186. channel->band);
  187. /* check that channel matches the right operating channel */
  188. if (!tracking && channel->center_freq != ht_cfreq) {
  189. /*
  190. * It's possible that some APs are confused here;
  191. * Netgear WNDR3700 sometimes reports 4 higher than
  192. * the actual channel in association responses, but
  193. * since we look at probe response/beacon data here
  194. * it should be OK.
  195. */
  196. sdata_info(sdata,
  197. "Wrong control channel: center-freq: %d ht-cfreq: %d ht->primary_chan: %d band: %d - Disabling HT\n",
  198. channel->center_freq, ht_cfreq,
  199. ht_oper->primary_chan, channel->band);
  200. ret = IEEE80211_CONN_DISABLE_HT |
  201. IEEE80211_CONN_DISABLE_VHT |
  202. IEEE80211_CONN_DISABLE_HE |
  203. IEEE80211_CONN_DISABLE_EHT;
  204. goto out;
  205. }
  206. /* check 40 MHz support, if we have it */
  207. if (sta_ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) {
  208. ieee80211_chandef_ht_oper(ht_oper, chandef);
  209. } else {
  210. mlme_dbg(sdata, "40 MHz not supported\n");
  211. /* 40 MHz (and 80 MHz) must be supported for VHT */
  212. ret = IEEE80211_CONN_DISABLE_VHT;
  213. /* also mark 40 MHz disabled */
  214. ret |= IEEE80211_CONN_DISABLE_40MHZ;
  215. goto out;
  216. }
  217. if (!vht_oper || !sband->vht_cap.vht_supported) {
  218. mlme_dbg(sdata, "VHT operation missing / VHT not supported\n");
  219. ret = IEEE80211_CONN_DISABLE_VHT;
  220. goto out;
  221. }
  222. vht_chandef = *chandef;
  223. if (!(conn_flags & IEEE80211_CONN_DISABLE_HE) &&
  224. he_oper &&
  225. (le32_to_cpu(he_oper->he_oper_params) &
  226. IEEE80211_HE_OPERATION_VHT_OPER_INFO)) {
  227. struct ieee80211_vht_operation he_oper_vht_cap;
  228. /*
  229. * Set only first 3 bytes (other 2 aren't used in
  230. * ieee80211_chandef_vht_oper() anyway)
  231. */
  232. memcpy(&he_oper_vht_cap, he_oper->optional, 3);
  233. he_oper_vht_cap.basic_mcs_set = cpu_to_le16(0);
  234. if (!ieee80211_chandef_vht_oper(&sdata->local->hw, vht_cap_info,
  235. &he_oper_vht_cap, ht_oper,
  236. &vht_chandef)) {
  237. if (!(conn_flags & IEEE80211_CONN_DISABLE_HE))
  238. sdata_info(sdata,
  239. "HE AP VHT information is invalid, disabling HE\n");
  240. ret = IEEE80211_CONN_DISABLE_HE | IEEE80211_CONN_DISABLE_EHT;
  241. goto out;
  242. }
  243. } else if (!ieee80211_chandef_vht_oper(&sdata->local->hw,
  244. vht_cap_info,
  245. vht_oper, ht_oper,
  246. &vht_chandef)) {
  247. if (!(conn_flags & IEEE80211_CONN_DISABLE_VHT))
  248. sdata_info(sdata,
  249. "AP VHT information is invalid, disabling VHT\n");
  250. ret = IEEE80211_CONN_DISABLE_VHT;
  251. goto out;
  252. }
  253. if (!cfg80211_chandef_valid(&vht_chandef)) {
  254. if (!(conn_flags & IEEE80211_CONN_DISABLE_VHT))
  255. sdata_info(sdata,
  256. "AP VHT information is invalid, disabling VHT\n");
  257. ret = IEEE80211_CONN_DISABLE_VHT;
  258. goto out;
  259. }
  260. if (cfg80211_chandef_identical(chandef, &vht_chandef)) {
  261. ret = 0;
  262. goto out;
  263. }
  264. if (!cfg80211_chandef_compatible(chandef, &vht_chandef)) {
  265. if (!(conn_flags & IEEE80211_CONN_DISABLE_VHT))
  266. sdata_info(sdata,
  267. "AP VHT information doesn't match HT, disabling VHT\n");
  268. ret = IEEE80211_CONN_DISABLE_VHT;
  269. goto out;
  270. }
  271. *chandef = vht_chandef;
  272. /*
  273. * handle the case that the EHT operation indicates that it holds EHT
  274. * operation information (in case that the channel width differs from
  275. * the channel width reported in HT/VHT/HE).
  276. */
  277. if (eht_oper && (eht_oper->params & IEEE80211_EHT_OPER_INFO_PRESENT)) {
  278. struct cfg80211_chan_def eht_chandef = *chandef;
  279. ieee80211_chandef_eht_oper(eht_oper,
  280. eht_chandef.width ==
  281. NL80211_CHAN_WIDTH_160,
  282. false, &eht_chandef);
  283. if (!cfg80211_chandef_valid(&eht_chandef)) {
  284. if (!(conn_flags & IEEE80211_CONN_DISABLE_EHT))
  285. sdata_info(sdata,
  286. "AP EHT information is invalid, disabling EHT\n");
  287. ret = IEEE80211_CONN_DISABLE_EHT;
  288. goto out;
  289. }
  290. if (!cfg80211_chandef_compatible(chandef, &eht_chandef)) {
  291. if (!(conn_flags & IEEE80211_CONN_DISABLE_EHT))
  292. sdata_info(sdata,
  293. "AP EHT information is incompatible, disabling EHT\n");
  294. ret = IEEE80211_CONN_DISABLE_EHT;
  295. goto out;
  296. }
  297. *chandef = eht_chandef;
  298. }
  299. ret = 0;
  300. out:
  301. /*
  302. * When tracking the current AP, don't do any further checks if the
  303. * new chandef is identical to the one we're currently using for the
  304. * connection. This keeps us from playing ping-pong with regulatory,
  305. * without it the following can happen (for example):
  306. * - connect to an AP with 80 MHz, world regdom allows 80 MHz
  307. * - AP advertises regdom US
  308. * - CRDA loads regdom US with 80 MHz prohibited (old database)
  309. * - the code below detects an unsupported channel, downgrades, and
  310. * we disconnect from the AP in the caller
  311. * - disconnect causes CRDA to reload world regdomain and the game
  312. * starts anew.
  313. * (see https://bugzilla.kernel.org/show_bug.cgi?id=70881)
  314. *
  315. * It seems possible that there are still scenarios with CSA or real
  316. * bandwidth changes where a this could happen, but those cases are
  317. * less common and wouldn't completely prevent using the AP.
  318. */
  319. if (tracking &&
  320. cfg80211_chandef_identical(chandef, &link->conf->chandef))
  321. return ret;
  322. /* don't print the message below for VHT mismatch if VHT is disabled */
  323. if (ret & IEEE80211_CONN_DISABLE_VHT)
  324. vht_chandef = *chandef;
  325. /*
  326. * Ignore the DISABLED flag when we're already connected and only
  327. * tracking the APs beacon for bandwidth changes - otherwise we
  328. * might get disconnected here if we connect to an AP, update our
  329. * regulatory information based on the AP's country IE and the
  330. * information we have is wrong/outdated and disables the channel
  331. * that we're actually using for the connection to the AP.
  332. */
  333. while (!cfg80211_chandef_usable(sdata->local->hw.wiphy, chandef,
  334. tracking ? 0 :
  335. IEEE80211_CHAN_DISABLED)) {
  336. if (WARN_ON(chandef->width == NL80211_CHAN_WIDTH_20_NOHT)) {
  337. ret = IEEE80211_CONN_DISABLE_HT |
  338. IEEE80211_CONN_DISABLE_VHT |
  339. IEEE80211_CONN_DISABLE_HE |
  340. IEEE80211_CONN_DISABLE_EHT;
  341. break;
  342. }
  343. ret |= ieee80211_chandef_downgrade(chandef);
  344. }
  345. if (!he_oper || !cfg80211_chandef_usable(sdata->wdev.wiphy, chandef,
  346. IEEE80211_CHAN_NO_HE))
  347. ret |= IEEE80211_CONN_DISABLE_HE | IEEE80211_CONN_DISABLE_EHT;
  348. if (!eht_oper || !cfg80211_chandef_usable(sdata->wdev.wiphy, chandef,
  349. IEEE80211_CHAN_NO_EHT))
  350. ret |= IEEE80211_CONN_DISABLE_EHT;
  351. if (chandef->width != vht_chandef.width && !tracking)
  352. sdata_info(sdata,
  353. "capabilities/regulatory prevented using AP HT/VHT configuration, downgraded\n");
  354. WARN_ON_ONCE(!cfg80211_chandef_valid(chandef));
  355. return ret;
  356. }
  357. static int ieee80211_config_bw(struct ieee80211_link_data *link,
  358. const struct ieee80211_ht_cap *ht_cap,
  359. const struct ieee80211_vht_cap *vht_cap,
  360. const struct ieee80211_ht_operation *ht_oper,
  361. const struct ieee80211_vht_operation *vht_oper,
  362. const struct ieee80211_he_operation *he_oper,
  363. const struct ieee80211_eht_operation *eht_oper,
  364. const struct ieee80211_s1g_oper_ie *s1g_oper,
  365. const u8 *bssid, u32 *changed)
  366. {
  367. struct ieee80211_sub_if_data *sdata = link->sdata;
  368. struct ieee80211_local *local = sdata->local;
  369. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  370. struct ieee80211_channel *chan = link->conf->chandef.chan;
  371. struct ieee80211_supported_band *sband =
  372. local->hw.wiphy->bands[chan->band];
  373. struct cfg80211_chan_def chandef;
  374. u16 ht_opmode;
  375. ieee80211_conn_flags_t flags;
  376. u32 vht_cap_info = 0;
  377. int ret;
  378. /* if HT was/is disabled, don't track any bandwidth changes */
  379. if (link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_HT || !ht_oper)
  380. return 0;
  381. /* don't check VHT if we associated as non-VHT station */
  382. if (link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_VHT)
  383. vht_oper = NULL;
  384. /* don't check HE if we associated as non-HE station */
  385. if (link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_HE ||
  386. !ieee80211_get_he_iftype_cap(sband,
  387. ieee80211_vif_type_p2p(&sdata->vif))) {
  388. he_oper = NULL;
  389. eht_oper = NULL;
  390. }
  391. /* don't check EHT if we associated as non-EHT station */
  392. if (link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_EHT ||
  393. !ieee80211_get_eht_iftype_cap(sband,
  394. ieee80211_vif_type_p2p(&sdata->vif)))
  395. eht_oper = NULL;
  396. /*
  397. * if bss configuration changed store the new one -
  398. * this may be applicable even if channel is identical
  399. */
  400. ht_opmode = le16_to_cpu(ht_oper->operation_mode);
  401. if (link->conf->ht_operation_mode != ht_opmode) {
  402. *changed |= BSS_CHANGED_HT;
  403. link->conf->ht_operation_mode = ht_opmode;
  404. }
  405. if (vht_cap)
  406. vht_cap_info = le32_to_cpu(vht_cap->vht_cap_info);
  407. /* calculate new channel (type) based on HT/VHT/HE operation IEs */
  408. flags = ieee80211_determine_chantype(sdata, link,
  409. link->u.mgd.conn_flags,
  410. sband, chan, vht_cap_info,
  411. ht_oper, vht_oper,
  412. he_oper, eht_oper,
  413. s1g_oper, &chandef, true);
  414. /*
  415. * Downgrade the new channel if we associated with restricted
  416. * capabilities. For example, if we associated as a 20 MHz STA
  417. * to a 40 MHz AP (due to regulatory, capabilities or config
  418. * reasons) then switching to a 40 MHz channel now won't do us
  419. * any good -- we couldn't use it with the AP.
  420. */
  421. if (link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_80P80MHZ &&
  422. chandef.width == NL80211_CHAN_WIDTH_80P80)
  423. flags |= ieee80211_chandef_downgrade(&chandef);
  424. if (link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_160MHZ &&
  425. chandef.width == NL80211_CHAN_WIDTH_160)
  426. flags |= ieee80211_chandef_downgrade(&chandef);
  427. if (link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_40MHZ &&
  428. chandef.width > NL80211_CHAN_WIDTH_20)
  429. flags |= ieee80211_chandef_downgrade(&chandef);
  430. if (cfg80211_chandef_identical(&chandef, &link->conf->chandef))
  431. return 0;
  432. link_info(link,
  433. "AP %pM changed bandwidth, new config is %d.%03d MHz, width %d (%d.%03d/%d MHz)\n",
  434. link->u.mgd.bssid, chandef.chan->center_freq,
  435. chandef.chan->freq_offset, chandef.width,
  436. chandef.center_freq1, chandef.freq1_offset,
  437. chandef.center_freq2);
  438. if (flags != (link->u.mgd.conn_flags &
  439. (IEEE80211_CONN_DISABLE_HT |
  440. IEEE80211_CONN_DISABLE_VHT |
  441. IEEE80211_CONN_DISABLE_HE |
  442. IEEE80211_CONN_DISABLE_EHT |
  443. IEEE80211_CONN_DISABLE_40MHZ |
  444. IEEE80211_CONN_DISABLE_80P80MHZ |
  445. IEEE80211_CONN_DISABLE_160MHZ |
  446. IEEE80211_CONN_DISABLE_320MHZ)) ||
  447. !cfg80211_chandef_valid(&chandef)) {
  448. sdata_info(sdata,
  449. "AP %pM changed caps/bw in a way we can't support (0x%x/0x%x) - disconnect\n",
  450. link->u.mgd.bssid, flags, ifmgd->flags);
  451. return -EINVAL;
  452. }
  453. ret = ieee80211_link_change_bandwidth(link, &chandef, changed);
  454. if (ret) {
  455. sdata_info(sdata,
  456. "AP %pM changed bandwidth to incompatible one - disconnect\n",
  457. link->u.mgd.bssid);
  458. return ret;
  459. }
  460. return 0;
  461. }
  462. /* frame sending functions */
  463. static void ieee80211_add_ht_ie(struct ieee80211_sub_if_data *sdata,
  464. struct sk_buff *skb, u8 ap_ht_param,
  465. struct ieee80211_supported_band *sband,
  466. struct ieee80211_channel *channel,
  467. enum ieee80211_smps_mode smps,
  468. ieee80211_conn_flags_t conn_flags)
  469. {
  470. u8 *pos;
  471. u32 flags = channel->flags;
  472. u16 cap;
  473. struct ieee80211_sta_ht_cap ht_cap;
  474. BUILD_BUG_ON(sizeof(ht_cap) != sizeof(sband->ht_cap));
  475. memcpy(&ht_cap, &sband->ht_cap, sizeof(ht_cap));
  476. ieee80211_apply_htcap_overrides(sdata, &ht_cap);
  477. /* determine capability flags */
  478. cap = ht_cap.cap;
  479. switch (ap_ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET) {
  480. case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
  481. if (flags & IEEE80211_CHAN_NO_HT40PLUS) {
  482. cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
  483. cap &= ~IEEE80211_HT_CAP_SGI_40;
  484. }
  485. break;
  486. case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
  487. if (flags & IEEE80211_CHAN_NO_HT40MINUS) {
  488. cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
  489. cap &= ~IEEE80211_HT_CAP_SGI_40;
  490. }
  491. break;
  492. }
  493. /*
  494. * If 40 MHz was disabled associate as though we weren't
  495. * capable of 40 MHz -- some broken APs will never fall
  496. * back to trying to transmit in 20 MHz.
  497. */
  498. if (conn_flags & IEEE80211_CONN_DISABLE_40MHZ) {
  499. cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
  500. cap &= ~IEEE80211_HT_CAP_SGI_40;
  501. }
  502. /* set SM PS mode properly */
  503. cap &= ~IEEE80211_HT_CAP_SM_PS;
  504. switch (smps) {
  505. case IEEE80211_SMPS_AUTOMATIC:
  506. case IEEE80211_SMPS_NUM_MODES:
  507. WARN_ON(1);
  508. fallthrough;
  509. case IEEE80211_SMPS_OFF:
  510. cap |= WLAN_HT_CAP_SM_PS_DISABLED <<
  511. IEEE80211_HT_CAP_SM_PS_SHIFT;
  512. break;
  513. case IEEE80211_SMPS_STATIC:
  514. cap |= WLAN_HT_CAP_SM_PS_STATIC <<
  515. IEEE80211_HT_CAP_SM_PS_SHIFT;
  516. break;
  517. case IEEE80211_SMPS_DYNAMIC:
  518. cap |= WLAN_HT_CAP_SM_PS_DYNAMIC <<
  519. IEEE80211_HT_CAP_SM_PS_SHIFT;
  520. break;
  521. }
  522. /* reserve and fill IE */
  523. pos = skb_put(skb, sizeof(struct ieee80211_ht_cap) + 2);
  524. ieee80211_ie_build_ht_cap(pos, &ht_cap, cap);
  525. }
  526. /* This function determines vht capability flags for the association
  527. * and builds the IE.
  528. * Note - the function returns true to own the MU-MIMO capability
  529. */
  530. static bool ieee80211_add_vht_ie(struct ieee80211_sub_if_data *sdata,
  531. struct sk_buff *skb,
  532. struct ieee80211_supported_band *sband,
  533. struct ieee80211_vht_cap *ap_vht_cap,
  534. ieee80211_conn_flags_t conn_flags)
  535. {
  536. struct ieee80211_local *local = sdata->local;
  537. u8 *pos;
  538. u32 cap;
  539. struct ieee80211_sta_vht_cap vht_cap;
  540. u32 mask, ap_bf_sts, our_bf_sts;
  541. bool mu_mimo_owner = false;
  542. BUILD_BUG_ON(sizeof(vht_cap) != sizeof(sband->vht_cap));
  543. memcpy(&vht_cap, &sband->vht_cap, sizeof(vht_cap));
  544. ieee80211_apply_vhtcap_overrides(sdata, &vht_cap);
  545. /* determine capability flags */
  546. cap = vht_cap.cap;
  547. if (conn_flags & IEEE80211_CONN_DISABLE_80P80MHZ) {
  548. u32 bw = cap & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK;
  549. cap &= ~IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK;
  550. if (bw == IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ ||
  551. bw == IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ)
  552. cap |= IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
  553. }
  554. if (conn_flags & IEEE80211_CONN_DISABLE_160MHZ) {
  555. cap &= ~IEEE80211_VHT_CAP_SHORT_GI_160;
  556. cap &= ~IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK;
  557. }
  558. /*
  559. * Some APs apparently get confused if our capabilities are better
  560. * than theirs, so restrict what we advertise in the assoc request.
  561. */
  562. if (!(ap_vht_cap->vht_cap_info &
  563. cpu_to_le32(IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)))
  564. cap &= ~(IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
  565. IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE);
  566. else if (!(ap_vht_cap->vht_cap_info &
  567. cpu_to_le32(IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)))
  568. cap &= ~IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
  569. /*
  570. * If some other vif is using the MU-MIMO capability we cannot associate
  571. * using MU-MIMO - this will lead to contradictions in the group-id
  572. * mechanism.
  573. * Ownership is defined since association request, in order to avoid
  574. * simultaneous associations with MU-MIMO.
  575. */
  576. if (cap & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE) {
  577. bool disable_mu_mimo = false;
  578. struct ieee80211_sub_if_data *other;
  579. list_for_each_entry_rcu(other, &local->interfaces, list) {
  580. if (other->vif.bss_conf.mu_mimo_owner) {
  581. disable_mu_mimo = true;
  582. break;
  583. }
  584. }
  585. if (disable_mu_mimo)
  586. cap &= ~IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
  587. else
  588. mu_mimo_owner = true;
  589. }
  590. mask = IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK;
  591. ap_bf_sts = le32_to_cpu(ap_vht_cap->vht_cap_info) & mask;
  592. our_bf_sts = cap & mask;
  593. if (ap_bf_sts < our_bf_sts) {
  594. cap &= ~mask;
  595. cap |= ap_bf_sts;
  596. }
  597. /* reserve and fill IE */
  598. pos = skb_put(skb, sizeof(struct ieee80211_vht_cap) + 2);
  599. ieee80211_ie_build_vht_cap(pos, &vht_cap, cap);
  600. return mu_mimo_owner;
  601. }
  602. /* This function determines HE capability flags for the association
  603. * and builds the IE.
  604. */
  605. static void ieee80211_add_he_ie(struct ieee80211_sub_if_data *sdata,
  606. struct sk_buff *skb,
  607. struct ieee80211_supported_band *sband,
  608. enum ieee80211_smps_mode smps_mode,
  609. ieee80211_conn_flags_t conn_flags)
  610. {
  611. u8 *pos, *pre_he_pos;
  612. const struct ieee80211_sta_he_cap *he_cap;
  613. u8 he_cap_size;
  614. he_cap = ieee80211_get_he_iftype_cap(sband,
  615. ieee80211_vif_type_p2p(&sdata->vif));
  616. if (WARN_ON(!he_cap))
  617. return;
  618. /* get a max size estimate */
  619. he_cap_size =
  620. 2 + 1 + sizeof(he_cap->he_cap_elem) +
  621. ieee80211_he_mcs_nss_size(&he_cap->he_cap_elem) +
  622. ieee80211_he_ppe_size(he_cap->ppe_thres[0],
  623. he_cap->he_cap_elem.phy_cap_info);
  624. pos = skb_put(skb, he_cap_size);
  625. pre_he_pos = pos;
  626. pos = ieee80211_ie_build_he_cap(conn_flags,
  627. pos, he_cap, pos + he_cap_size);
  628. /* trim excess if any */
  629. skb_trim(skb, skb->len - (pre_he_pos + he_cap_size - pos));
  630. ieee80211_ie_build_he_6ghz_cap(sdata, smps_mode, skb);
  631. }
  632. static void ieee80211_add_eht_ie(struct ieee80211_sub_if_data *sdata,
  633. struct sk_buff *skb,
  634. struct ieee80211_supported_band *sband)
  635. {
  636. u8 *pos;
  637. const struct ieee80211_sta_he_cap *he_cap;
  638. const struct ieee80211_sta_eht_cap *eht_cap;
  639. u8 eht_cap_size;
  640. he_cap = ieee80211_get_he_iftype_cap(sband,
  641. ieee80211_vif_type_p2p(&sdata->vif));
  642. eht_cap = ieee80211_get_eht_iftype_cap(sband,
  643. ieee80211_vif_type_p2p(&sdata->vif));
  644. /*
  645. * EHT capabilities element is only added if the HE capabilities element
  646. * was added so assume that 'he_cap' is valid and don't check it.
  647. */
  648. if (WARN_ON(!he_cap || !eht_cap))
  649. return;
  650. eht_cap_size =
  651. 2 + 1 + sizeof(eht_cap->eht_cap_elem) +
  652. ieee80211_eht_mcs_nss_size(&he_cap->he_cap_elem,
  653. &eht_cap->eht_cap_elem,
  654. false) +
  655. ieee80211_eht_ppe_size(eht_cap->eht_ppe_thres[0],
  656. eht_cap->eht_cap_elem.phy_cap_info);
  657. pos = skb_put(skb, eht_cap_size);
  658. ieee80211_ie_build_eht_cap(pos, he_cap, eht_cap, pos + eht_cap_size,
  659. false);
  660. }
  661. static void ieee80211_assoc_add_rates(struct sk_buff *skb,
  662. enum nl80211_chan_width width,
  663. struct ieee80211_supported_band *sband,
  664. struct ieee80211_mgd_assoc_data *assoc_data)
  665. {
  666. unsigned int shift = ieee80211_chanwidth_get_shift(width);
  667. unsigned int rates_len, supp_rates_len;
  668. u32 rates = 0;
  669. int i, count;
  670. u8 *pos;
  671. if (assoc_data->supp_rates_len) {
  672. /*
  673. * Get all rates supported by the device and the AP as
  674. * some APs don't like getting a superset of their rates
  675. * in the association request (e.g. D-Link DAP 1353 in
  676. * b-only mode)...
  677. */
  678. rates_len = ieee80211_parse_bitrates(width, sband,
  679. assoc_data->supp_rates,
  680. assoc_data->supp_rates_len,
  681. &rates);
  682. } else {
  683. /*
  684. * In case AP not provide any supported rates information
  685. * before association, we send information element(s) with
  686. * all rates that we support.
  687. */
  688. rates_len = sband->n_bitrates;
  689. for (i = 0; i < sband->n_bitrates; i++)
  690. rates |= BIT(i);
  691. }
  692. supp_rates_len = rates_len;
  693. if (supp_rates_len > 8)
  694. supp_rates_len = 8;
  695. pos = skb_put(skb, supp_rates_len + 2);
  696. *pos++ = WLAN_EID_SUPP_RATES;
  697. *pos++ = supp_rates_len;
  698. count = 0;
  699. for (i = 0; i < sband->n_bitrates; i++) {
  700. if (BIT(i) & rates) {
  701. int rate = DIV_ROUND_UP(sband->bitrates[i].bitrate,
  702. 5 * (1 << shift));
  703. *pos++ = (u8)rate;
  704. if (++count == 8)
  705. break;
  706. }
  707. }
  708. if (rates_len > count) {
  709. pos = skb_put(skb, rates_len - count + 2);
  710. *pos++ = WLAN_EID_EXT_SUPP_RATES;
  711. *pos++ = rates_len - count;
  712. for (i++; i < sband->n_bitrates; i++) {
  713. if (BIT(i) & rates) {
  714. int rate;
  715. rate = DIV_ROUND_UP(sband->bitrates[i].bitrate,
  716. 5 * (1 << shift));
  717. *pos++ = (u8)rate;
  718. }
  719. }
  720. }
  721. }
  722. static size_t ieee80211_add_before_ht_elems(struct sk_buff *skb,
  723. const u8 *elems,
  724. size_t elems_len,
  725. size_t offset)
  726. {
  727. size_t noffset;
  728. static const u8 before_ht[] = {
  729. WLAN_EID_SSID,
  730. WLAN_EID_SUPP_RATES,
  731. WLAN_EID_EXT_SUPP_RATES,
  732. WLAN_EID_PWR_CAPABILITY,
  733. WLAN_EID_SUPPORTED_CHANNELS,
  734. WLAN_EID_RSN,
  735. WLAN_EID_QOS_CAPA,
  736. WLAN_EID_RRM_ENABLED_CAPABILITIES,
  737. WLAN_EID_MOBILITY_DOMAIN,
  738. WLAN_EID_FAST_BSS_TRANSITION, /* reassoc only */
  739. WLAN_EID_RIC_DATA, /* reassoc only */
  740. WLAN_EID_SUPPORTED_REGULATORY_CLASSES,
  741. };
  742. static const u8 after_ric[] = {
  743. WLAN_EID_SUPPORTED_REGULATORY_CLASSES,
  744. WLAN_EID_HT_CAPABILITY,
  745. WLAN_EID_BSS_COEX_2040,
  746. /* luckily this is almost always there */
  747. WLAN_EID_EXT_CAPABILITY,
  748. WLAN_EID_QOS_TRAFFIC_CAPA,
  749. WLAN_EID_TIM_BCAST_REQ,
  750. WLAN_EID_INTERWORKING,
  751. /* 60 GHz (Multi-band, DMG, MMS) can't happen */
  752. WLAN_EID_VHT_CAPABILITY,
  753. WLAN_EID_OPMODE_NOTIF,
  754. };
  755. if (!elems_len)
  756. return offset;
  757. noffset = ieee80211_ie_split_ric(elems, elems_len,
  758. before_ht,
  759. ARRAY_SIZE(before_ht),
  760. after_ric,
  761. ARRAY_SIZE(after_ric),
  762. offset);
  763. skb_put_data(skb, elems + offset, noffset - offset);
  764. return noffset;
  765. }
  766. static size_t ieee80211_add_before_vht_elems(struct sk_buff *skb,
  767. const u8 *elems,
  768. size_t elems_len,
  769. size_t offset)
  770. {
  771. static const u8 before_vht[] = {
  772. /*
  773. * no need to list the ones split off before HT
  774. * or generated here
  775. */
  776. WLAN_EID_BSS_COEX_2040,
  777. WLAN_EID_EXT_CAPABILITY,
  778. WLAN_EID_QOS_TRAFFIC_CAPA,
  779. WLAN_EID_TIM_BCAST_REQ,
  780. WLAN_EID_INTERWORKING,
  781. /* 60 GHz (Multi-band, DMG, MMS) can't happen */
  782. };
  783. size_t noffset;
  784. if (!elems_len)
  785. return offset;
  786. /* RIC already taken care of in ieee80211_add_before_ht_elems() */
  787. noffset = ieee80211_ie_split(elems, elems_len,
  788. before_vht, ARRAY_SIZE(before_vht),
  789. offset);
  790. skb_put_data(skb, elems + offset, noffset - offset);
  791. return noffset;
  792. }
  793. static size_t ieee80211_add_before_he_elems(struct sk_buff *skb,
  794. const u8 *elems,
  795. size_t elems_len,
  796. size_t offset)
  797. {
  798. static const u8 before_he[] = {
  799. /*
  800. * no need to list the ones split off before VHT
  801. * or generated here
  802. */
  803. WLAN_EID_OPMODE_NOTIF,
  804. WLAN_EID_EXTENSION, WLAN_EID_EXT_FUTURE_CHAN_GUIDANCE,
  805. /* 11ai elements */
  806. WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_SESSION,
  807. WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_PUBLIC_KEY,
  808. WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_KEY_CONFIRM,
  809. WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_HLP_CONTAINER,
  810. WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_IP_ADDR_ASSIGN,
  811. /* TODO: add 11ah/11aj/11ak elements */
  812. };
  813. size_t noffset;
  814. if (!elems_len)
  815. return offset;
  816. /* RIC already taken care of in ieee80211_add_before_ht_elems() */
  817. noffset = ieee80211_ie_split(elems, elems_len,
  818. before_he, ARRAY_SIZE(before_he),
  819. offset);
  820. skb_put_data(skb, elems + offset, noffset - offset);
  821. return noffset;
  822. }
  823. #define PRESENT_ELEMS_MAX 8
  824. #define PRESENT_ELEM_EXT_OFFS 0x100
  825. static void ieee80211_assoc_add_ml_elem(struct ieee80211_sub_if_data *sdata,
  826. struct sk_buff *skb, u16 capab,
  827. const struct element *ext_capa,
  828. const u16 *present_elems);
  829. static size_t ieee80211_assoc_link_elems(struct ieee80211_sub_if_data *sdata,
  830. struct sk_buff *skb, u16 *capab,
  831. const struct element *ext_capa,
  832. const u8 *extra_elems,
  833. size_t extra_elems_len,
  834. unsigned int link_id,
  835. struct ieee80211_link_data *link,
  836. u16 *present_elems)
  837. {
  838. enum nl80211_iftype iftype = ieee80211_vif_type_p2p(&sdata->vif);
  839. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  840. struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;
  841. struct cfg80211_bss *cbss = assoc_data->link[link_id].bss;
  842. struct ieee80211_channel *chan = cbss->channel;
  843. const struct ieee80211_sband_iftype_data *iftd;
  844. struct ieee80211_local *local = sdata->local;
  845. struct ieee80211_supported_band *sband;
  846. enum nl80211_chan_width width = NL80211_CHAN_WIDTH_20;
  847. struct ieee80211_chanctx_conf *chanctx_conf;
  848. enum ieee80211_smps_mode smps_mode;
  849. u16 orig_capab = *capab;
  850. size_t offset = 0;
  851. int present_elems_len = 0;
  852. u8 *pos;
  853. int i;
  854. #define ADD_PRESENT_ELEM(id) do { \
  855. /* need a last for termination - we use 0 == SSID */ \
  856. if (!WARN_ON(present_elems_len >= PRESENT_ELEMS_MAX - 1)) \
  857. present_elems[present_elems_len++] = (id); \
  858. } while (0)
  859. #define ADD_PRESENT_EXT_ELEM(id) ADD_PRESENT_ELEM(PRESENT_ELEM_EXT_OFFS | (id))
  860. if (link)
  861. smps_mode = link->smps_mode;
  862. else if (sdata->u.mgd.powersave)
  863. smps_mode = IEEE80211_SMPS_DYNAMIC;
  864. else
  865. smps_mode = IEEE80211_SMPS_OFF;
  866. if (link) {
  867. /*
  868. * 5/10 MHz scenarios are only viable without MLO, in which
  869. * case this pointer should be used ... All of this is a bit
  870. * unclear though, not sure this even works at all.
  871. */
  872. rcu_read_lock();
  873. chanctx_conf = rcu_dereference(link->conf->chanctx_conf);
  874. if (chanctx_conf)
  875. width = chanctx_conf->def.width;
  876. rcu_read_unlock();
  877. }
  878. sband = local->hw.wiphy->bands[chan->band];
  879. iftd = ieee80211_get_sband_iftype_data(sband, iftype);
  880. if (sband->band == NL80211_BAND_2GHZ) {
  881. *capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
  882. *capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
  883. }
  884. if ((cbss->capability & WLAN_CAPABILITY_SPECTRUM_MGMT) &&
  885. ieee80211_hw_check(&local->hw, SPECTRUM_MGMT))
  886. *capab |= WLAN_CAPABILITY_SPECTRUM_MGMT;
  887. if (sband->band != NL80211_BAND_S1GHZ)
  888. ieee80211_assoc_add_rates(skb, width, sband, assoc_data);
  889. if (*capab & WLAN_CAPABILITY_SPECTRUM_MGMT ||
  890. *capab & WLAN_CAPABILITY_RADIO_MEASURE) {
  891. struct cfg80211_chan_def chandef = {
  892. .width = width,
  893. .chan = chan,
  894. };
  895. pos = skb_put(skb, 4);
  896. *pos++ = WLAN_EID_PWR_CAPABILITY;
  897. *pos++ = 2;
  898. *pos++ = 0; /* min tx power */
  899. /* max tx power */
  900. *pos++ = ieee80211_chandef_max_power(&chandef);
  901. ADD_PRESENT_ELEM(WLAN_EID_PWR_CAPABILITY);
  902. }
  903. /*
  904. * Per spec, we shouldn't include the list of channels if we advertise
  905. * support for extended channel switching, but we've always done that;
  906. * (for now?) apply this restriction only on the (new) 6 GHz band.
  907. */
  908. if (*capab & WLAN_CAPABILITY_SPECTRUM_MGMT &&
  909. (sband->band != NL80211_BAND_6GHZ ||
  910. !ext_capa || ext_capa->datalen < 1 ||
  911. !(ext_capa->data[0] & WLAN_EXT_CAPA1_EXT_CHANNEL_SWITCHING))) {
  912. /* TODO: get this in reg domain format */
  913. pos = skb_put(skb, 2 * sband->n_channels + 2);
  914. *pos++ = WLAN_EID_SUPPORTED_CHANNELS;
  915. *pos++ = 2 * sband->n_channels;
  916. for (i = 0; i < sband->n_channels; i++) {
  917. int cf = sband->channels[i].center_freq;
  918. *pos++ = ieee80211_frequency_to_channel(cf);
  919. *pos++ = 1; /* one channel in the subband*/
  920. }
  921. ADD_PRESENT_ELEM(WLAN_EID_SUPPORTED_CHANNELS);
  922. }
  923. /* if present, add any custom IEs that go before HT */
  924. offset = ieee80211_add_before_ht_elems(skb, extra_elems,
  925. extra_elems_len,
  926. offset);
  927. if (sband->band != NL80211_BAND_6GHZ &&
  928. !(assoc_data->link[link_id].conn_flags & IEEE80211_CONN_DISABLE_HT)) {
  929. ieee80211_add_ht_ie(sdata, skb,
  930. assoc_data->link[link_id].ap_ht_param,
  931. sband, chan, smps_mode,
  932. assoc_data->link[link_id].conn_flags);
  933. ADD_PRESENT_ELEM(WLAN_EID_HT_CAPABILITY);
  934. }
  935. /* if present, add any custom IEs that go before VHT */
  936. offset = ieee80211_add_before_vht_elems(skb, extra_elems,
  937. extra_elems_len,
  938. offset);
  939. if (sband->band != NL80211_BAND_6GHZ &&
  940. !(assoc_data->link[link_id].conn_flags & IEEE80211_CONN_DISABLE_VHT)) {
  941. bool mu_mimo_owner =
  942. ieee80211_add_vht_ie(sdata, skb, sband,
  943. &assoc_data->link[link_id].ap_vht_cap,
  944. assoc_data->link[link_id].conn_flags);
  945. if (link)
  946. link->conf->mu_mimo_owner = mu_mimo_owner;
  947. ADD_PRESENT_ELEM(WLAN_EID_VHT_CAPABILITY);
  948. }
  949. /*
  950. * If AP doesn't support HT, mark HE and EHT as disabled.
  951. * If on the 5GHz band, make sure it supports VHT.
  952. */
  953. if (assoc_data->link[link_id].conn_flags & IEEE80211_CONN_DISABLE_HT ||
  954. (sband->band == NL80211_BAND_5GHZ &&
  955. assoc_data->link[link_id].conn_flags & IEEE80211_CONN_DISABLE_VHT))
  956. assoc_data->link[link_id].conn_flags |=
  957. IEEE80211_CONN_DISABLE_HE |
  958. IEEE80211_CONN_DISABLE_EHT;
  959. /* if present, add any custom IEs that go before HE */
  960. offset = ieee80211_add_before_he_elems(skb, extra_elems,
  961. extra_elems_len,
  962. offset);
  963. if (!(assoc_data->link[link_id].conn_flags & IEEE80211_CONN_DISABLE_HE)) {
  964. ieee80211_add_he_ie(sdata, skb, sband, smps_mode,
  965. assoc_data->link[link_id].conn_flags);
  966. ADD_PRESENT_EXT_ELEM(WLAN_EID_EXT_HE_CAPABILITY);
  967. }
  968. /*
  969. * careful - need to know about all the present elems before
  970. * calling ieee80211_assoc_add_ml_elem(), so add this one if
  971. * we're going to put it after the ML element
  972. */
  973. if (!(assoc_data->link[link_id].conn_flags & IEEE80211_CONN_DISABLE_EHT))
  974. ADD_PRESENT_EXT_ELEM(WLAN_EID_EXT_EHT_CAPABILITY);
  975. if (link_id == assoc_data->assoc_link_id)
  976. ieee80211_assoc_add_ml_elem(sdata, skb, orig_capab, ext_capa,
  977. present_elems);
  978. /* crash if somebody gets it wrong */
  979. present_elems = NULL;
  980. if (!(assoc_data->link[link_id].conn_flags & IEEE80211_CONN_DISABLE_EHT))
  981. ieee80211_add_eht_ie(sdata, skb, sband);
  982. if (sband->band == NL80211_BAND_S1GHZ) {
  983. ieee80211_add_aid_request_ie(sdata, skb);
  984. ieee80211_add_s1g_capab_ie(sdata, &sband->s1g_cap, skb);
  985. }
  986. if (iftd && iftd->vendor_elems.data && iftd->vendor_elems.len)
  987. skb_put_data(skb, iftd->vendor_elems.data, iftd->vendor_elems.len);
  988. if (link)
  989. link->u.mgd.conn_flags = assoc_data->link[link_id].conn_flags;
  990. return offset;
  991. }
  992. static void ieee80211_add_non_inheritance_elem(struct sk_buff *skb,
  993. const u16 *outer,
  994. const u16 *inner)
  995. {
  996. unsigned int skb_len = skb->len;
  997. bool at_extension = false;
  998. bool added = false;
  999. int i, j;
  1000. u8 *len, *list_len = NULL;
  1001. skb_put_u8(skb, WLAN_EID_EXTENSION);
  1002. len = skb_put(skb, 1);
  1003. skb_put_u8(skb, WLAN_EID_EXT_NON_INHERITANCE);
  1004. for (i = 0; i < PRESENT_ELEMS_MAX && outer[i]; i++) {
  1005. u16 elem = outer[i];
  1006. bool have_inner = false;
  1007. /* should at least be sorted in the sense of normal -> ext */
  1008. WARN_ON(at_extension && elem < PRESENT_ELEM_EXT_OFFS);
  1009. /* switch to extension list */
  1010. if (!at_extension && elem >= PRESENT_ELEM_EXT_OFFS) {
  1011. at_extension = true;
  1012. if (!list_len)
  1013. skb_put_u8(skb, 0);
  1014. list_len = NULL;
  1015. }
  1016. for (j = 0; j < PRESENT_ELEMS_MAX && inner[j]; j++) {
  1017. if (elem == inner[j]) {
  1018. have_inner = true;
  1019. break;
  1020. }
  1021. }
  1022. if (have_inner)
  1023. continue;
  1024. if (!list_len) {
  1025. list_len = skb_put(skb, 1);
  1026. *list_len = 0;
  1027. }
  1028. *list_len += 1;
  1029. skb_put_u8(skb, (u8)elem);
  1030. added = true;
  1031. }
  1032. /* if we added a list but no extension list, make a zero-len one */
  1033. if (added && (!at_extension || !list_len))
  1034. skb_put_u8(skb, 0);
  1035. /* if nothing added remove extension element completely */
  1036. if (!added)
  1037. skb_trim(skb, skb_len);
  1038. else
  1039. *len = skb->len - skb_len - 2;
  1040. }
  1041. static void ieee80211_assoc_add_ml_elem(struct ieee80211_sub_if_data *sdata,
  1042. struct sk_buff *skb, u16 capab,
  1043. const struct element *ext_capa,
  1044. const u16 *outer_present_elems)
  1045. {
  1046. struct ieee80211_local *local = sdata->local;
  1047. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  1048. struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;
  1049. struct ieee80211_multi_link_elem *ml_elem;
  1050. struct ieee80211_mle_basic_common_info *common;
  1051. const struct wiphy_iftype_ext_capab *ift_ext_capa;
  1052. __le16 eml_capa = 0, mld_capa_ops = 0;
  1053. unsigned int link_id;
  1054. u8 *ml_elem_len;
  1055. void *capab_pos;
  1056. if (!sdata->vif.valid_links)
  1057. return;
  1058. ift_ext_capa = cfg80211_get_iftype_ext_capa(local->hw.wiphy,
  1059. ieee80211_vif_type_p2p(&sdata->vif));
  1060. if (ift_ext_capa) {
  1061. eml_capa = cpu_to_le16(ift_ext_capa->eml_capabilities);
  1062. mld_capa_ops = cpu_to_le16(ift_ext_capa->mld_capa_and_ops);
  1063. }
  1064. skb_put_u8(skb, WLAN_EID_EXTENSION);
  1065. ml_elem_len = skb_put(skb, 1);
  1066. skb_put_u8(skb, WLAN_EID_EXT_EHT_MULTI_LINK);
  1067. ml_elem = skb_put(skb, sizeof(*ml_elem));
  1068. ml_elem->control =
  1069. cpu_to_le16(IEEE80211_ML_CONTROL_TYPE_BASIC |
  1070. IEEE80211_MLC_BASIC_PRES_MLD_CAPA_OP);
  1071. common = skb_put(skb, sizeof(*common));
  1072. common->len = sizeof(*common) +
  1073. 2; /* MLD capa/ops */
  1074. memcpy(common->mld_mac_addr, sdata->vif.addr, ETH_ALEN);
  1075. /* add EML_CAPA only if needed, see Draft P802.11be_D2.1, 35.3.17 */
  1076. if (eml_capa &
  1077. cpu_to_le16((IEEE80211_EML_CAP_EMLSR_SUPP |
  1078. IEEE80211_EML_CAP_EMLMR_SUPPORT))) {
  1079. common->len += 2; /* EML capabilities */
  1080. ml_elem->control |=
  1081. cpu_to_le16(IEEE80211_MLC_BASIC_PRES_EML_CAPA);
  1082. skb_put_data(skb, &eml_capa, sizeof(eml_capa));
  1083. }
  1084. /* need indication from userspace to support this */
  1085. mld_capa_ops &= ~cpu_to_le16(IEEE80211_MLD_CAP_OP_TID_TO_LINK_MAP_NEG_SUPP);
  1086. skb_put_data(skb, &mld_capa_ops, sizeof(mld_capa_ops));
  1087. for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS; link_id++) {
  1088. u16 link_present_elems[PRESENT_ELEMS_MAX] = {};
  1089. const u8 *extra_elems;
  1090. size_t extra_elems_len;
  1091. size_t extra_used;
  1092. u8 *subelem_len = NULL;
  1093. __le16 ctrl;
  1094. if (!assoc_data->link[link_id].bss ||
  1095. link_id == assoc_data->assoc_link_id)
  1096. continue;
  1097. extra_elems = assoc_data->link[link_id].elems;
  1098. extra_elems_len = assoc_data->link[link_id].elems_len;
  1099. skb_put_u8(skb, IEEE80211_MLE_SUBELEM_PER_STA_PROFILE);
  1100. subelem_len = skb_put(skb, 1);
  1101. ctrl = cpu_to_le16(link_id |
  1102. IEEE80211_MLE_STA_CONTROL_COMPLETE_PROFILE |
  1103. IEEE80211_MLE_STA_CONTROL_STA_MAC_ADDR_PRESENT);
  1104. skb_put_data(skb, &ctrl, sizeof(ctrl));
  1105. skb_put_u8(skb, 1 + ETH_ALEN); /* STA Info Length */
  1106. skb_put_data(skb, assoc_data->link[link_id].addr,
  1107. ETH_ALEN);
  1108. /*
  1109. * Now add the contents of the (re)association request,
  1110. * but the "listen interval" and "current AP address"
  1111. * (if applicable) are skipped. So we only have
  1112. * the capability field (remember the position and fill
  1113. * later), followed by the elements added below by
  1114. * calling ieee80211_assoc_link_elems().
  1115. */
  1116. capab_pos = skb_put(skb, 2);
  1117. extra_used = ieee80211_assoc_link_elems(sdata, skb, &capab,
  1118. ext_capa,
  1119. extra_elems,
  1120. extra_elems_len,
  1121. link_id, NULL,
  1122. link_present_elems);
  1123. if (extra_elems)
  1124. skb_put_data(skb, extra_elems + extra_used,
  1125. extra_elems_len - extra_used);
  1126. put_unaligned_le16(capab, capab_pos);
  1127. ieee80211_add_non_inheritance_elem(skb, outer_present_elems,
  1128. link_present_elems);
  1129. ieee80211_fragment_element(skb, subelem_len);
  1130. }
  1131. ieee80211_fragment_element(skb, ml_elem_len);
  1132. }
  1133. static int ieee80211_send_assoc(struct ieee80211_sub_if_data *sdata)
  1134. {
  1135. struct ieee80211_local *local = sdata->local;
  1136. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  1137. struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;
  1138. struct ieee80211_link_data *link;
  1139. struct sk_buff *skb;
  1140. struct ieee80211_mgmt *mgmt;
  1141. u8 *pos, qos_info, *ie_start;
  1142. size_t offset, noffset;
  1143. u16 capab = WLAN_CAPABILITY_ESS, link_capab;
  1144. __le16 listen_int;
  1145. struct element *ext_capa = NULL;
  1146. enum nl80211_iftype iftype = ieee80211_vif_type_p2p(&sdata->vif);
  1147. struct ieee80211_prep_tx_info info = {};
  1148. unsigned int link_id, n_links = 0;
  1149. u16 present_elems[PRESENT_ELEMS_MAX] = {};
  1150. void *capab_pos;
  1151. size_t size;
  1152. int ret;
  1153. /* we know it's writable, cast away the const */
  1154. if (assoc_data->ie_len)
  1155. ext_capa = (void *)cfg80211_find_elem(WLAN_EID_EXT_CAPABILITY,
  1156. assoc_data->ie,
  1157. assoc_data->ie_len);
  1158. sdata_assert_lock(sdata);
  1159. size = local->hw.extra_tx_headroom +
  1160. sizeof(*mgmt) + /* bit too much but doesn't matter */
  1161. 2 + assoc_data->ssid_len + /* SSID */
  1162. assoc_data->ie_len + /* extra IEs */
  1163. (assoc_data->fils_kek_len ? 16 /* AES-SIV */ : 0) +
  1164. 9; /* WMM */
  1165. for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS; link_id++) {
  1166. struct cfg80211_bss *cbss = assoc_data->link[link_id].bss;
  1167. const struct ieee80211_sband_iftype_data *iftd;
  1168. struct ieee80211_supported_band *sband;
  1169. if (!cbss)
  1170. continue;
  1171. sband = local->hw.wiphy->bands[cbss->channel->band];
  1172. n_links++;
  1173. /* add STA profile elements length */
  1174. size += assoc_data->link[link_id].elems_len;
  1175. /* and supported rates length */
  1176. size += 4 + sband->n_bitrates;
  1177. /* supported channels */
  1178. size += 2 + 2 * sband->n_channels;
  1179. iftd = ieee80211_get_sband_iftype_data(sband, iftype);
  1180. if (iftd)
  1181. size += iftd->vendor_elems.len;
  1182. /* power capability */
  1183. size += 4;
  1184. /* HT, VHT, HE, EHT */
  1185. size += 2 + sizeof(struct ieee80211_ht_cap);
  1186. size += 2 + sizeof(struct ieee80211_vht_cap);
  1187. size += 2 + 1 + sizeof(struct ieee80211_he_cap_elem) +
  1188. sizeof(struct ieee80211_he_mcs_nss_supp) +
  1189. IEEE80211_HE_PPE_THRES_MAX_LEN;
  1190. if (sband->band == NL80211_BAND_6GHZ)
  1191. size += 2 + 1 + sizeof(struct ieee80211_he_6ghz_capa);
  1192. size += 2 + 1 + sizeof(struct ieee80211_eht_cap_elem) +
  1193. sizeof(struct ieee80211_eht_mcs_nss_supp) +
  1194. IEEE80211_EHT_PPE_THRES_MAX_LEN;
  1195. /* non-inheritance element */
  1196. size += 2 + 2 + PRESENT_ELEMS_MAX;
  1197. /* should be the same across all BSSes */
  1198. if (cbss->capability & WLAN_CAPABILITY_PRIVACY)
  1199. capab |= WLAN_CAPABILITY_PRIVACY;
  1200. }
  1201. if (sdata->vif.valid_links) {
  1202. /* consider the multi-link element with STA profile */
  1203. size += sizeof(struct ieee80211_multi_link_elem);
  1204. /* max common info field in basic multi-link element */
  1205. size += sizeof(struct ieee80211_mle_basic_common_info) +
  1206. 2 + /* capa & op */
  1207. 2; /* EML capa */
  1208. /*
  1209. * The capability elements were already considered above;
  1210. * note this over-estimates a bit because there's no
  1211. * STA profile for the assoc link.
  1212. */
  1213. size += (n_links - 1) *
  1214. (1 + 1 + /* subelement ID/length */
  1215. 2 + /* STA control */
  1216. 1 + ETH_ALEN + 2 /* STA Info field */);
  1217. }
  1218. link = sdata_dereference(sdata->link[assoc_data->assoc_link_id], sdata);
  1219. if (WARN_ON(!link))
  1220. return -EINVAL;
  1221. if (WARN_ON(!assoc_data->link[assoc_data->assoc_link_id].bss))
  1222. return -EINVAL;
  1223. skb = alloc_skb(size, GFP_KERNEL);
  1224. if (!skb)
  1225. return -ENOMEM;
  1226. skb_reserve(skb, local->hw.extra_tx_headroom);
  1227. if (ifmgd->flags & IEEE80211_STA_ENABLE_RRM)
  1228. capab |= WLAN_CAPABILITY_RADIO_MEASURE;
  1229. /* Set MBSSID support for HE AP if needed */
  1230. if (ieee80211_hw_check(&local->hw, SUPPORTS_ONLY_HE_MULTI_BSSID) &&
  1231. !(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_HE) &&
  1232. ext_capa && ext_capa->datalen >= 3)
  1233. ext_capa->data[2] |= WLAN_EXT_CAPA3_MULTI_BSSID_SUPPORT;
  1234. mgmt = skb_put_zero(skb, 24);
  1235. memcpy(mgmt->da, sdata->vif.cfg.ap_addr, ETH_ALEN);
  1236. memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
  1237. memcpy(mgmt->bssid, sdata->vif.cfg.ap_addr, ETH_ALEN);
  1238. listen_int = cpu_to_le16(assoc_data->s1g ?
  1239. ieee80211_encode_usf(local->hw.conf.listen_interval) :
  1240. local->hw.conf.listen_interval);
  1241. if (!is_zero_ether_addr(assoc_data->prev_ap_addr)) {
  1242. skb_put(skb, 10);
  1243. mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
  1244. IEEE80211_STYPE_REASSOC_REQ);
  1245. capab_pos = &mgmt->u.reassoc_req.capab_info;
  1246. mgmt->u.reassoc_req.listen_interval = listen_int;
  1247. memcpy(mgmt->u.reassoc_req.current_ap,
  1248. assoc_data->prev_ap_addr, ETH_ALEN);
  1249. info.subtype = IEEE80211_STYPE_REASSOC_REQ;
  1250. } else {
  1251. skb_put(skb, 4);
  1252. mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
  1253. IEEE80211_STYPE_ASSOC_REQ);
  1254. capab_pos = &mgmt->u.assoc_req.capab_info;
  1255. mgmt->u.assoc_req.listen_interval = listen_int;
  1256. info.subtype = IEEE80211_STYPE_ASSOC_REQ;
  1257. }
  1258. /* SSID */
  1259. pos = skb_put(skb, 2 + assoc_data->ssid_len);
  1260. ie_start = pos;
  1261. *pos++ = WLAN_EID_SSID;
  1262. *pos++ = assoc_data->ssid_len;
  1263. memcpy(pos, assoc_data->ssid, assoc_data->ssid_len);
  1264. /* add the elements for the assoc (main) link */
  1265. link_capab = capab;
  1266. offset = ieee80211_assoc_link_elems(sdata, skb, &link_capab,
  1267. ext_capa,
  1268. assoc_data->ie,
  1269. assoc_data->ie_len,
  1270. assoc_data->assoc_link_id, link,
  1271. present_elems);
  1272. put_unaligned_le16(link_capab, capab_pos);
  1273. /* if present, add any custom non-vendor IEs */
  1274. if (assoc_data->ie_len) {
  1275. noffset = ieee80211_ie_split_vendor(assoc_data->ie,
  1276. assoc_data->ie_len,
  1277. offset);
  1278. skb_put_data(skb, assoc_data->ie + offset, noffset - offset);
  1279. offset = noffset;
  1280. }
  1281. if (assoc_data->wmm) {
  1282. if (assoc_data->uapsd) {
  1283. qos_info = ifmgd->uapsd_queues;
  1284. qos_info |= (ifmgd->uapsd_max_sp_len <<
  1285. IEEE80211_WMM_IE_STA_QOSINFO_SP_SHIFT);
  1286. } else {
  1287. qos_info = 0;
  1288. }
  1289. pos = ieee80211_add_wmm_info_ie(skb_put(skb, 9), qos_info);
  1290. }
  1291. /* add any remaining custom (i.e. vendor specific here) IEs */
  1292. if (assoc_data->ie_len) {
  1293. noffset = assoc_data->ie_len;
  1294. skb_put_data(skb, assoc_data->ie + offset, noffset - offset);
  1295. }
  1296. if (assoc_data->fils_kek_len) {
  1297. ret = fils_encrypt_assoc_req(skb, assoc_data);
  1298. if (ret < 0) {
  1299. dev_kfree_skb(skb);
  1300. return ret;
  1301. }
  1302. }
  1303. pos = skb_tail_pointer(skb);
  1304. kfree(ifmgd->assoc_req_ies);
  1305. ifmgd->assoc_req_ies = kmemdup(ie_start, pos - ie_start, GFP_ATOMIC);
  1306. if (!ifmgd->assoc_req_ies) {
  1307. dev_kfree_skb(skb);
  1308. return -ENOMEM;
  1309. }
  1310. ifmgd->assoc_req_ies_len = pos - ie_start;
  1311. drv_mgd_prepare_tx(local, sdata, &info);
  1312. IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
  1313. if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
  1314. IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS |
  1315. IEEE80211_TX_INTFL_MLME_CONN_TX;
  1316. ieee80211_tx_skb(sdata, skb);
  1317. return 0;
  1318. }
  1319. void ieee80211_send_pspoll(struct ieee80211_local *local,
  1320. struct ieee80211_sub_if_data *sdata)
  1321. {
  1322. struct ieee80211_pspoll *pspoll;
  1323. struct sk_buff *skb;
  1324. skb = ieee80211_pspoll_get(&local->hw, &sdata->vif);
  1325. if (!skb)
  1326. return;
  1327. pspoll = (struct ieee80211_pspoll *) skb->data;
  1328. pspoll->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
  1329. IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
  1330. ieee80211_tx_skb(sdata, skb);
  1331. }
  1332. void ieee80211_send_nullfunc(struct ieee80211_local *local,
  1333. struct ieee80211_sub_if_data *sdata,
  1334. bool powersave)
  1335. {
  1336. struct sk_buff *skb;
  1337. struct ieee80211_hdr_3addr *nullfunc;
  1338. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  1339. skb = ieee80211_nullfunc_get(&local->hw, &sdata->vif, -1,
  1340. !ieee80211_hw_check(&local->hw,
  1341. DOESNT_SUPPORT_QOS_NDP));
  1342. if (!skb)
  1343. return;
  1344. nullfunc = (struct ieee80211_hdr_3addr *) skb->data;
  1345. if (powersave)
  1346. nullfunc->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
  1347. IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT |
  1348. IEEE80211_TX_INTFL_OFFCHAN_TX_OK;
  1349. if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
  1350. IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS;
  1351. if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL)
  1352. IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_USE_MINRATE;
  1353. ieee80211_tx_skb(sdata, skb);
  1354. }
  1355. void ieee80211_send_4addr_nullfunc(struct ieee80211_local *local,
  1356. struct ieee80211_sub_if_data *sdata)
  1357. {
  1358. struct sk_buff *skb;
  1359. struct ieee80211_hdr *nullfunc;
  1360. __le16 fc;
  1361. if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
  1362. return;
  1363. skb = dev_alloc_skb(local->hw.extra_tx_headroom + 30);
  1364. if (!skb)
  1365. return;
  1366. skb_reserve(skb, local->hw.extra_tx_headroom);
  1367. nullfunc = skb_put_zero(skb, 30);
  1368. fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_NULLFUNC |
  1369. IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS);
  1370. nullfunc->frame_control = fc;
  1371. memcpy(nullfunc->addr1, sdata->deflink.u.mgd.bssid, ETH_ALEN);
  1372. memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
  1373. memcpy(nullfunc->addr3, sdata->deflink.u.mgd.bssid, ETH_ALEN);
  1374. memcpy(nullfunc->addr4, sdata->vif.addr, ETH_ALEN);
  1375. IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
  1376. IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_USE_MINRATE;
  1377. ieee80211_tx_skb(sdata, skb);
  1378. }
  1379. /* spectrum management related things */
  1380. static void ieee80211_chswitch_work(struct work_struct *work)
  1381. {
  1382. struct ieee80211_link_data *link =
  1383. container_of(work, struct ieee80211_link_data, u.mgd.chswitch_work);
  1384. struct ieee80211_sub_if_data *sdata = link->sdata;
  1385. struct ieee80211_local *local = sdata->local;
  1386. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  1387. int ret;
  1388. if (!ieee80211_sdata_running(sdata))
  1389. return;
  1390. sdata_lock(sdata);
  1391. mutex_lock(&local->mtx);
  1392. mutex_lock(&local->chanctx_mtx);
  1393. if (!ifmgd->associated)
  1394. goto out;
  1395. if (!link->conf->csa_active)
  1396. goto out;
  1397. /*
  1398. * using reservation isn't immediate as it may be deferred until later
  1399. * with multi-vif. once reservation is complete it will re-schedule the
  1400. * work with no reserved_chanctx so verify chandef to check if it
  1401. * completed successfully
  1402. */
  1403. if (link->reserved_chanctx) {
  1404. /*
  1405. * with multi-vif csa driver may call ieee80211_csa_finish()
  1406. * many times while waiting for other interfaces to use their
  1407. * reservations
  1408. */
  1409. if (link->reserved_ready)
  1410. goto out;
  1411. ret = ieee80211_link_use_reserved_context(link);
  1412. if (ret) {
  1413. sdata_info(sdata,
  1414. "failed to use reserved channel context, disconnecting (err=%d)\n",
  1415. ret);
  1416. ieee80211_queue_work(&sdata->local->hw,
  1417. &ifmgd->csa_connection_drop_work);
  1418. goto out;
  1419. }
  1420. goto out;
  1421. }
  1422. if (!cfg80211_chandef_identical(&link->conf->chandef,
  1423. &link->csa_chandef)) {
  1424. sdata_info(sdata,
  1425. "failed to finalize channel switch, disconnecting\n");
  1426. ieee80211_queue_work(&sdata->local->hw,
  1427. &ifmgd->csa_connection_drop_work);
  1428. goto out;
  1429. }
  1430. link->u.mgd.csa_waiting_bcn = true;
  1431. ieee80211_sta_reset_beacon_monitor(sdata);
  1432. ieee80211_sta_reset_conn_monitor(sdata);
  1433. out:
  1434. mutex_unlock(&local->chanctx_mtx);
  1435. mutex_unlock(&local->mtx);
  1436. sdata_unlock(sdata);
  1437. }
  1438. static void ieee80211_chswitch_post_beacon(struct ieee80211_link_data *link)
  1439. {
  1440. struct ieee80211_sub_if_data *sdata = link->sdata;
  1441. struct ieee80211_local *local = sdata->local;
  1442. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  1443. int ret;
  1444. sdata_assert_lock(sdata);
  1445. WARN_ON(!link->conf->csa_active);
  1446. if (link->csa_block_tx) {
  1447. ieee80211_wake_vif_queues(local, sdata,
  1448. IEEE80211_QUEUE_STOP_REASON_CSA);
  1449. link->csa_block_tx = false;
  1450. }
  1451. link->conf->csa_active = false;
  1452. link->u.mgd.csa_waiting_bcn = false;
  1453. /*
  1454. * If the CSA IE is still present on the beacon after the switch,
  1455. * we need to consider it as a new CSA (possibly to self).
  1456. */
  1457. link->u.mgd.beacon_crc_valid = false;
  1458. ret = drv_post_channel_switch(sdata);
  1459. if (ret) {
  1460. sdata_info(sdata,
  1461. "driver post channel switch failed, disconnecting\n");
  1462. ieee80211_queue_work(&local->hw,
  1463. &ifmgd->csa_connection_drop_work);
  1464. return;
  1465. }
  1466. cfg80211_ch_switch_notify(sdata->dev, &link->reserved_chandef, 0, 0);
  1467. }
  1468. void ieee80211_chswitch_done(struct ieee80211_vif *vif, bool success)
  1469. {
  1470. struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
  1471. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  1472. if (WARN_ON(sdata->vif.valid_links))
  1473. success = false;
  1474. trace_api_chswitch_done(sdata, success);
  1475. if (!success) {
  1476. sdata_info(sdata,
  1477. "driver channel switch failed, disconnecting\n");
  1478. ieee80211_queue_work(&sdata->local->hw,
  1479. &ifmgd->csa_connection_drop_work);
  1480. } else {
  1481. ieee80211_queue_work(&sdata->local->hw,
  1482. &sdata->deflink.u.mgd.chswitch_work);
  1483. }
  1484. }
  1485. EXPORT_SYMBOL(ieee80211_chswitch_done);
  1486. static void ieee80211_chswitch_timer(struct timer_list *t)
  1487. {
  1488. struct ieee80211_link_data *link =
  1489. from_timer(link, t, u.mgd.chswitch_timer);
  1490. ieee80211_queue_work(&link->sdata->local->hw,
  1491. &link->u.mgd.chswitch_work);
  1492. }
  1493. static void
  1494. ieee80211_sta_abort_chanswitch(struct ieee80211_link_data *link)
  1495. {
  1496. struct ieee80211_sub_if_data *sdata = link->sdata;
  1497. struct ieee80211_local *local = sdata->local;
  1498. if (!local->ops->abort_channel_switch)
  1499. return;
  1500. mutex_lock(&local->mtx);
  1501. mutex_lock(&local->chanctx_mtx);
  1502. ieee80211_link_unreserve_chanctx(link);
  1503. mutex_unlock(&local->chanctx_mtx);
  1504. if (link->csa_block_tx)
  1505. ieee80211_wake_vif_queues(local, sdata,
  1506. IEEE80211_QUEUE_STOP_REASON_CSA);
  1507. link->csa_block_tx = false;
  1508. link->conf->csa_active = false;
  1509. mutex_unlock(&local->mtx);
  1510. drv_abort_channel_switch(sdata);
  1511. }
  1512. static void
  1513. ieee80211_sta_process_chanswitch(struct ieee80211_link_data *link,
  1514. u64 timestamp, u32 device_timestamp,
  1515. struct ieee802_11_elems *elems,
  1516. bool beacon)
  1517. {
  1518. struct ieee80211_sub_if_data *sdata = link->sdata;
  1519. struct ieee80211_local *local = sdata->local;
  1520. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  1521. struct cfg80211_bss *cbss = link->u.mgd.bss;
  1522. struct ieee80211_chanctx_conf *conf;
  1523. struct ieee80211_chanctx *chanctx;
  1524. enum nl80211_band current_band;
  1525. struct ieee80211_csa_ie csa_ie;
  1526. struct ieee80211_channel_switch ch_switch;
  1527. struct ieee80211_bss *bss;
  1528. int res;
  1529. sdata_assert_lock(sdata);
  1530. if (!cbss)
  1531. return;
  1532. if (local->scanning)
  1533. return;
  1534. current_band = cbss->channel->band;
  1535. bss = (void *)cbss->priv;
  1536. res = ieee80211_parse_ch_switch_ie(sdata, elems, current_band,
  1537. bss->vht_cap_info,
  1538. link->u.mgd.conn_flags,
  1539. link->u.mgd.bssid, &csa_ie);
  1540. if (!res) {
  1541. ch_switch.timestamp = timestamp;
  1542. ch_switch.device_timestamp = device_timestamp;
  1543. ch_switch.block_tx = csa_ie.mode;
  1544. ch_switch.chandef = csa_ie.chandef;
  1545. ch_switch.count = csa_ie.count;
  1546. ch_switch.delay = csa_ie.max_switch_time;
  1547. }
  1548. if (res < 0)
  1549. goto lock_and_drop_connection;
  1550. if (beacon && link->conf->csa_active &&
  1551. !link->u.mgd.csa_waiting_bcn) {
  1552. if (res)
  1553. ieee80211_sta_abort_chanswitch(link);
  1554. else
  1555. drv_channel_switch_rx_beacon(sdata, &ch_switch);
  1556. return;
  1557. } else if (link->conf->csa_active || res) {
  1558. /* disregard subsequent announcements if already processing */
  1559. return;
  1560. }
  1561. if (link->conf->chandef.chan->band !=
  1562. csa_ie.chandef.chan->band) {
  1563. sdata_info(sdata,
  1564. "AP %pM switches to different band (%d MHz, width:%d, CF1/2: %d/%d MHz), disconnecting\n",
  1565. link->u.mgd.bssid,
  1566. csa_ie.chandef.chan->center_freq,
  1567. csa_ie.chandef.width, csa_ie.chandef.center_freq1,
  1568. csa_ie.chandef.center_freq2);
  1569. goto lock_and_drop_connection;
  1570. }
  1571. if (!cfg80211_chandef_usable(local->hw.wiphy, &csa_ie.chandef,
  1572. IEEE80211_CHAN_DISABLED)) {
  1573. sdata_info(sdata,
  1574. "AP %pM switches to unsupported channel "
  1575. "(%d.%03d MHz, width:%d, CF1/2: %d.%03d/%d MHz), "
  1576. "disconnecting\n",
  1577. link->u.mgd.bssid,
  1578. csa_ie.chandef.chan->center_freq,
  1579. csa_ie.chandef.chan->freq_offset,
  1580. csa_ie.chandef.width, csa_ie.chandef.center_freq1,
  1581. csa_ie.chandef.freq1_offset,
  1582. csa_ie.chandef.center_freq2);
  1583. goto lock_and_drop_connection;
  1584. }
  1585. if (cfg80211_chandef_identical(&csa_ie.chandef,
  1586. &link->conf->chandef) &&
  1587. (!csa_ie.mode || !beacon)) {
  1588. if (link->u.mgd.csa_ignored_same_chan)
  1589. return;
  1590. sdata_info(sdata,
  1591. "AP %pM tries to chanswitch to same channel, ignore\n",
  1592. link->u.mgd.bssid);
  1593. link->u.mgd.csa_ignored_same_chan = true;
  1594. return;
  1595. }
  1596. /*
  1597. * Drop all TDLS peers - either we disconnect or move to a different
  1598. * channel from this point on. There's no telling what our peer will do.
  1599. * The TDLS WIDER_BW scenario is also problematic, as peers might now
  1600. * have an incompatible wider chandef.
  1601. */
  1602. ieee80211_teardown_tdls_peers(sdata);
  1603. mutex_lock(&local->mtx);
  1604. mutex_lock(&local->chanctx_mtx);
  1605. conf = rcu_dereference_protected(link->conf->chanctx_conf,
  1606. lockdep_is_held(&local->chanctx_mtx));
  1607. if (!conf) {
  1608. sdata_info(sdata,
  1609. "no channel context assigned to vif?, disconnecting\n");
  1610. goto drop_connection;
  1611. }
  1612. chanctx = container_of(conf, struct ieee80211_chanctx, conf);
  1613. if (local->use_chanctx &&
  1614. !ieee80211_hw_check(&local->hw, CHANCTX_STA_CSA)) {
  1615. sdata_info(sdata,
  1616. "driver doesn't support chan-switch with channel contexts\n");
  1617. goto drop_connection;
  1618. }
  1619. if (drv_pre_channel_switch(sdata, &ch_switch)) {
  1620. sdata_info(sdata,
  1621. "preparing for channel switch failed, disconnecting\n");
  1622. goto drop_connection;
  1623. }
  1624. res = ieee80211_link_reserve_chanctx(link, &csa_ie.chandef,
  1625. chanctx->mode, false);
  1626. if (res) {
  1627. sdata_info(sdata,
  1628. "failed to reserve channel context for channel switch, disconnecting (err=%d)\n",
  1629. res);
  1630. goto drop_connection;
  1631. }
  1632. mutex_unlock(&local->chanctx_mtx);
  1633. link->conf->csa_active = true;
  1634. link->csa_chandef = csa_ie.chandef;
  1635. link->csa_block_tx = csa_ie.mode;
  1636. link->u.mgd.csa_ignored_same_chan = false;
  1637. link->u.mgd.beacon_crc_valid = false;
  1638. if (link->csa_block_tx)
  1639. ieee80211_stop_vif_queues(local, sdata,
  1640. IEEE80211_QUEUE_STOP_REASON_CSA);
  1641. mutex_unlock(&local->mtx);
  1642. cfg80211_ch_switch_started_notify(sdata->dev, &csa_ie.chandef, 0,
  1643. csa_ie.count, csa_ie.mode, 0);
  1644. if (local->ops->channel_switch) {
  1645. /* use driver's channel switch callback */
  1646. drv_channel_switch(local, sdata, &ch_switch);
  1647. return;
  1648. }
  1649. /* channel switch handled in software */
  1650. if (csa_ie.count <= 1)
  1651. ieee80211_queue_work(&local->hw, &link->u.mgd.chswitch_work);
  1652. else
  1653. mod_timer(&link->u.mgd.chswitch_timer,
  1654. TU_TO_EXP_TIME((csa_ie.count - 1) *
  1655. cbss->beacon_interval));
  1656. return;
  1657. lock_and_drop_connection:
  1658. mutex_lock(&local->mtx);
  1659. mutex_lock(&local->chanctx_mtx);
  1660. drop_connection:
  1661. /*
  1662. * This is just so that the disconnect flow will know that
  1663. * we were trying to switch channel and failed. In case the
  1664. * mode is 1 (we are not allowed to Tx), we will know not to
  1665. * send a deauthentication frame. Those two fields will be
  1666. * reset when the disconnection worker runs.
  1667. */
  1668. link->conf->csa_active = true;
  1669. link->csa_block_tx = csa_ie.mode;
  1670. ieee80211_queue_work(&local->hw, &ifmgd->csa_connection_drop_work);
  1671. mutex_unlock(&local->chanctx_mtx);
  1672. mutex_unlock(&local->mtx);
  1673. }
  1674. static bool
  1675. ieee80211_find_80211h_pwr_constr(struct ieee80211_sub_if_data *sdata,
  1676. struct ieee80211_channel *channel,
  1677. const u8 *country_ie, u8 country_ie_len,
  1678. const u8 *pwr_constr_elem,
  1679. int *chan_pwr, int *pwr_reduction)
  1680. {
  1681. struct ieee80211_country_ie_triplet *triplet;
  1682. int chan = ieee80211_frequency_to_channel(channel->center_freq);
  1683. int i, chan_increment;
  1684. bool have_chan_pwr = false;
  1685. /* Invalid IE */
  1686. if (country_ie_len % 2 || country_ie_len < IEEE80211_COUNTRY_IE_MIN_LEN)
  1687. return false;
  1688. triplet = (void *)(country_ie + 3);
  1689. country_ie_len -= 3;
  1690. switch (channel->band) {
  1691. default:
  1692. WARN_ON_ONCE(1);
  1693. fallthrough;
  1694. case NL80211_BAND_2GHZ:
  1695. case NL80211_BAND_60GHZ:
  1696. case NL80211_BAND_LC:
  1697. chan_increment = 1;
  1698. break;
  1699. case NL80211_BAND_5GHZ:
  1700. chan_increment = 4;
  1701. break;
  1702. case NL80211_BAND_6GHZ:
  1703. /*
  1704. * In the 6 GHz band, the "maximum transmit power level"
  1705. * field in the triplets is reserved, and thus will be
  1706. * zero and we shouldn't use it to control TX power.
  1707. * The actual TX power will be given in the transmit
  1708. * power envelope element instead.
  1709. */
  1710. return false;
  1711. }
  1712. /* find channel */
  1713. while (country_ie_len >= 3) {
  1714. u8 first_channel = triplet->chans.first_channel;
  1715. if (first_channel >= IEEE80211_COUNTRY_EXTENSION_ID)
  1716. goto next;
  1717. for (i = 0; i < triplet->chans.num_channels; i++) {
  1718. if (first_channel + i * chan_increment == chan) {
  1719. have_chan_pwr = true;
  1720. *chan_pwr = triplet->chans.max_power;
  1721. break;
  1722. }
  1723. }
  1724. if (have_chan_pwr)
  1725. break;
  1726. next:
  1727. triplet++;
  1728. country_ie_len -= 3;
  1729. }
  1730. if (have_chan_pwr && pwr_constr_elem)
  1731. *pwr_reduction = *pwr_constr_elem;
  1732. else
  1733. *pwr_reduction = 0;
  1734. return have_chan_pwr;
  1735. }
  1736. static void ieee80211_find_cisco_dtpc(struct ieee80211_sub_if_data *sdata,
  1737. struct ieee80211_channel *channel,
  1738. const u8 *cisco_dtpc_ie,
  1739. int *pwr_level)
  1740. {
  1741. /* From practical testing, the first data byte of the DTPC element
  1742. * seems to contain the requested dBm level, and the CLI on Cisco
  1743. * APs clearly state the range is -127 to 127 dBm, which indicates
  1744. * a signed byte, although it seemingly never actually goes negative.
  1745. * The other byte seems to always be zero.
  1746. */
  1747. *pwr_level = (__s8)cisco_dtpc_ie[4];
  1748. }
  1749. static u32 ieee80211_handle_pwr_constr(struct ieee80211_link_data *link,
  1750. struct ieee80211_channel *channel,
  1751. struct ieee80211_mgmt *mgmt,
  1752. const u8 *country_ie, u8 country_ie_len,
  1753. const u8 *pwr_constr_ie,
  1754. const u8 *cisco_dtpc_ie)
  1755. {
  1756. struct ieee80211_sub_if_data *sdata = link->sdata;
  1757. bool has_80211h_pwr = false, has_cisco_pwr = false;
  1758. int chan_pwr = 0, pwr_reduction_80211h = 0;
  1759. int pwr_level_cisco, pwr_level_80211h;
  1760. int new_ap_level;
  1761. __le16 capab = mgmt->u.probe_resp.capab_info;
  1762. if (ieee80211_is_s1g_beacon(mgmt->frame_control))
  1763. return 0; /* TODO */
  1764. if (country_ie &&
  1765. (capab & cpu_to_le16(WLAN_CAPABILITY_SPECTRUM_MGMT) ||
  1766. capab & cpu_to_le16(WLAN_CAPABILITY_RADIO_MEASURE))) {
  1767. has_80211h_pwr = ieee80211_find_80211h_pwr_constr(
  1768. sdata, channel, country_ie, country_ie_len,
  1769. pwr_constr_ie, &chan_pwr, &pwr_reduction_80211h);
  1770. pwr_level_80211h =
  1771. max_t(int, 0, chan_pwr - pwr_reduction_80211h);
  1772. }
  1773. if (cisco_dtpc_ie) {
  1774. ieee80211_find_cisco_dtpc(
  1775. sdata, channel, cisco_dtpc_ie, &pwr_level_cisco);
  1776. has_cisco_pwr = true;
  1777. }
  1778. if (!has_80211h_pwr && !has_cisco_pwr)
  1779. return 0;
  1780. /* If we have both 802.11h and Cisco DTPC, apply both limits
  1781. * by picking the smallest of the two power levels advertised.
  1782. */
  1783. if (has_80211h_pwr &&
  1784. (!has_cisco_pwr || pwr_level_80211h <= pwr_level_cisco)) {
  1785. new_ap_level = pwr_level_80211h;
  1786. if (link->ap_power_level == new_ap_level)
  1787. return 0;
  1788. sdata_dbg(sdata,
  1789. "Limiting TX power to %d (%d - %d) dBm as advertised by %pM\n",
  1790. pwr_level_80211h, chan_pwr, pwr_reduction_80211h,
  1791. link->u.mgd.bssid);
  1792. } else { /* has_cisco_pwr is always true here. */
  1793. new_ap_level = pwr_level_cisco;
  1794. if (link->ap_power_level == new_ap_level)
  1795. return 0;
  1796. sdata_dbg(sdata,
  1797. "Limiting TX power to %d dBm as advertised by %pM\n",
  1798. pwr_level_cisco, link->u.mgd.bssid);
  1799. }
  1800. link->ap_power_level = new_ap_level;
  1801. if (__ieee80211_recalc_txpower(sdata))
  1802. return BSS_CHANGED_TXPOWER;
  1803. return 0;
  1804. }
  1805. /* powersave */
  1806. static void ieee80211_enable_ps(struct ieee80211_local *local,
  1807. struct ieee80211_sub_if_data *sdata)
  1808. {
  1809. struct ieee80211_conf *conf = &local->hw.conf;
  1810. /*
  1811. * If we are scanning right now then the parameters will
  1812. * take effect when scan finishes.
  1813. */
  1814. if (local->scanning)
  1815. return;
  1816. if (conf->dynamic_ps_timeout > 0 &&
  1817. !ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS)) {
  1818. mod_timer(&local->dynamic_ps_timer, jiffies +
  1819. msecs_to_jiffies(conf->dynamic_ps_timeout));
  1820. } else {
  1821. if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK))
  1822. ieee80211_send_nullfunc(local, sdata, true);
  1823. if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK) &&
  1824. ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
  1825. return;
  1826. conf->flags |= IEEE80211_CONF_PS;
  1827. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
  1828. }
  1829. }
  1830. static void ieee80211_change_ps(struct ieee80211_local *local)
  1831. {
  1832. struct ieee80211_conf *conf = &local->hw.conf;
  1833. if (local->ps_sdata) {
  1834. ieee80211_enable_ps(local, local->ps_sdata);
  1835. } else if (conf->flags & IEEE80211_CONF_PS) {
  1836. conf->flags &= ~IEEE80211_CONF_PS;
  1837. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
  1838. del_timer_sync(&local->dynamic_ps_timer);
  1839. cancel_work_sync(&local->dynamic_ps_enable_work);
  1840. }
  1841. }
  1842. static bool ieee80211_powersave_allowed(struct ieee80211_sub_if_data *sdata)
  1843. {
  1844. struct ieee80211_local *local = sdata->local;
  1845. struct ieee80211_if_managed *mgd = &sdata->u.mgd;
  1846. struct sta_info *sta = NULL;
  1847. bool authorized = false;
  1848. if (!mgd->powersave)
  1849. return false;
  1850. if (mgd->broken_ap)
  1851. return false;
  1852. if (!mgd->associated)
  1853. return false;
  1854. if (mgd->flags & IEEE80211_STA_CONNECTION_POLL)
  1855. return false;
  1856. if (!(local->hw.wiphy->flags & WIPHY_FLAG_SUPPORTS_MLO) &&
  1857. !sdata->deflink.u.mgd.have_beacon)
  1858. return false;
  1859. rcu_read_lock();
  1860. sta = sta_info_get(sdata, sdata->vif.cfg.ap_addr);
  1861. if (sta)
  1862. authorized = test_sta_flag(sta, WLAN_STA_AUTHORIZED);
  1863. rcu_read_unlock();
  1864. return authorized;
  1865. }
  1866. /* need to hold RTNL or interface lock */
  1867. void ieee80211_recalc_ps(struct ieee80211_local *local)
  1868. {
  1869. struct ieee80211_sub_if_data *sdata, *found = NULL;
  1870. int count = 0;
  1871. int timeout;
  1872. if (!ieee80211_hw_check(&local->hw, SUPPORTS_PS) ||
  1873. ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS)) {
  1874. local->ps_sdata = NULL;
  1875. return;
  1876. }
  1877. list_for_each_entry(sdata, &local->interfaces, list) {
  1878. if (!ieee80211_sdata_running(sdata))
  1879. continue;
  1880. if (sdata->vif.type == NL80211_IFTYPE_AP) {
  1881. /* If an AP vif is found, then disable PS
  1882. * by setting the count to zero thereby setting
  1883. * ps_sdata to NULL.
  1884. */
  1885. count = 0;
  1886. break;
  1887. }
  1888. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  1889. continue;
  1890. found = sdata;
  1891. count++;
  1892. }
  1893. if (count == 1 && ieee80211_powersave_allowed(found)) {
  1894. u8 dtimper = found->deflink.u.mgd.dtim_period;
  1895. timeout = local->dynamic_ps_forced_timeout;
  1896. if (timeout < 0)
  1897. timeout = 100;
  1898. local->hw.conf.dynamic_ps_timeout = timeout;
  1899. /* If the TIM IE is invalid, pretend the value is 1 */
  1900. if (!dtimper)
  1901. dtimper = 1;
  1902. local->hw.conf.ps_dtim_period = dtimper;
  1903. local->ps_sdata = found;
  1904. } else {
  1905. local->ps_sdata = NULL;
  1906. }
  1907. ieee80211_change_ps(local);
  1908. }
  1909. void ieee80211_recalc_ps_vif(struct ieee80211_sub_if_data *sdata)
  1910. {
  1911. bool ps_allowed = ieee80211_powersave_allowed(sdata);
  1912. if (sdata->vif.cfg.ps != ps_allowed) {
  1913. sdata->vif.cfg.ps = ps_allowed;
  1914. ieee80211_vif_cfg_change_notify(sdata, BSS_CHANGED_PS);
  1915. }
  1916. }
  1917. void ieee80211_dynamic_ps_disable_work(struct work_struct *work)
  1918. {
  1919. struct ieee80211_local *local =
  1920. container_of(work, struct ieee80211_local,
  1921. dynamic_ps_disable_work);
  1922. if (local->hw.conf.flags & IEEE80211_CONF_PS) {
  1923. local->hw.conf.flags &= ~IEEE80211_CONF_PS;
  1924. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
  1925. }
  1926. ieee80211_wake_queues_by_reason(&local->hw,
  1927. IEEE80211_MAX_QUEUE_MAP,
  1928. IEEE80211_QUEUE_STOP_REASON_PS,
  1929. false);
  1930. }
  1931. void ieee80211_dynamic_ps_enable_work(struct work_struct *work)
  1932. {
  1933. struct ieee80211_local *local =
  1934. container_of(work, struct ieee80211_local,
  1935. dynamic_ps_enable_work);
  1936. struct ieee80211_sub_if_data *sdata = local->ps_sdata;
  1937. struct ieee80211_if_managed *ifmgd;
  1938. unsigned long flags;
  1939. int q;
  1940. /* can only happen when PS was just disabled anyway */
  1941. if (!sdata)
  1942. return;
  1943. ifmgd = &sdata->u.mgd;
  1944. if (local->hw.conf.flags & IEEE80211_CONF_PS)
  1945. return;
  1946. if (local->hw.conf.dynamic_ps_timeout > 0) {
  1947. /* don't enter PS if TX frames are pending */
  1948. if (drv_tx_frames_pending(local)) {
  1949. mod_timer(&local->dynamic_ps_timer, jiffies +
  1950. msecs_to_jiffies(
  1951. local->hw.conf.dynamic_ps_timeout));
  1952. return;
  1953. }
  1954. /*
  1955. * transmission can be stopped by others which leads to
  1956. * dynamic_ps_timer expiry. Postpone the ps timer if it
  1957. * is not the actual idle state.
  1958. */
  1959. spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
  1960. for (q = 0; q < local->hw.queues; q++) {
  1961. if (local->queue_stop_reasons[q]) {
  1962. spin_unlock_irqrestore(&local->queue_stop_reason_lock,
  1963. flags);
  1964. mod_timer(&local->dynamic_ps_timer, jiffies +
  1965. msecs_to_jiffies(
  1966. local->hw.conf.dynamic_ps_timeout));
  1967. return;
  1968. }
  1969. }
  1970. spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
  1971. }
  1972. if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK) &&
  1973. !(ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED)) {
  1974. if (drv_tx_frames_pending(local)) {
  1975. mod_timer(&local->dynamic_ps_timer, jiffies +
  1976. msecs_to_jiffies(
  1977. local->hw.conf.dynamic_ps_timeout));
  1978. } else {
  1979. ieee80211_send_nullfunc(local, sdata, true);
  1980. /* Flush to get the tx status of nullfunc frame */
  1981. ieee80211_flush_queues(local, sdata, false);
  1982. }
  1983. }
  1984. if (!(ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS) &&
  1985. ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK)) ||
  1986. (ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED)) {
  1987. ifmgd->flags &= ~IEEE80211_STA_NULLFUNC_ACKED;
  1988. local->hw.conf.flags |= IEEE80211_CONF_PS;
  1989. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
  1990. }
  1991. }
  1992. void ieee80211_dynamic_ps_timer(struct timer_list *t)
  1993. {
  1994. struct ieee80211_local *local = from_timer(local, t, dynamic_ps_timer);
  1995. ieee80211_queue_work(&local->hw, &local->dynamic_ps_enable_work);
  1996. }
  1997. void ieee80211_dfs_cac_timer_work(struct work_struct *work)
  1998. {
  1999. struct delayed_work *delayed_work = to_delayed_work(work);
  2000. struct ieee80211_link_data *link =
  2001. container_of(delayed_work, struct ieee80211_link_data,
  2002. dfs_cac_timer_work);
  2003. struct cfg80211_chan_def chandef = link->conf->chandef;
  2004. struct ieee80211_sub_if_data *sdata = link->sdata;
  2005. mutex_lock(&sdata->local->mtx);
  2006. if (sdata->wdev.cac_started) {
  2007. ieee80211_link_release_channel(link);
  2008. cfg80211_cac_event(sdata->dev, &chandef,
  2009. NL80211_RADAR_CAC_FINISHED,
  2010. GFP_KERNEL);
  2011. }
  2012. mutex_unlock(&sdata->local->mtx);
  2013. }
  2014. static bool
  2015. __ieee80211_sta_handle_tspec_ac_params(struct ieee80211_sub_if_data *sdata)
  2016. {
  2017. struct ieee80211_local *local = sdata->local;
  2018. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  2019. bool ret = false;
  2020. int ac;
  2021. if (local->hw.queues < IEEE80211_NUM_ACS)
  2022. return false;
  2023. for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
  2024. struct ieee80211_sta_tx_tspec *tx_tspec = &ifmgd->tx_tspec[ac];
  2025. int non_acm_ac;
  2026. unsigned long now = jiffies;
  2027. if (tx_tspec->action == TX_TSPEC_ACTION_NONE &&
  2028. tx_tspec->admitted_time &&
  2029. time_after(now, tx_tspec->time_slice_start + HZ)) {
  2030. tx_tspec->consumed_tx_time = 0;
  2031. tx_tspec->time_slice_start = now;
  2032. if (tx_tspec->downgraded)
  2033. tx_tspec->action =
  2034. TX_TSPEC_ACTION_STOP_DOWNGRADE;
  2035. }
  2036. switch (tx_tspec->action) {
  2037. case TX_TSPEC_ACTION_STOP_DOWNGRADE:
  2038. /* take the original parameters */
  2039. if (drv_conf_tx(local, &sdata->deflink, ac,
  2040. &sdata->deflink.tx_conf[ac]))
  2041. link_err(&sdata->deflink,
  2042. "failed to set TX queue parameters for queue %d\n",
  2043. ac);
  2044. tx_tspec->action = TX_TSPEC_ACTION_NONE;
  2045. tx_tspec->downgraded = false;
  2046. ret = true;
  2047. break;
  2048. case TX_TSPEC_ACTION_DOWNGRADE:
  2049. if (time_after(now, tx_tspec->time_slice_start + HZ)) {
  2050. tx_tspec->action = TX_TSPEC_ACTION_NONE;
  2051. ret = true;
  2052. break;
  2053. }
  2054. /* downgrade next lower non-ACM AC */
  2055. for (non_acm_ac = ac + 1;
  2056. non_acm_ac < IEEE80211_NUM_ACS;
  2057. non_acm_ac++)
  2058. if (!(sdata->wmm_acm & BIT(7 - 2 * non_acm_ac)))
  2059. break;
  2060. /* Usually the loop will result in using BK even if it
  2061. * requires admission control, but such a configuration
  2062. * makes no sense and we have to transmit somehow - the
  2063. * AC selection does the same thing.
  2064. * If we started out trying to downgrade from BK, then
  2065. * the extra condition here might be needed.
  2066. */
  2067. if (non_acm_ac >= IEEE80211_NUM_ACS)
  2068. non_acm_ac = IEEE80211_AC_BK;
  2069. if (drv_conf_tx(local, &sdata->deflink, ac,
  2070. &sdata->deflink.tx_conf[non_acm_ac]))
  2071. link_err(&sdata->deflink,
  2072. "failed to set TX queue parameters for queue %d\n",
  2073. ac);
  2074. tx_tspec->action = TX_TSPEC_ACTION_NONE;
  2075. ret = true;
  2076. schedule_delayed_work(&ifmgd->tx_tspec_wk,
  2077. tx_tspec->time_slice_start + HZ - now + 1);
  2078. break;
  2079. case TX_TSPEC_ACTION_NONE:
  2080. /* nothing now */
  2081. break;
  2082. }
  2083. }
  2084. return ret;
  2085. }
  2086. void ieee80211_sta_handle_tspec_ac_params(struct ieee80211_sub_if_data *sdata)
  2087. {
  2088. if (__ieee80211_sta_handle_tspec_ac_params(sdata))
  2089. ieee80211_link_info_change_notify(sdata, &sdata->deflink,
  2090. BSS_CHANGED_QOS);
  2091. }
  2092. static void ieee80211_sta_handle_tspec_ac_params_wk(struct work_struct *work)
  2093. {
  2094. struct ieee80211_sub_if_data *sdata;
  2095. sdata = container_of(work, struct ieee80211_sub_if_data,
  2096. u.mgd.tx_tspec_wk.work);
  2097. ieee80211_sta_handle_tspec_ac_params(sdata);
  2098. }
  2099. void ieee80211_mgd_set_link_qos_params(struct ieee80211_link_data *link)
  2100. {
  2101. struct ieee80211_sub_if_data *sdata = link->sdata;
  2102. struct ieee80211_local *local = sdata->local;
  2103. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  2104. struct ieee80211_tx_queue_params *params = link->tx_conf;
  2105. u8 ac;
  2106. for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
  2107. mlme_dbg(sdata,
  2108. "WMM AC=%d acm=%d aifs=%d cWmin=%d cWmax=%d txop=%d uapsd=%d, downgraded=%d\n",
  2109. ac, params[ac].acm,
  2110. params[ac].aifs, params[ac].cw_min, params[ac].cw_max,
  2111. params[ac].txop, params[ac].uapsd,
  2112. ifmgd->tx_tspec[ac].downgraded);
  2113. if (!ifmgd->tx_tspec[ac].downgraded &&
  2114. drv_conf_tx(local, link, ac, &params[ac]))
  2115. link_err(link,
  2116. "failed to set TX queue parameters for AC %d\n",
  2117. ac);
  2118. }
  2119. }
  2120. /* MLME */
  2121. static bool
  2122. ieee80211_sta_wmm_params(struct ieee80211_local *local,
  2123. struct ieee80211_link_data *link,
  2124. const u8 *wmm_param, size_t wmm_param_len,
  2125. const struct ieee80211_mu_edca_param_set *mu_edca)
  2126. {
  2127. struct ieee80211_sub_if_data *sdata = link->sdata;
  2128. struct ieee80211_tx_queue_params params[IEEE80211_NUM_ACS];
  2129. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  2130. size_t left;
  2131. int count, mu_edca_count, ac;
  2132. const u8 *pos;
  2133. u8 uapsd_queues = 0;
  2134. if (!local->ops->conf_tx)
  2135. return false;
  2136. if (local->hw.queues < IEEE80211_NUM_ACS)
  2137. return false;
  2138. if (!wmm_param)
  2139. return false;
  2140. if (wmm_param_len < 8 || wmm_param[5] /* version */ != 1)
  2141. return false;
  2142. if (ifmgd->flags & IEEE80211_STA_UAPSD_ENABLED)
  2143. uapsd_queues = ifmgd->uapsd_queues;
  2144. count = wmm_param[6] & 0x0f;
  2145. /* -1 is the initial value of ifmgd->mu_edca_last_param_set.
  2146. * if mu_edca was preset before and now it disappeared tell
  2147. * the driver about it.
  2148. */
  2149. mu_edca_count = mu_edca ? mu_edca->mu_qos_info & 0x0f : -1;
  2150. if (count == link->u.mgd.wmm_last_param_set &&
  2151. mu_edca_count == link->u.mgd.mu_edca_last_param_set)
  2152. return false;
  2153. link->u.mgd.wmm_last_param_set = count;
  2154. link->u.mgd.mu_edca_last_param_set = mu_edca_count;
  2155. pos = wmm_param + 8;
  2156. left = wmm_param_len - 8;
  2157. memset(&params, 0, sizeof(params));
  2158. sdata->wmm_acm = 0;
  2159. for (; left >= 4; left -= 4, pos += 4) {
  2160. int aci = (pos[0] >> 5) & 0x03;
  2161. int acm = (pos[0] >> 4) & 0x01;
  2162. bool uapsd = false;
  2163. switch (aci) {
  2164. case 1: /* AC_BK */
  2165. ac = IEEE80211_AC_BK;
  2166. if (acm)
  2167. sdata->wmm_acm |= BIT(1) | BIT(2); /* BK/- */
  2168. if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
  2169. uapsd = true;
  2170. params[ac].mu_edca = !!mu_edca;
  2171. if (mu_edca)
  2172. params[ac].mu_edca_param_rec = mu_edca->ac_bk;
  2173. break;
  2174. case 2: /* AC_VI */
  2175. ac = IEEE80211_AC_VI;
  2176. if (acm)
  2177. sdata->wmm_acm |= BIT(4) | BIT(5); /* CL/VI */
  2178. if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
  2179. uapsd = true;
  2180. params[ac].mu_edca = !!mu_edca;
  2181. if (mu_edca)
  2182. params[ac].mu_edca_param_rec = mu_edca->ac_vi;
  2183. break;
  2184. case 3: /* AC_VO */
  2185. ac = IEEE80211_AC_VO;
  2186. if (acm)
  2187. sdata->wmm_acm |= BIT(6) | BIT(7); /* VO/NC */
  2188. if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
  2189. uapsd = true;
  2190. params[ac].mu_edca = !!mu_edca;
  2191. if (mu_edca)
  2192. params[ac].mu_edca_param_rec = mu_edca->ac_vo;
  2193. break;
  2194. case 0: /* AC_BE */
  2195. default:
  2196. ac = IEEE80211_AC_BE;
  2197. if (acm)
  2198. sdata->wmm_acm |= BIT(0) | BIT(3); /* BE/EE */
  2199. if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
  2200. uapsd = true;
  2201. params[ac].mu_edca = !!mu_edca;
  2202. if (mu_edca)
  2203. params[ac].mu_edca_param_rec = mu_edca->ac_be;
  2204. break;
  2205. }
  2206. params[ac].aifs = pos[0] & 0x0f;
  2207. if (params[ac].aifs < 2) {
  2208. sdata_info(sdata,
  2209. "AP has invalid WMM params (AIFSN=%d for ACI %d), will use 2\n",
  2210. params[ac].aifs, aci);
  2211. params[ac].aifs = 2;
  2212. }
  2213. params[ac].cw_max = ecw2cw((pos[1] & 0xf0) >> 4);
  2214. params[ac].cw_min = ecw2cw(pos[1] & 0x0f);
  2215. params[ac].txop = get_unaligned_le16(pos + 2);
  2216. params[ac].acm = acm;
  2217. params[ac].uapsd = uapsd;
  2218. if (params[ac].cw_min == 0 ||
  2219. params[ac].cw_min > params[ac].cw_max) {
  2220. sdata_info(sdata,
  2221. "AP has invalid WMM params (CWmin/max=%d/%d for ACI %d), using defaults\n",
  2222. params[ac].cw_min, params[ac].cw_max, aci);
  2223. return false;
  2224. }
  2225. ieee80211_regulatory_limit_wmm_params(sdata, &params[ac], ac);
  2226. }
  2227. /* WMM specification requires all 4 ACIs. */
  2228. for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
  2229. if (params[ac].cw_min == 0) {
  2230. sdata_info(sdata,
  2231. "AP has invalid WMM params (missing AC %d), using defaults\n",
  2232. ac);
  2233. return false;
  2234. }
  2235. }
  2236. for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
  2237. link->tx_conf[ac] = params[ac];
  2238. ieee80211_mgd_set_link_qos_params(link);
  2239. /* enable WMM or activate new settings */
  2240. link->conf->qos = true;
  2241. return true;
  2242. }
  2243. static void __ieee80211_stop_poll(struct ieee80211_sub_if_data *sdata)
  2244. {
  2245. lockdep_assert_held(&sdata->local->mtx);
  2246. sdata->u.mgd.flags &= ~IEEE80211_STA_CONNECTION_POLL;
  2247. ieee80211_run_deferred_scan(sdata->local);
  2248. }
  2249. static void ieee80211_stop_poll(struct ieee80211_sub_if_data *sdata)
  2250. {
  2251. mutex_lock(&sdata->local->mtx);
  2252. __ieee80211_stop_poll(sdata);
  2253. mutex_unlock(&sdata->local->mtx);
  2254. }
  2255. static u32 ieee80211_handle_bss_capability(struct ieee80211_link_data *link,
  2256. u16 capab, bool erp_valid, u8 erp)
  2257. {
  2258. struct ieee80211_bss_conf *bss_conf = link->conf;
  2259. struct ieee80211_supported_band *sband;
  2260. u32 changed = 0;
  2261. bool use_protection;
  2262. bool use_short_preamble;
  2263. bool use_short_slot;
  2264. sband = ieee80211_get_link_sband(link);
  2265. if (!sband)
  2266. return changed;
  2267. if (erp_valid) {
  2268. use_protection = (erp & WLAN_ERP_USE_PROTECTION) != 0;
  2269. use_short_preamble = (erp & WLAN_ERP_BARKER_PREAMBLE) == 0;
  2270. } else {
  2271. use_protection = false;
  2272. use_short_preamble = !!(capab & WLAN_CAPABILITY_SHORT_PREAMBLE);
  2273. }
  2274. use_short_slot = !!(capab & WLAN_CAPABILITY_SHORT_SLOT_TIME);
  2275. if (sband->band == NL80211_BAND_5GHZ ||
  2276. sband->band == NL80211_BAND_6GHZ)
  2277. use_short_slot = true;
  2278. if (use_protection != bss_conf->use_cts_prot) {
  2279. bss_conf->use_cts_prot = use_protection;
  2280. changed |= BSS_CHANGED_ERP_CTS_PROT;
  2281. }
  2282. if (use_short_preamble != bss_conf->use_short_preamble) {
  2283. bss_conf->use_short_preamble = use_short_preamble;
  2284. changed |= BSS_CHANGED_ERP_PREAMBLE;
  2285. }
  2286. if (use_short_slot != bss_conf->use_short_slot) {
  2287. bss_conf->use_short_slot = use_short_slot;
  2288. changed |= BSS_CHANGED_ERP_SLOT;
  2289. }
  2290. return changed;
  2291. }
  2292. static u32 ieee80211_link_set_associated(struct ieee80211_link_data *link,
  2293. struct cfg80211_bss *cbss)
  2294. {
  2295. struct ieee80211_sub_if_data *sdata = link->sdata;
  2296. struct ieee80211_bss_conf *bss_conf = link->conf;
  2297. struct ieee80211_bss *bss = (void *)cbss->priv;
  2298. u32 changed = BSS_CHANGED_QOS;
  2299. /* not really used in MLO */
  2300. sdata->u.mgd.beacon_timeout =
  2301. usecs_to_jiffies(ieee80211_tu_to_usec(beacon_loss_count *
  2302. bss_conf->beacon_int));
  2303. changed |= ieee80211_handle_bss_capability(link,
  2304. bss_conf->assoc_capability,
  2305. bss->has_erp_value,
  2306. bss->erp_value);
  2307. ieee80211_check_rate_mask(link);
  2308. link->u.mgd.bss = cbss;
  2309. memcpy(link->u.mgd.bssid, cbss->bssid, ETH_ALEN);
  2310. if (sdata->vif.p2p ||
  2311. sdata->vif.driver_flags & IEEE80211_VIF_GET_NOA_UPDATE) {
  2312. const struct cfg80211_bss_ies *ies;
  2313. rcu_read_lock();
  2314. ies = rcu_dereference(cbss->ies);
  2315. if (ies) {
  2316. int ret;
  2317. ret = cfg80211_get_p2p_attr(
  2318. ies->data, ies->len,
  2319. IEEE80211_P2P_ATTR_ABSENCE_NOTICE,
  2320. (u8 *) &bss_conf->p2p_noa_attr,
  2321. sizeof(bss_conf->p2p_noa_attr));
  2322. if (ret >= 2) {
  2323. link->u.mgd.p2p_noa_index =
  2324. bss_conf->p2p_noa_attr.index;
  2325. changed |= BSS_CHANGED_P2P_PS;
  2326. }
  2327. }
  2328. rcu_read_unlock();
  2329. }
  2330. if (link->u.mgd.have_beacon) {
  2331. /*
  2332. * If the AP is buggy we may get here with no DTIM period
  2333. * known, so assume it's 1 which is the only safe assumption
  2334. * in that case, although if the TIM IE is broken powersave
  2335. * probably just won't work at all.
  2336. */
  2337. bss_conf->dtim_period = link->u.mgd.dtim_period ?: 1;
  2338. bss_conf->beacon_rate = bss->beacon_rate;
  2339. changed |= BSS_CHANGED_BEACON_INFO;
  2340. } else {
  2341. bss_conf->beacon_rate = NULL;
  2342. bss_conf->dtim_period = 0;
  2343. }
  2344. /* Tell the driver to monitor connection quality (if supported) */
  2345. if (sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI &&
  2346. bss_conf->cqm_rssi_thold)
  2347. changed |= BSS_CHANGED_CQM;
  2348. return changed;
  2349. }
  2350. static void ieee80211_set_associated(struct ieee80211_sub_if_data *sdata,
  2351. struct ieee80211_mgd_assoc_data *assoc_data,
  2352. u64 changed[IEEE80211_MLD_MAX_NUM_LINKS])
  2353. {
  2354. struct ieee80211_local *local = sdata->local;
  2355. struct ieee80211_vif_cfg *vif_cfg = &sdata->vif.cfg;
  2356. u64 vif_changed = BSS_CHANGED_ASSOC;
  2357. unsigned int link_id;
  2358. sdata->u.mgd.associated = true;
  2359. for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS; link_id++) {
  2360. struct cfg80211_bss *cbss = assoc_data->link[link_id].bss;
  2361. struct ieee80211_link_data *link;
  2362. if (!cbss)
  2363. continue;
  2364. link = sdata_dereference(sdata->link[link_id], sdata);
  2365. if (WARN_ON(!link))
  2366. return;
  2367. changed[link_id] |= ieee80211_link_set_associated(link, cbss);
  2368. }
  2369. /* just to be sure */
  2370. ieee80211_stop_poll(sdata);
  2371. ieee80211_led_assoc(local, 1);
  2372. vif_cfg->assoc = 1;
  2373. /* Enable ARP filtering */
  2374. if (vif_cfg->arp_addr_cnt)
  2375. vif_changed |= BSS_CHANGED_ARP_FILTER;
  2376. if (sdata->vif.valid_links) {
  2377. for (link_id = 0;
  2378. link_id < IEEE80211_MLD_MAX_NUM_LINKS;
  2379. link_id++) {
  2380. struct ieee80211_link_data *link;
  2381. struct cfg80211_bss *cbss = assoc_data->link[link_id].bss;
  2382. if (!cbss)
  2383. continue;
  2384. link = sdata_dereference(sdata->link[link_id], sdata);
  2385. if (WARN_ON(!link))
  2386. return;
  2387. ieee80211_link_info_change_notify(sdata, link,
  2388. changed[link_id]);
  2389. ieee80211_recalc_smps(sdata, link);
  2390. }
  2391. ieee80211_vif_cfg_change_notify(sdata, vif_changed);
  2392. } else {
  2393. ieee80211_bss_info_change_notify(sdata,
  2394. vif_changed | changed[0]);
  2395. }
  2396. mutex_lock(&local->iflist_mtx);
  2397. ieee80211_recalc_ps(local);
  2398. mutex_unlock(&local->iflist_mtx);
  2399. /* leave this here to not change ordering in non-MLO cases */
  2400. if (!sdata->vif.valid_links)
  2401. ieee80211_recalc_smps(sdata, &sdata->deflink);
  2402. ieee80211_recalc_ps_vif(sdata);
  2403. netif_carrier_on(sdata->dev);
  2404. }
  2405. static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata,
  2406. u16 stype, u16 reason, bool tx,
  2407. u8 *frame_buf)
  2408. {
  2409. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  2410. struct ieee80211_local *local = sdata->local;
  2411. unsigned int link_id;
  2412. u32 changed = 0;
  2413. struct ieee80211_prep_tx_info info = {
  2414. .subtype = stype,
  2415. };
  2416. sdata_assert_lock(sdata);
  2417. if (WARN_ON_ONCE(tx && !frame_buf))
  2418. return;
  2419. if (WARN_ON(!ifmgd->associated))
  2420. return;
  2421. ieee80211_stop_poll(sdata);
  2422. ifmgd->associated = false;
  2423. /* other links will be destroyed */
  2424. sdata->deflink.u.mgd.bss = NULL;
  2425. netif_carrier_off(sdata->dev);
  2426. /*
  2427. * if we want to get out of ps before disassoc (why?) we have
  2428. * to do it before sending disassoc, as otherwise the null-packet
  2429. * won't be valid.
  2430. */
  2431. if (local->hw.conf.flags & IEEE80211_CONF_PS) {
  2432. local->hw.conf.flags &= ~IEEE80211_CONF_PS;
  2433. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
  2434. }
  2435. local->ps_sdata = NULL;
  2436. /* disable per-vif ps */
  2437. ieee80211_recalc_ps_vif(sdata);
  2438. /* make sure ongoing transmission finishes */
  2439. synchronize_net();
  2440. /*
  2441. * drop any frame before deauth/disassoc, this can be data or
  2442. * management frame. Since we are disconnecting, we should not
  2443. * insist sending these frames which can take time and delay
  2444. * the disconnection and possible the roaming.
  2445. */
  2446. if (tx)
  2447. ieee80211_flush_queues(local, sdata, true);
  2448. /* deauthenticate/disassociate now */
  2449. if (tx || frame_buf) {
  2450. /*
  2451. * In multi channel scenarios guarantee that the virtual
  2452. * interface is granted immediate airtime to transmit the
  2453. * deauthentication frame by calling mgd_prepare_tx, if the
  2454. * driver requested so.
  2455. */
  2456. if (ieee80211_hw_check(&local->hw, DEAUTH_NEED_MGD_TX_PREP) &&
  2457. !sdata->deflink.u.mgd.have_beacon) {
  2458. drv_mgd_prepare_tx(sdata->local, sdata, &info);
  2459. }
  2460. ieee80211_send_deauth_disassoc(sdata, sdata->vif.cfg.ap_addr,
  2461. sdata->vif.cfg.ap_addr, stype,
  2462. reason, tx, frame_buf);
  2463. }
  2464. /* flush out frame - make sure the deauth was actually sent */
  2465. if (tx)
  2466. ieee80211_flush_queues(local, sdata, false);
  2467. drv_mgd_complete_tx(sdata->local, sdata, &info);
  2468. /* clear AP addr only after building the needed mgmt frames */
  2469. eth_zero_addr(sdata->deflink.u.mgd.bssid);
  2470. eth_zero_addr(sdata->vif.cfg.ap_addr);
  2471. sdata->vif.cfg.ssid_len = 0;
  2472. /* remove AP and TDLS peers */
  2473. sta_info_flush(sdata);
  2474. /* finally reset all BSS / config parameters */
  2475. if (!sdata->vif.valid_links)
  2476. changed |= ieee80211_reset_erp_info(sdata);
  2477. ieee80211_led_assoc(local, 0);
  2478. changed |= BSS_CHANGED_ASSOC;
  2479. sdata->vif.cfg.assoc = false;
  2480. sdata->deflink.u.mgd.p2p_noa_index = -1;
  2481. memset(&sdata->vif.bss_conf.p2p_noa_attr, 0,
  2482. sizeof(sdata->vif.bss_conf.p2p_noa_attr));
  2483. /* on the next assoc, re-program HT/VHT parameters */
  2484. memset(&ifmgd->ht_capa, 0, sizeof(ifmgd->ht_capa));
  2485. memset(&ifmgd->ht_capa_mask, 0, sizeof(ifmgd->ht_capa_mask));
  2486. memset(&ifmgd->vht_capa, 0, sizeof(ifmgd->vht_capa));
  2487. memset(&ifmgd->vht_capa_mask, 0, sizeof(ifmgd->vht_capa_mask));
  2488. /*
  2489. * reset MU-MIMO ownership and group data in default link,
  2490. * if used, other links are destroyed
  2491. */
  2492. memset(sdata->vif.bss_conf.mu_group.membership, 0,
  2493. sizeof(sdata->vif.bss_conf.mu_group.membership));
  2494. memset(sdata->vif.bss_conf.mu_group.position, 0,
  2495. sizeof(sdata->vif.bss_conf.mu_group.position));
  2496. if (!sdata->vif.valid_links)
  2497. changed |= BSS_CHANGED_MU_GROUPS;
  2498. sdata->vif.bss_conf.mu_mimo_owner = false;
  2499. sdata->deflink.ap_power_level = IEEE80211_UNSET_POWER_LEVEL;
  2500. del_timer_sync(&local->dynamic_ps_timer);
  2501. cancel_work_sync(&local->dynamic_ps_enable_work);
  2502. /* Disable ARP filtering */
  2503. if (sdata->vif.cfg.arp_addr_cnt)
  2504. changed |= BSS_CHANGED_ARP_FILTER;
  2505. sdata->vif.bss_conf.qos = false;
  2506. if (!sdata->vif.valid_links) {
  2507. changed |= BSS_CHANGED_QOS;
  2508. /* The BSSID (not really interesting) and HT changed */
  2509. changed |= BSS_CHANGED_BSSID | BSS_CHANGED_HT;
  2510. ieee80211_bss_info_change_notify(sdata, changed);
  2511. } else {
  2512. ieee80211_vif_cfg_change_notify(sdata, changed);
  2513. }
  2514. /* disassociated - set to defaults now */
  2515. ieee80211_set_wmm_default(&sdata->deflink, false, false);
  2516. del_timer_sync(&sdata->u.mgd.conn_mon_timer);
  2517. del_timer_sync(&sdata->u.mgd.bcn_mon_timer);
  2518. del_timer_sync(&sdata->u.mgd.timer);
  2519. del_timer_sync(&sdata->deflink.u.mgd.chswitch_timer);
  2520. sdata->vif.bss_conf.dtim_period = 0;
  2521. sdata->vif.bss_conf.beacon_rate = NULL;
  2522. sdata->deflink.u.mgd.have_beacon = false;
  2523. sdata->deflink.u.mgd.tracking_signal_avg = false;
  2524. sdata->deflink.u.mgd.disable_wmm_tracking = false;
  2525. ifmgd->flags = 0;
  2526. sdata->deflink.u.mgd.conn_flags = 0;
  2527. mutex_lock(&local->mtx);
  2528. for (link_id = 0; link_id < ARRAY_SIZE(sdata->link); link_id++) {
  2529. struct ieee80211_link_data *link;
  2530. link = sdata_dereference(sdata->link[link_id], sdata);
  2531. if (!link)
  2532. continue;
  2533. ieee80211_link_release_channel(link);
  2534. }
  2535. sdata->vif.bss_conf.csa_active = false;
  2536. sdata->deflink.u.mgd.csa_waiting_bcn = false;
  2537. sdata->deflink.u.mgd.csa_ignored_same_chan = false;
  2538. if (sdata->deflink.csa_block_tx) {
  2539. ieee80211_wake_vif_queues(local, sdata,
  2540. IEEE80211_QUEUE_STOP_REASON_CSA);
  2541. sdata->deflink.csa_block_tx = false;
  2542. }
  2543. mutex_unlock(&local->mtx);
  2544. /* existing TX TSPEC sessions no longer exist */
  2545. memset(ifmgd->tx_tspec, 0, sizeof(ifmgd->tx_tspec));
  2546. cancel_delayed_work_sync(&ifmgd->tx_tspec_wk);
  2547. sdata->vif.bss_conf.pwr_reduction = 0;
  2548. sdata->vif.bss_conf.tx_pwr_env_num = 0;
  2549. memset(sdata->vif.bss_conf.tx_pwr_env, 0,
  2550. sizeof(sdata->vif.bss_conf.tx_pwr_env));
  2551. ieee80211_vif_set_links(sdata, 0);
  2552. }
  2553. static void ieee80211_reset_ap_probe(struct ieee80211_sub_if_data *sdata)
  2554. {
  2555. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  2556. struct ieee80211_local *local = sdata->local;
  2557. mutex_lock(&local->mtx);
  2558. if (!(ifmgd->flags & IEEE80211_STA_CONNECTION_POLL))
  2559. goto out;
  2560. __ieee80211_stop_poll(sdata);
  2561. mutex_lock(&local->iflist_mtx);
  2562. ieee80211_recalc_ps(local);
  2563. mutex_unlock(&local->iflist_mtx);
  2564. if (ieee80211_hw_check(&sdata->local->hw, CONNECTION_MONITOR))
  2565. goto out;
  2566. /*
  2567. * We've received a probe response, but are not sure whether
  2568. * we have or will be receiving any beacons or data, so let's
  2569. * schedule the timers again, just in case.
  2570. */
  2571. ieee80211_sta_reset_beacon_monitor(sdata);
  2572. mod_timer(&ifmgd->conn_mon_timer,
  2573. round_jiffies_up(jiffies +
  2574. IEEE80211_CONNECTION_IDLE_TIME));
  2575. out:
  2576. mutex_unlock(&local->mtx);
  2577. }
  2578. static void ieee80211_sta_tx_wmm_ac_notify(struct ieee80211_sub_if_data *sdata,
  2579. struct ieee80211_hdr *hdr,
  2580. u16 tx_time)
  2581. {
  2582. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  2583. u16 tid;
  2584. int ac;
  2585. struct ieee80211_sta_tx_tspec *tx_tspec;
  2586. unsigned long now = jiffies;
  2587. if (!ieee80211_is_data_qos(hdr->frame_control))
  2588. return;
  2589. tid = ieee80211_get_tid(hdr);
  2590. ac = ieee80211_ac_from_tid(tid);
  2591. tx_tspec = &ifmgd->tx_tspec[ac];
  2592. if (likely(!tx_tspec->admitted_time))
  2593. return;
  2594. if (time_after(now, tx_tspec->time_slice_start + HZ)) {
  2595. tx_tspec->consumed_tx_time = 0;
  2596. tx_tspec->time_slice_start = now;
  2597. if (tx_tspec->downgraded) {
  2598. tx_tspec->action = TX_TSPEC_ACTION_STOP_DOWNGRADE;
  2599. schedule_delayed_work(&ifmgd->tx_tspec_wk, 0);
  2600. }
  2601. }
  2602. if (tx_tspec->downgraded)
  2603. return;
  2604. tx_tspec->consumed_tx_time += tx_time;
  2605. if (tx_tspec->consumed_tx_time >= tx_tspec->admitted_time) {
  2606. tx_tspec->downgraded = true;
  2607. tx_tspec->action = TX_TSPEC_ACTION_DOWNGRADE;
  2608. schedule_delayed_work(&ifmgd->tx_tspec_wk, 0);
  2609. }
  2610. }
  2611. void ieee80211_sta_tx_notify(struct ieee80211_sub_if_data *sdata,
  2612. struct ieee80211_hdr *hdr, bool ack, u16 tx_time)
  2613. {
  2614. ieee80211_sta_tx_wmm_ac_notify(sdata, hdr, tx_time);
  2615. if (!ieee80211_is_any_nullfunc(hdr->frame_control) ||
  2616. !sdata->u.mgd.probe_send_count)
  2617. return;
  2618. if (ack)
  2619. sdata->u.mgd.probe_send_count = 0;
  2620. else
  2621. sdata->u.mgd.nullfunc_failed = true;
  2622. ieee80211_queue_work(&sdata->local->hw, &sdata->work);
  2623. }
  2624. static void ieee80211_mlme_send_probe_req(struct ieee80211_sub_if_data *sdata,
  2625. const u8 *src, const u8 *dst,
  2626. const u8 *ssid, size_t ssid_len,
  2627. struct ieee80211_channel *channel)
  2628. {
  2629. struct sk_buff *skb;
  2630. skb = ieee80211_build_probe_req(sdata, src, dst, (u32)-1, channel,
  2631. ssid, ssid_len, NULL, 0,
  2632. IEEE80211_PROBE_FLAG_DIRECTED);
  2633. if (skb)
  2634. ieee80211_tx_skb(sdata, skb);
  2635. }
  2636. static void ieee80211_mgd_probe_ap_send(struct ieee80211_sub_if_data *sdata)
  2637. {
  2638. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  2639. u8 *dst = sdata->vif.cfg.ap_addr;
  2640. u8 unicast_limit = max(1, max_probe_tries - 3);
  2641. struct sta_info *sta;
  2642. if (WARN_ON(sdata->vif.valid_links))
  2643. return;
  2644. /*
  2645. * Try sending broadcast probe requests for the last three
  2646. * probe requests after the first ones failed since some
  2647. * buggy APs only support broadcast probe requests.
  2648. */
  2649. if (ifmgd->probe_send_count >= unicast_limit)
  2650. dst = NULL;
  2651. /*
  2652. * When the hardware reports an accurate Tx ACK status, it's
  2653. * better to send a nullfunc frame instead of a probe request,
  2654. * as it will kick us off the AP quickly if we aren't associated
  2655. * anymore. The timeout will be reset if the frame is ACKed by
  2656. * the AP.
  2657. */
  2658. ifmgd->probe_send_count++;
  2659. if (dst) {
  2660. mutex_lock(&sdata->local->sta_mtx);
  2661. sta = sta_info_get(sdata, dst);
  2662. if (!WARN_ON(!sta))
  2663. ieee80211_check_fast_rx(sta);
  2664. mutex_unlock(&sdata->local->sta_mtx);
  2665. }
  2666. if (ieee80211_hw_check(&sdata->local->hw, REPORTS_TX_ACK_STATUS)) {
  2667. ifmgd->nullfunc_failed = false;
  2668. ieee80211_send_nullfunc(sdata->local, sdata, false);
  2669. } else {
  2670. ieee80211_mlme_send_probe_req(sdata, sdata->vif.addr, dst,
  2671. sdata->vif.cfg.ssid,
  2672. sdata->vif.cfg.ssid_len,
  2673. sdata->deflink.u.mgd.bss->channel);
  2674. }
  2675. ifmgd->probe_timeout = jiffies + msecs_to_jiffies(probe_wait_ms);
  2676. run_again(sdata, ifmgd->probe_timeout);
  2677. }
  2678. static void ieee80211_mgd_probe_ap(struct ieee80211_sub_if_data *sdata,
  2679. bool beacon)
  2680. {
  2681. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  2682. bool already = false;
  2683. if (WARN_ON(sdata->vif.valid_links))
  2684. return;
  2685. if (!ieee80211_sdata_running(sdata))
  2686. return;
  2687. sdata_lock(sdata);
  2688. if (!ifmgd->associated)
  2689. goto out;
  2690. mutex_lock(&sdata->local->mtx);
  2691. if (sdata->local->tmp_channel || sdata->local->scanning) {
  2692. mutex_unlock(&sdata->local->mtx);
  2693. goto out;
  2694. }
  2695. if (sdata->local->suspending) {
  2696. /* reschedule after resume */
  2697. mutex_unlock(&sdata->local->mtx);
  2698. ieee80211_reset_ap_probe(sdata);
  2699. goto out;
  2700. }
  2701. if (beacon) {
  2702. mlme_dbg_ratelimited(sdata,
  2703. "detected beacon loss from AP (missed %d beacons) - probing\n",
  2704. beacon_loss_count);
  2705. ieee80211_cqm_beacon_loss_notify(&sdata->vif, GFP_KERNEL);
  2706. }
  2707. /*
  2708. * The driver/our work has already reported this event or the
  2709. * connection monitoring has kicked in and we have already sent
  2710. * a probe request. Or maybe the AP died and the driver keeps
  2711. * reporting until we disassociate...
  2712. *
  2713. * In either case we have to ignore the current call to this
  2714. * function (except for setting the correct probe reason bit)
  2715. * because otherwise we would reset the timer every time and
  2716. * never check whether we received a probe response!
  2717. */
  2718. if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL)
  2719. already = true;
  2720. ifmgd->flags |= IEEE80211_STA_CONNECTION_POLL;
  2721. mutex_unlock(&sdata->local->mtx);
  2722. if (already)
  2723. goto out;
  2724. mutex_lock(&sdata->local->iflist_mtx);
  2725. ieee80211_recalc_ps(sdata->local);
  2726. mutex_unlock(&sdata->local->iflist_mtx);
  2727. ifmgd->probe_send_count = 0;
  2728. ieee80211_mgd_probe_ap_send(sdata);
  2729. out:
  2730. sdata_unlock(sdata);
  2731. }
  2732. struct sk_buff *ieee80211_ap_probereq_get(struct ieee80211_hw *hw,
  2733. struct ieee80211_vif *vif)
  2734. {
  2735. struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
  2736. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  2737. struct cfg80211_bss *cbss;
  2738. struct sk_buff *skb;
  2739. const struct element *ssid;
  2740. int ssid_len;
  2741. if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION ||
  2742. sdata->vif.valid_links))
  2743. return NULL;
  2744. sdata_assert_lock(sdata);
  2745. if (ifmgd->associated)
  2746. cbss = sdata->deflink.u.mgd.bss;
  2747. else if (ifmgd->auth_data)
  2748. cbss = ifmgd->auth_data->bss;
  2749. else if (ifmgd->assoc_data && ifmgd->assoc_data->link[0].bss)
  2750. cbss = ifmgd->assoc_data->link[0].bss;
  2751. else
  2752. return NULL;
  2753. rcu_read_lock();
  2754. ssid = ieee80211_bss_get_elem(cbss, WLAN_EID_SSID);
  2755. if (WARN_ONCE(!ssid || ssid->datalen > IEEE80211_MAX_SSID_LEN,
  2756. "invalid SSID element (len=%d)",
  2757. ssid ? ssid->datalen : -1))
  2758. ssid_len = 0;
  2759. else
  2760. ssid_len = ssid->datalen;
  2761. skb = ieee80211_build_probe_req(sdata, sdata->vif.addr, cbss->bssid,
  2762. (u32) -1, cbss->channel,
  2763. ssid->data, ssid_len,
  2764. NULL, 0, IEEE80211_PROBE_FLAG_DIRECTED);
  2765. rcu_read_unlock();
  2766. return skb;
  2767. }
  2768. EXPORT_SYMBOL(ieee80211_ap_probereq_get);
  2769. static void ieee80211_report_disconnect(struct ieee80211_sub_if_data *sdata,
  2770. const u8 *buf, size_t len, bool tx,
  2771. u16 reason, bool reconnect)
  2772. {
  2773. struct ieee80211_event event = {
  2774. .type = MLME_EVENT,
  2775. .u.mlme.data = tx ? DEAUTH_TX_EVENT : DEAUTH_RX_EVENT,
  2776. .u.mlme.reason = reason,
  2777. };
  2778. if (tx)
  2779. cfg80211_tx_mlme_mgmt(sdata->dev, buf, len, reconnect);
  2780. else
  2781. cfg80211_rx_mlme_mgmt(sdata->dev, buf, len);
  2782. drv_event_callback(sdata->local, sdata, &event);
  2783. }
  2784. static void __ieee80211_disconnect(struct ieee80211_sub_if_data *sdata)
  2785. {
  2786. struct ieee80211_local *local = sdata->local;
  2787. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  2788. u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
  2789. bool tx;
  2790. sdata_lock(sdata);
  2791. if (!ifmgd->associated) {
  2792. sdata_unlock(sdata);
  2793. return;
  2794. }
  2795. /* in MLO assume we have a link where we can TX the frame */
  2796. tx = sdata->vif.valid_links || !sdata->deflink.csa_block_tx;
  2797. if (!ifmgd->driver_disconnect) {
  2798. unsigned int link_id;
  2799. /*
  2800. * AP is probably out of range (or not reachable for another
  2801. * reason) so remove the bss structs for that AP. In the case
  2802. * of multi-link, it's not clear that all of them really are
  2803. * out of range, but if they weren't the driver likely would
  2804. * have switched to just have a single link active?
  2805. */
  2806. for (link_id = 0;
  2807. link_id < ARRAY_SIZE(sdata->link);
  2808. link_id++) {
  2809. struct ieee80211_link_data *link;
  2810. link = sdata_dereference(sdata->link[link_id], sdata);
  2811. if (!link)
  2812. continue;
  2813. cfg80211_unlink_bss(local->hw.wiphy, link->u.mgd.bss);
  2814. link->u.mgd.bss = NULL;
  2815. }
  2816. }
  2817. ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
  2818. ifmgd->driver_disconnect ?
  2819. WLAN_REASON_DEAUTH_LEAVING :
  2820. WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY,
  2821. tx, frame_buf);
  2822. mutex_lock(&local->mtx);
  2823. /* the other links will be destroyed */
  2824. sdata->vif.bss_conf.csa_active = false;
  2825. sdata->deflink.u.mgd.csa_waiting_bcn = false;
  2826. if (sdata->deflink.csa_block_tx) {
  2827. ieee80211_wake_vif_queues(local, sdata,
  2828. IEEE80211_QUEUE_STOP_REASON_CSA);
  2829. sdata->deflink.csa_block_tx = false;
  2830. }
  2831. mutex_unlock(&local->mtx);
  2832. ieee80211_report_disconnect(sdata, frame_buf, sizeof(frame_buf), tx,
  2833. WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY,
  2834. ifmgd->reconnect);
  2835. ifmgd->reconnect = false;
  2836. sdata_unlock(sdata);
  2837. }
  2838. static void ieee80211_beacon_connection_loss_work(struct work_struct *work)
  2839. {
  2840. struct ieee80211_sub_if_data *sdata =
  2841. container_of(work, struct ieee80211_sub_if_data,
  2842. u.mgd.beacon_connection_loss_work);
  2843. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  2844. if (ifmgd->connection_loss) {
  2845. sdata_info(sdata, "Connection to AP %pM lost\n",
  2846. sdata->vif.cfg.ap_addr);
  2847. __ieee80211_disconnect(sdata);
  2848. ifmgd->connection_loss = false;
  2849. } else if (ifmgd->driver_disconnect) {
  2850. sdata_info(sdata,
  2851. "Driver requested disconnection from AP %pM\n",
  2852. sdata->vif.cfg.ap_addr);
  2853. __ieee80211_disconnect(sdata);
  2854. ifmgd->driver_disconnect = false;
  2855. } else {
  2856. if (ifmgd->associated)
  2857. sdata->deflink.u.mgd.beacon_loss_count++;
  2858. ieee80211_mgd_probe_ap(sdata, true);
  2859. }
  2860. }
  2861. static void ieee80211_csa_connection_drop_work(struct work_struct *work)
  2862. {
  2863. struct ieee80211_sub_if_data *sdata =
  2864. container_of(work, struct ieee80211_sub_if_data,
  2865. u.mgd.csa_connection_drop_work);
  2866. __ieee80211_disconnect(sdata);
  2867. }
  2868. void ieee80211_beacon_loss(struct ieee80211_vif *vif)
  2869. {
  2870. struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
  2871. struct ieee80211_hw *hw = &sdata->local->hw;
  2872. trace_api_beacon_loss(sdata);
  2873. sdata->u.mgd.connection_loss = false;
  2874. ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work);
  2875. }
  2876. EXPORT_SYMBOL(ieee80211_beacon_loss);
  2877. void ieee80211_connection_loss(struct ieee80211_vif *vif)
  2878. {
  2879. struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
  2880. struct ieee80211_hw *hw = &sdata->local->hw;
  2881. trace_api_connection_loss(sdata);
  2882. sdata->u.mgd.connection_loss = true;
  2883. ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work);
  2884. }
  2885. EXPORT_SYMBOL(ieee80211_connection_loss);
  2886. void ieee80211_disconnect(struct ieee80211_vif *vif, bool reconnect)
  2887. {
  2888. struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
  2889. struct ieee80211_hw *hw = &sdata->local->hw;
  2890. trace_api_disconnect(sdata, reconnect);
  2891. if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
  2892. return;
  2893. sdata->u.mgd.driver_disconnect = true;
  2894. sdata->u.mgd.reconnect = reconnect;
  2895. ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work);
  2896. }
  2897. EXPORT_SYMBOL(ieee80211_disconnect);
  2898. static void ieee80211_destroy_auth_data(struct ieee80211_sub_if_data *sdata,
  2899. bool assoc)
  2900. {
  2901. struct ieee80211_mgd_auth_data *auth_data = sdata->u.mgd.auth_data;
  2902. sdata_assert_lock(sdata);
  2903. if (!assoc) {
  2904. /*
  2905. * we are not authenticated yet, the only timer that could be
  2906. * running is the timeout for the authentication response which
  2907. * which is not relevant anymore.
  2908. */
  2909. del_timer_sync(&sdata->u.mgd.timer);
  2910. sta_info_destroy_addr(sdata, auth_data->ap_addr);
  2911. /* other links are destroyed */
  2912. sdata->deflink.u.mgd.conn_flags = 0;
  2913. eth_zero_addr(sdata->deflink.u.mgd.bssid);
  2914. ieee80211_link_info_change_notify(sdata, &sdata->deflink,
  2915. BSS_CHANGED_BSSID);
  2916. sdata->u.mgd.flags = 0;
  2917. mutex_lock(&sdata->local->mtx);
  2918. ieee80211_link_release_channel(&sdata->deflink);
  2919. ieee80211_vif_set_links(sdata, 0);
  2920. mutex_unlock(&sdata->local->mtx);
  2921. }
  2922. cfg80211_put_bss(sdata->local->hw.wiphy, auth_data->bss);
  2923. kfree(auth_data);
  2924. sdata->u.mgd.auth_data = NULL;
  2925. }
  2926. enum assoc_status {
  2927. ASSOC_SUCCESS,
  2928. ASSOC_REJECTED,
  2929. ASSOC_TIMEOUT,
  2930. ASSOC_ABANDON,
  2931. };
  2932. static void ieee80211_destroy_assoc_data(struct ieee80211_sub_if_data *sdata,
  2933. enum assoc_status status)
  2934. {
  2935. struct ieee80211_mgd_assoc_data *assoc_data = sdata->u.mgd.assoc_data;
  2936. sdata_assert_lock(sdata);
  2937. if (status != ASSOC_SUCCESS) {
  2938. /*
  2939. * we are not associated yet, the only timer that could be
  2940. * running is the timeout for the association response which
  2941. * which is not relevant anymore.
  2942. */
  2943. del_timer_sync(&sdata->u.mgd.timer);
  2944. sta_info_destroy_addr(sdata, assoc_data->ap_addr);
  2945. sdata->deflink.u.mgd.conn_flags = 0;
  2946. eth_zero_addr(sdata->deflink.u.mgd.bssid);
  2947. ieee80211_link_info_change_notify(sdata, &sdata->deflink,
  2948. BSS_CHANGED_BSSID);
  2949. sdata->u.mgd.flags = 0;
  2950. sdata->vif.bss_conf.mu_mimo_owner = false;
  2951. if (status != ASSOC_REJECTED) {
  2952. struct cfg80211_assoc_failure data = {
  2953. .timeout = status == ASSOC_TIMEOUT,
  2954. };
  2955. int i;
  2956. BUILD_BUG_ON(ARRAY_SIZE(data.bss) !=
  2957. ARRAY_SIZE(assoc_data->link));
  2958. for (i = 0; i < ARRAY_SIZE(data.bss); i++)
  2959. data.bss[i] = assoc_data->link[i].bss;
  2960. if (sdata->vif.valid_links)
  2961. data.ap_mld_addr = assoc_data->ap_addr;
  2962. cfg80211_assoc_failure(sdata->dev, &data);
  2963. }
  2964. mutex_lock(&sdata->local->mtx);
  2965. ieee80211_link_release_channel(&sdata->deflink);
  2966. ieee80211_vif_set_links(sdata, 0);
  2967. mutex_unlock(&sdata->local->mtx);
  2968. }
  2969. kfree(assoc_data);
  2970. sdata->u.mgd.assoc_data = NULL;
  2971. }
  2972. static void ieee80211_auth_challenge(struct ieee80211_sub_if_data *sdata,
  2973. struct ieee80211_mgmt *mgmt, size_t len)
  2974. {
  2975. struct ieee80211_local *local = sdata->local;
  2976. struct ieee80211_mgd_auth_data *auth_data = sdata->u.mgd.auth_data;
  2977. const struct element *challenge;
  2978. u8 *pos;
  2979. u32 tx_flags = 0;
  2980. struct ieee80211_prep_tx_info info = {
  2981. .subtype = IEEE80211_STYPE_AUTH,
  2982. };
  2983. pos = mgmt->u.auth.variable;
  2984. challenge = cfg80211_find_elem(WLAN_EID_CHALLENGE, pos,
  2985. len - (pos - (u8 *)mgmt));
  2986. if (!challenge)
  2987. return;
  2988. auth_data->expected_transaction = 4;
  2989. drv_mgd_prepare_tx(sdata->local, sdata, &info);
  2990. if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
  2991. tx_flags = IEEE80211_TX_CTL_REQ_TX_STATUS |
  2992. IEEE80211_TX_INTFL_MLME_CONN_TX;
  2993. ieee80211_send_auth(sdata, 3, auth_data->algorithm, 0,
  2994. (void *)challenge,
  2995. challenge->datalen + sizeof(*challenge),
  2996. auth_data->ap_addr, auth_data->ap_addr,
  2997. auth_data->key, auth_data->key_len,
  2998. auth_data->key_idx, tx_flags);
  2999. }
  3000. static bool ieee80211_mark_sta_auth(struct ieee80211_sub_if_data *sdata)
  3001. {
  3002. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  3003. const u8 *ap_addr = ifmgd->auth_data->ap_addr;
  3004. struct sta_info *sta;
  3005. bool result = true;
  3006. sdata_info(sdata, "authenticated\n");
  3007. ifmgd->auth_data->done = true;
  3008. ifmgd->auth_data->timeout = jiffies + IEEE80211_AUTH_WAIT_ASSOC;
  3009. ifmgd->auth_data->timeout_started = true;
  3010. run_again(sdata, ifmgd->auth_data->timeout);
  3011. /* move station state to auth */
  3012. mutex_lock(&sdata->local->sta_mtx);
  3013. sta = sta_info_get(sdata, ap_addr);
  3014. if (!sta) {
  3015. WARN_ONCE(1, "%s: STA %pM not found", sdata->name, ap_addr);
  3016. result = false;
  3017. goto out;
  3018. }
  3019. if (sta_info_move_state(sta, IEEE80211_STA_AUTH)) {
  3020. sdata_info(sdata, "failed moving %pM to auth\n", ap_addr);
  3021. result = false;
  3022. goto out;
  3023. }
  3024. out:
  3025. mutex_unlock(&sdata->local->sta_mtx);
  3026. return result;
  3027. }
  3028. static void ieee80211_rx_mgmt_auth(struct ieee80211_sub_if_data *sdata,
  3029. struct ieee80211_mgmt *mgmt, size_t len)
  3030. {
  3031. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  3032. u16 auth_alg, auth_transaction, status_code;
  3033. struct ieee80211_event event = {
  3034. .type = MLME_EVENT,
  3035. .u.mlme.data = AUTH_EVENT,
  3036. };
  3037. struct ieee80211_prep_tx_info info = {
  3038. .subtype = IEEE80211_STYPE_AUTH,
  3039. };
  3040. sdata_assert_lock(sdata);
  3041. if (len < 24 + 6)
  3042. return;
  3043. if (!ifmgd->auth_data || ifmgd->auth_data->done)
  3044. return;
  3045. if (!ether_addr_equal(ifmgd->auth_data->ap_addr, mgmt->bssid))
  3046. return;
  3047. auth_alg = le16_to_cpu(mgmt->u.auth.auth_alg);
  3048. auth_transaction = le16_to_cpu(mgmt->u.auth.auth_transaction);
  3049. status_code = le16_to_cpu(mgmt->u.auth.status_code);
  3050. if (auth_alg != ifmgd->auth_data->algorithm ||
  3051. (auth_alg != WLAN_AUTH_SAE &&
  3052. auth_transaction != ifmgd->auth_data->expected_transaction) ||
  3053. (auth_alg == WLAN_AUTH_SAE &&
  3054. (auth_transaction < ifmgd->auth_data->expected_transaction ||
  3055. auth_transaction > 2))) {
  3056. sdata_info(sdata, "%pM unexpected authentication state: alg %d (expected %d) transact %d (expected %d)\n",
  3057. mgmt->sa, auth_alg, ifmgd->auth_data->algorithm,
  3058. auth_transaction,
  3059. ifmgd->auth_data->expected_transaction);
  3060. goto notify_driver;
  3061. }
  3062. if (status_code != WLAN_STATUS_SUCCESS) {
  3063. cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len);
  3064. if (auth_alg == WLAN_AUTH_SAE &&
  3065. (status_code == WLAN_STATUS_ANTI_CLOG_REQUIRED ||
  3066. (auth_transaction == 1 &&
  3067. (status_code == WLAN_STATUS_SAE_HASH_TO_ELEMENT ||
  3068. status_code == WLAN_STATUS_SAE_PK)))) {
  3069. /* waiting for userspace now */
  3070. ifmgd->auth_data->waiting = true;
  3071. ifmgd->auth_data->timeout =
  3072. jiffies + IEEE80211_AUTH_WAIT_SAE_RETRY;
  3073. ifmgd->auth_data->timeout_started = true;
  3074. run_again(sdata, ifmgd->auth_data->timeout);
  3075. goto notify_driver;
  3076. }
  3077. sdata_info(sdata, "%pM denied authentication (status %d)\n",
  3078. mgmt->sa, status_code);
  3079. ieee80211_destroy_auth_data(sdata, false);
  3080. event.u.mlme.status = MLME_DENIED;
  3081. event.u.mlme.reason = status_code;
  3082. drv_event_callback(sdata->local, sdata, &event);
  3083. goto notify_driver;
  3084. }
  3085. switch (ifmgd->auth_data->algorithm) {
  3086. case WLAN_AUTH_OPEN:
  3087. case WLAN_AUTH_LEAP:
  3088. case WLAN_AUTH_FT:
  3089. case WLAN_AUTH_SAE:
  3090. case WLAN_AUTH_FILS_SK:
  3091. case WLAN_AUTH_FILS_SK_PFS:
  3092. case WLAN_AUTH_FILS_PK:
  3093. break;
  3094. case WLAN_AUTH_SHARED_KEY:
  3095. if (ifmgd->auth_data->expected_transaction != 4) {
  3096. ieee80211_auth_challenge(sdata, mgmt, len);
  3097. /* need another frame */
  3098. return;
  3099. }
  3100. break;
  3101. default:
  3102. WARN_ONCE(1, "invalid auth alg %d",
  3103. ifmgd->auth_data->algorithm);
  3104. goto notify_driver;
  3105. }
  3106. event.u.mlme.status = MLME_SUCCESS;
  3107. info.success = 1;
  3108. drv_event_callback(sdata->local, sdata, &event);
  3109. if (ifmgd->auth_data->algorithm != WLAN_AUTH_SAE ||
  3110. (auth_transaction == 2 &&
  3111. ifmgd->auth_data->expected_transaction == 2)) {
  3112. if (!ieee80211_mark_sta_auth(sdata))
  3113. return; /* ignore frame -- wait for timeout */
  3114. } else if (ifmgd->auth_data->algorithm == WLAN_AUTH_SAE &&
  3115. auth_transaction == 2) {
  3116. sdata_info(sdata, "SAE peer confirmed\n");
  3117. ifmgd->auth_data->peer_confirmed = true;
  3118. }
  3119. cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len);
  3120. notify_driver:
  3121. drv_mgd_complete_tx(sdata->local, sdata, &info);
  3122. }
  3123. #define case_WLAN(type) \
  3124. case WLAN_REASON_##type: return #type
  3125. const char *ieee80211_get_reason_code_string(u16 reason_code)
  3126. {
  3127. switch (reason_code) {
  3128. case_WLAN(UNSPECIFIED);
  3129. case_WLAN(PREV_AUTH_NOT_VALID);
  3130. case_WLAN(DEAUTH_LEAVING);
  3131. case_WLAN(DISASSOC_DUE_TO_INACTIVITY);
  3132. case_WLAN(DISASSOC_AP_BUSY);
  3133. case_WLAN(CLASS2_FRAME_FROM_NONAUTH_STA);
  3134. case_WLAN(CLASS3_FRAME_FROM_NONASSOC_STA);
  3135. case_WLAN(DISASSOC_STA_HAS_LEFT);
  3136. case_WLAN(STA_REQ_ASSOC_WITHOUT_AUTH);
  3137. case_WLAN(DISASSOC_BAD_POWER);
  3138. case_WLAN(DISASSOC_BAD_SUPP_CHAN);
  3139. case_WLAN(INVALID_IE);
  3140. case_WLAN(MIC_FAILURE);
  3141. case_WLAN(4WAY_HANDSHAKE_TIMEOUT);
  3142. case_WLAN(GROUP_KEY_HANDSHAKE_TIMEOUT);
  3143. case_WLAN(IE_DIFFERENT);
  3144. case_WLAN(INVALID_GROUP_CIPHER);
  3145. case_WLAN(INVALID_PAIRWISE_CIPHER);
  3146. case_WLAN(INVALID_AKMP);
  3147. case_WLAN(UNSUPP_RSN_VERSION);
  3148. case_WLAN(INVALID_RSN_IE_CAP);
  3149. case_WLAN(IEEE8021X_FAILED);
  3150. case_WLAN(CIPHER_SUITE_REJECTED);
  3151. case_WLAN(DISASSOC_UNSPECIFIED_QOS);
  3152. case_WLAN(DISASSOC_QAP_NO_BANDWIDTH);
  3153. case_WLAN(DISASSOC_LOW_ACK);
  3154. case_WLAN(DISASSOC_QAP_EXCEED_TXOP);
  3155. case_WLAN(QSTA_LEAVE_QBSS);
  3156. case_WLAN(QSTA_NOT_USE);
  3157. case_WLAN(QSTA_REQUIRE_SETUP);
  3158. case_WLAN(QSTA_TIMEOUT);
  3159. case_WLAN(QSTA_CIPHER_NOT_SUPP);
  3160. case_WLAN(MESH_PEER_CANCELED);
  3161. case_WLAN(MESH_MAX_PEERS);
  3162. case_WLAN(MESH_CONFIG);
  3163. case_WLAN(MESH_CLOSE);
  3164. case_WLAN(MESH_MAX_RETRIES);
  3165. case_WLAN(MESH_CONFIRM_TIMEOUT);
  3166. case_WLAN(MESH_INVALID_GTK);
  3167. case_WLAN(MESH_INCONSISTENT_PARAM);
  3168. case_WLAN(MESH_INVALID_SECURITY);
  3169. case_WLAN(MESH_PATH_ERROR);
  3170. case_WLAN(MESH_PATH_NOFORWARD);
  3171. case_WLAN(MESH_PATH_DEST_UNREACHABLE);
  3172. case_WLAN(MAC_EXISTS_IN_MBSS);
  3173. case_WLAN(MESH_CHAN_REGULATORY);
  3174. case_WLAN(MESH_CHAN);
  3175. default: return "<unknown>";
  3176. }
  3177. }
  3178. static void ieee80211_rx_mgmt_deauth(struct ieee80211_sub_if_data *sdata,
  3179. struct ieee80211_mgmt *mgmt, size_t len)
  3180. {
  3181. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  3182. u16 reason_code = le16_to_cpu(mgmt->u.deauth.reason_code);
  3183. sdata_assert_lock(sdata);
  3184. if (len < 24 + 2)
  3185. return;
  3186. if (!ether_addr_equal(mgmt->bssid, mgmt->sa)) {
  3187. ieee80211_tdls_handle_disconnect(sdata, mgmt->sa, reason_code);
  3188. return;
  3189. }
  3190. if (ifmgd->associated &&
  3191. ether_addr_equal(mgmt->bssid, sdata->vif.cfg.ap_addr)) {
  3192. sdata_info(sdata, "deauthenticated from %pM (Reason: %u=%s)\n",
  3193. sdata->vif.cfg.ap_addr, reason_code,
  3194. ieee80211_get_reason_code_string(reason_code));
  3195. ieee80211_set_disassoc(sdata, 0, 0, false, NULL);
  3196. ieee80211_report_disconnect(sdata, (u8 *)mgmt, len, false,
  3197. reason_code, false);
  3198. return;
  3199. }
  3200. if (ifmgd->assoc_data &&
  3201. ether_addr_equal(mgmt->bssid, ifmgd->assoc_data->ap_addr)) {
  3202. sdata_info(sdata,
  3203. "deauthenticated from %pM while associating (Reason: %u=%s)\n",
  3204. ifmgd->assoc_data->ap_addr, reason_code,
  3205. ieee80211_get_reason_code_string(reason_code));
  3206. ieee80211_destroy_assoc_data(sdata, ASSOC_ABANDON);
  3207. cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len);
  3208. return;
  3209. }
  3210. }
  3211. static void ieee80211_rx_mgmt_disassoc(struct ieee80211_sub_if_data *sdata,
  3212. struct ieee80211_mgmt *mgmt, size_t len)
  3213. {
  3214. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  3215. u16 reason_code;
  3216. sdata_assert_lock(sdata);
  3217. if (len < 24 + 2)
  3218. return;
  3219. if (!ifmgd->associated ||
  3220. !ether_addr_equal(mgmt->bssid, sdata->vif.cfg.ap_addr))
  3221. return;
  3222. reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code);
  3223. if (!ether_addr_equal(mgmt->bssid, mgmt->sa)) {
  3224. ieee80211_tdls_handle_disconnect(sdata, mgmt->sa, reason_code);
  3225. return;
  3226. }
  3227. sdata_info(sdata, "disassociated from %pM (Reason: %u=%s)\n",
  3228. sdata->vif.cfg.ap_addr, reason_code,
  3229. ieee80211_get_reason_code_string(reason_code));
  3230. ieee80211_set_disassoc(sdata, 0, 0, false, NULL);
  3231. ieee80211_report_disconnect(sdata, (u8 *)mgmt, len, false, reason_code,
  3232. false);
  3233. }
  3234. static void ieee80211_get_rates(struct ieee80211_supported_band *sband,
  3235. u8 *supp_rates, unsigned int supp_rates_len,
  3236. u32 *rates, u32 *basic_rates,
  3237. bool *have_higher_than_11mbit,
  3238. int *min_rate, int *min_rate_index,
  3239. int shift)
  3240. {
  3241. int i, j;
  3242. for (i = 0; i < supp_rates_len; i++) {
  3243. int rate = supp_rates[i] & 0x7f;
  3244. bool is_basic = !!(supp_rates[i] & 0x80);
  3245. if ((rate * 5 * (1 << shift)) > 110)
  3246. *have_higher_than_11mbit = true;
  3247. /*
  3248. * Skip HT, VHT, HE and SAE H2E only BSS membership selectors
  3249. * since they're not rates.
  3250. *
  3251. * Note: Even though the membership selector and the basic
  3252. * rate flag share the same bit, they are not exactly
  3253. * the same.
  3254. */
  3255. if (supp_rates[i] == (0x80 | BSS_MEMBERSHIP_SELECTOR_HT_PHY) ||
  3256. supp_rates[i] == (0x80 | BSS_MEMBERSHIP_SELECTOR_VHT_PHY) ||
  3257. supp_rates[i] == (0x80 | BSS_MEMBERSHIP_SELECTOR_HE_PHY) ||
  3258. supp_rates[i] == (0x80 | BSS_MEMBERSHIP_SELECTOR_SAE_H2E))
  3259. continue;
  3260. for (j = 0; j < sband->n_bitrates; j++) {
  3261. struct ieee80211_rate *br;
  3262. int brate;
  3263. br = &sband->bitrates[j];
  3264. brate = DIV_ROUND_UP(br->bitrate, (1 << shift) * 5);
  3265. if (brate == rate) {
  3266. *rates |= BIT(j);
  3267. if (is_basic)
  3268. *basic_rates |= BIT(j);
  3269. if ((rate * 5) < *min_rate) {
  3270. *min_rate = rate * 5;
  3271. *min_rate_index = j;
  3272. }
  3273. break;
  3274. }
  3275. }
  3276. }
  3277. }
  3278. static bool ieee80211_twt_req_supported(const struct link_sta_info *link_sta,
  3279. const struct ieee802_11_elems *elems)
  3280. {
  3281. if (elems->ext_capab_len < 10)
  3282. return false;
  3283. if (!(elems->ext_capab[9] & WLAN_EXT_CAPA10_TWT_RESPONDER_SUPPORT))
  3284. return false;
  3285. return link_sta->pub->he_cap.he_cap_elem.mac_cap_info[0] &
  3286. IEEE80211_HE_MAC_CAP0_TWT_RES;
  3287. }
  3288. static int ieee80211_recalc_twt_req(struct ieee80211_link_data *link,
  3289. struct link_sta_info *link_sta,
  3290. struct ieee802_11_elems *elems)
  3291. {
  3292. bool twt = ieee80211_twt_req_supported(link_sta, elems);
  3293. if (link->conf->twt_requester != twt) {
  3294. link->conf->twt_requester = twt;
  3295. return BSS_CHANGED_TWT;
  3296. }
  3297. return 0;
  3298. }
  3299. static bool ieee80211_twt_bcast_support(struct ieee80211_sub_if_data *sdata,
  3300. struct ieee80211_bss_conf *bss_conf,
  3301. struct ieee80211_supported_band *sband,
  3302. struct link_sta_info *link_sta)
  3303. {
  3304. const struct ieee80211_sta_he_cap *own_he_cap =
  3305. ieee80211_get_he_iftype_cap(sband,
  3306. ieee80211_vif_type_p2p(&sdata->vif));
  3307. return bss_conf->he_support &&
  3308. (link_sta->pub->he_cap.he_cap_elem.mac_cap_info[2] &
  3309. IEEE80211_HE_MAC_CAP2_BCAST_TWT) &&
  3310. own_he_cap &&
  3311. (own_he_cap->he_cap_elem.mac_cap_info[2] &
  3312. IEEE80211_HE_MAC_CAP2_BCAST_TWT);
  3313. }
  3314. static bool ieee80211_assoc_config_link(struct ieee80211_link_data *link,
  3315. struct link_sta_info *link_sta,
  3316. struct cfg80211_bss *cbss,
  3317. struct ieee80211_mgmt *mgmt,
  3318. const u8 *elem_start,
  3319. unsigned int elem_len,
  3320. u64 *changed)
  3321. {
  3322. struct ieee80211_sub_if_data *sdata = link->sdata;
  3323. struct ieee80211_mgd_assoc_data *assoc_data = sdata->u.mgd.assoc_data;
  3324. struct ieee80211_bss_conf *bss_conf = link->conf;
  3325. struct ieee80211_local *local = sdata->local;
  3326. struct ieee80211_elems_parse_params parse_params = {
  3327. .start = elem_start,
  3328. .len = elem_len,
  3329. .bss = cbss,
  3330. .link_id = link == &sdata->deflink ? -1 : link->link_id,
  3331. .from_ap = true,
  3332. };
  3333. bool is_6ghz = cbss->channel->band == NL80211_BAND_6GHZ;
  3334. bool is_s1g = cbss->channel->band == NL80211_BAND_S1GHZ;
  3335. const struct cfg80211_bss_ies *bss_ies = NULL;
  3336. struct ieee80211_supported_band *sband;
  3337. struct ieee802_11_elems *elems;
  3338. u16 capab_info;
  3339. bool ret;
  3340. elems = ieee802_11_parse_elems_full(&parse_params);
  3341. if (!elems)
  3342. return false;
  3343. /* FIXME: use from STA profile element after parsing that */
  3344. capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
  3345. if (!is_s1g && !elems->supp_rates) {
  3346. sdata_info(sdata, "no SuppRates element in AssocResp\n");
  3347. ret = false;
  3348. goto out;
  3349. }
  3350. link->u.mgd.tdls_chan_switch_prohibited =
  3351. elems->ext_capab && elems->ext_capab_len >= 5 &&
  3352. (elems->ext_capab[4] & WLAN_EXT_CAPA5_TDLS_CH_SW_PROHIBITED);
  3353. /*
  3354. * Some APs are erroneously not including some information in their
  3355. * (re)association response frames. Try to recover by using the data
  3356. * from the beacon or probe response. This seems to afflict mobile
  3357. * 2G/3G/4G wifi routers, reported models include the "Onda PN51T",
  3358. * "Vodafone PocketWiFi 2", "ZTE MF60" and a similar T-Mobile device.
  3359. */
  3360. if (!is_6ghz &&
  3361. ((assoc_data->wmm && !elems->wmm_param) ||
  3362. (!(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_HT) &&
  3363. (!elems->ht_cap_elem || !elems->ht_operation)) ||
  3364. (!(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_VHT) &&
  3365. (!elems->vht_cap_elem || !elems->vht_operation)))) {
  3366. const struct cfg80211_bss_ies *ies;
  3367. struct ieee802_11_elems *bss_elems;
  3368. rcu_read_lock();
  3369. ies = rcu_dereference(cbss->ies);
  3370. if (ies)
  3371. bss_ies = kmemdup(ies, sizeof(*ies) + ies->len,
  3372. GFP_ATOMIC);
  3373. rcu_read_unlock();
  3374. if (!bss_ies) {
  3375. ret = false;
  3376. goto out;
  3377. }
  3378. parse_params.start = bss_ies->data;
  3379. parse_params.len = bss_ies->len;
  3380. bss_elems = ieee802_11_parse_elems_full(&parse_params);
  3381. if (!bss_elems) {
  3382. ret = false;
  3383. goto out;
  3384. }
  3385. if (assoc_data->wmm &&
  3386. !elems->wmm_param && bss_elems->wmm_param) {
  3387. elems->wmm_param = bss_elems->wmm_param;
  3388. sdata_info(sdata,
  3389. "AP bug: WMM param missing from AssocResp\n");
  3390. }
  3391. /*
  3392. * Also check if we requested HT/VHT, otherwise the AP doesn't
  3393. * have to include the IEs in the (re)association response.
  3394. */
  3395. if (!elems->ht_cap_elem && bss_elems->ht_cap_elem &&
  3396. !(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_HT)) {
  3397. elems->ht_cap_elem = bss_elems->ht_cap_elem;
  3398. sdata_info(sdata,
  3399. "AP bug: HT capability missing from AssocResp\n");
  3400. }
  3401. if (!elems->ht_operation && bss_elems->ht_operation &&
  3402. !(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_HT)) {
  3403. elems->ht_operation = bss_elems->ht_operation;
  3404. sdata_info(sdata,
  3405. "AP bug: HT operation missing from AssocResp\n");
  3406. }
  3407. if (!elems->vht_cap_elem && bss_elems->vht_cap_elem &&
  3408. !(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_VHT)) {
  3409. elems->vht_cap_elem = bss_elems->vht_cap_elem;
  3410. sdata_info(sdata,
  3411. "AP bug: VHT capa missing from AssocResp\n");
  3412. }
  3413. if (!elems->vht_operation && bss_elems->vht_operation &&
  3414. !(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_VHT)) {
  3415. elems->vht_operation = bss_elems->vht_operation;
  3416. sdata_info(sdata,
  3417. "AP bug: VHT operation missing from AssocResp\n");
  3418. }
  3419. kfree(bss_elems);
  3420. }
  3421. /*
  3422. * We previously checked these in the beacon/probe response, so
  3423. * they should be present here. This is just a safety net.
  3424. */
  3425. if (!is_6ghz && !(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_HT) &&
  3426. (!elems->wmm_param || !elems->ht_cap_elem || !elems->ht_operation)) {
  3427. sdata_info(sdata,
  3428. "HT AP is missing WMM params or HT capability/operation\n");
  3429. ret = false;
  3430. goto out;
  3431. }
  3432. if (!is_6ghz && !(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_VHT) &&
  3433. (!elems->vht_cap_elem || !elems->vht_operation)) {
  3434. sdata_info(sdata,
  3435. "VHT AP is missing VHT capability/operation\n");
  3436. ret = false;
  3437. goto out;
  3438. }
  3439. if (is_6ghz && !(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_HE) &&
  3440. !elems->he_6ghz_capa) {
  3441. sdata_info(sdata,
  3442. "HE 6 GHz AP is missing HE 6 GHz band capability\n");
  3443. ret = false;
  3444. goto out;
  3445. }
  3446. if (WARN_ON(!link->conf->chandef.chan)) {
  3447. ret = false;
  3448. goto out;
  3449. }
  3450. sband = local->hw.wiphy->bands[link->conf->chandef.chan->band];
  3451. if (!(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_HE) &&
  3452. (!elems->he_cap || !elems->he_operation)) {
  3453. sdata_info(sdata,
  3454. "HE AP is missing HE capability/operation\n");
  3455. ret = false;
  3456. goto out;
  3457. }
  3458. /* Set up internal HT/VHT capabilities */
  3459. if (elems->ht_cap_elem && !(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_HT))
  3460. ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
  3461. elems->ht_cap_elem,
  3462. link_sta);
  3463. if (elems->vht_cap_elem &&
  3464. !(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_VHT)) {
  3465. const struct ieee80211_vht_cap *bss_vht_cap = NULL;
  3466. const struct cfg80211_bss_ies *ies;
  3467. /*
  3468. * Cisco AP module 9115 with FW 17.3 has a bug and sends a
  3469. * too large maximum MPDU length in the association response
  3470. * (indicating 12k) that it cannot actually process ...
  3471. * Work around that.
  3472. */
  3473. rcu_read_lock();
  3474. ies = rcu_dereference(cbss->ies);
  3475. if (ies) {
  3476. const struct element *elem;
  3477. elem = cfg80211_find_elem(WLAN_EID_VHT_CAPABILITY,
  3478. ies->data, ies->len);
  3479. if (elem && elem->datalen >= sizeof(*bss_vht_cap))
  3480. bss_vht_cap = (const void *)elem->data;
  3481. }
  3482. ieee80211_vht_cap_ie_to_sta_vht_cap(sdata, sband,
  3483. elems->vht_cap_elem,
  3484. bss_vht_cap, link_sta);
  3485. rcu_read_unlock();
  3486. }
  3487. if (elems->he_operation && !(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_HE) &&
  3488. elems->he_cap) {
  3489. ieee80211_he_cap_ie_to_sta_he_cap(sdata, sband,
  3490. elems->he_cap,
  3491. elems->he_cap_len,
  3492. elems->he_6ghz_capa,
  3493. link_sta);
  3494. bss_conf->he_support = link_sta->pub->he_cap.has_he;
  3495. if (elems->rsnx && elems->rsnx_len &&
  3496. (elems->rsnx[0] & WLAN_RSNX_CAPA_PROTECTED_TWT) &&
  3497. wiphy_ext_feature_isset(local->hw.wiphy,
  3498. NL80211_EXT_FEATURE_PROTECTED_TWT))
  3499. bss_conf->twt_protected = true;
  3500. else
  3501. bss_conf->twt_protected = false;
  3502. *changed |= ieee80211_recalc_twt_req(link, link_sta, elems);
  3503. if (elems->eht_operation && elems->eht_cap &&
  3504. !(link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_EHT)) {
  3505. ieee80211_eht_cap_ie_to_sta_eht_cap(sdata, sband,
  3506. elems->he_cap,
  3507. elems->he_cap_len,
  3508. elems->eht_cap,
  3509. elems->eht_cap_len,
  3510. link_sta);
  3511. bss_conf->eht_support = link_sta->pub->eht_cap.has_eht;
  3512. } else {
  3513. bss_conf->eht_support = false;
  3514. }
  3515. } else {
  3516. bss_conf->he_support = false;
  3517. bss_conf->twt_requester = false;
  3518. bss_conf->twt_protected = false;
  3519. bss_conf->eht_support = false;
  3520. }
  3521. bss_conf->twt_broadcast =
  3522. ieee80211_twt_bcast_support(sdata, bss_conf, sband, link_sta);
  3523. if (bss_conf->he_support) {
  3524. bss_conf->he_bss_color.color =
  3525. le32_get_bits(elems->he_operation->he_oper_params,
  3526. IEEE80211_HE_OPERATION_BSS_COLOR_MASK);
  3527. bss_conf->he_bss_color.partial =
  3528. le32_get_bits(elems->he_operation->he_oper_params,
  3529. IEEE80211_HE_OPERATION_PARTIAL_BSS_COLOR);
  3530. bss_conf->he_bss_color.enabled =
  3531. !le32_get_bits(elems->he_operation->he_oper_params,
  3532. IEEE80211_HE_OPERATION_BSS_COLOR_DISABLED);
  3533. if (bss_conf->he_bss_color.enabled)
  3534. *changed |= BSS_CHANGED_HE_BSS_COLOR;
  3535. bss_conf->htc_trig_based_pkt_ext =
  3536. le32_get_bits(elems->he_operation->he_oper_params,
  3537. IEEE80211_HE_OPERATION_DFLT_PE_DURATION_MASK);
  3538. bss_conf->frame_time_rts_th =
  3539. le32_get_bits(elems->he_operation->he_oper_params,
  3540. IEEE80211_HE_OPERATION_RTS_THRESHOLD_MASK);
  3541. bss_conf->uora_exists = !!elems->uora_element;
  3542. if (elems->uora_element)
  3543. bss_conf->uora_ocw_range = elems->uora_element[0];
  3544. ieee80211_he_op_ie_to_bss_conf(&sdata->vif, elems->he_operation);
  3545. ieee80211_he_spr_ie_to_bss_conf(&sdata->vif, elems->he_spr);
  3546. /* TODO: OPEN: what happens if BSS color disable is set? */
  3547. }
  3548. if (cbss->transmitted_bss) {
  3549. bss_conf->nontransmitted = true;
  3550. ether_addr_copy(bss_conf->transmitter_bssid,
  3551. cbss->transmitted_bss->bssid);
  3552. bss_conf->bssid_indicator = cbss->max_bssid_indicator;
  3553. bss_conf->bssid_index = cbss->bssid_index;
  3554. }
  3555. /*
  3556. * Some APs, e.g. Netgear WNDR3700, report invalid HT operation data
  3557. * in their association response, so ignore that data for our own
  3558. * configuration. If it changed since the last beacon, we'll get the
  3559. * next beacon and update then.
  3560. */
  3561. /*
  3562. * If an operating mode notification IE is present, override the
  3563. * NSS calculation (that would be done in rate_control_rate_init())
  3564. * and use the # of streams from that element.
  3565. */
  3566. if (elems->opmode_notif &&
  3567. !(*elems->opmode_notif & IEEE80211_OPMODE_NOTIF_RX_NSS_TYPE_BF)) {
  3568. u8 nss;
  3569. nss = *elems->opmode_notif & IEEE80211_OPMODE_NOTIF_RX_NSS_MASK;
  3570. nss >>= IEEE80211_OPMODE_NOTIF_RX_NSS_SHIFT;
  3571. nss += 1;
  3572. link_sta->pub->rx_nss = nss;
  3573. }
  3574. /*
  3575. * Always handle WMM once after association regardless
  3576. * of the first value the AP uses. Setting -1 here has
  3577. * that effect because the AP values is an unsigned
  3578. * 4-bit value.
  3579. */
  3580. link->u.mgd.wmm_last_param_set = -1;
  3581. link->u.mgd.mu_edca_last_param_set = -1;
  3582. if (link->u.mgd.disable_wmm_tracking) {
  3583. ieee80211_set_wmm_default(link, false, false);
  3584. } else if (!ieee80211_sta_wmm_params(local, link, elems->wmm_param,
  3585. elems->wmm_param_len,
  3586. elems->mu_edca_param_set)) {
  3587. /* still enable QoS since we might have HT/VHT */
  3588. ieee80211_set_wmm_default(link, false, true);
  3589. /* disable WMM tracking in this case to disable
  3590. * tracking WMM parameter changes in the beacon if
  3591. * the parameters weren't actually valid. Doing so
  3592. * avoids changing parameters very strangely when
  3593. * the AP is going back and forth between valid and
  3594. * invalid parameters.
  3595. */
  3596. link->u.mgd.disable_wmm_tracking = true;
  3597. }
  3598. if (elems->max_idle_period_ie) {
  3599. bss_conf->max_idle_period =
  3600. le16_to_cpu(elems->max_idle_period_ie->max_idle_period);
  3601. bss_conf->protected_keep_alive =
  3602. !!(elems->max_idle_period_ie->idle_options &
  3603. WLAN_IDLE_OPTIONS_PROTECTED_KEEP_ALIVE);
  3604. *changed |= BSS_CHANGED_KEEP_ALIVE;
  3605. } else {
  3606. bss_conf->max_idle_period = 0;
  3607. bss_conf->protected_keep_alive = false;
  3608. }
  3609. /* set assoc capability (AID was already set earlier),
  3610. * ieee80211_set_associated() will tell the driver */
  3611. bss_conf->assoc_capability = capab_info;
  3612. ret = true;
  3613. out:
  3614. kfree(elems);
  3615. kfree(bss_ies);
  3616. return ret;
  3617. }
  3618. static int ieee80211_mgd_setup_link_sta(struct ieee80211_link_data *link,
  3619. struct sta_info *sta,
  3620. struct link_sta_info *link_sta,
  3621. struct cfg80211_bss *cbss)
  3622. {
  3623. struct ieee80211_sub_if_data *sdata = link->sdata;
  3624. struct ieee80211_local *local = sdata->local;
  3625. struct ieee80211_bss *bss = (void *)cbss->priv;
  3626. u32 rates = 0, basic_rates = 0;
  3627. bool have_higher_than_11mbit = false;
  3628. int min_rate = INT_MAX, min_rate_index = -1;
  3629. /* this is clearly wrong for MLO but we'll just remove it later */
  3630. int shift = ieee80211_vif_get_shift(&sdata->vif);
  3631. struct ieee80211_supported_band *sband;
  3632. memcpy(link_sta->addr, cbss->bssid, ETH_ALEN);
  3633. memcpy(link_sta->pub->addr, cbss->bssid, ETH_ALEN);
  3634. /* TODO: S1G Basic Rate Set is expressed elsewhere */
  3635. if (cbss->channel->band == NL80211_BAND_S1GHZ) {
  3636. ieee80211_s1g_sta_rate_init(sta);
  3637. return 0;
  3638. }
  3639. sband = local->hw.wiphy->bands[cbss->channel->band];
  3640. ieee80211_get_rates(sband, bss->supp_rates, bss->supp_rates_len,
  3641. &rates, &basic_rates, &have_higher_than_11mbit,
  3642. &min_rate, &min_rate_index, shift);
  3643. /*
  3644. * This used to be a workaround for basic rates missing
  3645. * in the association response frame. Now that we no
  3646. * longer use the basic rates from there, it probably
  3647. * doesn't happen any more, but keep the workaround so
  3648. * in case some *other* APs are buggy in different ways
  3649. * we can connect -- with a warning.
  3650. * Allow this workaround only in case the AP provided at least
  3651. * one rate.
  3652. */
  3653. if (min_rate_index < 0) {
  3654. link_info(link, "No legacy rates in association response\n");
  3655. return -EINVAL;
  3656. } else if (!basic_rates) {
  3657. link_info(link, "No basic rates, using min rate instead\n");
  3658. basic_rates = BIT(min_rate_index);
  3659. }
  3660. if (rates)
  3661. link_sta->pub->supp_rates[cbss->channel->band] = rates;
  3662. else
  3663. link_info(link, "No rates found, keeping mandatory only\n");
  3664. link->conf->basic_rates = basic_rates;
  3665. /* cf. IEEE 802.11 9.2.12 */
  3666. link->operating_11g_mode = sband->band == NL80211_BAND_2GHZ &&
  3667. have_higher_than_11mbit;
  3668. return 0;
  3669. }
  3670. static u8 ieee80211_max_rx_chains(struct ieee80211_link_data *link,
  3671. struct cfg80211_bss *cbss)
  3672. {
  3673. struct ieee80211_he_mcs_nss_supp *he_mcs_nss_supp;
  3674. const struct element *ht_cap_elem, *vht_cap_elem;
  3675. const struct cfg80211_bss_ies *ies;
  3676. const struct ieee80211_ht_cap *ht_cap;
  3677. const struct ieee80211_vht_cap *vht_cap;
  3678. const struct ieee80211_he_cap_elem *he_cap;
  3679. const struct element *he_cap_elem;
  3680. u16 mcs_80_map, mcs_160_map;
  3681. int i, mcs_nss_size;
  3682. bool support_160;
  3683. u8 chains = 1;
  3684. if (link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_HT)
  3685. return chains;
  3686. ht_cap_elem = ieee80211_bss_get_elem(cbss, WLAN_EID_HT_CAPABILITY);
  3687. if (ht_cap_elem && ht_cap_elem->datalen >= sizeof(*ht_cap)) {
  3688. ht_cap = (void *)ht_cap_elem->data;
  3689. chains = ieee80211_mcs_to_chains(&ht_cap->mcs);
  3690. /*
  3691. * TODO: use "Tx Maximum Number Spatial Streams Supported" and
  3692. * "Tx Unequal Modulation Supported" fields.
  3693. */
  3694. }
  3695. if (link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_VHT)
  3696. return chains;
  3697. vht_cap_elem = ieee80211_bss_get_elem(cbss, WLAN_EID_VHT_CAPABILITY);
  3698. if (vht_cap_elem && vht_cap_elem->datalen >= sizeof(*vht_cap)) {
  3699. u8 nss;
  3700. u16 tx_mcs_map;
  3701. vht_cap = (void *)vht_cap_elem->data;
  3702. tx_mcs_map = le16_to_cpu(vht_cap->supp_mcs.tx_mcs_map);
  3703. for (nss = 8; nss > 0; nss--) {
  3704. if (((tx_mcs_map >> (2 * (nss - 1))) & 3) !=
  3705. IEEE80211_VHT_MCS_NOT_SUPPORTED)
  3706. break;
  3707. }
  3708. /* TODO: use "Tx Highest Supported Long GI Data Rate" field? */
  3709. chains = max(chains, nss);
  3710. }
  3711. if (link->u.mgd.conn_flags & IEEE80211_CONN_DISABLE_HE)
  3712. return chains;
  3713. ies = rcu_dereference(cbss->ies);
  3714. he_cap_elem = cfg80211_find_ext_elem(WLAN_EID_EXT_HE_CAPABILITY,
  3715. ies->data, ies->len);
  3716. if (!he_cap_elem || he_cap_elem->datalen < sizeof(*he_cap))
  3717. return chains;
  3718. /* skip one byte ext_tag_id */
  3719. he_cap = (void *)(he_cap_elem->data + 1);
  3720. mcs_nss_size = ieee80211_he_mcs_nss_size(he_cap);
  3721. /* invalid HE IE */
  3722. if (he_cap_elem->datalen < 1 + mcs_nss_size + sizeof(*he_cap))
  3723. return chains;
  3724. /* mcs_nss is right after he_cap info */
  3725. he_mcs_nss_supp = (void *)(he_cap + 1);
  3726. mcs_80_map = le16_to_cpu(he_mcs_nss_supp->tx_mcs_80);
  3727. for (i = 7; i >= 0; i--) {
  3728. u8 mcs_80 = mcs_80_map >> (2 * i) & 3;
  3729. if (mcs_80 != IEEE80211_VHT_MCS_NOT_SUPPORTED) {
  3730. chains = max_t(u8, chains, i + 1);
  3731. break;
  3732. }
  3733. }
  3734. support_160 = he_cap->phy_cap_info[0] &
  3735. IEEE80211_HE_PHY_CAP0_CHANNEL_WIDTH_SET_160MHZ_IN_5G;
  3736. if (!support_160)
  3737. return chains;
  3738. mcs_160_map = le16_to_cpu(he_mcs_nss_supp->tx_mcs_160);
  3739. for (i = 7; i >= 0; i--) {
  3740. u8 mcs_160 = mcs_160_map >> (2 * i) & 3;
  3741. if (mcs_160 != IEEE80211_VHT_MCS_NOT_SUPPORTED) {
  3742. chains = max_t(u8, chains, i + 1);
  3743. break;
  3744. }
  3745. }
  3746. return chains;
  3747. }
  3748. static bool
  3749. ieee80211_verify_peer_he_mcs_support(struct ieee80211_sub_if_data *sdata,
  3750. const struct cfg80211_bss_ies *ies,
  3751. const struct ieee80211_he_operation *he_op)
  3752. {
  3753. const struct element *he_cap_elem;
  3754. const struct ieee80211_he_cap_elem *he_cap;
  3755. struct ieee80211_he_mcs_nss_supp *he_mcs_nss_supp;
  3756. u16 mcs_80_map_tx, mcs_80_map_rx;
  3757. u16 ap_min_req_set;
  3758. int mcs_nss_size;
  3759. int nss;
  3760. he_cap_elem = cfg80211_find_ext_elem(WLAN_EID_EXT_HE_CAPABILITY,
  3761. ies->data, ies->len);
  3762. if (!he_cap_elem)
  3763. return false;
  3764. /* invalid HE IE */
  3765. if (he_cap_elem->datalen < 1 + sizeof(*he_cap)) {
  3766. sdata_info(sdata,
  3767. "Invalid HE elem, Disable HE\n");
  3768. return false;
  3769. }
  3770. /* skip one byte ext_tag_id */
  3771. he_cap = (void *)(he_cap_elem->data + 1);
  3772. mcs_nss_size = ieee80211_he_mcs_nss_size(he_cap);
  3773. /* invalid HE IE */
  3774. if (he_cap_elem->datalen < 1 + sizeof(*he_cap) + mcs_nss_size) {
  3775. sdata_info(sdata,
  3776. "Invalid HE elem with nss size, Disable HE\n");
  3777. return false;
  3778. }
  3779. /* mcs_nss is right after he_cap info */
  3780. he_mcs_nss_supp = (void *)(he_cap + 1);
  3781. mcs_80_map_tx = le16_to_cpu(he_mcs_nss_supp->tx_mcs_80);
  3782. mcs_80_map_rx = le16_to_cpu(he_mcs_nss_supp->rx_mcs_80);
  3783. /* P802.11-REVme/D0.3
  3784. * 27.1.1 Introduction to the HE PHY
  3785. * ...
  3786. * An HE STA shall support the following features:
  3787. * ...
  3788. * Single spatial stream HE-MCSs 0 to 7 (transmit and receive) in all
  3789. * supported channel widths for HE SU PPDUs
  3790. */
  3791. if ((mcs_80_map_tx & 0x3) == IEEE80211_HE_MCS_NOT_SUPPORTED ||
  3792. (mcs_80_map_rx & 0x3) == IEEE80211_HE_MCS_NOT_SUPPORTED) {
  3793. sdata_info(sdata,
  3794. "Missing mandatory rates for 1 Nss, rx 0x%x, tx 0x%x, disable HE\n",
  3795. mcs_80_map_tx, mcs_80_map_rx);
  3796. return false;
  3797. }
  3798. if (!he_op)
  3799. return true;
  3800. ap_min_req_set = le16_to_cpu(he_op->he_mcs_nss_set);
  3801. /*
  3802. * Apparently iPhone 13 (at least iOS version 15.3.1) sets this to all
  3803. * zeroes, which is nonsense, and completely inconsistent with itself
  3804. * (it doesn't have 8 streams). Accept the settings in this case anyway.
  3805. */
  3806. if (!ap_min_req_set)
  3807. return true;
  3808. /* make sure the AP is consistent with itself
  3809. *
  3810. * P802.11-REVme/D0.3
  3811. * 26.17.1 Basic HE BSS operation
  3812. *
  3813. * A STA that is operating in an HE BSS shall be able to receive and
  3814. * transmit at each of the <HE-MCS, NSS> tuple values indicated by the
  3815. * Basic HE-MCS And NSS Set field of the HE Operation parameter of the
  3816. * MLME-START.request primitive and shall be able to receive at each of
  3817. * the <HE-MCS, NSS> tuple values indicated by the Supported HE-MCS and
  3818. * NSS Set field in the HE Capabilities parameter of the MLMESTART.request
  3819. * primitive
  3820. */
  3821. for (nss = 8; nss > 0; nss--) {
  3822. u8 ap_op_val = (ap_min_req_set >> (2 * (nss - 1))) & 3;
  3823. u8 ap_rx_val;
  3824. u8 ap_tx_val;
  3825. if (ap_op_val == IEEE80211_HE_MCS_NOT_SUPPORTED)
  3826. continue;
  3827. ap_rx_val = (mcs_80_map_rx >> (2 * (nss - 1))) & 3;
  3828. ap_tx_val = (mcs_80_map_tx >> (2 * (nss - 1))) & 3;
  3829. if (ap_rx_val == IEEE80211_HE_MCS_NOT_SUPPORTED ||
  3830. ap_tx_val == IEEE80211_HE_MCS_NOT_SUPPORTED ||
  3831. ap_rx_val < ap_op_val || ap_tx_val < ap_op_val) {
  3832. sdata_info(sdata,
  3833. "Invalid rates for %d Nss, rx %d, tx %d oper %d, disable HE\n",
  3834. nss, ap_rx_val, ap_rx_val, ap_op_val);
  3835. return false;
  3836. }
  3837. }
  3838. return true;
  3839. }
  3840. static bool
  3841. ieee80211_verify_sta_he_mcs_support(struct ieee80211_sub_if_data *sdata,
  3842. struct ieee80211_supported_band *sband,
  3843. const struct ieee80211_he_operation *he_op)
  3844. {
  3845. const struct ieee80211_sta_he_cap *sta_he_cap =
  3846. ieee80211_get_he_iftype_cap(sband,
  3847. ieee80211_vif_type_p2p(&sdata->vif));
  3848. u16 ap_min_req_set;
  3849. int i;
  3850. if (!sta_he_cap || !he_op)
  3851. return false;
  3852. ap_min_req_set = le16_to_cpu(he_op->he_mcs_nss_set);
  3853. /*
  3854. * Apparently iPhone 13 (at least iOS version 15.3.1) sets this to all
  3855. * zeroes, which is nonsense, and completely inconsistent with itself
  3856. * (it doesn't have 8 streams). Accept the settings in this case anyway.
  3857. */
  3858. if (!ap_min_req_set)
  3859. return true;
  3860. /* Need to go over for 80MHz, 160MHz and for 80+80 */
  3861. for (i = 0; i < 3; i++) {
  3862. const struct ieee80211_he_mcs_nss_supp *sta_mcs_nss_supp =
  3863. &sta_he_cap->he_mcs_nss_supp;
  3864. u16 sta_mcs_map_rx =
  3865. le16_to_cpu(((__le16 *)sta_mcs_nss_supp)[2 * i]);
  3866. u16 sta_mcs_map_tx =
  3867. le16_to_cpu(((__le16 *)sta_mcs_nss_supp)[2 * i + 1]);
  3868. u8 nss;
  3869. bool verified = true;
  3870. /*
  3871. * For each band there is a maximum of 8 spatial streams
  3872. * possible. Each of the sta_mcs_map_* is a 16-bit struct built
  3873. * of 2 bits per NSS (1-8), with the values defined in enum
  3874. * ieee80211_he_mcs_support. Need to make sure STA TX and RX
  3875. * capabilities aren't less than the AP's minimum requirements
  3876. * for this HE BSS per SS.
  3877. * It is enough to find one such band that meets the reqs.
  3878. */
  3879. for (nss = 8; nss > 0; nss--) {
  3880. u8 sta_rx_val = (sta_mcs_map_rx >> (2 * (nss - 1))) & 3;
  3881. u8 sta_tx_val = (sta_mcs_map_tx >> (2 * (nss - 1))) & 3;
  3882. u8 ap_val = (ap_min_req_set >> (2 * (nss - 1))) & 3;
  3883. if (ap_val == IEEE80211_HE_MCS_NOT_SUPPORTED)
  3884. continue;
  3885. /*
  3886. * Make sure the HE AP doesn't require MCSs that aren't
  3887. * supported by the client as required by spec
  3888. *
  3889. * P802.11-REVme/D0.3
  3890. * 26.17.1 Basic HE BSS operation
  3891. *
  3892. * An HE STA shall not attempt to join * (MLME-JOIN.request primitive)
  3893. * a BSS, unless it supports (i.e., is able to both transmit and
  3894. * receive using) all of the <HE-MCS, NSS> tuples in the basic
  3895. * HE-MCS and NSS set.
  3896. */
  3897. if (sta_rx_val == IEEE80211_HE_MCS_NOT_SUPPORTED ||
  3898. sta_tx_val == IEEE80211_HE_MCS_NOT_SUPPORTED ||
  3899. (ap_val > sta_rx_val) || (ap_val > sta_tx_val)) {
  3900. verified = false;
  3901. break;
  3902. }
  3903. }
  3904. if (verified)
  3905. return true;
  3906. }
  3907. /* If here, STA doesn't meet AP's HE min requirements */
  3908. return false;
  3909. }
  3910. static int ieee80211_prep_channel(struct ieee80211_sub_if_data *sdata,
  3911. struct ieee80211_link_data *link,
  3912. struct cfg80211_bss *cbss,
  3913. ieee80211_conn_flags_t *conn_flags)
  3914. {
  3915. struct ieee80211_local *local = sdata->local;
  3916. const struct ieee80211_ht_cap *ht_cap = NULL;
  3917. const struct ieee80211_ht_operation *ht_oper = NULL;
  3918. const struct ieee80211_vht_operation *vht_oper = NULL;
  3919. const struct ieee80211_he_operation *he_oper = NULL;
  3920. const struct ieee80211_eht_operation *eht_oper = NULL;
  3921. const struct ieee80211_s1g_oper_ie *s1g_oper = NULL;
  3922. struct ieee80211_supported_band *sband;
  3923. struct cfg80211_chan_def chandef;
  3924. bool is_6ghz = cbss->channel->band == NL80211_BAND_6GHZ;
  3925. bool is_5ghz = cbss->channel->band == NL80211_BAND_5GHZ;
  3926. struct ieee80211_bss *bss = (void *)cbss->priv;
  3927. struct ieee80211_elems_parse_params parse_params = {
  3928. .bss = cbss,
  3929. .link_id = -1,
  3930. .from_ap = true,
  3931. };
  3932. struct ieee802_11_elems *elems;
  3933. const struct cfg80211_bss_ies *ies;
  3934. int ret;
  3935. u32 i;
  3936. bool have_80mhz;
  3937. rcu_read_lock();
  3938. ies = rcu_dereference(cbss->ies);
  3939. parse_params.start = ies->data;
  3940. parse_params.len = ies->len;
  3941. elems = ieee802_11_parse_elems_full(&parse_params);
  3942. if (!elems) {
  3943. rcu_read_unlock();
  3944. return -ENOMEM;
  3945. }
  3946. sband = local->hw.wiphy->bands[cbss->channel->band];
  3947. *conn_flags &= ~(IEEE80211_CONN_DISABLE_40MHZ |
  3948. IEEE80211_CONN_DISABLE_80P80MHZ |
  3949. IEEE80211_CONN_DISABLE_160MHZ);
  3950. /* disable HT/VHT/HE if we don't support them */
  3951. if (!sband->ht_cap.ht_supported && !is_6ghz) {
  3952. mlme_dbg(sdata, "HT not supported, disabling HT/VHT/HE/EHT\n");
  3953. *conn_flags |= IEEE80211_CONN_DISABLE_HT;
  3954. *conn_flags |= IEEE80211_CONN_DISABLE_VHT;
  3955. *conn_flags |= IEEE80211_CONN_DISABLE_HE;
  3956. *conn_flags |= IEEE80211_CONN_DISABLE_EHT;
  3957. }
  3958. if (!sband->vht_cap.vht_supported && is_5ghz) {
  3959. mlme_dbg(sdata, "VHT not supported, disabling VHT/HE/EHT\n");
  3960. *conn_flags |= IEEE80211_CONN_DISABLE_VHT;
  3961. *conn_flags |= IEEE80211_CONN_DISABLE_HE;
  3962. *conn_flags |= IEEE80211_CONN_DISABLE_EHT;
  3963. }
  3964. if (!ieee80211_get_he_iftype_cap(sband,
  3965. ieee80211_vif_type_p2p(&sdata->vif))) {
  3966. mlme_dbg(sdata, "HE not supported, disabling HE and EHT\n");
  3967. *conn_flags |= IEEE80211_CONN_DISABLE_HE;
  3968. *conn_flags |= IEEE80211_CONN_DISABLE_EHT;
  3969. }
  3970. if (!ieee80211_get_eht_iftype_cap(sband,
  3971. ieee80211_vif_type_p2p(&sdata->vif))) {
  3972. mlme_dbg(sdata, "EHT not supported, disabling EHT\n");
  3973. *conn_flags |= IEEE80211_CONN_DISABLE_EHT;
  3974. }
  3975. if (!(*conn_flags & IEEE80211_CONN_DISABLE_HT) && !is_6ghz) {
  3976. ht_oper = elems->ht_operation;
  3977. ht_cap = elems->ht_cap_elem;
  3978. if (!ht_cap) {
  3979. *conn_flags |= IEEE80211_CONN_DISABLE_HT;
  3980. ht_oper = NULL;
  3981. }
  3982. }
  3983. if (!(*conn_flags & IEEE80211_CONN_DISABLE_VHT) && !is_6ghz) {
  3984. vht_oper = elems->vht_operation;
  3985. if (vht_oper && !ht_oper) {
  3986. vht_oper = NULL;
  3987. sdata_info(sdata,
  3988. "AP advertised VHT without HT, disabling HT/VHT/HE\n");
  3989. *conn_flags |= IEEE80211_CONN_DISABLE_HT;
  3990. *conn_flags |= IEEE80211_CONN_DISABLE_VHT;
  3991. *conn_flags |= IEEE80211_CONN_DISABLE_HE;
  3992. *conn_flags |= IEEE80211_CONN_DISABLE_EHT;
  3993. }
  3994. if (!elems->vht_cap_elem) {
  3995. *conn_flags |= IEEE80211_CONN_DISABLE_VHT;
  3996. vht_oper = NULL;
  3997. }
  3998. }
  3999. if (!(*conn_flags & IEEE80211_CONN_DISABLE_HE)) {
  4000. he_oper = elems->he_operation;
  4001. if (link && is_6ghz) {
  4002. struct ieee80211_bss_conf *bss_conf;
  4003. u8 j = 0;
  4004. bss_conf = link->conf;
  4005. if (elems->pwr_constr_elem)
  4006. bss_conf->pwr_reduction = *elems->pwr_constr_elem;
  4007. BUILD_BUG_ON(ARRAY_SIZE(bss_conf->tx_pwr_env) !=
  4008. ARRAY_SIZE(elems->tx_pwr_env));
  4009. for (i = 0; i < elems->tx_pwr_env_num; i++) {
  4010. if (elems->tx_pwr_env_len[i] >
  4011. sizeof(bss_conf->tx_pwr_env[j]))
  4012. continue;
  4013. bss_conf->tx_pwr_env_num++;
  4014. memcpy(&bss_conf->tx_pwr_env[j], elems->tx_pwr_env[i],
  4015. elems->tx_pwr_env_len[i]);
  4016. j++;
  4017. }
  4018. }
  4019. if (!ieee80211_verify_peer_he_mcs_support(sdata, ies, he_oper) ||
  4020. !ieee80211_verify_sta_he_mcs_support(sdata, sband, he_oper))
  4021. *conn_flags |= IEEE80211_CONN_DISABLE_HE |
  4022. IEEE80211_CONN_DISABLE_EHT;
  4023. }
  4024. /*
  4025. * EHT requires HE to be supported as well. Specifically for 6 GHz
  4026. * channels, the operation channel information can only be deduced from
  4027. * both the 6 GHz operation information (from the HE operation IE) and
  4028. * EHT operation.
  4029. */
  4030. if (!(*conn_flags &
  4031. (IEEE80211_CONN_DISABLE_HE |
  4032. IEEE80211_CONN_DISABLE_EHT)) &&
  4033. he_oper) {
  4034. const struct cfg80211_bss_ies *cbss_ies;
  4035. const u8 *eht_oper_ie;
  4036. cbss_ies = rcu_dereference(cbss->ies);
  4037. eht_oper_ie = cfg80211_find_ext_ie(WLAN_EID_EXT_EHT_OPERATION,
  4038. cbss_ies->data, cbss_ies->len);
  4039. if (eht_oper_ie && eht_oper_ie[1] >=
  4040. 1 + sizeof(struct ieee80211_eht_operation))
  4041. eht_oper = (void *)(eht_oper_ie + 3);
  4042. else
  4043. eht_oper = NULL;
  4044. }
  4045. /* Allow VHT if at least one channel on the sband supports 80 MHz */
  4046. have_80mhz = false;
  4047. for (i = 0; i < sband->n_channels; i++) {
  4048. if (sband->channels[i].flags & (IEEE80211_CHAN_DISABLED |
  4049. IEEE80211_CHAN_NO_80MHZ))
  4050. continue;
  4051. have_80mhz = true;
  4052. break;
  4053. }
  4054. if (!have_80mhz) {
  4055. sdata_info(sdata, "80 MHz not supported, disabling VHT\n");
  4056. *conn_flags |= IEEE80211_CONN_DISABLE_VHT;
  4057. }
  4058. if (sband->band == NL80211_BAND_S1GHZ) {
  4059. s1g_oper = elems->s1g_oper;
  4060. if (!s1g_oper)
  4061. sdata_info(sdata,
  4062. "AP missing S1G operation element?\n");
  4063. }
  4064. *conn_flags |=
  4065. ieee80211_determine_chantype(sdata, link, *conn_flags,
  4066. sband,
  4067. cbss->channel,
  4068. bss->vht_cap_info,
  4069. ht_oper, vht_oper,
  4070. he_oper, eht_oper,
  4071. s1g_oper,
  4072. &chandef, false);
  4073. if (link)
  4074. link->needed_rx_chains =
  4075. min(ieee80211_max_rx_chains(link, cbss),
  4076. local->rx_chains);
  4077. rcu_read_unlock();
  4078. /* the element data was RCU protected so no longer valid anyway */
  4079. kfree(elems);
  4080. elems = NULL;
  4081. if (*conn_flags & IEEE80211_CONN_DISABLE_HE && is_6ghz) {
  4082. sdata_info(sdata, "Rejecting non-HE 6/7 GHz connection");
  4083. return -EINVAL;
  4084. }
  4085. if (!link)
  4086. return 0;
  4087. /* will change later if needed */
  4088. link->smps_mode = IEEE80211_SMPS_OFF;
  4089. mutex_lock(&local->mtx);
  4090. /*
  4091. * If this fails (possibly due to channel context sharing
  4092. * on incompatible channels, e.g. 80+80 and 160 sharing the
  4093. * same control channel) try to use a smaller bandwidth.
  4094. */
  4095. ret = ieee80211_link_use_channel(link, &chandef,
  4096. IEEE80211_CHANCTX_SHARED);
  4097. /* don't downgrade for 5 and 10 MHz channels, though. */
  4098. if (chandef.width == NL80211_CHAN_WIDTH_5 ||
  4099. chandef.width == NL80211_CHAN_WIDTH_10)
  4100. goto out;
  4101. while (ret && chandef.width != NL80211_CHAN_WIDTH_20_NOHT) {
  4102. *conn_flags |=
  4103. ieee80211_chandef_downgrade(&chandef);
  4104. ret = ieee80211_link_use_channel(link, &chandef,
  4105. IEEE80211_CHANCTX_SHARED);
  4106. }
  4107. out:
  4108. mutex_unlock(&local->mtx);
  4109. return ret;
  4110. }
  4111. static bool ieee80211_get_dtim(const struct cfg80211_bss_ies *ies,
  4112. u8 *dtim_count, u8 *dtim_period)
  4113. {
  4114. const u8 *tim_ie = cfg80211_find_ie(WLAN_EID_TIM, ies->data, ies->len);
  4115. const u8 *idx_ie = cfg80211_find_ie(WLAN_EID_MULTI_BSSID_IDX, ies->data,
  4116. ies->len);
  4117. const struct ieee80211_tim_ie *tim = NULL;
  4118. const struct ieee80211_bssid_index *idx;
  4119. bool valid = tim_ie && tim_ie[1] >= 2;
  4120. if (valid)
  4121. tim = (void *)(tim_ie + 2);
  4122. if (dtim_count)
  4123. *dtim_count = valid ? tim->dtim_count : 0;
  4124. if (dtim_period)
  4125. *dtim_period = valid ? tim->dtim_period : 0;
  4126. /* Check if value is overridden by non-transmitted profile */
  4127. if (!idx_ie || idx_ie[1] < 3)
  4128. return valid;
  4129. idx = (void *)(idx_ie + 2);
  4130. if (dtim_count)
  4131. *dtim_count = idx->dtim_count;
  4132. if (dtim_period)
  4133. *dtim_period = idx->dtim_period;
  4134. return true;
  4135. }
  4136. static bool ieee80211_assoc_success(struct ieee80211_sub_if_data *sdata,
  4137. struct ieee80211_mgmt *mgmt,
  4138. struct ieee802_11_elems *elems,
  4139. const u8 *elem_start, unsigned int elem_len)
  4140. {
  4141. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  4142. struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;
  4143. struct ieee80211_local *local = sdata->local;
  4144. unsigned int link_id;
  4145. struct sta_info *sta;
  4146. u64 changed[IEEE80211_MLD_MAX_NUM_LINKS] = {};
  4147. int err;
  4148. mutex_lock(&sdata->local->sta_mtx);
  4149. /*
  4150. * station info was already allocated and inserted before
  4151. * the association and should be available to us
  4152. */
  4153. sta = sta_info_get(sdata, assoc_data->ap_addr);
  4154. if (WARN_ON(!sta))
  4155. goto out_err;
  4156. if (sdata->vif.valid_links) {
  4157. u16 valid_links = 0;
  4158. for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS; link_id++) {
  4159. if (!assoc_data->link[link_id].bss)
  4160. continue;
  4161. valid_links |= BIT(link_id);
  4162. if (link_id != assoc_data->assoc_link_id) {
  4163. err = ieee80211_sta_allocate_link(sta, link_id);
  4164. if (err)
  4165. goto out_err;
  4166. }
  4167. }
  4168. ieee80211_vif_set_links(sdata, valid_links);
  4169. }
  4170. for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS; link_id++) {
  4171. struct ieee80211_link_data *link;
  4172. struct link_sta_info *link_sta;
  4173. if (!assoc_data->link[link_id].bss)
  4174. continue;
  4175. link = sdata_dereference(sdata->link[link_id], sdata);
  4176. if (WARN_ON(!link))
  4177. goto out_err;
  4178. if (sdata->vif.valid_links)
  4179. link_info(link,
  4180. "local address %pM, AP link address %pM\n",
  4181. link->conf->addr,
  4182. assoc_data->link[link_id].bss->bssid);
  4183. link_sta = rcu_dereference_protected(sta->link[link_id],
  4184. lockdep_is_held(&local->sta_mtx));
  4185. if (WARN_ON(!link_sta))
  4186. goto out_err;
  4187. if (link_id != assoc_data->assoc_link_id) {
  4188. struct cfg80211_bss *cbss = assoc_data->link[link_id].bss;
  4189. const struct cfg80211_bss_ies *ies;
  4190. rcu_read_lock();
  4191. ies = rcu_dereference(cbss->ies);
  4192. ieee80211_get_dtim(ies,
  4193. &link->conf->sync_dtim_count,
  4194. &link->u.mgd.dtim_period);
  4195. link->conf->dtim_period = link->u.mgd.dtim_period ?: 1;
  4196. link->conf->beacon_int = cbss->beacon_interval;
  4197. rcu_read_unlock();
  4198. err = ieee80211_prep_channel(sdata, link, cbss,
  4199. &link->u.mgd.conn_flags);
  4200. if (err) {
  4201. link_info(link, "prep_channel failed\n");
  4202. goto out_err;
  4203. }
  4204. }
  4205. err = ieee80211_mgd_setup_link_sta(link, sta, link_sta,
  4206. assoc_data->link[link_id].bss);
  4207. if (err)
  4208. goto out_err;
  4209. if (!ieee80211_assoc_config_link(link, link_sta,
  4210. assoc_data->link[link_id].bss,
  4211. mgmt, elem_start, elem_len,
  4212. &changed[link_id]))
  4213. goto out_err;
  4214. if (link_id != assoc_data->assoc_link_id) {
  4215. err = ieee80211_sta_activate_link(sta, link_id);
  4216. if (err)
  4217. goto out_err;
  4218. }
  4219. }
  4220. rate_control_rate_init(sta);
  4221. if (ifmgd->flags & IEEE80211_STA_MFP_ENABLED) {
  4222. set_sta_flag(sta, WLAN_STA_MFP);
  4223. sta->sta.mfp = true;
  4224. } else {
  4225. sta->sta.mfp = false;
  4226. }
  4227. ieee80211_sta_set_max_amsdu_subframes(sta, elems->ext_capab,
  4228. elems->ext_capab_len);
  4229. sta->sta.wme = (elems->wmm_param || elems->s1g_capab) &&
  4230. local->hw.queues >= IEEE80211_NUM_ACS;
  4231. err = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
  4232. if (!err && !(ifmgd->flags & IEEE80211_STA_CONTROL_PORT))
  4233. err = sta_info_move_state(sta, IEEE80211_STA_AUTHORIZED);
  4234. if (err) {
  4235. sdata_info(sdata,
  4236. "failed to move station %pM to desired state\n",
  4237. sta->sta.addr);
  4238. WARN_ON(__sta_info_destroy(sta));
  4239. goto out_err;
  4240. }
  4241. if (sdata->wdev.use_4addr)
  4242. drv_sta_set_4addr(local, sdata, &sta->sta, true);
  4243. mutex_unlock(&sdata->local->sta_mtx);
  4244. ieee80211_set_associated(sdata, assoc_data, changed);
  4245. /*
  4246. * If we're using 4-addr mode, let the AP know that we're
  4247. * doing so, so that it can create the STA VLAN on its side
  4248. */
  4249. if (ifmgd->use_4addr)
  4250. ieee80211_send_4addr_nullfunc(local, sdata);
  4251. /*
  4252. * Start timer to probe the connection to the AP now.
  4253. * Also start the timer that will detect beacon loss.
  4254. */
  4255. ieee80211_sta_reset_beacon_monitor(sdata);
  4256. ieee80211_sta_reset_conn_monitor(sdata);
  4257. return true;
  4258. out_err:
  4259. eth_zero_addr(sdata->vif.cfg.ap_addr);
  4260. mutex_unlock(&sdata->local->sta_mtx);
  4261. return false;
  4262. }
  4263. static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
  4264. struct ieee80211_mgmt *mgmt,
  4265. size_t len)
  4266. {
  4267. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  4268. struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;
  4269. u16 capab_info, status_code, aid;
  4270. struct ieee80211_elems_parse_params parse_params = {
  4271. .bss = NULL,
  4272. .link_id = -1,
  4273. .from_ap = true,
  4274. };
  4275. struct ieee802_11_elems *elems;
  4276. int ac;
  4277. const u8 *elem_start;
  4278. unsigned int elem_len;
  4279. bool reassoc;
  4280. struct ieee80211_event event = {
  4281. .type = MLME_EVENT,
  4282. .u.mlme.data = ASSOC_EVENT,
  4283. };
  4284. struct ieee80211_prep_tx_info info = {};
  4285. struct cfg80211_rx_assoc_resp resp = {
  4286. .uapsd_queues = -1,
  4287. };
  4288. u8 ap_mld_addr[ETH_ALEN] __aligned(2);
  4289. unsigned int link_id;
  4290. sdata_assert_lock(sdata);
  4291. if (!assoc_data)
  4292. return;
  4293. if (!ether_addr_equal(assoc_data->ap_addr, mgmt->bssid) ||
  4294. !ether_addr_equal(assoc_data->ap_addr, mgmt->sa))
  4295. return;
  4296. /*
  4297. * AssocResp and ReassocResp have identical structure, so process both
  4298. * of them in this function.
  4299. */
  4300. if (len < 24 + 6)
  4301. return;
  4302. reassoc = ieee80211_is_reassoc_resp(mgmt->frame_control);
  4303. capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
  4304. status_code = le16_to_cpu(mgmt->u.assoc_resp.status_code);
  4305. if (assoc_data->s1g)
  4306. elem_start = mgmt->u.s1g_assoc_resp.variable;
  4307. else
  4308. elem_start = mgmt->u.assoc_resp.variable;
  4309. /*
  4310. * Note: this may not be perfect, AP might misbehave - if
  4311. * anyone needs to rely on perfect complete notification
  4312. * with the exact right subtype, then we need to track what
  4313. * we actually transmitted.
  4314. */
  4315. info.subtype = reassoc ? IEEE80211_STYPE_REASSOC_REQ :
  4316. IEEE80211_STYPE_ASSOC_REQ;
  4317. if (assoc_data->fils_kek_len &&
  4318. fils_decrypt_assoc_resp(sdata, (u8 *)mgmt, &len, assoc_data) < 0)
  4319. return;
  4320. elem_len = len - (elem_start - (u8 *)mgmt);
  4321. parse_params.start = elem_start;
  4322. parse_params.len = elem_len;
  4323. elems = ieee802_11_parse_elems_full(&parse_params);
  4324. if (!elems)
  4325. goto notify_driver;
  4326. if (elems->aid_resp)
  4327. aid = le16_to_cpu(elems->aid_resp->aid);
  4328. else if (assoc_data->s1g)
  4329. aid = 0; /* TODO */
  4330. else
  4331. aid = le16_to_cpu(mgmt->u.assoc_resp.aid);
  4332. /*
  4333. * The 5 MSB of the AID field are reserved
  4334. * (802.11-2016 9.4.1.8 AID field)
  4335. */
  4336. aid &= 0x7ff;
  4337. sdata_info(sdata,
  4338. "RX %sssocResp from %pM (capab=0x%x status=%d aid=%d)\n",
  4339. reassoc ? "Rea" : "A", assoc_data->ap_addr,
  4340. capab_info, status_code, (u16)(aid & ~(BIT(15) | BIT(14))));
  4341. ifmgd->broken_ap = false;
  4342. if (status_code == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY &&
  4343. elems->timeout_int &&
  4344. elems->timeout_int->type == WLAN_TIMEOUT_ASSOC_COMEBACK) {
  4345. u32 tu, ms;
  4346. cfg80211_assoc_comeback(sdata->dev, assoc_data->ap_addr,
  4347. le32_to_cpu(elems->timeout_int->value));
  4348. tu = le32_to_cpu(elems->timeout_int->value);
  4349. ms = tu * 1024 / 1000;
  4350. sdata_info(sdata,
  4351. "%pM rejected association temporarily; comeback duration %u TU (%u ms)\n",
  4352. assoc_data->ap_addr, tu, ms);
  4353. assoc_data->timeout = jiffies + msecs_to_jiffies(ms);
  4354. assoc_data->timeout_started = true;
  4355. if (ms > IEEE80211_ASSOC_TIMEOUT)
  4356. run_again(sdata, assoc_data->timeout);
  4357. goto notify_driver;
  4358. }
  4359. if (status_code != WLAN_STATUS_SUCCESS) {
  4360. sdata_info(sdata, "%pM denied association (code=%d)\n",
  4361. assoc_data->ap_addr, status_code);
  4362. event.u.mlme.status = MLME_DENIED;
  4363. event.u.mlme.reason = status_code;
  4364. drv_event_callback(sdata->local, sdata, &event);
  4365. } else {
  4366. if (aid == 0 || aid > IEEE80211_MAX_AID) {
  4367. sdata_info(sdata,
  4368. "invalid AID value %d (out of range), turn off PS\n",
  4369. aid);
  4370. aid = 0;
  4371. ifmgd->broken_ap = true;
  4372. }
  4373. if (sdata->vif.valid_links) {
  4374. if (!elems->multi_link) {
  4375. sdata_info(sdata,
  4376. "MLO association with %pM but no multi-link element in response!\n",
  4377. assoc_data->ap_addr);
  4378. goto abandon_assoc;
  4379. }
  4380. if (le16_get_bits(elems->multi_link->control,
  4381. IEEE80211_ML_CONTROL_TYPE) !=
  4382. IEEE80211_ML_CONTROL_TYPE_BASIC) {
  4383. sdata_info(sdata,
  4384. "bad multi-link element (control=0x%x)\n",
  4385. le16_to_cpu(elems->multi_link->control));
  4386. goto abandon_assoc;
  4387. } else {
  4388. struct ieee80211_mle_basic_common_info *common;
  4389. common = (void *)elems->multi_link->variable;
  4390. if (memcmp(assoc_data->ap_addr,
  4391. common->mld_mac_addr, ETH_ALEN)) {
  4392. sdata_info(sdata,
  4393. "AP MLD MAC address mismatch: got %pM expected %pM\n",
  4394. common->mld_mac_addr,
  4395. assoc_data->ap_addr);
  4396. goto abandon_assoc;
  4397. }
  4398. }
  4399. }
  4400. sdata->vif.cfg.aid = aid;
  4401. if (!ieee80211_assoc_success(sdata, mgmt, elems,
  4402. elem_start, elem_len)) {
  4403. /* oops -- internal error -- send timeout for now */
  4404. ieee80211_destroy_assoc_data(sdata, ASSOC_TIMEOUT);
  4405. goto notify_driver;
  4406. }
  4407. event.u.mlme.status = MLME_SUCCESS;
  4408. drv_event_callback(sdata->local, sdata, &event);
  4409. sdata_info(sdata, "associated\n");
  4410. info.success = 1;
  4411. }
  4412. for (link_id = 0; link_id < IEEE80211_MLD_MAX_NUM_LINKS; link_id++) {
  4413. struct ieee80211_link_data *link;
  4414. link = sdata_dereference(sdata->link[link_id], sdata);
  4415. if (!link)
  4416. continue;
  4417. if (!assoc_data->link[link_id].bss)
  4418. continue;
  4419. resp.links[link_id].bss = assoc_data->link[link_id].bss;
  4420. resp.links[link_id].addr = link->conf->addr;
  4421. /* get uapsd queues configuration - same for all links */
  4422. resp.uapsd_queues = 0;
  4423. for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
  4424. if (link->tx_conf[ac].uapsd)
  4425. resp.uapsd_queues |= ieee80211_ac_to_qos_mask[ac];
  4426. }
  4427. if (sdata->vif.valid_links) {
  4428. ether_addr_copy(ap_mld_addr, sdata->vif.cfg.ap_addr);
  4429. resp.ap_mld_addr = ap_mld_addr;
  4430. }
  4431. ieee80211_destroy_assoc_data(sdata,
  4432. status_code == WLAN_STATUS_SUCCESS ?
  4433. ASSOC_SUCCESS :
  4434. ASSOC_REJECTED);
  4435. resp.buf = (u8 *)mgmt;
  4436. resp.len = len;
  4437. resp.req_ies = ifmgd->assoc_req_ies;
  4438. resp.req_ies_len = ifmgd->assoc_req_ies_len;
  4439. cfg80211_rx_assoc_resp(sdata->dev, &resp);
  4440. notify_driver:
  4441. drv_mgd_complete_tx(sdata->local, sdata, &info);
  4442. kfree(elems);
  4443. return;
  4444. abandon_assoc:
  4445. ieee80211_destroy_assoc_data(sdata, ASSOC_ABANDON);
  4446. goto notify_driver;
  4447. }
  4448. static void ieee80211_rx_bss_info(struct ieee80211_link_data *link,
  4449. struct ieee80211_mgmt *mgmt, size_t len,
  4450. struct ieee80211_rx_status *rx_status)
  4451. {
  4452. struct ieee80211_sub_if_data *sdata = link->sdata;
  4453. struct ieee80211_local *local = sdata->local;
  4454. struct ieee80211_bss *bss;
  4455. struct ieee80211_channel *channel;
  4456. sdata_assert_lock(sdata);
  4457. channel = ieee80211_get_channel_khz(local->hw.wiphy,
  4458. ieee80211_rx_status_to_khz(rx_status));
  4459. if (!channel)
  4460. return;
  4461. bss = ieee80211_bss_info_update(local, rx_status, mgmt, len, channel);
  4462. if (bss) {
  4463. link->conf->beacon_rate = bss->beacon_rate;
  4464. ieee80211_rx_bss_put(local, bss);
  4465. }
  4466. }
  4467. static void ieee80211_rx_mgmt_probe_resp(struct ieee80211_link_data *link,
  4468. struct sk_buff *skb)
  4469. {
  4470. struct ieee80211_sub_if_data *sdata = link->sdata;
  4471. struct ieee80211_mgmt *mgmt = (void *)skb->data;
  4472. struct ieee80211_if_managed *ifmgd;
  4473. struct ieee80211_rx_status *rx_status = (void *) skb->cb;
  4474. struct ieee80211_channel *channel;
  4475. size_t baselen, len = skb->len;
  4476. ifmgd = &sdata->u.mgd;
  4477. sdata_assert_lock(sdata);
  4478. /*
  4479. * According to Draft P802.11ax D6.0 clause 26.17.2.3.2:
  4480. * "If a 6 GHz AP receives a Probe Request frame and responds with
  4481. * a Probe Response frame [..], the Address 1 field of the Probe
  4482. * Response frame shall be set to the broadcast address [..]"
  4483. * So, on 6GHz band we should also accept broadcast responses.
  4484. */
  4485. channel = ieee80211_get_channel(sdata->local->hw.wiphy,
  4486. rx_status->freq);
  4487. if (!channel)
  4488. return;
  4489. if (!ether_addr_equal(mgmt->da, sdata->vif.addr) &&
  4490. (channel->band != NL80211_BAND_6GHZ ||
  4491. !is_broadcast_ether_addr(mgmt->da)))
  4492. return; /* ignore ProbeResp to foreign address */
  4493. baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt;
  4494. if (baselen > len)
  4495. return;
  4496. ieee80211_rx_bss_info(link, mgmt, len, rx_status);
  4497. if (ifmgd->associated &&
  4498. ether_addr_equal(mgmt->bssid, link->u.mgd.bssid))
  4499. ieee80211_reset_ap_probe(sdata);
  4500. }
  4501. /*
  4502. * This is the canonical list of information elements we care about,
  4503. * the filter code also gives us all changes to the Microsoft OUI
  4504. * (00:50:F2) vendor IE which is used for WMM which we need to track,
  4505. * as well as the DTPC IE (part of the Cisco OUI) used for signaling
  4506. * changes to requested client power.
  4507. *
  4508. * We implement beacon filtering in software since that means we can
  4509. * avoid processing the frame here and in cfg80211, and userspace
  4510. * will not be able to tell whether the hardware supports it or not.
  4511. *
  4512. * XXX: This list needs to be dynamic -- userspace needs to be able to
  4513. * add items it requires. It also needs to be able to tell us to
  4514. * look out for other vendor IEs.
  4515. */
  4516. static const u64 care_about_ies =
  4517. (1ULL << WLAN_EID_COUNTRY) |
  4518. (1ULL << WLAN_EID_ERP_INFO) |
  4519. (1ULL << WLAN_EID_CHANNEL_SWITCH) |
  4520. (1ULL << WLAN_EID_PWR_CONSTRAINT) |
  4521. (1ULL << WLAN_EID_HT_CAPABILITY) |
  4522. (1ULL << WLAN_EID_HT_OPERATION) |
  4523. (1ULL << WLAN_EID_EXT_CHANSWITCH_ANN);
  4524. static void ieee80211_handle_beacon_sig(struct ieee80211_link_data *link,
  4525. struct ieee80211_if_managed *ifmgd,
  4526. struct ieee80211_bss_conf *bss_conf,
  4527. struct ieee80211_local *local,
  4528. struct ieee80211_rx_status *rx_status)
  4529. {
  4530. struct ieee80211_sub_if_data *sdata = link->sdata;
  4531. /* Track average RSSI from the Beacon frames of the current AP */
  4532. if (!link->u.mgd.tracking_signal_avg) {
  4533. link->u.mgd.tracking_signal_avg = true;
  4534. ewma_beacon_signal_init(&link->u.mgd.ave_beacon_signal);
  4535. link->u.mgd.last_cqm_event_signal = 0;
  4536. link->u.mgd.count_beacon_signal = 1;
  4537. link->u.mgd.last_ave_beacon_signal = 0;
  4538. } else {
  4539. link->u.mgd.count_beacon_signal++;
  4540. }
  4541. ewma_beacon_signal_add(&link->u.mgd.ave_beacon_signal,
  4542. -rx_status->signal);
  4543. if (ifmgd->rssi_min_thold != ifmgd->rssi_max_thold &&
  4544. link->u.mgd.count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT) {
  4545. int sig = -ewma_beacon_signal_read(&link->u.mgd.ave_beacon_signal);
  4546. int last_sig = link->u.mgd.last_ave_beacon_signal;
  4547. struct ieee80211_event event = {
  4548. .type = RSSI_EVENT,
  4549. };
  4550. /*
  4551. * if signal crosses either of the boundaries, invoke callback
  4552. * with appropriate parameters
  4553. */
  4554. if (sig > ifmgd->rssi_max_thold &&
  4555. (last_sig <= ifmgd->rssi_min_thold || last_sig == 0)) {
  4556. link->u.mgd.last_ave_beacon_signal = sig;
  4557. event.u.rssi.data = RSSI_EVENT_HIGH;
  4558. drv_event_callback(local, sdata, &event);
  4559. } else if (sig < ifmgd->rssi_min_thold &&
  4560. (last_sig >= ifmgd->rssi_max_thold ||
  4561. last_sig == 0)) {
  4562. link->u.mgd.last_ave_beacon_signal = sig;
  4563. event.u.rssi.data = RSSI_EVENT_LOW;
  4564. drv_event_callback(local, sdata, &event);
  4565. }
  4566. }
  4567. if (bss_conf->cqm_rssi_thold &&
  4568. link->u.mgd.count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT &&
  4569. !(sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)) {
  4570. int sig = -ewma_beacon_signal_read(&link->u.mgd.ave_beacon_signal);
  4571. int last_event = link->u.mgd.last_cqm_event_signal;
  4572. int thold = bss_conf->cqm_rssi_thold;
  4573. int hyst = bss_conf->cqm_rssi_hyst;
  4574. if (sig < thold &&
  4575. (last_event == 0 || sig < last_event - hyst)) {
  4576. link->u.mgd.last_cqm_event_signal = sig;
  4577. ieee80211_cqm_rssi_notify(
  4578. &sdata->vif,
  4579. NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW,
  4580. sig, GFP_KERNEL);
  4581. } else if (sig > thold &&
  4582. (last_event == 0 || sig > last_event + hyst)) {
  4583. link->u.mgd.last_cqm_event_signal = sig;
  4584. ieee80211_cqm_rssi_notify(
  4585. &sdata->vif,
  4586. NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH,
  4587. sig, GFP_KERNEL);
  4588. }
  4589. }
  4590. if (bss_conf->cqm_rssi_low &&
  4591. link->u.mgd.count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT) {
  4592. int sig = -ewma_beacon_signal_read(&link->u.mgd.ave_beacon_signal);
  4593. int last_event = link->u.mgd.last_cqm_event_signal;
  4594. int low = bss_conf->cqm_rssi_low;
  4595. int high = bss_conf->cqm_rssi_high;
  4596. if (sig < low &&
  4597. (last_event == 0 || last_event >= low)) {
  4598. link->u.mgd.last_cqm_event_signal = sig;
  4599. ieee80211_cqm_rssi_notify(
  4600. &sdata->vif,
  4601. NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW,
  4602. sig, GFP_KERNEL);
  4603. } else if (sig > high &&
  4604. (last_event == 0 || last_event <= high)) {
  4605. link->u.mgd.last_cqm_event_signal = sig;
  4606. ieee80211_cqm_rssi_notify(
  4607. &sdata->vif,
  4608. NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH,
  4609. sig, GFP_KERNEL);
  4610. }
  4611. }
  4612. }
  4613. static bool ieee80211_rx_our_beacon(const u8 *tx_bssid,
  4614. struct cfg80211_bss *bss)
  4615. {
  4616. if (ether_addr_equal(tx_bssid, bss->bssid))
  4617. return true;
  4618. if (!bss->transmitted_bss)
  4619. return false;
  4620. return ether_addr_equal(tx_bssid, bss->transmitted_bss->bssid);
  4621. }
  4622. static void ieee80211_rx_mgmt_beacon(struct ieee80211_link_data *link,
  4623. struct ieee80211_hdr *hdr, size_t len,
  4624. struct ieee80211_rx_status *rx_status)
  4625. {
  4626. struct ieee80211_sub_if_data *sdata = link->sdata;
  4627. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  4628. struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
  4629. struct ieee80211_vif_cfg *vif_cfg = &sdata->vif.cfg;
  4630. struct ieee80211_mgmt *mgmt = (void *) hdr;
  4631. size_t baselen;
  4632. struct ieee802_11_elems *elems;
  4633. struct ieee80211_local *local = sdata->local;
  4634. struct ieee80211_chanctx_conf *chanctx_conf;
  4635. struct ieee80211_channel *chan;
  4636. struct link_sta_info *link_sta;
  4637. struct sta_info *sta;
  4638. u32 changed = 0;
  4639. bool erp_valid;
  4640. u8 erp_value = 0;
  4641. u32 ncrc = 0;
  4642. u8 *bssid, *variable = mgmt->u.beacon.variable;
  4643. u8 deauth_buf[IEEE80211_DEAUTH_FRAME_LEN];
  4644. struct ieee80211_elems_parse_params parse_params = {
  4645. .link_id = -1,
  4646. .from_ap = true,
  4647. };
  4648. sdata_assert_lock(sdata);
  4649. /* Process beacon from the current BSS */
  4650. bssid = ieee80211_get_bssid(hdr, len, sdata->vif.type);
  4651. if (ieee80211_is_s1g_beacon(mgmt->frame_control)) {
  4652. struct ieee80211_ext *ext = (void *) mgmt;
  4653. if (ieee80211_is_s1g_short_beacon(ext->frame_control))
  4654. variable = ext->u.s1g_short_beacon.variable;
  4655. else
  4656. variable = ext->u.s1g_beacon.variable;
  4657. }
  4658. baselen = (u8 *) variable - (u8 *) mgmt;
  4659. if (baselen > len)
  4660. return;
  4661. parse_params.start = variable;
  4662. parse_params.len = len - baselen;
  4663. rcu_read_lock();
  4664. chanctx_conf = rcu_dereference(link->conf->chanctx_conf);
  4665. if (!chanctx_conf) {
  4666. rcu_read_unlock();
  4667. return;
  4668. }
  4669. if (ieee80211_rx_status_to_khz(rx_status) !=
  4670. ieee80211_channel_to_khz(chanctx_conf->def.chan)) {
  4671. rcu_read_unlock();
  4672. return;
  4673. }
  4674. chan = chanctx_conf->def.chan;
  4675. rcu_read_unlock();
  4676. if (ifmgd->assoc_data && ifmgd->assoc_data->need_beacon &&
  4677. !WARN_ON(sdata->vif.valid_links) &&
  4678. ieee80211_rx_our_beacon(bssid, ifmgd->assoc_data->link[0].bss)) {
  4679. parse_params.bss = ifmgd->assoc_data->link[0].bss;
  4680. elems = ieee802_11_parse_elems_full(&parse_params);
  4681. if (!elems)
  4682. return;
  4683. ieee80211_rx_bss_info(link, mgmt, len, rx_status);
  4684. if (elems->dtim_period)
  4685. link->u.mgd.dtim_period = elems->dtim_period;
  4686. link->u.mgd.have_beacon = true;
  4687. ifmgd->assoc_data->need_beacon = false;
  4688. if (ieee80211_hw_check(&local->hw, TIMING_BEACON_ONLY)) {
  4689. link->conf->sync_tsf =
  4690. le64_to_cpu(mgmt->u.beacon.timestamp);
  4691. link->conf->sync_device_ts =
  4692. rx_status->device_timestamp;
  4693. link->conf->sync_dtim_count = elems->dtim_count;
  4694. }
  4695. if (elems->mbssid_config_ie)
  4696. bss_conf->profile_periodicity =
  4697. elems->mbssid_config_ie->profile_periodicity;
  4698. else
  4699. bss_conf->profile_periodicity = 0;
  4700. if (elems->ext_capab_len >= 11 &&
  4701. (elems->ext_capab[10] & WLAN_EXT_CAPA11_EMA_SUPPORT))
  4702. bss_conf->ema_ap = true;
  4703. else
  4704. bss_conf->ema_ap = false;
  4705. /* continue assoc process */
  4706. ifmgd->assoc_data->timeout = jiffies;
  4707. ifmgd->assoc_data->timeout_started = true;
  4708. run_again(sdata, ifmgd->assoc_data->timeout);
  4709. kfree(elems);
  4710. return;
  4711. }
  4712. if (!ifmgd->associated ||
  4713. !ieee80211_rx_our_beacon(bssid, link->u.mgd.bss))
  4714. return;
  4715. bssid = link->u.mgd.bssid;
  4716. if (!(rx_status->flag & RX_FLAG_NO_SIGNAL_VAL))
  4717. ieee80211_handle_beacon_sig(link, ifmgd, bss_conf,
  4718. local, rx_status);
  4719. if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL) {
  4720. mlme_dbg_ratelimited(sdata,
  4721. "cancelling AP probe due to a received beacon\n");
  4722. ieee80211_reset_ap_probe(sdata);
  4723. }
  4724. /*
  4725. * Push the beacon loss detection into the future since
  4726. * we are processing a beacon from the AP just now.
  4727. */
  4728. ieee80211_sta_reset_beacon_monitor(sdata);
  4729. /* TODO: CRC urrently not calculated on S1G Beacon Compatibility
  4730. * element (which carries the beacon interval). Don't forget to add a
  4731. * bit to care_about_ies[] above if mac80211 is interested in a
  4732. * changing S1G element.
  4733. */
  4734. if (!ieee80211_is_s1g_beacon(hdr->frame_control))
  4735. ncrc = crc32_be(0, (void *)&mgmt->u.beacon.beacon_int, 4);
  4736. parse_params.bss = link->u.mgd.bss;
  4737. parse_params.filter = care_about_ies;
  4738. parse_params.crc = ncrc;
  4739. elems = ieee802_11_parse_elems_full(&parse_params);
  4740. if (!elems)
  4741. return;
  4742. ncrc = elems->crc;
  4743. if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK) &&
  4744. ieee80211_check_tim(elems->tim, elems->tim_len, vif_cfg->aid)) {
  4745. if (local->hw.conf.dynamic_ps_timeout > 0) {
  4746. if (local->hw.conf.flags & IEEE80211_CONF_PS) {
  4747. local->hw.conf.flags &= ~IEEE80211_CONF_PS;
  4748. ieee80211_hw_config(local,
  4749. IEEE80211_CONF_CHANGE_PS);
  4750. }
  4751. ieee80211_send_nullfunc(local, sdata, false);
  4752. } else if (!local->pspolling && sdata->u.mgd.powersave) {
  4753. local->pspolling = true;
  4754. /*
  4755. * Here is assumed that the driver will be
  4756. * able to send ps-poll frame and receive a
  4757. * response even though power save mode is
  4758. * enabled, but some drivers might require
  4759. * to disable power save here. This needs
  4760. * to be investigated.
  4761. */
  4762. ieee80211_send_pspoll(local, sdata);
  4763. }
  4764. }
  4765. if (sdata->vif.p2p ||
  4766. sdata->vif.driver_flags & IEEE80211_VIF_GET_NOA_UPDATE) {
  4767. struct ieee80211_p2p_noa_attr noa = {};
  4768. int ret;
  4769. ret = cfg80211_get_p2p_attr(variable,
  4770. len - baselen,
  4771. IEEE80211_P2P_ATTR_ABSENCE_NOTICE,
  4772. (u8 *) &noa, sizeof(noa));
  4773. if (ret >= 2) {
  4774. if (link->u.mgd.p2p_noa_index != noa.index) {
  4775. /* valid noa_attr and index changed */
  4776. link->u.mgd.p2p_noa_index = noa.index;
  4777. memcpy(&bss_conf->p2p_noa_attr, &noa, sizeof(noa));
  4778. changed |= BSS_CHANGED_P2P_PS;
  4779. /*
  4780. * make sure we update all information, the CRC
  4781. * mechanism doesn't look at P2P attributes.
  4782. */
  4783. link->u.mgd.beacon_crc_valid = false;
  4784. }
  4785. } else if (link->u.mgd.p2p_noa_index != -1) {
  4786. /* noa_attr not found and we had valid noa_attr before */
  4787. link->u.mgd.p2p_noa_index = -1;
  4788. memset(&bss_conf->p2p_noa_attr, 0, sizeof(bss_conf->p2p_noa_attr));
  4789. changed |= BSS_CHANGED_P2P_PS;
  4790. link->u.mgd.beacon_crc_valid = false;
  4791. }
  4792. }
  4793. if (link->u.mgd.csa_waiting_bcn)
  4794. ieee80211_chswitch_post_beacon(link);
  4795. /*
  4796. * Update beacon timing and dtim count on every beacon appearance. This
  4797. * will allow the driver to use the most updated values. Do it before
  4798. * comparing this one with last received beacon.
  4799. * IMPORTANT: These parameters would possibly be out of sync by the time
  4800. * the driver will use them. The synchronized view is currently
  4801. * guaranteed only in certain callbacks.
  4802. */
  4803. if (ieee80211_hw_check(&local->hw, TIMING_BEACON_ONLY) &&
  4804. !ieee80211_is_s1g_beacon(hdr->frame_control)) {
  4805. link->conf->sync_tsf =
  4806. le64_to_cpu(mgmt->u.beacon.timestamp);
  4807. link->conf->sync_device_ts =
  4808. rx_status->device_timestamp;
  4809. link->conf->sync_dtim_count = elems->dtim_count;
  4810. }
  4811. if ((ncrc == link->u.mgd.beacon_crc && link->u.mgd.beacon_crc_valid) ||
  4812. ieee80211_is_s1g_short_beacon(mgmt->frame_control))
  4813. goto free;
  4814. link->u.mgd.beacon_crc = ncrc;
  4815. link->u.mgd.beacon_crc_valid = true;
  4816. ieee80211_rx_bss_info(link, mgmt, len, rx_status);
  4817. ieee80211_sta_process_chanswitch(link, rx_status->mactime,
  4818. rx_status->device_timestamp,
  4819. elems, true);
  4820. if (!link->u.mgd.disable_wmm_tracking &&
  4821. ieee80211_sta_wmm_params(local, link, elems->wmm_param,
  4822. elems->wmm_param_len,
  4823. elems->mu_edca_param_set))
  4824. changed |= BSS_CHANGED_QOS;
  4825. /*
  4826. * If we haven't had a beacon before, tell the driver about the
  4827. * DTIM period (and beacon timing if desired) now.
  4828. */
  4829. if (!link->u.mgd.have_beacon) {
  4830. /* a few bogus AP send dtim_period = 0 or no TIM IE */
  4831. bss_conf->dtim_period = elems->dtim_period ?: 1;
  4832. changed |= BSS_CHANGED_BEACON_INFO;
  4833. link->u.mgd.have_beacon = true;
  4834. mutex_lock(&local->iflist_mtx);
  4835. ieee80211_recalc_ps(local);
  4836. mutex_unlock(&local->iflist_mtx);
  4837. ieee80211_recalc_ps_vif(sdata);
  4838. }
  4839. if (elems->erp_info) {
  4840. erp_valid = true;
  4841. erp_value = elems->erp_info[0];
  4842. } else {
  4843. erp_valid = false;
  4844. }
  4845. if (!ieee80211_is_s1g_beacon(hdr->frame_control))
  4846. changed |= ieee80211_handle_bss_capability(link,
  4847. le16_to_cpu(mgmt->u.beacon.capab_info),
  4848. erp_valid, erp_value);
  4849. mutex_lock(&local->sta_mtx);
  4850. sta = sta_info_get(sdata, sdata->vif.cfg.ap_addr);
  4851. if (WARN_ON(!sta)) {
  4852. mutex_unlock(&local->sta_mtx);
  4853. goto free;
  4854. }
  4855. link_sta = rcu_dereference_protected(sta->link[link->link_id],
  4856. lockdep_is_held(&local->sta_mtx));
  4857. if (WARN_ON(!link_sta)) {
  4858. mutex_unlock(&local->sta_mtx);
  4859. goto free;
  4860. }
  4861. changed |= ieee80211_recalc_twt_req(link, link_sta, elems);
  4862. if (ieee80211_config_bw(link, elems->ht_cap_elem,
  4863. elems->vht_cap_elem, elems->ht_operation,
  4864. elems->vht_operation, elems->he_operation,
  4865. elems->eht_operation,
  4866. elems->s1g_oper, bssid, &changed)) {
  4867. mutex_unlock(&local->sta_mtx);
  4868. sdata_info(sdata,
  4869. "failed to follow AP %pM bandwidth change, disconnect\n",
  4870. bssid);
  4871. ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
  4872. WLAN_REASON_DEAUTH_LEAVING,
  4873. true, deauth_buf);
  4874. ieee80211_report_disconnect(sdata, deauth_buf,
  4875. sizeof(deauth_buf), true,
  4876. WLAN_REASON_DEAUTH_LEAVING,
  4877. false);
  4878. goto free;
  4879. }
  4880. if (sta && elems->opmode_notif)
  4881. ieee80211_vht_handle_opmode(sdata, link_sta,
  4882. *elems->opmode_notif,
  4883. rx_status->band);
  4884. mutex_unlock(&local->sta_mtx);
  4885. changed |= ieee80211_handle_pwr_constr(link, chan, mgmt,
  4886. elems->country_elem,
  4887. elems->country_elem_len,
  4888. elems->pwr_constr_elem,
  4889. elems->cisco_dtpc_elem);
  4890. ieee80211_link_info_change_notify(sdata, link, changed);
  4891. free:
  4892. kfree(elems);
  4893. }
  4894. void ieee80211_sta_rx_queued_ext(struct ieee80211_sub_if_data *sdata,
  4895. struct sk_buff *skb)
  4896. {
  4897. struct ieee80211_link_data *link = &sdata->deflink;
  4898. struct ieee80211_rx_status *rx_status;
  4899. struct ieee80211_hdr *hdr;
  4900. u16 fc;
  4901. rx_status = (struct ieee80211_rx_status *) skb->cb;
  4902. hdr = (struct ieee80211_hdr *) skb->data;
  4903. fc = le16_to_cpu(hdr->frame_control);
  4904. sdata_lock(sdata);
  4905. switch (fc & IEEE80211_FCTL_STYPE) {
  4906. case IEEE80211_STYPE_S1G_BEACON:
  4907. ieee80211_rx_mgmt_beacon(link, hdr, skb->len, rx_status);
  4908. break;
  4909. }
  4910. sdata_unlock(sdata);
  4911. }
  4912. void ieee80211_sta_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
  4913. struct sk_buff *skb)
  4914. {
  4915. struct ieee80211_link_data *link = &sdata->deflink;
  4916. struct ieee80211_rx_status *rx_status;
  4917. struct ieee80211_mgmt *mgmt;
  4918. u16 fc;
  4919. int ies_len;
  4920. rx_status = (struct ieee80211_rx_status *) skb->cb;
  4921. mgmt = (struct ieee80211_mgmt *) skb->data;
  4922. fc = le16_to_cpu(mgmt->frame_control);
  4923. sdata_lock(sdata);
  4924. if (rx_status->link_valid) {
  4925. link = sdata_dereference(sdata->link[rx_status->link_id],
  4926. sdata);
  4927. if (!link)
  4928. goto out;
  4929. }
  4930. switch (fc & IEEE80211_FCTL_STYPE) {
  4931. case IEEE80211_STYPE_BEACON:
  4932. ieee80211_rx_mgmt_beacon(link, (void *)mgmt,
  4933. skb->len, rx_status);
  4934. break;
  4935. case IEEE80211_STYPE_PROBE_RESP:
  4936. ieee80211_rx_mgmt_probe_resp(link, skb);
  4937. break;
  4938. case IEEE80211_STYPE_AUTH:
  4939. ieee80211_rx_mgmt_auth(sdata, mgmt, skb->len);
  4940. break;
  4941. case IEEE80211_STYPE_DEAUTH:
  4942. ieee80211_rx_mgmt_deauth(sdata, mgmt, skb->len);
  4943. break;
  4944. case IEEE80211_STYPE_DISASSOC:
  4945. ieee80211_rx_mgmt_disassoc(sdata, mgmt, skb->len);
  4946. break;
  4947. case IEEE80211_STYPE_ASSOC_RESP:
  4948. case IEEE80211_STYPE_REASSOC_RESP:
  4949. ieee80211_rx_mgmt_assoc_resp(sdata, mgmt, skb->len);
  4950. break;
  4951. case IEEE80211_STYPE_ACTION:
  4952. if (mgmt->u.action.category == WLAN_CATEGORY_SPECTRUM_MGMT) {
  4953. struct ieee802_11_elems *elems;
  4954. ies_len = skb->len -
  4955. offsetof(struct ieee80211_mgmt,
  4956. u.action.u.chan_switch.variable);
  4957. if (ies_len < 0)
  4958. break;
  4959. /* CSA IE cannot be overridden, no need for BSSID */
  4960. elems = ieee802_11_parse_elems(
  4961. mgmt->u.action.u.chan_switch.variable,
  4962. ies_len, true, NULL);
  4963. if (elems && !elems->parse_error)
  4964. ieee80211_sta_process_chanswitch(link,
  4965. rx_status->mactime,
  4966. rx_status->device_timestamp,
  4967. elems, false);
  4968. kfree(elems);
  4969. } else if (mgmt->u.action.category == WLAN_CATEGORY_PUBLIC) {
  4970. struct ieee802_11_elems *elems;
  4971. ies_len = skb->len -
  4972. offsetof(struct ieee80211_mgmt,
  4973. u.action.u.ext_chan_switch.variable);
  4974. if (ies_len < 0)
  4975. break;
  4976. /*
  4977. * extended CSA IE can't be overridden, no need for
  4978. * BSSID
  4979. */
  4980. elems = ieee802_11_parse_elems(
  4981. mgmt->u.action.u.ext_chan_switch.variable,
  4982. ies_len, true, NULL);
  4983. if (elems && !elems->parse_error) {
  4984. /* for the handling code pretend it was an IE */
  4985. elems->ext_chansw_ie =
  4986. &mgmt->u.action.u.ext_chan_switch.data;
  4987. ieee80211_sta_process_chanswitch(link,
  4988. rx_status->mactime,
  4989. rx_status->device_timestamp,
  4990. elems, false);
  4991. }
  4992. kfree(elems);
  4993. }
  4994. break;
  4995. }
  4996. out:
  4997. sdata_unlock(sdata);
  4998. }
  4999. static void ieee80211_sta_timer(struct timer_list *t)
  5000. {
  5001. struct ieee80211_sub_if_data *sdata =
  5002. from_timer(sdata, t, u.mgd.timer);
  5003. ieee80211_queue_work(&sdata->local->hw, &sdata->work);
  5004. }
  5005. void ieee80211_sta_connection_lost(struct ieee80211_sub_if_data *sdata,
  5006. u8 reason, bool tx)
  5007. {
  5008. u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
  5009. ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH, reason,
  5010. tx, frame_buf);
  5011. ieee80211_report_disconnect(sdata, frame_buf, sizeof(frame_buf), true,
  5012. reason, false);
  5013. }
  5014. static int ieee80211_auth(struct ieee80211_sub_if_data *sdata)
  5015. {
  5016. struct ieee80211_local *local = sdata->local;
  5017. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  5018. struct ieee80211_mgd_auth_data *auth_data = ifmgd->auth_data;
  5019. u32 tx_flags = 0;
  5020. u16 trans = 1;
  5021. u16 status = 0;
  5022. struct ieee80211_prep_tx_info info = {
  5023. .subtype = IEEE80211_STYPE_AUTH,
  5024. };
  5025. sdata_assert_lock(sdata);
  5026. if (WARN_ON_ONCE(!auth_data))
  5027. return -EINVAL;
  5028. auth_data->tries++;
  5029. if (auth_data->tries > IEEE80211_AUTH_MAX_TRIES) {
  5030. sdata_info(sdata, "authentication with %pM timed out\n",
  5031. auth_data->ap_addr);
  5032. /*
  5033. * Most likely AP is not in the range so remove the
  5034. * bss struct for that AP.
  5035. */
  5036. cfg80211_unlink_bss(local->hw.wiphy, auth_data->bss);
  5037. return -ETIMEDOUT;
  5038. }
  5039. if (auth_data->algorithm == WLAN_AUTH_SAE)
  5040. info.duration = jiffies_to_msecs(IEEE80211_AUTH_TIMEOUT_SAE);
  5041. drv_mgd_prepare_tx(local, sdata, &info);
  5042. sdata_info(sdata, "send auth to %pM (try %d/%d)\n",
  5043. auth_data->ap_addr, auth_data->tries,
  5044. IEEE80211_AUTH_MAX_TRIES);
  5045. auth_data->expected_transaction = 2;
  5046. if (auth_data->algorithm == WLAN_AUTH_SAE) {
  5047. trans = auth_data->sae_trans;
  5048. status = auth_data->sae_status;
  5049. auth_data->expected_transaction = trans;
  5050. }
  5051. if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
  5052. tx_flags = IEEE80211_TX_CTL_REQ_TX_STATUS |
  5053. IEEE80211_TX_INTFL_MLME_CONN_TX;
  5054. ieee80211_send_auth(sdata, trans, auth_data->algorithm, status,
  5055. auth_data->data, auth_data->data_len,
  5056. auth_data->ap_addr, auth_data->ap_addr,
  5057. NULL, 0, 0, tx_flags);
  5058. if (tx_flags == 0) {
  5059. if (auth_data->algorithm == WLAN_AUTH_SAE)
  5060. auth_data->timeout = jiffies +
  5061. IEEE80211_AUTH_TIMEOUT_SAE;
  5062. else
  5063. auth_data->timeout = jiffies + IEEE80211_AUTH_TIMEOUT;
  5064. } else {
  5065. auth_data->timeout =
  5066. round_jiffies_up(jiffies + IEEE80211_AUTH_TIMEOUT_LONG);
  5067. }
  5068. auth_data->timeout_started = true;
  5069. run_again(sdata, auth_data->timeout);
  5070. return 0;
  5071. }
  5072. static int ieee80211_do_assoc(struct ieee80211_sub_if_data *sdata)
  5073. {
  5074. struct ieee80211_mgd_assoc_data *assoc_data = sdata->u.mgd.assoc_data;
  5075. struct ieee80211_local *local = sdata->local;
  5076. int ret;
  5077. sdata_assert_lock(sdata);
  5078. assoc_data->tries++;
  5079. if (assoc_data->tries > IEEE80211_ASSOC_MAX_TRIES) {
  5080. sdata_info(sdata, "association with %pM timed out\n",
  5081. assoc_data->ap_addr);
  5082. /*
  5083. * Most likely AP is not in the range so remove the
  5084. * bss struct for that AP.
  5085. */
  5086. cfg80211_unlink_bss(local->hw.wiphy,
  5087. assoc_data->link[assoc_data->assoc_link_id].bss);
  5088. return -ETIMEDOUT;
  5089. }
  5090. sdata_info(sdata, "associate with %pM (try %d/%d)\n",
  5091. assoc_data->ap_addr, assoc_data->tries,
  5092. IEEE80211_ASSOC_MAX_TRIES);
  5093. ret = ieee80211_send_assoc(sdata);
  5094. if (ret)
  5095. return ret;
  5096. if (!ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) {
  5097. assoc_data->timeout = jiffies + IEEE80211_ASSOC_TIMEOUT;
  5098. assoc_data->timeout_started = true;
  5099. run_again(sdata, assoc_data->timeout);
  5100. } else {
  5101. assoc_data->timeout =
  5102. round_jiffies_up(jiffies +
  5103. IEEE80211_ASSOC_TIMEOUT_LONG);
  5104. assoc_data->timeout_started = true;
  5105. run_again(sdata, assoc_data->timeout);
  5106. }
  5107. return 0;
  5108. }
  5109. void ieee80211_mgd_conn_tx_status(struct ieee80211_sub_if_data *sdata,
  5110. __le16 fc, bool acked)
  5111. {
  5112. struct ieee80211_local *local = sdata->local;
  5113. sdata->u.mgd.status_fc = fc;
  5114. sdata->u.mgd.status_acked = acked;
  5115. sdata->u.mgd.status_received = true;
  5116. ieee80211_queue_work(&local->hw, &sdata->work);
  5117. }
  5118. void ieee80211_sta_work(struct ieee80211_sub_if_data *sdata)
  5119. {
  5120. struct ieee80211_local *local = sdata->local;
  5121. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  5122. sdata_lock(sdata);
  5123. if (ifmgd->status_received) {
  5124. __le16 fc = ifmgd->status_fc;
  5125. bool status_acked = ifmgd->status_acked;
  5126. ifmgd->status_received = false;
  5127. if (ifmgd->auth_data && ieee80211_is_auth(fc)) {
  5128. if (status_acked) {
  5129. if (ifmgd->auth_data->algorithm ==
  5130. WLAN_AUTH_SAE)
  5131. ifmgd->auth_data->timeout =
  5132. jiffies +
  5133. IEEE80211_AUTH_TIMEOUT_SAE;
  5134. else
  5135. ifmgd->auth_data->timeout =
  5136. jiffies +
  5137. IEEE80211_AUTH_TIMEOUT_SHORT;
  5138. run_again(sdata, ifmgd->auth_data->timeout);
  5139. } else {
  5140. ifmgd->auth_data->timeout = jiffies - 1;
  5141. }
  5142. ifmgd->auth_data->timeout_started = true;
  5143. } else if (ifmgd->assoc_data &&
  5144. (ieee80211_is_assoc_req(fc) ||
  5145. ieee80211_is_reassoc_req(fc))) {
  5146. if (status_acked) {
  5147. ifmgd->assoc_data->timeout =
  5148. jiffies + IEEE80211_ASSOC_TIMEOUT_SHORT;
  5149. run_again(sdata, ifmgd->assoc_data->timeout);
  5150. } else {
  5151. ifmgd->assoc_data->timeout = jiffies - 1;
  5152. }
  5153. ifmgd->assoc_data->timeout_started = true;
  5154. }
  5155. }
  5156. if (ifmgd->auth_data && ifmgd->auth_data->timeout_started &&
  5157. time_after(jiffies, ifmgd->auth_data->timeout)) {
  5158. if (ifmgd->auth_data->done || ifmgd->auth_data->waiting) {
  5159. /*
  5160. * ok ... we waited for assoc or continuation but
  5161. * userspace didn't do it, so kill the auth data
  5162. */
  5163. ieee80211_destroy_auth_data(sdata, false);
  5164. } else if (ieee80211_auth(sdata)) {
  5165. u8 ap_addr[ETH_ALEN];
  5166. struct ieee80211_event event = {
  5167. .type = MLME_EVENT,
  5168. .u.mlme.data = AUTH_EVENT,
  5169. .u.mlme.status = MLME_TIMEOUT,
  5170. };
  5171. memcpy(ap_addr, ifmgd->auth_data->ap_addr, ETH_ALEN);
  5172. ieee80211_destroy_auth_data(sdata, false);
  5173. cfg80211_auth_timeout(sdata->dev, ap_addr);
  5174. drv_event_callback(sdata->local, sdata, &event);
  5175. }
  5176. } else if (ifmgd->auth_data && ifmgd->auth_data->timeout_started)
  5177. run_again(sdata, ifmgd->auth_data->timeout);
  5178. if (ifmgd->assoc_data && ifmgd->assoc_data->timeout_started &&
  5179. time_after(jiffies, ifmgd->assoc_data->timeout)) {
  5180. if ((ifmgd->assoc_data->need_beacon &&
  5181. !sdata->deflink.u.mgd.have_beacon) ||
  5182. ieee80211_do_assoc(sdata)) {
  5183. struct ieee80211_event event = {
  5184. .type = MLME_EVENT,
  5185. .u.mlme.data = ASSOC_EVENT,
  5186. .u.mlme.status = MLME_TIMEOUT,
  5187. };
  5188. ieee80211_destroy_assoc_data(sdata, ASSOC_TIMEOUT);
  5189. drv_event_callback(sdata->local, sdata, &event);
  5190. }
  5191. } else if (ifmgd->assoc_data && ifmgd->assoc_data->timeout_started)
  5192. run_again(sdata, ifmgd->assoc_data->timeout);
  5193. if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL &&
  5194. ifmgd->associated) {
  5195. u8 *bssid = sdata->deflink.u.mgd.bssid;
  5196. int max_tries;
  5197. if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
  5198. max_tries = max_nullfunc_tries;
  5199. else
  5200. max_tries = max_probe_tries;
  5201. /* ACK received for nullfunc probing frame */
  5202. if (!ifmgd->probe_send_count)
  5203. ieee80211_reset_ap_probe(sdata);
  5204. else if (ifmgd->nullfunc_failed) {
  5205. if (ifmgd->probe_send_count < max_tries) {
  5206. mlme_dbg(sdata,
  5207. "No ack for nullfunc frame to AP %pM, try %d/%i\n",
  5208. bssid, ifmgd->probe_send_count,
  5209. max_tries);
  5210. ieee80211_mgd_probe_ap_send(sdata);
  5211. } else {
  5212. mlme_dbg(sdata,
  5213. "No ack for nullfunc frame to AP %pM, disconnecting.\n",
  5214. bssid);
  5215. ieee80211_sta_connection_lost(sdata,
  5216. WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY,
  5217. false);
  5218. }
  5219. } else if (time_is_after_jiffies(ifmgd->probe_timeout))
  5220. run_again(sdata, ifmgd->probe_timeout);
  5221. else if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) {
  5222. mlme_dbg(sdata,
  5223. "Failed to send nullfunc to AP %pM after %dms, disconnecting\n",
  5224. bssid, probe_wait_ms);
  5225. ieee80211_sta_connection_lost(sdata,
  5226. WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY, false);
  5227. } else if (ifmgd->probe_send_count < max_tries) {
  5228. mlme_dbg(sdata,
  5229. "No probe response from AP %pM after %dms, try %d/%i\n",
  5230. bssid, probe_wait_ms,
  5231. ifmgd->probe_send_count, max_tries);
  5232. ieee80211_mgd_probe_ap_send(sdata);
  5233. } else {
  5234. /*
  5235. * We actually lost the connection ... or did we?
  5236. * Let's make sure!
  5237. */
  5238. mlme_dbg(sdata,
  5239. "No probe response from AP %pM after %dms, disconnecting.\n",
  5240. bssid, probe_wait_ms);
  5241. ieee80211_sta_connection_lost(sdata,
  5242. WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY, false);
  5243. }
  5244. }
  5245. sdata_unlock(sdata);
  5246. }
  5247. static void ieee80211_sta_bcn_mon_timer(struct timer_list *t)
  5248. {
  5249. struct ieee80211_sub_if_data *sdata =
  5250. from_timer(sdata, t, u.mgd.bcn_mon_timer);
  5251. if (WARN_ON(sdata->vif.valid_links))
  5252. return;
  5253. if (sdata->vif.bss_conf.csa_active &&
  5254. !sdata->deflink.u.mgd.csa_waiting_bcn)
  5255. return;
  5256. if (sdata->vif.driver_flags & IEEE80211_VIF_BEACON_FILTER)
  5257. return;
  5258. sdata->u.mgd.connection_loss = false;
  5259. ieee80211_queue_work(&sdata->local->hw,
  5260. &sdata->u.mgd.beacon_connection_loss_work);
  5261. }
  5262. static void ieee80211_sta_conn_mon_timer(struct timer_list *t)
  5263. {
  5264. struct ieee80211_sub_if_data *sdata =
  5265. from_timer(sdata, t, u.mgd.conn_mon_timer);
  5266. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  5267. struct ieee80211_local *local = sdata->local;
  5268. struct sta_info *sta;
  5269. unsigned long timeout;
  5270. if (WARN_ON(sdata->vif.valid_links))
  5271. return;
  5272. if (sdata->vif.bss_conf.csa_active &&
  5273. !sdata->deflink.u.mgd.csa_waiting_bcn)
  5274. return;
  5275. sta = sta_info_get(sdata, sdata->vif.cfg.ap_addr);
  5276. if (!sta)
  5277. return;
  5278. timeout = sta->deflink.status_stats.last_ack;
  5279. if (time_before(sta->deflink.status_stats.last_ack, sta->deflink.rx_stats.last_rx))
  5280. timeout = sta->deflink.rx_stats.last_rx;
  5281. timeout += IEEE80211_CONNECTION_IDLE_TIME;
  5282. /* If timeout is after now, then update timer to fire at
  5283. * the later date, but do not actually probe at this time.
  5284. */
  5285. if (time_is_after_jiffies(timeout)) {
  5286. mod_timer(&ifmgd->conn_mon_timer, round_jiffies_up(timeout));
  5287. return;
  5288. }
  5289. ieee80211_queue_work(&local->hw, &ifmgd->monitor_work);
  5290. }
  5291. static void ieee80211_sta_monitor_work(struct work_struct *work)
  5292. {
  5293. struct ieee80211_sub_if_data *sdata =
  5294. container_of(work, struct ieee80211_sub_if_data,
  5295. u.mgd.monitor_work);
  5296. ieee80211_mgd_probe_ap(sdata, false);
  5297. }
  5298. static void ieee80211_restart_sta_timer(struct ieee80211_sub_if_data *sdata)
  5299. {
  5300. if (sdata->vif.type == NL80211_IFTYPE_STATION) {
  5301. __ieee80211_stop_poll(sdata);
  5302. /* let's probe the connection once */
  5303. if (!ieee80211_hw_check(&sdata->local->hw, CONNECTION_MONITOR))
  5304. ieee80211_queue_work(&sdata->local->hw,
  5305. &sdata->u.mgd.monitor_work);
  5306. }
  5307. }
  5308. #ifdef CONFIG_PM
  5309. void ieee80211_mgd_quiesce(struct ieee80211_sub_if_data *sdata)
  5310. {
  5311. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  5312. u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
  5313. sdata_lock(sdata);
  5314. if (ifmgd->auth_data || ifmgd->assoc_data) {
  5315. const u8 *ap_addr = ifmgd->auth_data ?
  5316. ifmgd->auth_data->ap_addr :
  5317. ifmgd->assoc_data->ap_addr;
  5318. /*
  5319. * If we are trying to authenticate / associate while suspending,
  5320. * cfg80211 won't know and won't actually abort those attempts,
  5321. * thus we need to do that ourselves.
  5322. */
  5323. ieee80211_send_deauth_disassoc(sdata, ap_addr, ap_addr,
  5324. IEEE80211_STYPE_DEAUTH,
  5325. WLAN_REASON_DEAUTH_LEAVING,
  5326. false, frame_buf);
  5327. if (ifmgd->assoc_data)
  5328. ieee80211_destroy_assoc_data(sdata, ASSOC_ABANDON);
  5329. if (ifmgd->auth_data)
  5330. ieee80211_destroy_auth_data(sdata, false);
  5331. cfg80211_tx_mlme_mgmt(sdata->dev, frame_buf,
  5332. IEEE80211_DEAUTH_FRAME_LEN,
  5333. false);
  5334. }
  5335. /* This is a bit of a hack - we should find a better and more generic
  5336. * solution to this. Normally when suspending, cfg80211 will in fact
  5337. * deauthenticate. However, it doesn't (and cannot) stop an ongoing
  5338. * auth (not so important) or assoc (this is the problem) process.
  5339. *
  5340. * As a consequence, it can happen that we are in the process of both
  5341. * associating and suspending, and receive an association response
  5342. * after cfg80211 has checked if it needs to disconnect, but before
  5343. * we actually set the flag to drop incoming frames. This will then
  5344. * cause the workqueue flush to process the association response in
  5345. * the suspend, resulting in a successful association just before it
  5346. * tries to remove the interface from the driver, which now though
  5347. * has a channel context assigned ... this results in issues.
  5348. *
  5349. * To work around this (for now) simply deauth here again if we're
  5350. * now connected.
  5351. */
  5352. if (ifmgd->associated && !sdata->local->wowlan) {
  5353. u8 bssid[ETH_ALEN];
  5354. struct cfg80211_deauth_request req = {
  5355. .reason_code = WLAN_REASON_DEAUTH_LEAVING,
  5356. .bssid = bssid,
  5357. };
  5358. memcpy(bssid, sdata->vif.cfg.ap_addr, ETH_ALEN);
  5359. ieee80211_mgd_deauth(sdata, &req);
  5360. }
  5361. sdata_unlock(sdata);
  5362. }
  5363. #endif
  5364. void ieee80211_sta_restart(struct ieee80211_sub_if_data *sdata)
  5365. {
  5366. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  5367. sdata_lock(sdata);
  5368. if (!ifmgd->associated) {
  5369. sdata_unlock(sdata);
  5370. return;
  5371. }
  5372. if (sdata->flags & IEEE80211_SDATA_DISCONNECT_RESUME) {
  5373. sdata->flags &= ~IEEE80211_SDATA_DISCONNECT_RESUME;
  5374. mlme_dbg(sdata, "driver requested disconnect after resume\n");
  5375. ieee80211_sta_connection_lost(sdata,
  5376. WLAN_REASON_UNSPECIFIED,
  5377. true);
  5378. sdata_unlock(sdata);
  5379. return;
  5380. }
  5381. if (sdata->flags & IEEE80211_SDATA_DISCONNECT_HW_RESTART) {
  5382. sdata->flags &= ~IEEE80211_SDATA_DISCONNECT_HW_RESTART;
  5383. mlme_dbg(sdata, "driver requested disconnect after hardware restart\n");
  5384. ieee80211_sta_connection_lost(sdata,
  5385. WLAN_REASON_UNSPECIFIED,
  5386. true);
  5387. sdata_unlock(sdata);
  5388. return;
  5389. }
  5390. sdata_unlock(sdata);
  5391. }
  5392. static void ieee80211_request_smps_mgd_work(struct work_struct *work)
  5393. {
  5394. struct ieee80211_link_data *link =
  5395. container_of(work, struct ieee80211_link_data,
  5396. u.mgd.request_smps_work);
  5397. sdata_lock(link->sdata);
  5398. __ieee80211_request_smps_mgd(link->sdata, link,
  5399. link->u.mgd.driver_smps_mode);
  5400. sdata_unlock(link->sdata);
  5401. }
  5402. /* interface setup */
  5403. void ieee80211_sta_setup_sdata(struct ieee80211_sub_if_data *sdata)
  5404. {
  5405. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  5406. INIT_WORK(&ifmgd->monitor_work, ieee80211_sta_monitor_work);
  5407. INIT_WORK(&ifmgd->beacon_connection_loss_work,
  5408. ieee80211_beacon_connection_loss_work);
  5409. INIT_WORK(&ifmgd->csa_connection_drop_work,
  5410. ieee80211_csa_connection_drop_work);
  5411. INIT_DELAYED_WORK(&ifmgd->tdls_peer_del_work,
  5412. ieee80211_tdls_peer_del_work);
  5413. timer_setup(&ifmgd->timer, ieee80211_sta_timer, 0);
  5414. timer_setup(&ifmgd->bcn_mon_timer, ieee80211_sta_bcn_mon_timer, 0);
  5415. timer_setup(&ifmgd->conn_mon_timer, ieee80211_sta_conn_mon_timer, 0);
  5416. INIT_DELAYED_WORK(&ifmgd->tx_tspec_wk,
  5417. ieee80211_sta_handle_tspec_ac_params_wk);
  5418. ifmgd->flags = 0;
  5419. ifmgd->powersave = sdata->wdev.ps;
  5420. ifmgd->uapsd_queues = sdata->local->hw.uapsd_queues;
  5421. ifmgd->uapsd_max_sp_len = sdata->local->hw.uapsd_max_sp_len;
  5422. /* Setup TDLS data */
  5423. spin_lock_init(&ifmgd->teardown_lock);
  5424. ifmgd->teardown_skb = NULL;
  5425. ifmgd->orig_teardown_skb = NULL;
  5426. }
  5427. void ieee80211_mgd_setup_link(struct ieee80211_link_data *link)
  5428. {
  5429. struct ieee80211_sub_if_data *sdata = link->sdata;
  5430. struct ieee80211_local *local = sdata->local;
  5431. unsigned int link_id = link->link_id;
  5432. link->u.mgd.p2p_noa_index = -1;
  5433. link->u.mgd.conn_flags = 0;
  5434. link->conf->bssid = link->u.mgd.bssid;
  5435. INIT_WORK(&link->u.mgd.request_smps_work,
  5436. ieee80211_request_smps_mgd_work);
  5437. if (local->hw.wiphy->features & NL80211_FEATURE_DYNAMIC_SMPS)
  5438. link->u.mgd.req_smps = IEEE80211_SMPS_AUTOMATIC;
  5439. else
  5440. link->u.mgd.req_smps = IEEE80211_SMPS_OFF;
  5441. INIT_WORK(&link->u.mgd.chswitch_work, ieee80211_chswitch_work);
  5442. timer_setup(&link->u.mgd.chswitch_timer, ieee80211_chswitch_timer, 0);
  5443. if (sdata->u.mgd.assoc_data)
  5444. ether_addr_copy(link->conf->addr,
  5445. sdata->u.mgd.assoc_data->link[link_id].addr);
  5446. else if (!is_valid_ether_addr(link->conf->addr))
  5447. eth_random_addr(link->conf->addr);
  5448. }
  5449. /* scan finished notification */
  5450. void ieee80211_mlme_notify_scan_completed(struct ieee80211_local *local)
  5451. {
  5452. struct ieee80211_sub_if_data *sdata;
  5453. /* Restart STA timers */
  5454. rcu_read_lock();
  5455. list_for_each_entry_rcu(sdata, &local->interfaces, list) {
  5456. if (ieee80211_sdata_running(sdata))
  5457. ieee80211_restart_sta_timer(sdata);
  5458. }
  5459. rcu_read_unlock();
  5460. }
  5461. static int ieee80211_prep_connection(struct ieee80211_sub_if_data *sdata,
  5462. struct cfg80211_bss *cbss, s8 link_id,
  5463. const u8 *ap_mld_addr, bool assoc,
  5464. bool override)
  5465. {
  5466. struct ieee80211_local *local = sdata->local;
  5467. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  5468. struct ieee80211_bss *bss = (void *)cbss->priv;
  5469. struct sta_info *new_sta = NULL;
  5470. struct ieee80211_link_data *link;
  5471. bool have_sta = false;
  5472. bool mlo;
  5473. int err;
  5474. if (link_id >= 0) {
  5475. mlo = true;
  5476. if (WARN_ON(!ap_mld_addr))
  5477. return -EINVAL;
  5478. err = ieee80211_vif_set_links(sdata, BIT(link_id));
  5479. } else {
  5480. if (WARN_ON(ap_mld_addr))
  5481. return -EINVAL;
  5482. ap_mld_addr = cbss->bssid;
  5483. err = ieee80211_vif_set_links(sdata, 0);
  5484. link_id = 0;
  5485. mlo = false;
  5486. }
  5487. if (err)
  5488. return err;
  5489. link = sdata_dereference(sdata->link[link_id], sdata);
  5490. if (WARN_ON(!link)) {
  5491. err = -ENOLINK;
  5492. goto out_err;
  5493. }
  5494. if (WARN_ON(!ifmgd->auth_data && !ifmgd->assoc_data)) {
  5495. err = -EINVAL;
  5496. goto out_err;
  5497. }
  5498. /* If a reconfig is happening, bail out */
  5499. if (local->in_reconfig) {
  5500. err = -EBUSY;
  5501. goto out_err;
  5502. }
  5503. if (assoc) {
  5504. rcu_read_lock();
  5505. have_sta = sta_info_get(sdata, ap_mld_addr);
  5506. rcu_read_unlock();
  5507. }
  5508. if (!have_sta) {
  5509. if (mlo)
  5510. new_sta = sta_info_alloc_with_link(sdata, ap_mld_addr,
  5511. link_id, cbss->bssid,
  5512. GFP_KERNEL);
  5513. else
  5514. new_sta = sta_info_alloc(sdata, ap_mld_addr, GFP_KERNEL);
  5515. if (!new_sta) {
  5516. err = -ENOMEM;
  5517. goto out_err;
  5518. }
  5519. new_sta->sta.mlo = mlo;
  5520. }
  5521. /*
  5522. * Set up the information for the new channel before setting the
  5523. * new channel. We can't - completely race-free - change the basic
  5524. * rates bitmap and the channel (sband) that it refers to, but if
  5525. * we set it up before we at least avoid calling into the driver's
  5526. * bss_info_changed() method with invalid information (since we do
  5527. * call that from changing the channel - only for IDLE and perhaps
  5528. * some others, but ...).
  5529. *
  5530. * So to avoid that, just set up all the new information before the
  5531. * channel, but tell the driver to apply it only afterwards, since
  5532. * it might need the new channel for that.
  5533. */
  5534. if (new_sta) {
  5535. const struct cfg80211_bss_ies *ies;
  5536. struct link_sta_info *link_sta;
  5537. rcu_read_lock();
  5538. link_sta = rcu_dereference(new_sta->link[link_id]);
  5539. if (WARN_ON(!link_sta)) {
  5540. rcu_read_unlock();
  5541. sta_info_free(local, new_sta);
  5542. err = -EINVAL;
  5543. goto out_err;
  5544. }
  5545. err = ieee80211_mgd_setup_link_sta(link, new_sta,
  5546. link_sta, cbss);
  5547. if (err) {
  5548. rcu_read_unlock();
  5549. sta_info_free(local, new_sta);
  5550. goto out_err;
  5551. }
  5552. memcpy(link->u.mgd.bssid, cbss->bssid, ETH_ALEN);
  5553. /* set timing information */
  5554. link->conf->beacon_int = cbss->beacon_interval;
  5555. ies = rcu_dereference(cbss->beacon_ies);
  5556. if (ies) {
  5557. link->conf->sync_tsf = ies->tsf;
  5558. link->conf->sync_device_ts =
  5559. bss->device_ts_beacon;
  5560. ieee80211_get_dtim(ies,
  5561. &link->conf->sync_dtim_count,
  5562. NULL);
  5563. } else if (!ieee80211_hw_check(&sdata->local->hw,
  5564. TIMING_BEACON_ONLY)) {
  5565. ies = rcu_dereference(cbss->proberesp_ies);
  5566. /* must be non-NULL since beacon IEs were NULL */
  5567. link->conf->sync_tsf = ies->tsf;
  5568. link->conf->sync_device_ts =
  5569. bss->device_ts_presp;
  5570. link->conf->sync_dtim_count = 0;
  5571. } else {
  5572. link->conf->sync_tsf = 0;
  5573. link->conf->sync_device_ts = 0;
  5574. link->conf->sync_dtim_count = 0;
  5575. }
  5576. rcu_read_unlock();
  5577. }
  5578. if (new_sta || override) {
  5579. err = ieee80211_prep_channel(sdata, link, cbss,
  5580. &link->u.mgd.conn_flags);
  5581. if (err) {
  5582. if (new_sta)
  5583. sta_info_free(local, new_sta);
  5584. goto out_err;
  5585. }
  5586. }
  5587. if (new_sta) {
  5588. /*
  5589. * tell driver about BSSID, basic rates and timing
  5590. * this was set up above, before setting the channel
  5591. */
  5592. ieee80211_link_info_change_notify(sdata, link,
  5593. BSS_CHANGED_BSSID |
  5594. BSS_CHANGED_BASIC_RATES |
  5595. BSS_CHANGED_BEACON_INT);
  5596. if (assoc)
  5597. sta_info_pre_move_state(new_sta, IEEE80211_STA_AUTH);
  5598. err = sta_info_insert(new_sta);
  5599. new_sta = NULL;
  5600. if (err) {
  5601. sdata_info(sdata,
  5602. "failed to insert STA entry for the AP (error %d)\n",
  5603. err);
  5604. goto out_err;
  5605. }
  5606. } else
  5607. WARN_ON_ONCE(!ether_addr_equal(link->u.mgd.bssid, cbss->bssid));
  5608. /* Cancel scan to ensure that nothing interferes with connection */
  5609. if (local->scanning)
  5610. ieee80211_scan_cancel(local);
  5611. return 0;
  5612. out_err:
  5613. ieee80211_link_release_channel(&sdata->deflink);
  5614. ieee80211_vif_set_links(sdata, 0);
  5615. return err;
  5616. }
  5617. /* config hooks */
  5618. int ieee80211_mgd_auth(struct ieee80211_sub_if_data *sdata,
  5619. struct cfg80211_auth_request *req)
  5620. {
  5621. struct ieee80211_local *local = sdata->local;
  5622. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  5623. struct ieee80211_mgd_auth_data *auth_data;
  5624. u16 auth_alg;
  5625. int err;
  5626. bool cont_auth;
  5627. /* prepare auth data structure */
  5628. switch (req->auth_type) {
  5629. case NL80211_AUTHTYPE_OPEN_SYSTEM:
  5630. auth_alg = WLAN_AUTH_OPEN;
  5631. break;
  5632. case NL80211_AUTHTYPE_SHARED_KEY:
  5633. if (fips_enabled)
  5634. return -EOPNOTSUPP;
  5635. auth_alg = WLAN_AUTH_SHARED_KEY;
  5636. break;
  5637. case NL80211_AUTHTYPE_FT:
  5638. auth_alg = WLAN_AUTH_FT;
  5639. break;
  5640. case NL80211_AUTHTYPE_NETWORK_EAP:
  5641. auth_alg = WLAN_AUTH_LEAP;
  5642. break;
  5643. case NL80211_AUTHTYPE_SAE:
  5644. auth_alg = WLAN_AUTH_SAE;
  5645. break;
  5646. case NL80211_AUTHTYPE_FILS_SK:
  5647. auth_alg = WLAN_AUTH_FILS_SK;
  5648. break;
  5649. case NL80211_AUTHTYPE_FILS_SK_PFS:
  5650. auth_alg = WLAN_AUTH_FILS_SK_PFS;
  5651. break;
  5652. case NL80211_AUTHTYPE_FILS_PK:
  5653. auth_alg = WLAN_AUTH_FILS_PK;
  5654. break;
  5655. default:
  5656. return -EOPNOTSUPP;
  5657. }
  5658. if (ifmgd->assoc_data)
  5659. return -EBUSY;
  5660. auth_data = kzalloc(sizeof(*auth_data) + req->auth_data_len +
  5661. req->ie_len, GFP_KERNEL);
  5662. if (!auth_data)
  5663. return -ENOMEM;
  5664. memcpy(auth_data->ap_addr,
  5665. req->ap_mld_addr ?: req->bss->bssid,
  5666. ETH_ALEN);
  5667. auth_data->bss = req->bss;
  5668. auth_data->link_id = req->link_id;
  5669. if (req->auth_data_len >= 4) {
  5670. if (req->auth_type == NL80211_AUTHTYPE_SAE) {
  5671. __le16 *pos = (__le16 *) req->auth_data;
  5672. auth_data->sae_trans = le16_to_cpu(pos[0]);
  5673. auth_data->sae_status = le16_to_cpu(pos[1]);
  5674. }
  5675. memcpy(auth_data->data, req->auth_data + 4,
  5676. req->auth_data_len - 4);
  5677. auth_data->data_len += req->auth_data_len - 4;
  5678. }
  5679. /* Check if continuing authentication or trying to authenticate with the
  5680. * same BSS that we were in the process of authenticating with and avoid
  5681. * removal and re-addition of the STA entry in
  5682. * ieee80211_prep_connection().
  5683. */
  5684. cont_auth = ifmgd->auth_data && req->bss == ifmgd->auth_data->bss &&
  5685. ifmgd->auth_data->link_id == req->link_id;
  5686. if (req->ie && req->ie_len) {
  5687. memcpy(&auth_data->data[auth_data->data_len],
  5688. req->ie, req->ie_len);
  5689. auth_data->data_len += req->ie_len;
  5690. }
  5691. if (req->key && req->key_len) {
  5692. auth_data->key_len = req->key_len;
  5693. auth_data->key_idx = req->key_idx;
  5694. memcpy(auth_data->key, req->key, req->key_len);
  5695. }
  5696. auth_data->algorithm = auth_alg;
  5697. /* try to authenticate/probe */
  5698. if (ifmgd->auth_data) {
  5699. if (cont_auth && req->auth_type == NL80211_AUTHTYPE_SAE) {
  5700. auth_data->peer_confirmed =
  5701. ifmgd->auth_data->peer_confirmed;
  5702. }
  5703. ieee80211_destroy_auth_data(sdata, cont_auth);
  5704. }
  5705. /* prep auth_data so we don't go into idle on disassoc */
  5706. ifmgd->auth_data = auth_data;
  5707. /* If this is continuation of an ongoing SAE authentication exchange
  5708. * (i.e., request to send SAE Confirm) and the peer has already
  5709. * confirmed, mark authentication completed since we are about to send
  5710. * out SAE Confirm.
  5711. */
  5712. if (cont_auth && req->auth_type == NL80211_AUTHTYPE_SAE &&
  5713. auth_data->peer_confirmed && auth_data->sae_trans == 2)
  5714. ieee80211_mark_sta_auth(sdata);
  5715. if (ifmgd->associated) {
  5716. u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
  5717. sdata_info(sdata,
  5718. "disconnect from AP %pM for new auth to %pM\n",
  5719. sdata->vif.cfg.ap_addr, auth_data->ap_addr);
  5720. ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
  5721. WLAN_REASON_UNSPECIFIED,
  5722. false, frame_buf);
  5723. ieee80211_report_disconnect(sdata, frame_buf,
  5724. sizeof(frame_buf), true,
  5725. WLAN_REASON_UNSPECIFIED,
  5726. false);
  5727. }
  5728. sdata_info(sdata, "authenticate with %pM\n", auth_data->ap_addr);
  5729. /* needed for transmitting the auth frame(s) properly */
  5730. memcpy(sdata->vif.cfg.ap_addr, auth_data->ap_addr, ETH_ALEN);
  5731. err = ieee80211_prep_connection(sdata, req->bss, req->link_id,
  5732. req->ap_mld_addr, cont_auth, false);
  5733. if (err)
  5734. goto err_clear;
  5735. err = ieee80211_auth(sdata);
  5736. if (err) {
  5737. sta_info_destroy_addr(sdata, auth_data->ap_addr);
  5738. goto err_clear;
  5739. }
  5740. /* hold our own reference */
  5741. cfg80211_ref_bss(local->hw.wiphy, auth_data->bss);
  5742. return 0;
  5743. err_clear:
  5744. if (!sdata->vif.valid_links) {
  5745. eth_zero_addr(sdata->deflink.u.mgd.bssid);
  5746. ieee80211_link_info_change_notify(sdata, &sdata->deflink,
  5747. BSS_CHANGED_BSSID);
  5748. mutex_lock(&sdata->local->mtx);
  5749. ieee80211_link_release_channel(&sdata->deflink);
  5750. mutex_unlock(&sdata->local->mtx);
  5751. }
  5752. ifmgd->auth_data = NULL;
  5753. kfree(auth_data);
  5754. return err;
  5755. }
  5756. static ieee80211_conn_flags_t
  5757. ieee80211_setup_assoc_link(struct ieee80211_sub_if_data *sdata,
  5758. struct ieee80211_mgd_assoc_data *assoc_data,
  5759. struct cfg80211_assoc_request *req,
  5760. ieee80211_conn_flags_t conn_flags,
  5761. unsigned int link_id)
  5762. {
  5763. struct ieee80211_local *local = sdata->local;
  5764. const struct cfg80211_bss_ies *beacon_ies;
  5765. struct ieee80211_supported_band *sband;
  5766. const struct element *ht_elem, *vht_elem;
  5767. struct ieee80211_link_data *link;
  5768. struct cfg80211_bss *cbss;
  5769. struct ieee80211_bss *bss;
  5770. bool is_5ghz, is_6ghz;
  5771. cbss = assoc_data->link[link_id].bss;
  5772. if (WARN_ON(!cbss))
  5773. return 0;
  5774. bss = (void *)cbss->priv;
  5775. sband = local->hw.wiphy->bands[cbss->channel->band];
  5776. if (WARN_ON(!sband))
  5777. return 0;
  5778. link = sdata_dereference(sdata->link[link_id], sdata);
  5779. if (WARN_ON(!link))
  5780. return 0;
  5781. is_5ghz = cbss->channel->band == NL80211_BAND_5GHZ;
  5782. is_6ghz = cbss->channel->band == NL80211_BAND_6GHZ;
  5783. /* for MLO connections assume advertising all rates is OK */
  5784. if (!req->ap_mld_addr) {
  5785. assoc_data->supp_rates = bss->supp_rates;
  5786. assoc_data->supp_rates_len = bss->supp_rates_len;
  5787. }
  5788. /* copy and link elems for the STA profile */
  5789. if (req->links[link_id].elems_len) {
  5790. memcpy(assoc_data->ie_pos, req->links[link_id].elems,
  5791. req->links[link_id].elems_len);
  5792. assoc_data->link[link_id].elems = assoc_data->ie_pos;
  5793. assoc_data->link[link_id].elems_len = req->links[link_id].elems_len;
  5794. assoc_data->ie_pos += req->links[link_id].elems_len;
  5795. }
  5796. rcu_read_lock();
  5797. ht_elem = ieee80211_bss_get_elem(cbss, WLAN_EID_HT_OPERATION);
  5798. if (ht_elem && ht_elem->datalen >= sizeof(struct ieee80211_ht_operation))
  5799. assoc_data->link[link_id].ap_ht_param =
  5800. ((struct ieee80211_ht_operation *)(ht_elem->data))->ht_param;
  5801. else if (!is_6ghz)
  5802. conn_flags |= IEEE80211_CONN_DISABLE_HT;
  5803. vht_elem = ieee80211_bss_get_elem(cbss, WLAN_EID_VHT_CAPABILITY);
  5804. if (vht_elem && vht_elem->datalen >= sizeof(struct ieee80211_vht_cap)) {
  5805. memcpy(&assoc_data->link[link_id].ap_vht_cap, vht_elem->data,
  5806. sizeof(struct ieee80211_vht_cap));
  5807. } else if (is_5ghz) {
  5808. link_info(link,
  5809. "VHT capa missing/short, disabling VHT/HE/EHT\n");
  5810. conn_flags |= IEEE80211_CONN_DISABLE_VHT |
  5811. IEEE80211_CONN_DISABLE_HE |
  5812. IEEE80211_CONN_DISABLE_EHT;
  5813. }
  5814. rcu_read_unlock();
  5815. link->u.mgd.beacon_crc_valid = false;
  5816. link->u.mgd.dtim_period = 0;
  5817. link->u.mgd.have_beacon = false;
  5818. /* override HT/VHT configuration only if the AP and we support it */
  5819. if (!(conn_flags & IEEE80211_CONN_DISABLE_HT)) {
  5820. struct ieee80211_sta_ht_cap sta_ht_cap;
  5821. memcpy(&sta_ht_cap, &sband->ht_cap, sizeof(sta_ht_cap));
  5822. ieee80211_apply_htcap_overrides(sdata, &sta_ht_cap);
  5823. }
  5824. rcu_read_lock();
  5825. beacon_ies = rcu_dereference(cbss->beacon_ies);
  5826. if (beacon_ies) {
  5827. const struct element *elem;
  5828. u8 dtim_count = 0;
  5829. ieee80211_get_dtim(beacon_ies, &dtim_count,
  5830. &link->u.mgd.dtim_period);
  5831. sdata->deflink.u.mgd.have_beacon = true;
  5832. if (ieee80211_hw_check(&local->hw, TIMING_BEACON_ONLY)) {
  5833. link->conf->sync_tsf = beacon_ies->tsf;
  5834. link->conf->sync_device_ts = bss->device_ts_beacon;
  5835. link->conf->sync_dtim_count = dtim_count;
  5836. }
  5837. elem = cfg80211_find_ext_elem(WLAN_EID_EXT_MULTIPLE_BSSID_CONFIGURATION,
  5838. beacon_ies->data, beacon_ies->len);
  5839. if (elem && elem->datalen >= 3)
  5840. link->conf->profile_periodicity = elem->data[2];
  5841. else
  5842. link->conf->profile_periodicity = 0;
  5843. elem = cfg80211_find_elem(WLAN_EID_EXT_CAPABILITY,
  5844. beacon_ies->data, beacon_ies->len);
  5845. if (elem && elem->datalen >= 11 &&
  5846. (elem->data[10] & WLAN_EXT_CAPA11_EMA_SUPPORT))
  5847. link->conf->ema_ap = true;
  5848. else
  5849. link->conf->ema_ap = false;
  5850. }
  5851. rcu_read_unlock();
  5852. if (bss->corrupt_data) {
  5853. char *corrupt_type = "data";
  5854. if (bss->corrupt_data & IEEE80211_BSS_CORRUPT_BEACON) {
  5855. if (bss->corrupt_data & IEEE80211_BSS_CORRUPT_PROBE_RESP)
  5856. corrupt_type = "beacon and probe response";
  5857. else
  5858. corrupt_type = "beacon";
  5859. } else if (bss->corrupt_data & IEEE80211_BSS_CORRUPT_PROBE_RESP) {
  5860. corrupt_type = "probe response";
  5861. }
  5862. sdata_info(sdata, "associating to AP %pM with corrupt %s\n",
  5863. cbss->bssid, corrupt_type);
  5864. }
  5865. if (link->u.mgd.req_smps == IEEE80211_SMPS_AUTOMATIC) {
  5866. if (sdata->u.mgd.powersave)
  5867. link->smps_mode = IEEE80211_SMPS_DYNAMIC;
  5868. else
  5869. link->smps_mode = IEEE80211_SMPS_OFF;
  5870. } else {
  5871. link->smps_mode = link->u.mgd.req_smps;
  5872. }
  5873. return conn_flags;
  5874. }
  5875. int ieee80211_mgd_assoc(struct ieee80211_sub_if_data *sdata,
  5876. struct cfg80211_assoc_request *req)
  5877. {
  5878. unsigned int assoc_link_id = req->link_id < 0 ? 0 : req->link_id;
  5879. struct ieee80211_local *local = sdata->local;
  5880. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  5881. struct ieee80211_mgd_assoc_data *assoc_data;
  5882. const struct element *ssid_elem;
  5883. struct ieee80211_vif_cfg *vif_cfg = &sdata->vif.cfg;
  5884. ieee80211_conn_flags_t conn_flags = 0;
  5885. struct ieee80211_link_data *link;
  5886. struct cfg80211_bss *cbss;
  5887. struct ieee80211_bss *bss;
  5888. bool override;
  5889. int i, err;
  5890. size_t size = sizeof(*assoc_data) + req->ie_len;
  5891. for (i = 0; i < IEEE80211_MLD_MAX_NUM_LINKS; i++)
  5892. size += req->links[i].elems_len;
  5893. /* FIXME: no support for 4-addr MLO yet */
  5894. if (sdata->u.mgd.use_4addr && req->link_id >= 0)
  5895. return -EOPNOTSUPP;
  5896. assoc_data = kzalloc(size, GFP_KERNEL);
  5897. if (!assoc_data)
  5898. return -ENOMEM;
  5899. cbss = req->link_id < 0 ? req->bss : req->links[req->link_id].bss;
  5900. rcu_read_lock();
  5901. ssid_elem = ieee80211_bss_get_elem(cbss, WLAN_EID_SSID);
  5902. if (!ssid_elem || ssid_elem->datalen > sizeof(assoc_data->ssid)) {
  5903. rcu_read_unlock();
  5904. kfree(assoc_data);
  5905. return -EINVAL;
  5906. }
  5907. memcpy(assoc_data->ssid, ssid_elem->data, ssid_elem->datalen);
  5908. assoc_data->ssid_len = ssid_elem->datalen;
  5909. memcpy(vif_cfg->ssid, assoc_data->ssid, assoc_data->ssid_len);
  5910. vif_cfg->ssid_len = assoc_data->ssid_len;
  5911. rcu_read_unlock();
  5912. if (req->ap_mld_addr) {
  5913. for (i = 0; i < IEEE80211_MLD_MAX_NUM_LINKS; i++) {
  5914. if (!req->links[i].bss)
  5915. continue;
  5916. link = sdata_dereference(sdata->link[i], sdata);
  5917. if (link)
  5918. ether_addr_copy(assoc_data->link[i].addr,
  5919. link->conf->addr);
  5920. else
  5921. eth_random_addr(assoc_data->link[i].addr);
  5922. }
  5923. } else {
  5924. memcpy(assoc_data->link[0].addr, sdata->vif.addr, ETH_ALEN);
  5925. }
  5926. assoc_data->s1g = cbss->channel->band == NL80211_BAND_S1GHZ;
  5927. memcpy(assoc_data->ap_addr,
  5928. req->ap_mld_addr ?: req->bss->bssid,
  5929. ETH_ALEN);
  5930. if (ifmgd->associated) {
  5931. u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
  5932. sdata_info(sdata,
  5933. "disconnect from AP %pM for new assoc to %pM\n",
  5934. sdata->vif.cfg.ap_addr, assoc_data->ap_addr);
  5935. ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
  5936. WLAN_REASON_UNSPECIFIED,
  5937. false, frame_buf);
  5938. ieee80211_report_disconnect(sdata, frame_buf,
  5939. sizeof(frame_buf), true,
  5940. WLAN_REASON_UNSPECIFIED,
  5941. false);
  5942. }
  5943. if (ifmgd->auth_data && !ifmgd->auth_data->done) {
  5944. err = -EBUSY;
  5945. goto err_free;
  5946. }
  5947. if (ifmgd->assoc_data) {
  5948. err = -EBUSY;
  5949. goto err_free;
  5950. }
  5951. if (ifmgd->auth_data) {
  5952. bool match;
  5953. /* keep sta info, bssid if matching */
  5954. match = ether_addr_equal(ifmgd->auth_data->ap_addr,
  5955. assoc_data->ap_addr) &&
  5956. ifmgd->auth_data->link_id == req->link_id;
  5957. ieee80211_destroy_auth_data(sdata, match);
  5958. }
  5959. /* prepare assoc data */
  5960. bss = (void *)cbss->priv;
  5961. assoc_data->wmm = bss->wmm_used &&
  5962. (local->hw.queues >= IEEE80211_NUM_ACS);
  5963. /*
  5964. * IEEE802.11n does not allow TKIP/WEP as pairwise ciphers in HT mode.
  5965. * We still associate in non-HT mode (11a/b/g) if any one of these
  5966. * ciphers is configured as pairwise.
  5967. * We can set this to true for non-11n hardware, that'll be checked
  5968. * separately along with the peer capabilities.
  5969. */
  5970. for (i = 0; i < req->crypto.n_ciphers_pairwise; i++) {
  5971. if (req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP40 ||
  5972. req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_TKIP ||
  5973. req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP104) {
  5974. conn_flags |= IEEE80211_CONN_DISABLE_HT;
  5975. conn_flags |= IEEE80211_CONN_DISABLE_VHT;
  5976. conn_flags |= IEEE80211_CONN_DISABLE_HE;
  5977. conn_flags |= IEEE80211_CONN_DISABLE_EHT;
  5978. netdev_info(sdata->dev,
  5979. "disabling HT/VHT/HE due to WEP/TKIP use\n");
  5980. }
  5981. }
  5982. /* also disable HT/VHT/HE/EHT if the AP doesn't use WMM */
  5983. if (!bss->wmm_used) {
  5984. conn_flags |= IEEE80211_CONN_DISABLE_HT;
  5985. conn_flags |= IEEE80211_CONN_DISABLE_VHT;
  5986. conn_flags |= IEEE80211_CONN_DISABLE_HE;
  5987. conn_flags |= IEEE80211_CONN_DISABLE_EHT;
  5988. netdev_info(sdata->dev,
  5989. "disabling HT/VHT/HE as WMM/QoS is not supported by the AP\n");
  5990. }
  5991. if (req->flags & ASSOC_REQ_DISABLE_HT) {
  5992. mlme_dbg(sdata, "HT disabled by flag, disabling HT/VHT/HE\n");
  5993. conn_flags |= IEEE80211_CONN_DISABLE_HT;
  5994. conn_flags |= IEEE80211_CONN_DISABLE_VHT;
  5995. conn_flags |= IEEE80211_CONN_DISABLE_HE;
  5996. conn_flags |= IEEE80211_CONN_DISABLE_EHT;
  5997. }
  5998. if (req->flags & ASSOC_REQ_DISABLE_VHT) {
  5999. mlme_dbg(sdata, "VHT disabled by flag, disabling VHT\n");
  6000. conn_flags |= IEEE80211_CONN_DISABLE_VHT;
  6001. }
  6002. if (req->flags & ASSOC_REQ_DISABLE_HE) {
  6003. mlme_dbg(sdata, "HE disabled by flag, disabling HE/EHT\n");
  6004. conn_flags |= IEEE80211_CONN_DISABLE_HE;
  6005. conn_flags |= IEEE80211_CONN_DISABLE_EHT;
  6006. }
  6007. if (req->flags & ASSOC_REQ_DISABLE_EHT)
  6008. conn_flags |= IEEE80211_CONN_DISABLE_EHT;
  6009. memcpy(&ifmgd->ht_capa, &req->ht_capa, sizeof(ifmgd->ht_capa));
  6010. memcpy(&ifmgd->ht_capa_mask, &req->ht_capa_mask,
  6011. sizeof(ifmgd->ht_capa_mask));
  6012. memcpy(&ifmgd->vht_capa, &req->vht_capa, sizeof(ifmgd->vht_capa));
  6013. memcpy(&ifmgd->vht_capa_mask, &req->vht_capa_mask,
  6014. sizeof(ifmgd->vht_capa_mask));
  6015. memcpy(&ifmgd->s1g_capa, &req->s1g_capa, sizeof(ifmgd->s1g_capa));
  6016. memcpy(&ifmgd->s1g_capa_mask, &req->s1g_capa_mask,
  6017. sizeof(ifmgd->s1g_capa_mask));
  6018. if (req->ie && req->ie_len) {
  6019. memcpy(assoc_data->ie, req->ie, req->ie_len);
  6020. assoc_data->ie_len = req->ie_len;
  6021. assoc_data->ie_pos = assoc_data->ie + assoc_data->ie_len;
  6022. } else {
  6023. assoc_data->ie_pos = assoc_data->ie;
  6024. }
  6025. if (req->fils_kek) {
  6026. /* should already be checked in cfg80211 - so warn */
  6027. if (WARN_ON(req->fils_kek_len > FILS_MAX_KEK_LEN)) {
  6028. err = -EINVAL;
  6029. goto err_free;
  6030. }
  6031. memcpy(assoc_data->fils_kek, req->fils_kek,
  6032. req->fils_kek_len);
  6033. assoc_data->fils_kek_len = req->fils_kek_len;
  6034. }
  6035. if (req->fils_nonces)
  6036. memcpy(assoc_data->fils_nonces, req->fils_nonces,
  6037. 2 * FILS_NONCE_LEN);
  6038. /* default timeout */
  6039. assoc_data->timeout = jiffies;
  6040. assoc_data->timeout_started = true;
  6041. assoc_data->assoc_link_id = assoc_link_id;
  6042. if (req->ap_mld_addr) {
  6043. for (i = 0; i < ARRAY_SIZE(assoc_data->link); i++) {
  6044. assoc_data->link[i].conn_flags = conn_flags;
  6045. assoc_data->link[i].bss = req->links[i].bss;
  6046. }
  6047. /* if there was no authentication, set up the link */
  6048. err = ieee80211_vif_set_links(sdata, BIT(assoc_link_id));
  6049. if (err)
  6050. goto err_clear;
  6051. } else {
  6052. assoc_data->link[0].conn_flags = conn_flags;
  6053. assoc_data->link[0].bss = cbss;
  6054. }
  6055. link = sdata_dereference(sdata->link[assoc_link_id], sdata);
  6056. if (WARN_ON(!link)) {
  6057. err = -EINVAL;
  6058. goto err_clear;
  6059. }
  6060. /* keep old conn_flags from ieee80211_prep_channel() from auth */
  6061. conn_flags |= link->u.mgd.conn_flags;
  6062. conn_flags |= ieee80211_setup_assoc_link(sdata, assoc_data, req,
  6063. conn_flags, assoc_link_id);
  6064. override = link->u.mgd.conn_flags != conn_flags;
  6065. link->u.mgd.conn_flags |= conn_flags;
  6066. if (WARN((sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_UAPSD) &&
  6067. ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK),
  6068. "U-APSD not supported with HW_PS_NULLFUNC_STACK\n"))
  6069. sdata->vif.driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD;
  6070. if (bss->wmm_used && bss->uapsd_supported &&
  6071. (sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_UAPSD)) {
  6072. assoc_data->uapsd = true;
  6073. ifmgd->flags |= IEEE80211_STA_UAPSD_ENABLED;
  6074. } else {
  6075. assoc_data->uapsd = false;
  6076. ifmgd->flags &= ~IEEE80211_STA_UAPSD_ENABLED;
  6077. }
  6078. if (req->prev_bssid)
  6079. memcpy(assoc_data->prev_ap_addr, req->prev_bssid, ETH_ALEN);
  6080. if (req->use_mfp) {
  6081. ifmgd->mfp = IEEE80211_MFP_REQUIRED;
  6082. ifmgd->flags |= IEEE80211_STA_MFP_ENABLED;
  6083. } else {
  6084. ifmgd->mfp = IEEE80211_MFP_DISABLED;
  6085. ifmgd->flags &= ~IEEE80211_STA_MFP_ENABLED;
  6086. }
  6087. if (req->flags & ASSOC_REQ_USE_RRM)
  6088. ifmgd->flags |= IEEE80211_STA_ENABLE_RRM;
  6089. else
  6090. ifmgd->flags &= ~IEEE80211_STA_ENABLE_RRM;
  6091. if (req->crypto.control_port)
  6092. ifmgd->flags |= IEEE80211_STA_CONTROL_PORT;
  6093. else
  6094. ifmgd->flags &= ~IEEE80211_STA_CONTROL_PORT;
  6095. sdata->control_port_protocol = req->crypto.control_port_ethertype;
  6096. sdata->control_port_no_encrypt = req->crypto.control_port_no_encrypt;
  6097. sdata->control_port_over_nl80211 =
  6098. req->crypto.control_port_over_nl80211;
  6099. sdata->control_port_no_preauth = req->crypto.control_port_no_preauth;
  6100. /* kick off associate process */
  6101. ifmgd->assoc_data = assoc_data;
  6102. for (i = 0; i < ARRAY_SIZE(assoc_data->link); i++) {
  6103. if (!assoc_data->link[i].bss)
  6104. continue;
  6105. if (i == assoc_data->assoc_link_id)
  6106. continue;
  6107. /* only calculate the flags, hence link == NULL */
  6108. err = ieee80211_prep_channel(sdata, NULL, assoc_data->link[i].bss,
  6109. &assoc_data->link[i].conn_flags);
  6110. if (err)
  6111. goto err_clear;
  6112. }
  6113. /* needed for transmitting the assoc frames properly */
  6114. memcpy(sdata->vif.cfg.ap_addr, assoc_data->ap_addr, ETH_ALEN);
  6115. err = ieee80211_prep_connection(sdata, cbss, req->link_id,
  6116. req->ap_mld_addr, true, override);
  6117. if (err)
  6118. goto err_clear;
  6119. assoc_data->link[assoc_data->assoc_link_id].conn_flags =
  6120. link->u.mgd.conn_flags;
  6121. if (ieee80211_hw_check(&sdata->local->hw, NEED_DTIM_BEFORE_ASSOC)) {
  6122. const struct cfg80211_bss_ies *beacon_ies;
  6123. rcu_read_lock();
  6124. beacon_ies = rcu_dereference(req->bss->beacon_ies);
  6125. if (beacon_ies) {
  6126. /*
  6127. * Wait up to one beacon interval ...
  6128. * should this be more if we miss one?
  6129. */
  6130. sdata_info(sdata, "waiting for beacon from %pM\n",
  6131. link->u.mgd.bssid);
  6132. assoc_data->timeout = TU_TO_EXP_TIME(req->bss->beacon_interval);
  6133. assoc_data->timeout_started = true;
  6134. assoc_data->need_beacon = true;
  6135. }
  6136. rcu_read_unlock();
  6137. }
  6138. run_again(sdata, assoc_data->timeout);
  6139. return 0;
  6140. err_clear:
  6141. eth_zero_addr(sdata->deflink.u.mgd.bssid);
  6142. ieee80211_link_info_change_notify(sdata, &sdata->deflink,
  6143. BSS_CHANGED_BSSID);
  6144. ifmgd->assoc_data = NULL;
  6145. err_free:
  6146. kfree(assoc_data);
  6147. return err;
  6148. }
  6149. int ieee80211_mgd_deauth(struct ieee80211_sub_if_data *sdata,
  6150. struct cfg80211_deauth_request *req)
  6151. {
  6152. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  6153. u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
  6154. bool tx = !req->local_state_change;
  6155. struct ieee80211_prep_tx_info info = {
  6156. .subtype = IEEE80211_STYPE_DEAUTH,
  6157. };
  6158. if (ifmgd->auth_data &&
  6159. ether_addr_equal(ifmgd->auth_data->ap_addr, req->bssid)) {
  6160. sdata_info(sdata,
  6161. "aborting authentication with %pM by local choice (Reason: %u=%s)\n",
  6162. req->bssid, req->reason_code,
  6163. ieee80211_get_reason_code_string(req->reason_code));
  6164. drv_mgd_prepare_tx(sdata->local, sdata, &info);
  6165. ieee80211_send_deauth_disassoc(sdata, req->bssid, req->bssid,
  6166. IEEE80211_STYPE_DEAUTH,
  6167. req->reason_code, tx,
  6168. frame_buf);
  6169. ieee80211_destroy_auth_data(sdata, false);
  6170. ieee80211_report_disconnect(sdata, frame_buf,
  6171. sizeof(frame_buf), true,
  6172. req->reason_code, false);
  6173. drv_mgd_complete_tx(sdata->local, sdata, &info);
  6174. return 0;
  6175. }
  6176. if (ifmgd->assoc_data &&
  6177. ether_addr_equal(ifmgd->assoc_data->ap_addr, req->bssid)) {
  6178. sdata_info(sdata,
  6179. "aborting association with %pM by local choice (Reason: %u=%s)\n",
  6180. req->bssid, req->reason_code,
  6181. ieee80211_get_reason_code_string(req->reason_code));
  6182. drv_mgd_prepare_tx(sdata->local, sdata, &info);
  6183. ieee80211_send_deauth_disassoc(sdata, req->bssid, req->bssid,
  6184. IEEE80211_STYPE_DEAUTH,
  6185. req->reason_code, tx,
  6186. frame_buf);
  6187. ieee80211_destroy_assoc_data(sdata, ASSOC_ABANDON);
  6188. ieee80211_report_disconnect(sdata, frame_buf,
  6189. sizeof(frame_buf), true,
  6190. req->reason_code, false);
  6191. return 0;
  6192. }
  6193. if (ifmgd->associated &&
  6194. ether_addr_equal(sdata->vif.cfg.ap_addr, req->bssid)) {
  6195. sdata_info(sdata,
  6196. "deauthenticating from %pM by local choice (Reason: %u=%s)\n",
  6197. req->bssid, req->reason_code,
  6198. ieee80211_get_reason_code_string(req->reason_code));
  6199. ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
  6200. req->reason_code, tx, frame_buf);
  6201. ieee80211_report_disconnect(sdata, frame_buf,
  6202. sizeof(frame_buf), true,
  6203. req->reason_code, false);
  6204. drv_mgd_complete_tx(sdata->local, sdata, &info);
  6205. return 0;
  6206. }
  6207. return -ENOTCONN;
  6208. }
  6209. int ieee80211_mgd_disassoc(struct ieee80211_sub_if_data *sdata,
  6210. struct cfg80211_disassoc_request *req)
  6211. {
  6212. u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
  6213. if (!sdata->u.mgd.associated ||
  6214. memcmp(sdata->vif.cfg.ap_addr, req->ap_addr, ETH_ALEN))
  6215. return -ENOTCONN;
  6216. sdata_info(sdata,
  6217. "disassociating from %pM by local choice (Reason: %u=%s)\n",
  6218. req->ap_addr, req->reason_code,
  6219. ieee80211_get_reason_code_string(req->reason_code));
  6220. ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DISASSOC,
  6221. req->reason_code, !req->local_state_change,
  6222. frame_buf);
  6223. ieee80211_report_disconnect(sdata, frame_buf, sizeof(frame_buf), true,
  6224. req->reason_code, false);
  6225. return 0;
  6226. }
  6227. void ieee80211_mgd_stop_link(struct ieee80211_link_data *link)
  6228. {
  6229. cancel_work_sync(&link->u.mgd.request_smps_work);
  6230. cancel_work_sync(&link->u.mgd.chswitch_work);
  6231. }
  6232. void ieee80211_mgd_stop(struct ieee80211_sub_if_data *sdata)
  6233. {
  6234. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  6235. /*
  6236. * Make sure some work items will not run after this,
  6237. * they will not do anything but might not have been
  6238. * cancelled when disconnecting.
  6239. */
  6240. cancel_work_sync(&ifmgd->monitor_work);
  6241. cancel_work_sync(&ifmgd->beacon_connection_loss_work);
  6242. cancel_work_sync(&ifmgd->csa_connection_drop_work);
  6243. cancel_delayed_work_sync(&ifmgd->tdls_peer_del_work);
  6244. sdata_lock(sdata);
  6245. if (ifmgd->assoc_data)
  6246. ieee80211_destroy_assoc_data(sdata, ASSOC_TIMEOUT);
  6247. if (ifmgd->auth_data)
  6248. ieee80211_destroy_auth_data(sdata, false);
  6249. spin_lock_bh(&ifmgd->teardown_lock);
  6250. if (ifmgd->teardown_skb) {
  6251. kfree_skb(ifmgd->teardown_skb);
  6252. ifmgd->teardown_skb = NULL;
  6253. ifmgd->orig_teardown_skb = NULL;
  6254. }
  6255. kfree(ifmgd->assoc_req_ies);
  6256. ifmgd->assoc_req_ies = NULL;
  6257. ifmgd->assoc_req_ies_len = 0;
  6258. spin_unlock_bh(&ifmgd->teardown_lock);
  6259. del_timer_sync(&ifmgd->timer);
  6260. sdata_unlock(sdata);
  6261. }
  6262. void ieee80211_cqm_rssi_notify(struct ieee80211_vif *vif,
  6263. enum nl80211_cqm_rssi_threshold_event rssi_event,
  6264. s32 rssi_level,
  6265. gfp_t gfp)
  6266. {
  6267. struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
  6268. trace_api_cqm_rssi_notify(sdata, rssi_event, rssi_level);
  6269. cfg80211_cqm_rssi_notify(sdata->dev, rssi_event, rssi_level, gfp);
  6270. }
  6271. EXPORT_SYMBOL(ieee80211_cqm_rssi_notify);
  6272. void ieee80211_cqm_beacon_loss_notify(struct ieee80211_vif *vif, gfp_t gfp)
  6273. {
  6274. struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
  6275. trace_api_cqm_beacon_loss_notify(sdata->local, sdata);
  6276. cfg80211_cqm_beacon_loss_notify(sdata->dev, gfp);
  6277. }
  6278. EXPORT_SYMBOL(ieee80211_cqm_beacon_loss_notify);
  6279. static void _ieee80211_enable_rssi_reports(struct ieee80211_sub_if_data *sdata,
  6280. int rssi_min_thold,
  6281. int rssi_max_thold)
  6282. {
  6283. trace_api_enable_rssi_reports(sdata, rssi_min_thold, rssi_max_thold);
  6284. if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
  6285. return;
  6286. /*
  6287. * Scale up threshold values before storing it, as the RSSI averaging
  6288. * algorithm uses a scaled up value as well. Change this scaling
  6289. * factor if the RSSI averaging algorithm changes.
  6290. */
  6291. sdata->u.mgd.rssi_min_thold = rssi_min_thold*16;
  6292. sdata->u.mgd.rssi_max_thold = rssi_max_thold*16;
  6293. }
  6294. void ieee80211_enable_rssi_reports(struct ieee80211_vif *vif,
  6295. int rssi_min_thold,
  6296. int rssi_max_thold)
  6297. {
  6298. struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
  6299. WARN_ON(rssi_min_thold == rssi_max_thold ||
  6300. rssi_min_thold > rssi_max_thold);
  6301. _ieee80211_enable_rssi_reports(sdata, rssi_min_thold,
  6302. rssi_max_thold);
  6303. }
  6304. EXPORT_SYMBOL(ieee80211_enable_rssi_reports);
  6305. void ieee80211_disable_rssi_reports(struct ieee80211_vif *vif)
  6306. {
  6307. struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
  6308. _ieee80211_enable_rssi_reports(sdata, 0, 0);
  6309. }
  6310. EXPORT_SYMBOL(ieee80211_disable_rssi_reports);