mlme.c 158 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493
  1. /*
  2. * BSS client mode implementation
  3. * Copyright 2003-2008, Jouni Malinen <j@w1.fi>
  4. * Copyright 2004, Instant802 Networks, Inc.
  5. * Copyright 2005, Devicescape Software, Inc.
  6. * Copyright 2006-2007 Jiri Benc <jbenc@suse.cz>
  7. * Copyright 2007, Michael Wu <flamingice@sourmilk.net>
  8. * Copyright 2013-2014 Intel Mobile Communications GmbH
  9. * Copyright (C) 2015 - 2017 Intel Deutschland GmbH
  10. * Copyright (C) 2018 Intel Corporation
  11. *
  12. * This program is free software; you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License version 2 as
  14. * published by the Free Software Foundation.
  15. */
  16. #include <linux/delay.h>
  17. #include <linux/if_ether.h>
  18. #include <linux/skbuff.h>
  19. #include <linux/if_arp.h>
  20. #include <linux/etherdevice.h>
  21. #include <linux/moduleparam.h>
  22. #include <linux/rtnetlink.h>
  23. #include <linux/crc32.h>
  24. #include <linux/slab.h>
  25. #include <linux/export.h>
  26. #include <net/mac80211.h>
  27. #include <asm/unaligned.h>
  28. #include "ieee80211_i.h"
  29. #include "driver-ops.h"
  30. #include "rate.h"
  31. #include "led.h"
  32. #include "fils_aead.h"
  33. #define IEEE80211_AUTH_TIMEOUT (HZ / 5)
  34. #define IEEE80211_AUTH_TIMEOUT_LONG (HZ / 2)
  35. #define IEEE80211_AUTH_TIMEOUT_SHORT (HZ / 10)
  36. #define IEEE80211_AUTH_TIMEOUT_SAE (HZ * 2)
  37. #define IEEE80211_AUTH_MAX_TRIES 3
  38. #define IEEE80211_AUTH_WAIT_ASSOC (HZ * 5)
  39. #define IEEE80211_ASSOC_TIMEOUT (HZ / 5)
  40. #define IEEE80211_ASSOC_TIMEOUT_LONG (HZ / 2)
  41. #define IEEE80211_ASSOC_TIMEOUT_SHORT (HZ / 10)
  42. #define IEEE80211_ASSOC_MAX_TRIES 3
  43. static int max_nullfunc_tries = 2;
  44. module_param(max_nullfunc_tries, int, 0644);
  45. MODULE_PARM_DESC(max_nullfunc_tries,
  46. "Maximum nullfunc tx tries before disconnecting (reason 4).");
  47. static int max_probe_tries = 5;
  48. module_param(max_probe_tries, int, 0644);
  49. MODULE_PARM_DESC(max_probe_tries,
  50. "Maximum probe tries before disconnecting (reason 4).");
  51. /*
  52. * Beacon loss timeout is calculated as N frames times the
  53. * advertised beacon interval. This may need to be somewhat
  54. * higher than what hardware might detect to account for
  55. * delays in the host processing frames. But since we also
  56. * probe on beacon miss before declaring the connection lost
  57. * default to what we want.
  58. */
  59. static int beacon_loss_count = 7;
  60. module_param(beacon_loss_count, int, 0644);
  61. MODULE_PARM_DESC(beacon_loss_count,
  62. "Number of beacon intervals before we decide beacon was lost.");
  63. /*
  64. * Time the connection can be idle before we probe
  65. * it to see if we can still talk to the AP.
  66. */
  67. #define IEEE80211_CONNECTION_IDLE_TIME (30 * HZ)
  68. /*
  69. * Time we wait for a probe response after sending
  70. * a probe request because of beacon loss or for
  71. * checking the connection still works.
  72. */
  73. static int probe_wait_ms = 500;
  74. module_param(probe_wait_ms, int, 0644);
  75. MODULE_PARM_DESC(probe_wait_ms,
  76. "Maximum time(ms) to wait for probe response"
  77. " before disconnecting (reason 4).");
  78. /*
  79. * How many Beacon frames need to have been used in average signal strength
  80. * before starting to indicate signal change events.
  81. */
  82. #define IEEE80211_SIGNAL_AVE_MIN_COUNT 4
  83. /*
  84. * We can have multiple work items (and connection probing)
  85. * scheduling this timer, but we need to take care to only
  86. * reschedule it when it should fire _earlier_ than it was
  87. * asked for before, or if it's not pending right now. This
  88. * function ensures that. Note that it then is required to
  89. * run this function for all timeouts after the first one
  90. * has happened -- the work that runs from this timer will
  91. * do that.
  92. */
  93. static void run_again(struct ieee80211_sub_if_data *sdata,
  94. unsigned long timeout)
  95. {
  96. sdata_assert_lock(sdata);
  97. if (!timer_pending(&sdata->u.mgd.timer) ||
  98. time_before(timeout, sdata->u.mgd.timer.expires))
  99. mod_timer(&sdata->u.mgd.timer, timeout);
  100. }
  101. void ieee80211_sta_reset_beacon_monitor(struct ieee80211_sub_if_data *sdata)
  102. {
  103. if (sdata->vif.driver_flags & IEEE80211_VIF_BEACON_FILTER)
  104. return;
  105. if (ieee80211_hw_check(&sdata->local->hw, CONNECTION_MONITOR))
  106. return;
  107. mod_timer(&sdata->u.mgd.bcn_mon_timer,
  108. round_jiffies_up(jiffies + sdata->u.mgd.beacon_timeout));
  109. }
  110. void ieee80211_sta_reset_conn_monitor(struct ieee80211_sub_if_data *sdata)
  111. {
  112. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  113. if (unlikely(!ifmgd->associated))
  114. return;
  115. if (ifmgd->probe_send_count)
  116. ifmgd->probe_send_count = 0;
  117. if (ieee80211_hw_check(&sdata->local->hw, CONNECTION_MONITOR))
  118. return;
  119. mod_timer(&ifmgd->conn_mon_timer,
  120. round_jiffies_up(jiffies + IEEE80211_CONNECTION_IDLE_TIME));
  121. }
  122. static int ecw2cw(int ecw)
  123. {
  124. return (1 << ecw) - 1;
  125. }
  126. static u32
  127. ieee80211_determine_chantype(struct ieee80211_sub_if_data *sdata,
  128. struct ieee80211_supported_band *sband,
  129. struct ieee80211_channel *channel,
  130. const struct ieee80211_ht_operation *ht_oper,
  131. const struct ieee80211_vht_operation *vht_oper,
  132. const struct ieee80211_he_operation *he_oper,
  133. struct cfg80211_chan_def *chandef, bool tracking)
  134. {
  135. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  136. struct cfg80211_chan_def vht_chandef;
  137. struct ieee80211_sta_ht_cap sta_ht_cap;
  138. u32 ht_cfreq, ret;
  139. memcpy(&sta_ht_cap, &sband->ht_cap, sizeof(sta_ht_cap));
  140. ieee80211_apply_htcap_overrides(sdata, &sta_ht_cap);
  141. chandef->chan = channel;
  142. chandef->width = NL80211_CHAN_WIDTH_20_NOHT;
  143. chandef->center_freq1 = channel->center_freq;
  144. chandef->center_freq2 = 0;
  145. if (!ht_oper || !sta_ht_cap.ht_supported) {
  146. ret = IEEE80211_STA_DISABLE_HT | IEEE80211_STA_DISABLE_VHT;
  147. goto out;
  148. }
  149. chandef->width = NL80211_CHAN_WIDTH_20;
  150. ht_cfreq = ieee80211_channel_to_frequency(ht_oper->primary_chan,
  151. channel->band);
  152. /* check that channel matches the right operating channel */
  153. if (!tracking && channel->center_freq != ht_cfreq) {
  154. /*
  155. * It's possible that some APs are confused here;
  156. * Netgear WNDR3700 sometimes reports 4 higher than
  157. * the actual channel in association responses, but
  158. * since we look at probe response/beacon data here
  159. * it should be OK.
  160. */
  161. sdata_info(sdata,
  162. "Wrong control channel: center-freq: %d ht-cfreq: %d ht->primary_chan: %d band: %d - Disabling HT\n",
  163. channel->center_freq, ht_cfreq,
  164. ht_oper->primary_chan, channel->band);
  165. ret = IEEE80211_STA_DISABLE_HT | IEEE80211_STA_DISABLE_VHT;
  166. goto out;
  167. }
  168. /* check 40 MHz support, if we have it */
  169. if (sta_ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40) {
  170. ieee80211_chandef_ht_oper(ht_oper, chandef);
  171. } else {
  172. /* 40 MHz (and 80 MHz) must be supported for VHT */
  173. ret = IEEE80211_STA_DISABLE_VHT;
  174. /* also mark 40 MHz disabled */
  175. ret |= IEEE80211_STA_DISABLE_40MHZ;
  176. goto out;
  177. }
  178. if (!vht_oper || !sband->vht_cap.vht_supported) {
  179. ret = IEEE80211_STA_DISABLE_VHT;
  180. goto out;
  181. }
  182. vht_chandef = *chandef;
  183. if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HE) && he_oper &&
  184. (le32_to_cpu(he_oper->he_oper_params) &
  185. IEEE80211_HE_OPERATION_VHT_OPER_INFO)) {
  186. struct ieee80211_vht_operation he_oper_vht_cap;
  187. /*
  188. * Set only first 3 bytes (other 2 aren't used in
  189. * ieee80211_chandef_vht_oper() anyway)
  190. */
  191. memcpy(&he_oper_vht_cap, he_oper->optional, 3);
  192. he_oper_vht_cap.basic_mcs_set = cpu_to_le16(0);
  193. if (!ieee80211_chandef_vht_oper(&he_oper_vht_cap,
  194. &vht_chandef)) {
  195. if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HE))
  196. sdata_info(sdata,
  197. "HE AP VHT information is invalid, disable HE\n");
  198. ret = IEEE80211_STA_DISABLE_HE;
  199. goto out;
  200. }
  201. } else if (!ieee80211_chandef_vht_oper(vht_oper, &vht_chandef)) {
  202. if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT))
  203. sdata_info(sdata,
  204. "AP VHT information is invalid, disable VHT\n");
  205. ret = IEEE80211_STA_DISABLE_VHT;
  206. goto out;
  207. }
  208. if (!cfg80211_chandef_valid(&vht_chandef)) {
  209. if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT))
  210. sdata_info(sdata,
  211. "AP VHT information is invalid, disable VHT\n");
  212. ret = IEEE80211_STA_DISABLE_VHT;
  213. goto out;
  214. }
  215. if (cfg80211_chandef_identical(chandef, &vht_chandef)) {
  216. ret = 0;
  217. goto out;
  218. }
  219. if (!cfg80211_chandef_compatible(chandef, &vht_chandef)) {
  220. if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT))
  221. sdata_info(sdata,
  222. "AP VHT information doesn't match HT, disable VHT\n");
  223. ret = IEEE80211_STA_DISABLE_VHT;
  224. goto out;
  225. }
  226. *chandef = vht_chandef;
  227. ret = 0;
  228. out:
  229. /*
  230. * When tracking the current AP, don't do any further checks if the
  231. * new chandef is identical to the one we're currently using for the
  232. * connection. This keeps us from playing ping-pong with regulatory,
  233. * without it the following can happen (for example):
  234. * - connect to an AP with 80 MHz, world regdom allows 80 MHz
  235. * - AP advertises regdom US
  236. * - CRDA loads regdom US with 80 MHz prohibited (old database)
  237. * - the code below detects an unsupported channel, downgrades, and
  238. * we disconnect from the AP in the caller
  239. * - disconnect causes CRDA to reload world regdomain and the game
  240. * starts anew.
  241. * (see https://bugzilla.kernel.org/show_bug.cgi?id=70881)
  242. *
  243. * It seems possible that there are still scenarios with CSA or real
  244. * bandwidth changes where a this could happen, but those cases are
  245. * less common and wouldn't completely prevent using the AP.
  246. */
  247. if (tracking &&
  248. cfg80211_chandef_identical(chandef, &sdata->vif.bss_conf.chandef))
  249. return ret;
  250. /* don't print the message below for VHT mismatch if VHT is disabled */
  251. if (ret & IEEE80211_STA_DISABLE_VHT)
  252. vht_chandef = *chandef;
  253. /*
  254. * Ignore the DISABLED flag when we're already connected and only
  255. * tracking the APs beacon for bandwidth changes - otherwise we
  256. * might get disconnected here if we connect to an AP, update our
  257. * regulatory information based on the AP's country IE and the
  258. * information we have is wrong/outdated and disables the channel
  259. * that we're actually using for the connection to the AP.
  260. */
  261. while (!cfg80211_chandef_usable(sdata->local->hw.wiphy, chandef,
  262. tracking ? 0 :
  263. IEEE80211_CHAN_DISABLED)) {
  264. if (WARN_ON(chandef->width == NL80211_CHAN_WIDTH_20_NOHT)) {
  265. ret = IEEE80211_STA_DISABLE_HT |
  266. IEEE80211_STA_DISABLE_VHT;
  267. break;
  268. }
  269. ret |= ieee80211_chandef_downgrade(chandef);
  270. }
  271. if (chandef->width != vht_chandef.width && !tracking)
  272. sdata_info(sdata,
  273. "capabilities/regulatory prevented using AP HT/VHT configuration, downgraded\n");
  274. WARN_ON_ONCE(!cfg80211_chandef_valid(chandef));
  275. return ret;
  276. }
  277. static int ieee80211_config_bw(struct ieee80211_sub_if_data *sdata,
  278. struct sta_info *sta,
  279. const struct ieee80211_ht_cap *ht_cap,
  280. const struct ieee80211_ht_operation *ht_oper,
  281. const struct ieee80211_vht_operation *vht_oper,
  282. const struct ieee80211_he_operation *he_oper,
  283. const u8 *bssid, u32 *changed)
  284. {
  285. struct ieee80211_local *local = sdata->local;
  286. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  287. struct ieee80211_channel *chan = sdata->vif.bss_conf.chandef.chan;
  288. struct ieee80211_supported_band *sband =
  289. local->hw.wiphy->bands[chan->band];
  290. struct cfg80211_chan_def chandef;
  291. u16 ht_opmode;
  292. u32 flags;
  293. enum ieee80211_sta_rx_bandwidth new_sta_bw;
  294. int ret;
  295. /* if HT was/is disabled, don't track any bandwidth changes */
  296. if (ifmgd->flags & IEEE80211_STA_DISABLE_HT || !ht_oper)
  297. return 0;
  298. /* don't check VHT if we associated as non-VHT station */
  299. if (ifmgd->flags & IEEE80211_STA_DISABLE_VHT)
  300. vht_oper = NULL;
  301. /* don't check HE if we associated as non-HE station */
  302. if (ifmgd->flags & IEEE80211_STA_DISABLE_HE ||
  303. !ieee80211_get_he_sta_cap(sband))
  304. he_oper = NULL;
  305. if (WARN_ON_ONCE(!sta))
  306. return -EINVAL;
  307. /*
  308. * if bss configuration changed store the new one -
  309. * this may be applicable even if channel is identical
  310. */
  311. ht_opmode = le16_to_cpu(ht_oper->operation_mode);
  312. if (sdata->vif.bss_conf.ht_operation_mode != ht_opmode) {
  313. *changed |= BSS_CHANGED_HT;
  314. sdata->vif.bss_conf.ht_operation_mode = ht_opmode;
  315. }
  316. /* calculate new channel (type) based on HT/VHT/HE operation IEs */
  317. flags = ieee80211_determine_chantype(sdata, sband, chan,
  318. ht_oper, vht_oper, he_oper,
  319. &chandef, true);
  320. /*
  321. * Downgrade the new channel if we associated with restricted
  322. * capabilities. For example, if we associated as a 20 MHz STA
  323. * to a 40 MHz AP (due to regulatory, capabilities or config
  324. * reasons) then switching to a 40 MHz channel now won't do us
  325. * any good -- we couldn't use it with the AP.
  326. */
  327. if (ifmgd->flags & IEEE80211_STA_DISABLE_80P80MHZ &&
  328. chandef.width == NL80211_CHAN_WIDTH_80P80)
  329. flags |= ieee80211_chandef_downgrade(&chandef);
  330. if (ifmgd->flags & IEEE80211_STA_DISABLE_160MHZ &&
  331. chandef.width == NL80211_CHAN_WIDTH_160)
  332. flags |= ieee80211_chandef_downgrade(&chandef);
  333. if (ifmgd->flags & IEEE80211_STA_DISABLE_40MHZ &&
  334. chandef.width > NL80211_CHAN_WIDTH_20)
  335. flags |= ieee80211_chandef_downgrade(&chandef);
  336. if (cfg80211_chandef_identical(&chandef, &sdata->vif.bss_conf.chandef))
  337. return 0;
  338. sdata_info(sdata,
  339. "AP %pM changed bandwidth, new config is %d MHz, width %d (%d/%d MHz)\n",
  340. ifmgd->bssid, chandef.chan->center_freq, chandef.width,
  341. chandef.center_freq1, chandef.center_freq2);
  342. if (flags != (ifmgd->flags & (IEEE80211_STA_DISABLE_HT |
  343. IEEE80211_STA_DISABLE_VHT |
  344. IEEE80211_STA_DISABLE_40MHZ |
  345. IEEE80211_STA_DISABLE_80P80MHZ |
  346. IEEE80211_STA_DISABLE_160MHZ)) ||
  347. !cfg80211_chandef_valid(&chandef)) {
  348. sdata_info(sdata,
  349. "AP %pM changed bandwidth in a way we can't support - disconnect\n",
  350. ifmgd->bssid);
  351. return -EINVAL;
  352. }
  353. switch (chandef.width) {
  354. case NL80211_CHAN_WIDTH_20_NOHT:
  355. case NL80211_CHAN_WIDTH_20:
  356. new_sta_bw = IEEE80211_STA_RX_BW_20;
  357. break;
  358. case NL80211_CHAN_WIDTH_40:
  359. new_sta_bw = IEEE80211_STA_RX_BW_40;
  360. break;
  361. case NL80211_CHAN_WIDTH_80:
  362. new_sta_bw = IEEE80211_STA_RX_BW_80;
  363. break;
  364. case NL80211_CHAN_WIDTH_80P80:
  365. case NL80211_CHAN_WIDTH_160:
  366. new_sta_bw = IEEE80211_STA_RX_BW_160;
  367. break;
  368. default:
  369. return -EINVAL;
  370. }
  371. if (new_sta_bw > sta->cur_max_bandwidth)
  372. new_sta_bw = sta->cur_max_bandwidth;
  373. if (new_sta_bw < sta->sta.bandwidth) {
  374. sta->sta.bandwidth = new_sta_bw;
  375. rate_control_rate_update(local, sband, sta,
  376. IEEE80211_RC_BW_CHANGED);
  377. }
  378. ret = ieee80211_vif_change_bandwidth(sdata, &chandef, changed);
  379. if (ret) {
  380. sdata_info(sdata,
  381. "AP %pM changed bandwidth to incompatible one - disconnect\n",
  382. ifmgd->bssid);
  383. return ret;
  384. }
  385. if (new_sta_bw > sta->sta.bandwidth) {
  386. sta->sta.bandwidth = new_sta_bw;
  387. rate_control_rate_update(local, sband, sta,
  388. IEEE80211_RC_BW_CHANGED);
  389. }
  390. return 0;
  391. }
  392. /* frame sending functions */
  393. static void ieee80211_add_ht_ie(struct ieee80211_sub_if_data *sdata,
  394. struct sk_buff *skb, u8 ap_ht_param,
  395. struct ieee80211_supported_band *sband,
  396. struct ieee80211_channel *channel,
  397. enum ieee80211_smps_mode smps)
  398. {
  399. u8 *pos;
  400. u32 flags = channel->flags;
  401. u16 cap;
  402. struct ieee80211_sta_ht_cap ht_cap;
  403. BUILD_BUG_ON(sizeof(ht_cap) != sizeof(sband->ht_cap));
  404. memcpy(&ht_cap, &sband->ht_cap, sizeof(ht_cap));
  405. ieee80211_apply_htcap_overrides(sdata, &ht_cap);
  406. /* determine capability flags */
  407. cap = ht_cap.cap;
  408. switch (ap_ht_param & IEEE80211_HT_PARAM_CHA_SEC_OFFSET) {
  409. case IEEE80211_HT_PARAM_CHA_SEC_ABOVE:
  410. if (flags & IEEE80211_CHAN_NO_HT40PLUS) {
  411. cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
  412. cap &= ~IEEE80211_HT_CAP_SGI_40;
  413. }
  414. break;
  415. case IEEE80211_HT_PARAM_CHA_SEC_BELOW:
  416. if (flags & IEEE80211_CHAN_NO_HT40MINUS) {
  417. cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
  418. cap &= ~IEEE80211_HT_CAP_SGI_40;
  419. }
  420. break;
  421. }
  422. /*
  423. * If 40 MHz was disabled associate as though we weren't
  424. * capable of 40 MHz -- some broken APs will never fall
  425. * back to trying to transmit in 20 MHz.
  426. */
  427. if (sdata->u.mgd.flags & IEEE80211_STA_DISABLE_40MHZ) {
  428. cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
  429. cap &= ~IEEE80211_HT_CAP_SGI_40;
  430. }
  431. /* set SM PS mode properly */
  432. cap &= ~IEEE80211_HT_CAP_SM_PS;
  433. switch (smps) {
  434. case IEEE80211_SMPS_AUTOMATIC:
  435. case IEEE80211_SMPS_NUM_MODES:
  436. WARN_ON(1);
  437. /* fall through */
  438. case IEEE80211_SMPS_OFF:
  439. cap |= WLAN_HT_CAP_SM_PS_DISABLED <<
  440. IEEE80211_HT_CAP_SM_PS_SHIFT;
  441. break;
  442. case IEEE80211_SMPS_STATIC:
  443. cap |= WLAN_HT_CAP_SM_PS_STATIC <<
  444. IEEE80211_HT_CAP_SM_PS_SHIFT;
  445. break;
  446. case IEEE80211_SMPS_DYNAMIC:
  447. cap |= WLAN_HT_CAP_SM_PS_DYNAMIC <<
  448. IEEE80211_HT_CAP_SM_PS_SHIFT;
  449. break;
  450. }
  451. /* reserve and fill IE */
  452. pos = skb_put(skb, sizeof(struct ieee80211_ht_cap) + 2);
  453. ieee80211_ie_build_ht_cap(pos, &ht_cap, cap);
  454. }
  455. /* This function determines vht capability flags for the association
  456. * and builds the IE.
  457. * Note - the function may set the owner of the MU-MIMO capability
  458. */
  459. static void ieee80211_add_vht_ie(struct ieee80211_sub_if_data *sdata,
  460. struct sk_buff *skb,
  461. struct ieee80211_supported_band *sband,
  462. struct ieee80211_vht_cap *ap_vht_cap)
  463. {
  464. struct ieee80211_local *local = sdata->local;
  465. u8 *pos;
  466. u32 cap;
  467. struct ieee80211_sta_vht_cap vht_cap;
  468. u32 mask, ap_bf_sts, our_bf_sts;
  469. BUILD_BUG_ON(sizeof(vht_cap) != sizeof(sband->vht_cap));
  470. memcpy(&vht_cap, &sband->vht_cap, sizeof(vht_cap));
  471. ieee80211_apply_vhtcap_overrides(sdata, &vht_cap);
  472. /* determine capability flags */
  473. cap = vht_cap.cap;
  474. if (sdata->u.mgd.flags & IEEE80211_STA_DISABLE_80P80MHZ) {
  475. u32 bw = cap & IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK;
  476. cap &= ~IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK;
  477. if (bw == IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ ||
  478. bw == IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160_80PLUS80MHZ)
  479. cap |= IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
  480. }
  481. if (sdata->u.mgd.flags & IEEE80211_STA_DISABLE_160MHZ) {
  482. cap &= ~IEEE80211_VHT_CAP_SHORT_GI_160;
  483. cap &= ~IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_MASK;
  484. }
  485. /*
  486. * Some APs apparently get confused if our capabilities are better
  487. * than theirs, so restrict what we advertise in the assoc request.
  488. */
  489. if (!(ap_vht_cap->vht_cap_info &
  490. cpu_to_le32(IEEE80211_VHT_CAP_SU_BEAMFORMER_CAPABLE)))
  491. cap &= ~(IEEE80211_VHT_CAP_SU_BEAMFORMEE_CAPABLE |
  492. IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE);
  493. else if (!(ap_vht_cap->vht_cap_info &
  494. cpu_to_le32(IEEE80211_VHT_CAP_MU_BEAMFORMER_CAPABLE)))
  495. cap &= ~IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
  496. /*
  497. * If some other vif is using the MU-MIMO capablity we cannot associate
  498. * using MU-MIMO - this will lead to contradictions in the group-id
  499. * mechanism.
  500. * Ownership is defined since association request, in order to avoid
  501. * simultaneous associations with MU-MIMO.
  502. */
  503. if (cap & IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE) {
  504. bool disable_mu_mimo = false;
  505. struct ieee80211_sub_if_data *other;
  506. list_for_each_entry_rcu(other, &local->interfaces, list) {
  507. if (other->vif.mu_mimo_owner) {
  508. disable_mu_mimo = true;
  509. break;
  510. }
  511. }
  512. if (disable_mu_mimo)
  513. cap &= ~IEEE80211_VHT_CAP_MU_BEAMFORMEE_CAPABLE;
  514. else
  515. sdata->vif.mu_mimo_owner = true;
  516. }
  517. mask = IEEE80211_VHT_CAP_BEAMFORMEE_STS_MASK;
  518. ap_bf_sts = le32_to_cpu(ap_vht_cap->vht_cap_info) & mask;
  519. our_bf_sts = cap & mask;
  520. if (ap_bf_sts < our_bf_sts) {
  521. cap &= ~mask;
  522. cap |= ap_bf_sts;
  523. }
  524. /* reserve and fill IE */
  525. pos = skb_put(skb, sizeof(struct ieee80211_vht_cap) + 2);
  526. ieee80211_ie_build_vht_cap(pos, &vht_cap, cap);
  527. }
  528. /* This function determines HE capability flags for the association
  529. * and builds the IE.
  530. */
  531. static void ieee80211_add_he_ie(struct ieee80211_sub_if_data *sdata,
  532. struct sk_buff *skb,
  533. struct ieee80211_supported_band *sband)
  534. {
  535. u8 *pos;
  536. const struct ieee80211_sta_he_cap *he_cap = NULL;
  537. u8 he_cap_size;
  538. he_cap = ieee80211_get_he_sta_cap(sband);
  539. if (!he_cap)
  540. return;
  541. /*
  542. * TODO: the 1 added is because this temporarily is under the EXTENSION
  543. * IE. Get rid of it when it moves.
  544. */
  545. he_cap_size =
  546. 2 + 1 + sizeof(he_cap->he_cap_elem) +
  547. ieee80211_he_mcs_nss_size(&he_cap->he_cap_elem) +
  548. ieee80211_he_ppe_size(he_cap->ppe_thres[0],
  549. he_cap->he_cap_elem.phy_cap_info);
  550. pos = skb_put(skb, he_cap_size);
  551. ieee80211_ie_build_he_cap(pos, he_cap, pos + he_cap_size);
  552. }
  553. static void ieee80211_send_assoc(struct ieee80211_sub_if_data *sdata)
  554. {
  555. struct ieee80211_local *local = sdata->local;
  556. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  557. struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;
  558. struct sk_buff *skb;
  559. struct ieee80211_mgmt *mgmt;
  560. u8 *pos, qos_info;
  561. size_t offset = 0, noffset;
  562. int i, count, rates_len, supp_rates_len, shift;
  563. u16 capab;
  564. struct ieee80211_supported_band *sband;
  565. struct ieee80211_chanctx_conf *chanctx_conf;
  566. struct ieee80211_channel *chan;
  567. u32 rates = 0;
  568. sdata_assert_lock(sdata);
  569. rcu_read_lock();
  570. chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
  571. if (WARN_ON(!chanctx_conf)) {
  572. rcu_read_unlock();
  573. return;
  574. }
  575. chan = chanctx_conf->def.chan;
  576. rcu_read_unlock();
  577. sband = local->hw.wiphy->bands[chan->band];
  578. shift = ieee80211_vif_get_shift(&sdata->vif);
  579. if (assoc_data->supp_rates_len) {
  580. /*
  581. * Get all rates supported by the device and the AP as
  582. * some APs don't like getting a superset of their rates
  583. * in the association request (e.g. D-Link DAP 1353 in
  584. * b-only mode)...
  585. */
  586. rates_len = ieee80211_parse_bitrates(&chanctx_conf->def, sband,
  587. assoc_data->supp_rates,
  588. assoc_data->supp_rates_len,
  589. &rates);
  590. } else {
  591. /*
  592. * In case AP not provide any supported rates information
  593. * before association, we send information element(s) with
  594. * all rates that we support.
  595. */
  596. rates_len = 0;
  597. for (i = 0; i < sband->n_bitrates; i++) {
  598. rates |= BIT(i);
  599. rates_len++;
  600. }
  601. }
  602. skb = alloc_skb(local->hw.extra_tx_headroom +
  603. sizeof(*mgmt) + /* bit too much but doesn't matter */
  604. 2 + assoc_data->ssid_len + /* SSID */
  605. 4 + rates_len + /* (extended) rates */
  606. 4 + /* power capability */
  607. 2 + 2 * sband->n_channels + /* supported channels */
  608. 2 + sizeof(struct ieee80211_ht_cap) + /* HT */
  609. 2 + sizeof(struct ieee80211_vht_cap) + /* VHT */
  610. 2 + 1 + sizeof(struct ieee80211_he_cap_elem) + /* HE */
  611. sizeof(struct ieee80211_he_mcs_nss_supp) +
  612. IEEE80211_HE_PPE_THRES_MAX_LEN +
  613. assoc_data->ie_len + /* extra IEs */
  614. (assoc_data->fils_kek_len ? 16 /* AES-SIV */ : 0) +
  615. 9, /* WMM */
  616. GFP_KERNEL);
  617. if (!skb)
  618. return;
  619. skb_reserve(skb, local->hw.extra_tx_headroom);
  620. capab = WLAN_CAPABILITY_ESS;
  621. if (sband->band == NL80211_BAND_2GHZ) {
  622. capab |= WLAN_CAPABILITY_SHORT_SLOT_TIME;
  623. capab |= WLAN_CAPABILITY_SHORT_PREAMBLE;
  624. }
  625. if (assoc_data->capability & WLAN_CAPABILITY_PRIVACY)
  626. capab |= WLAN_CAPABILITY_PRIVACY;
  627. if ((assoc_data->capability & WLAN_CAPABILITY_SPECTRUM_MGMT) &&
  628. ieee80211_hw_check(&local->hw, SPECTRUM_MGMT))
  629. capab |= WLAN_CAPABILITY_SPECTRUM_MGMT;
  630. if (ifmgd->flags & IEEE80211_STA_ENABLE_RRM)
  631. capab |= WLAN_CAPABILITY_RADIO_MEASURE;
  632. mgmt = skb_put_zero(skb, 24);
  633. memcpy(mgmt->da, assoc_data->bss->bssid, ETH_ALEN);
  634. memcpy(mgmt->sa, sdata->vif.addr, ETH_ALEN);
  635. memcpy(mgmt->bssid, assoc_data->bss->bssid, ETH_ALEN);
  636. if (!is_zero_ether_addr(assoc_data->prev_bssid)) {
  637. skb_put(skb, 10);
  638. mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
  639. IEEE80211_STYPE_REASSOC_REQ);
  640. mgmt->u.reassoc_req.capab_info = cpu_to_le16(capab);
  641. mgmt->u.reassoc_req.listen_interval =
  642. cpu_to_le16(local->hw.conf.listen_interval);
  643. memcpy(mgmt->u.reassoc_req.current_ap, assoc_data->prev_bssid,
  644. ETH_ALEN);
  645. } else {
  646. skb_put(skb, 4);
  647. mgmt->frame_control = cpu_to_le16(IEEE80211_FTYPE_MGMT |
  648. IEEE80211_STYPE_ASSOC_REQ);
  649. mgmt->u.assoc_req.capab_info = cpu_to_le16(capab);
  650. mgmt->u.assoc_req.listen_interval =
  651. cpu_to_le16(local->hw.conf.listen_interval);
  652. }
  653. /* SSID */
  654. pos = skb_put(skb, 2 + assoc_data->ssid_len);
  655. *pos++ = WLAN_EID_SSID;
  656. *pos++ = assoc_data->ssid_len;
  657. memcpy(pos, assoc_data->ssid, assoc_data->ssid_len);
  658. /* add all rates which were marked to be used above */
  659. supp_rates_len = rates_len;
  660. if (supp_rates_len > 8)
  661. supp_rates_len = 8;
  662. pos = skb_put(skb, supp_rates_len + 2);
  663. *pos++ = WLAN_EID_SUPP_RATES;
  664. *pos++ = supp_rates_len;
  665. count = 0;
  666. for (i = 0; i < sband->n_bitrates; i++) {
  667. if (BIT(i) & rates) {
  668. int rate = DIV_ROUND_UP(sband->bitrates[i].bitrate,
  669. 5 * (1 << shift));
  670. *pos++ = (u8) rate;
  671. if (++count == 8)
  672. break;
  673. }
  674. }
  675. if (rates_len > count) {
  676. pos = skb_put(skb, rates_len - count + 2);
  677. *pos++ = WLAN_EID_EXT_SUPP_RATES;
  678. *pos++ = rates_len - count;
  679. for (i++; i < sband->n_bitrates; i++) {
  680. if (BIT(i) & rates) {
  681. int rate;
  682. rate = DIV_ROUND_UP(sband->bitrates[i].bitrate,
  683. 5 * (1 << shift));
  684. *pos++ = (u8) rate;
  685. }
  686. }
  687. }
  688. if (capab & WLAN_CAPABILITY_SPECTRUM_MGMT ||
  689. capab & WLAN_CAPABILITY_RADIO_MEASURE) {
  690. pos = skb_put(skb, 4);
  691. *pos++ = WLAN_EID_PWR_CAPABILITY;
  692. *pos++ = 2;
  693. *pos++ = 0; /* min tx power */
  694. /* max tx power */
  695. *pos++ = ieee80211_chandef_max_power(&chanctx_conf->def);
  696. }
  697. if (capab & WLAN_CAPABILITY_SPECTRUM_MGMT) {
  698. /* TODO: get this in reg domain format */
  699. pos = skb_put(skb, 2 * sband->n_channels + 2);
  700. *pos++ = WLAN_EID_SUPPORTED_CHANNELS;
  701. *pos++ = 2 * sband->n_channels;
  702. for (i = 0; i < sband->n_channels; i++) {
  703. *pos++ = ieee80211_frequency_to_channel(
  704. sband->channels[i].center_freq);
  705. *pos++ = 1; /* one channel in the subband*/
  706. }
  707. }
  708. /* if present, add any custom IEs that go before HT */
  709. if (assoc_data->ie_len) {
  710. static const u8 before_ht[] = {
  711. WLAN_EID_SSID,
  712. WLAN_EID_SUPP_RATES,
  713. WLAN_EID_EXT_SUPP_RATES,
  714. WLAN_EID_PWR_CAPABILITY,
  715. WLAN_EID_SUPPORTED_CHANNELS,
  716. WLAN_EID_RSN,
  717. WLAN_EID_QOS_CAPA,
  718. WLAN_EID_RRM_ENABLED_CAPABILITIES,
  719. WLAN_EID_MOBILITY_DOMAIN,
  720. WLAN_EID_FAST_BSS_TRANSITION, /* reassoc only */
  721. WLAN_EID_RIC_DATA, /* reassoc only */
  722. WLAN_EID_SUPPORTED_REGULATORY_CLASSES,
  723. };
  724. static const u8 after_ric[] = {
  725. WLAN_EID_SUPPORTED_REGULATORY_CLASSES,
  726. WLAN_EID_HT_CAPABILITY,
  727. WLAN_EID_BSS_COEX_2040,
  728. /* luckily this is almost always there */
  729. WLAN_EID_EXT_CAPABILITY,
  730. WLAN_EID_QOS_TRAFFIC_CAPA,
  731. WLAN_EID_TIM_BCAST_REQ,
  732. WLAN_EID_INTERWORKING,
  733. /* 60 GHz (Multi-band, DMG, MMS) can't happen */
  734. WLAN_EID_VHT_CAPABILITY,
  735. WLAN_EID_OPMODE_NOTIF,
  736. };
  737. noffset = ieee80211_ie_split_ric(assoc_data->ie,
  738. assoc_data->ie_len,
  739. before_ht,
  740. ARRAY_SIZE(before_ht),
  741. after_ric,
  742. ARRAY_SIZE(after_ric),
  743. offset);
  744. skb_put_data(skb, assoc_data->ie + offset, noffset - offset);
  745. offset = noffset;
  746. }
  747. if (WARN_ON_ONCE((ifmgd->flags & IEEE80211_STA_DISABLE_HT) &&
  748. !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT)))
  749. ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
  750. if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT))
  751. ieee80211_add_ht_ie(sdata, skb, assoc_data->ap_ht_param,
  752. sband, chan, sdata->smps_mode);
  753. /* if present, add any custom IEs that go before VHT */
  754. if (assoc_data->ie_len) {
  755. static const u8 before_vht[] = {
  756. /*
  757. * no need to list the ones split off before HT
  758. * or generated here
  759. */
  760. WLAN_EID_BSS_COEX_2040,
  761. WLAN_EID_EXT_CAPABILITY,
  762. WLAN_EID_QOS_TRAFFIC_CAPA,
  763. WLAN_EID_TIM_BCAST_REQ,
  764. WLAN_EID_INTERWORKING,
  765. /* 60 GHz (Multi-band, DMG, MMS) can't happen */
  766. };
  767. /* RIC already taken above, so no need to handle here anymore */
  768. noffset = ieee80211_ie_split(assoc_data->ie, assoc_data->ie_len,
  769. before_vht, ARRAY_SIZE(before_vht),
  770. offset);
  771. skb_put_data(skb, assoc_data->ie + offset, noffset - offset);
  772. offset = noffset;
  773. }
  774. /* if present, add any custom IEs that go before HE */
  775. if (assoc_data->ie_len) {
  776. static const u8 before_he[] = {
  777. /*
  778. * no need to list the ones split off before VHT
  779. * or generated here
  780. */
  781. WLAN_EID_OPMODE_NOTIF,
  782. WLAN_EID_EXTENSION, WLAN_EID_EXT_FUTURE_CHAN_GUIDANCE,
  783. /* 11ai elements */
  784. WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_SESSION,
  785. WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_PUBLIC_KEY,
  786. WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_KEY_CONFIRM,
  787. WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_HLP_CONTAINER,
  788. WLAN_EID_EXTENSION, WLAN_EID_EXT_FILS_IP_ADDR_ASSIGN,
  789. /* TODO: add 11ah/11aj/11ak elements */
  790. };
  791. /* RIC already taken above, so no need to handle here anymore */
  792. noffset = ieee80211_ie_split(assoc_data->ie, assoc_data->ie_len,
  793. before_he, ARRAY_SIZE(before_he),
  794. offset);
  795. pos = skb_put(skb, noffset - offset);
  796. memcpy(pos, assoc_data->ie + offset, noffset - offset);
  797. offset = noffset;
  798. }
  799. if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT))
  800. ieee80211_add_vht_ie(sdata, skb, sband,
  801. &assoc_data->ap_vht_cap);
  802. if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HE))
  803. ieee80211_add_he_ie(sdata, skb, sband);
  804. /* if present, add any custom non-vendor IEs that go after HE */
  805. if (assoc_data->ie_len) {
  806. noffset = ieee80211_ie_split_vendor(assoc_data->ie,
  807. assoc_data->ie_len,
  808. offset);
  809. skb_put_data(skb, assoc_data->ie + offset, noffset - offset);
  810. offset = noffset;
  811. }
  812. if (assoc_data->wmm) {
  813. if (assoc_data->uapsd) {
  814. qos_info = ifmgd->uapsd_queues;
  815. qos_info |= (ifmgd->uapsd_max_sp_len <<
  816. IEEE80211_WMM_IE_STA_QOSINFO_SP_SHIFT);
  817. } else {
  818. qos_info = 0;
  819. }
  820. pos = ieee80211_add_wmm_info_ie(skb_put(skb, 9), qos_info);
  821. }
  822. /* add any remaining custom (i.e. vendor specific here) IEs */
  823. if (assoc_data->ie_len) {
  824. noffset = assoc_data->ie_len;
  825. skb_put_data(skb, assoc_data->ie + offset, noffset - offset);
  826. }
  827. if (assoc_data->fils_kek_len &&
  828. fils_encrypt_assoc_req(skb, assoc_data) < 0) {
  829. dev_kfree_skb(skb);
  830. return;
  831. }
  832. drv_mgd_prepare_tx(local, sdata, 0);
  833. IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
  834. if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
  835. IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS |
  836. IEEE80211_TX_INTFL_MLME_CONN_TX;
  837. ieee80211_tx_skb(sdata, skb);
  838. }
  839. void ieee80211_send_pspoll(struct ieee80211_local *local,
  840. struct ieee80211_sub_if_data *sdata)
  841. {
  842. struct ieee80211_pspoll *pspoll;
  843. struct sk_buff *skb;
  844. skb = ieee80211_pspoll_get(&local->hw, &sdata->vif);
  845. if (!skb)
  846. return;
  847. pspoll = (struct ieee80211_pspoll *) skb->data;
  848. pspoll->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
  849. IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
  850. ieee80211_tx_skb(sdata, skb);
  851. }
  852. void ieee80211_send_nullfunc(struct ieee80211_local *local,
  853. struct ieee80211_sub_if_data *sdata,
  854. bool powersave)
  855. {
  856. struct sk_buff *skb;
  857. struct ieee80211_hdr_3addr *nullfunc;
  858. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  859. /* Don't send NDPs when STA is connected HE */
  860. if (sdata->vif.type == NL80211_IFTYPE_STATION &&
  861. !(ifmgd->flags & IEEE80211_STA_DISABLE_HE))
  862. return;
  863. skb = ieee80211_nullfunc_get(&local->hw, &sdata->vif,
  864. !ieee80211_hw_check(&local->hw, DOESNT_SUPPORT_QOS_NDP));
  865. if (!skb)
  866. return;
  867. nullfunc = (struct ieee80211_hdr_3addr *) skb->data;
  868. if (powersave)
  869. nullfunc->frame_control |= cpu_to_le16(IEEE80211_FCTL_PM);
  870. IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT |
  871. IEEE80211_TX_INTFL_OFFCHAN_TX_OK;
  872. if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
  873. IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_REQ_TX_STATUS;
  874. if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL)
  875. IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_CTL_USE_MINRATE;
  876. ieee80211_tx_skb(sdata, skb);
  877. }
  878. static void ieee80211_send_4addr_nullfunc(struct ieee80211_local *local,
  879. struct ieee80211_sub_if_data *sdata)
  880. {
  881. struct sk_buff *skb;
  882. struct ieee80211_hdr *nullfunc;
  883. __le16 fc;
  884. if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
  885. return;
  886. /* Don't send NDPs when connected HE */
  887. if (!(sdata->u.mgd.flags & IEEE80211_STA_DISABLE_HE))
  888. return;
  889. skb = dev_alloc_skb(local->hw.extra_tx_headroom + 30);
  890. if (!skb)
  891. return;
  892. skb_reserve(skb, local->hw.extra_tx_headroom);
  893. nullfunc = skb_put_zero(skb, 30);
  894. fc = cpu_to_le16(IEEE80211_FTYPE_DATA | IEEE80211_STYPE_NULLFUNC |
  895. IEEE80211_FCTL_FROMDS | IEEE80211_FCTL_TODS);
  896. nullfunc->frame_control = fc;
  897. memcpy(nullfunc->addr1, sdata->u.mgd.bssid, ETH_ALEN);
  898. memcpy(nullfunc->addr2, sdata->vif.addr, ETH_ALEN);
  899. memcpy(nullfunc->addr3, sdata->u.mgd.bssid, ETH_ALEN);
  900. memcpy(nullfunc->addr4, sdata->vif.addr, ETH_ALEN);
  901. IEEE80211_SKB_CB(skb)->flags |= IEEE80211_TX_INTFL_DONT_ENCRYPT;
  902. ieee80211_tx_skb(sdata, skb);
  903. }
  904. /* spectrum management related things */
  905. static void ieee80211_chswitch_work(struct work_struct *work)
  906. {
  907. struct ieee80211_sub_if_data *sdata =
  908. container_of(work, struct ieee80211_sub_if_data, u.mgd.chswitch_work);
  909. struct ieee80211_local *local = sdata->local;
  910. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  911. int ret;
  912. if (!ieee80211_sdata_running(sdata))
  913. return;
  914. sdata_lock(sdata);
  915. mutex_lock(&local->mtx);
  916. mutex_lock(&local->chanctx_mtx);
  917. if (!ifmgd->associated)
  918. goto out;
  919. if (!sdata->vif.csa_active)
  920. goto out;
  921. /*
  922. * using reservation isn't immediate as it may be deferred until later
  923. * with multi-vif. once reservation is complete it will re-schedule the
  924. * work with no reserved_chanctx so verify chandef to check if it
  925. * completed successfully
  926. */
  927. if (sdata->reserved_chanctx) {
  928. struct ieee80211_supported_band *sband = NULL;
  929. struct sta_info *mgd_sta = NULL;
  930. enum ieee80211_sta_rx_bandwidth bw = IEEE80211_STA_RX_BW_20;
  931. /*
  932. * with multi-vif csa driver may call ieee80211_csa_finish()
  933. * many times while waiting for other interfaces to use their
  934. * reservations
  935. */
  936. if (sdata->reserved_ready)
  937. goto out;
  938. if (sdata->vif.bss_conf.chandef.width !=
  939. sdata->csa_chandef.width) {
  940. /*
  941. * For managed interface, we need to also update the AP
  942. * station bandwidth and align the rate scale algorithm
  943. * on the bandwidth change. Here we only consider the
  944. * bandwidth of the new channel definition (as channel
  945. * switch flow does not have the full HT/VHT/HE
  946. * information), assuming that if additional changes are
  947. * required they would be done as part of the processing
  948. * of the next beacon from the AP.
  949. */
  950. switch (sdata->csa_chandef.width) {
  951. case NL80211_CHAN_WIDTH_20_NOHT:
  952. case NL80211_CHAN_WIDTH_20:
  953. default:
  954. bw = IEEE80211_STA_RX_BW_20;
  955. break;
  956. case NL80211_CHAN_WIDTH_40:
  957. bw = IEEE80211_STA_RX_BW_40;
  958. break;
  959. case NL80211_CHAN_WIDTH_80:
  960. bw = IEEE80211_STA_RX_BW_80;
  961. break;
  962. case NL80211_CHAN_WIDTH_80P80:
  963. case NL80211_CHAN_WIDTH_160:
  964. bw = IEEE80211_STA_RX_BW_160;
  965. break;
  966. }
  967. mgd_sta = sta_info_get(sdata, ifmgd->bssid);
  968. sband =
  969. local->hw.wiphy->bands[sdata->csa_chandef.chan->band];
  970. }
  971. if (sdata->vif.bss_conf.chandef.width >
  972. sdata->csa_chandef.width) {
  973. mgd_sta->sta.bandwidth = bw;
  974. rate_control_rate_update(local, sband, mgd_sta,
  975. IEEE80211_RC_BW_CHANGED);
  976. }
  977. ret = ieee80211_vif_use_reserved_context(sdata);
  978. if (ret) {
  979. sdata_info(sdata,
  980. "failed to use reserved channel context, disconnecting (err=%d)\n",
  981. ret);
  982. ieee80211_queue_work(&sdata->local->hw,
  983. &ifmgd->csa_connection_drop_work);
  984. goto out;
  985. }
  986. if (sdata->vif.bss_conf.chandef.width <
  987. sdata->csa_chandef.width) {
  988. mgd_sta->sta.bandwidth = bw;
  989. rate_control_rate_update(local, sband, mgd_sta,
  990. IEEE80211_RC_BW_CHANGED);
  991. }
  992. goto out;
  993. }
  994. if (!cfg80211_chandef_identical(&sdata->vif.bss_conf.chandef,
  995. &sdata->csa_chandef)) {
  996. sdata_info(sdata,
  997. "failed to finalize channel switch, disconnecting\n");
  998. ieee80211_queue_work(&sdata->local->hw,
  999. &ifmgd->csa_connection_drop_work);
  1000. goto out;
  1001. }
  1002. ifmgd->csa_waiting_bcn = true;
  1003. ieee80211_sta_reset_beacon_monitor(sdata);
  1004. ieee80211_sta_reset_conn_monitor(sdata);
  1005. out:
  1006. mutex_unlock(&local->chanctx_mtx);
  1007. mutex_unlock(&local->mtx);
  1008. sdata_unlock(sdata);
  1009. }
  1010. static void ieee80211_chswitch_post_beacon(struct ieee80211_sub_if_data *sdata)
  1011. {
  1012. struct ieee80211_local *local = sdata->local;
  1013. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  1014. int ret;
  1015. sdata_assert_lock(sdata);
  1016. WARN_ON(!sdata->vif.csa_active);
  1017. if (sdata->csa_block_tx) {
  1018. ieee80211_wake_vif_queues(local, sdata,
  1019. IEEE80211_QUEUE_STOP_REASON_CSA);
  1020. sdata->csa_block_tx = false;
  1021. }
  1022. sdata->vif.csa_active = false;
  1023. ifmgd->csa_waiting_bcn = false;
  1024. /*
  1025. * If the CSA IE is still present on the beacon after the switch,
  1026. * we need to consider it as a new CSA (possibly to self).
  1027. */
  1028. ifmgd->beacon_crc_valid = false;
  1029. ret = drv_post_channel_switch(sdata);
  1030. if (ret) {
  1031. sdata_info(sdata,
  1032. "driver post channel switch failed, disconnecting\n");
  1033. ieee80211_queue_work(&local->hw,
  1034. &ifmgd->csa_connection_drop_work);
  1035. return;
  1036. }
  1037. cfg80211_ch_switch_notify(sdata->dev, &sdata->reserved_chandef);
  1038. }
  1039. void ieee80211_chswitch_done(struct ieee80211_vif *vif, bool success)
  1040. {
  1041. struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
  1042. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  1043. trace_api_chswitch_done(sdata, success);
  1044. if (!success) {
  1045. sdata_info(sdata,
  1046. "driver channel switch failed, disconnecting\n");
  1047. ieee80211_queue_work(&sdata->local->hw,
  1048. &ifmgd->csa_connection_drop_work);
  1049. } else {
  1050. ieee80211_queue_work(&sdata->local->hw, &ifmgd->chswitch_work);
  1051. }
  1052. }
  1053. EXPORT_SYMBOL(ieee80211_chswitch_done);
  1054. static void ieee80211_chswitch_timer(struct timer_list *t)
  1055. {
  1056. struct ieee80211_sub_if_data *sdata =
  1057. from_timer(sdata, t, u.mgd.chswitch_timer);
  1058. ieee80211_queue_work(&sdata->local->hw, &sdata->u.mgd.chswitch_work);
  1059. }
  1060. static void
  1061. ieee80211_sta_process_chanswitch(struct ieee80211_sub_if_data *sdata,
  1062. u64 timestamp, u32 device_timestamp,
  1063. struct ieee802_11_elems *elems,
  1064. bool beacon)
  1065. {
  1066. struct ieee80211_local *local = sdata->local;
  1067. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  1068. struct cfg80211_bss *cbss = ifmgd->associated;
  1069. struct ieee80211_chanctx_conf *conf;
  1070. struct ieee80211_chanctx *chanctx;
  1071. enum nl80211_band current_band;
  1072. struct ieee80211_csa_ie csa_ie;
  1073. struct ieee80211_channel_switch ch_switch;
  1074. int res;
  1075. sdata_assert_lock(sdata);
  1076. if (!cbss)
  1077. return;
  1078. if (local->scanning)
  1079. return;
  1080. /* disregard subsequent announcements if we are already processing */
  1081. if (sdata->vif.csa_active)
  1082. return;
  1083. current_band = cbss->channel->band;
  1084. res = ieee80211_parse_ch_switch_ie(sdata, elems, current_band,
  1085. ifmgd->flags,
  1086. ifmgd->associated->bssid, &csa_ie);
  1087. if (res < 0)
  1088. ieee80211_queue_work(&local->hw,
  1089. &ifmgd->csa_connection_drop_work);
  1090. if (res)
  1091. return;
  1092. if (!cfg80211_chandef_usable(local->hw.wiphy, &csa_ie.chandef,
  1093. IEEE80211_CHAN_DISABLED)) {
  1094. sdata_info(sdata,
  1095. "AP %pM switches to unsupported channel (%d MHz, width:%d, CF1/2: %d/%d MHz), disconnecting\n",
  1096. ifmgd->associated->bssid,
  1097. csa_ie.chandef.chan->center_freq,
  1098. csa_ie.chandef.width, csa_ie.chandef.center_freq1,
  1099. csa_ie.chandef.center_freq2);
  1100. ieee80211_queue_work(&local->hw,
  1101. &ifmgd->csa_connection_drop_work);
  1102. return;
  1103. }
  1104. if (cfg80211_chandef_identical(&csa_ie.chandef,
  1105. &sdata->vif.bss_conf.chandef)) {
  1106. if (ifmgd->csa_ignored_same_chan)
  1107. return;
  1108. sdata_info(sdata,
  1109. "AP %pM tries to chanswitch to same channel, ignore\n",
  1110. ifmgd->associated->bssid);
  1111. ifmgd->csa_ignored_same_chan = true;
  1112. return;
  1113. }
  1114. /*
  1115. * Drop all TDLS peers - either we disconnect or move to a different
  1116. * channel from this point on. There's no telling what our peer will do.
  1117. * The TDLS WIDER_BW scenario is also problematic, as peers might now
  1118. * have an incompatible wider chandef.
  1119. */
  1120. ieee80211_teardown_tdls_peers(sdata);
  1121. mutex_lock(&local->mtx);
  1122. mutex_lock(&local->chanctx_mtx);
  1123. conf = rcu_dereference_protected(sdata->vif.chanctx_conf,
  1124. lockdep_is_held(&local->chanctx_mtx));
  1125. if (!conf) {
  1126. sdata_info(sdata,
  1127. "no channel context assigned to vif?, disconnecting\n");
  1128. goto drop_connection;
  1129. }
  1130. chanctx = container_of(conf, struct ieee80211_chanctx, conf);
  1131. if (local->use_chanctx &&
  1132. !ieee80211_hw_check(&local->hw, CHANCTX_STA_CSA)) {
  1133. sdata_info(sdata,
  1134. "driver doesn't support chan-switch with channel contexts\n");
  1135. goto drop_connection;
  1136. }
  1137. ch_switch.timestamp = timestamp;
  1138. ch_switch.device_timestamp = device_timestamp;
  1139. ch_switch.block_tx = csa_ie.mode;
  1140. ch_switch.chandef = csa_ie.chandef;
  1141. ch_switch.count = csa_ie.count;
  1142. if (drv_pre_channel_switch(sdata, &ch_switch)) {
  1143. sdata_info(sdata,
  1144. "preparing for channel switch failed, disconnecting\n");
  1145. goto drop_connection;
  1146. }
  1147. res = ieee80211_vif_reserve_chanctx(sdata, &csa_ie.chandef,
  1148. chanctx->mode, false);
  1149. if (res) {
  1150. sdata_info(sdata,
  1151. "failed to reserve channel context for channel switch, disconnecting (err=%d)\n",
  1152. res);
  1153. goto drop_connection;
  1154. }
  1155. mutex_unlock(&local->chanctx_mtx);
  1156. sdata->vif.csa_active = true;
  1157. sdata->csa_chandef = csa_ie.chandef;
  1158. sdata->csa_block_tx = csa_ie.mode;
  1159. ifmgd->csa_ignored_same_chan = false;
  1160. if (sdata->csa_block_tx)
  1161. ieee80211_stop_vif_queues(local, sdata,
  1162. IEEE80211_QUEUE_STOP_REASON_CSA);
  1163. mutex_unlock(&local->mtx);
  1164. cfg80211_ch_switch_started_notify(sdata->dev, &csa_ie.chandef,
  1165. csa_ie.count);
  1166. if (local->ops->channel_switch) {
  1167. /* use driver's channel switch callback */
  1168. drv_channel_switch(local, sdata, &ch_switch);
  1169. return;
  1170. }
  1171. /* channel switch handled in software */
  1172. if (csa_ie.count <= 1)
  1173. ieee80211_queue_work(&local->hw, &ifmgd->chswitch_work);
  1174. else
  1175. mod_timer(&ifmgd->chswitch_timer,
  1176. TU_TO_EXP_TIME((csa_ie.count - 1) *
  1177. cbss->beacon_interval));
  1178. return;
  1179. drop_connection:
  1180. /*
  1181. * This is just so that the disconnect flow will know that
  1182. * we were trying to switch channel and failed. In case the
  1183. * mode is 1 (we are not allowed to Tx), we will know not to
  1184. * send a deauthentication frame. Those two fields will be
  1185. * reset when the disconnection worker runs.
  1186. */
  1187. sdata->vif.csa_active = true;
  1188. sdata->csa_block_tx = csa_ie.mode;
  1189. ieee80211_queue_work(&local->hw, &ifmgd->csa_connection_drop_work);
  1190. mutex_unlock(&local->chanctx_mtx);
  1191. mutex_unlock(&local->mtx);
  1192. }
  1193. static bool
  1194. ieee80211_find_80211h_pwr_constr(struct ieee80211_sub_if_data *sdata,
  1195. struct ieee80211_channel *channel,
  1196. const u8 *country_ie, u8 country_ie_len,
  1197. const u8 *pwr_constr_elem,
  1198. int *chan_pwr, int *pwr_reduction)
  1199. {
  1200. struct ieee80211_country_ie_triplet *triplet;
  1201. int chan = ieee80211_frequency_to_channel(channel->center_freq);
  1202. int i, chan_increment;
  1203. bool have_chan_pwr = false;
  1204. /* Invalid IE */
  1205. if (country_ie_len % 2 || country_ie_len < IEEE80211_COUNTRY_IE_MIN_LEN)
  1206. return false;
  1207. triplet = (void *)(country_ie + 3);
  1208. country_ie_len -= 3;
  1209. switch (channel->band) {
  1210. default:
  1211. WARN_ON_ONCE(1);
  1212. /* fall through */
  1213. case NL80211_BAND_2GHZ:
  1214. case NL80211_BAND_60GHZ:
  1215. chan_increment = 1;
  1216. break;
  1217. case NL80211_BAND_5GHZ:
  1218. chan_increment = 4;
  1219. break;
  1220. }
  1221. /* find channel */
  1222. while (country_ie_len >= 3) {
  1223. u8 first_channel = triplet->chans.first_channel;
  1224. if (first_channel >= IEEE80211_COUNTRY_EXTENSION_ID)
  1225. goto next;
  1226. for (i = 0; i < triplet->chans.num_channels; i++) {
  1227. if (first_channel + i * chan_increment == chan) {
  1228. have_chan_pwr = true;
  1229. *chan_pwr = triplet->chans.max_power;
  1230. break;
  1231. }
  1232. }
  1233. if (have_chan_pwr)
  1234. break;
  1235. next:
  1236. triplet++;
  1237. country_ie_len -= 3;
  1238. }
  1239. if (have_chan_pwr && pwr_constr_elem)
  1240. *pwr_reduction = *pwr_constr_elem;
  1241. else
  1242. *pwr_reduction = 0;
  1243. return have_chan_pwr;
  1244. }
  1245. static void ieee80211_find_cisco_dtpc(struct ieee80211_sub_if_data *sdata,
  1246. struct ieee80211_channel *channel,
  1247. const u8 *cisco_dtpc_ie,
  1248. int *pwr_level)
  1249. {
  1250. /* From practical testing, the first data byte of the DTPC element
  1251. * seems to contain the requested dBm level, and the CLI on Cisco
  1252. * APs clearly state the range is -127 to 127 dBm, which indicates
  1253. * a signed byte, although it seemingly never actually goes negative.
  1254. * The other byte seems to always be zero.
  1255. */
  1256. *pwr_level = (__s8)cisco_dtpc_ie[4];
  1257. }
  1258. static u32 ieee80211_handle_pwr_constr(struct ieee80211_sub_if_data *sdata,
  1259. struct ieee80211_channel *channel,
  1260. struct ieee80211_mgmt *mgmt,
  1261. const u8 *country_ie, u8 country_ie_len,
  1262. const u8 *pwr_constr_ie,
  1263. const u8 *cisco_dtpc_ie)
  1264. {
  1265. bool has_80211h_pwr = false, has_cisco_pwr = false;
  1266. int chan_pwr = 0, pwr_reduction_80211h = 0;
  1267. int pwr_level_cisco, pwr_level_80211h;
  1268. int new_ap_level;
  1269. __le16 capab = mgmt->u.probe_resp.capab_info;
  1270. if (country_ie &&
  1271. (capab & cpu_to_le16(WLAN_CAPABILITY_SPECTRUM_MGMT) ||
  1272. capab & cpu_to_le16(WLAN_CAPABILITY_RADIO_MEASURE))) {
  1273. has_80211h_pwr = ieee80211_find_80211h_pwr_constr(
  1274. sdata, channel, country_ie, country_ie_len,
  1275. pwr_constr_ie, &chan_pwr, &pwr_reduction_80211h);
  1276. pwr_level_80211h =
  1277. max_t(int, 0, chan_pwr - pwr_reduction_80211h);
  1278. }
  1279. if (cisco_dtpc_ie) {
  1280. ieee80211_find_cisco_dtpc(
  1281. sdata, channel, cisco_dtpc_ie, &pwr_level_cisco);
  1282. has_cisco_pwr = true;
  1283. }
  1284. if (!has_80211h_pwr && !has_cisco_pwr)
  1285. return 0;
  1286. /* If we have both 802.11h and Cisco DTPC, apply both limits
  1287. * by picking the smallest of the two power levels advertised.
  1288. */
  1289. if (has_80211h_pwr &&
  1290. (!has_cisco_pwr || pwr_level_80211h <= pwr_level_cisco)) {
  1291. new_ap_level = pwr_level_80211h;
  1292. if (sdata->ap_power_level == new_ap_level)
  1293. return 0;
  1294. sdata_dbg(sdata,
  1295. "Limiting TX power to %d (%d - %d) dBm as advertised by %pM\n",
  1296. pwr_level_80211h, chan_pwr, pwr_reduction_80211h,
  1297. sdata->u.mgd.bssid);
  1298. } else { /* has_cisco_pwr is always true here. */
  1299. new_ap_level = pwr_level_cisco;
  1300. if (sdata->ap_power_level == new_ap_level)
  1301. return 0;
  1302. sdata_dbg(sdata,
  1303. "Limiting TX power to %d dBm as advertised by %pM\n",
  1304. pwr_level_cisco, sdata->u.mgd.bssid);
  1305. }
  1306. sdata->ap_power_level = new_ap_level;
  1307. if (__ieee80211_recalc_txpower(sdata))
  1308. return BSS_CHANGED_TXPOWER;
  1309. return 0;
  1310. }
  1311. /* powersave */
  1312. static void ieee80211_enable_ps(struct ieee80211_local *local,
  1313. struct ieee80211_sub_if_data *sdata)
  1314. {
  1315. struct ieee80211_conf *conf = &local->hw.conf;
  1316. /*
  1317. * If we are scanning right now then the parameters will
  1318. * take effect when scan finishes.
  1319. */
  1320. if (local->scanning)
  1321. return;
  1322. if (conf->dynamic_ps_timeout > 0 &&
  1323. !ieee80211_hw_check(&local->hw, SUPPORTS_DYNAMIC_PS)) {
  1324. mod_timer(&local->dynamic_ps_timer, jiffies +
  1325. msecs_to_jiffies(conf->dynamic_ps_timeout));
  1326. } else {
  1327. if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK))
  1328. ieee80211_send_nullfunc(local, sdata, true);
  1329. if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK) &&
  1330. ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
  1331. return;
  1332. conf->flags |= IEEE80211_CONF_PS;
  1333. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
  1334. }
  1335. }
  1336. static void ieee80211_change_ps(struct ieee80211_local *local)
  1337. {
  1338. struct ieee80211_conf *conf = &local->hw.conf;
  1339. if (local->ps_sdata) {
  1340. ieee80211_enable_ps(local, local->ps_sdata);
  1341. } else if (conf->flags & IEEE80211_CONF_PS) {
  1342. conf->flags &= ~IEEE80211_CONF_PS;
  1343. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
  1344. del_timer_sync(&local->dynamic_ps_timer);
  1345. cancel_work_sync(&local->dynamic_ps_enable_work);
  1346. }
  1347. }
  1348. static bool ieee80211_powersave_allowed(struct ieee80211_sub_if_data *sdata)
  1349. {
  1350. struct ieee80211_if_managed *mgd = &sdata->u.mgd;
  1351. struct sta_info *sta = NULL;
  1352. bool authorized = false;
  1353. if (!mgd->powersave)
  1354. return false;
  1355. if (mgd->broken_ap)
  1356. return false;
  1357. if (!mgd->associated)
  1358. return false;
  1359. if (mgd->flags & IEEE80211_STA_CONNECTION_POLL)
  1360. return false;
  1361. if (!mgd->have_beacon)
  1362. return false;
  1363. rcu_read_lock();
  1364. sta = sta_info_get(sdata, mgd->bssid);
  1365. if (sta)
  1366. authorized = test_sta_flag(sta, WLAN_STA_AUTHORIZED);
  1367. rcu_read_unlock();
  1368. return authorized;
  1369. }
  1370. /* need to hold RTNL or interface lock */
  1371. void ieee80211_recalc_ps(struct ieee80211_local *local)
  1372. {
  1373. struct ieee80211_sub_if_data *sdata, *found = NULL;
  1374. int count = 0;
  1375. int timeout;
  1376. if (!ieee80211_hw_check(&local->hw, SUPPORTS_PS)) {
  1377. local->ps_sdata = NULL;
  1378. return;
  1379. }
  1380. list_for_each_entry(sdata, &local->interfaces, list) {
  1381. if (!ieee80211_sdata_running(sdata))
  1382. continue;
  1383. if (sdata->vif.type == NL80211_IFTYPE_AP) {
  1384. /* If an AP vif is found, then disable PS
  1385. * by setting the count to zero thereby setting
  1386. * ps_sdata to NULL.
  1387. */
  1388. count = 0;
  1389. break;
  1390. }
  1391. if (sdata->vif.type != NL80211_IFTYPE_STATION)
  1392. continue;
  1393. found = sdata;
  1394. count++;
  1395. }
  1396. if (count == 1 && ieee80211_powersave_allowed(found)) {
  1397. u8 dtimper = found->u.mgd.dtim_period;
  1398. timeout = local->dynamic_ps_forced_timeout;
  1399. if (timeout < 0)
  1400. timeout = 100;
  1401. local->hw.conf.dynamic_ps_timeout = timeout;
  1402. /* If the TIM IE is invalid, pretend the value is 1 */
  1403. if (!dtimper)
  1404. dtimper = 1;
  1405. local->hw.conf.ps_dtim_period = dtimper;
  1406. local->ps_sdata = found;
  1407. } else {
  1408. local->ps_sdata = NULL;
  1409. }
  1410. ieee80211_change_ps(local);
  1411. }
  1412. void ieee80211_recalc_ps_vif(struct ieee80211_sub_if_data *sdata)
  1413. {
  1414. bool ps_allowed = ieee80211_powersave_allowed(sdata);
  1415. if (sdata->vif.bss_conf.ps != ps_allowed) {
  1416. sdata->vif.bss_conf.ps = ps_allowed;
  1417. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_PS);
  1418. }
  1419. }
  1420. void ieee80211_dynamic_ps_disable_work(struct work_struct *work)
  1421. {
  1422. struct ieee80211_local *local =
  1423. container_of(work, struct ieee80211_local,
  1424. dynamic_ps_disable_work);
  1425. if (local->hw.conf.flags & IEEE80211_CONF_PS) {
  1426. local->hw.conf.flags &= ~IEEE80211_CONF_PS;
  1427. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
  1428. }
  1429. ieee80211_wake_queues_by_reason(&local->hw,
  1430. IEEE80211_MAX_QUEUE_MAP,
  1431. IEEE80211_QUEUE_STOP_REASON_PS,
  1432. false);
  1433. }
  1434. void ieee80211_dynamic_ps_enable_work(struct work_struct *work)
  1435. {
  1436. struct ieee80211_local *local =
  1437. container_of(work, struct ieee80211_local,
  1438. dynamic_ps_enable_work);
  1439. struct ieee80211_sub_if_data *sdata = local->ps_sdata;
  1440. struct ieee80211_if_managed *ifmgd;
  1441. unsigned long flags;
  1442. int q;
  1443. /* can only happen when PS was just disabled anyway */
  1444. if (!sdata)
  1445. return;
  1446. ifmgd = &sdata->u.mgd;
  1447. if (local->hw.conf.flags & IEEE80211_CONF_PS)
  1448. return;
  1449. if (local->hw.conf.dynamic_ps_timeout > 0) {
  1450. /* don't enter PS if TX frames are pending */
  1451. if (drv_tx_frames_pending(local)) {
  1452. mod_timer(&local->dynamic_ps_timer, jiffies +
  1453. msecs_to_jiffies(
  1454. local->hw.conf.dynamic_ps_timeout));
  1455. return;
  1456. }
  1457. /*
  1458. * transmission can be stopped by others which leads to
  1459. * dynamic_ps_timer expiry. Postpone the ps timer if it
  1460. * is not the actual idle state.
  1461. */
  1462. spin_lock_irqsave(&local->queue_stop_reason_lock, flags);
  1463. for (q = 0; q < local->hw.queues; q++) {
  1464. if (local->queue_stop_reasons[q]) {
  1465. spin_unlock_irqrestore(&local->queue_stop_reason_lock,
  1466. flags);
  1467. mod_timer(&local->dynamic_ps_timer, jiffies +
  1468. msecs_to_jiffies(
  1469. local->hw.conf.dynamic_ps_timeout));
  1470. return;
  1471. }
  1472. }
  1473. spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
  1474. }
  1475. if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK) &&
  1476. !(ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED)) {
  1477. if (drv_tx_frames_pending(local)) {
  1478. mod_timer(&local->dynamic_ps_timer, jiffies +
  1479. msecs_to_jiffies(
  1480. local->hw.conf.dynamic_ps_timeout));
  1481. } else {
  1482. ieee80211_send_nullfunc(local, sdata, true);
  1483. /* Flush to get the tx status of nullfunc frame */
  1484. ieee80211_flush_queues(local, sdata, false);
  1485. }
  1486. }
  1487. if (!(ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS) &&
  1488. ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK)) ||
  1489. (ifmgd->flags & IEEE80211_STA_NULLFUNC_ACKED)) {
  1490. ifmgd->flags &= ~IEEE80211_STA_NULLFUNC_ACKED;
  1491. local->hw.conf.flags |= IEEE80211_CONF_PS;
  1492. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
  1493. }
  1494. }
  1495. void ieee80211_dynamic_ps_timer(struct timer_list *t)
  1496. {
  1497. struct ieee80211_local *local = from_timer(local, t, dynamic_ps_timer);
  1498. ieee80211_queue_work(&local->hw, &local->dynamic_ps_enable_work);
  1499. }
  1500. void ieee80211_dfs_cac_timer_work(struct work_struct *work)
  1501. {
  1502. struct delayed_work *delayed_work = to_delayed_work(work);
  1503. struct ieee80211_sub_if_data *sdata =
  1504. container_of(delayed_work, struct ieee80211_sub_if_data,
  1505. dfs_cac_timer_work);
  1506. struct cfg80211_chan_def chandef = sdata->vif.bss_conf.chandef;
  1507. mutex_lock(&sdata->local->mtx);
  1508. if (sdata->wdev.cac_started) {
  1509. ieee80211_vif_release_channel(sdata);
  1510. cfg80211_cac_event(sdata->dev, &chandef,
  1511. NL80211_RADAR_CAC_FINISHED,
  1512. GFP_KERNEL);
  1513. }
  1514. mutex_unlock(&sdata->local->mtx);
  1515. }
  1516. static bool
  1517. __ieee80211_sta_handle_tspec_ac_params(struct ieee80211_sub_if_data *sdata)
  1518. {
  1519. struct ieee80211_local *local = sdata->local;
  1520. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  1521. bool ret = false;
  1522. int ac;
  1523. if (local->hw.queues < IEEE80211_NUM_ACS)
  1524. return false;
  1525. for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
  1526. struct ieee80211_sta_tx_tspec *tx_tspec = &ifmgd->tx_tspec[ac];
  1527. int non_acm_ac;
  1528. unsigned long now = jiffies;
  1529. if (tx_tspec->action == TX_TSPEC_ACTION_NONE &&
  1530. tx_tspec->admitted_time &&
  1531. time_after(now, tx_tspec->time_slice_start + HZ)) {
  1532. tx_tspec->consumed_tx_time = 0;
  1533. tx_tspec->time_slice_start = now;
  1534. if (tx_tspec->downgraded)
  1535. tx_tspec->action =
  1536. TX_TSPEC_ACTION_STOP_DOWNGRADE;
  1537. }
  1538. switch (tx_tspec->action) {
  1539. case TX_TSPEC_ACTION_STOP_DOWNGRADE:
  1540. /* take the original parameters */
  1541. if (drv_conf_tx(local, sdata, ac, &sdata->tx_conf[ac]))
  1542. sdata_err(sdata,
  1543. "failed to set TX queue parameters for queue %d\n",
  1544. ac);
  1545. tx_tspec->action = TX_TSPEC_ACTION_NONE;
  1546. tx_tspec->downgraded = false;
  1547. ret = true;
  1548. break;
  1549. case TX_TSPEC_ACTION_DOWNGRADE:
  1550. if (time_after(now, tx_tspec->time_slice_start + HZ)) {
  1551. tx_tspec->action = TX_TSPEC_ACTION_NONE;
  1552. ret = true;
  1553. break;
  1554. }
  1555. /* downgrade next lower non-ACM AC */
  1556. for (non_acm_ac = ac + 1;
  1557. non_acm_ac < IEEE80211_NUM_ACS;
  1558. non_acm_ac++)
  1559. if (!(sdata->wmm_acm & BIT(7 - 2 * non_acm_ac)))
  1560. break;
  1561. /* Usually the loop will result in using BK even if it
  1562. * requires admission control, but such a configuration
  1563. * makes no sense and we have to transmit somehow - the
  1564. * AC selection does the same thing.
  1565. * If we started out trying to downgrade from BK, then
  1566. * the extra condition here might be needed.
  1567. */
  1568. if (non_acm_ac >= IEEE80211_NUM_ACS)
  1569. non_acm_ac = IEEE80211_AC_BK;
  1570. if (drv_conf_tx(local, sdata, ac,
  1571. &sdata->tx_conf[non_acm_ac]))
  1572. sdata_err(sdata,
  1573. "failed to set TX queue parameters for queue %d\n",
  1574. ac);
  1575. tx_tspec->action = TX_TSPEC_ACTION_NONE;
  1576. ret = true;
  1577. schedule_delayed_work(&ifmgd->tx_tspec_wk,
  1578. tx_tspec->time_slice_start + HZ - now + 1);
  1579. break;
  1580. case TX_TSPEC_ACTION_NONE:
  1581. /* nothing now */
  1582. break;
  1583. }
  1584. }
  1585. return ret;
  1586. }
  1587. void ieee80211_sta_handle_tspec_ac_params(struct ieee80211_sub_if_data *sdata)
  1588. {
  1589. if (__ieee80211_sta_handle_tspec_ac_params(sdata))
  1590. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_QOS);
  1591. }
  1592. static void ieee80211_sta_handle_tspec_ac_params_wk(struct work_struct *work)
  1593. {
  1594. struct ieee80211_sub_if_data *sdata;
  1595. sdata = container_of(work, struct ieee80211_sub_if_data,
  1596. u.mgd.tx_tspec_wk.work);
  1597. ieee80211_sta_handle_tspec_ac_params(sdata);
  1598. }
  1599. /* MLME */
  1600. static bool
  1601. ieee80211_sta_wmm_params(struct ieee80211_local *local,
  1602. struct ieee80211_sub_if_data *sdata,
  1603. const u8 *wmm_param, size_t wmm_param_len,
  1604. const struct ieee80211_mu_edca_param_set *mu_edca)
  1605. {
  1606. struct ieee80211_tx_queue_params params[IEEE80211_NUM_ACS];
  1607. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  1608. size_t left;
  1609. int count, ac;
  1610. const u8 *pos;
  1611. u8 uapsd_queues = 0;
  1612. if (!local->ops->conf_tx)
  1613. return false;
  1614. if (local->hw.queues < IEEE80211_NUM_ACS)
  1615. return false;
  1616. if (!wmm_param)
  1617. return false;
  1618. if (wmm_param_len < 8 || wmm_param[5] /* version */ != 1)
  1619. return false;
  1620. if (ifmgd->flags & IEEE80211_STA_UAPSD_ENABLED)
  1621. uapsd_queues = ifmgd->uapsd_queues;
  1622. count = wmm_param[6] & 0x0f;
  1623. if (count == ifmgd->wmm_last_param_set)
  1624. return false;
  1625. ifmgd->wmm_last_param_set = count;
  1626. pos = wmm_param + 8;
  1627. left = wmm_param_len - 8;
  1628. memset(&params, 0, sizeof(params));
  1629. sdata->wmm_acm = 0;
  1630. for (; left >= 4; left -= 4, pos += 4) {
  1631. int aci = (pos[0] >> 5) & 0x03;
  1632. int acm = (pos[0] >> 4) & 0x01;
  1633. bool uapsd = false;
  1634. switch (aci) {
  1635. case 1: /* AC_BK */
  1636. ac = IEEE80211_AC_BK;
  1637. if (acm)
  1638. sdata->wmm_acm |= BIT(1) | BIT(2); /* BK/- */
  1639. if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BK)
  1640. uapsd = true;
  1641. params[ac].mu_edca = !!mu_edca;
  1642. if (mu_edca)
  1643. params[ac].mu_edca_param_rec = mu_edca->ac_bk;
  1644. break;
  1645. case 2: /* AC_VI */
  1646. ac = IEEE80211_AC_VI;
  1647. if (acm)
  1648. sdata->wmm_acm |= BIT(4) | BIT(5); /* CL/VI */
  1649. if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VI)
  1650. uapsd = true;
  1651. params[ac].mu_edca = !!mu_edca;
  1652. if (mu_edca)
  1653. params[ac].mu_edca_param_rec = mu_edca->ac_vi;
  1654. break;
  1655. case 3: /* AC_VO */
  1656. ac = IEEE80211_AC_VO;
  1657. if (acm)
  1658. sdata->wmm_acm |= BIT(6) | BIT(7); /* VO/NC */
  1659. if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_VO)
  1660. uapsd = true;
  1661. params[ac].mu_edca = !!mu_edca;
  1662. if (mu_edca)
  1663. params[ac].mu_edca_param_rec = mu_edca->ac_vo;
  1664. break;
  1665. case 0: /* AC_BE */
  1666. default:
  1667. ac = IEEE80211_AC_BE;
  1668. if (acm)
  1669. sdata->wmm_acm |= BIT(0) | BIT(3); /* BE/EE */
  1670. if (uapsd_queues & IEEE80211_WMM_IE_STA_QOSINFO_AC_BE)
  1671. uapsd = true;
  1672. params[ac].mu_edca = !!mu_edca;
  1673. if (mu_edca)
  1674. params[ac].mu_edca_param_rec = mu_edca->ac_be;
  1675. break;
  1676. }
  1677. params[ac].aifs = pos[0] & 0x0f;
  1678. if (params[ac].aifs < 2) {
  1679. sdata_info(sdata,
  1680. "AP has invalid WMM params (AIFSN=%d for ACI %d), will use 2\n",
  1681. params[ac].aifs, aci);
  1682. params[ac].aifs = 2;
  1683. }
  1684. params[ac].cw_max = ecw2cw((pos[1] & 0xf0) >> 4);
  1685. params[ac].cw_min = ecw2cw(pos[1] & 0x0f);
  1686. params[ac].txop = get_unaligned_le16(pos + 2);
  1687. params[ac].acm = acm;
  1688. params[ac].uapsd = uapsd;
  1689. if (params[ac].cw_min == 0 ||
  1690. params[ac].cw_min > params[ac].cw_max) {
  1691. sdata_info(sdata,
  1692. "AP has invalid WMM params (CWmin/max=%d/%d for ACI %d), using defaults\n",
  1693. params[ac].cw_min, params[ac].cw_max, aci);
  1694. return false;
  1695. }
  1696. ieee80211_regulatory_limit_wmm_params(sdata, &params[ac], ac);
  1697. }
  1698. /* WMM specification requires all 4 ACIs. */
  1699. for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
  1700. if (params[ac].cw_min == 0) {
  1701. sdata_info(sdata,
  1702. "AP has invalid WMM params (missing AC %d), using defaults\n",
  1703. ac);
  1704. return false;
  1705. }
  1706. }
  1707. for (ac = 0; ac < IEEE80211_NUM_ACS; ac++) {
  1708. mlme_dbg(sdata,
  1709. "WMM AC=%d acm=%d aifs=%d cWmin=%d cWmax=%d txop=%d uapsd=%d, downgraded=%d\n",
  1710. ac, params[ac].acm,
  1711. params[ac].aifs, params[ac].cw_min, params[ac].cw_max,
  1712. params[ac].txop, params[ac].uapsd,
  1713. ifmgd->tx_tspec[ac].downgraded);
  1714. sdata->tx_conf[ac] = params[ac];
  1715. if (!ifmgd->tx_tspec[ac].downgraded &&
  1716. drv_conf_tx(local, sdata, ac, &params[ac]))
  1717. sdata_err(sdata,
  1718. "failed to set TX queue parameters for AC %d\n",
  1719. ac);
  1720. }
  1721. /* enable WMM or activate new settings */
  1722. sdata->vif.bss_conf.qos = true;
  1723. return true;
  1724. }
  1725. static void __ieee80211_stop_poll(struct ieee80211_sub_if_data *sdata)
  1726. {
  1727. lockdep_assert_held(&sdata->local->mtx);
  1728. sdata->u.mgd.flags &= ~IEEE80211_STA_CONNECTION_POLL;
  1729. ieee80211_run_deferred_scan(sdata->local);
  1730. }
  1731. static void ieee80211_stop_poll(struct ieee80211_sub_if_data *sdata)
  1732. {
  1733. mutex_lock(&sdata->local->mtx);
  1734. __ieee80211_stop_poll(sdata);
  1735. mutex_unlock(&sdata->local->mtx);
  1736. }
  1737. static u32 ieee80211_handle_bss_capability(struct ieee80211_sub_if_data *sdata,
  1738. u16 capab, bool erp_valid, u8 erp)
  1739. {
  1740. struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
  1741. struct ieee80211_supported_band *sband;
  1742. u32 changed = 0;
  1743. bool use_protection;
  1744. bool use_short_preamble;
  1745. bool use_short_slot;
  1746. sband = ieee80211_get_sband(sdata);
  1747. if (!sband)
  1748. return changed;
  1749. if (erp_valid) {
  1750. use_protection = (erp & WLAN_ERP_USE_PROTECTION) != 0;
  1751. use_short_preamble = (erp & WLAN_ERP_BARKER_PREAMBLE) == 0;
  1752. } else {
  1753. use_protection = false;
  1754. use_short_preamble = !!(capab & WLAN_CAPABILITY_SHORT_PREAMBLE);
  1755. }
  1756. use_short_slot = !!(capab & WLAN_CAPABILITY_SHORT_SLOT_TIME);
  1757. if (sband->band == NL80211_BAND_5GHZ)
  1758. use_short_slot = true;
  1759. if (use_protection != bss_conf->use_cts_prot) {
  1760. bss_conf->use_cts_prot = use_protection;
  1761. changed |= BSS_CHANGED_ERP_CTS_PROT;
  1762. }
  1763. if (use_short_preamble != bss_conf->use_short_preamble) {
  1764. bss_conf->use_short_preamble = use_short_preamble;
  1765. changed |= BSS_CHANGED_ERP_PREAMBLE;
  1766. }
  1767. if (use_short_slot != bss_conf->use_short_slot) {
  1768. bss_conf->use_short_slot = use_short_slot;
  1769. changed |= BSS_CHANGED_ERP_SLOT;
  1770. }
  1771. return changed;
  1772. }
  1773. static void ieee80211_set_associated(struct ieee80211_sub_if_data *sdata,
  1774. struct cfg80211_bss *cbss,
  1775. u32 bss_info_changed)
  1776. {
  1777. struct ieee80211_bss *bss = (void *)cbss->priv;
  1778. struct ieee80211_local *local = sdata->local;
  1779. struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
  1780. bss_info_changed |= BSS_CHANGED_ASSOC;
  1781. bss_info_changed |= ieee80211_handle_bss_capability(sdata,
  1782. bss_conf->assoc_capability, bss->has_erp_value, bss->erp_value);
  1783. sdata->u.mgd.beacon_timeout = usecs_to_jiffies(ieee80211_tu_to_usec(
  1784. beacon_loss_count * bss_conf->beacon_int));
  1785. sdata->u.mgd.associated = cbss;
  1786. memcpy(sdata->u.mgd.bssid, cbss->bssid, ETH_ALEN);
  1787. ieee80211_check_rate_mask(sdata);
  1788. sdata->u.mgd.flags |= IEEE80211_STA_RESET_SIGNAL_AVE;
  1789. if (sdata->vif.p2p ||
  1790. sdata->vif.driver_flags & IEEE80211_VIF_GET_NOA_UPDATE) {
  1791. const struct cfg80211_bss_ies *ies;
  1792. rcu_read_lock();
  1793. ies = rcu_dereference(cbss->ies);
  1794. if (ies) {
  1795. int ret;
  1796. ret = cfg80211_get_p2p_attr(
  1797. ies->data, ies->len,
  1798. IEEE80211_P2P_ATTR_ABSENCE_NOTICE,
  1799. (u8 *) &bss_conf->p2p_noa_attr,
  1800. sizeof(bss_conf->p2p_noa_attr));
  1801. if (ret >= 2) {
  1802. sdata->u.mgd.p2p_noa_index =
  1803. bss_conf->p2p_noa_attr.index;
  1804. bss_info_changed |= BSS_CHANGED_P2P_PS;
  1805. }
  1806. }
  1807. rcu_read_unlock();
  1808. }
  1809. /* just to be sure */
  1810. ieee80211_stop_poll(sdata);
  1811. ieee80211_led_assoc(local, 1);
  1812. if (sdata->u.mgd.have_beacon) {
  1813. /*
  1814. * If the AP is buggy we may get here with no DTIM period
  1815. * known, so assume it's 1 which is the only safe assumption
  1816. * in that case, although if the TIM IE is broken powersave
  1817. * probably just won't work at all.
  1818. */
  1819. bss_conf->dtim_period = sdata->u.mgd.dtim_period ?: 1;
  1820. bss_conf->beacon_rate = bss->beacon_rate;
  1821. bss_info_changed |= BSS_CHANGED_BEACON_INFO;
  1822. } else {
  1823. bss_conf->beacon_rate = NULL;
  1824. bss_conf->dtim_period = 0;
  1825. }
  1826. bss_conf->assoc = 1;
  1827. /* Tell the driver to monitor connection quality (if supported) */
  1828. if (sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI &&
  1829. bss_conf->cqm_rssi_thold)
  1830. bss_info_changed |= BSS_CHANGED_CQM;
  1831. /* Enable ARP filtering */
  1832. if (bss_conf->arp_addr_cnt)
  1833. bss_info_changed |= BSS_CHANGED_ARP_FILTER;
  1834. ieee80211_bss_info_change_notify(sdata, bss_info_changed);
  1835. mutex_lock(&local->iflist_mtx);
  1836. ieee80211_recalc_ps(local);
  1837. mutex_unlock(&local->iflist_mtx);
  1838. ieee80211_recalc_smps(sdata);
  1839. ieee80211_recalc_ps_vif(sdata);
  1840. netif_carrier_on(sdata->dev);
  1841. }
  1842. static void ieee80211_set_disassoc(struct ieee80211_sub_if_data *sdata,
  1843. u16 stype, u16 reason, bool tx,
  1844. u8 *frame_buf)
  1845. {
  1846. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  1847. struct ieee80211_local *local = sdata->local;
  1848. u32 changed = 0;
  1849. sdata_assert_lock(sdata);
  1850. if (WARN_ON_ONCE(tx && !frame_buf))
  1851. return;
  1852. if (WARN_ON(!ifmgd->associated))
  1853. return;
  1854. ieee80211_stop_poll(sdata);
  1855. ifmgd->associated = NULL;
  1856. netif_carrier_off(sdata->dev);
  1857. /*
  1858. * if we want to get out of ps before disassoc (why?) we have
  1859. * to do it before sending disassoc, as otherwise the null-packet
  1860. * won't be valid.
  1861. */
  1862. if (local->hw.conf.flags & IEEE80211_CONF_PS) {
  1863. local->hw.conf.flags &= ~IEEE80211_CONF_PS;
  1864. ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_PS);
  1865. }
  1866. local->ps_sdata = NULL;
  1867. /* disable per-vif ps */
  1868. ieee80211_recalc_ps_vif(sdata);
  1869. /* make sure ongoing transmission finishes */
  1870. synchronize_net();
  1871. /*
  1872. * drop any frame before deauth/disassoc, this can be data or
  1873. * management frame. Since we are disconnecting, we should not
  1874. * insist sending these frames which can take time and delay
  1875. * the disconnection and possible the roaming.
  1876. */
  1877. if (tx)
  1878. ieee80211_flush_queues(local, sdata, true);
  1879. /* deauthenticate/disassociate now */
  1880. if (tx || frame_buf) {
  1881. /*
  1882. * In multi channel scenarios guarantee that the virtual
  1883. * interface is granted immediate airtime to transmit the
  1884. * deauthentication frame by calling mgd_prepare_tx, if the
  1885. * driver requested so.
  1886. */
  1887. if (ieee80211_hw_check(&local->hw, DEAUTH_NEED_MGD_TX_PREP) &&
  1888. !ifmgd->have_beacon)
  1889. drv_mgd_prepare_tx(sdata->local, sdata, 0);
  1890. ieee80211_send_deauth_disassoc(sdata, ifmgd->bssid, stype,
  1891. reason, tx, frame_buf);
  1892. }
  1893. /* flush out frame - make sure the deauth was actually sent */
  1894. if (tx)
  1895. ieee80211_flush_queues(local, sdata, false);
  1896. /* clear bssid only after building the needed mgmt frames */
  1897. eth_zero_addr(ifmgd->bssid);
  1898. /* remove AP and TDLS peers */
  1899. sta_info_flush(sdata);
  1900. /* finally reset all BSS / config parameters */
  1901. changed |= ieee80211_reset_erp_info(sdata);
  1902. ieee80211_led_assoc(local, 0);
  1903. changed |= BSS_CHANGED_ASSOC;
  1904. sdata->vif.bss_conf.assoc = false;
  1905. ifmgd->p2p_noa_index = -1;
  1906. memset(&sdata->vif.bss_conf.p2p_noa_attr, 0,
  1907. sizeof(sdata->vif.bss_conf.p2p_noa_attr));
  1908. /* on the next assoc, re-program HT/VHT parameters */
  1909. memset(&ifmgd->ht_capa, 0, sizeof(ifmgd->ht_capa));
  1910. memset(&ifmgd->ht_capa_mask, 0, sizeof(ifmgd->ht_capa_mask));
  1911. memset(&ifmgd->vht_capa, 0, sizeof(ifmgd->vht_capa));
  1912. memset(&ifmgd->vht_capa_mask, 0, sizeof(ifmgd->vht_capa_mask));
  1913. /* reset MU-MIMO ownership and group data */
  1914. memset(sdata->vif.bss_conf.mu_group.membership, 0,
  1915. sizeof(sdata->vif.bss_conf.mu_group.membership));
  1916. memset(sdata->vif.bss_conf.mu_group.position, 0,
  1917. sizeof(sdata->vif.bss_conf.mu_group.position));
  1918. changed |= BSS_CHANGED_MU_GROUPS;
  1919. sdata->vif.mu_mimo_owner = false;
  1920. sdata->ap_power_level = IEEE80211_UNSET_POWER_LEVEL;
  1921. del_timer_sync(&local->dynamic_ps_timer);
  1922. cancel_work_sync(&local->dynamic_ps_enable_work);
  1923. /* Disable ARP filtering */
  1924. if (sdata->vif.bss_conf.arp_addr_cnt)
  1925. changed |= BSS_CHANGED_ARP_FILTER;
  1926. sdata->vif.bss_conf.qos = false;
  1927. changed |= BSS_CHANGED_QOS;
  1928. /* The BSSID (not really interesting) and HT changed */
  1929. changed |= BSS_CHANGED_BSSID | BSS_CHANGED_HT;
  1930. ieee80211_bss_info_change_notify(sdata, changed);
  1931. /* disassociated - set to defaults now */
  1932. ieee80211_set_wmm_default(sdata, false, false);
  1933. del_timer_sync(&sdata->u.mgd.conn_mon_timer);
  1934. del_timer_sync(&sdata->u.mgd.bcn_mon_timer);
  1935. del_timer_sync(&sdata->u.mgd.timer);
  1936. del_timer_sync(&sdata->u.mgd.chswitch_timer);
  1937. sdata->vif.bss_conf.dtim_period = 0;
  1938. sdata->vif.bss_conf.beacon_rate = NULL;
  1939. ifmgd->have_beacon = false;
  1940. ifmgd->flags = 0;
  1941. mutex_lock(&local->mtx);
  1942. ieee80211_vif_release_channel(sdata);
  1943. sdata->vif.csa_active = false;
  1944. ifmgd->csa_waiting_bcn = false;
  1945. ifmgd->csa_ignored_same_chan = false;
  1946. if (sdata->csa_block_tx) {
  1947. ieee80211_wake_vif_queues(local, sdata,
  1948. IEEE80211_QUEUE_STOP_REASON_CSA);
  1949. sdata->csa_block_tx = false;
  1950. }
  1951. mutex_unlock(&local->mtx);
  1952. /* existing TX TSPEC sessions no longer exist */
  1953. memset(ifmgd->tx_tspec, 0, sizeof(ifmgd->tx_tspec));
  1954. cancel_delayed_work_sync(&ifmgd->tx_tspec_wk);
  1955. sdata->encrypt_headroom = IEEE80211_ENCRYPT_HEADROOM;
  1956. }
  1957. void ieee80211_sta_rx_notify(struct ieee80211_sub_if_data *sdata,
  1958. struct ieee80211_hdr *hdr)
  1959. {
  1960. /*
  1961. * We can postpone the mgd.timer whenever receiving unicast frames
  1962. * from AP because we know that the connection is working both ways
  1963. * at that time. But multicast frames (and hence also beacons) must
  1964. * be ignored here, because we need to trigger the timer during
  1965. * data idle periods for sending the periodic probe request to the
  1966. * AP we're connected to.
  1967. */
  1968. if (is_multicast_ether_addr(hdr->addr1))
  1969. return;
  1970. ieee80211_sta_reset_conn_monitor(sdata);
  1971. }
  1972. static void ieee80211_reset_ap_probe(struct ieee80211_sub_if_data *sdata)
  1973. {
  1974. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  1975. struct ieee80211_local *local = sdata->local;
  1976. mutex_lock(&local->mtx);
  1977. if (!(ifmgd->flags & IEEE80211_STA_CONNECTION_POLL))
  1978. goto out;
  1979. __ieee80211_stop_poll(sdata);
  1980. mutex_lock(&local->iflist_mtx);
  1981. ieee80211_recalc_ps(local);
  1982. mutex_unlock(&local->iflist_mtx);
  1983. if (ieee80211_hw_check(&sdata->local->hw, CONNECTION_MONITOR))
  1984. goto out;
  1985. /*
  1986. * We've received a probe response, but are not sure whether
  1987. * we have or will be receiving any beacons or data, so let's
  1988. * schedule the timers again, just in case.
  1989. */
  1990. ieee80211_sta_reset_beacon_monitor(sdata);
  1991. mod_timer(&ifmgd->conn_mon_timer,
  1992. round_jiffies_up(jiffies +
  1993. IEEE80211_CONNECTION_IDLE_TIME));
  1994. out:
  1995. mutex_unlock(&local->mtx);
  1996. }
  1997. static void ieee80211_sta_tx_wmm_ac_notify(struct ieee80211_sub_if_data *sdata,
  1998. struct ieee80211_hdr *hdr,
  1999. u16 tx_time)
  2000. {
  2001. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  2002. u16 tid = ieee80211_get_tid(hdr);
  2003. int ac = ieee80211_ac_from_tid(tid);
  2004. struct ieee80211_sta_tx_tspec *tx_tspec = &ifmgd->tx_tspec[ac];
  2005. unsigned long now = jiffies;
  2006. if (likely(!tx_tspec->admitted_time))
  2007. return;
  2008. if (time_after(now, tx_tspec->time_slice_start + HZ)) {
  2009. tx_tspec->consumed_tx_time = 0;
  2010. tx_tspec->time_slice_start = now;
  2011. if (tx_tspec->downgraded) {
  2012. tx_tspec->action = TX_TSPEC_ACTION_STOP_DOWNGRADE;
  2013. schedule_delayed_work(&ifmgd->tx_tspec_wk, 0);
  2014. }
  2015. }
  2016. if (tx_tspec->downgraded)
  2017. return;
  2018. tx_tspec->consumed_tx_time += tx_time;
  2019. if (tx_tspec->consumed_tx_time >= tx_tspec->admitted_time) {
  2020. tx_tspec->downgraded = true;
  2021. tx_tspec->action = TX_TSPEC_ACTION_DOWNGRADE;
  2022. schedule_delayed_work(&ifmgd->tx_tspec_wk, 0);
  2023. }
  2024. }
  2025. void ieee80211_sta_tx_notify(struct ieee80211_sub_if_data *sdata,
  2026. struct ieee80211_hdr *hdr, bool ack, u16 tx_time)
  2027. {
  2028. ieee80211_sta_tx_wmm_ac_notify(sdata, hdr, tx_time);
  2029. if (!ieee80211_is_data(hdr->frame_control))
  2030. return;
  2031. if (ieee80211_is_any_nullfunc(hdr->frame_control) &&
  2032. sdata->u.mgd.probe_send_count > 0) {
  2033. if (ack)
  2034. ieee80211_sta_reset_conn_monitor(sdata);
  2035. else
  2036. sdata->u.mgd.nullfunc_failed = true;
  2037. ieee80211_queue_work(&sdata->local->hw, &sdata->work);
  2038. return;
  2039. }
  2040. if (ack)
  2041. ieee80211_sta_reset_conn_monitor(sdata);
  2042. }
  2043. static void ieee80211_mlme_send_probe_req(struct ieee80211_sub_if_data *sdata,
  2044. const u8 *src, const u8 *dst,
  2045. const u8 *ssid, size_t ssid_len,
  2046. struct ieee80211_channel *channel)
  2047. {
  2048. struct sk_buff *skb;
  2049. skb = ieee80211_build_probe_req(sdata, src, dst, (u32)-1, channel,
  2050. ssid, ssid_len, NULL, 0,
  2051. IEEE80211_PROBE_FLAG_DIRECTED);
  2052. if (skb)
  2053. ieee80211_tx_skb(sdata, skb);
  2054. }
  2055. static void ieee80211_mgd_probe_ap_send(struct ieee80211_sub_if_data *sdata)
  2056. {
  2057. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  2058. const u8 *ssid;
  2059. u8 *dst = ifmgd->associated->bssid;
  2060. u8 unicast_limit = max(1, max_probe_tries - 3);
  2061. struct sta_info *sta;
  2062. /*
  2063. * Try sending broadcast probe requests for the last three
  2064. * probe requests after the first ones failed since some
  2065. * buggy APs only support broadcast probe requests.
  2066. */
  2067. if (ifmgd->probe_send_count >= unicast_limit)
  2068. dst = NULL;
  2069. /*
  2070. * When the hardware reports an accurate Tx ACK status, it's
  2071. * better to send a nullfunc frame instead of a probe request,
  2072. * as it will kick us off the AP quickly if we aren't associated
  2073. * anymore. The timeout will be reset if the frame is ACKed by
  2074. * the AP.
  2075. */
  2076. ifmgd->probe_send_count++;
  2077. if (dst) {
  2078. mutex_lock(&sdata->local->sta_mtx);
  2079. sta = sta_info_get(sdata, dst);
  2080. if (!WARN_ON(!sta))
  2081. ieee80211_check_fast_rx(sta);
  2082. mutex_unlock(&sdata->local->sta_mtx);
  2083. }
  2084. if (ieee80211_hw_check(&sdata->local->hw, REPORTS_TX_ACK_STATUS)) {
  2085. ifmgd->nullfunc_failed = false;
  2086. ieee80211_send_nullfunc(sdata->local, sdata, false);
  2087. } else {
  2088. int ssid_len;
  2089. rcu_read_lock();
  2090. ssid = ieee80211_bss_get_ie(ifmgd->associated, WLAN_EID_SSID);
  2091. if (WARN_ON_ONCE(ssid == NULL))
  2092. ssid_len = 0;
  2093. else
  2094. ssid_len = ssid[1];
  2095. ieee80211_mlme_send_probe_req(sdata, sdata->vif.addr, dst,
  2096. ssid + 2, ssid_len,
  2097. ifmgd->associated->channel);
  2098. rcu_read_unlock();
  2099. }
  2100. ifmgd->probe_timeout = jiffies + msecs_to_jiffies(probe_wait_ms);
  2101. run_again(sdata, ifmgd->probe_timeout);
  2102. }
  2103. static void ieee80211_mgd_probe_ap(struct ieee80211_sub_if_data *sdata,
  2104. bool beacon)
  2105. {
  2106. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  2107. bool already = false;
  2108. if (!ieee80211_sdata_running(sdata))
  2109. return;
  2110. sdata_lock(sdata);
  2111. if (!ifmgd->associated)
  2112. goto out;
  2113. mutex_lock(&sdata->local->mtx);
  2114. if (sdata->local->tmp_channel || sdata->local->scanning) {
  2115. mutex_unlock(&sdata->local->mtx);
  2116. goto out;
  2117. }
  2118. if (beacon) {
  2119. mlme_dbg_ratelimited(sdata,
  2120. "detected beacon loss from AP (missed %d beacons) - probing\n",
  2121. beacon_loss_count);
  2122. ieee80211_cqm_beacon_loss_notify(&sdata->vif, GFP_KERNEL);
  2123. }
  2124. /*
  2125. * The driver/our work has already reported this event or the
  2126. * connection monitoring has kicked in and we have already sent
  2127. * a probe request. Or maybe the AP died and the driver keeps
  2128. * reporting until we disassociate...
  2129. *
  2130. * In either case we have to ignore the current call to this
  2131. * function (except for setting the correct probe reason bit)
  2132. * because otherwise we would reset the timer every time and
  2133. * never check whether we received a probe response!
  2134. */
  2135. if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL)
  2136. already = true;
  2137. ifmgd->flags |= IEEE80211_STA_CONNECTION_POLL;
  2138. mutex_unlock(&sdata->local->mtx);
  2139. if (already)
  2140. goto out;
  2141. mutex_lock(&sdata->local->iflist_mtx);
  2142. ieee80211_recalc_ps(sdata->local);
  2143. mutex_unlock(&sdata->local->iflist_mtx);
  2144. ifmgd->probe_send_count = 0;
  2145. ieee80211_mgd_probe_ap_send(sdata);
  2146. out:
  2147. sdata_unlock(sdata);
  2148. }
  2149. struct sk_buff *ieee80211_ap_probereq_get(struct ieee80211_hw *hw,
  2150. struct ieee80211_vif *vif)
  2151. {
  2152. struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
  2153. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  2154. struct cfg80211_bss *cbss;
  2155. struct sk_buff *skb;
  2156. const u8 *ssid;
  2157. int ssid_len;
  2158. if (WARN_ON(sdata->vif.type != NL80211_IFTYPE_STATION))
  2159. return NULL;
  2160. sdata_assert_lock(sdata);
  2161. if (ifmgd->associated)
  2162. cbss = ifmgd->associated;
  2163. else if (ifmgd->auth_data)
  2164. cbss = ifmgd->auth_data->bss;
  2165. else if (ifmgd->assoc_data)
  2166. cbss = ifmgd->assoc_data->bss;
  2167. else
  2168. return NULL;
  2169. rcu_read_lock();
  2170. ssid = ieee80211_bss_get_ie(cbss, WLAN_EID_SSID);
  2171. if (WARN_ONCE(!ssid || ssid[1] > IEEE80211_MAX_SSID_LEN,
  2172. "invalid SSID element (len=%d)", ssid ? ssid[1] : -1))
  2173. ssid_len = 0;
  2174. else
  2175. ssid_len = ssid[1];
  2176. skb = ieee80211_build_probe_req(sdata, sdata->vif.addr, cbss->bssid,
  2177. (u32) -1, cbss->channel,
  2178. ssid + 2, ssid_len,
  2179. NULL, 0, IEEE80211_PROBE_FLAG_DIRECTED);
  2180. rcu_read_unlock();
  2181. return skb;
  2182. }
  2183. EXPORT_SYMBOL(ieee80211_ap_probereq_get);
  2184. static void ieee80211_report_disconnect(struct ieee80211_sub_if_data *sdata,
  2185. const u8 *buf, size_t len, bool tx,
  2186. u16 reason)
  2187. {
  2188. struct ieee80211_event event = {
  2189. .type = MLME_EVENT,
  2190. .u.mlme.data = tx ? DEAUTH_TX_EVENT : DEAUTH_RX_EVENT,
  2191. .u.mlme.reason = reason,
  2192. };
  2193. if (tx)
  2194. cfg80211_tx_mlme_mgmt(sdata->dev, buf, len);
  2195. else
  2196. cfg80211_rx_mlme_mgmt(sdata->dev, buf, len);
  2197. drv_event_callback(sdata->local, sdata, &event);
  2198. }
  2199. static void __ieee80211_disconnect(struct ieee80211_sub_if_data *sdata)
  2200. {
  2201. struct ieee80211_local *local = sdata->local;
  2202. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  2203. u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
  2204. bool tx;
  2205. sdata_lock(sdata);
  2206. if (!ifmgd->associated) {
  2207. sdata_unlock(sdata);
  2208. return;
  2209. }
  2210. tx = !sdata->csa_block_tx;
  2211. /* AP is probably out of range (or not reachable for another reason) so
  2212. * remove the bss struct for that AP.
  2213. */
  2214. cfg80211_unlink_bss(local->hw.wiphy, ifmgd->associated);
  2215. ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
  2216. WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY,
  2217. tx, frame_buf);
  2218. mutex_lock(&local->mtx);
  2219. sdata->vif.csa_active = false;
  2220. ifmgd->csa_waiting_bcn = false;
  2221. if (sdata->csa_block_tx) {
  2222. ieee80211_wake_vif_queues(local, sdata,
  2223. IEEE80211_QUEUE_STOP_REASON_CSA);
  2224. sdata->csa_block_tx = false;
  2225. }
  2226. mutex_unlock(&local->mtx);
  2227. ieee80211_report_disconnect(sdata, frame_buf, sizeof(frame_buf), tx,
  2228. WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY);
  2229. sdata_unlock(sdata);
  2230. }
  2231. static void ieee80211_beacon_connection_loss_work(struct work_struct *work)
  2232. {
  2233. struct ieee80211_sub_if_data *sdata =
  2234. container_of(work, struct ieee80211_sub_if_data,
  2235. u.mgd.beacon_connection_loss_work);
  2236. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  2237. if (ifmgd->associated)
  2238. ifmgd->beacon_loss_count++;
  2239. if (ifmgd->connection_loss) {
  2240. sdata_info(sdata, "Connection to AP %pM lost\n",
  2241. ifmgd->bssid);
  2242. __ieee80211_disconnect(sdata);
  2243. } else {
  2244. ieee80211_mgd_probe_ap(sdata, true);
  2245. }
  2246. }
  2247. static void ieee80211_csa_connection_drop_work(struct work_struct *work)
  2248. {
  2249. struct ieee80211_sub_if_data *sdata =
  2250. container_of(work, struct ieee80211_sub_if_data,
  2251. u.mgd.csa_connection_drop_work);
  2252. __ieee80211_disconnect(sdata);
  2253. }
  2254. void ieee80211_beacon_loss(struct ieee80211_vif *vif)
  2255. {
  2256. struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
  2257. struct ieee80211_hw *hw = &sdata->local->hw;
  2258. trace_api_beacon_loss(sdata);
  2259. sdata->u.mgd.connection_loss = false;
  2260. ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work);
  2261. }
  2262. EXPORT_SYMBOL(ieee80211_beacon_loss);
  2263. void ieee80211_connection_loss(struct ieee80211_vif *vif)
  2264. {
  2265. struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
  2266. struct ieee80211_hw *hw = &sdata->local->hw;
  2267. trace_api_connection_loss(sdata);
  2268. sdata->u.mgd.connection_loss = true;
  2269. ieee80211_queue_work(hw, &sdata->u.mgd.beacon_connection_loss_work);
  2270. }
  2271. EXPORT_SYMBOL(ieee80211_connection_loss);
  2272. static void ieee80211_destroy_auth_data(struct ieee80211_sub_if_data *sdata,
  2273. bool assoc)
  2274. {
  2275. struct ieee80211_mgd_auth_data *auth_data = sdata->u.mgd.auth_data;
  2276. sdata_assert_lock(sdata);
  2277. if (!assoc) {
  2278. /*
  2279. * we are not authenticated yet, the only timer that could be
  2280. * running is the timeout for the authentication response which
  2281. * which is not relevant anymore.
  2282. */
  2283. del_timer_sync(&sdata->u.mgd.timer);
  2284. sta_info_destroy_addr(sdata, auth_data->bss->bssid);
  2285. eth_zero_addr(sdata->u.mgd.bssid);
  2286. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID);
  2287. sdata->u.mgd.flags = 0;
  2288. mutex_lock(&sdata->local->mtx);
  2289. ieee80211_vif_release_channel(sdata);
  2290. mutex_unlock(&sdata->local->mtx);
  2291. }
  2292. cfg80211_put_bss(sdata->local->hw.wiphy, auth_data->bss);
  2293. kfree(auth_data);
  2294. sdata->u.mgd.auth_data = NULL;
  2295. }
  2296. static void ieee80211_destroy_assoc_data(struct ieee80211_sub_if_data *sdata,
  2297. bool assoc, bool abandon)
  2298. {
  2299. struct ieee80211_mgd_assoc_data *assoc_data = sdata->u.mgd.assoc_data;
  2300. sdata_assert_lock(sdata);
  2301. if (!assoc) {
  2302. /*
  2303. * we are not associated yet, the only timer that could be
  2304. * running is the timeout for the association response which
  2305. * which is not relevant anymore.
  2306. */
  2307. del_timer_sync(&sdata->u.mgd.timer);
  2308. sta_info_destroy_addr(sdata, assoc_data->bss->bssid);
  2309. eth_zero_addr(sdata->u.mgd.bssid);
  2310. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID);
  2311. sdata->u.mgd.flags = 0;
  2312. sdata->vif.mu_mimo_owner = false;
  2313. mutex_lock(&sdata->local->mtx);
  2314. ieee80211_vif_release_channel(sdata);
  2315. mutex_unlock(&sdata->local->mtx);
  2316. if (abandon)
  2317. cfg80211_abandon_assoc(sdata->dev, assoc_data->bss);
  2318. }
  2319. kfree(assoc_data);
  2320. sdata->u.mgd.assoc_data = NULL;
  2321. }
  2322. static void ieee80211_auth_challenge(struct ieee80211_sub_if_data *sdata,
  2323. struct ieee80211_mgmt *mgmt, size_t len)
  2324. {
  2325. struct ieee80211_local *local = sdata->local;
  2326. struct ieee80211_mgd_auth_data *auth_data = sdata->u.mgd.auth_data;
  2327. u8 *pos;
  2328. struct ieee802_11_elems elems;
  2329. u32 tx_flags = 0;
  2330. pos = mgmt->u.auth.variable;
  2331. ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), false, &elems);
  2332. if (!elems.challenge)
  2333. return;
  2334. auth_data->expected_transaction = 4;
  2335. drv_mgd_prepare_tx(sdata->local, sdata, 0);
  2336. if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
  2337. tx_flags = IEEE80211_TX_CTL_REQ_TX_STATUS |
  2338. IEEE80211_TX_INTFL_MLME_CONN_TX;
  2339. ieee80211_send_auth(sdata, 3, auth_data->algorithm, 0,
  2340. elems.challenge - 2, elems.challenge_len + 2,
  2341. auth_data->bss->bssid, auth_data->bss->bssid,
  2342. auth_data->key, auth_data->key_len,
  2343. auth_data->key_idx, tx_flags);
  2344. }
  2345. static void ieee80211_rx_mgmt_auth(struct ieee80211_sub_if_data *sdata,
  2346. struct ieee80211_mgmt *mgmt, size_t len)
  2347. {
  2348. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  2349. u8 bssid[ETH_ALEN];
  2350. u16 auth_alg, auth_transaction, status_code;
  2351. struct sta_info *sta;
  2352. struct ieee80211_event event = {
  2353. .type = MLME_EVENT,
  2354. .u.mlme.data = AUTH_EVENT,
  2355. };
  2356. sdata_assert_lock(sdata);
  2357. if (len < 24 + 6)
  2358. return;
  2359. if (!ifmgd->auth_data || ifmgd->auth_data->done)
  2360. return;
  2361. memcpy(bssid, ifmgd->auth_data->bss->bssid, ETH_ALEN);
  2362. if (!ether_addr_equal(bssid, mgmt->bssid))
  2363. return;
  2364. auth_alg = le16_to_cpu(mgmt->u.auth.auth_alg);
  2365. auth_transaction = le16_to_cpu(mgmt->u.auth.auth_transaction);
  2366. status_code = le16_to_cpu(mgmt->u.auth.status_code);
  2367. if (auth_alg != ifmgd->auth_data->algorithm ||
  2368. auth_transaction != ifmgd->auth_data->expected_transaction) {
  2369. sdata_info(sdata, "%pM unexpected authentication state: alg %d (expected %d) transact %d (expected %d)\n",
  2370. mgmt->sa, auth_alg, ifmgd->auth_data->algorithm,
  2371. auth_transaction,
  2372. ifmgd->auth_data->expected_transaction);
  2373. return;
  2374. }
  2375. if (status_code != WLAN_STATUS_SUCCESS) {
  2376. sdata_info(sdata, "%pM denied authentication (status %d)\n",
  2377. mgmt->sa, status_code);
  2378. ieee80211_destroy_auth_data(sdata, false);
  2379. cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len);
  2380. event.u.mlme.status = MLME_DENIED;
  2381. event.u.mlme.reason = status_code;
  2382. drv_event_callback(sdata->local, sdata, &event);
  2383. return;
  2384. }
  2385. switch (ifmgd->auth_data->algorithm) {
  2386. case WLAN_AUTH_OPEN:
  2387. case WLAN_AUTH_LEAP:
  2388. case WLAN_AUTH_FT:
  2389. case WLAN_AUTH_SAE:
  2390. case WLAN_AUTH_FILS_SK:
  2391. case WLAN_AUTH_FILS_SK_PFS:
  2392. case WLAN_AUTH_FILS_PK:
  2393. break;
  2394. case WLAN_AUTH_SHARED_KEY:
  2395. if (ifmgd->auth_data->expected_transaction != 4) {
  2396. ieee80211_auth_challenge(sdata, mgmt, len);
  2397. /* need another frame */
  2398. return;
  2399. }
  2400. break;
  2401. default:
  2402. WARN_ONCE(1, "invalid auth alg %d",
  2403. ifmgd->auth_data->algorithm);
  2404. return;
  2405. }
  2406. event.u.mlme.status = MLME_SUCCESS;
  2407. drv_event_callback(sdata->local, sdata, &event);
  2408. sdata_info(sdata, "authenticated\n");
  2409. ifmgd->auth_data->done = true;
  2410. ifmgd->auth_data->timeout = jiffies + IEEE80211_AUTH_WAIT_ASSOC;
  2411. ifmgd->auth_data->timeout_started = true;
  2412. run_again(sdata, ifmgd->auth_data->timeout);
  2413. if (ifmgd->auth_data->algorithm == WLAN_AUTH_SAE &&
  2414. ifmgd->auth_data->expected_transaction != 2) {
  2415. /*
  2416. * Report auth frame to user space for processing since another
  2417. * round of Authentication frames is still needed.
  2418. */
  2419. cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len);
  2420. return;
  2421. }
  2422. /* move station state to auth */
  2423. mutex_lock(&sdata->local->sta_mtx);
  2424. sta = sta_info_get(sdata, bssid);
  2425. if (!sta) {
  2426. WARN_ONCE(1, "%s: STA %pM not found", sdata->name, bssid);
  2427. goto out_err;
  2428. }
  2429. if (sta_info_move_state(sta, IEEE80211_STA_AUTH)) {
  2430. sdata_info(sdata, "failed moving %pM to auth\n", bssid);
  2431. goto out_err;
  2432. }
  2433. mutex_unlock(&sdata->local->sta_mtx);
  2434. cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len);
  2435. return;
  2436. out_err:
  2437. mutex_unlock(&sdata->local->sta_mtx);
  2438. /* ignore frame -- wait for timeout */
  2439. }
  2440. #define case_WLAN(type) \
  2441. case WLAN_REASON_##type: return #type
  2442. const char *ieee80211_get_reason_code_string(u16 reason_code)
  2443. {
  2444. switch (reason_code) {
  2445. case_WLAN(UNSPECIFIED);
  2446. case_WLAN(PREV_AUTH_NOT_VALID);
  2447. case_WLAN(DEAUTH_LEAVING);
  2448. case_WLAN(DISASSOC_DUE_TO_INACTIVITY);
  2449. case_WLAN(DISASSOC_AP_BUSY);
  2450. case_WLAN(CLASS2_FRAME_FROM_NONAUTH_STA);
  2451. case_WLAN(CLASS3_FRAME_FROM_NONASSOC_STA);
  2452. case_WLAN(DISASSOC_STA_HAS_LEFT);
  2453. case_WLAN(STA_REQ_ASSOC_WITHOUT_AUTH);
  2454. case_WLAN(DISASSOC_BAD_POWER);
  2455. case_WLAN(DISASSOC_BAD_SUPP_CHAN);
  2456. case_WLAN(INVALID_IE);
  2457. case_WLAN(MIC_FAILURE);
  2458. case_WLAN(4WAY_HANDSHAKE_TIMEOUT);
  2459. case_WLAN(GROUP_KEY_HANDSHAKE_TIMEOUT);
  2460. case_WLAN(IE_DIFFERENT);
  2461. case_WLAN(INVALID_GROUP_CIPHER);
  2462. case_WLAN(INVALID_PAIRWISE_CIPHER);
  2463. case_WLAN(INVALID_AKMP);
  2464. case_WLAN(UNSUPP_RSN_VERSION);
  2465. case_WLAN(INVALID_RSN_IE_CAP);
  2466. case_WLAN(IEEE8021X_FAILED);
  2467. case_WLAN(CIPHER_SUITE_REJECTED);
  2468. case_WLAN(DISASSOC_UNSPECIFIED_QOS);
  2469. case_WLAN(DISASSOC_QAP_NO_BANDWIDTH);
  2470. case_WLAN(DISASSOC_LOW_ACK);
  2471. case_WLAN(DISASSOC_QAP_EXCEED_TXOP);
  2472. case_WLAN(QSTA_LEAVE_QBSS);
  2473. case_WLAN(QSTA_NOT_USE);
  2474. case_WLAN(QSTA_REQUIRE_SETUP);
  2475. case_WLAN(QSTA_TIMEOUT);
  2476. case_WLAN(QSTA_CIPHER_NOT_SUPP);
  2477. case_WLAN(MESH_PEER_CANCELED);
  2478. case_WLAN(MESH_MAX_PEERS);
  2479. case_WLAN(MESH_CONFIG);
  2480. case_WLAN(MESH_CLOSE);
  2481. case_WLAN(MESH_MAX_RETRIES);
  2482. case_WLAN(MESH_CONFIRM_TIMEOUT);
  2483. case_WLAN(MESH_INVALID_GTK);
  2484. case_WLAN(MESH_INCONSISTENT_PARAM);
  2485. case_WLAN(MESH_INVALID_SECURITY);
  2486. case_WLAN(MESH_PATH_ERROR);
  2487. case_WLAN(MESH_PATH_NOFORWARD);
  2488. case_WLAN(MESH_PATH_DEST_UNREACHABLE);
  2489. case_WLAN(MAC_EXISTS_IN_MBSS);
  2490. case_WLAN(MESH_CHAN_REGULATORY);
  2491. case_WLAN(MESH_CHAN);
  2492. default: return "<unknown>";
  2493. }
  2494. }
  2495. static void ieee80211_rx_mgmt_deauth(struct ieee80211_sub_if_data *sdata,
  2496. struct ieee80211_mgmt *mgmt, size_t len)
  2497. {
  2498. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  2499. u16 reason_code = le16_to_cpu(mgmt->u.deauth.reason_code);
  2500. sdata_assert_lock(sdata);
  2501. if (len < 24 + 2)
  2502. return;
  2503. if (!ether_addr_equal(mgmt->bssid, mgmt->sa)) {
  2504. ieee80211_tdls_handle_disconnect(sdata, mgmt->sa, reason_code);
  2505. return;
  2506. }
  2507. if (ifmgd->associated &&
  2508. ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid)) {
  2509. const u8 *bssid = ifmgd->associated->bssid;
  2510. sdata_info(sdata, "deauthenticated from %pM (Reason: %u=%s)\n",
  2511. bssid, reason_code,
  2512. ieee80211_get_reason_code_string(reason_code));
  2513. ieee80211_set_disassoc(sdata, 0, 0, false, NULL);
  2514. ieee80211_report_disconnect(sdata, (u8 *)mgmt, len, false,
  2515. reason_code);
  2516. return;
  2517. }
  2518. if (ifmgd->assoc_data &&
  2519. ether_addr_equal(mgmt->bssid, ifmgd->assoc_data->bss->bssid)) {
  2520. const u8 *bssid = ifmgd->assoc_data->bss->bssid;
  2521. sdata_info(sdata,
  2522. "deauthenticated from %pM while associating (Reason: %u=%s)\n",
  2523. bssid, reason_code,
  2524. ieee80211_get_reason_code_string(reason_code));
  2525. ieee80211_destroy_assoc_data(sdata, false, true);
  2526. cfg80211_rx_mlme_mgmt(sdata->dev, (u8 *)mgmt, len);
  2527. return;
  2528. }
  2529. }
  2530. static void ieee80211_rx_mgmt_disassoc(struct ieee80211_sub_if_data *sdata,
  2531. struct ieee80211_mgmt *mgmt, size_t len)
  2532. {
  2533. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  2534. u16 reason_code;
  2535. sdata_assert_lock(sdata);
  2536. if (len < 24 + 2)
  2537. return;
  2538. if (!ifmgd->associated ||
  2539. !ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid))
  2540. return;
  2541. reason_code = le16_to_cpu(mgmt->u.disassoc.reason_code);
  2542. if (!ether_addr_equal(mgmt->bssid, mgmt->sa)) {
  2543. ieee80211_tdls_handle_disconnect(sdata, mgmt->sa, reason_code);
  2544. return;
  2545. }
  2546. sdata_info(sdata, "disassociated from %pM (Reason: %u=%s)\n",
  2547. mgmt->sa, reason_code,
  2548. ieee80211_get_reason_code_string(reason_code));
  2549. ieee80211_set_disassoc(sdata, 0, 0, false, NULL);
  2550. ieee80211_report_disconnect(sdata, (u8 *)mgmt, len, false, reason_code);
  2551. }
  2552. static void ieee80211_get_rates(struct ieee80211_supported_band *sband,
  2553. u8 *supp_rates, unsigned int supp_rates_len,
  2554. u32 *rates, u32 *basic_rates,
  2555. bool *have_higher_than_11mbit,
  2556. int *min_rate, int *min_rate_index,
  2557. int shift)
  2558. {
  2559. int i, j;
  2560. for (i = 0; i < supp_rates_len; i++) {
  2561. int rate = supp_rates[i] & 0x7f;
  2562. bool is_basic = !!(supp_rates[i] & 0x80);
  2563. if ((rate * 5 * (1 << shift)) > 110)
  2564. *have_higher_than_11mbit = true;
  2565. /*
  2566. * Skip HT and VHT BSS membership selectors since they're not
  2567. * rates.
  2568. *
  2569. * Note: Even though the membership selector and the basic
  2570. * rate flag share the same bit, they are not exactly
  2571. * the same.
  2572. */
  2573. if (supp_rates[i] == (0x80 | BSS_MEMBERSHIP_SELECTOR_HT_PHY) ||
  2574. supp_rates[i] == (0x80 | BSS_MEMBERSHIP_SELECTOR_VHT_PHY))
  2575. continue;
  2576. for (j = 0; j < sband->n_bitrates; j++) {
  2577. struct ieee80211_rate *br;
  2578. int brate;
  2579. br = &sband->bitrates[j];
  2580. brate = DIV_ROUND_UP(br->bitrate, (1 << shift) * 5);
  2581. if (brate == rate) {
  2582. *rates |= BIT(j);
  2583. if (is_basic)
  2584. *basic_rates |= BIT(j);
  2585. if ((rate * 5) < *min_rate) {
  2586. *min_rate = rate * 5;
  2587. *min_rate_index = j;
  2588. }
  2589. break;
  2590. }
  2591. }
  2592. }
  2593. }
  2594. static bool ieee80211_assoc_success(struct ieee80211_sub_if_data *sdata,
  2595. struct cfg80211_bss *cbss,
  2596. struct ieee80211_mgmt *mgmt, size_t len)
  2597. {
  2598. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  2599. struct ieee80211_local *local = sdata->local;
  2600. struct ieee80211_supported_band *sband;
  2601. struct sta_info *sta;
  2602. u8 *pos;
  2603. u16 capab_info, aid;
  2604. struct ieee802_11_elems elems;
  2605. struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
  2606. const struct cfg80211_bss_ies *bss_ies = NULL;
  2607. struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;
  2608. u32 changed = 0;
  2609. int err;
  2610. bool ret;
  2611. /* AssocResp and ReassocResp have identical structure */
  2612. aid = le16_to_cpu(mgmt->u.assoc_resp.aid);
  2613. capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
  2614. /*
  2615. * The 5 MSB of the AID field are reserved
  2616. * (802.11-2016 9.4.1.8 AID field)
  2617. */
  2618. aid &= 0x7ff;
  2619. ifmgd->broken_ap = false;
  2620. if (aid == 0 || aid > IEEE80211_MAX_AID) {
  2621. sdata_info(sdata, "invalid AID value %d (out of range), turn off PS\n",
  2622. aid);
  2623. aid = 0;
  2624. ifmgd->broken_ap = true;
  2625. }
  2626. pos = mgmt->u.assoc_resp.variable;
  2627. ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), false, &elems);
  2628. if (!elems.supp_rates) {
  2629. sdata_info(sdata, "no SuppRates element in AssocResp\n");
  2630. return false;
  2631. }
  2632. ifmgd->aid = aid;
  2633. ifmgd->tdls_chan_switch_prohibited =
  2634. elems.ext_capab && elems.ext_capab_len >= 5 &&
  2635. (elems.ext_capab[4] & WLAN_EXT_CAPA5_TDLS_CH_SW_PROHIBITED);
  2636. /*
  2637. * Some APs are erroneously not including some information in their
  2638. * (re)association response frames. Try to recover by using the data
  2639. * from the beacon or probe response. This seems to afflict mobile
  2640. * 2G/3G/4G wifi routers, reported models include the "Onda PN51T",
  2641. * "Vodafone PocketWiFi 2", "ZTE MF60" and a similar T-Mobile device.
  2642. */
  2643. if ((assoc_data->wmm && !elems.wmm_param) ||
  2644. (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT) &&
  2645. (!elems.ht_cap_elem || !elems.ht_operation)) ||
  2646. (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT) &&
  2647. (!elems.vht_cap_elem || !elems.vht_operation))) {
  2648. const struct cfg80211_bss_ies *ies;
  2649. struct ieee802_11_elems bss_elems;
  2650. rcu_read_lock();
  2651. ies = rcu_dereference(cbss->ies);
  2652. if (ies)
  2653. bss_ies = kmemdup(ies, sizeof(*ies) + ies->len,
  2654. GFP_ATOMIC);
  2655. rcu_read_unlock();
  2656. if (!bss_ies)
  2657. return false;
  2658. ieee802_11_parse_elems(bss_ies->data, bss_ies->len,
  2659. false, &bss_elems);
  2660. if (assoc_data->wmm &&
  2661. !elems.wmm_param && bss_elems.wmm_param) {
  2662. elems.wmm_param = bss_elems.wmm_param;
  2663. sdata_info(sdata,
  2664. "AP bug: WMM param missing from AssocResp\n");
  2665. }
  2666. /*
  2667. * Also check if we requested HT/VHT, otherwise the AP doesn't
  2668. * have to include the IEs in the (re)association response.
  2669. */
  2670. if (!elems.ht_cap_elem && bss_elems.ht_cap_elem &&
  2671. !(ifmgd->flags & IEEE80211_STA_DISABLE_HT)) {
  2672. elems.ht_cap_elem = bss_elems.ht_cap_elem;
  2673. sdata_info(sdata,
  2674. "AP bug: HT capability missing from AssocResp\n");
  2675. }
  2676. if (!elems.ht_operation && bss_elems.ht_operation &&
  2677. !(ifmgd->flags & IEEE80211_STA_DISABLE_HT)) {
  2678. elems.ht_operation = bss_elems.ht_operation;
  2679. sdata_info(sdata,
  2680. "AP bug: HT operation missing from AssocResp\n");
  2681. }
  2682. if (!elems.vht_cap_elem && bss_elems.vht_cap_elem &&
  2683. !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT)) {
  2684. elems.vht_cap_elem = bss_elems.vht_cap_elem;
  2685. sdata_info(sdata,
  2686. "AP bug: VHT capa missing from AssocResp\n");
  2687. }
  2688. if (!elems.vht_operation && bss_elems.vht_operation &&
  2689. !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT)) {
  2690. elems.vht_operation = bss_elems.vht_operation;
  2691. sdata_info(sdata,
  2692. "AP bug: VHT operation missing from AssocResp\n");
  2693. }
  2694. }
  2695. /*
  2696. * We previously checked these in the beacon/probe response, so
  2697. * they should be present here. This is just a safety net.
  2698. */
  2699. if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT) &&
  2700. (!elems.wmm_param || !elems.ht_cap_elem || !elems.ht_operation)) {
  2701. sdata_info(sdata,
  2702. "HT AP is missing WMM params or HT capability/operation\n");
  2703. ret = false;
  2704. goto out;
  2705. }
  2706. if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT) &&
  2707. (!elems.vht_cap_elem || !elems.vht_operation)) {
  2708. sdata_info(sdata,
  2709. "VHT AP is missing VHT capability/operation\n");
  2710. ret = false;
  2711. goto out;
  2712. }
  2713. mutex_lock(&sdata->local->sta_mtx);
  2714. /*
  2715. * station info was already allocated and inserted before
  2716. * the association and should be available to us
  2717. */
  2718. sta = sta_info_get(sdata, cbss->bssid);
  2719. if (WARN_ON(!sta)) {
  2720. mutex_unlock(&sdata->local->sta_mtx);
  2721. ret = false;
  2722. goto out;
  2723. }
  2724. sband = ieee80211_get_sband(sdata);
  2725. if (!sband) {
  2726. mutex_unlock(&sdata->local->sta_mtx);
  2727. ret = false;
  2728. goto out;
  2729. }
  2730. /*
  2731. * If AP doesn't support HT, or it doesn't have HE mandatory IEs, mark
  2732. * HE as disabled. If on the 5GHz band, make sure it supports VHT.
  2733. */
  2734. if (ifmgd->flags & IEEE80211_STA_DISABLE_HT ||
  2735. (sband->band == NL80211_BAND_5GHZ &&
  2736. ifmgd->flags & IEEE80211_STA_DISABLE_VHT) ||
  2737. (!elems.he_cap && !elems.he_operation))
  2738. ifmgd->flags |= IEEE80211_STA_DISABLE_HE;
  2739. if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HE) &&
  2740. (!elems.he_cap || !elems.he_operation)) {
  2741. mutex_unlock(&sdata->local->sta_mtx);
  2742. sdata_info(sdata,
  2743. "HE AP is missing HE capability/operation\n");
  2744. ret = false;
  2745. goto out;
  2746. }
  2747. /* Set up internal HT/VHT capabilities */
  2748. if (elems.ht_cap_elem && !(ifmgd->flags & IEEE80211_STA_DISABLE_HT))
  2749. ieee80211_ht_cap_ie_to_sta_ht_cap(sdata, sband,
  2750. elems.ht_cap_elem, sta);
  2751. if (elems.vht_cap_elem && !(ifmgd->flags & IEEE80211_STA_DISABLE_VHT))
  2752. ieee80211_vht_cap_ie_to_sta_vht_cap(sdata, sband,
  2753. elems.vht_cap_elem, sta);
  2754. if (elems.he_operation && !(ifmgd->flags & IEEE80211_STA_DISABLE_HE) &&
  2755. elems.he_cap) {
  2756. ieee80211_he_cap_ie_to_sta_he_cap(sdata, sband,
  2757. elems.he_cap,
  2758. elems.he_cap_len,
  2759. sta);
  2760. bss_conf->he_support = sta->sta.he_cap.has_he;
  2761. } else {
  2762. bss_conf->he_support = false;
  2763. }
  2764. if (bss_conf->he_support) {
  2765. bss_conf->bss_color =
  2766. le32_get_bits(elems.he_operation->he_oper_params,
  2767. IEEE80211_HE_OPERATION_BSS_COLOR_MASK);
  2768. bss_conf->htc_trig_based_pkt_ext =
  2769. le32_get_bits(elems.he_operation->he_oper_params,
  2770. IEEE80211_HE_OPERATION_DFLT_PE_DURATION_MASK);
  2771. bss_conf->frame_time_rts_th =
  2772. le32_get_bits(elems.he_operation->he_oper_params,
  2773. IEEE80211_HE_OPERATION_RTS_THRESHOLD_MASK);
  2774. bss_conf->multi_sta_back_32bit =
  2775. sta->sta.he_cap.he_cap_elem.mac_cap_info[2] &
  2776. IEEE80211_HE_MAC_CAP2_32BIT_BA_BITMAP;
  2777. bss_conf->ack_enabled =
  2778. sta->sta.he_cap.he_cap_elem.mac_cap_info[2] &
  2779. IEEE80211_HE_MAC_CAP2_ACK_EN;
  2780. bss_conf->uora_exists = !!elems.uora_element;
  2781. if (elems.uora_element)
  2782. bss_conf->uora_ocw_range = elems.uora_element[0];
  2783. /* TODO: OPEN: what happens if BSS color disable is set? */
  2784. }
  2785. /*
  2786. * Some APs, e.g. Netgear WNDR3700, report invalid HT operation data
  2787. * in their association response, so ignore that data for our own
  2788. * configuration. If it changed since the last beacon, we'll get the
  2789. * next beacon and update then.
  2790. */
  2791. /*
  2792. * If an operating mode notification IE is present, override the
  2793. * NSS calculation (that would be done in rate_control_rate_init())
  2794. * and use the # of streams from that element.
  2795. */
  2796. if (elems.opmode_notif &&
  2797. !(*elems.opmode_notif & IEEE80211_OPMODE_NOTIF_RX_NSS_TYPE_BF)) {
  2798. u8 nss;
  2799. nss = *elems.opmode_notif & IEEE80211_OPMODE_NOTIF_RX_NSS_MASK;
  2800. nss >>= IEEE80211_OPMODE_NOTIF_RX_NSS_SHIFT;
  2801. nss += 1;
  2802. sta->sta.rx_nss = nss;
  2803. }
  2804. rate_control_rate_init(sta);
  2805. if (ifmgd->flags & IEEE80211_STA_MFP_ENABLED) {
  2806. set_sta_flag(sta, WLAN_STA_MFP);
  2807. sta->sta.mfp = true;
  2808. } else {
  2809. sta->sta.mfp = false;
  2810. }
  2811. sta->sta.wme = elems.wmm_param && local->hw.queues >= IEEE80211_NUM_ACS;
  2812. err = sta_info_move_state(sta, IEEE80211_STA_ASSOC);
  2813. if (!err && !(ifmgd->flags & IEEE80211_STA_CONTROL_PORT))
  2814. err = sta_info_move_state(sta, IEEE80211_STA_AUTHORIZED);
  2815. if (err) {
  2816. sdata_info(sdata,
  2817. "failed to move station %pM to desired state\n",
  2818. sta->sta.addr);
  2819. WARN_ON(__sta_info_destroy(sta));
  2820. mutex_unlock(&sdata->local->sta_mtx);
  2821. ret = false;
  2822. goto out;
  2823. }
  2824. mutex_unlock(&sdata->local->sta_mtx);
  2825. /*
  2826. * Always handle WMM once after association regardless
  2827. * of the first value the AP uses. Setting -1 here has
  2828. * that effect because the AP values is an unsigned
  2829. * 4-bit value.
  2830. */
  2831. ifmgd->wmm_last_param_set = -1;
  2832. if (ifmgd->flags & IEEE80211_STA_DISABLE_WMM) {
  2833. ieee80211_set_wmm_default(sdata, false, false);
  2834. } else if (!ieee80211_sta_wmm_params(local, sdata, elems.wmm_param,
  2835. elems.wmm_param_len,
  2836. elems.mu_edca_param_set)) {
  2837. /* still enable QoS since we might have HT/VHT */
  2838. ieee80211_set_wmm_default(sdata, false, true);
  2839. /* set the disable-WMM flag in this case to disable
  2840. * tracking WMM parameter changes in the beacon if
  2841. * the parameters weren't actually valid. Doing so
  2842. * avoids changing parameters very strangely when
  2843. * the AP is going back and forth between valid and
  2844. * invalid parameters.
  2845. */
  2846. ifmgd->flags |= IEEE80211_STA_DISABLE_WMM;
  2847. }
  2848. changed |= BSS_CHANGED_QOS;
  2849. if (elems.max_idle_period_ie) {
  2850. bss_conf->max_idle_period =
  2851. le16_to_cpu(elems.max_idle_period_ie->max_idle_period);
  2852. bss_conf->protected_keep_alive =
  2853. !!(elems.max_idle_period_ie->idle_options &
  2854. WLAN_IDLE_OPTIONS_PROTECTED_KEEP_ALIVE);
  2855. changed |= BSS_CHANGED_KEEP_ALIVE;
  2856. } else {
  2857. bss_conf->max_idle_period = 0;
  2858. bss_conf->protected_keep_alive = false;
  2859. }
  2860. /* set AID and assoc capability,
  2861. * ieee80211_set_associated() will tell the driver */
  2862. bss_conf->aid = aid;
  2863. bss_conf->assoc_capability = capab_info;
  2864. ieee80211_set_associated(sdata, cbss, changed);
  2865. /*
  2866. * If we're using 4-addr mode, let the AP know that we're
  2867. * doing so, so that it can create the STA VLAN on its side
  2868. */
  2869. if (ifmgd->use_4addr)
  2870. ieee80211_send_4addr_nullfunc(local, sdata);
  2871. /*
  2872. * Start timer to probe the connection to the AP now.
  2873. * Also start the timer that will detect beacon loss.
  2874. */
  2875. ieee80211_sta_rx_notify(sdata, (struct ieee80211_hdr *)mgmt);
  2876. ieee80211_sta_reset_beacon_monitor(sdata);
  2877. ret = true;
  2878. out:
  2879. kfree(bss_ies);
  2880. return ret;
  2881. }
  2882. static void ieee80211_rx_mgmt_assoc_resp(struct ieee80211_sub_if_data *sdata,
  2883. struct ieee80211_mgmt *mgmt,
  2884. size_t len)
  2885. {
  2886. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  2887. struct ieee80211_mgd_assoc_data *assoc_data = ifmgd->assoc_data;
  2888. u16 capab_info, status_code, aid;
  2889. struct ieee802_11_elems elems;
  2890. int ac, uapsd_queues = -1;
  2891. u8 *pos;
  2892. bool reassoc;
  2893. struct cfg80211_bss *bss;
  2894. struct ieee80211_event event = {
  2895. .type = MLME_EVENT,
  2896. .u.mlme.data = ASSOC_EVENT,
  2897. };
  2898. sdata_assert_lock(sdata);
  2899. if (!assoc_data)
  2900. return;
  2901. if (!ether_addr_equal(assoc_data->bss->bssid, mgmt->bssid))
  2902. return;
  2903. /*
  2904. * AssocResp and ReassocResp have identical structure, so process both
  2905. * of them in this function.
  2906. */
  2907. if (len < 24 + 6)
  2908. return;
  2909. reassoc = ieee80211_is_reassoc_resp(mgmt->frame_control);
  2910. capab_info = le16_to_cpu(mgmt->u.assoc_resp.capab_info);
  2911. status_code = le16_to_cpu(mgmt->u.assoc_resp.status_code);
  2912. aid = le16_to_cpu(mgmt->u.assoc_resp.aid);
  2913. sdata_info(sdata,
  2914. "RX %sssocResp from %pM (capab=0x%x status=%d aid=%d)\n",
  2915. reassoc ? "Rea" : "A", mgmt->sa,
  2916. capab_info, status_code, (u16)(aid & ~(BIT(15) | BIT(14))));
  2917. if (assoc_data->fils_kek_len &&
  2918. fils_decrypt_assoc_resp(sdata, (u8 *)mgmt, &len, assoc_data) < 0)
  2919. return;
  2920. pos = mgmt->u.assoc_resp.variable;
  2921. ieee802_11_parse_elems(pos, len - (pos - (u8 *) mgmt), false, &elems);
  2922. if (status_code == WLAN_STATUS_ASSOC_REJECTED_TEMPORARILY &&
  2923. elems.timeout_int &&
  2924. elems.timeout_int->type == WLAN_TIMEOUT_ASSOC_COMEBACK) {
  2925. u32 tu, ms;
  2926. tu = le32_to_cpu(elems.timeout_int->value);
  2927. ms = tu * 1024 / 1000;
  2928. sdata_info(sdata,
  2929. "%pM rejected association temporarily; comeback duration %u TU (%u ms)\n",
  2930. mgmt->sa, tu, ms);
  2931. assoc_data->timeout = jiffies + msecs_to_jiffies(ms);
  2932. assoc_data->timeout_started = true;
  2933. if (ms > IEEE80211_ASSOC_TIMEOUT)
  2934. run_again(sdata, assoc_data->timeout);
  2935. return;
  2936. }
  2937. bss = assoc_data->bss;
  2938. if (status_code != WLAN_STATUS_SUCCESS) {
  2939. sdata_info(sdata, "%pM denied association (code=%d)\n",
  2940. mgmt->sa, status_code);
  2941. ieee80211_destroy_assoc_data(sdata, false, false);
  2942. event.u.mlme.status = MLME_DENIED;
  2943. event.u.mlme.reason = status_code;
  2944. drv_event_callback(sdata->local, sdata, &event);
  2945. } else {
  2946. if (!ieee80211_assoc_success(sdata, bss, mgmt, len)) {
  2947. /* oops -- internal error -- send timeout for now */
  2948. ieee80211_destroy_assoc_data(sdata, false, false);
  2949. cfg80211_assoc_timeout(sdata->dev, bss);
  2950. return;
  2951. }
  2952. event.u.mlme.status = MLME_SUCCESS;
  2953. drv_event_callback(sdata->local, sdata, &event);
  2954. sdata_info(sdata, "associated\n");
  2955. /*
  2956. * destroy assoc_data afterwards, as otherwise an idle
  2957. * recalc after assoc_data is NULL but before associated
  2958. * is set can cause the interface to go idle
  2959. */
  2960. ieee80211_destroy_assoc_data(sdata, true, false);
  2961. /* get uapsd queues configuration */
  2962. uapsd_queues = 0;
  2963. for (ac = 0; ac < IEEE80211_NUM_ACS; ac++)
  2964. if (sdata->tx_conf[ac].uapsd)
  2965. uapsd_queues |= ieee80211_ac_to_qos_mask[ac];
  2966. }
  2967. cfg80211_rx_assoc_resp(sdata->dev, bss, (u8 *)mgmt, len, uapsd_queues);
  2968. }
  2969. static void ieee80211_rx_bss_info(struct ieee80211_sub_if_data *sdata,
  2970. struct ieee80211_mgmt *mgmt, size_t len,
  2971. struct ieee80211_rx_status *rx_status,
  2972. struct ieee802_11_elems *elems)
  2973. {
  2974. struct ieee80211_local *local = sdata->local;
  2975. struct ieee80211_bss *bss;
  2976. struct ieee80211_channel *channel;
  2977. sdata_assert_lock(sdata);
  2978. channel = ieee80211_get_channel(local->hw.wiphy, rx_status->freq);
  2979. if (!channel)
  2980. return;
  2981. bss = ieee80211_bss_info_update(local, rx_status, mgmt, len, elems,
  2982. channel);
  2983. if (bss) {
  2984. sdata->vif.bss_conf.beacon_rate = bss->beacon_rate;
  2985. ieee80211_rx_bss_put(local, bss);
  2986. }
  2987. }
  2988. static void ieee80211_rx_mgmt_probe_resp(struct ieee80211_sub_if_data *sdata,
  2989. struct sk_buff *skb)
  2990. {
  2991. struct ieee80211_mgmt *mgmt = (void *)skb->data;
  2992. struct ieee80211_if_managed *ifmgd;
  2993. struct ieee80211_rx_status *rx_status = (void *) skb->cb;
  2994. size_t baselen, len = skb->len;
  2995. struct ieee802_11_elems elems;
  2996. ifmgd = &sdata->u.mgd;
  2997. sdata_assert_lock(sdata);
  2998. if (!ether_addr_equal(mgmt->da, sdata->vif.addr))
  2999. return; /* ignore ProbeResp to foreign address */
  3000. baselen = (u8 *) mgmt->u.probe_resp.variable - (u8 *) mgmt;
  3001. if (baselen > len)
  3002. return;
  3003. ieee802_11_parse_elems(mgmt->u.probe_resp.variable, len - baselen,
  3004. false, &elems);
  3005. ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems);
  3006. if (ifmgd->associated &&
  3007. ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid))
  3008. ieee80211_reset_ap_probe(sdata);
  3009. }
  3010. /*
  3011. * This is the canonical list of information elements we care about,
  3012. * the filter code also gives us all changes to the Microsoft OUI
  3013. * (00:50:F2) vendor IE which is used for WMM which we need to track,
  3014. * as well as the DTPC IE (part of the Cisco OUI) used for signaling
  3015. * changes to requested client power.
  3016. *
  3017. * We implement beacon filtering in software since that means we can
  3018. * avoid processing the frame here and in cfg80211, and userspace
  3019. * will not be able to tell whether the hardware supports it or not.
  3020. *
  3021. * XXX: This list needs to be dynamic -- userspace needs to be able to
  3022. * add items it requires. It also needs to be able to tell us to
  3023. * look out for other vendor IEs.
  3024. */
  3025. static const u64 care_about_ies =
  3026. (1ULL << WLAN_EID_COUNTRY) |
  3027. (1ULL << WLAN_EID_ERP_INFO) |
  3028. (1ULL << WLAN_EID_CHANNEL_SWITCH) |
  3029. (1ULL << WLAN_EID_PWR_CONSTRAINT) |
  3030. (1ULL << WLAN_EID_HT_CAPABILITY) |
  3031. (1ULL << WLAN_EID_HT_OPERATION) |
  3032. (1ULL << WLAN_EID_EXT_CHANSWITCH_ANN);
  3033. static void ieee80211_handle_beacon_sig(struct ieee80211_sub_if_data *sdata,
  3034. struct ieee80211_if_managed *ifmgd,
  3035. struct ieee80211_bss_conf *bss_conf,
  3036. struct ieee80211_local *local,
  3037. struct ieee80211_rx_status *rx_status)
  3038. {
  3039. /* Track average RSSI from the Beacon frames of the current AP */
  3040. if (ifmgd->flags & IEEE80211_STA_RESET_SIGNAL_AVE) {
  3041. ifmgd->flags &= ~IEEE80211_STA_RESET_SIGNAL_AVE;
  3042. ewma_beacon_signal_init(&ifmgd->ave_beacon_signal);
  3043. ifmgd->last_cqm_event_signal = 0;
  3044. ifmgd->count_beacon_signal = 1;
  3045. ifmgd->last_ave_beacon_signal = 0;
  3046. } else {
  3047. ifmgd->count_beacon_signal++;
  3048. }
  3049. ewma_beacon_signal_add(&ifmgd->ave_beacon_signal, -rx_status->signal);
  3050. if (ifmgd->rssi_min_thold != ifmgd->rssi_max_thold &&
  3051. ifmgd->count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT) {
  3052. int sig = -ewma_beacon_signal_read(&ifmgd->ave_beacon_signal);
  3053. int last_sig = ifmgd->last_ave_beacon_signal;
  3054. struct ieee80211_event event = {
  3055. .type = RSSI_EVENT,
  3056. };
  3057. /*
  3058. * if signal crosses either of the boundaries, invoke callback
  3059. * with appropriate parameters
  3060. */
  3061. if (sig > ifmgd->rssi_max_thold &&
  3062. (last_sig <= ifmgd->rssi_min_thold || last_sig == 0)) {
  3063. ifmgd->last_ave_beacon_signal = sig;
  3064. event.u.rssi.data = RSSI_EVENT_HIGH;
  3065. drv_event_callback(local, sdata, &event);
  3066. } else if (sig < ifmgd->rssi_min_thold &&
  3067. (last_sig >= ifmgd->rssi_max_thold ||
  3068. last_sig == 0)) {
  3069. ifmgd->last_ave_beacon_signal = sig;
  3070. event.u.rssi.data = RSSI_EVENT_LOW;
  3071. drv_event_callback(local, sdata, &event);
  3072. }
  3073. }
  3074. if (bss_conf->cqm_rssi_thold &&
  3075. ifmgd->count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT &&
  3076. !(sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_CQM_RSSI)) {
  3077. int sig = -ewma_beacon_signal_read(&ifmgd->ave_beacon_signal);
  3078. int last_event = ifmgd->last_cqm_event_signal;
  3079. int thold = bss_conf->cqm_rssi_thold;
  3080. int hyst = bss_conf->cqm_rssi_hyst;
  3081. if (sig < thold &&
  3082. (last_event == 0 || sig < last_event - hyst)) {
  3083. ifmgd->last_cqm_event_signal = sig;
  3084. ieee80211_cqm_rssi_notify(
  3085. &sdata->vif,
  3086. NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW,
  3087. sig, GFP_KERNEL);
  3088. } else if (sig > thold &&
  3089. (last_event == 0 || sig > last_event + hyst)) {
  3090. ifmgd->last_cqm_event_signal = sig;
  3091. ieee80211_cqm_rssi_notify(
  3092. &sdata->vif,
  3093. NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH,
  3094. sig, GFP_KERNEL);
  3095. }
  3096. }
  3097. if (bss_conf->cqm_rssi_low &&
  3098. ifmgd->count_beacon_signal >= IEEE80211_SIGNAL_AVE_MIN_COUNT) {
  3099. int sig = -ewma_beacon_signal_read(&ifmgd->ave_beacon_signal);
  3100. int last_event = ifmgd->last_cqm_event_signal;
  3101. int low = bss_conf->cqm_rssi_low;
  3102. int high = bss_conf->cqm_rssi_high;
  3103. if (sig < low &&
  3104. (last_event == 0 || last_event >= low)) {
  3105. ifmgd->last_cqm_event_signal = sig;
  3106. ieee80211_cqm_rssi_notify(
  3107. &sdata->vif,
  3108. NL80211_CQM_RSSI_THRESHOLD_EVENT_LOW,
  3109. sig, GFP_KERNEL);
  3110. } else if (sig > high &&
  3111. (last_event == 0 || last_event <= high)) {
  3112. ifmgd->last_cqm_event_signal = sig;
  3113. ieee80211_cqm_rssi_notify(
  3114. &sdata->vif,
  3115. NL80211_CQM_RSSI_THRESHOLD_EVENT_HIGH,
  3116. sig, GFP_KERNEL);
  3117. }
  3118. }
  3119. }
  3120. static void ieee80211_rx_mgmt_beacon(struct ieee80211_sub_if_data *sdata,
  3121. struct ieee80211_mgmt *mgmt, size_t len,
  3122. struct ieee80211_rx_status *rx_status)
  3123. {
  3124. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  3125. struct ieee80211_bss_conf *bss_conf = &sdata->vif.bss_conf;
  3126. size_t baselen;
  3127. struct ieee802_11_elems elems;
  3128. struct ieee80211_local *local = sdata->local;
  3129. struct ieee80211_chanctx_conf *chanctx_conf;
  3130. struct ieee80211_channel *chan;
  3131. struct sta_info *sta;
  3132. u32 changed = 0;
  3133. bool erp_valid;
  3134. u8 erp_value = 0;
  3135. u32 ncrc;
  3136. u8 *bssid;
  3137. u8 deauth_buf[IEEE80211_DEAUTH_FRAME_LEN];
  3138. sdata_assert_lock(sdata);
  3139. /* Process beacon from the current BSS */
  3140. baselen = (u8 *) mgmt->u.beacon.variable - (u8 *) mgmt;
  3141. if (baselen > len)
  3142. return;
  3143. rcu_read_lock();
  3144. chanctx_conf = rcu_dereference(sdata->vif.chanctx_conf);
  3145. if (!chanctx_conf) {
  3146. rcu_read_unlock();
  3147. return;
  3148. }
  3149. if (rx_status->freq != chanctx_conf->def.chan->center_freq) {
  3150. rcu_read_unlock();
  3151. return;
  3152. }
  3153. chan = chanctx_conf->def.chan;
  3154. rcu_read_unlock();
  3155. if (ifmgd->assoc_data && ifmgd->assoc_data->need_beacon &&
  3156. ether_addr_equal(mgmt->bssid, ifmgd->assoc_data->bss->bssid)) {
  3157. ieee802_11_parse_elems(mgmt->u.beacon.variable,
  3158. len - baselen, false, &elems);
  3159. ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems);
  3160. if (elems.tim && !elems.parse_error) {
  3161. const struct ieee80211_tim_ie *tim_ie = elems.tim;
  3162. ifmgd->dtim_period = tim_ie->dtim_period;
  3163. }
  3164. ifmgd->have_beacon = true;
  3165. ifmgd->assoc_data->need_beacon = false;
  3166. if (ieee80211_hw_check(&local->hw, TIMING_BEACON_ONLY)) {
  3167. sdata->vif.bss_conf.sync_tsf =
  3168. le64_to_cpu(mgmt->u.beacon.timestamp);
  3169. sdata->vif.bss_conf.sync_device_ts =
  3170. rx_status->device_timestamp;
  3171. if (elems.tim)
  3172. sdata->vif.bss_conf.sync_dtim_count =
  3173. elems.tim->dtim_count;
  3174. else
  3175. sdata->vif.bss_conf.sync_dtim_count = 0;
  3176. }
  3177. /* continue assoc process */
  3178. ifmgd->assoc_data->timeout = jiffies;
  3179. ifmgd->assoc_data->timeout_started = true;
  3180. run_again(sdata, ifmgd->assoc_data->timeout);
  3181. return;
  3182. }
  3183. if (!ifmgd->associated ||
  3184. !ether_addr_equal(mgmt->bssid, ifmgd->associated->bssid))
  3185. return;
  3186. bssid = ifmgd->associated->bssid;
  3187. if (!(rx_status->flag & RX_FLAG_NO_SIGNAL_VAL))
  3188. ieee80211_handle_beacon_sig(sdata, ifmgd, bss_conf,
  3189. local, rx_status);
  3190. if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL) {
  3191. mlme_dbg_ratelimited(sdata,
  3192. "cancelling AP probe due to a received beacon\n");
  3193. ieee80211_reset_ap_probe(sdata);
  3194. }
  3195. /*
  3196. * Push the beacon loss detection into the future since
  3197. * we are processing a beacon from the AP just now.
  3198. */
  3199. ieee80211_sta_reset_beacon_monitor(sdata);
  3200. ncrc = crc32_be(0, (void *)&mgmt->u.beacon.beacon_int, 4);
  3201. ncrc = ieee802_11_parse_elems_crc(mgmt->u.beacon.variable,
  3202. len - baselen, false, &elems,
  3203. care_about_ies, ncrc);
  3204. if (ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK) &&
  3205. ieee80211_check_tim(elems.tim, elems.tim_len, ifmgd->aid)) {
  3206. if (local->hw.conf.dynamic_ps_timeout > 0) {
  3207. if (local->hw.conf.flags & IEEE80211_CONF_PS) {
  3208. local->hw.conf.flags &= ~IEEE80211_CONF_PS;
  3209. ieee80211_hw_config(local,
  3210. IEEE80211_CONF_CHANGE_PS);
  3211. }
  3212. ieee80211_send_nullfunc(local, sdata, false);
  3213. } else if (!local->pspolling && sdata->u.mgd.powersave) {
  3214. local->pspolling = true;
  3215. /*
  3216. * Here is assumed that the driver will be
  3217. * able to send ps-poll frame and receive a
  3218. * response even though power save mode is
  3219. * enabled, but some drivers might require
  3220. * to disable power save here. This needs
  3221. * to be investigated.
  3222. */
  3223. ieee80211_send_pspoll(local, sdata);
  3224. }
  3225. }
  3226. if (sdata->vif.p2p ||
  3227. sdata->vif.driver_flags & IEEE80211_VIF_GET_NOA_UPDATE) {
  3228. struct ieee80211_p2p_noa_attr noa = {};
  3229. int ret;
  3230. ret = cfg80211_get_p2p_attr(mgmt->u.beacon.variable,
  3231. len - baselen,
  3232. IEEE80211_P2P_ATTR_ABSENCE_NOTICE,
  3233. (u8 *) &noa, sizeof(noa));
  3234. if (ret >= 2) {
  3235. if (sdata->u.mgd.p2p_noa_index != noa.index) {
  3236. /* valid noa_attr and index changed */
  3237. sdata->u.mgd.p2p_noa_index = noa.index;
  3238. memcpy(&bss_conf->p2p_noa_attr, &noa, sizeof(noa));
  3239. changed |= BSS_CHANGED_P2P_PS;
  3240. /*
  3241. * make sure we update all information, the CRC
  3242. * mechanism doesn't look at P2P attributes.
  3243. */
  3244. ifmgd->beacon_crc_valid = false;
  3245. }
  3246. } else if (sdata->u.mgd.p2p_noa_index != -1) {
  3247. /* noa_attr not found and we had valid noa_attr before */
  3248. sdata->u.mgd.p2p_noa_index = -1;
  3249. memset(&bss_conf->p2p_noa_attr, 0, sizeof(bss_conf->p2p_noa_attr));
  3250. changed |= BSS_CHANGED_P2P_PS;
  3251. ifmgd->beacon_crc_valid = false;
  3252. }
  3253. }
  3254. if (ifmgd->csa_waiting_bcn)
  3255. ieee80211_chswitch_post_beacon(sdata);
  3256. /*
  3257. * Update beacon timing and dtim count on every beacon appearance. This
  3258. * will allow the driver to use the most updated values. Do it before
  3259. * comparing this one with last received beacon.
  3260. * IMPORTANT: These parameters would possibly be out of sync by the time
  3261. * the driver will use them. The synchronized view is currently
  3262. * guaranteed only in certain callbacks.
  3263. */
  3264. if (ieee80211_hw_check(&local->hw, TIMING_BEACON_ONLY)) {
  3265. sdata->vif.bss_conf.sync_tsf =
  3266. le64_to_cpu(mgmt->u.beacon.timestamp);
  3267. sdata->vif.bss_conf.sync_device_ts =
  3268. rx_status->device_timestamp;
  3269. if (elems.tim)
  3270. sdata->vif.bss_conf.sync_dtim_count =
  3271. elems.tim->dtim_count;
  3272. else
  3273. sdata->vif.bss_conf.sync_dtim_count = 0;
  3274. }
  3275. if (ncrc == ifmgd->beacon_crc && ifmgd->beacon_crc_valid)
  3276. return;
  3277. ifmgd->beacon_crc = ncrc;
  3278. ifmgd->beacon_crc_valid = true;
  3279. ieee80211_rx_bss_info(sdata, mgmt, len, rx_status, &elems);
  3280. ieee80211_sta_process_chanswitch(sdata, rx_status->mactime,
  3281. rx_status->device_timestamp,
  3282. &elems, true);
  3283. if (!(ifmgd->flags & IEEE80211_STA_DISABLE_WMM) &&
  3284. ieee80211_sta_wmm_params(local, sdata, elems.wmm_param,
  3285. elems.wmm_param_len,
  3286. elems.mu_edca_param_set))
  3287. changed |= BSS_CHANGED_QOS;
  3288. /*
  3289. * If we haven't had a beacon before, tell the driver about the
  3290. * DTIM period (and beacon timing if desired) now.
  3291. */
  3292. if (!ifmgd->have_beacon) {
  3293. /* a few bogus AP send dtim_period = 0 or no TIM IE */
  3294. if (elems.tim)
  3295. bss_conf->dtim_period = elems.tim->dtim_period ?: 1;
  3296. else
  3297. bss_conf->dtim_period = 1;
  3298. changed |= BSS_CHANGED_BEACON_INFO;
  3299. ifmgd->have_beacon = true;
  3300. mutex_lock(&local->iflist_mtx);
  3301. ieee80211_recalc_ps(local);
  3302. mutex_unlock(&local->iflist_mtx);
  3303. ieee80211_recalc_ps_vif(sdata);
  3304. }
  3305. if (elems.erp_info) {
  3306. erp_valid = true;
  3307. erp_value = elems.erp_info[0];
  3308. } else {
  3309. erp_valid = false;
  3310. }
  3311. changed |= ieee80211_handle_bss_capability(sdata,
  3312. le16_to_cpu(mgmt->u.beacon.capab_info),
  3313. erp_valid, erp_value);
  3314. mutex_lock(&local->sta_mtx);
  3315. sta = sta_info_get(sdata, bssid);
  3316. if (ieee80211_config_bw(sdata, sta,
  3317. elems.ht_cap_elem, elems.ht_operation,
  3318. elems.vht_operation, elems.he_operation,
  3319. bssid, &changed)) {
  3320. mutex_unlock(&local->sta_mtx);
  3321. sdata_info(sdata,
  3322. "failed to follow AP %pM bandwidth change, disconnect\n",
  3323. bssid);
  3324. ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
  3325. WLAN_REASON_DEAUTH_LEAVING,
  3326. true, deauth_buf);
  3327. ieee80211_report_disconnect(sdata, deauth_buf,
  3328. sizeof(deauth_buf), true,
  3329. WLAN_REASON_DEAUTH_LEAVING);
  3330. return;
  3331. }
  3332. if (sta && elems.opmode_notif)
  3333. ieee80211_vht_handle_opmode(sdata, sta, *elems.opmode_notif,
  3334. rx_status->band);
  3335. mutex_unlock(&local->sta_mtx);
  3336. changed |= ieee80211_handle_pwr_constr(sdata, chan, mgmt,
  3337. elems.country_elem,
  3338. elems.country_elem_len,
  3339. elems.pwr_constr_elem,
  3340. elems.cisco_dtpc_elem);
  3341. ieee80211_bss_info_change_notify(sdata, changed);
  3342. }
  3343. void ieee80211_sta_rx_queued_mgmt(struct ieee80211_sub_if_data *sdata,
  3344. struct sk_buff *skb)
  3345. {
  3346. struct ieee80211_rx_status *rx_status;
  3347. struct ieee80211_mgmt *mgmt;
  3348. u16 fc;
  3349. struct ieee802_11_elems elems;
  3350. int ies_len;
  3351. rx_status = (struct ieee80211_rx_status *) skb->cb;
  3352. mgmt = (struct ieee80211_mgmt *) skb->data;
  3353. fc = le16_to_cpu(mgmt->frame_control);
  3354. sdata_lock(sdata);
  3355. switch (fc & IEEE80211_FCTL_STYPE) {
  3356. case IEEE80211_STYPE_BEACON:
  3357. ieee80211_rx_mgmt_beacon(sdata, mgmt, skb->len, rx_status);
  3358. break;
  3359. case IEEE80211_STYPE_PROBE_RESP:
  3360. ieee80211_rx_mgmt_probe_resp(sdata, skb);
  3361. break;
  3362. case IEEE80211_STYPE_AUTH:
  3363. ieee80211_rx_mgmt_auth(sdata, mgmt, skb->len);
  3364. break;
  3365. case IEEE80211_STYPE_DEAUTH:
  3366. ieee80211_rx_mgmt_deauth(sdata, mgmt, skb->len);
  3367. break;
  3368. case IEEE80211_STYPE_DISASSOC:
  3369. ieee80211_rx_mgmt_disassoc(sdata, mgmt, skb->len);
  3370. break;
  3371. case IEEE80211_STYPE_ASSOC_RESP:
  3372. case IEEE80211_STYPE_REASSOC_RESP:
  3373. ieee80211_rx_mgmt_assoc_resp(sdata, mgmt, skb->len);
  3374. break;
  3375. case IEEE80211_STYPE_ACTION:
  3376. if (mgmt->u.action.category == WLAN_CATEGORY_SPECTRUM_MGMT) {
  3377. ies_len = skb->len -
  3378. offsetof(struct ieee80211_mgmt,
  3379. u.action.u.chan_switch.variable);
  3380. if (ies_len < 0)
  3381. break;
  3382. ieee802_11_parse_elems(
  3383. mgmt->u.action.u.chan_switch.variable,
  3384. ies_len, true, &elems);
  3385. if (elems.parse_error)
  3386. break;
  3387. ieee80211_sta_process_chanswitch(sdata,
  3388. rx_status->mactime,
  3389. rx_status->device_timestamp,
  3390. &elems, false);
  3391. } else if (mgmt->u.action.category == WLAN_CATEGORY_PUBLIC) {
  3392. ies_len = skb->len -
  3393. offsetof(struct ieee80211_mgmt,
  3394. u.action.u.ext_chan_switch.variable);
  3395. if (ies_len < 0)
  3396. break;
  3397. ieee802_11_parse_elems(
  3398. mgmt->u.action.u.ext_chan_switch.variable,
  3399. ies_len, true, &elems);
  3400. if (elems.parse_error)
  3401. break;
  3402. /* for the handling code pretend this was also an IE */
  3403. elems.ext_chansw_ie =
  3404. &mgmt->u.action.u.ext_chan_switch.data;
  3405. ieee80211_sta_process_chanswitch(sdata,
  3406. rx_status->mactime,
  3407. rx_status->device_timestamp,
  3408. &elems, false);
  3409. }
  3410. break;
  3411. }
  3412. sdata_unlock(sdata);
  3413. }
  3414. static void ieee80211_sta_timer(struct timer_list *t)
  3415. {
  3416. struct ieee80211_sub_if_data *sdata =
  3417. from_timer(sdata, t, u.mgd.timer);
  3418. ieee80211_queue_work(&sdata->local->hw, &sdata->work);
  3419. }
  3420. static void ieee80211_sta_connection_lost(struct ieee80211_sub_if_data *sdata,
  3421. u8 *bssid, u8 reason, bool tx)
  3422. {
  3423. u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
  3424. ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH, reason,
  3425. tx, frame_buf);
  3426. ieee80211_report_disconnect(sdata, frame_buf, sizeof(frame_buf), true,
  3427. reason);
  3428. }
  3429. static int ieee80211_auth(struct ieee80211_sub_if_data *sdata)
  3430. {
  3431. struct ieee80211_local *local = sdata->local;
  3432. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  3433. struct ieee80211_mgd_auth_data *auth_data = ifmgd->auth_data;
  3434. u32 tx_flags = 0;
  3435. u16 trans = 1;
  3436. u16 status = 0;
  3437. u16 prepare_tx_duration = 0;
  3438. sdata_assert_lock(sdata);
  3439. if (WARN_ON_ONCE(!auth_data))
  3440. return -EINVAL;
  3441. auth_data->tries++;
  3442. if (auth_data->tries > IEEE80211_AUTH_MAX_TRIES) {
  3443. sdata_info(sdata, "authentication with %pM timed out\n",
  3444. auth_data->bss->bssid);
  3445. /*
  3446. * Most likely AP is not in the range so remove the
  3447. * bss struct for that AP.
  3448. */
  3449. cfg80211_unlink_bss(local->hw.wiphy, auth_data->bss);
  3450. return -ETIMEDOUT;
  3451. }
  3452. if (auth_data->algorithm == WLAN_AUTH_SAE)
  3453. prepare_tx_duration =
  3454. jiffies_to_msecs(IEEE80211_AUTH_TIMEOUT_SAE);
  3455. drv_mgd_prepare_tx(local, sdata, prepare_tx_duration);
  3456. sdata_info(sdata, "send auth to %pM (try %d/%d)\n",
  3457. auth_data->bss->bssid, auth_data->tries,
  3458. IEEE80211_AUTH_MAX_TRIES);
  3459. auth_data->expected_transaction = 2;
  3460. if (auth_data->algorithm == WLAN_AUTH_SAE) {
  3461. trans = auth_data->sae_trans;
  3462. status = auth_data->sae_status;
  3463. auth_data->expected_transaction = trans;
  3464. }
  3465. if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
  3466. tx_flags = IEEE80211_TX_CTL_REQ_TX_STATUS |
  3467. IEEE80211_TX_INTFL_MLME_CONN_TX;
  3468. ieee80211_send_auth(sdata, trans, auth_data->algorithm, status,
  3469. auth_data->data, auth_data->data_len,
  3470. auth_data->bss->bssid,
  3471. auth_data->bss->bssid, NULL, 0, 0,
  3472. tx_flags);
  3473. if (tx_flags == 0) {
  3474. if (auth_data->algorithm == WLAN_AUTH_SAE)
  3475. auth_data->timeout = jiffies +
  3476. IEEE80211_AUTH_TIMEOUT_SAE;
  3477. else
  3478. auth_data->timeout = jiffies + IEEE80211_AUTH_TIMEOUT;
  3479. } else {
  3480. auth_data->timeout =
  3481. round_jiffies_up(jiffies + IEEE80211_AUTH_TIMEOUT_LONG);
  3482. }
  3483. auth_data->timeout_started = true;
  3484. run_again(sdata, auth_data->timeout);
  3485. return 0;
  3486. }
  3487. static int ieee80211_do_assoc(struct ieee80211_sub_if_data *sdata)
  3488. {
  3489. struct ieee80211_mgd_assoc_data *assoc_data = sdata->u.mgd.assoc_data;
  3490. struct ieee80211_local *local = sdata->local;
  3491. sdata_assert_lock(sdata);
  3492. assoc_data->tries++;
  3493. if (assoc_data->tries > IEEE80211_ASSOC_MAX_TRIES) {
  3494. sdata_info(sdata, "association with %pM timed out\n",
  3495. assoc_data->bss->bssid);
  3496. /*
  3497. * Most likely AP is not in the range so remove the
  3498. * bss struct for that AP.
  3499. */
  3500. cfg80211_unlink_bss(local->hw.wiphy, assoc_data->bss);
  3501. return -ETIMEDOUT;
  3502. }
  3503. sdata_info(sdata, "associate with %pM (try %d/%d)\n",
  3504. assoc_data->bss->bssid, assoc_data->tries,
  3505. IEEE80211_ASSOC_MAX_TRIES);
  3506. ieee80211_send_assoc(sdata);
  3507. if (!ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) {
  3508. assoc_data->timeout = jiffies + IEEE80211_ASSOC_TIMEOUT;
  3509. assoc_data->timeout_started = true;
  3510. run_again(sdata, assoc_data->timeout);
  3511. } else {
  3512. assoc_data->timeout =
  3513. round_jiffies_up(jiffies +
  3514. IEEE80211_ASSOC_TIMEOUT_LONG);
  3515. assoc_data->timeout_started = true;
  3516. run_again(sdata, assoc_data->timeout);
  3517. }
  3518. return 0;
  3519. }
  3520. void ieee80211_mgd_conn_tx_status(struct ieee80211_sub_if_data *sdata,
  3521. __le16 fc, bool acked)
  3522. {
  3523. struct ieee80211_local *local = sdata->local;
  3524. sdata->u.mgd.status_fc = fc;
  3525. sdata->u.mgd.status_acked = acked;
  3526. sdata->u.mgd.status_received = true;
  3527. ieee80211_queue_work(&local->hw, &sdata->work);
  3528. }
  3529. void ieee80211_sta_work(struct ieee80211_sub_if_data *sdata)
  3530. {
  3531. struct ieee80211_local *local = sdata->local;
  3532. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  3533. sdata_lock(sdata);
  3534. if (ifmgd->status_received) {
  3535. __le16 fc = ifmgd->status_fc;
  3536. bool status_acked = ifmgd->status_acked;
  3537. ifmgd->status_received = false;
  3538. if (ifmgd->auth_data && ieee80211_is_auth(fc)) {
  3539. if (status_acked) {
  3540. if (ifmgd->auth_data->algorithm ==
  3541. WLAN_AUTH_SAE)
  3542. ifmgd->auth_data->timeout =
  3543. jiffies +
  3544. IEEE80211_AUTH_TIMEOUT_SAE;
  3545. else
  3546. ifmgd->auth_data->timeout =
  3547. jiffies +
  3548. IEEE80211_AUTH_TIMEOUT_SHORT;
  3549. run_again(sdata, ifmgd->auth_data->timeout);
  3550. } else {
  3551. ifmgd->auth_data->timeout = jiffies - 1;
  3552. }
  3553. ifmgd->auth_data->timeout_started = true;
  3554. } else if (ifmgd->assoc_data &&
  3555. (ieee80211_is_assoc_req(fc) ||
  3556. ieee80211_is_reassoc_req(fc))) {
  3557. if (status_acked) {
  3558. ifmgd->assoc_data->timeout =
  3559. jiffies + IEEE80211_ASSOC_TIMEOUT_SHORT;
  3560. run_again(sdata, ifmgd->assoc_data->timeout);
  3561. } else {
  3562. ifmgd->assoc_data->timeout = jiffies - 1;
  3563. }
  3564. ifmgd->assoc_data->timeout_started = true;
  3565. }
  3566. }
  3567. if (ifmgd->auth_data && ifmgd->auth_data->timeout_started &&
  3568. time_after(jiffies, ifmgd->auth_data->timeout)) {
  3569. if (ifmgd->auth_data->done) {
  3570. /*
  3571. * ok ... we waited for assoc but userspace didn't,
  3572. * so let's just kill the auth data
  3573. */
  3574. ieee80211_destroy_auth_data(sdata, false);
  3575. } else if (ieee80211_auth(sdata)) {
  3576. u8 bssid[ETH_ALEN];
  3577. struct ieee80211_event event = {
  3578. .type = MLME_EVENT,
  3579. .u.mlme.data = AUTH_EVENT,
  3580. .u.mlme.status = MLME_TIMEOUT,
  3581. };
  3582. memcpy(bssid, ifmgd->auth_data->bss->bssid, ETH_ALEN);
  3583. ieee80211_destroy_auth_data(sdata, false);
  3584. cfg80211_auth_timeout(sdata->dev, bssid);
  3585. drv_event_callback(sdata->local, sdata, &event);
  3586. }
  3587. } else if (ifmgd->auth_data && ifmgd->auth_data->timeout_started)
  3588. run_again(sdata, ifmgd->auth_data->timeout);
  3589. if (ifmgd->assoc_data && ifmgd->assoc_data->timeout_started &&
  3590. time_after(jiffies, ifmgd->assoc_data->timeout)) {
  3591. if ((ifmgd->assoc_data->need_beacon && !ifmgd->have_beacon) ||
  3592. ieee80211_do_assoc(sdata)) {
  3593. struct cfg80211_bss *bss = ifmgd->assoc_data->bss;
  3594. struct ieee80211_event event = {
  3595. .type = MLME_EVENT,
  3596. .u.mlme.data = ASSOC_EVENT,
  3597. .u.mlme.status = MLME_TIMEOUT,
  3598. };
  3599. ieee80211_destroy_assoc_data(sdata, false, false);
  3600. cfg80211_assoc_timeout(sdata->dev, bss);
  3601. drv_event_callback(sdata->local, sdata, &event);
  3602. }
  3603. } else if (ifmgd->assoc_data && ifmgd->assoc_data->timeout_started)
  3604. run_again(sdata, ifmgd->assoc_data->timeout);
  3605. if (ifmgd->flags & IEEE80211_STA_CONNECTION_POLL &&
  3606. ifmgd->associated) {
  3607. u8 bssid[ETH_ALEN];
  3608. int max_tries;
  3609. memcpy(bssid, ifmgd->associated->bssid, ETH_ALEN);
  3610. if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS))
  3611. max_tries = max_nullfunc_tries;
  3612. else
  3613. max_tries = max_probe_tries;
  3614. /* ACK received for nullfunc probing frame */
  3615. if (!ifmgd->probe_send_count)
  3616. ieee80211_reset_ap_probe(sdata);
  3617. else if (ifmgd->nullfunc_failed) {
  3618. if (ifmgd->probe_send_count < max_tries) {
  3619. mlme_dbg(sdata,
  3620. "No ack for nullfunc frame to AP %pM, try %d/%i\n",
  3621. bssid, ifmgd->probe_send_count,
  3622. max_tries);
  3623. ieee80211_mgd_probe_ap_send(sdata);
  3624. } else {
  3625. mlme_dbg(sdata,
  3626. "No ack for nullfunc frame to AP %pM, disconnecting.\n",
  3627. bssid);
  3628. ieee80211_sta_connection_lost(sdata, bssid,
  3629. WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY,
  3630. false);
  3631. }
  3632. } else if (time_is_after_jiffies(ifmgd->probe_timeout))
  3633. run_again(sdata, ifmgd->probe_timeout);
  3634. else if (ieee80211_hw_check(&local->hw, REPORTS_TX_ACK_STATUS)) {
  3635. mlme_dbg(sdata,
  3636. "Failed to send nullfunc to AP %pM after %dms, disconnecting\n",
  3637. bssid, probe_wait_ms);
  3638. ieee80211_sta_connection_lost(sdata, bssid,
  3639. WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY, false);
  3640. } else if (ifmgd->probe_send_count < max_tries) {
  3641. mlme_dbg(sdata,
  3642. "No probe response from AP %pM after %dms, try %d/%i\n",
  3643. bssid, probe_wait_ms,
  3644. ifmgd->probe_send_count, max_tries);
  3645. ieee80211_mgd_probe_ap_send(sdata);
  3646. } else {
  3647. /*
  3648. * We actually lost the connection ... or did we?
  3649. * Let's make sure!
  3650. */
  3651. mlme_dbg(sdata,
  3652. "No probe response from AP %pM after %dms, disconnecting.\n",
  3653. bssid, probe_wait_ms);
  3654. ieee80211_sta_connection_lost(sdata, bssid,
  3655. WLAN_REASON_DISASSOC_DUE_TO_INACTIVITY, false);
  3656. }
  3657. }
  3658. sdata_unlock(sdata);
  3659. }
  3660. static void ieee80211_sta_bcn_mon_timer(struct timer_list *t)
  3661. {
  3662. struct ieee80211_sub_if_data *sdata =
  3663. from_timer(sdata, t, u.mgd.bcn_mon_timer);
  3664. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  3665. if (sdata->vif.csa_active && !ifmgd->csa_waiting_bcn)
  3666. return;
  3667. sdata->u.mgd.connection_loss = false;
  3668. ieee80211_queue_work(&sdata->local->hw,
  3669. &sdata->u.mgd.beacon_connection_loss_work);
  3670. }
  3671. static void ieee80211_sta_conn_mon_timer(struct timer_list *t)
  3672. {
  3673. struct ieee80211_sub_if_data *sdata =
  3674. from_timer(sdata, t, u.mgd.conn_mon_timer);
  3675. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  3676. struct ieee80211_local *local = sdata->local;
  3677. if (sdata->vif.csa_active && !ifmgd->csa_waiting_bcn)
  3678. return;
  3679. ieee80211_queue_work(&local->hw, &ifmgd->monitor_work);
  3680. }
  3681. static void ieee80211_sta_monitor_work(struct work_struct *work)
  3682. {
  3683. struct ieee80211_sub_if_data *sdata =
  3684. container_of(work, struct ieee80211_sub_if_data,
  3685. u.mgd.monitor_work);
  3686. ieee80211_mgd_probe_ap(sdata, false);
  3687. }
  3688. static void ieee80211_restart_sta_timer(struct ieee80211_sub_if_data *sdata)
  3689. {
  3690. if (sdata->vif.type == NL80211_IFTYPE_STATION) {
  3691. __ieee80211_stop_poll(sdata);
  3692. /* let's probe the connection once */
  3693. if (!ieee80211_hw_check(&sdata->local->hw, CONNECTION_MONITOR))
  3694. ieee80211_queue_work(&sdata->local->hw,
  3695. &sdata->u.mgd.monitor_work);
  3696. }
  3697. }
  3698. #ifdef CONFIG_PM
  3699. void ieee80211_mgd_quiesce(struct ieee80211_sub_if_data *sdata)
  3700. {
  3701. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  3702. u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
  3703. sdata_lock(sdata);
  3704. if (ifmgd->auth_data || ifmgd->assoc_data) {
  3705. const u8 *bssid = ifmgd->auth_data ?
  3706. ifmgd->auth_data->bss->bssid :
  3707. ifmgd->assoc_data->bss->bssid;
  3708. /*
  3709. * If we are trying to authenticate / associate while suspending,
  3710. * cfg80211 won't know and won't actually abort those attempts,
  3711. * thus we need to do that ourselves.
  3712. */
  3713. ieee80211_send_deauth_disassoc(sdata, bssid,
  3714. IEEE80211_STYPE_DEAUTH,
  3715. WLAN_REASON_DEAUTH_LEAVING,
  3716. false, frame_buf);
  3717. if (ifmgd->assoc_data)
  3718. ieee80211_destroy_assoc_data(sdata, false, true);
  3719. if (ifmgd->auth_data)
  3720. ieee80211_destroy_auth_data(sdata, false);
  3721. cfg80211_tx_mlme_mgmt(sdata->dev, frame_buf,
  3722. IEEE80211_DEAUTH_FRAME_LEN);
  3723. }
  3724. /* This is a bit of a hack - we should find a better and more generic
  3725. * solution to this. Normally when suspending, cfg80211 will in fact
  3726. * deauthenticate. However, it doesn't (and cannot) stop an ongoing
  3727. * auth (not so important) or assoc (this is the problem) process.
  3728. *
  3729. * As a consequence, it can happen that we are in the process of both
  3730. * associating and suspending, and receive an association response
  3731. * after cfg80211 has checked if it needs to disconnect, but before
  3732. * we actually set the flag to drop incoming frames. This will then
  3733. * cause the workqueue flush to process the association response in
  3734. * the suspend, resulting in a successful association just before it
  3735. * tries to remove the interface from the driver, which now though
  3736. * has a channel context assigned ... this results in issues.
  3737. *
  3738. * To work around this (for now) simply deauth here again if we're
  3739. * now connected.
  3740. */
  3741. if (ifmgd->associated && !sdata->local->wowlan) {
  3742. u8 bssid[ETH_ALEN];
  3743. struct cfg80211_deauth_request req = {
  3744. .reason_code = WLAN_REASON_DEAUTH_LEAVING,
  3745. .bssid = bssid,
  3746. };
  3747. memcpy(bssid, ifmgd->associated->bssid, ETH_ALEN);
  3748. ieee80211_mgd_deauth(sdata, &req);
  3749. }
  3750. sdata_unlock(sdata);
  3751. }
  3752. void ieee80211_sta_restart(struct ieee80211_sub_if_data *sdata)
  3753. {
  3754. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  3755. sdata_lock(sdata);
  3756. if (!ifmgd->associated) {
  3757. sdata_unlock(sdata);
  3758. return;
  3759. }
  3760. if (sdata->flags & IEEE80211_SDATA_DISCONNECT_RESUME) {
  3761. sdata->flags &= ~IEEE80211_SDATA_DISCONNECT_RESUME;
  3762. mlme_dbg(sdata, "driver requested disconnect after resume\n");
  3763. ieee80211_sta_connection_lost(sdata,
  3764. ifmgd->associated->bssid,
  3765. WLAN_REASON_UNSPECIFIED,
  3766. true);
  3767. sdata_unlock(sdata);
  3768. return;
  3769. }
  3770. sdata_unlock(sdata);
  3771. }
  3772. #endif
  3773. /* interface setup */
  3774. void ieee80211_sta_setup_sdata(struct ieee80211_sub_if_data *sdata)
  3775. {
  3776. struct ieee80211_if_managed *ifmgd;
  3777. ifmgd = &sdata->u.mgd;
  3778. INIT_WORK(&ifmgd->monitor_work, ieee80211_sta_monitor_work);
  3779. INIT_WORK(&ifmgd->chswitch_work, ieee80211_chswitch_work);
  3780. INIT_WORK(&ifmgd->beacon_connection_loss_work,
  3781. ieee80211_beacon_connection_loss_work);
  3782. INIT_WORK(&ifmgd->csa_connection_drop_work,
  3783. ieee80211_csa_connection_drop_work);
  3784. INIT_WORK(&ifmgd->request_smps_work, ieee80211_request_smps_mgd_work);
  3785. INIT_DELAYED_WORK(&ifmgd->tdls_peer_del_work,
  3786. ieee80211_tdls_peer_del_work);
  3787. timer_setup(&ifmgd->timer, ieee80211_sta_timer, 0);
  3788. timer_setup(&ifmgd->bcn_mon_timer, ieee80211_sta_bcn_mon_timer, 0);
  3789. timer_setup(&ifmgd->conn_mon_timer, ieee80211_sta_conn_mon_timer, 0);
  3790. timer_setup(&ifmgd->chswitch_timer, ieee80211_chswitch_timer, 0);
  3791. INIT_DELAYED_WORK(&ifmgd->tx_tspec_wk,
  3792. ieee80211_sta_handle_tspec_ac_params_wk);
  3793. ifmgd->flags = 0;
  3794. ifmgd->powersave = sdata->wdev.ps;
  3795. ifmgd->uapsd_queues = sdata->local->hw.uapsd_queues;
  3796. ifmgd->uapsd_max_sp_len = sdata->local->hw.uapsd_max_sp_len;
  3797. ifmgd->p2p_noa_index = -1;
  3798. if (sdata->local->hw.wiphy->features & NL80211_FEATURE_DYNAMIC_SMPS)
  3799. ifmgd->req_smps = IEEE80211_SMPS_AUTOMATIC;
  3800. else
  3801. ifmgd->req_smps = IEEE80211_SMPS_OFF;
  3802. /* Setup TDLS data */
  3803. spin_lock_init(&ifmgd->teardown_lock);
  3804. ifmgd->teardown_skb = NULL;
  3805. ifmgd->orig_teardown_skb = NULL;
  3806. }
  3807. /* scan finished notification */
  3808. void ieee80211_mlme_notify_scan_completed(struct ieee80211_local *local)
  3809. {
  3810. struct ieee80211_sub_if_data *sdata;
  3811. /* Restart STA timers */
  3812. rcu_read_lock();
  3813. list_for_each_entry_rcu(sdata, &local->interfaces, list) {
  3814. if (ieee80211_sdata_running(sdata))
  3815. ieee80211_restart_sta_timer(sdata);
  3816. }
  3817. rcu_read_unlock();
  3818. }
  3819. static u8 ieee80211_ht_vht_rx_chains(struct ieee80211_sub_if_data *sdata,
  3820. struct cfg80211_bss *cbss)
  3821. {
  3822. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  3823. const u8 *ht_cap_ie, *vht_cap_ie;
  3824. const struct ieee80211_ht_cap *ht_cap;
  3825. const struct ieee80211_vht_cap *vht_cap;
  3826. u8 chains = 1;
  3827. if (ifmgd->flags & IEEE80211_STA_DISABLE_HT)
  3828. return chains;
  3829. ht_cap_ie = ieee80211_bss_get_ie(cbss, WLAN_EID_HT_CAPABILITY);
  3830. if (ht_cap_ie && ht_cap_ie[1] >= sizeof(*ht_cap)) {
  3831. ht_cap = (void *)(ht_cap_ie + 2);
  3832. chains = ieee80211_mcs_to_chains(&ht_cap->mcs);
  3833. /*
  3834. * TODO: use "Tx Maximum Number Spatial Streams Supported" and
  3835. * "Tx Unequal Modulation Supported" fields.
  3836. */
  3837. }
  3838. if (ifmgd->flags & IEEE80211_STA_DISABLE_VHT)
  3839. return chains;
  3840. vht_cap_ie = ieee80211_bss_get_ie(cbss, WLAN_EID_VHT_CAPABILITY);
  3841. if (vht_cap_ie && vht_cap_ie[1] >= sizeof(*vht_cap)) {
  3842. u8 nss;
  3843. u16 tx_mcs_map;
  3844. vht_cap = (void *)(vht_cap_ie + 2);
  3845. tx_mcs_map = le16_to_cpu(vht_cap->supp_mcs.tx_mcs_map);
  3846. for (nss = 8; nss > 0; nss--) {
  3847. if (((tx_mcs_map >> (2 * (nss - 1))) & 3) !=
  3848. IEEE80211_VHT_MCS_NOT_SUPPORTED)
  3849. break;
  3850. }
  3851. /* TODO: use "Tx Highest Supported Long GI Data Rate" field? */
  3852. chains = max(chains, nss);
  3853. }
  3854. return chains;
  3855. }
  3856. static bool
  3857. ieee80211_verify_sta_he_mcs_support(struct ieee80211_supported_band *sband,
  3858. const struct ieee80211_he_operation *he_op)
  3859. {
  3860. const struct ieee80211_sta_he_cap *sta_he_cap =
  3861. ieee80211_get_he_sta_cap(sband);
  3862. u16 ap_min_req_set;
  3863. int i;
  3864. if (!sta_he_cap || !he_op)
  3865. return false;
  3866. ap_min_req_set = le16_to_cpu(he_op->he_mcs_nss_set);
  3867. /* Need to go over for 80MHz, 160MHz and for 80+80 */
  3868. for (i = 0; i < 3; i++) {
  3869. const struct ieee80211_he_mcs_nss_supp *sta_mcs_nss_supp =
  3870. &sta_he_cap->he_mcs_nss_supp;
  3871. u16 sta_mcs_map_rx =
  3872. le16_to_cpu(((__le16 *)sta_mcs_nss_supp)[2 * i]);
  3873. u16 sta_mcs_map_tx =
  3874. le16_to_cpu(((__le16 *)sta_mcs_nss_supp)[2 * i + 1]);
  3875. u8 nss;
  3876. bool verified = true;
  3877. /*
  3878. * For each band there is a maximum of 8 spatial streams
  3879. * possible. Each of the sta_mcs_map_* is a 16-bit struct built
  3880. * of 2 bits per NSS (1-8), with the values defined in enum
  3881. * ieee80211_he_mcs_support. Need to make sure STA TX and RX
  3882. * capabilities aren't less than the AP's minimum requirements
  3883. * for this HE BSS per SS.
  3884. * It is enough to find one such band that meets the reqs.
  3885. */
  3886. for (nss = 8; nss > 0; nss--) {
  3887. u8 sta_rx_val = (sta_mcs_map_rx >> (2 * (nss - 1))) & 3;
  3888. u8 sta_tx_val = (sta_mcs_map_tx >> (2 * (nss - 1))) & 3;
  3889. u8 ap_val = (ap_min_req_set >> (2 * (nss - 1))) & 3;
  3890. if (ap_val == IEEE80211_HE_MCS_NOT_SUPPORTED)
  3891. continue;
  3892. /*
  3893. * Make sure the HE AP doesn't require MCSs that aren't
  3894. * supported by the client
  3895. */
  3896. if (sta_rx_val == IEEE80211_HE_MCS_NOT_SUPPORTED ||
  3897. sta_tx_val == IEEE80211_HE_MCS_NOT_SUPPORTED ||
  3898. (ap_val > sta_rx_val) || (ap_val > sta_tx_val)) {
  3899. verified = false;
  3900. break;
  3901. }
  3902. }
  3903. if (verified)
  3904. return true;
  3905. }
  3906. /* If here, STA doesn't meet AP's HE min requirements */
  3907. return false;
  3908. }
  3909. static int ieee80211_prep_channel(struct ieee80211_sub_if_data *sdata,
  3910. struct cfg80211_bss *cbss)
  3911. {
  3912. struct ieee80211_local *local = sdata->local;
  3913. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  3914. const struct ieee80211_ht_cap *ht_cap = NULL;
  3915. const struct ieee80211_ht_operation *ht_oper = NULL;
  3916. const struct ieee80211_vht_operation *vht_oper = NULL;
  3917. const struct ieee80211_he_operation *he_oper = NULL;
  3918. struct ieee80211_supported_band *sband;
  3919. struct cfg80211_chan_def chandef;
  3920. int ret;
  3921. u32 i;
  3922. bool have_80mhz;
  3923. sband = local->hw.wiphy->bands[cbss->channel->band];
  3924. ifmgd->flags &= ~(IEEE80211_STA_DISABLE_40MHZ |
  3925. IEEE80211_STA_DISABLE_80P80MHZ |
  3926. IEEE80211_STA_DISABLE_160MHZ);
  3927. rcu_read_lock();
  3928. if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT) &&
  3929. sband->ht_cap.ht_supported) {
  3930. const u8 *ht_oper_ie, *ht_cap_ie;
  3931. ht_oper_ie = ieee80211_bss_get_ie(cbss, WLAN_EID_HT_OPERATION);
  3932. if (ht_oper_ie && ht_oper_ie[1] >= sizeof(*ht_oper))
  3933. ht_oper = (void *)(ht_oper_ie + 2);
  3934. ht_cap_ie = ieee80211_bss_get_ie(cbss, WLAN_EID_HT_CAPABILITY);
  3935. if (ht_cap_ie && ht_cap_ie[1] >= sizeof(*ht_cap))
  3936. ht_cap = (void *)(ht_cap_ie + 2);
  3937. if (!ht_cap) {
  3938. ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
  3939. ht_oper = NULL;
  3940. }
  3941. }
  3942. if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT) &&
  3943. sband->vht_cap.vht_supported) {
  3944. const u8 *vht_oper_ie, *vht_cap;
  3945. vht_oper_ie = ieee80211_bss_get_ie(cbss,
  3946. WLAN_EID_VHT_OPERATION);
  3947. if (vht_oper_ie && vht_oper_ie[1] >= sizeof(*vht_oper))
  3948. vht_oper = (void *)(vht_oper_ie + 2);
  3949. if (vht_oper && !ht_oper) {
  3950. vht_oper = NULL;
  3951. sdata_info(sdata,
  3952. "AP advertised VHT without HT, disabling both\n");
  3953. ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
  3954. ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
  3955. }
  3956. vht_cap = ieee80211_bss_get_ie(cbss, WLAN_EID_VHT_CAPABILITY);
  3957. if (!vht_cap || vht_cap[1] < sizeof(struct ieee80211_vht_cap)) {
  3958. ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
  3959. vht_oper = NULL;
  3960. }
  3961. }
  3962. if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HE) &&
  3963. ieee80211_get_he_sta_cap(sband)) {
  3964. const struct cfg80211_bss_ies *ies;
  3965. const u8 *he_oper_ie;
  3966. ies = rcu_dereference(cbss->ies);
  3967. he_oper_ie = cfg80211_find_ext_ie(WLAN_EID_EXT_HE_OPERATION,
  3968. ies->data, ies->len);
  3969. if (he_oper_ie &&
  3970. he_oper_ie[1] == ieee80211_he_oper_size(&he_oper_ie[3]))
  3971. he_oper = (void *)(he_oper_ie + 3);
  3972. else
  3973. he_oper = NULL;
  3974. if (!ieee80211_verify_sta_he_mcs_support(sband, he_oper))
  3975. ifmgd->flags |= IEEE80211_STA_DISABLE_HE;
  3976. }
  3977. /* Allow VHT if at least one channel on the sband supports 80 MHz */
  3978. have_80mhz = false;
  3979. for (i = 0; i < sband->n_channels; i++) {
  3980. if (sband->channels[i].flags & (IEEE80211_CHAN_DISABLED |
  3981. IEEE80211_CHAN_NO_80MHZ))
  3982. continue;
  3983. have_80mhz = true;
  3984. break;
  3985. }
  3986. if (!have_80mhz)
  3987. ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
  3988. ifmgd->flags |= ieee80211_determine_chantype(sdata, sband,
  3989. cbss->channel,
  3990. ht_oper, vht_oper, he_oper,
  3991. &chandef, false);
  3992. sdata->needed_rx_chains = min(ieee80211_ht_vht_rx_chains(sdata, cbss),
  3993. local->rx_chains);
  3994. rcu_read_unlock();
  3995. /* will change later if needed */
  3996. sdata->smps_mode = IEEE80211_SMPS_OFF;
  3997. mutex_lock(&local->mtx);
  3998. /*
  3999. * If this fails (possibly due to channel context sharing
  4000. * on incompatible channels, e.g. 80+80 and 160 sharing the
  4001. * same control channel) try to use a smaller bandwidth.
  4002. */
  4003. ret = ieee80211_vif_use_channel(sdata, &chandef,
  4004. IEEE80211_CHANCTX_SHARED);
  4005. /* don't downgrade for 5 and 10 MHz channels, though. */
  4006. if (chandef.width == NL80211_CHAN_WIDTH_5 ||
  4007. chandef.width == NL80211_CHAN_WIDTH_10)
  4008. goto out;
  4009. while (ret && chandef.width != NL80211_CHAN_WIDTH_20_NOHT) {
  4010. ifmgd->flags |= ieee80211_chandef_downgrade(&chandef);
  4011. ret = ieee80211_vif_use_channel(sdata, &chandef,
  4012. IEEE80211_CHANCTX_SHARED);
  4013. }
  4014. out:
  4015. mutex_unlock(&local->mtx);
  4016. return ret;
  4017. }
  4018. static int ieee80211_prep_connection(struct ieee80211_sub_if_data *sdata,
  4019. struct cfg80211_bss *cbss, bool assoc,
  4020. bool override)
  4021. {
  4022. struct ieee80211_local *local = sdata->local;
  4023. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  4024. struct ieee80211_bss *bss = (void *)cbss->priv;
  4025. struct sta_info *new_sta = NULL;
  4026. struct ieee80211_supported_band *sband;
  4027. bool have_sta = false;
  4028. int err;
  4029. sband = local->hw.wiphy->bands[cbss->channel->band];
  4030. if (WARN_ON(!ifmgd->auth_data && !ifmgd->assoc_data))
  4031. return -EINVAL;
  4032. /* If a reconfig is happening, bail out */
  4033. if (local->in_reconfig)
  4034. return -EBUSY;
  4035. if (assoc) {
  4036. rcu_read_lock();
  4037. have_sta = sta_info_get(sdata, cbss->bssid);
  4038. rcu_read_unlock();
  4039. }
  4040. if (!have_sta) {
  4041. new_sta = sta_info_alloc(sdata, cbss->bssid, GFP_KERNEL);
  4042. if (!new_sta)
  4043. return -ENOMEM;
  4044. }
  4045. /*
  4046. * Set up the information for the new channel before setting the
  4047. * new channel. We can't - completely race-free - change the basic
  4048. * rates bitmap and the channel (sband) that it refers to, but if
  4049. * we set it up before we at least avoid calling into the driver's
  4050. * bss_info_changed() method with invalid information (since we do
  4051. * call that from changing the channel - only for IDLE and perhaps
  4052. * some others, but ...).
  4053. *
  4054. * So to avoid that, just set up all the new information before the
  4055. * channel, but tell the driver to apply it only afterwards, since
  4056. * it might need the new channel for that.
  4057. */
  4058. if (new_sta) {
  4059. u32 rates = 0, basic_rates = 0;
  4060. bool have_higher_than_11mbit;
  4061. int min_rate = INT_MAX, min_rate_index = -1;
  4062. const struct cfg80211_bss_ies *ies;
  4063. int shift = ieee80211_vif_get_shift(&sdata->vif);
  4064. ieee80211_get_rates(sband, bss->supp_rates,
  4065. bss->supp_rates_len,
  4066. &rates, &basic_rates,
  4067. &have_higher_than_11mbit,
  4068. &min_rate, &min_rate_index,
  4069. shift);
  4070. /*
  4071. * This used to be a workaround for basic rates missing
  4072. * in the association response frame. Now that we no
  4073. * longer use the basic rates from there, it probably
  4074. * doesn't happen any more, but keep the workaround so
  4075. * in case some *other* APs are buggy in different ways
  4076. * we can connect -- with a warning.
  4077. */
  4078. if (!basic_rates && min_rate_index >= 0) {
  4079. sdata_info(sdata,
  4080. "No basic rates, using min rate instead\n");
  4081. basic_rates = BIT(min_rate_index);
  4082. }
  4083. new_sta->sta.supp_rates[cbss->channel->band] = rates;
  4084. sdata->vif.bss_conf.basic_rates = basic_rates;
  4085. /* cf. IEEE 802.11 9.2.12 */
  4086. if (cbss->channel->band == NL80211_BAND_2GHZ &&
  4087. have_higher_than_11mbit)
  4088. sdata->flags |= IEEE80211_SDATA_OPERATING_GMODE;
  4089. else
  4090. sdata->flags &= ~IEEE80211_SDATA_OPERATING_GMODE;
  4091. memcpy(ifmgd->bssid, cbss->bssid, ETH_ALEN);
  4092. /* set timing information */
  4093. sdata->vif.bss_conf.beacon_int = cbss->beacon_interval;
  4094. rcu_read_lock();
  4095. ies = rcu_dereference(cbss->beacon_ies);
  4096. if (ies) {
  4097. const u8 *tim_ie;
  4098. sdata->vif.bss_conf.sync_tsf = ies->tsf;
  4099. sdata->vif.bss_conf.sync_device_ts =
  4100. bss->device_ts_beacon;
  4101. tim_ie = cfg80211_find_ie(WLAN_EID_TIM,
  4102. ies->data, ies->len);
  4103. if (tim_ie && tim_ie[1] >= 2)
  4104. sdata->vif.bss_conf.sync_dtim_count = tim_ie[2];
  4105. else
  4106. sdata->vif.bss_conf.sync_dtim_count = 0;
  4107. } else if (!ieee80211_hw_check(&sdata->local->hw,
  4108. TIMING_BEACON_ONLY)) {
  4109. ies = rcu_dereference(cbss->proberesp_ies);
  4110. /* must be non-NULL since beacon IEs were NULL */
  4111. sdata->vif.bss_conf.sync_tsf = ies->tsf;
  4112. sdata->vif.bss_conf.sync_device_ts =
  4113. bss->device_ts_presp;
  4114. sdata->vif.bss_conf.sync_dtim_count = 0;
  4115. } else {
  4116. sdata->vif.bss_conf.sync_tsf = 0;
  4117. sdata->vif.bss_conf.sync_device_ts = 0;
  4118. sdata->vif.bss_conf.sync_dtim_count = 0;
  4119. }
  4120. rcu_read_unlock();
  4121. }
  4122. if (new_sta || override) {
  4123. err = ieee80211_prep_channel(sdata, cbss);
  4124. if (err) {
  4125. if (new_sta)
  4126. sta_info_free(local, new_sta);
  4127. return -EINVAL;
  4128. }
  4129. }
  4130. if (new_sta) {
  4131. /*
  4132. * tell driver about BSSID, basic rates and timing
  4133. * this was set up above, before setting the channel
  4134. */
  4135. ieee80211_bss_info_change_notify(sdata,
  4136. BSS_CHANGED_BSSID | BSS_CHANGED_BASIC_RATES |
  4137. BSS_CHANGED_BEACON_INT);
  4138. if (assoc)
  4139. sta_info_pre_move_state(new_sta, IEEE80211_STA_AUTH);
  4140. err = sta_info_insert(new_sta);
  4141. new_sta = NULL;
  4142. if (err) {
  4143. sdata_info(sdata,
  4144. "failed to insert STA entry for the AP (error %d)\n",
  4145. err);
  4146. return err;
  4147. }
  4148. } else
  4149. WARN_ON_ONCE(!ether_addr_equal(ifmgd->bssid, cbss->bssid));
  4150. /* Cancel scan to ensure that nothing interferes with connection */
  4151. if (local->scanning)
  4152. ieee80211_scan_cancel(local);
  4153. return 0;
  4154. }
  4155. /* config hooks */
  4156. int ieee80211_mgd_auth(struct ieee80211_sub_if_data *sdata,
  4157. struct cfg80211_auth_request *req)
  4158. {
  4159. struct ieee80211_local *local = sdata->local;
  4160. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  4161. struct ieee80211_mgd_auth_data *auth_data;
  4162. u16 auth_alg;
  4163. int err;
  4164. /* prepare auth data structure */
  4165. switch (req->auth_type) {
  4166. case NL80211_AUTHTYPE_OPEN_SYSTEM:
  4167. auth_alg = WLAN_AUTH_OPEN;
  4168. break;
  4169. case NL80211_AUTHTYPE_SHARED_KEY:
  4170. if (IS_ERR(local->wep_tx_tfm))
  4171. return -EOPNOTSUPP;
  4172. auth_alg = WLAN_AUTH_SHARED_KEY;
  4173. break;
  4174. case NL80211_AUTHTYPE_FT:
  4175. auth_alg = WLAN_AUTH_FT;
  4176. break;
  4177. case NL80211_AUTHTYPE_NETWORK_EAP:
  4178. auth_alg = WLAN_AUTH_LEAP;
  4179. break;
  4180. case NL80211_AUTHTYPE_SAE:
  4181. auth_alg = WLAN_AUTH_SAE;
  4182. break;
  4183. case NL80211_AUTHTYPE_FILS_SK:
  4184. auth_alg = WLAN_AUTH_FILS_SK;
  4185. break;
  4186. case NL80211_AUTHTYPE_FILS_SK_PFS:
  4187. auth_alg = WLAN_AUTH_FILS_SK_PFS;
  4188. break;
  4189. case NL80211_AUTHTYPE_FILS_PK:
  4190. auth_alg = WLAN_AUTH_FILS_PK;
  4191. break;
  4192. default:
  4193. return -EOPNOTSUPP;
  4194. }
  4195. auth_data = kzalloc(sizeof(*auth_data) + req->auth_data_len +
  4196. req->ie_len, GFP_KERNEL);
  4197. if (!auth_data)
  4198. return -ENOMEM;
  4199. auth_data->bss = req->bss;
  4200. if (req->auth_data_len >= 4) {
  4201. if (req->auth_type == NL80211_AUTHTYPE_SAE) {
  4202. __le16 *pos = (__le16 *) req->auth_data;
  4203. auth_data->sae_trans = le16_to_cpu(pos[0]);
  4204. auth_data->sae_status = le16_to_cpu(pos[1]);
  4205. }
  4206. memcpy(auth_data->data, req->auth_data + 4,
  4207. req->auth_data_len - 4);
  4208. auth_data->data_len += req->auth_data_len - 4;
  4209. }
  4210. if (req->ie && req->ie_len) {
  4211. memcpy(&auth_data->data[auth_data->data_len],
  4212. req->ie, req->ie_len);
  4213. auth_data->data_len += req->ie_len;
  4214. }
  4215. if (req->key && req->key_len) {
  4216. auth_data->key_len = req->key_len;
  4217. auth_data->key_idx = req->key_idx;
  4218. memcpy(auth_data->key, req->key, req->key_len);
  4219. }
  4220. auth_data->algorithm = auth_alg;
  4221. /* try to authenticate/probe */
  4222. if ((ifmgd->auth_data && !ifmgd->auth_data->done) ||
  4223. ifmgd->assoc_data) {
  4224. err = -EBUSY;
  4225. goto err_free;
  4226. }
  4227. if (ifmgd->auth_data)
  4228. ieee80211_destroy_auth_data(sdata, false);
  4229. /* prep auth_data so we don't go into idle on disassoc */
  4230. ifmgd->auth_data = auth_data;
  4231. if (ifmgd->associated) {
  4232. u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
  4233. sdata_info(sdata,
  4234. "disconnect from AP %pM for new auth to %pM\n",
  4235. ifmgd->associated->bssid, req->bss->bssid);
  4236. ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
  4237. WLAN_REASON_UNSPECIFIED,
  4238. false, frame_buf);
  4239. ieee80211_report_disconnect(sdata, frame_buf,
  4240. sizeof(frame_buf), true,
  4241. WLAN_REASON_UNSPECIFIED);
  4242. }
  4243. sdata_info(sdata, "authenticate with %pM\n", req->bss->bssid);
  4244. err = ieee80211_prep_connection(sdata, req->bss, false, false);
  4245. if (err)
  4246. goto err_clear;
  4247. err = ieee80211_auth(sdata);
  4248. if (err) {
  4249. sta_info_destroy_addr(sdata, req->bss->bssid);
  4250. goto err_clear;
  4251. }
  4252. /* hold our own reference */
  4253. cfg80211_ref_bss(local->hw.wiphy, auth_data->bss);
  4254. return 0;
  4255. err_clear:
  4256. eth_zero_addr(ifmgd->bssid);
  4257. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID);
  4258. ifmgd->auth_data = NULL;
  4259. mutex_lock(&sdata->local->mtx);
  4260. ieee80211_vif_release_channel(sdata);
  4261. mutex_unlock(&sdata->local->mtx);
  4262. err_free:
  4263. kfree(auth_data);
  4264. return err;
  4265. }
  4266. int ieee80211_mgd_assoc(struct ieee80211_sub_if_data *sdata,
  4267. struct cfg80211_assoc_request *req)
  4268. {
  4269. struct ieee80211_local *local = sdata->local;
  4270. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  4271. struct ieee80211_bss *bss = (void *)req->bss->priv;
  4272. struct ieee80211_mgd_assoc_data *assoc_data;
  4273. const struct cfg80211_bss_ies *beacon_ies;
  4274. struct ieee80211_supported_band *sband;
  4275. const u8 *ssidie, *ht_ie, *vht_ie;
  4276. int i, err;
  4277. bool override = false;
  4278. assoc_data = kzalloc(sizeof(*assoc_data) + req->ie_len, GFP_KERNEL);
  4279. if (!assoc_data)
  4280. return -ENOMEM;
  4281. rcu_read_lock();
  4282. ssidie = ieee80211_bss_get_ie(req->bss, WLAN_EID_SSID);
  4283. if (!ssidie || ssidie[1] > sizeof(assoc_data->ssid)) {
  4284. rcu_read_unlock();
  4285. kfree(assoc_data);
  4286. return -EINVAL;
  4287. }
  4288. memcpy(assoc_data->ssid, ssidie + 2, ssidie[1]);
  4289. assoc_data->ssid_len = ssidie[1];
  4290. rcu_read_unlock();
  4291. if (ifmgd->associated) {
  4292. u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
  4293. sdata_info(sdata,
  4294. "disconnect from AP %pM for new assoc to %pM\n",
  4295. ifmgd->associated->bssid, req->bss->bssid);
  4296. ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
  4297. WLAN_REASON_UNSPECIFIED,
  4298. false, frame_buf);
  4299. ieee80211_report_disconnect(sdata, frame_buf,
  4300. sizeof(frame_buf), true,
  4301. WLAN_REASON_UNSPECIFIED);
  4302. }
  4303. if (ifmgd->auth_data && !ifmgd->auth_data->done) {
  4304. err = -EBUSY;
  4305. goto err_free;
  4306. }
  4307. if (ifmgd->assoc_data) {
  4308. err = -EBUSY;
  4309. goto err_free;
  4310. }
  4311. if (ifmgd->auth_data) {
  4312. bool match;
  4313. /* keep sta info, bssid if matching */
  4314. match = ether_addr_equal(ifmgd->bssid, req->bss->bssid);
  4315. ieee80211_destroy_auth_data(sdata, match);
  4316. }
  4317. /* prepare assoc data */
  4318. ifmgd->beacon_crc_valid = false;
  4319. assoc_data->wmm = bss->wmm_used &&
  4320. (local->hw.queues >= IEEE80211_NUM_ACS);
  4321. /*
  4322. * IEEE802.11n does not allow TKIP/WEP as pairwise ciphers in HT mode.
  4323. * We still associate in non-HT mode (11a/b/g) if any one of these
  4324. * ciphers is configured as pairwise.
  4325. * We can set this to true for non-11n hardware, that'll be checked
  4326. * separately along with the peer capabilities.
  4327. */
  4328. for (i = 0; i < req->crypto.n_ciphers_pairwise; i++) {
  4329. if (req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP40 ||
  4330. req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_TKIP ||
  4331. req->crypto.ciphers_pairwise[i] == WLAN_CIPHER_SUITE_WEP104) {
  4332. ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
  4333. ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
  4334. ifmgd->flags |= IEEE80211_STA_DISABLE_HE;
  4335. netdev_info(sdata->dev,
  4336. "disabling HE/HT/VHT due to WEP/TKIP use\n");
  4337. }
  4338. }
  4339. /* Also disable HT if we don't support it or the AP doesn't use WMM */
  4340. sband = local->hw.wiphy->bands[req->bss->channel->band];
  4341. if (!sband->ht_cap.ht_supported ||
  4342. local->hw.queues < IEEE80211_NUM_ACS || !bss->wmm_used ||
  4343. ifmgd->flags & IEEE80211_STA_DISABLE_WMM) {
  4344. ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
  4345. if (!bss->wmm_used &&
  4346. !(ifmgd->flags & IEEE80211_STA_DISABLE_WMM))
  4347. netdev_info(sdata->dev,
  4348. "disabling HT as WMM/QoS is not supported by the AP\n");
  4349. }
  4350. /* disable VHT if we don't support it or the AP doesn't use WMM */
  4351. if (!sband->vht_cap.vht_supported ||
  4352. local->hw.queues < IEEE80211_NUM_ACS || !bss->wmm_used ||
  4353. ifmgd->flags & IEEE80211_STA_DISABLE_WMM) {
  4354. ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
  4355. if (!bss->wmm_used &&
  4356. !(ifmgd->flags & IEEE80211_STA_DISABLE_WMM))
  4357. netdev_info(sdata->dev,
  4358. "disabling VHT as WMM/QoS is not supported by the AP\n");
  4359. }
  4360. memcpy(&ifmgd->ht_capa, &req->ht_capa, sizeof(ifmgd->ht_capa));
  4361. memcpy(&ifmgd->ht_capa_mask, &req->ht_capa_mask,
  4362. sizeof(ifmgd->ht_capa_mask));
  4363. memcpy(&ifmgd->vht_capa, &req->vht_capa, sizeof(ifmgd->vht_capa));
  4364. memcpy(&ifmgd->vht_capa_mask, &req->vht_capa_mask,
  4365. sizeof(ifmgd->vht_capa_mask));
  4366. if (req->ie && req->ie_len) {
  4367. memcpy(assoc_data->ie, req->ie, req->ie_len);
  4368. assoc_data->ie_len = req->ie_len;
  4369. }
  4370. if (req->fils_kek) {
  4371. /* should already be checked in cfg80211 - so warn */
  4372. if (WARN_ON(req->fils_kek_len > FILS_MAX_KEK_LEN)) {
  4373. err = -EINVAL;
  4374. goto err_free;
  4375. }
  4376. memcpy(assoc_data->fils_kek, req->fils_kek,
  4377. req->fils_kek_len);
  4378. assoc_data->fils_kek_len = req->fils_kek_len;
  4379. }
  4380. if (req->fils_nonces)
  4381. memcpy(assoc_data->fils_nonces, req->fils_nonces,
  4382. 2 * FILS_NONCE_LEN);
  4383. assoc_data->bss = req->bss;
  4384. if (ifmgd->req_smps == IEEE80211_SMPS_AUTOMATIC) {
  4385. if (ifmgd->powersave)
  4386. sdata->smps_mode = IEEE80211_SMPS_DYNAMIC;
  4387. else
  4388. sdata->smps_mode = IEEE80211_SMPS_OFF;
  4389. } else
  4390. sdata->smps_mode = ifmgd->req_smps;
  4391. assoc_data->capability = req->bss->capability;
  4392. assoc_data->supp_rates = bss->supp_rates;
  4393. assoc_data->supp_rates_len = bss->supp_rates_len;
  4394. rcu_read_lock();
  4395. ht_ie = ieee80211_bss_get_ie(req->bss, WLAN_EID_HT_OPERATION);
  4396. if (ht_ie && ht_ie[1] >= sizeof(struct ieee80211_ht_operation))
  4397. assoc_data->ap_ht_param =
  4398. ((struct ieee80211_ht_operation *)(ht_ie + 2))->ht_param;
  4399. else
  4400. ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
  4401. vht_ie = ieee80211_bss_get_ie(req->bss, WLAN_EID_VHT_CAPABILITY);
  4402. if (vht_ie && vht_ie[1] >= sizeof(struct ieee80211_vht_cap))
  4403. memcpy(&assoc_data->ap_vht_cap, vht_ie + 2,
  4404. sizeof(struct ieee80211_vht_cap));
  4405. else
  4406. ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
  4407. rcu_read_unlock();
  4408. if (WARN((sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_UAPSD) &&
  4409. ieee80211_hw_check(&local->hw, PS_NULLFUNC_STACK),
  4410. "U-APSD not supported with HW_PS_NULLFUNC_STACK\n"))
  4411. sdata->vif.driver_flags &= ~IEEE80211_VIF_SUPPORTS_UAPSD;
  4412. if (bss->wmm_used && bss->uapsd_supported &&
  4413. (sdata->vif.driver_flags & IEEE80211_VIF_SUPPORTS_UAPSD)) {
  4414. assoc_data->uapsd = true;
  4415. ifmgd->flags |= IEEE80211_STA_UAPSD_ENABLED;
  4416. } else {
  4417. assoc_data->uapsd = false;
  4418. ifmgd->flags &= ~IEEE80211_STA_UAPSD_ENABLED;
  4419. }
  4420. if (req->prev_bssid)
  4421. memcpy(assoc_data->prev_bssid, req->prev_bssid, ETH_ALEN);
  4422. if (req->use_mfp) {
  4423. ifmgd->mfp = IEEE80211_MFP_REQUIRED;
  4424. ifmgd->flags |= IEEE80211_STA_MFP_ENABLED;
  4425. } else {
  4426. ifmgd->mfp = IEEE80211_MFP_DISABLED;
  4427. ifmgd->flags &= ~IEEE80211_STA_MFP_ENABLED;
  4428. }
  4429. if (req->flags & ASSOC_REQ_USE_RRM)
  4430. ifmgd->flags |= IEEE80211_STA_ENABLE_RRM;
  4431. else
  4432. ifmgd->flags &= ~IEEE80211_STA_ENABLE_RRM;
  4433. if (req->crypto.control_port)
  4434. ifmgd->flags |= IEEE80211_STA_CONTROL_PORT;
  4435. else
  4436. ifmgd->flags &= ~IEEE80211_STA_CONTROL_PORT;
  4437. sdata->control_port_protocol = req->crypto.control_port_ethertype;
  4438. sdata->control_port_no_encrypt = req->crypto.control_port_no_encrypt;
  4439. sdata->control_port_over_nl80211 =
  4440. req->crypto.control_port_over_nl80211;
  4441. sdata->encrypt_headroom = ieee80211_cs_headroom(local, &req->crypto,
  4442. sdata->vif.type);
  4443. /* kick off associate process */
  4444. ifmgd->assoc_data = assoc_data;
  4445. ifmgd->dtim_period = 0;
  4446. ifmgd->have_beacon = false;
  4447. /* override HT/VHT configuration only if the AP and we support it */
  4448. if (!(ifmgd->flags & IEEE80211_STA_DISABLE_HT)) {
  4449. struct ieee80211_sta_ht_cap sta_ht_cap;
  4450. if (req->flags & ASSOC_REQ_DISABLE_HT)
  4451. override = true;
  4452. memcpy(&sta_ht_cap, &sband->ht_cap, sizeof(sta_ht_cap));
  4453. ieee80211_apply_htcap_overrides(sdata, &sta_ht_cap);
  4454. /* check for 40 MHz disable override */
  4455. if (!(ifmgd->flags & IEEE80211_STA_DISABLE_40MHZ) &&
  4456. sband->ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40 &&
  4457. !(sta_ht_cap.cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40))
  4458. override = true;
  4459. if (!(ifmgd->flags & IEEE80211_STA_DISABLE_VHT) &&
  4460. req->flags & ASSOC_REQ_DISABLE_VHT)
  4461. override = true;
  4462. }
  4463. if (req->flags & ASSOC_REQ_DISABLE_HT) {
  4464. ifmgd->flags |= IEEE80211_STA_DISABLE_HT;
  4465. ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
  4466. }
  4467. if (req->flags & ASSOC_REQ_DISABLE_VHT)
  4468. ifmgd->flags |= IEEE80211_STA_DISABLE_VHT;
  4469. err = ieee80211_prep_connection(sdata, req->bss, true, override);
  4470. if (err)
  4471. goto err_clear;
  4472. rcu_read_lock();
  4473. beacon_ies = rcu_dereference(req->bss->beacon_ies);
  4474. if (ieee80211_hw_check(&sdata->local->hw, NEED_DTIM_BEFORE_ASSOC) &&
  4475. !beacon_ies) {
  4476. /*
  4477. * Wait up to one beacon interval ...
  4478. * should this be more if we miss one?
  4479. */
  4480. sdata_info(sdata, "waiting for beacon from %pM\n",
  4481. ifmgd->bssid);
  4482. assoc_data->timeout = TU_TO_EXP_TIME(req->bss->beacon_interval);
  4483. assoc_data->timeout_started = true;
  4484. assoc_data->need_beacon = true;
  4485. } else if (beacon_ies) {
  4486. const u8 *tim_ie = cfg80211_find_ie(WLAN_EID_TIM,
  4487. beacon_ies->data,
  4488. beacon_ies->len);
  4489. u8 dtim_count = 0;
  4490. if (tim_ie && tim_ie[1] >= sizeof(struct ieee80211_tim_ie)) {
  4491. const struct ieee80211_tim_ie *tim;
  4492. tim = (void *)(tim_ie + 2);
  4493. ifmgd->dtim_period = tim->dtim_period;
  4494. dtim_count = tim->dtim_count;
  4495. }
  4496. ifmgd->have_beacon = true;
  4497. assoc_data->timeout = jiffies;
  4498. assoc_data->timeout_started = true;
  4499. if (ieee80211_hw_check(&local->hw, TIMING_BEACON_ONLY)) {
  4500. sdata->vif.bss_conf.sync_tsf = beacon_ies->tsf;
  4501. sdata->vif.bss_conf.sync_device_ts =
  4502. bss->device_ts_beacon;
  4503. sdata->vif.bss_conf.sync_dtim_count = dtim_count;
  4504. }
  4505. } else {
  4506. assoc_data->timeout = jiffies;
  4507. assoc_data->timeout_started = true;
  4508. }
  4509. rcu_read_unlock();
  4510. run_again(sdata, assoc_data->timeout);
  4511. if (bss->corrupt_data) {
  4512. char *corrupt_type = "data";
  4513. if (bss->corrupt_data & IEEE80211_BSS_CORRUPT_BEACON) {
  4514. if (bss->corrupt_data &
  4515. IEEE80211_BSS_CORRUPT_PROBE_RESP)
  4516. corrupt_type = "beacon and probe response";
  4517. else
  4518. corrupt_type = "beacon";
  4519. } else if (bss->corrupt_data & IEEE80211_BSS_CORRUPT_PROBE_RESP)
  4520. corrupt_type = "probe response";
  4521. sdata_info(sdata, "associating with AP with corrupt %s\n",
  4522. corrupt_type);
  4523. }
  4524. return 0;
  4525. err_clear:
  4526. eth_zero_addr(ifmgd->bssid);
  4527. ieee80211_bss_info_change_notify(sdata, BSS_CHANGED_BSSID);
  4528. ifmgd->assoc_data = NULL;
  4529. err_free:
  4530. kfree(assoc_data);
  4531. return err;
  4532. }
  4533. int ieee80211_mgd_deauth(struct ieee80211_sub_if_data *sdata,
  4534. struct cfg80211_deauth_request *req)
  4535. {
  4536. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  4537. u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
  4538. bool tx = !req->local_state_change;
  4539. if (ifmgd->auth_data &&
  4540. ether_addr_equal(ifmgd->auth_data->bss->bssid, req->bssid)) {
  4541. sdata_info(sdata,
  4542. "aborting authentication with %pM by local choice (Reason: %u=%s)\n",
  4543. req->bssid, req->reason_code,
  4544. ieee80211_get_reason_code_string(req->reason_code));
  4545. drv_mgd_prepare_tx(sdata->local, sdata, 0);
  4546. ieee80211_send_deauth_disassoc(sdata, req->bssid,
  4547. IEEE80211_STYPE_DEAUTH,
  4548. req->reason_code, tx,
  4549. frame_buf);
  4550. ieee80211_destroy_auth_data(sdata, false);
  4551. ieee80211_report_disconnect(sdata, frame_buf,
  4552. sizeof(frame_buf), true,
  4553. req->reason_code);
  4554. return 0;
  4555. }
  4556. if (ifmgd->assoc_data &&
  4557. ether_addr_equal(ifmgd->assoc_data->bss->bssid, req->bssid)) {
  4558. sdata_info(sdata,
  4559. "aborting association with %pM by local choice (Reason: %u=%s)\n",
  4560. req->bssid, req->reason_code,
  4561. ieee80211_get_reason_code_string(req->reason_code));
  4562. drv_mgd_prepare_tx(sdata->local, sdata, 0);
  4563. ieee80211_send_deauth_disassoc(sdata, req->bssid,
  4564. IEEE80211_STYPE_DEAUTH,
  4565. req->reason_code, tx,
  4566. frame_buf);
  4567. ieee80211_destroy_assoc_data(sdata, false, true);
  4568. ieee80211_report_disconnect(sdata, frame_buf,
  4569. sizeof(frame_buf), true,
  4570. req->reason_code);
  4571. return 0;
  4572. }
  4573. if (ifmgd->associated &&
  4574. ether_addr_equal(ifmgd->associated->bssid, req->bssid)) {
  4575. sdata_info(sdata,
  4576. "deauthenticating from %pM by local choice (Reason: %u=%s)\n",
  4577. req->bssid, req->reason_code,
  4578. ieee80211_get_reason_code_string(req->reason_code));
  4579. ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DEAUTH,
  4580. req->reason_code, tx, frame_buf);
  4581. ieee80211_report_disconnect(sdata, frame_buf,
  4582. sizeof(frame_buf), true,
  4583. req->reason_code);
  4584. return 0;
  4585. }
  4586. return -ENOTCONN;
  4587. }
  4588. int ieee80211_mgd_disassoc(struct ieee80211_sub_if_data *sdata,
  4589. struct cfg80211_disassoc_request *req)
  4590. {
  4591. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  4592. u8 bssid[ETH_ALEN];
  4593. u8 frame_buf[IEEE80211_DEAUTH_FRAME_LEN];
  4594. /*
  4595. * cfg80211 should catch this ... but it's racy since
  4596. * we can receive a disassoc frame, process it, hand it
  4597. * to cfg80211 while that's in a locked section already
  4598. * trying to tell us that the user wants to disconnect.
  4599. */
  4600. if (ifmgd->associated != req->bss)
  4601. return -ENOLINK;
  4602. sdata_info(sdata,
  4603. "disassociating from %pM by local choice (Reason: %u=%s)\n",
  4604. req->bss->bssid, req->reason_code, ieee80211_get_reason_code_string(req->reason_code));
  4605. memcpy(bssid, req->bss->bssid, ETH_ALEN);
  4606. ieee80211_set_disassoc(sdata, IEEE80211_STYPE_DISASSOC,
  4607. req->reason_code, !req->local_state_change,
  4608. frame_buf);
  4609. ieee80211_report_disconnect(sdata, frame_buf, sizeof(frame_buf), true,
  4610. req->reason_code);
  4611. return 0;
  4612. }
  4613. void ieee80211_mgd_stop(struct ieee80211_sub_if_data *sdata)
  4614. {
  4615. struct ieee80211_if_managed *ifmgd = &sdata->u.mgd;
  4616. /*
  4617. * Make sure some work items will not run after this,
  4618. * they will not do anything but might not have been
  4619. * cancelled when disconnecting.
  4620. */
  4621. cancel_work_sync(&ifmgd->monitor_work);
  4622. cancel_work_sync(&ifmgd->beacon_connection_loss_work);
  4623. cancel_work_sync(&ifmgd->request_smps_work);
  4624. cancel_work_sync(&ifmgd->csa_connection_drop_work);
  4625. cancel_work_sync(&ifmgd->chswitch_work);
  4626. cancel_delayed_work_sync(&ifmgd->tdls_peer_del_work);
  4627. sdata_lock(sdata);
  4628. if (ifmgd->assoc_data) {
  4629. struct cfg80211_bss *bss = ifmgd->assoc_data->bss;
  4630. ieee80211_destroy_assoc_data(sdata, false, false);
  4631. cfg80211_assoc_timeout(sdata->dev, bss);
  4632. }
  4633. if (ifmgd->auth_data)
  4634. ieee80211_destroy_auth_data(sdata, false);
  4635. spin_lock_bh(&ifmgd->teardown_lock);
  4636. if (ifmgd->teardown_skb) {
  4637. kfree_skb(ifmgd->teardown_skb);
  4638. ifmgd->teardown_skb = NULL;
  4639. ifmgd->orig_teardown_skb = NULL;
  4640. }
  4641. spin_unlock_bh(&ifmgd->teardown_lock);
  4642. del_timer_sync(&ifmgd->timer);
  4643. sdata_unlock(sdata);
  4644. }
  4645. void ieee80211_cqm_rssi_notify(struct ieee80211_vif *vif,
  4646. enum nl80211_cqm_rssi_threshold_event rssi_event,
  4647. s32 rssi_level,
  4648. gfp_t gfp)
  4649. {
  4650. struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
  4651. trace_api_cqm_rssi_notify(sdata, rssi_event, rssi_level);
  4652. cfg80211_cqm_rssi_notify(sdata->dev, rssi_event, rssi_level, gfp);
  4653. }
  4654. EXPORT_SYMBOL(ieee80211_cqm_rssi_notify);
  4655. void ieee80211_cqm_beacon_loss_notify(struct ieee80211_vif *vif, gfp_t gfp)
  4656. {
  4657. struct ieee80211_sub_if_data *sdata = vif_to_sdata(vif);
  4658. trace_api_cqm_beacon_loss_notify(sdata->local, sdata);
  4659. cfg80211_cqm_beacon_loss_notify(sdata->dev, gfp);
  4660. }
  4661. EXPORT_SYMBOL(ieee80211_cqm_beacon_loss_notify);