cfg80211.c 163 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165
  1. /*
  2. * Copyright (c) 2010 Broadcom Corporation
  3. *
  4. * Permission to use, copy, modify, and/or distribute this software for any
  5. * purpose with or without fee is hereby granted, provided that the above
  6. * copyright notice and this permission notice appear in all copies.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
  11. * SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION
  13. * OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
  14. * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. /* Toplevel file. Relies on dhd_linux.c to send commands to the dongle. */
  17. #include <linux/kernel.h>
  18. #include <linux/etherdevice.h>
  19. #include <linux/module.h>
  20. #include <linux/vmalloc.h>
  21. #include <net/cfg80211.h>
  22. #include <net/netlink.h>
  23. #include <brcmu_utils.h>
  24. #include <defs.h>
  25. #include <brcmu_wifi.h>
  26. #include "core.h"
  27. #include "debug.h"
  28. #include "tracepoint.h"
  29. #include "fwil_types.h"
  30. #include "p2p.h"
  31. #include "btcoex.h"
  32. #include "cfg80211.h"
  33. #include "feature.h"
  34. #include "fwil.h"
  35. #include "proto.h"
  36. #include "vendor.h"
  37. #include "bus.h"
  38. #include "common.h"
  39. #define BRCMF_SCAN_IE_LEN_MAX 2048
  40. #define BRCMF_PNO_VERSION 2
  41. #define BRCMF_PNO_TIME 30
  42. #define BRCMF_PNO_REPEAT 4
  43. #define BRCMF_PNO_FREQ_EXPO_MAX 3
  44. #define BRCMF_PNO_MAX_PFN_COUNT 16
  45. #define BRCMF_PNO_ENABLE_ADAPTSCAN_BIT 6
  46. #define BRCMF_PNO_HIDDEN_BIT 2
  47. #define BRCMF_PNO_WPA_AUTH_ANY 0xFFFFFFFF
  48. #define BRCMF_PNO_SCAN_COMPLETE 1
  49. #define BRCMF_PNO_SCAN_INCOMPLETE 0
  50. #define BRCMF_IFACE_MAX_CNT 3
  51. #define WPA_OUI "\x00\x50\xF2" /* WPA OUI */
  52. #define WPA_OUI_TYPE 1
  53. #define RSN_OUI "\x00\x0F\xAC" /* RSN OUI */
  54. #define WME_OUI_TYPE 2
  55. #define WPS_OUI_TYPE 4
  56. #define VS_IE_FIXED_HDR_LEN 6
  57. #define WPA_IE_VERSION_LEN 2
  58. #define WPA_IE_MIN_OUI_LEN 4
  59. #define WPA_IE_SUITE_COUNT_LEN 2
  60. #define WPA_CIPHER_NONE 0 /* None */
  61. #define WPA_CIPHER_WEP_40 1 /* WEP (40-bit) */
  62. #define WPA_CIPHER_TKIP 2 /* TKIP: default for WPA */
  63. #define WPA_CIPHER_AES_CCM 4 /* AES (CCM) */
  64. #define WPA_CIPHER_WEP_104 5 /* WEP (104-bit) */
  65. #define RSN_AKM_NONE 0 /* None (IBSS) */
  66. #define RSN_AKM_UNSPECIFIED 1 /* Over 802.1x */
  67. #define RSN_AKM_PSK 2 /* Pre-shared Key */
  68. #define RSN_CAP_LEN 2 /* Length of RSN capabilities */
  69. #define RSN_CAP_PTK_REPLAY_CNTR_MASK 0x000C
  70. #define VNDR_IE_CMD_LEN 4 /* length of the set command
  71. * string :"add", "del" (+ NUL)
  72. */
  73. #define VNDR_IE_COUNT_OFFSET 4
  74. #define VNDR_IE_PKTFLAG_OFFSET 8
  75. #define VNDR_IE_VSIE_OFFSET 12
  76. #define VNDR_IE_HDR_SIZE 12
  77. #define VNDR_IE_PARSE_LIMIT 5
  78. #define DOT11_MGMT_HDR_LEN 24 /* d11 management header len */
  79. #define DOT11_BCN_PRB_FIXED_LEN 12 /* beacon/probe fixed length */
  80. #define BRCMF_SCAN_JOIN_ACTIVE_DWELL_TIME_MS 320
  81. #define BRCMF_SCAN_JOIN_PASSIVE_DWELL_TIME_MS 400
  82. #define BRCMF_SCAN_JOIN_PROBE_INTERVAL_MS 20
  83. #define BRCMF_ASSOC_PARAMS_FIXED_SIZE \
  84. (sizeof(struct brcmf_assoc_params_le) - sizeof(u16))
  85. static bool check_vif_up(struct brcmf_cfg80211_vif *vif)
  86. {
  87. if (!test_bit(BRCMF_VIF_STATUS_READY, &vif->sme_state)) {
  88. brcmf_dbg(INFO, "device is not ready : status (%lu)\n",
  89. vif->sme_state);
  90. return false;
  91. }
  92. return true;
  93. }
  94. #define RATE_TO_BASE100KBPS(rate) (((rate) * 10) / 2)
  95. #define RATETAB_ENT(_rateid, _flags) \
  96. { \
  97. .bitrate = RATE_TO_BASE100KBPS(_rateid), \
  98. .hw_value = (_rateid), \
  99. .flags = (_flags), \
  100. }
  101. static struct ieee80211_rate __wl_rates[] = {
  102. RATETAB_ENT(BRCM_RATE_1M, 0),
  103. RATETAB_ENT(BRCM_RATE_2M, IEEE80211_RATE_SHORT_PREAMBLE),
  104. RATETAB_ENT(BRCM_RATE_5M5, IEEE80211_RATE_SHORT_PREAMBLE),
  105. RATETAB_ENT(BRCM_RATE_11M, IEEE80211_RATE_SHORT_PREAMBLE),
  106. RATETAB_ENT(BRCM_RATE_6M, 0),
  107. RATETAB_ENT(BRCM_RATE_9M, 0),
  108. RATETAB_ENT(BRCM_RATE_12M, 0),
  109. RATETAB_ENT(BRCM_RATE_18M, 0),
  110. RATETAB_ENT(BRCM_RATE_24M, 0),
  111. RATETAB_ENT(BRCM_RATE_36M, 0),
  112. RATETAB_ENT(BRCM_RATE_48M, 0),
  113. RATETAB_ENT(BRCM_RATE_54M, 0),
  114. };
  115. #define wl_a_rates (__wl_rates + 4)
  116. #define wl_a_rates_size 8
  117. #define wl_g_rates (__wl_rates + 0)
  118. #define wl_g_rates_size 12
  119. /* Band templates duplicated per wiphy. The channel info
  120. * is filled in after querying the device.
  121. */
  122. static const struct ieee80211_supported_band __wl_band_2ghz = {
  123. .band = IEEE80211_BAND_2GHZ,
  124. .bitrates = wl_g_rates,
  125. .n_bitrates = wl_g_rates_size,
  126. };
  127. static const struct ieee80211_supported_band __wl_band_5ghz_a = {
  128. .band = IEEE80211_BAND_5GHZ,
  129. .bitrates = wl_a_rates,
  130. .n_bitrates = wl_a_rates_size,
  131. };
  132. /* This is to override regulatory domains defined in cfg80211 module (reg.c)
  133. * By default world regulatory domain defined in reg.c puts the flags
  134. * NL80211_RRF_NO_IR for 5GHz channels (for * 36..48 and 149..165).
  135. * With respect to these flags, wpa_supplicant doesn't * start p2p
  136. * operations on 5GHz channels. All the changes in world regulatory
  137. * domain are to be done here.
  138. */
  139. static const struct ieee80211_regdomain brcmf_regdom = {
  140. .n_reg_rules = 4,
  141. .alpha2 = "99",
  142. .reg_rules = {
  143. /* IEEE 802.11b/g, channels 1..11 */
  144. REG_RULE(2412-10, 2472+10, 40, 6, 20, 0),
  145. /* If any */
  146. /* IEEE 802.11 channel 14 - Only JP enables
  147. * this and for 802.11b only
  148. */
  149. REG_RULE(2484-10, 2484+10, 20, 6, 20, 0),
  150. /* IEEE 802.11a, channel 36..64 */
  151. REG_RULE(5150-10, 5350+10, 80, 6, 20, 0),
  152. /* IEEE 802.11a, channel 100..165 */
  153. REG_RULE(5470-10, 5850+10, 80, 6, 20, 0), }
  154. };
  155. static const u32 __wl_cipher_suites[] = {
  156. WLAN_CIPHER_SUITE_WEP40,
  157. WLAN_CIPHER_SUITE_WEP104,
  158. WLAN_CIPHER_SUITE_TKIP,
  159. WLAN_CIPHER_SUITE_CCMP,
  160. WLAN_CIPHER_SUITE_AES_CMAC,
  161. };
  162. /* Vendor specific ie. id = 221, oui and type defines exact ie */
  163. struct brcmf_vs_tlv {
  164. u8 id;
  165. u8 len;
  166. u8 oui[3];
  167. u8 oui_type;
  168. };
  169. struct parsed_vndr_ie_info {
  170. u8 *ie_ptr;
  171. u32 ie_len; /* total length including id & length field */
  172. struct brcmf_vs_tlv vndrie;
  173. };
  174. struct parsed_vndr_ies {
  175. u32 count;
  176. struct parsed_vndr_ie_info ie_info[VNDR_IE_PARSE_LIMIT];
  177. };
  178. static int brcmf_roamoff;
  179. module_param_named(roamoff, brcmf_roamoff, int, S_IRUSR);
  180. MODULE_PARM_DESC(roamoff, "do not use internal roaming engine");
  181. /* Quarter dBm units to mW
  182. * Table starts at QDBM_OFFSET, so the first entry is mW for qdBm=153
  183. * Table is offset so the last entry is largest mW value that fits in
  184. * a u16.
  185. */
  186. #define QDBM_OFFSET 153 /* Offset for first entry */
  187. #define QDBM_TABLE_LEN 40 /* Table size */
  188. /* Smallest mW value that will round up to the first table entry, QDBM_OFFSET.
  189. * Value is ( mW(QDBM_OFFSET - 1) + mW(QDBM_OFFSET) ) / 2
  190. */
  191. #define QDBM_TABLE_LOW_BOUND 6493 /* Low bound */
  192. /* Largest mW value that will round down to the last table entry,
  193. * QDBM_OFFSET + QDBM_TABLE_LEN-1.
  194. * Value is ( mW(QDBM_OFFSET + QDBM_TABLE_LEN - 1) +
  195. * mW(QDBM_OFFSET + QDBM_TABLE_LEN) ) / 2.
  196. */
  197. #define QDBM_TABLE_HIGH_BOUND 64938 /* High bound */
  198. static const u16 nqdBm_to_mW_map[QDBM_TABLE_LEN] = {
  199. /* qdBm: +0 +1 +2 +3 +4 +5 +6 +7 */
  200. /* 153: */ 6683, 7079, 7499, 7943, 8414, 8913, 9441, 10000,
  201. /* 161: */ 10593, 11220, 11885, 12589, 13335, 14125, 14962, 15849,
  202. /* 169: */ 16788, 17783, 18836, 19953, 21135, 22387, 23714, 25119,
  203. /* 177: */ 26607, 28184, 29854, 31623, 33497, 35481, 37584, 39811,
  204. /* 185: */ 42170, 44668, 47315, 50119, 53088, 56234, 59566, 63096
  205. };
  206. static u16 brcmf_qdbm_to_mw(u8 qdbm)
  207. {
  208. uint factor = 1;
  209. int idx = qdbm - QDBM_OFFSET;
  210. if (idx >= QDBM_TABLE_LEN)
  211. /* clamp to max u16 mW value */
  212. return 0xFFFF;
  213. /* scale the qdBm index up to the range of the table 0-40
  214. * where an offset of 40 qdBm equals a factor of 10 mW.
  215. */
  216. while (idx < 0) {
  217. idx += 40;
  218. factor *= 10;
  219. }
  220. /* return the mW value scaled down to the correct factor of 10,
  221. * adding in factor/2 to get proper rounding.
  222. */
  223. return (nqdBm_to_mW_map[idx] + factor / 2) / factor;
  224. }
  225. static u8 brcmf_mw_to_qdbm(u16 mw)
  226. {
  227. u8 qdbm;
  228. int offset;
  229. uint mw_uint = mw;
  230. uint boundary;
  231. /* handle boundary case */
  232. if (mw_uint <= 1)
  233. return 0;
  234. offset = QDBM_OFFSET;
  235. /* move mw into the range of the table */
  236. while (mw_uint < QDBM_TABLE_LOW_BOUND) {
  237. mw_uint *= 10;
  238. offset -= 40;
  239. }
  240. for (qdbm = 0; qdbm < QDBM_TABLE_LEN - 1; qdbm++) {
  241. boundary = nqdBm_to_mW_map[qdbm] + (nqdBm_to_mW_map[qdbm + 1] -
  242. nqdBm_to_mW_map[qdbm]) / 2;
  243. if (mw_uint < boundary)
  244. break;
  245. }
  246. qdbm += (u8) offset;
  247. return qdbm;
  248. }
  249. static u16 chandef_to_chanspec(struct brcmu_d11inf *d11inf,
  250. struct cfg80211_chan_def *ch)
  251. {
  252. struct brcmu_chan ch_inf;
  253. s32 primary_offset;
  254. brcmf_dbg(TRACE, "chandef: control %d center %d width %d\n",
  255. ch->chan->center_freq, ch->center_freq1, ch->width);
  256. ch_inf.chnum = ieee80211_frequency_to_channel(ch->center_freq1);
  257. primary_offset = ch->center_freq1 - ch->chan->center_freq;
  258. switch (ch->width) {
  259. case NL80211_CHAN_WIDTH_20:
  260. case NL80211_CHAN_WIDTH_20_NOHT:
  261. ch_inf.bw = BRCMU_CHAN_BW_20;
  262. WARN_ON(primary_offset != 0);
  263. break;
  264. case NL80211_CHAN_WIDTH_40:
  265. ch_inf.bw = BRCMU_CHAN_BW_40;
  266. if (primary_offset < 0)
  267. ch_inf.sb = BRCMU_CHAN_SB_U;
  268. else
  269. ch_inf.sb = BRCMU_CHAN_SB_L;
  270. break;
  271. case NL80211_CHAN_WIDTH_80:
  272. ch_inf.bw = BRCMU_CHAN_BW_80;
  273. if (primary_offset < 0) {
  274. if (primary_offset < -CH_10MHZ_APART)
  275. ch_inf.sb = BRCMU_CHAN_SB_UU;
  276. else
  277. ch_inf.sb = BRCMU_CHAN_SB_UL;
  278. } else {
  279. if (primary_offset > CH_10MHZ_APART)
  280. ch_inf.sb = BRCMU_CHAN_SB_LL;
  281. else
  282. ch_inf.sb = BRCMU_CHAN_SB_LU;
  283. }
  284. break;
  285. case NL80211_CHAN_WIDTH_80P80:
  286. case NL80211_CHAN_WIDTH_160:
  287. case NL80211_CHAN_WIDTH_5:
  288. case NL80211_CHAN_WIDTH_10:
  289. default:
  290. WARN_ON_ONCE(1);
  291. }
  292. switch (ch->chan->band) {
  293. case IEEE80211_BAND_2GHZ:
  294. ch_inf.band = BRCMU_CHAN_BAND_2G;
  295. break;
  296. case IEEE80211_BAND_5GHZ:
  297. ch_inf.band = BRCMU_CHAN_BAND_5G;
  298. break;
  299. case IEEE80211_BAND_60GHZ:
  300. default:
  301. WARN_ON_ONCE(1);
  302. }
  303. d11inf->encchspec(&ch_inf);
  304. return ch_inf.chspec;
  305. }
  306. u16 channel_to_chanspec(struct brcmu_d11inf *d11inf,
  307. struct ieee80211_channel *ch)
  308. {
  309. struct brcmu_chan ch_inf;
  310. ch_inf.chnum = ieee80211_frequency_to_channel(ch->center_freq);
  311. ch_inf.bw = BRCMU_CHAN_BW_20;
  312. d11inf->encchspec(&ch_inf);
  313. return ch_inf.chspec;
  314. }
  315. /* Traverse a string of 1-byte tag/1-byte length/variable-length value
  316. * triples, returning a pointer to the substring whose first element
  317. * matches tag
  318. */
  319. const struct brcmf_tlv *
  320. brcmf_parse_tlvs(const void *buf, int buflen, uint key)
  321. {
  322. const struct brcmf_tlv *elt = buf;
  323. int totlen = buflen;
  324. /* find tagged parameter */
  325. while (totlen >= TLV_HDR_LEN) {
  326. int len = elt->len;
  327. /* validate remaining totlen */
  328. if ((elt->id == key) && (totlen >= (len + TLV_HDR_LEN)))
  329. return elt;
  330. elt = (struct brcmf_tlv *)((u8 *)elt + (len + TLV_HDR_LEN));
  331. totlen -= (len + TLV_HDR_LEN);
  332. }
  333. return NULL;
  334. }
  335. /* Is any of the tlvs the expected entry? If
  336. * not update the tlvs buffer pointer/length.
  337. */
  338. static bool
  339. brcmf_tlv_has_ie(const u8 *ie, const u8 **tlvs, u32 *tlvs_len,
  340. const u8 *oui, u32 oui_len, u8 type)
  341. {
  342. /* If the contents match the OUI and the type */
  343. if (ie[TLV_LEN_OFF] >= oui_len + 1 &&
  344. !memcmp(&ie[TLV_BODY_OFF], oui, oui_len) &&
  345. type == ie[TLV_BODY_OFF + oui_len]) {
  346. return true;
  347. }
  348. if (tlvs == NULL)
  349. return false;
  350. /* point to the next ie */
  351. ie += ie[TLV_LEN_OFF] + TLV_HDR_LEN;
  352. /* calculate the length of the rest of the buffer */
  353. *tlvs_len -= (int)(ie - *tlvs);
  354. /* update the pointer to the start of the buffer */
  355. *tlvs = ie;
  356. return false;
  357. }
  358. static struct brcmf_vs_tlv *
  359. brcmf_find_wpaie(const u8 *parse, u32 len)
  360. {
  361. const struct brcmf_tlv *ie;
  362. while ((ie = brcmf_parse_tlvs(parse, len, WLAN_EID_VENDOR_SPECIFIC))) {
  363. if (brcmf_tlv_has_ie((const u8 *)ie, &parse, &len,
  364. WPA_OUI, TLV_OUI_LEN, WPA_OUI_TYPE))
  365. return (struct brcmf_vs_tlv *)ie;
  366. }
  367. return NULL;
  368. }
  369. static struct brcmf_vs_tlv *
  370. brcmf_find_wpsie(const u8 *parse, u32 len)
  371. {
  372. const struct brcmf_tlv *ie;
  373. while ((ie = brcmf_parse_tlvs(parse, len, WLAN_EID_VENDOR_SPECIFIC))) {
  374. if (brcmf_tlv_has_ie((u8 *)ie, &parse, &len,
  375. WPA_OUI, TLV_OUI_LEN, WPS_OUI_TYPE))
  376. return (struct brcmf_vs_tlv *)ie;
  377. }
  378. return NULL;
  379. }
  380. static void convert_key_from_CPU(struct brcmf_wsec_key *key,
  381. struct brcmf_wsec_key_le *key_le)
  382. {
  383. key_le->index = cpu_to_le32(key->index);
  384. key_le->len = cpu_to_le32(key->len);
  385. key_le->algo = cpu_to_le32(key->algo);
  386. key_le->flags = cpu_to_le32(key->flags);
  387. key_le->rxiv.hi = cpu_to_le32(key->rxiv.hi);
  388. key_le->rxiv.lo = cpu_to_le16(key->rxiv.lo);
  389. key_le->iv_initialized = cpu_to_le32(key->iv_initialized);
  390. memcpy(key_le->data, key->data, sizeof(key->data));
  391. memcpy(key_le->ea, key->ea, sizeof(key->ea));
  392. }
  393. static int
  394. send_key_to_dongle(struct brcmf_if *ifp, struct brcmf_wsec_key *key)
  395. {
  396. int err;
  397. struct brcmf_wsec_key_le key_le;
  398. convert_key_from_CPU(key, &key_le);
  399. brcmf_netdev_wait_pend8021x(ifp);
  400. err = brcmf_fil_bsscfg_data_set(ifp, "wsec_key", &key_le,
  401. sizeof(key_le));
  402. if (err)
  403. brcmf_err("wsec_key error (%d)\n", err);
  404. return err;
  405. }
  406. static s32
  407. brcmf_configure_arp_offload(struct brcmf_if *ifp, bool enable)
  408. {
  409. s32 err;
  410. u32 mode;
  411. if (enable)
  412. mode = BRCMF_ARP_OL_AGENT | BRCMF_ARP_OL_PEER_AUTO_REPLY;
  413. else
  414. mode = 0;
  415. /* Try to set and enable ARP offload feature, this may fail, then it */
  416. /* is simply not supported and err 0 will be returned */
  417. err = brcmf_fil_iovar_int_set(ifp, "arp_ol", mode);
  418. if (err) {
  419. brcmf_dbg(TRACE, "failed to set ARP offload mode to 0x%x, err = %d\n",
  420. mode, err);
  421. err = 0;
  422. } else {
  423. err = brcmf_fil_iovar_int_set(ifp, "arpoe", enable);
  424. if (err) {
  425. brcmf_dbg(TRACE, "failed to configure (%d) ARP offload err = %d\n",
  426. enable, err);
  427. err = 0;
  428. } else
  429. brcmf_dbg(TRACE, "successfully configured (%d) ARP offload to 0x%x\n",
  430. enable, mode);
  431. }
  432. return err;
  433. }
  434. static void
  435. brcmf_cfg80211_update_proto_addr_mode(struct wireless_dev *wdev)
  436. {
  437. struct brcmf_cfg80211_vif *vif;
  438. struct brcmf_if *ifp;
  439. vif = container_of(wdev, struct brcmf_cfg80211_vif, wdev);
  440. ifp = vif->ifp;
  441. if ((wdev->iftype == NL80211_IFTYPE_ADHOC) ||
  442. (wdev->iftype == NL80211_IFTYPE_AP) ||
  443. (wdev->iftype == NL80211_IFTYPE_P2P_GO))
  444. brcmf_proto_configure_addr_mode(ifp->drvr, ifp->ifidx,
  445. ADDR_DIRECT);
  446. else
  447. brcmf_proto_configure_addr_mode(ifp->drvr, ifp->ifidx,
  448. ADDR_INDIRECT);
  449. }
  450. static int brcmf_cfg80211_request_ap_if(struct brcmf_if *ifp)
  451. {
  452. struct brcmf_mbss_ssid_le mbss_ssid_le;
  453. int bsscfgidx;
  454. int err;
  455. memset(&mbss_ssid_le, 0, sizeof(mbss_ssid_le));
  456. bsscfgidx = brcmf_get_next_free_bsscfgidx(ifp->drvr);
  457. if (bsscfgidx < 0)
  458. return bsscfgidx;
  459. mbss_ssid_le.bsscfgidx = cpu_to_le32(bsscfgidx);
  460. mbss_ssid_le.SSID_len = cpu_to_le32(5);
  461. sprintf(mbss_ssid_le.SSID, "ssid%d" , bsscfgidx);
  462. err = brcmf_fil_bsscfg_data_set(ifp, "bsscfg:ssid", &mbss_ssid_le,
  463. sizeof(mbss_ssid_le));
  464. if (err < 0)
  465. brcmf_err("setting ssid failed %d\n", err);
  466. return err;
  467. }
  468. /**
  469. * brcmf_ap_add_vif() - create a new AP virtual interface for multiple BSS
  470. *
  471. * @wiphy: wiphy device of new interface.
  472. * @name: name of the new interface.
  473. * @flags: not used.
  474. * @params: contains mac address for AP device.
  475. */
  476. static
  477. struct wireless_dev *brcmf_ap_add_vif(struct wiphy *wiphy, const char *name,
  478. u32 *flags, struct vif_params *params)
  479. {
  480. struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
  481. struct brcmf_if *ifp = netdev_priv(cfg_to_ndev(cfg));
  482. struct brcmf_cfg80211_vif *vif;
  483. int err;
  484. if (brcmf_cfg80211_vif_event_armed(cfg))
  485. return ERR_PTR(-EBUSY);
  486. brcmf_dbg(INFO, "Adding vif \"%s\"\n", name);
  487. vif = brcmf_alloc_vif(cfg, NL80211_IFTYPE_AP, false);
  488. if (IS_ERR(vif))
  489. return (struct wireless_dev *)vif;
  490. brcmf_cfg80211_arm_vif_event(cfg, vif);
  491. err = brcmf_cfg80211_request_ap_if(ifp);
  492. if (err) {
  493. brcmf_cfg80211_arm_vif_event(cfg, NULL);
  494. goto fail;
  495. }
  496. /* wait for firmware event */
  497. err = brcmf_cfg80211_wait_vif_event_timeout(cfg, BRCMF_E_IF_ADD,
  498. msecs_to_jiffies(1500));
  499. brcmf_cfg80211_arm_vif_event(cfg, NULL);
  500. if (!err) {
  501. brcmf_err("timeout occurred\n");
  502. err = -EIO;
  503. goto fail;
  504. }
  505. /* interface created in firmware */
  506. ifp = vif->ifp;
  507. if (!ifp) {
  508. brcmf_err("no if pointer provided\n");
  509. err = -ENOENT;
  510. goto fail;
  511. }
  512. strncpy(ifp->ndev->name, name, sizeof(ifp->ndev->name) - 1);
  513. err = brcmf_net_attach(ifp, true);
  514. if (err) {
  515. brcmf_err("Registering netdevice failed\n");
  516. goto fail;
  517. }
  518. return &ifp->vif->wdev;
  519. fail:
  520. brcmf_free_vif(vif);
  521. return ERR_PTR(err);
  522. }
  523. static bool brcmf_is_apmode(struct brcmf_cfg80211_vif *vif)
  524. {
  525. enum nl80211_iftype iftype;
  526. iftype = vif->wdev.iftype;
  527. return iftype == NL80211_IFTYPE_AP || iftype == NL80211_IFTYPE_P2P_GO;
  528. }
  529. static bool brcmf_is_ibssmode(struct brcmf_cfg80211_vif *vif)
  530. {
  531. return vif->wdev.iftype == NL80211_IFTYPE_ADHOC;
  532. }
  533. static struct wireless_dev *brcmf_cfg80211_add_iface(struct wiphy *wiphy,
  534. const char *name,
  535. enum nl80211_iftype type,
  536. u32 *flags,
  537. struct vif_params *params)
  538. {
  539. struct wireless_dev *wdev;
  540. brcmf_dbg(TRACE, "enter: %s type %d\n", name, type);
  541. switch (type) {
  542. case NL80211_IFTYPE_ADHOC:
  543. case NL80211_IFTYPE_STATION:
  544. case NL80211_IFTYPE_AP_VLAN:
  545. case NL80211_IFTYPE_WDS:
  546. case NL80211_IFTYPE_MONITOR:
  547. case NL80211_IFTYPE_MESH_POINT:
  548. return ERR_PTR(-EOPNOTSUPP);
  549. case NL80211_IFTYPE_AP:
  550. wdev = brcmf_ap_add_vif(wiphy, name, flags, params);
  551. if (!IS_ERR(wdev))
  552. brcmf_cfg80211_update_proto_addr_mode(wdev);
  553. return wdev;
  554. case NL80211_IFTYPE_P2P_CLIENT:
  555. case NL80211_IFTYPE_P2P_GO:
  556. case NL80211_IFTYPE_P2P_DEVICE:
  557. wdev = brcmf_p2p_add_vif(wiphy, name, type, flags, params);
  558. if (!IS_ERR(wdev))
  559. brcmf_cfg80211_update_proto_addr_mode(wdev);
  560. return wdev;
  561. case NL80211_IFTYPE_UNSPECIFIED:
  562. default:
  563. return ERR_PTR(-EINVAL);
  564. }
  565. }
  566. static void brcmf_scan_config_mpc(struct brcmf_if *ifp, int mpc)
  567. {
  568. if (brcmf_feat_is_quirk_enabled(ifp, BRCMF_FEAT_QUIRK_NEED_MPC))
  569. brcmf_set_mpc(ifp, mpc);
  570. }
  571. void brcmf_set_mpc(struct brcmf_if *ifp, int mpc)
  572. {
  573. s32 err = 0;
  574. if (check_vif_up(ifp->vif)) {
  575. err = brcmf_fil_iovar_int_set(ifp, "mpc", mpc);
  576. if (err) {
  577. brcmf_err("fail to set mpc\n");
  578. return;
  579. }
  580. brcmf_dbg(INFO, "MPC : %d\n", mpc);
  581. }
  582. }
  583. s32 brcmf_notify_escan_complete(struct brcmf_cfg80211_info *cfg,
  584. struct brcmf_if *ifp, bool aborted,
  585. bool fw_abort)
  586. {
  587. struct brcmf_scan_params_le params_le;
  588. struct cfg80211_scan_request *scan_request;
  589. s32 err = 0;
  590. brcmf_dbg(SCAN, "Enter\n");
  591. /* clear scan request, because the FW abort can cause a second call */
  592. /* to this functon and might cause a double cfg80211_scan_done */
  593. scan_request = cfg->scan_request;
  594. cfg->scan_request = NULL;
  595. if (timer_pending(&cfg->escan_timeout))
  596. del_timer_sync(&cfg->escan_timeout);
  597. if (fw_abort) {
  598. /* Do a scan abort to stop the driver's scan engine */
  599. brcmf_dbg(SCAN, "ABORT scan in firmware\n");
  600. memset(&params_le, 0, sizeof(params_le));
  601. memset(params_le.bssid, 0xFF, ETH_ALEN);
  602. params_le.bss_type = DOT11_BSSTYPE_ANY;
  603. params_le.scan_type = 0;
  604. params_le.channel_num = cpu_to_le32(1);
  605. params_le.nprobes = cpu_to_le32(1);
  606. params_le.active_time = cpu_to_le32(-1);
  607. params_le.passive_time = cpu_to_le32(-1);
  608. params_le.home_time = cpu_to_le32(-1);
  609. /* Scan is aborted by setting channel_list[0] to -1 */
  610. params_le.channel_list[0] = cpu_to_le16(-1);
  611. /* E-Scan (or anyother type) can be aborted by SCAN */
  612. err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SCAN,
  613. &params_le, sizeof(params_le));
  614. if (err)
  615. brcmf_err("Scan abort failed\n");
  616. }
  617. brcmf_scan_config_mpc(ifp, 1);
  618. /*
  619. * e-scan can be initiated by scheduled scan
  620. * which takes precedence.
  621. */
  622. if (cfg->sched_escan) {
  623. brcmf_dbg(SCAN, "scheduled scan completed\n");
  624. cfg->sched_escan = false;
  625. if (!aborted)
  626. cfg80211_sched_scan_results(cfg_to_wiphy(cfg));
  627. } else if (scan_request) {
  628. brcmf_dbg(SCAN, "ESCAN Completed scan: %s\n",
  629. aborted ? "Aborted" : "Done");
  630. cfg80211_scan_done(scan_request, aborted);
  631. }
  632. if (!test_and_clear_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status))
  633. brcmf_dbg(SCAN, "Scan complete, probably P2P scan\n");
  634. return err;
  635. }
  636. static
  637. int brcmf_cfg80211_del_iface(struct wiphy *wiphy, struct wireless_dev *wdev)
  638. {
  639. struct brcmf_cfg80211_info *cfg = wiphy_priv(wiphy);
  640. struct net_device *ndev = wdev->netdev;
  641. /* vif event pending in firmware */
  642. if (brcmf_cfg80211_vif_event_armed(cfg))
  643. return -EBUSY;
  644. if (ndev) {
  645. if (test_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status) &&
  646. cfg->escan_info.ifp == netdev_priv(ndev))
  647. brcmf_notify_escan_complete(cfg, netdev_priv(ndev),
  648. true, true);
  649. brcmf_fil_iovar_int_set(netdev_priv(ndev), "mpc", 1);
  650. }
  651. switch (wdev->iftype) {
  652. case NL80211_IFTYPE_ADHOC:
  653. case NL80211_IFTYPE_STATION:
  654. case NL80211_IFTYPE_AP:
  655. case NL80211_IFTYPE_AP_VLAN:
  656. case NL80211_IFTYPE_WDS:
  657. case NL80211_IFTYPE_MONITOR:
  658. case NL80211_IFTYPE_MESH_POINT:
  659. return -EOPNOTSUPP;
  660. case NL80211_IFTYPE_P2P_CLIENT:
  661. case NL80211_IFTYPE_P2P_GO:
  662. case NL80211_IFTYPE_P2P_DEVICE:
  663. return brcmf_p2p_del_vif(wiphy, wdev);
  664. case NL80211_IFTYPE_UNSPECIFIED:
  665. default:
  666. return -EINVAL;
  667. }
  668. return -EOPNOTSUPP;
  669. }
  670. static s32
  671. brcmf_cfg80211_change_iface(struct wiphy *wiphy, struct net_device *ndev,
  672. enum nl80211_iftype type, u32 *flags,
  673. struct vif_params *params)
  674. {
  675. struct brcmf_cfg80211_info *cfg = wiphy_priv(wiphy);
  676. struct brcmf_if *ifp = netdev_priv(ndev);
  677. struct brcmf_cfg80211_vif *vif = ifp->vif;
  678. s32 infra = 0;
  679. s32 ap = 0;
  680. s32 err = 0;
  681. brcmf_dbg(TRACE, "Enter, ndev=%p, type=%d\n", ndev, type);
  682. switch (type) {
  683. case NL80211_IFTYPE_MONITOR:
  684. case NL80211_IFTYPE_WDS:
  685. brcmf_err("type (%d) : currently we do not support this type\n",
  686. type);
  687. return -EOPNOTSUPP;
  688. case NL80211_IFTYPE_ADHOC:
  689. infra = 0;
  690. break;
  691. case NL80211_IFTYPE_STATION:
  692. /* Ignore change for p2p IF. Unclear why supplicant does this */
  693. if ((vif->wdev.iftype == NL80211_IFTYPE_P2P_CLIENT) ||
  694. (vif->wdev.iftype == NL80211_IFTYPE_P2P_GO)) {
  695. brcmf_dbg(TRACE, "Ignoring cmd for p2p if\n");
  696. /* WAR: It is unexpected to get a change of VIF for P2P
  697. * IF, but it happens. The request can not be handled
  698. * but returning EPERM causes a crash. Returning 0
  699. * without setting ieee80211_ptr->iftype causes trace
  700. * (WARN_ON) but it works with wpa_supplicant
  701. */
  702. return 0;
  703. }
  704. infra = 1;
  705. break;
  706. case NL80211_IFTYPE_AP:
  707. case NL80211_IFTYPE_P2P_GO:
  708. ap = 1;
  709. break;
  710. default:
  711. err = -EINVAL;
  712. goto done;
  713. }
  714. if (ap) {
  715. if (type == NL80211_IFTYPE_P2P_GO) {
  716. brcmf_dbg(INFO, "IF Type = P2P GO\n");
  717. err = brcmf_p2p_ifchange(cfg, BRCMF_FIL_P2P_IF_GO);
  718. }
  719. if (!err) {
  720. set_bit(BRCMF_VIF_STATUS_AP_CREATING, &vif->sme_state);
  721. brcmf_dbg(INFO, "IF Type = AP\n");
  722. }
  723. } else {
  724. err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_INFRA, infra);
  725. if (err) {
  726. brcmf_err("WLC_SET_INFRA error (%d)\n", err);
  727. err = -EAGAIN;
  728. goto done;
  729. }
  730. brcmf_dbg(INFO, "IF Type = %s\n", brcmf_is_ibssmode(vif) ?
  731. "Adhoc" : "Infra");
  732. }
  733. ndev->ieee80211_ptr->iftype = type;
  734. brcmf_cfg80211_update_proto_addr_mode(&vif->wdev);
  735. done:
  736. brcmf_dbg(TRACE, "Exit\n");
  737. return err;
  738. }
  739. static void brcmf_escan_prep(struct brcmf_cfg80211_info *cfg,
  740. struct brcmf_scan_params_le *params_le,
  741. struct cfg80211_scan_request *request)
  742. {
  743. u32 n_ssids;
  744. u32 n_channels;
  745. s32 i;
  746. s32 offset;
  747. u16 chanspec;
  748. char *ptr;
  749. struct brcmf_ssid_le ssid_le;
  750. memset(params_le->bssid, 0xFF, ETH_ALEN);
  751. params_le->bss_type = DOT11_BSSTYPE_ANY;
  752. params_le->scan_type = 0;
  753. params_le->channel_num = 0;
  754. params_le->nprobes = cpu_to_le32(-1);
  755. params_le->active_time = cpu_to_le32(-1);
  756. params_le->passive_time = cpu_to_le32(-1);
  757. params_le->home_time = cpu_to_le32(-1);
  758. memset(&params_le->ssid_le, 0, sizeof(params_le->ssid_le));
  759. /* if request is null exit so it will be all channel broadcast scan */
  760. if (!request)
  761. return;
  762. n_ssids = request->n_ssids;
  763. n_channels = request->n_channels;
  764. /* Copy channel array if applicable */
  765. brcmf_dbg(SCAN, "### List of channelspecs to scan ### %d\n",
  766. n_channels);
  767. if (n_channels > 0) {
  768. for (i = 0; i < n_channels; i++) {
  769. chanspec = channel_to_chanspec(&cfg->d11inf,
  770. request->channels[i]);
  771. brcmf_dbg(SCAN, "Chan : %d, Channel spec: %x\n",
  772. request->channels[i]->hw_value, chanspec);
  773. params_le->channel_list[i] = cpu_to_le16(chanspec);
  774. }
  775. } else {
  776. brcmf_dbg(SCAN, "Scanning all channels\n");
  777. }
  778. /* Copy ssid array if applicable */
  779. brcmf_dbg(SCAN, "### List of SSIDs to scan ### %d\n", n_ssids);
  780. if (n_ssids > 0) {
  781. offset = offsetof(struct brcmf_scan_params_le, channel_list) +
  782. n_channels * sizeof(u16);
  783. offset = roundup(offset, sizeof(u32));
  784. ptr = (char *)params_le + offset;
  785. for (i = 0; i < n_ssids; i++) {
  786. memset(&ssid_le, 0, sizeof(ssid_le));
  787. ssid_le.SSID_len =
  788. cpu_to_le32(request->ssids[i].ssid_len);
  789. memcpy(ssid_le.SSID, request->ssids[i].ssid,
  790. request->ssids[i].ssid_len);
  791. if (!ssid_le.SSID_len)
  792. brcmf_dbg(SCAN, "%d: Broadcast scan\n", i);
  793. else
  794. brcmf_dbg(SCAN, "%d: scan for %s size =%d\n",
  795. i, ssid_le.SSID, ssid_le.SSID_len);
  796. memcpy(ptr, &ssid_le, sizeof(ssid_le));
  797. ptr += sizeof(ssid_le);
  798. }
  799. } else {
  800. brcmf_dbg(SCAN, "Broadcast scan %p\n", request->ssids);
  801. if ((request->ssids) && request->ssids->ssid_len) {
  802. brcmf_dbg(SCAN, "SSID %s len=%d\n",
  803. params_le->ssid_le.SSID,
  804. request->ssids->ssid_len);
  805. params_le->ssid_le.SSID_len =
  806. cpu_to_le32(request->ssids->ssid_len);
  807. memcpy(&params_le->ssid_le.SSID, request->ssids->ssid,
  808. request->ssids->ssid_len);
  809. }
  810. }
  811. /* Adding mask to channel numbers */
  812. params_le->channel_num =
  813. cpu_to_le32((n_ssids << BRCMF_SCAN_PARAMS_NSSID_SHIFT) |
  814. (n_channels & BRCMF_SCAN_PARAMS_COUNT_MASK));
  815. }
  816. static s32
  817. brcmf_run_escan(struct brcmf_cfg80211_info *cfg, struct brcmf_if *ifp,
  818. struct cfg80211_scan_request *request, u16 action)
  819. {
  820. s32 params_size = BRCMF_SCAN_PARAMS_FIXED_SIZE +
  821. offsetof(struct brcmf_escan_params_le, params_le);
  822. struct brcmf_escan_params_le *params;
  823. s32 err = 0;
  824. brcmf_dbg(SCAN, "E-SCAN START\n");
  825. if (request != NULL) {
  826. /* Allocate space for populating ssids in struct */
  827. params_size += sizeof(u32) * ((request->n_channels + 1) / 2);
  828. /* Allocate space for populating ssids in struct */
  829. params_size += sizeof(struct brcmf_ssid) * request->n_ssids;
  830. }
  831. params = kzalloc(params_size, GFP_KERNEL);
  832. if (!params) {
  833. err = -ENOMEM;
  834. goto exit;
  835. }
  836. BUG_ON(params_size + sizeof("escan") >= BRCMF_DCMD_MEDLEN);
  837. brcmf_escan_prep(cfg, &params->params_le, request);
  838. params->version = cpu_to_le32(BRCMF_ESCAN_REQ_VERSION);
  839. params->action = cpu_to_le16(action);
  840. params->sync_id = cpu_to_le16(0x1234);
  841. err = brcmf_fil_iovar_data_set(ifp, "escan", params, params_size);
  842. if (err) {
  843. if (err == -EBUSY)
  844. brcmf_dbg(INFO, "system busy : escan canceled\n");
  845. else
  846. brcmf_err("error (%d)\n", err);
  847. }
  848. kfree(params);
  849. exit:
  850. return err;
  851. }
  852. static s32
  853. brcmf_do_escan(struct brcmf_cfg80211_info *cfg, struct wiphy *wiphy,
  854. struct brcmf_if *ifp, struct cfg80211_scan_request *request)
  855. {
  856. s32 err;
  857. u32 passive_scan;
  858. struct brcmf_scan_results *results;
  859. struct escan_info *escan = &cfg->escan_info;
  860. brcmf_dbg(SCAN, "Enter\n");
  861. escan->ifp = ifp;
  862. escan->wiphy = wiphy;
  863. escan->escan_state = WL_ESCAN_STATE_SCANNING;
  864. passive_scan = cfg->active_scan ? 0 : 1;
  865. err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_PASSIVE_SCAN,
  866. passive_scan);
  867. if (err) {
  868. brcmf_err("error (%d)\n", err);
  869. return err;
  870. }
  871. brcmf_scan_config_mpc(ifp, 0);
  872. results = (struct brcmf_scan_results *)cfg->escan_info.escan_buf;
  873. results->version = 0;
  874. results->count = 0;
  875. results->buflen = WL_ESCAN_RESULTS_FIXED_SIZE;
  876. err = escan->run(cfg, ifp, request, WL_ESCAN_ACTION_START);
  877. if (err)
  878. brcmf_scan_config_mpc(ifp, 1);
  879. return err;
  880. }
  881. static s32
  882. brcmf_cfg80211_escan(struct wiphy *wiphy, struct brcmf_cfg80211_vif *vif,
  883. struct cfg80211_scan_request *request,
  884. struct cfg80211_ssid *this_ssid)
  885. {
  886. struct brcmf_if *ifp = vif->ifp;
  887. struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
  888. struct cfg80211_ssid *ssids;
  889. struct brcmf_cfg80211_scan_req *sr = &cfg->scan_req_int;
  890. u32 passive_scan;
  891. bool escan_req;
  892. bool spec_scan;
  893. s32 err;
  894. u32 SSID_len;
  895. brcmf_dbg(SCAN, "START ESCAN\n");
  896. if (test_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status)) {
  897. brcmf_err("Scanning already: status (%lu)\n", cfg->scan_status);
  898. return -EAGAIN;
  899. }
  900. if (test_bit(BRCMF_SCAN_STATUS_ABORT, &cfg->scan_status)) {
  901. brcmf_err("Scanning being aborted: status (%lu)\n",
  902. cfg->scan_status);
  903. return -EAGAIN;
  904. }
  905. if (test_bit(BRCMF_SCAN_STATUS_SUPPRESS, &cfg->scan_status)) {
  906. brcmf_err("Scanning suppressed: status (%lu)\n",
  907. cfg->scan_status);
  908. return -EAGAIN;
  909. }
  910. if (test_bit(BRCMF_VIF_STATUS_CONNECTING, &ifp->vif->sme_state)) {
  911. brcmf_err("Connecting: status (%lu)\n", ifp->vif->sme_state);
  912. return -EAGAIN;
  913. }
  914. /* If scan req comes for p2p0, send it over primary I/F */
  915. if (vif == cfg->p2p.bss_idx[P2PAPI_BSSCFG_DEVICE].vif)
  916. vif = cfg->p2p.bss_idx[P2PAPI_BSSCFG_PRIMARY].vif;
  917. /* Arm scan timeout timer */
  918. mod_timer(&cfg->escan_timeout, jiffies +
  919. WL_ESCAN_TIMER_INTERVAL_MS * HZ / 1000);
  920. escan_req = false;
  921. if (request) {
  922. /* scan bss */
  923. ssids = request->ssids;
  924. escan_req = true;
  925. } else {
  926. /* scan in ibss */
  927. /* we don't do escan in ibss */
  928. ssids = this_ssid;
  929. }
  930. cfg->scan_request = request;
  931. set_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status);
  932. if (escan_req) {
  933. cfg->escan_info.run = brcmf_run_escan;
  934. err = brcmf_p2p_scan_prep(wiphy, request, vif);
  935. if (err)
  936. goto scan_out;
  937. err = brcmf_do_escan(cfg, wiphy, vif->ifp, request);
  938. if (err)
  939. goto scan_out;
  940. } else {
  941. brcmf_dbg(SCAN, "ssid \"%s\", ssid_len (%d)\n",
  942. ssids->ssid, ssids->ssid_len);
  943. memset(&sr->ssid_le, 0, sizeof(sr->ssid_le));
  944. SSID_len = min_t(u8, sizeof(sr->ssid_le.SSID), ssids->ssid_len);
  945. sr->ssid_le.SSID_len = cpu_to_le32(0);
  946. spec_scan = false;
  947. if (SSID_len) {
  948. memcpy(sr->ssid_le.SSID, ssids->ssid, SSID_len);
  949. sr->ssid_le.SSID_len = cpu_to_le32(SSID_len);
  950. spec_scan = true;
  951. } else
  952. brcmf_dbg(SCAN, "Broadcast scan\n");
  953. passive_scan = cfg->active_scan ? 0 : 1;
  954. err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_PASSIVE_SCAN,
  955. passive_scan);
  956. if (err) {
  957. brcmf_err("WLC_SET_PASSIVE_SCAN error (%d)\n", err);
  958. goto scan_out;
  959. }
  960. brcmf_scan_config_mpc(ifp, 0);
  961. err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SCAN,
  962. &sr->ssid_le, sizeof(sr->ssid_le));
  963. if (err) {
  964. if (err == -EBUSY)
  965. brcmf_dbg(INFO, "BUSY: scan for \"%s\" canceled\n",
  966. sr->ssid_le.SSID);
  967. else
  968. brcmf_err("WLC_SCAN error (%d)\n", err);
  969. brcmf_scan_config_mpc(ifp, 1);
  970. goto scan_out;
  971. }
  972. }
  973. return 0;
  974. scan_out:
  975. clear_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status);
  976. if (timer_pending(&cfg->escan_timeout))
  977. del_timer_sync(&cfg->escan_timeout);
  978. cfg->scan_request = NULL;
  979. return err;
  980. }
  981. static s32
  982. brcmf_cfg80211_scan(struct wiphy *wiphy, struct cfg80211_scan_request *request)
  983. {
  984. struct brcmf_cfg80211_vif *vif;
  985. s32 err = 0;
  986. brcmf_dbg(TRACE, "Enter\n");
  987. vif = container_of(request->wdev, struct brcmf_cfg80211_vif, wdev);
  988. if (!check_vif_up(vif))
  989. return -EIO;
  990. err = brcmf_cfg80211_escan(wiphy, vif, request, NULL);
  991. if (err)
  992. brcmf_err("scan error (%d)\n", err);
  993. brcmf_dbg(TRACE, "Exit\n");
  994. return err;
  995. }
  996. static s32 brcmf_set_rts(struct net_device *ndev, u32 rts_threshold)
  997. {
  998. s32 err = 0;
  999. err = brcmf_fil_iovar_int_set(netdev_priv(ndev), "rtsthresh",
  1000. rts_threshold);
  1001. if (err)
  1002. brcmf_err("Error (%d)\n", err);
  1003. return err;
  1004. }
  1005. static s32 brcmf_set_frag(struct net_device *ndev, u32 frag_threshold)
  1006. {
  1007. s32 err = 0;
  1008. err = brcmf_fil_iovar_int_set(netdev_priv(ndev), "fragthresh",
  1009. frag_threshold);
  1010. if (err)
  1011. brcmf_err("Error (%d)\n", err);
  1012. return err;
  1013. }
  1014. static s32 brcmf_set_retry(struct net_device *ndev, u32 retry, bool l)
  1015. {
  1016. s32 err = 0;
  1017. u32 cmd = (l ? BRCMF_C_SET_LRL : BRCMF_C_SET_SRL);
  1018. err = brcmf_fil_cmd_int_set(netdev_priv(ndev), cmd, retry);
  1019. if (err) {
  1020. brcmf_err("cmd (%d) , error (%d)\n", cmd, err);
  1021. return err;
  1022. }
  1023. return err;
  1024. }
  1025. static s32 brcmf_cfg80211_set_wiphy_params(struct wiphy *wiphy, u32 changed)
  1026. {
  1027. struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
  1028. struct net_device *ndev = cfg_to_ndev(cfg);
  1029. struct brcmf_if *ifp = netdev_priv(ndev);
  1030. s32 err = 0;
  1031. brcmf_dbg(TRACE, "Enter\n");
  1032. if (!check_vif_up(ifp->vif))
  1033. return -EIO;
  1034. if (changed & WIPHY_PARAM_RTS_THRESHOLD &&
  1035. (cfg->conf->rts_threshold != wiphy->rts_threshold)) {
  1036. cfg->conf->rts_threshold = wiphy->rts_threshold;
  1037. err = brcmf_set_rts(ndev, cfg->conf->rts_threshold);
  1038. if (!err)
  1039. goto done;
  1040. }
  1041. if (changed & WIPHY_PARAM_FRAG_THRESHOLD &&
  1042. (cfg->conf->frag_threshold != wiphy->frag_threshold)) {
  1043. cfg->conf->frag_threshold = wiphy->frag_threshold;
  1044. err = brcmf_set_frag(ndev, cfg->conf->frag_threshold);
  1045. if (!err)
  1046. goto done;
  1047. }
  1048. if (changed & WIPHY_PARAM_RETRY_LONG
  1049. && (cfg->conf->retry_long != wiphy->retry_long)) {
  1050. cfg->conf->retry_long = wiphy->retry_long;
  1051. err = brcmf_set_retry(ndev, cfg->conf->retry_long, true);
  1052. if (!err)
  1053. goto done;
  1054. }
  1055. if (changed & WIPHY_PARAM_RETRY_SHORT
  1056. && (cfg->conf->retry_short != wiphy->retry_short)) {
  1057. cfg->conf->retry_short = wiphy->retry_short;
  1058. err = brcmf_set_retry(ndev, cfg->conf->retry_short, false);
  1059. if (!err)
  1060. goto done;
  1061. }
  1062. done:
  1063. brcmf_dbg(TRACE, "Exit\n");
  1064. return err;
  1065. }
  1066. static void brcmf_init_prof(struct brcmf_cfg80211_profile *prof)
  1067. {
  1068. memset(prof, 0, sizeof(*prof));
  1069. }
  1070. static u16 brcmf_map_fw_linkdown_reason(const struct brcmf_event_msg *e)
  1071. {
  1072. u16 reason;
  1073. switch (e->event_code) {
  1074. case BRCMF_E_DEAUTH:
  1075. case BRCMF_E_DEAUTH_IND:
  1076. case BRCMF_E_DISASSOC_IND:
  1077. reason = e->reason;
  1078. break;
  1079. case BRCMF_E_LINK:
  1080. default:
  1081. reason = 0;
  1082. break;
  1083. }
  1084. return reason;
  1085. }
  1086. static void brcmf_link_down(struct brcmf_cfg80211_vif *vif, u16 reason)
  1087. {
  1088. struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(vif->wdev.wiphy);
  1089. s32 err = 0;
  1090. brcmf_dbg(TRACE, "Enter\n");
  1091. if (test_bit(BRCMF_VIF_STATUS_CONNECTED, &vif->sme_state)) {
  1092. brcmf_dbg(INFO, "Call WLC_DISASSOC to stop excess roaming\n ");
  1093. err = brcmf_fil_cmd_data_set(vif->ifp,
  1094. BRCMF_C_DISASSOC, NULL, 0);
  1095. if (err) {
  1096. brcmf_err("WLC_DISASSOC failed (%d)\n", err);
  1097. }
  1098. clear_bit(BRCMF_VIF_STATUS_CONNECTED, &vif->sme_state);
  1099. cfg80211_disconnected(vif->wdev.netdev, reason, NULL, 0,
  1100. GFP_KERNEL);
  1101. }
  1102. clear_bit(BRCMF_VIF_STATUS_CONNECTING, &vif->sme_state);
  1103. clear_bit(BRCMF_SCAN_STATUS_SUPPRESS, &cfg->scan_status);
  1104. brcmf_btcoex_set_mode(vif, BRCMF_BTCOEX_ENABLED, 0);
  1105. brcmf_dbg(TRACE, "Exit\n");
  1106. }
  1107. static s32
  1108. brcmf_cfg80211_join_ibss(struct wiphy *wiphy, struct net_device *ndev,
  1109. struct cfg80211_ibss_params *params)
  1110. {
  1111. struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
  1112. struct brcmf_if *ifp = netdev_priv(ndev);
  1113. struct brcmf_cfg80211_profile *profile = &ifp->vif->profile;
  1114. struct brcmf_join_params join_params;
  1115. size_t join_params_size = 0;
  1116. s32 err = 0;
  1117. s32 wsec = 0;
  1118. s32 bcnprd;
  1119. u16 chanspec;
  1120. brcmf_dbg(TRACE, "Enter\n");
  1121. if (!check_vif_up(ifp->vif))
  1122. return -EIO;
  1123. if (params->ssid)
  1124. brcmf_dbg(CONN, "SSID: %s\n", params->ssid);
  1125. else {
  1126. brcmf_dbg(CONN, "SSID: NULL, Not supported\n");
  1127. return -EOPNOTSUPP;
  1128. }
  1129. set_bit(BRCMF_VIF_STATUS_CONNECTING, &ifp->vif->sme_state);
  1130. if (params->bssid)
  1131. brcmf_dbg(CONN, "BSSID: %pM\n", params->bssid);
  1132. else
  1133. brcmf_dbg(CONN, "No BSSID specified\n");
  1134. if (params->chandef.chan)
  1135. brcmf_dbg(CONN, "channel: %d\n",
  1136. params->chandef.chan->center_freq);
  1137. else
  1138. brcmf_dbg(CONN, "no channel specified\n");
  1139. if (params->channel_fixed)
  1140. brcmf_dbg(CONN, "fixed channel required\n");
  1141. else
  1142. brcmf_dbg(CONN, "no fixed channel required\n");
  1143. if (params->ie && params->ie_len)
  1144. brcmf_dbg(CONN, "ie len: %d\n", params->ie_len);
  1145. else
  1146. brcmf_dbg(CONN, "no ie specified\n");
  1147. if (params->beacon_interval)
  1148. brcmf_dbg(CONN, "beacon interval: %d\n",
  1149. params->beacon_interval);
  1150. else
  1151. brcmf_dbg(CONN, "no beacon interval specified\n");
  1152. if (params->basic_rates)
  1153. brcmf_dbg(CONN, "basic rates: %08X\n", params->basic_rates);
  1154. else
  1155. brcmf_dbg(CONN, "no basic rates specified\n");
  1156. if (params->privacy)
  1157. brcmf_dbg(CONN, "privacy required\n");
  1158. else
  1159. brcmf_dbg(CONN, "no privacy required\n");
  1160. /* Configure Privacy for starter */
  1161. if (params->privacy)
  1162. wsec |= WEP_ENABLED;
  1163. err = brcmf_fil_iovar_int_set(ifp, "wsec", wsec);
  1164. if (err) {
  1165. brcmf_err("wsec failed (%d)\n", err);
  1166. goto done;
  1167. }
  1168. /* Configure Beacon Interval for starter */
  1169. if (params->beacon_interval)
  1170. bcnprd = params->beacon_interval;
  1171. else
  1172. bcnprd = 100;
  1173. err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_BCNPRD, bcnprd);
  1174. if (err) {
  1175. brcmf_err("WLC_SET_BCNPRD failed (%d)\n", err);
  1176. goto done;
  1177. }
  1178. /* Configure required join parameter */
  1179. memset(&join_params, 0, sizeof(struct brcmf_join_params));
  1180. /* SSID */
  1181. profile->ssid.SSID_len = min_t(u32, params->ssid_len, 32);
  1182. memcpy(profile->ssid.SSID, params->ssid, profile->ssid.SSID_len);
  1183. memcpy(join_params.ssid_le.SSID, params->ssid, profile->ssid.SSID_len);
  1184. join_params.ssid_le.SSID_len = cpu_to_le32(profile->ssid.SSID_len);
  1185. join_params_size = sizeof(join_params.ssid_le);
  1186. /* BSSID */
  1187. if (params->bssid) {
  1188. memcpy(join_params.params_le.bssid, params->bssid, ETH_ALEN);
  1189. join_params_size = sizeof(join_params.ssid_le) +
  1190. BRCMF_ASSOC_PARAMS_FIXED_SIZE;
  1191. memcpy(profile->bssid, params->bssid, ETH_ALEN);
  1192. } else {
  1193. memset(join_params.params_le.bssid, 0xFF, ETH_ALEN);
  1194. memset(profile->bssid, 0, ETH_ALEN);
  1195. }
  1196. /* Channel */
  1197. if (params->chandef.chan) {
  1198. u32 target_channel;
  1199. cfg->channel =
  1200. ieee80211_frequency_to_channel(
  1201. params->chandef.chan->center_freq);
  1202. if (params->channel_fixed) {
  1203. /* adding chanspec */
  1204. chanspec = chandef_to_chanspec(&cfg->d11inf,
  1205. &params->chandef);
  1206. join_params.params_le.chanspec_list[0] =
  1207. cpu_to_le16(chanspec);
  1208. join_params.params_le.chanspec_num = cpu_to_le32(1);
  1209. join_params_size += sizeof(join_params.params_le);
  1210. }
  1211. /* set channel for starter */
  1212. target_channel = cfg->channel;
  1213. err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_CHANNEL,
  1214. target_channel);
  1215. if (err) {
  1216. brcmf_err("WLC_SET_CHANNEL failed (%d)\n", err);
  1217. goto done;
  1218. }
  1219. } else
  1220. cfg->channel = 0;
  1221. cfg->ibss_starter = false;
  1222. err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_SSID,
  1223. &join_params, join_params_size);
  1224. if (err) {
  1225. brcmf_err("WLC_SET_SSID failed (%d)\n", err);
  1226. goto done;
  1227. }
  1228. done:
  1229. if (err)
  1230. clear_bit(BRCMF_VIF_STATUS_CONNECTING, &ifp->vif->sme_state);
  1231. brcmf_dbg(TRACE, "Exit\n");
  1232. return err;
  1233. }
  1234. static s32
  1235. brcmf_cfg80211_leave_ibss(struct wiphy *wiphy, struct net_device *ndev)
  1236. {
  1237. struct brcmf_if *ifp = netdev_priv(ndev);
  1238. brcmf_dbg(TRACE, "Enter\n");
  1239. if (!check_vif_up(ifp->vif))
  1240. return -EIO;
  1241. brcmf_link_down(ifp->vif, WLAN_REASON_DEAUTH_LEAVING);
  1242. brcmf_dbg(TRACE, "Exit\n");
  1243. return 0;
  1244. }
  1245. static s32 brcmf_set_wpa_version(struct net_device *ndev,
  1246. struct cfg80211_connect_params *sme)
  1247. {
  1248. struct brcmf_cfg80211_profile *profile = ndev_to_prof(ndev);
  1249. struct brcmf_cfg80211_security *sec;
  1250. s32 val = 0;
  1251. s32 err = 0;
  1252. if (sme->crypto.wpa_versions & NL80211_WPA_VERSION_1)
  1253. val = WPA_AUTH_PSK | WPA_AUTH_UNSPECIFIED;
  1254. else if (sme->crypto.wpa_versions & NL80211_WPA_VERSION_2)
  1255. val = WPA2_AUTH_PSK | WPA2_AUTH_UNSPECIFIED;
  1256. else
  1257. val = WPA_AUTH_DISABLED;
  1258. brcmf_dbg(CONN, "setting wpa_auth to 0x%0x\n", val);
  1259. err = brcmf_fil_bsscfg_int_set(netdev_priv(ndev), "wpa_auth", val);
  1260. if (err) {
  1261. brcmf_err("set wpa_auth failed (%d)\n", err);
  1262. return err;
  1263. }
  1264. sec = &profile->sec;
  1265. sec->wpa_versions = sme->crypto.wpa_versions;
  1266. return err;
  1267. }
  1268. static s32 brcmf_set_auth_type(struct net_device *ndev,
  1269. struct cfg80211_connect_params *sme)
  1270. {
  1271. struct brcmf_cfg80211_profile *profile = ndev_to_prof(ndev);
  1272. struct brcmf_cfg80211_security *sec;
  1273. s32 val = 0;
  1274. s32 err = 0;
  1275. switch (sme->auth_type) {
  1276. case NL80211_AUTHTYPE_OPEN_SYSTEM:
  1277. val = 0;
  1278. brcmf_dbg(CONN, "open system\n");
  1279. break;
  1280. case NL80211_AUTHTYPE_SHARED_KEY:
  1281. val = 1;
  1282. brcmf_dbg(CONN, "shared key\n");
  1283. break;
  1284. case NL80211_AUTHTYPE_AUTOMATIC:
  1285. val = 2;
  1286. brcmf_dbg(CONN, "automatic\n");
  1287. break;
  1288. case NL80211_AUTHTYPE_NETWORK_EAP:
  1289. brcmf_dbg(CONN, "network eap\n");
  1290. default:
  1291. val = 2;
  1292. brcmf_err("invalid auth type (%d)\n", sme->auth_type);
  1293. break;
  1294. }
  1295. err = brcmf_fil_bsscfg_int_set(netdev_priv(ndev), "auth", val);
  1296. if (err) {
  1297. brcmf_err("set auth failed (%d)\n", err);
  1298. return err;
  1299. }
  1300. sec = &profile->sec;
  1301. sec->auth_type = sme->auth_type;
  1302. return err;
  1303. }
  1304. static s32
  1305. brcmf_set_wsec_mode(struct net_device *ndev,
  1306. struct cfg80211_connect_params *sme, bool mfp)
  1307. {
  1308. struct brcmf_cfg80211_profile *profile = ndev_to_prof(ndev);
  1309. struct brcmf_cfg80211_security *sec;
  1310. s32 pval = 0;
  1311. s32 gval = 0;
  1312. s32 wsec;
  1313. s32 err = 0;
  1314. if (sme->crypto.n_ciphers_pairwise) {
  1315. switch (sme->crypto.ciphers_pairwise[0]) {
  1316. case WLAN_CIPHER_SUITE_WEP40:
  1317. case WLAN_CIPHER_SUITE_WEP104:
  1318. pval = WEP_ENABLED;
  1319. break;
  1320. case WLAN_CIPHER_SUITE_TKIP:
  1321. pval = TKIP_ENABLED;
  1322. break;
  1323. case WLAN_CIPHER_SUITE_CCMP:
  1324. pval = AES_ENABLED;
  1325. break;
  1326. case WLAN_CIPHER_SUITE_AES_CMAC:
  1327. pval = AES_ENABLED;
  1328. break;
  1329. default:
  1330. brcmf_err("invalid cipher pairwise (%d)\n",
  1331. sme->crypto.ciphers_pairwise[0]);
  1332. return -EINVAL;
  1333. }
  1334. }
  1335. if (sme->crypto.cipher_group) {
  1336. switch (sme->crypto.cipher_group) {
  1337. case WLAN_CIPHER_SUITE_WEP40:
  1338. case WLAN_CIPHER_SUITE_WEP104:
  1339. gval = WEP_ENABLED;
  1340. break;
  1341. case WLAN_CIPHER_SUITE_TKIP:
  1342. gval = TKIP_ENABLED;
  1343. break;
  1344. case WLAN_CIPHER_SUITE_CCMP:
  1345. gval = AES_ENABLED;
  1346. break;
  1347. case WLAN_CIPHER_SUITE_AES_CMAC:
  1348. gval = AES_ENABLED;
  1349. break;
  1350. default:
  1351. brcmf_err("invalid cipher group (%d)\n",
  1352. sme->crypto.cipher_group);
  1353. return -EINVAL;
  1354. }
  1355. }
  1356. brcmf_dbg(CONN, "pval (%d) gval (%d)\n", pval, gval);
  1357. /* In case of privacy, but no security and WPS then simulate */
  1358. /* setting AES. WPS-2.0 allows no security */
  1359. if (brcmf_find_wpsie(sme->ie, sme->ie_len) && !pval && !gval &&
  1360. sme->privacy)
  1361. pval = AES_ENABLED;
  1362. if (mfp)
  1363. wsec = pval | gval | MFP_CAPABLE;
  1364. else
  1365. wsec = pval | gval;
  1366. err = brcmf_fil_bsscfg_int_set(netdev_priv(ndev), "wsec", wsec);
  1367. if (err) {
  1368. brcmf_err("error (%d)\n", err);
  1369. return err;
  1370. }
  1371. sec = &profile->sec;
  1372. sec->cipher_pairwise = sme->crypto.ciphers_pairwise[0];
  1373. sec->cipher_group = sme->crypto.cipher_group;
  1374. return err;
  1375. }
  1376. static s32
  1377. brcmf_set_key_mgmt(struct net_device *ndev, struct cfg80211_connect_params *sme)
  1378. {
  1379. struct brcmf_cfg80211_profile *profile = ndev_to_prof(ndev);
  1380. struct brcmf_cfg80211_security *sec;
  1381. s32 val = 0;
  1382. s32 err = 0;
  1383. if (sme->crypto.n_akm_suites) {
  1384. err = brcmf_fil_bsscfg_int_get(netdev_priv(ndev),
  1385. "wpa_auth", &val);
  1386. if (err) {
  1387. brcmf_err("could not get wpa_auth (%d)\n", err);
  1388. return err;
  1389. }
  1390. if (val & (WPA_AUTH_PSK | WPA_AUTH_UNSPECIFIED)) {
  1391. switch (sme->crypto.akm_suites[0]) {
  1392. case WLAN_AKM_SUITE_8021X:
  1393. val = WPA_AUTH_UNSPECIFIED;
  1394. break;
  1395. case WLAN_AKM_SUITE_PSK:
  1396. val = WPA_AUTH_PSK;
  1397. break;
  1398. default:
  1399. brcmf_err("invalid cipher group (%d)\n",
  1400. sme->crypto.cipher_group);
  1401. return -EINVAL;
  1402. }
  1403. } else if (val & (WPA2_AUTH_PSK | WPA2_AUTH_UNSPECIFIED)) {
  1404. switch (sme->crypto.akm_suites[0]) {
  1405. case WLAN_AKM_SUITE_8021X:
  1406. val = WPA2_AUTH_UNSPECIFIED;
  1407. break;
  1408. case WLAN_AKM_SUITE_PSK:
  1409. val = WPA2_AUTH_PSK;
  1410. break;
  1411. default:
  1412. brcmf_err("invalid cipher group (%d)\n",
  1413. sme->crypto.cipher_group);
  1414. return -EINVAL;
  1415. }
  1416. }
  1417. brcmf_dbg(CONN, "setting wpa_auth to %d\n", val);
  1418. err = brcmf_fil_bsscfg_int_set(netdev_priv(ndev),
  1419. "wpa_auth", val);
  1420. if (err) {
  1421. brcmf_err("could not set wpa_auth (%d)\n", err);
  1422. return err;
  1423. }
  1424. }
  1425. sec = &profile->sec;
  1426. sec->wpa_auth = sme->crypto.akm_suites[0];
  1427. return err;
  1428. }
  1429. static s32
  1430. brcmf_set_sharedkey(struct net_device *ndev,
  1431. struct cfg80211_connect_params *sme)
  1432. {
  1433. struct brcmf_cfg80211_profile *profile = ndev_to_prof(ndev);
  1434. struct brcmf_cfg80211_security *sec;
  1435. struct brcmf_wsec_key key;
  1436. s32 val;
  1437. s32 err = 0;
  1438. brcmf_dbg(CONN, "key len (%d)\n", sme->key_len);
  1439. if (sme->key_len == 0)
  1440. return 0;
  1441. sec = &profile->sec;
  1442. brcmf_dbg(CONN, "wpa_versions 0x%x cipher_pairwise 0x%x\n",
  1443. sec->wpa_versions, sec->cipher_pairwise);
  1444. if (sec->wpa_versions & (NL80211_WPA_VERSION_1 | NL80211_WPA_VERSION_2))
  1445. return 0;
  1446. if (!(sec->cipher_pairwise &
  1447. (WLAN_CIPHER_SUITE_WEP40 | WLAN_CIPHER_SUITE_WEP104)))
  1448. return 0;
  1449. memset(&key, 0, sizeof(key));
  1450. key.len = (u32) sme->key_len;
  1451. key.index = (u32) sme->key_idx;
  1452. if (key.len > sizeof(key.data)) {
  1453. brcmf_err("Too long key length (%u)\n", key.len);
  1454. return -EINVAL;
  1455. }
  1456. memcpy(key.data, sme->key, key.len);
  1457. key.flags = BRCMF_PRIMARY_KEY;
  1458. switch (sec->cipher_pairwise) {
  1459. case WLAN_CIPHER_SUITE_WEP40:
  1460. key.algo = CRYPTO_ALGO_WEP1;
  1461. break;
  1462. case WLAN_CIPHER_SUITE_WEP104:
  1463. key.algo = CRYPTO_ALGO_WEP128;
  1464. break;
  1465. default:
  1466. brcmf_err("Invalid algorithm (%d)\n",
  1467. sme->crypto.ciphers_pairwise[0]);
  1468. return -EINVAL;
  1469. }
  1470. /* Set the new key/index */
  1471. brcmf_dbg(CONN, "key length (%d) key index (%d) algo (%d)\n",
  1472. key.len, key.index, key.algo);
  1473. brcmf_dbg(CONN, "key \"%s\"\n", key.data);
  1474. err = send_key_to_dongle(netdev_priv(ndev), &key);
  1475. if (err)
  1476. return err;
  1477. if (sec->auth_type == NL80211_AUTHTYPE_SHARED_KEY) {
  1478. brcmf_dbg(CONN, "set auth_type to shared key\n");
  1479. val = WL_AUTH_SHARED_KEY; /* shared key */
  1480. err = brcmf_fil_bsscfg_int_set(netdev_priv(ndev), "auth", val);
  1481. if (err)
  1482. brcmf_err("set auth failed (%d)\n", err);
  1483. }
  1484. return err;
  1485. }
  1486. static
  1487. enum nl80211_auth_type brcmf_war_auth_type(struct brcmf_if *ifp,
  1488. enum nl80211_auth_type type)
  1489. {
  1490. if (type == NL80211_AUTHTYPE_AUTOMATIC &&
  1491. brcmf_feat_is_quirk_enabled(ifp, BRCMF_FEAT_QUIRK_AUTO_AUTH)) {
  1492. brcmf_dbg(CONN, "WAR: use OPEN instead of AUTO\n");
  1493. type = NL80211_AUTHTYPE_OPEN_SYSTEM;
  1494. }
  1495. return type;
  1496. }
  1497. static s32
  1498. brcmf_cfg80211_connect(struct wiphy *wiphy, struct net_device *ndev,
  1499. struct cfg80211_connect_params *sme)
  1500. {
  1501. struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
  1502. struct brcmf_if *ifp = netdev_priv(ndev);
  1503. struct brcmf_cfg80211_profile *profile = &ifp->vif->profile;
  1504. struct ieee80211_channel *chan = sme->channel;
  1505. struct brcmf_join_params join_params;
  1506. size_t join_params_size;
  1507. const struct brcmf_tlv *rsn_ie;
  1508. const struct brcmf_vs_tlv *wpa_ie;
  1509. const void *ie;
  1510. u32 ie_len;
  1511. struct brcmf_ext_join_params_le *ext_join_params;
  1512. u16 chanspec;
  1513. s32 err = 0;
  1514. brcmf_dbg(TRACE, "Enter\n");
  1515. if (!check_vif_up(ifp->vif))
  1516. return -EIO;
  1517. if (!sme->ssid) {
  1518. brcmf_err("Invalid ssid\n");
  1519. return -EOPNOTSUPP;
  1520. }
  1521. if (ifp->vif == cfg->p2p.bss_idx[P2PAPI_BSSCFG_PRIMARY].vif) {
  1522. /* A normal (non P2P) connection request setup. */
  1523. ie = NULL;
  1524. ie_len = 0;
  1525. /* find the WPA_IE */
  1526. wpa_ie = brcmf_find_wpaie((u8 *)sme->ie, sme->ie_len);
  1527. if (wpa_ie) {
  1528. ie = wpa_ie;
  1529. ie_len = wpa_ie->len + TLV_HDR_LEN;
  1530. } else {
  1531. /* find the RSN_IE */
  1532. rsn_ie = brcmf_parse_tlvs((const u8 *)sme->ie,
  1533. sme->ie_len,
  1534. WLAN_EID_RSN);
  1535. if (rsn_ie) {
  1536. ie = rsn_ie;
  1537. ie_len = rsn_ie->len + TLV_HDR_LEN;
  1538. }
  1539. }
  1540. brcmf_fil_iovar_data_set(ifp, "wpaie", ie, ie_len);
  1541. }
  1542. err = brcmf_vif_set_mgmt_ie(ifp->vif, BRCMF_VNDR_IE_ASSOCREQ_FLAG,
  1543. sme->ie, sme->ie_len);
  1544. if (err)
  1545. brcmf_err("Set Assoc REQ IE Failed\n");
  1546. else
  1547. brcmf_dbg(TRACE, "Applied Vndr IEs for Assoc request\n");
  1548. set_bit(BRCMF_VIF_STATUS_CONNECTING, &ifp->vif->sme_state);
  1549. if (chan) {
  1550. cfg->channel =
  1551. ieee80211_frequency_to_channel(chan->center_freq);
  1552. chanspec = channel_to_chanspec(&cfg->d11inf, chan);
  1553. brcmf_dbg(CONN, "channel=%d, center_req=%d, chanspec=0x%04x\n",
  1554. cfg->channel, chan->center_freq, chanspec);
  1555. } else {
  1556. cfg->channel = 0;
  1557. chanspec = 0;
  1558. }
  1559. brcmf_dbg(INFO, "ie (%p), ie_len (%zd)\n", sme->ie, sme->ie_len);
  1560. err = brcmf_set_wpa_version(ndev, sme);
  1561. if (err) {
  1562. brcmf_err("wl_set_wpa_version failed (%d)\n", err);
  1563. goto done;
  1564. }
  1565. sme->auth_type = brcmf_war_auth_type(ifp, sme->auth_type);
  1566. err = brcmf_set_auth_type(ndev, sme);
  1567. if (err) {
  1568. brcmf_err("wl_set_auth_type failed (%d)\n", err);
  1569. goto done;
  1570. }
  1571. err = brcmf_set_wsec_mode(ndev, sme, sme->mfp == NL80211_MFP_REQUIRED);
  1572. if (err) {
  1573. brcmf_err("wl_set_set_cipher failed (%d)\n", err);
  1574. goto done;
  1575. }
  1576. err = brcmf_set_key_mgmt(ndev, sme);
  1577. if (err) {
  1578. brcmf_err("wl_set_key_mgmt failed (%d)\n", err);
  1579. goto done;
  1580. }
  1581. err = brcmf_set_sharedkey(ndev, sme);
  1582. if (err) {
  1583. brcmf_err("brcmf_set_sharedkey failed (%d)\n", err);
  1584. goto done;
  1585. }
  1586. profile->ssid.SSID_len = min_t(u32, (u32)sizeof(profile->ssid.SSID),
  1587. (u32)sme->ssid_len);
  1588. memcpy(&profile->ssid.SSID, sme->ssid, profile->ssid.SSID_len);
  1589. if (profile->ssid.SSID_len < IEEE80211_MAX_SSID_LEN) {
  1590. profile->ssid.SSID[profile->ssid.SSID_len] = 0;
  1591. brcmf_dbg(CONN, "SSID \"%s\", len (%d)\n", profile->ssid.SSID,
  1592. profile->ssid.SSID_len);
  1593. }
  1594. /* Join with specific BSSID and cached SSID
  1595. * If SSID is zero join based on BSSID only
  1596. */
  1597. join_params_size = offsetof(struct brcmf_ext_join_params_le, assoc_le) +
  1598. offsetof(struct brcmf_assoc_params_le, chanspec_list);
  1599. if (cfg->channel)
  1600. join_params_size += sizeof(u16);
  1601. ext_join_params = kzalloc(join_params_size, GFP_KERNEL);
  1602. if (ext_join_params == NULL) {
  1603. err = -ENOMEM;
  1604. goto done;
  1605. }
  1606. ext_join_params->ssid_le.SSID_len = cpu_to_le32(profile->ssid.SSID_len);
  1607. memcpy(&ext_join_params->ssid_le.SSID, sme->ssid,
  1608. profile->ssid.SSID_len);
  1609. /* Set up join scan parameters */
  1610. ext_join_params->scan_le.scan_type = -1;
  1611. ext_join_params->scan_le.home_time = cpu_to_le32(-1);
  1612. if (sme->bssid)
  1613. memcpy(&ext_join_params->assoc_le.bssid, sme->bssid, ETH_ALEN);
  1614. else
  1615. memset(&ext_join_params->assoc_le.bssid, 0xFF, ETH_ALEN);
  1616. if (cfg->channel) {
  1617. ext_join_params->assoc_le.chanspec_num = cpu_to_le32(1);
  1618. ext_join_params->assoc_le.chanspec_list[0] =
  1619. cpu_to_le16(chanspec);
  1620. /* Increase dwell time to receive probe response or detect
  1621. * beacon from target AP at a noisy air only during connect
  1622. * command.
  1623. */
  1624. ext_join_params->scan_le.active_time =
  1625. cpu_to_le32(BRCMF_SCAN_JOIN_ACTIVE_DWELL_TIME_MS);
  1626. ext_join_params->scan_le.passive_time =
  1627. cpu_to_le32(BRCMF_SCAN_JOIN_PASSIVE_DWELL_TIME_MS);
  1628. /* To sync with presence period of VSDB GO send probe request
  1629. * more frequently. Probe request will be stopped when it gets
  1630. * probe response from target AP/GO.
  1631. */
  1632. ext_join_params->scan_le.nprobes =
  1633. cpu_to_le32(BRCMF_SCAN_JOIN_ACTIVE_DWELL_TIME_MS /
  1634. BRCMF_SCAN_JOIN_PROBE_INTERVAL_MS);
  1635. } else {
  1636. ext_join_params->scan_le.active_time = cpu_to_le32(-1);
  1637. ext_join_params->scan_le.passive_time = cpu_to_le32(-1);
  1638. ext_join_params->scan_le.nprobes = cpu_to_le32(-1);
  1639. }
  1640. err = brcmf_fil_bsscfg_data_set(ifp, "join", ext_join_params,
  1641. join_params_size);
  1642. kfree(ext_join_params);
  1643. if (!err)
  1644. /* This is it. join command worked, we are done */
  1645. goto done;
  1646. /* join command failed, fallback to set ssid */
  1647. memset(&join_params, 0, sizeof(join_params));
  1648. join_params_size = sizeof(join_params.ssid_le);
  1649. memcpy(&join_params.ssid_le.SSID, sme->ssid, profile->ssid.SSID_len);
  1650. join_params.ssid_le.SSID_len = cpu_to_le32(profile->ssid.SSID_len);
  1651. if (sme->bssid)
  1652. memcpy(join_params.params_le.bssid, sme->bssid, ETH_ALEN);
  1653. else
  1654. memset(join_params.params_le.bssid, 0xFF, ETH_ALEN);
  1655. if (cfg->channel) {
  1656. join_params.params_le.chanspec_list[0] = cpu_to_le16(chanspec);
  1657. join_params.params_le.chanspec_num = cpu_to_le32(1);
  1658. join_params_size += sizeof(join_params.params_le);
  1659. }
  1660. err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_SSID,
  1661. &join_params, join_params_size);
  1662. if (err)
  1663. brcmf_err("BRCMF_C_SET_SSID failed (%d)\n", err);
  1664. done:
  1665. if (err)
  1666. clear_bit(BRCMF_VIF_STATUS_CONNECTING, &ifp->vif->sme_state);
  1667. brcmf_dbg(TRACE, "Exit\n");
  1668. return err;
  1669. }
  1670. static s32
  1671. brcmf_cfg80211_disconnect(struct wiphy *wiphy, struct net_device *ndev,
  1672. u16 reason_code)
  1673. {
  1674. struct brcmf_if *ifp = netdev_priv(ndev);
  1675. struct brcmf_cfg80211_profile *profile = &ifp->vif->profile;
  1676. struct brcmf_scb_val_le scbval;
  1677. s32 err = 0;
  1678. brcmf_dbg(TRACE, "Enter. Reason code = %d\n", reason_code);
  1679. if (!check_vif_up(ifp->vif))
  1680. return -EIO;
  1681. clear_bit(BRCMF_VIF_STATUS_CONNECTED, &ifp->vif->sme_state);
  1682. clear_bit(BRCMF_VIF_STATUS_CONNECTING, &ifp->vif->sme_state);
  1683. cfg80211_disconnected(ndev, reason_code, NULL, 0, GFP_KERNEL);
  1684. memcpy(&scbval.ea, &profile->bssid, ETH_ALEN);
  1685. scbval.val = cpu_to_le32(reason_code);
  1686. err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_DISASSOC,
  1687. &scbval, sizeof(scbval));
  1688. if (err)
  1689. brcmf_err("error (%d)\n", err);
  1690. brcmf_dbg(TRACE, "Exit\n");
  1691. return err;
  1692. }
  1693. static s32
  1694. brcmf_cfg80211_set_tx_power(struct wiphy *wiphy, struct wireless_dev *wdev,
  1695. enum nl80211_tx_power_setting type, s32 mbm)
  1696. {
  1697. struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
  1698. struct net_device *ndev = cfg_to_ndev(cfg);
  1699. struct brcmf_if *ifp = netdev_priv(ndev);
  1700. u16 txpwrmw;
  1701. s32 err = 0;
  1702. s32 disable = 0;
  1703. s32 dbm = MBM_TO_DBM(mbm);
  1704. brcmf_dbg(TRACE, "Enter\n");
  1705. if (!check_vif_up(ifp->vif))
  1706. return -EIO;
  1707. switch (type) {
  1708. case NL80211_TX_POWER_AUTOMATIC:
  1709. break;
  1710. case NL80211_TX_POWER_LIMITED:
  1711. case NL80211_TX_POWER_FIXED:
  1712. if (dbm < 0) {
  1713. brcmf_err("TX_POWER_FIXED - dbm is negative\n");
  1714. err = -EINVAL;
  1715. goto done;
  1716. }
  1717. break;
  1718. }
  1719. /* Make sure radio is off or on as far as software is concerned */
  1720. disable = WL_RADIO_SW_DISABLE << 16;
  1721. err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_RADIO, disable);
  1722. if (err)
  1723. brcmf_err("WLC_SET_RADIO error (%d)\n", err);
  1724. if (dbm > 0xffff)
  1725. txpwrmw = 0xffff;
  1726. else
  1727. txpwrmw = (u16) dbm;
  1728. err = brcmf_fil_iovar_int_set(ifp, "qtxpower",
  1729. (s32)brcmf_mw_to_qdbm(txpwrmw));
  1730. if (err)
  1731. brcmf_err("qtxpower error (%d)\n", err);
  1732. cfg->conf->tx_power = dbm;
  1733. done:
  1734. brcmf_dbg(TRACE, "Exit\n");
  1735. return err;
  1736. }
  1737. static s32 brcmf_cfg80211_get_tx_power(struct wiphy *wiphy,
  1738. struct wireless_dev *wdev,
  1739. s32 *dbm)
  1740. {
  1741. struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
  1742. struct brcmf_if *ifp = netdev_priv(cfg_to_ndev(cfg));
  1743. s32 txpwrdbm;
  1744. u8 result;
  1745. s32 err = 0;
  1746. brcmf_dbg(TRACE, "Enter\n");
  1747. if (!check_vif_up(ifp->vif))
  1748. return -EIO;
  1749. err = brcmf_fil_iovar_int_get(ifp, "qtxpower", &txpwrdbm);
  1750. if (err) {
  1751. brcmf_err("error (%d)\n", err);
  1752. goto done;
  1753. }
  1754. result = (u8) (txpwrdbm & ~WL_TXPWR_OVERRIDE);
  1755. *dbm = (s32) brcmf_qdbm_to_mw(result);
  1756. done:
  1757. brcmf_dbg(TRACE, "Exit\n");
  1758. return err;
  1759. }
  1760. static s32
  1761. brcmf_cfg80211_config_default_key(struct wiphy *wiphy, struct net_device *ndev,
  1762. u8 key_idx, bool unicast, bool multicast)
  1763. {
  1764. struct brcmf_if *ifp = netdev_priv(ndev);
  1765. u32 index;
  1766. u32 wsec;
  1767. s32 err = 0;
  1768. brcmf_dbg(TRACE, "Enter\n");
  1769. brcmf_dbg(CONN, "key index (%d)\n", key_idx);
  1770. if (!check_vif_up(ifp->vif))
  1771. return -EIO;
  1772. err = brcmf_fil_bsscfg_int_get(ifp, "wsec", &wsec);
  1773. if (err) {
  1774. brcmf_err("WLC_GET_WSEC error (%d)\n", err);
  1775. goto done;
  1776. }
  1777. if (wsec & WEP_ENABLED) {
  1778. /* Just select a new current key */
  1779. index = key_idx;
  1780. err = brcmf_fil_cmd_int_set(ifp,
  1781. BRCMF_C_SET_KEY_PRIMARY, index);
  1782. if (err)
  1783. brcmf_err("error (%d)\n", err);
  1784. }
  1785. done:
  1786. brcmf_dbg(TRACE, "Exit\n");
  1787. return err;
  1788. }
  1789. static s32
  1790. brcmf_add_keyext(struct wiphy *wiphy, struct net_device *ndev,
  1791. u8 key_idx, const u8 *mac_addr, struct key_params *params)
  1792. {
  1793. struct brcmf_if *ifp = netdev_priv(ndev);
  1794. struct brcmf_wsec_key key;
  1795. s32 err = 0;
  1796. u8 keybuf[8];
  1797. memset(&key, 0, sizeof(key));
  1798. key.index = (u32) key_idx;
  1799. /* Instead of bcast for ea address for default wep keys,
  1800. driver needs it to be Null */
  1801. if (!is_multicast_ether_addr(mac_addr))
  1802. memcpy((char *)&key.ea, (void *)mac_addr, ETH_ALEN);
  1803. key.len = (u32) params->key_len;
  1804. /* check for key index change */
  1805. if (key.len == 0) {
  1806. /* key delete */
  1807. err = send_key_to_dongle(ifp, &key);
  1808. if (err)
  1809. brcmf_err("key delete error (%d)\n", err);
  1810. } else {
  1811. if (key.len > sizeof(key.data)) {
  1812. brcmf_err("Invalid key length (%d)\n", key.len);
  1813. return -EINVAL;
  1814. }
  1815. brcmf_dbg(CONN, "Setting the key index %d\n", key.index);
  1816. memcpy(key.data, params->key, key.len);
  1817. if (!brcmf_is_apmode(ifp->vif) &&
  1818. (params->cipher == WLAN_CIPHER_SUITE_TKIP)) {
  1819. brcmf_dbg(CONN, "Swapping RX/TX MIC key\n");
  1820. memcpy(keybuf, &key.data[24], sizeof(keybuf));
  1821. memcpy(&key.data[24], &key.data[16], sizeof(keybuf));
  1822. memcpy(&key.data[16], keybuf, sizeof(keybuf));
  1823. }
  1824. /* if IW_ENCODE_EXT_RX_SEQ_VALID set */
  1825. if (params->seq && params->seq_len == 6) {
  1826. /* rx iv */
  1827. u8 *ivptr;
  1828. ivptr = (u8 *) params->seq;
  1829. key.rxiv.hi = (ivptr[5] << 24) | (ivptr[4] << 16) |
  1830. (ivptr[3] << 8) | ivptr[2];
  1831. key.rxiv.lo = (ivptr[1] << 8) | ivptr[0];
  1832. key.iv_initialized = true;
  1833. }
  1834. switch (params->cipher) {
  1835. case WLAN_CIPHER_SUITE_WEP40:
  1836. key.algo = CRYPTO_ALGO_WEP1;
  1837. brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_WEP40\n");
  1838. break;
  1839. case WLAN_CIPHER_SUITE_WEP104:
  1840. key.algo = CRYPTO_ALGO_WEP128;
  1841. brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_WEP104\n");
  1842. break;
  1843. case WLAN_CIPHER_SUITE_TKIP:
  1844. key.algo = CRYPTO_ALGO_TKIP;
  1845. brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_TKIP\n");
  1846. break;
  1847. case WLAN_CIPHER_SUITE_AES_CMAC:
  1848. key.algo = CRYPTO_ALGO_AES_CCM;
  1849. brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_AES_CMAC\n");
  1850. break;
  1851. case WLAN_CIPHER_SUITE_CCMP:
  1852. key.algo = CRYPTO_ALGO_AES_CCM;
  1853. brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_CCMP\n");
  1854. break;
  1855. default:
  1856. brcmf_err("Invalid cipher (0x%x)\n", params->cipher);
  1857. return -EINVAL;
  1858. }
  1859. err = send_key_to_dongle(ifp, &key);
  1860. if (err)
  1861. brcmf_err("wsec_key error (%d)\n", err);
  1862. }
  1863. return err;
  1864. }
  1865. static s32
  1866. brcmf_cfg80211_add_key(struct wiphy *wiphy, struct net_device *ndev,
  1867. u8 key_idx, bool pairwise, const u8 *mac_addr,
  1868. struct key_params *params)
  1869. {
  1870. struct brcmf_if *ifp = netdev_priv(ndev);
  1871. struct brcmf_wsec_key *key;
  1872. s32 val;
  1873. s32 wsec;
  1874. s32 err = 0;
  1875. u8 keybuf[8];
  1876. brcmf_dbg(TRACE, "Enter\n");
  1877. brcmf_dbg(CONN, "key index (%d)\n", key_idx);
  1878. if (!check_vif_up(ifp->vif))
  1879. return -EIO;
  1880. if (key_idx >= BRCMF_MAX_DEFAULT_KEYS) {
  1881. /* we ignore this key index in this case */
  1882. brcmf_err("invalid key index (%d)\n", key_idx);
  1883. return -EINVAL;
  1884. }
  1885. if (mac_addr &&
  1886. (params->cipher != WLAN_CIPHER_SUITE_WEP40) &&
  1887. (params->cipher != WLAN_CIPHER_SUITE_WEP104)) {
  1888. brcmf_dbg(TRACE, "Exit");
  1889. return brcmf_add_keyext(wiphy, ndev, key_idx, mac_addr, params);
  1890. }
  1891. key = &ifp->vif->profile.key[key_idx];
  1892. memset(key, 0, sizeof(*key));
  1893. if (params->key_len > sizeof(key->data)) {
  1894. brcmf_err("Too long key length (%u)\n", params->key_len);
  1895. err = -EINVAL;
  1896. goto done;
  1897. }
  1898. key->len = params->key_len;
  1899. key->index = key_idx;
  1900. memcpy(key->data, params->key, key->len);
  1901. key->flags = BRCMF_PRIMARY_KEY;
  1902. switch (params->cipher) {
  1903. case WLAN_CIPHER_SUITE_WEP40:
  1904. key->algo = CRYPTO_ALGO_WEP1;
  1905. val = WEP_ENABLED;
  1906. brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_WEP40\n");
  1907. break;
  1908. case WLAN_CIPHER_SUITE_WEP104:
  1909. key->algo = CRYPTO_ALGO_WEP128;
  1910. val = WEP_ENABLED;
  1911. brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_WEP104\n");
  1912. break;
  1913. case WLAN_CIPHER_SUITE_TKIP:
  1914. if (!brcmf_is_apmode(ifp->vif)) {
  1915. brcmf_dbg(CONN, "Swapping RX/TX MIC key\n");
  1916. memcpy(keybuf, &key->data[24], sizeof(keybuf));
  1917. memcpy(&key->data[24], &key->data[16], sizeof(keybuf));
  1918. memcpy(&key->data[16], keybuf, sizeof(keybuf));
  1919. }
  1920. key->algo = CRYPTO_ALGO_TKIP;
  1921. val = TKIP_ENABLED;
  1922. brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_TKIP\n");
  1923. break;
  1924. case WLAN_CIPHER_SUITE_AES_CMAC:
  1925. key->algo = CRYPTO_ALGO_AES_CCM;
  1926. val = AES_ENABLED;
  1927. brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_AES_CMAC\n");
  1928. break;
  1929. case WLAN_CIPHER_SUITE_CCMP:
  1930. key->algo = CRYPTO_ALGO_AES_CCM;
  1931. val = AES_ENABLED;
  1932. brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_CCMP\n");
  1933. break;
  1934. default:
  1935. brcmf_err("Invalid cipher (0x%x)\n", params->cipher);
  1936. err = -EINVAL;
  1937. goto done;
  1938. }
  1939. err = send_key_to_dongle(ifp, key);
  1940. if (err)
  1941. goto done;
  1942. err = brcmf_fil_bsscfg_int_get(ifp, "wsec", &wsec);
  1943. if (err) {
  1944. brcmf_err("get wsec error (%d)\n", err);
  1945. goto done;
  1946. }
  1947. wsec |= val;
  1948. err = brcmf_fil_bsscfg_int_set(ifp, "wsec", wsec);
  1949. if (err) {
  1950. brcmf_err("set wsec error (%d)\n", err);
  1951. goto done;
  1952. }
  1953. done:
  1954. brcmf_dbg(TRACE, "Exit\n");
  1955. return err;
  1956. }
  1957. static s32
  1958. brcmf_cfg80211_del_key(struct wiphy *wiphy, struct net_device *ndev,
  1959. u8 key_idx, bool pairwise, const u8 *mac_addr)
  1960. {
  1961. struct brcmf_if *ifp = netdev_priv(ndev);
  1962. struct brcmf_wsec_key key;
  1963. s32 err = 0;
  1964. brcmf_dbg(TRACE, "Enter\n");
  1965. if (!check_vif_up(ifp->vif))
  1966. return -EIO;
  1967. if (key_idx >= BRCMF_MAX_DEFAULT_KEYS) {
  1968. /* we ignore this key index in this case */
  1969. brcmf_err("invalid key index (%d)\n", key_idx);
  1970. return -EINVAL;
  1971. }
  1972. memset(&key, 0, sizeof(key));
  1973. key.index = (u32) key_idx;
  1974. key.flags = BRCMF_PRIMARY_KEY;
  1975. key.algo = CRYPTO_ALGO_OFF;
  1976. brcmf_dbg(CONN, "key index (%d)\n", key_idx);
  1977. /* Set the new key/index */
  1978. err = send_key_to_dongle(ifp, &key);
  1979. brcmf_dbg(TRACE, "Exit\n");
  1980. return err;
  1981. }
  1982. static s32
  1983. brcmf_cfg80211_get_key(struct wiphy *wiphy, struct net_device *ndev,
  1984. u8 key_idx, bool pairwise, const u8 *mac_addr, void *cookie,
  1985. void (*callback) (void *cookie, struct key_params * params))
  1986. {
  1987. struct key_params params;
  1988. struct brcmf_if *ifp = netdev_priv(ndev);
  1989. struct brcmf_cfg80211_profile *profile = &ifp->vif->profile;
  1990. struct brcmf_cfg80211_security *sec;
  1991. s32 wsec;
  1992. s32 err = 0;
  1993. brcmf_dbg(TRACE, "Enter\n");
  1994. brcmf_dbg(CONN, "key index (%d)\n", key_idx);
  1995. if (!check_vif_up(ifp->vif))
  1996. return -EIO;
  1997. memset(&params, 0, sizeof(params));
  1998. err = brcmf_fil_bsscfg_int_get(ifp, "wsec", &wsec);
  1999. if (err) {
  2000. brcmf_err("WLC_GET_WSEC error (%d)\n", err);
  2001. /* Ignore this error, may happen during DISASSOC */
  2002. err = -EAGAIN;
  2003. goto done;
  2004. }
  2005. if (wsec & WEP_ENABLED) {
  2006. sec = &profile->sec;
  2007. if (sec->cipher_pairwise & WLAN_CIPHER_SUITE_WEP40) {
  2008. params.cipher = WLAN_CIPHER_SUITE_WEP40;
  2009. brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_WEP40\n");
  2010. } else if (sec->cipher_pairwise & WLAN_CIPHER_SUITE_WEP104) {
  2011. params.cipher = WLAN_CIPHER_SUITE_WEP104;
  2012. brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_WEP104\n");
  2013. }
  2014. } else if (wsec & TKIP_ENABLED) {
  2015. params.cipher = WLAN_CIPHER_SUITE_TKIP;
  2016. brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_TKIP\n");
  2017. } else if (wsec & AES_ENABLED) {
  2018. params.cipher = WLAN_CIPHER_SUITE_AES_CMAC;
  2019. brcmf_dbg(CONN, "WLAN_CIPHER_SUITE_AES_CMAC\n");
  2020. } else {
  2021. brcmf_err("Invalid algo (0x%x)\n", wsec);
  2022. err = -EINVAL;
  2023. goto done;
  2024. }
  2025. callback(cookie, &params);
  2026. done:
  2027. brcmf_dbg(TRACE, "Exit\n");
  2028. return err;
  2029. }
  2030. static s32
  2031. brcmf_cfg80211_config_default_mgmt_key(struct wiphy *wiphy,
  2032. struct net_device *ndev, u8 key_idx)
  2033. {
  2034. brcmf_dbg(INFO, "Not supported\n");
  2035. return -EOPNOTSUPP;
  2036. }
  2037. static void
  2038. brcmf_cfg80211_reconfigure_wep(struct brcmf_if *ifp)
  2039. {
  2040. s32 err;
  2041. u8 key_idx;
  2042. struct brcmf_wsec_key *key;
  2043. s32 wsec;
  2044. for (key_idx = 0; key_idx < BRCMF_MAX_DEFAULT_KEYS; key_idx++) {
  2045. key = &ifp->vif->profile.key[key_idx];
  2046. if ((key->algo == CRYPTO_ALGO_WEP1) ||
  2047. (key->algo == CRYPTO_ALGO_WEP128))
  2048. break;
  2049. }
  2050. if (key_idx == BRCMF_MAX_DEFAULT_KEYS)
  2051. return;
  2052. err = send_key_to_dongle(ifp, key);
  2053. if (err) {
  2054. brcmf_err("Setting WEP key failed (%d)\n", err);
  2055. return;
  2056. }
  2057. err = brcmf_fil_bsscfg_int_get(ifp, "wsec", &wsec);
  2058. if (err) {
  2059. brcmf_err("get wsec error (%d)\n", err);
  2060. return;
  2061. }
  2062. wsec |= WEP_ENABLED;
  2063. err = brcmf_fil_bsscfg_int_set(ifp, "wsec", wsec);
  2064. if (err)
  2065. brcmf_err("set wsec error (%d)\n", err);
  2066. }
  2067. static s32
  2068. brcmf_cfg80211_get_station(struct wiphy *wiphy, struct net_device *ndev,
  2069. const u8 *mac, struct station_info *sinfo)
  2070. {
  2071. struct brcmf_if *ifp = netdev_priv(ndev);
  2072. struct brcmf_cfg80211_profile *profile = &ifp->vif->profile;
  2073. struct brcmf_scb_val_le scb_val;
  2074. int rssi;
  2075. s32 rate;
  2076. s32 err = 0;
  2077. u8 *bssid = profile->bssid;
  2078. struct brcmf_sta_info_le sta_info_le;
  2079. u32 beacon_period;
  2080. u32 dtim_period;
  2081. brcmf_dbg(TRACE, "Enter, MAC %pM\n", mac);
  2082. if (!check_vif_up(ifp->vif))
  2083. return -EIO;
  2084. if (brcmf_is_apmode(ifp->vif)) {
  2085. memcpy(&sta_info_le, mac, ETH_ALEN);
  2086. err = brcmf_fil_iovar_data_get(ifp, "sta_info",
  2087. &sta_info_le,
  2088. sizeof(sta_info_le));
  2089. if (err < 0) {
  2090. brcmf_err("GET STA INFO failed, %d\n", err);
  2091. goto done;
  2092. }
  2093. sinfo->filled = BIT(NL80211_STA_INFO_INACTIVE_TIME);
  2094. sinfo->inactive_time = le32_to_cpu(sta_info_le.idle) * 1000;
  2095. if (le32_to_cpu(sta_info_le.flags) & BRCMF_STA_ASSOC) {
  2096. sinfo->filled |= BIT(NL80211_STA_INFO_CONNECTED_TIME);
  2097. sinfo->connected_time = le32_to_cpu(sta_info_le.in);
  2098. }
  2099. brcmf_dbg(TRACE, "STA idle time : %d ms, connected time :%d sec\n",
  2100. sinfo->inactive_time, sinfo->connected_time);
  2101. } else if (ifp->vif->wdev.iftype == NL80211_IFTYPE_STATION) {
  2102. if (memcmp(mac, bssid, ETH_ALEN)) {
  2103. brcmf_err("Wrong Mac address cfg_mac-%pM wl_bssid-%pM\n",
  2104. mac, bssid);
  2105. err = -ENOENT;
  2106. goto done;
  2107. }
  2108. /* Report the current tx rate */
  2109. err = brcmf_fil_cmd_int_get(ifp, BRCMF_C_GET_RATE, &rate);
  2110. if (err) {
  2111. brcmf_err("Could not get rate (%d)\n", err);
  2112. goto done;
  2113. } else {
  2114. sinfo->filled |= BIT(NL80211_STA_INFO_TX_BITRATE);
  2115. sinfo->txrate.legacy = rate * 5;
  2116. brcmf_dbg(CONN, "Rate %d Mbps\n", rate / 2);
  2117. }
  2118. if (test_bit(BRCMF_VIF_STATUS_CONNECTED,
  2119. &ifp->vif->sme_state)) {
  2120. memset(&scb_val, 0, sizeof(scb_val));
  2121. err = brcmf_fil_cmd_data_get(ifp, BRCMF_C_GET_RSSI,
  2122. &scb_val, sizeof(scb_val));
  2123. if (err) {
  2124. brcmf_err("Could not get rssi (%d)\n", err);
  2125. goto done;
  2126. } else {
  2127. rssi = le32_to_cpu(scb_val.val);
  2128. sinfo->filled |= BIT(NL80211_STA_INFO_SIGNAL);
  2129. sinfo->signal = rssi;
  2130. brcmf_dbg(CONN, "RSSI %d dBm\n", rssi);
  2131. }
  2132. err = brcmf_fil_cmd_int_get(ifp, BRCMF_C_GET_BCNPRD,
  2133. &beacon_period);
  2134. if (err) {
  2135. brcmf_err("Could not get beacon period (%d)\n",
  2136. err);
  2137. goto done;
  2138. } else {
  2139. sinfo->bss_param.beacon_interval =
  2140. beacon_period;
  2141. brcmf_dbg(CONN, "Beacon peroid %d\n",
  2142. beacon_period);
  2143. }
  2144. err = brcmf_fil_cmd_int_get(ifp, BRCMF_C_GET_DTIMPRD,
  2145. &dtim_period);
  2146. if (err) {
  2147. brcmf_err("Could not get DTIM period (%d)\n",
  2148. err);
  2149. goto done;
  2150. } else {
  2151. sinfo->bss_param.dtim_period = dtim_period;
  2152. brcmf_dbg(CONN, "DTIM peroid %d\n",
  2153. dtim_period);
  2154. }
  2155. sinfo->filled |= BIT(NL80211_STA_INFO_BSS_PARAM);
  2156. }
  2157. } else
  2158. err = -EPERM;
  2159. done:
  2160. brcmf_dbg(TRACE, "Exit\n");
  2161. return err;
  2162. }
  2163. static s32
  2164. brcmf_cfg80211_set_power_mgmt(struct wiphy *wiphy, struct net_device *ndev,
  2165. bool enabled, s32 timeout)
  2166. {
  2167. s32 pm;
  2168. s32 err = 0;
  2169. struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
  2170. struct brcmf_if *ifp = netdev_priv(ndev);
  2171. brcmf_dbg(TRACE, "Enter\n");
  2172. /*
  2173. * Powersave enable/disable request is coming from the
  2174. * cfg80211 even before the interface is up. In that
  2175. * scenario, driver will be storing the power save
  2176. * preference in cfg struct to apply this to
  2177. * FW later while initializing the dongle
  2178. */
  2179. cfg->pwr_save = enabled;
  2180. if (!check_vif_up(ifp->vif)) {
  2181. brcmf_dbg(INFO, "Device is not ready, storing the value in cfg_info struct\n");
  2182. goto done;
  2183. }
  2184. pm = enabled ? PM_FAST : PM_OFF;
  2185. /* Do not enable the power save after assoc if it is a p2p interface */
  2186. if (ifp->vif->wdev.iftype == NL80211_IFTYPE_P2P_CLIENT) {
  2187. brcmf_dbg(INFO, "Do not enable power save for P2P clients\n");
  2188. pm = PM_OFF;
  2189. }
  2190. brcmf_dbg(INFO, "power save %s\n", (pm ? "enabled" : "disabled"));
  2191. err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_PM, pm);
  2192. if (err) {
  2193. if (err == -ENODEV)
  2194. brcmf_err("net_device is not ready yet\n");
  2195. else
  2196. brcmf_err("error (%d)\n", err);
  2197. }
  2198. done:
  2199. brcmf_dbg(TRACE, "Exit\n");
  2200. return err;
  2201. }
  2202. static s32 brcmf_inform_single_bss(struct brcmf_cfg80211_info *cfg,
  2203. struct brcmf_bss_info_le *bi)
  2204. {
  2205. struct wiphy *wiphy = cfg_to_wiphy(cfg);
  2206. struct ieee80211_channel *notify_channel;
  2207. struct cfg80211_bss *bss;
  2208. struct ieee80211_supported_band *band;
  2209. struct brcmu_chan ch;
  2210. u16 channel;
  2211. u32 freq;
  2212. u16 notify_capability;
  2213. u16 notify_interval;
  2214. u8 *notify_ie;
  2215. size_t notify_ielen;
  2216. s32 notify_signal;
  2217. if (le32_to_cpu(bi->length) > WL_BSS_INFO_MAX) {
  2218. brcmf_err("Bss info is larger than buffer. Discarding\n");
  2219. return 0;
  2220. }
  2221. if (!bi->ctl_ch) {
  2222. ch.chspec = le16_to_cpu(bi->chanspec);
  2223. cfg->d11inf.decchspec(&ch);
  2224. bi->ctl_ch = ch.chnum;
  2225. }
  2226. channel = bi->ctl_ch;
  2227. if (channel <= CH_MAX_2G_CHANNEL)
  2228. band = wiphy->bands[IEEE80211_BAND_2GHZ];
  2229. else
  2230. band = wiphy->bands[IEEE80211_BAND_5GHZ];
  2231. freq = ieee80211_channel_to_frequency(channel, band->band);
  2232. notify_channel = ieee80211_get_channel(wiphy, freq);
  2233. notify_capability = le16_to_cpu(bi->capability);
  2234. notify_interval = le16_to_cpu(bi->beacon_period);
  2235. notify_ie = (u8 *)bi + le16_to_cpu(bi->ie_offset);
  2236. notify_ielen = le32_to_cpu(bi->ie_length);
  2237. notify_signal = (s16)le16_to_cpu(bi->RSSI) * 100;
  2238. brcmf_dbg(CONN, "bssid: %pM\n", bi->BSSID);
  2239. brcmf_dbg(CONN, "Channel: %d(%d)\n", channel, freq);
  2240. brcmf_dbg(CONN, "Capability: %X\n", notify_capability);
  2241. brcmf_dbg(CONN, "Beacon interval: %d\n", notify_interval);
  2242. brcmf_dbg(CONN, "Signal: %d\n", notify_signal);
  2243. bss = cfg80211_inform_bss(wiphy, notify_channel,
  2244. CFG80211_BSS_FTYPE_UNKNOWN,
  2245. (const u8 *)bi->BSSID,
  2246. 0, notify_capability,
  2247. notify_interval, notify_ie,
  2248. notify_ielen, notify_signal,
  2249. GFP_KERNEL);
  2250. if (!bss)
  2251. return -ENOMEM;
  2252. cfg80211_put_bss(wiphy, bss);
  2253. return 0;
  2254. }
  2255. static struct brcmf_bss_info_le *
  2256. next_bss_le(struct brcmf_scan_results *list, struct brcmf_bss_info_le *bss)
  2257. {
  2258. if (bss == NULL)
  2259. return list->bss_info_le;
  2260. return (struct brcmf_bss_info_le *)((unsigned long)bss +
  2261. le32_to_cpu(bss->length));
  2262. }
  2263. static s32 brcmf_inform_bss(struct brcmf_cfg80211_info *cfg)
  2264. {
  2265. struct brcmf_scan_results *bss_list;
  2266. struct brcmf_bss_info_le *bi = NULL; /* must be initialized */
  2267. s32 err = 0;
  2268. int i;
  2269. bss_list = (struct brcmf_scan_results *)cfg->escan_info.escan_buf;
  2270. if (bss_list->count != 0 &&
  2271. bss_list->version != BRCMF_BSS_INFO_VERSION) {
  2272. brcmf_err("Version %d != WL_BSS_INFO_VERSION\n",
  2273. bss_list->version);
  2274. return -EOPNOTSUPP;
  2275. }
  2276. brcmf_dbg(SCAN, "scanned AP count (%d)\n", bss_list->count);
  2277. for (i = 0; i < bss_list->count; i++) {
  2278. bi = next_bss_le(bss_list, bi);
  2279. err = brcmf_inform_single_bss(cfg, bi);
  2280. if (err)
  2281. break;
  2282. }
  2283. return err;
  2284. }
  2285. static s32 wl_inform_ibss(struct brcmf_cfg80211_info *cfg,
  2286. struct net_device *ndev, const u8 *bssid)
  2287. {
  2288. struct wiphy *wiphy = cfg_to_wiphy(cfg);
  2289. struct ieee80211_channel *notify_channel;
  2290. struct brcmf_bss_info_le *bi = NULL;
  2291. struct ieee80211_supported_band *band;
  2292. struct cfg80211_bss *bss;
  2293. struct brcmu_chan ch;
  2294. u8 *buf = NULL;
  2295. s32 err = 0;
  2296. u32 freq;
  2297. u16 notify_capability;
  2298. u16 notify_interval;
  2299. u8 *notify_ie;
  2300. size_t notify_ielen;
  2301. s32 notify_signal;
  2302. brcmf_dbg(TRACE, "Enter\n");
  2303. buf = kzalloc(WL_BSS_INFO_MAX, GFP_KERNEL);
  2304. if (buf == NULL) {
  2305. err = -ENOMEM;
  2306. goto CleanUp;
  2307. }
  2308. *(__le32 *)buf = cpu_to_le32(WL_BSS_INFO_MAX);
  2309. err = brcmf_fil_cmd_data_get(netdev_priv(ndev), BRCMF_C_GET_BSS_INFO,
  2310. buf, WL_BSS_INFO_MAX);
  2311. if (err) {
  2312. brcmf_err("WLC_GET_BSS_INFO failed: %d\n", err);
  2313. goto CleanUp;
  2314. }
  2315. bi = (struct brcmf_bss_info_le *)(buf + 4);
  2316. ch.chspec = le16_to_cpu(bi->chanspec);
  2317. cfg->d11inf.decchspec(&ch);
  2318. if (ch.band == BRCMU_CHAN_BAND_2G)
  2319. band = wiphy->bands[IEEE80211_BAND_2GHZ];
  2320. else
  2321. band = wiphy->bands[IEEE80211_BAND_5GHZ];
  2322. freq = ieee80211_channel_to_frequency(ch.chnum, band->band);
  2323. notify_channel = ieee80211_get_channel(wiphy, freq);
  2324. notify_capability = le16_to_cpu(bi->capability);
  2325. notify_interval = le16_to_cpu(bi->beacon_period);
  2326. notify_ie = (u8 *)bi + le16_to_cpu(bi->ie_offset);
  2327. notify_ielen = le32_to_cpu(bi->ie_length);
  2328. notify_signal = (s16)le16_to_cpu(bi->RSSI) * 100;
  2329. brcmf_dbg(CONN, "channel: %d(%d)\n", ch.chnum, freq);
  2330. brcmf_dbg(CONN, "capability: %X\n", notify_capability);
  2331. brcmf_dbg(CONN, "beacon interval: %d\n", notify_interval);
  2332. brcmf_dbg(CONN, "signal: %d\n", notify_signal);
  2333. bss = cfg80211_inform_bss(wiphy, notify_channel,
  2334. CFG80211_BSS_FTYPE_UNKNOWN, bssid, 0,
  2335. notify_capability, notify_interval,
  2336. notify_ie, notify_ielen, notify_signal,
  2337. GFP_KERNEL);
  2338. if (!bss) {
  2339. err = -ENOMEM;
  2340. goto CleanUp;
  2341. }
  2342. cfg80211_put_bss(wiphy, bss);
  2343. CleanUp:
  2344. kfree(buf);
  2345. brcmf_dbg(TRACE, "Exit\n");
  2346. return err;
  2347. }
  2348. static s32 brcmf_update_bss_info(struct brcmf_cfg80211_info *cfg,
  2349. struct brcmf_if *ifp)
  2350. {
  2351. struct brcmf_cfg80211_profile *profile = ndev_to_prof(ifp->ndev);
  2352. struct brcmf_bss_info_le *bi;
  2353. struct brcmf_ssid *ssid;
  2354. const struct brcmf_tlv *tim;
  2355. u16 beacon_interval;
  2356. u8 dtim_period;
  2357. size_t ie_len;
  2358. u8 *ie;
  2359. s32 err = 0;
  2360. brcmf_dbg(TRACE, "Enter\n");
  2361. if (brcmf_is_ibssmode(ifp->vif))
  2362. return err;
  2363. ssid = &profile->ssid;
  2364. *(__le32 *)cfg->extra_buf = cpu_to_le32(WL_EXTRA_BUF_MAX);
  2365. err = brcmf_fil_cmd_data_get(ifp, BRCMF_C_GET_BSS_INFO,
  2366. cfg->extra_buf, WL_EXTRA_BUF_MAX);
  2367. if (err) {
  2368. brcmf_err("Could not get bss info %d\n", err);
  2369. goto update_bss_info_out;
  2370. }
  2371. bi = (struct brcmf_bss_info_le *)(cfg->extra_buf + 4);
  2372. err = brcmf_inform_single_bss(cfg, bi);
  2373. if (err)
  2374. goto update_bss_info_out;
  2375. ie = ((u8 *)bi) + le16_to_cpu(bi->ie_offset);
  2376. ie_len = le32_to_cpu(bi->ie_length);
  2377. beacon_interval = le16_to_cpu(bi->beacon_period);
  2378. tim = brcmf_parse_tlvs(ie, ie_len, WLAN_EID_TIM);
  2379. if (tim)
  2380. dtim_period = tim->data[1];
  2381. else {
  2382. /*
  2383. * active scan was done so we could not get dtim
  2384. * information out of probe response.
  2385. * so we speficially query dtim information to dongle.
  2386. */
  2387. u32 var;
  2388. err = brcmf_fil_iovar_int_get(ifp, "dtim_assoc", &var);
  2389. if (err) {
  2390. brcmf_err("wl dtim_assoc failed (%d)\n", err);
  2391. goto update_bss_info_out;
  2392. }
  2393. dtim_period = (u8)var;
  2394. }
  2395. update_bss_info_out:
  2396. brcmf_dbg(TRACE, "Exit");
  2397. return err;
  2398. }
  2399. void brcmf_abort_scanning(struct brcmf_cfg80211_info *cfg)
  2400. {
  2401. struct escan_info *escan = &cfg->escan_info;
  2402. set_bit(BRCMF_SCAN_STATUS_ABORT, &cfg->scan_status);
  2403. if (cfg->scan_request) {
  2404. escan->escan_state = WL_ESCAN_STATE_IDLE;
  2405. brcmf_notify_escan_complete(cfg, escan->ifp, true, true);
  2406. }
  2407. clear_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status);
  2408. clear_bit(BRCMF_SCAN_STATUS_ABORT, &cfg->scan_status);
  2409. }
  2410. static void brcmf_cfg80211_escan_timeout_worker(struct work_struct *work)
  2411. {
  2412. struct brcmf_cfg80211_info *cfg =
  2413. container_of(work, struct brcmf_cfg80211_info,
  2414. escan_timeout_work);
  2415. brcmf_inform_bss(cfg);
  2416. brcmf_notify_escan_complete(cfg, cfg->escan_info.ifp, true, true);
  2417. }
  2418. static void brcmf_escan_timeout(unsigned long data)
  2419. {
  2420. struct brcmf_cfg80211_info *cfg =
  2421. (struct brcmf_cfg80211_info *)data;
  2422. if (cfg->scan_request) {
  2423. brcmf_err("timer expired\n");
  2424. schedule_work(&cfg->escan_timeout_work);
  2425. }
  2426. }
  2427. static s32
  2428. brcmf_compare_update_same_bss(struct brcmf_cfg80211_info *cfg,
  2429. struct brcmf_bss_info_le *bss,
  2430. struct brcmf_bss_info_le *bss_info_le)
  2431. {
  2432. struct brcmu_chan ch_bss, ch_bss_info_le;
  2433. ch_bss.chspec = le16_to_cpu(bss->chanspec);
  2434. cfg->d11inf.decchspec(&ch_bss);
  2435. ch_bss_info_le.chspec = le16_to_cpu(bss_info_le->chanspec);
  2436. cfg->d11inf.decchspec(&ch_bss_info_le);
  2437. if (!memcmp(&bss_info_le->BSSID, &bss->BSSID, ETH_ALEN) &&
  2438. ch_bss.band == ch_bss_info_le.band &&
  2439. bss_info_le->SSID_len == bss->SSID_len &&
  2440. !memcmp(bss_info_le->SSID, bss->SSID, bss_info_le->SSID_len)) {
  2441. if ((bss->flags & BRCMF_BSS_RSSI_ON_CHANNEL) ==
  2442. (bss_info_le->flags & BRCMF_BSS_RSSI_ON_CHANNEL)) {
  2443. s16 bss_rssi = le16_to_cpu(bss->RSSI);
  2444. s16 bss_info_rssi = le16_to_cpu(bss_info_le->RSSI);
  2445. /* preserve max RSSI if the measurements are
  2446. * both on-channel or both off-channel
  2447. */
  2448. if (bss_info_rssi > bss_rssi)
  2449. bss->RSSI = bss_info_le->RSSI;
  2450. } else if ((bss->flags & BRCMF_BSS_RSSI_ON_CHANNEL) &&
  2451. (bss_info_le->flags & BRCMF_BSS_RSSI_ON_CHANNEL) == 0) {
  2452. /* preserve the on-channel rssi measurement
  2453. * if the new measurement is off channel
  2454. */
  2455. bss->RSSI = bss_info_le->RSSI;
  2456. bss->flags |= BRCMF_BSS_RSSI_ON_CHANNEL;
  2457. }
  2458. return 1;
  2459. }
  2460. return 0;
  2461. }
  2462. static s32
  2463. brcmf_cfg80211_escan_handler(struct brcmf_if *ifp,
  2464. const struct brcmf_event_msg *e, void *data)
  2465. {
  2466. struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
  2467. s32 status;
  2468. struct brcmf_escan_result_le *escan_result_le;
  2469. struct brcmf_bss_info_le *bss_info_le;
  2470. struct brcmf_bss_info_le *bss = NULL;
  2471. u32 bi_length;
  2472. struct brcmf_scan_results *list;
  2473. u32 i;
  2474. bool aborted;
  2475. status = e->status;
  2476. if (!test_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status)) {
  2477. brcmf_err("scan not ready, bssidx=%d\n", ifp->bssidx);
  2478. return -EPERM;
  2479. }
  2480. if (status == BRCMF_E_STATUS_PARTIAL) {
  2481. brcmf_dbg(SCAN, "ESCAN Partial result\n");
  2482. escan_result_le = (struct brcmf_escan_result_le *) data;
  2483. if (!escan_result_le) {
  2484. brcmf_err("Invalid escan result (NULL pointer)\n");
  2485. goto exit;
  2486. }
  2487. if (le16_to_cpu(escan_result_le->bss_count) != 1) {
  2488. brcmf_err("Invalid bss_count %d: ignoring\n",
  2489. escan_result_le->bss_count);
  2490. goto exit;
  2491. }
  2492. bss_info_le = &escan_result_le->bss_info_le;
  2493. if (brcmf_p2p_scan_finding_common_channel(cfg, bss_info_le))
  2494. goto exit;
  2495. if (!cfg->scan_request) {
  2496. brcmf_dbg(SCAN, "result without cfg80211 request\n");
  2497. goto exit;
  2498. }
  2499. bi_length = le32_to_cpu(bss_info_le->length);
  2500. if (bi_length != (le32_to_cpu(escan_result_le->buflen) -
  2501. WL_ESCAN_RESULTS_FIXED_SIZE)) {
  2502. brcmf_err("Invalid bss_info length %d: ignoring\n",
  2503. bi_length);
  2504. goto exit;
  2505. }
  2506. if (!(cfg_to_wiphy(cfg)->interface_modes &
  2507. BIT(NL80211_IFTYPE_ADHOC))) {
  2508. if (le16_to_cpu(bss_info_le->capability) &
  2509. WLAN_CAPABILITY_IBSS) {
  2510. brcmf_err("Ignoring IBSS result\n");
  2511. goto exit;
  2512. }
  2513. }
  2514. list = (struct brcmf_scan_results *)
  2515. cfg->escan_info.escan_buf;
  2516. if (bi_length > WL_ESCAN_BUF_SIZE - list->buflen) {
  2517. brcmf_err("Buffer is too small: ignoring\n");
  2518. goto exit;
  2519. }
  2520. for (i = 0; i < list->count; i++) {
  2521. bss = bss ? (struct brcmf_bss_info_le *)
  2522. ((unsigned char *)bss +
  2523. le32_to_cpu(bss->length)) : list->bss_info_le;
  2524. if (brcmf_compare_update_same_bss(cfg, bss,
  2525. bss_info_le))
  2526. goto exit;
  2527. }
  2528. memcpy(&(cfg->escan_info.escan_buf[list->buflen]),
  2529. bss_info_le, bi_length);
  2530. list->version = le32_to_cpu(bss_info_le->version);
  2531. list->buflen += bi_length;
  2532. list->count++;
  2533. } else {
  2534. cfg->escan_info.escan_state = WL_ESCAN_STATE_IDLE;
  2535. if (brcmf_p2p_scan_finding_common_channel(cfg, NULL))
  2536. goto exit;
  2537. if (cfg->scan_request) {
  2538. brcmf_inform_bss(cfg);
  2539. aborted = status != BRCMF_E_STATUS_SUCCESS;
  2540. brcmf_notify_escan_complete(cfg, ifp, aborted, false);
  2541. } else
  2542. brcmf_dbg(SCAN, "Ignored scan complete result 0x%x\n",
  2543. status);
  2544. }
  2545. exit:
  2546. return 0;
  2547. }
  2548. static void brcmf_init_escan(struct brcmf_cfg80211_info *cfg)
  2549. {
  2550. brcmf_fweh_register(cfg->pub, BRCMF_E_ESCAN_RESULT,
  2551. brcmf_cfg80211_escan_handler);
  2552. cfg->escan_info.escan_state = WL_ESCAN_STATE_IDLE;
  2553. /* Init scan_timeout timer */
  2554. init_timer(&cfg->escan_timeout);
  2555. cfg->escan_timeout.data = (unsigned long) cfg;
  2556. cfg->escan_timeout.function = brcmf_escan_timeout;
  2557. INIT_WORK(&cfg->escan_timeout_work,
  2558. brcmf_cfg80211_escan_timeout_worker);
  2559. }
  2560. static __always_inline void brcmf_delay(u32 ms)
  2561. {
  2562. if (ms < 1000 / HZ) {
  2563. cond_resched();
  2564. mdelay(ms);
  2565. } else {
  2566. msleep(ms);
  2567. }
  2568. }
  2569. static s32 brcmf_config_wowl_pattern(struct brcmf_if *ifp, u8 cmd[4],
  2570. u8 *pattern, u32 patternsize, u8 *mask,
  2571. u32 packet_offset)
  2572. {
  2573. struct brcmf_fil_wowl_pattern_le *filter;
  2574. u32 masksize;
  2575. u32 patternoffset;
  2576. u8 *buf;
  2577. u32 bufsize;
  2578. s32 ret;
  2579. masksize = (patternsize + 7) / 8;
  2580. patternoffset = sizeof(*filter) - sizeof(filter->cmd) + masksize;
  2581. bufsize = sizeof(*filter) + patternsize + masksize;
  2582. buf = kzalloc(bufsize, GFP_KERNEL);
  2583. if (!buf)
  2584. return -ENOMEM;
  2585. filter = (struct brcmf_fil_wowl_pattern_le *)buf;
  2586. memcpy(filter->cmd, cmd, 4);
  2587. filter->masksize = cpu_to_le32(masksize);
  2588. filter->offset = cpu_to_le32(packet_offset);
  2589. filter->patternoffset = cpu_to_le32(patternoffset);
  2590. filter->patternsize = cpu_to_le32(patternsize);
  2591. filter->type = cpu_to_le32(BRCMF_WOWL_PATTERN_TYPE_BITMAP);
  2592. if ((mask) && (masksize))
  2593. memcpy(buf + sizeof(*filter), mask, masksize);
  2594. if ((pattern) && (patternsize))
  2595. memcpy(buf + sizeof(*filter) + masksize, pattern, patternsize);
  2596. ret = brcmf_fil_iovar_data_set(ifp, "wowl_pattern", buf, bufsize);
  2597. kfree(buf);
  2598. return ret;
  2599. }
  2600. static s32 brcmf_cfg80211_resume(struct wiphy *wiphy)
  2601. {
  2602. struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
  2603. struct net_device *ndev = cfg_to_ndev(cfg);
  2604. struct brcmf_if *ifp = netdev_priv(ndev);
  2605. brcmf_dbg(TRACE, "Enter\n");
  2606. if (cfg->wowl_enabled) {
  2607. brcmf_configure_arp_offload(ifp, true);
  2608. brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_PM,
  2609. cfg->pre_wowl_pmmode);
  2610. brcmf_fil_iovar_int_set(ifp, "wowl_clear", 0);
  2611. brcmf_config_wowl_pattern(ifp, "clr", NULL, 0, NULL, 0);
  2612. cfg->wowl_enabled = false;
  2613. }
  2614. return 0;
  2615. }
  2616. static void brcmf_configure_wowl(struct brcmf_cfg80211_info *cfg,
  2617. struct brcmf_if *ifp,
  2618. struct cfg80211_wowlan *wowl)
  2619. {
  2620. u32 wowl_config;
  2621. u32 i;
  2622. brcmf_dbg(TRACE, "Suspend, wowl config.\n");
  2623. brcmf_configure_arp_offload(ifp, false);
  2624. brcmf_fil_cmd_int_get(ifp, BRCMF_C_GET_PM, &cfg->pre_wowl_pmmode);
  2625. brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_PM, PM_MAX);
  2626. wowl_config = 0;
  2627. if (wowl->disconnect)
  2628. wowl_config = BRCMF_WOWL_DIS | BRCMF_WOWL_BCN | BRCMF_WOWL_RETR;
  2629. if (wowl->magic_pkt)
  2630. wowl_config |= BRCMF_WOWL_MAGIC;
  2631. if ((wowl->patterns) && (wowl->n_patterns)) {
  2632. wowl_config |= BRCMF_WOWL_NET;
  2633. for (i = 0; i < wowl->n_patterns; i++) {
  2634. brcmf_config_wowl_pattern(ifp, "add",
  2635. (u8 *)wowl->patterns[i].pattern,
  2636. wowl->patterns[i].pattern_len,
  2637. (u8 *)wowl->patterns[i].mask,
  2638. wowl->patterns[i].pkt_offset);
  2639. }
  2640. }
  2641. brcmf_fil_iovar_int_set(ifp, "wowl", wowl_config);
  2642. brcmf_fil_iovar_int_set(ifp, "wowl_activate", 1);
  2643. brcmf_bus_wowl_config(cfg->pub->bus_if, true);
  2644. cfg->wowl_enabled = true;
  2645. }
  2646. static s32 brcmf_cfg80211_suspend(struct wiphy *wiphy,
  2647. struct cfg80211_wowlan *wowl)
  2648. {
  2649. struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
  2650. struct net_device *ndev = cfg_to_ndev(cfg);
  2651. struct brcmf_if *ifp = netdev_priv(ndev);
  2652. struct brcmf_cfg80211_vif *vif;
  2653. brcmf_dbg(TRACE, "Enter\n");
  2654. /* if the primary net_device is not READY there is nothing
  2655. * we can do but pray resume goes smoothly.
  2656. */
  2657. if (!check_vif_up(ifp->vif))
  2658. goto exit;
  2659. /* end any scanning */
  2660. if (test_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status))
  2661. brcmf_abort_scanning(cfg);
  2662. if (wowl == NULL) {
  2663. brcmf_bus_wowl_config(cfg->pub->bus_if, false);
  2664. list_for_each_entry(vif, &cfg->vif_list, list) {
  2665. if (!test_bit(BRCMF_VIF_STATUS_READY, &vif->sme_state))
  2666. continue;
  2667. /* While going to suspend if associated with AP
  2668. * disassociate from AP to save power while system is
  2669. * in suspended state
  2670. */
  2671. brcmf_link_down(vif, WLAN_REASON_UNSPECIFIED);
  2672. /* Make sure WPA_Supplicant receives all the event
  2673. * generated due to DISASSOC call to the fw to keep
  2674. * the state fw and WPA_Supplicant state consistent
  2675. */
  2676. brcmf_delay(500);
  2677. }
  2678. /* Configure MPC */
  2679. brcmf_set_mpc(ifp, 1);
  2680. } else {
  2681. /* Configure WOWL paramaters */
  2682. brcmf_configure_wowl(cfg, ifp, wowl);
  2683. }
  2684. exit:
  2685. brcmf_dbg(TRACE, "Exit\n");
  2686. /* clear any scanning activity */
  2687. cfg->scan_status = 0;
  2688. return 0;
  2689. }
  2690. static __used s32
  2691. brcmf_update_pmklist(struct net_device *ndev,
  2692. struct brcmf_cfg80211_pmk_list *pmk_list, s32 err)
  2693. {
  2694. int i, j;
  2695. u32 pmkid_len;
  2696. pmkid_len = le32_to_cpu(pmk_list->pmkids.npmkid);
  2697. brcmf_dbg(CONN, "No of elements %d\n", pmkid_len);
  2698. for (i = 0; i < pmkid_len; i++) {
  2699. brcmf_dbg(CONN, "PMKID[%d]: %pM =\n", i,
  2700. &pmk_list->pmkids.pmkid[i].BSSID);
  2701. for (j = 0; j < WLAN_PMKID_LEN; j++)
  2702. brcmf_dbg(CONN, "%02x\n",
  2703. pmk_list->pmkids.pmkid[i].PMKID[j]);
  2704. }
  2705. if (!err)
  2706. brcmf_fil_iovar_data_set(netdev_priv(ndev), "pmkid_info",
  2707. (char *)pmk_list, sizeof(*pmk_list));
  2708. return err;
  2709. }
  2710. static s32
  2711. brcmf_cfg80211_set_pmksa(struct wiphy *wiphy, struct net_device *ndev,
  2712. struct cfg80211_pmksa *pmksa)
  2713. {
  2714. struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
  2715. struct brcmf_if *ifp = netdev_priv(ndev);
  2716. struct pmkid_list *pmkids = &cfg->pmk_list->pmkids;
  2717. s32 err = 0;
  2718. u32 pmkid_len, i;
  2719. brcmf_dbg(TRACE, "Enter\n");
  2720. if (!check_vif_up(ifp->vif))
  2721. return -EIO;
  2722. pmkid_len = le32_to_cpu(pmkids->npmkid);
  2723. for (i = 0; i < pmkid_len; i++)
  2724. if (!memcmp(pmksa->bssid, pmkids->pmkid[i].BSSID, ETH_ALEN))
  2725. break;
  2726. if (i < WL_NUM_PMKIDS_MAX) {
  2727. memcpy(pmkids->pmkid[i].BSSID, pmksa->bssid, ETH_ALEN);
  2728. memcpy(pmkids->pmkid[i].PMKID, pmksa->pmkid, WLAN_PMKID_LEN);
  2729. if (i == pmkid_len) {
  2730. pmkid_len++;
  2731. pmkids->npmkid = cpu_to_le32(pmkid_len);
  2732. }
  2733. } else
  2734. err = -EINVAL;
  2735. brcmf_dbg(CONN, "set_pmksa,IW_PMKSA_ADD - PMKID: %pM =\n",
  2736. pmkids->pmkid[pmkid_len].BSSID);
  2737. for (i = 0; i < WLAN_PMKID_LEN; i++)
  2738. brcmf_dbg(CONN, "%02x\n", pmkids->pmkid[pmkid_len].PMKID[i]);
  2739. err = brcmf_update_pmklist(ndev, cfg->pmk_list, err);
  2740. brcmf_dbg(TRACE, "Exit\n");
  2741. return err;
  2742. }
  2743. static s32
  2744. brcmf_cfg80211_del_pmksa(struct wiphy *wiphy, struct net_device *ndev,
  2745. struct cfg80211_pmksa *pmksa)
  2746. {
  2747. struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
  2748. struct brcmf_if *ifp = netdev_priv(ndev);
  2749. struct pmkid_list pmkid;
  2750. s32 err = 0;
  2751. u32 pmkid_len, i;
  2752. brcmf_dbg(TRACE, "Enter\n");
  2753. if (!check_vif_up(ifp->vif))
  2754. return -EIO;
  2755. memcpy(&pmkid.pmkid[0].BSSID, pmksa->bssid, ETH_ALEN);
  2756. memcpy(&pmkid.pmkid[0].PMKID, pmksa->pmkid, WLAN_PMKID_LEN);
  2757. brcmf_dbg(CONN, "del_pmksa,IW_PMKSA_REMOVE - PMKID: %pM =\n",
  2758. &pmkid.pmkid[0].BSSID);
  2759. for (i = 0; i < WLAN_PMKID_LEN; i++)
  2760. brcmf_dbg(CONN, "%02x\n", pmkid.pmkid[0].PMKID[i]);
  2761. pmkid_len = le32_to_cpu(cfg->pmk_list->pmkids.npmkid);
  2762. for (i = 0; i < pmkid_len; i++)
  2763. if (!memcmp
  2764. (pmksa->bssid, &cfg->pmk_list->pmkids.pmkid[i].BSSID,
  2765. ETH_ALEN))
  2766. break;
  2767. if ((pmkid_len > 0)
  2768. && (i < pmkid_len)) {
  2769. memset(&cfg->pmk_list->pmkids.pmkid[i], 0,
  2770. sizeof(struct pmkid));
  2771. for (; i < (pmkid_len - 1); i++) {
  2772. memcpy(&cfg->pmk_list->pmkids.pmkid[i].BSSID,
  2773. &cfg->pmk_list->pmkids.pmkid[i + 1].BSSID,
  2774. ETH_ALEN);
  2775. memcpy(&cfg->pmk_list->pmkids.pmkid[i].PMKID,
  2776. &cfg->pmk_list->pmkids.pmkid[i + 1].PMKID,
  2777. WLAN_PMKID_LEN);
  2778. }
  2779. cfg->pmk_list->pmkids.npmkid = cpu_to_le32(pmkid_len - 1);
  2780. } else
  2781. err = -EINVAL;
  2782. err = brcmf_update_pmklist(ndev, cfg->pmk_list, err);
  2783. brcmf_dbg(TRACE, "Exit\n");
  2784. return err;
  2785. }
  2786. static s32
  2787. brcmf_cfg80211_flush_pmksa(struct wiphy *wiphy, struct net_device *ndev)
  2788. {
  2789. struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
  2790. struct brcmf_if *ifp = netdev_priv(ndev);
  2791. s32 err = 0;
  2792. brcmf_dbg(TRACE, "Enter\n");
  2793. if (!check_vif_up(ifp->vif))
  2794. return -EIO;
  2795. memset(cfg->pmk_list, 0, sizeof(*cfg->pmk_list));
  2796. err = brcmf_update_pmklist(ndev, cfg->pmk_list, err);
  2797. brcmf_dbg(TRACE, "Exit\n");
  2798. return err;
  2799. }
  2800. /*
  2801. * PFN result doesn't have all the info which are
  2802. * required by the supplicant
  2803. * (For e.g IEs) Do a target Escan so that sched scan results are reported
  2804. * via wl_inform_single_bss in the required format. Escan does require the
  2805. * scan request in the form of cfg80211_scan_request. For timebeing, create
  2806. * cfg80211_scan_request one out of the received PNO event.
  2807. */
  2808. static s32
  2809. brcmf_notify_sched_scan_results(struct brcmf_if *ifp,
  2810. const struct brcmf_event_msg *e, void *data)
  2811. {
  2812. struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
  2813. struct brcmf_pno_net_info_le *netinfo, *netinfo_start;
  2814. struct cfg80211_scan_request *request = NULL;
  2815. struct cfg80211_ssid *ssid = NULL;
  2816. struct ieee80211_channel *channel = NULL;
  2817. struct wiphy *wiphy = cfg_to_wiphy(cfg);
  2818. int err = 0;
  2819. int channel_req = 0;
  2820. int band = 0;
  2821. struct brcmf_pno_scanresults_le *pfn_result;
  2822. u32 result_count;
  2823. u32 status;
  2824. brcmf_dbg(SCAN, "Enter\n");
  2825. if (e->event_code == BRCMF_E_PFN_NET_LOST) {
  2826. brcmf_dbg(SCAN, "PFN NET LOST event. Do Nothing\n");
  2827. return 0;
  2828. }
  2829. pfn_result = (struct brcmf_pno_scanresults_le *)data;
  2830. result_count = le32_to_cpu(pfn_result->count);
  2831. status = le32_to_cpu(pfn_result->status);
  2832. /*
  2833. * PFN event is limited to fit 512 bytes so we may get
  2834. * multiple NET_FOUND events. For now place a warning here.
  2835. */
  2836. WARN_ON(status != BRCMF_PNO_SCAN_COMPLETE);
  2837. brcmf_dbg(SCAN, "PFN NET FOUND event. count: %d\n", result_count);
  2838. if (result_count > 0) {
  2839. int i;
  2840. request = kzalloc(sizeof(*request), GFP_KERNEL);
  2841. ssid = kcalloc(result_count, sizeof(*ssid), GFP_KERNEL);
  2842. channel = kcalloc(result_count, sizeof(*channel), GFP_KERNEL);
  2843. if (!request || !ssid || !channel) {
  2844. err = -ENOMEM;
  2845. goto out_err;
  2846. }
  2847. request->wiphy = wiphy;
  2848. data += sizeof(struct brcmf_pno_scanresults_le);
  2849. netinfo_start = (struct brcmf_pno_net_info_le *)data;
  2850. for (i = 0; i < result_count; i++) {
  2851. netinfo = &netinfo_start[i];
  2852. if (!netinfo) {
  2853. brcmf_err("Invalid netinfo ptr. index: %d\n",
  2854. i);
  2855. err = -EINVAL;
  2856. goto out_err;
  2857. }
  2858. brcmf_dbg(SCAN, "SSID:%s Channel:%d\n",
  2859. netinfo->SSID, netinfo->channel);
  2860. memcpy(ssid[i].ssid, netinfo->SSID, netinfo->SSID_len);
  2861. ssid[i].ssid_len = netinfo->SSID_len;
  2862. request->n_ssids++;
  2863. channel_req = netinfo->channel;
  2864. if (channel_req <= CH_MAX_2G_CHANNEL)
  2865. band = NL80211_BAND_2GHZ;
  2866. else
  2867. band = NL80211_BAND_5GHZ;
  2868. channel[i].center_freq =
  2869. ieee80211_channel_to_frequency(channel_req,
  2870. band);
  2871. channel[i].band = band;
  2872. channel[i].flags |= IEEE80211_CHAN_NO_HT40;
  2873. request->channels[i] = &channel[i];
  2874. request->n_channels++;
  2875. }
  2876. /* assign parsed ssid array */
  2877. if (request->n_ssids)
  2878. request->ssids = &ssid[0];
  2879. if (test_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status)) {
  2880. /* Abort any on-going scan */
  2881. brcmf_abort_scanning(cfg);
  2882. }
  2883. set_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status);
  2884. cfg->escan_info.run = brcmf_run_escan;
  2885. err = brcmf_do_escan(cfg, wiphy, ifp, request);
  2886. if (err) {
  2887. clear_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status);
  2888. goto out_err;
  2889. }
  2890. cfg->sched_escan = true;
  2891. cfg->scan_request = request;
  2892. } else {
  2893. brcmf_err("FALSE PNO Event. (pfn_count == 0)\n");
  2894. goto out_err;
  2895. }
  2896. kfree(ssid);
  2897. kfree(channel);
  2898. kfree(request);
  2899. return 0;
  2900. out_err:
  2901. kfree(ssid);
  2902. kfree(channel);
  2903. kfree(request);
  2904. cfg80211_sched_scan_stopped(wiphy);
  2905. return err;
  2906. }
  2907. static int brcmf_dev_pno_clean(struct net_device *ndev)
  2908. {
  2909. int ret;
  2910. /* Disable pfn */
  2911. ret = brcmf_fil_iovar_int_set(netdev_priv(ndev), "pfn", 0);
  2912. if (ret == 0) {
  2913. /* clear pfn */
  2914. ret = brcmf_fil_iovar_data_set(netdev_priv(ndev), "pfnclear",
  2915. NULL, 0);
  2916. }
  2917. if (ret < 0)
  2918. brcmf_err("failed code %d\n", ret);
  2919. return ret;
  2920. }
  2921. static int brcmf_dev_pno_config(struct net_device *ndev)
  2922. {
  2923. struct brcmf_pno_param_le pfn_param;
  2924. memset(&pfn_param, 0, sizeof(pfn_param));
  2925. pfn_param.version = cpu_to_le32(BRCMF_PNO_VERSION);
  2926. /* set extra pno params */
  2927. pfn_param.flags = cpu_to_le16(1 << BRCMF_PNO_ENABLE_ADAPTSCAN_BIT);
  2928. pfn_param.repeat = BRCMF_PNO_REPEAT;
  2929. pfn_param.exp = BRCMF_PNO_FREQ_EXPO_MAX;
  2930. /* set up pno scan fr */
  2931. pfn_param.scan_freq = cpu_to_le32(BRCMF_PNO_TIME);
  2932. return brcmf_fil_iovar_data_set(netdev_priv(ndev), "pfn_set",
  2933. &pfn_param, sizeof(pfn_param));
  2934. }
  2935. static int
  2936. brcmf_cfg80211_sched_scan_start(struct wiphy *wiphy,
  2937. struct net_device *ndev,
  2938. struct cfg80211_sched_scan_request *request)
  2939. {
  2940. struct brcmf_if *ifp = netdev_priv(ndev);
  2941. struct brcmf_cfg80211_info *cfg = wiphy_priv(wiphy);
  2942. struct brcmf_pno_net_param_le pfn;
  2943. int i;
  2944. int ret = 0;
  2945. brcmf_dbg(SCAN, "Enter n_match_sets:%d n_ssids:%d\n",
  2946. request->n_match_sets, request->n_ssids);
  2947. if (test_bit(BRCMF_SCAN_STATUS_BUSY, &cfg->scan_status)) {
  2948. brcmf_err("Scanning already: status (%lu)\n", cfg->scan_status);
  2949. return -EAGAIN;
  2950. }
  2951. if (test_bit(BRCMF_SCAN_STATUS_SUPPRESS, &cfg->scan_status)) {
  2952. brcmf_err("Scanning suppressed: status (%lu)\n",
  2953. cfg->scan_status);
  2954. return -EAGAIN;
  2955. }
  2956. if (!request->n_ssids || !request->n_match_sets) {
  2957. brcmf_dbg(SCAN, "Invalid sched scan req!! n_ssids:%d\n",
  2958. request->n_ssids);
  2959. return -EINVAL;
  2960. }
  2961. if (request->n_ssids > 0) {
  2962. for (i = 0; i < request->n_ssids; i++) {
  2963. /* Active scan req for ssids */
  2964. brcmf_dbg(SCAN, ">>> Active scan req for ssid (%s)\n",
  2965. request->ssids[i].ssid);
  2966. /*
  2967. * match_set ssids is a supert set of n_ssid list,
  2968. * so we need not add these set seperately.
  2969. */
  2970. }
  2971. }
  2972. if (request->n_match_sets > 0) {
  2973. /* clean up everything */
  2974. ret = brcmf_dev_pno_clean(ndev);
  2975. if (ret < 0) {
  2976. brcmf_err("failed error=%d\n", ret);
  2977. return ret;
  2978. }
  2979. /* configure pno */
  2980. ret = brcmf_dev_pno_config(ndev);
  2981. if (ret < 0) {
  2982. brcmf_err("PNO setup failed!! ret=%d\n", ret);
  2983. return -EINVAL;
  2984. }
  2985. /* configure each match set */
  2986. for (i = 0; i < request->n_match_sets; i++) {
  2987. struct cfg80211_ssid *ssid;
  2988. u32 ssid_len;
  2989. ssid = &request->match_sets[i].ssid;
  2990. ssid_len = ssid->ssid_len;
  2991. if (!ssid_len) {
  2992. brcmf_err("skip broadcast ssid\n");
  2993. continue;
  2994. }
  2995. pfn.auth = cpu_to_le32(WLAN_AUTH_OPEN);
  2996. pfn.wpa_auth = cpu_to_le32(BRCMF_PNO_WPA_AUTH_ANY);
  2997. pfn.wsec = cpu_to_le32(0);
  2998. pfn.infra = cpu_to_le32(1);
  2999. pfn.flags = cpu_to_le32(1 << BRCMF_PNO_HIDDEN_BIT);
  3000. pfn.ssid.SSID_len = cpu_to_le32(ssid_len);
  3001. memcpy(pfn.ssid.SSID, ssid->ssid, ssid_len);
  3002. ret = brcmf_fil_iovar_data_set(ifp, "pfn_add", &pfn,
  3003. sizeof(pfn));
  3004. brcmf_dbg(SCAN, ">>> PNO filter %s for ssid (%s)\n",
  3005. ret == 0 ? "set" : "failed", ssid->ssid);
  3006. }
  3007. /* Enable the PNO */
  3008. if (brcmf_fil_iovar_int_set(ifp, "pfn", 1) < 0) {
  3009. brcmf_err("PNO enable failed!! ret=%d\n", ret);
  3010. return -EINVAL;
  3011. }
  3012. } else {
  3013. return -EINVAL;
  3014. }
  3015. return 0;
  3016. }
  3017. static int brcmf_cfg80211_sched_scan_stop(struct wiphy *wiphy,
  3018. struct net_device *ndev)
  3019. {
  3020. struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
  3021. brcmf_dbg(SCAN, "enter\n");
  3022. brcmf_dev_pno_clean(ndev);
  3023. if (cfg->sched_escan)
  3024. brcmf_notify_escan_complete(cfg, netdev_priv(ndev), true, true);
  3025. return 0;
  3026. }
  3027. static s32 brcmf_configure_opensecurity(struct brcmf_if *ifp)
  3028. {
  3029. s32 err;
  3030. /* set auth */
  3031. err = brcmf_fil_bsscfg_int_set(ifp, "auth", 0);
  3032. if (err < 0) {
  3033. brcmf_err("auth error %d\n", err);
  3034. return err;
  3035. }
  3036. /* set wsec */
  3037. err = brcmf_fil_bsscfg_int_set(ifp, "wsec", 0);
  3038. if (err < 0) {
  3039. brcmf_err("wsec error %d\n", err);
  3040. return err;
  3041. }
  3042. /* set upper-layer auth */
  3043. err = brcmf_fil_bsscfg_int_set(ifp, "wpa_auth", WPA_AUTH_NONE);
  3044. if (err < 0) {
  3045. brcmf_err("wpa_auth error %d\n", err);
  3046. return err;
  3047. }
  3048. return 0;
  3049. }
  3050. static bool brcmf_valid_wpa_oui(u8 *oui, bool is_rsn_ie)
  3051. {
  3052. if (is_rsn_ie)
  3053. return (memcmp(oui, RSN_OUI, TLV_OUI_LEN) == 0);
  3054. return (memcmp(oui, WPA_OUI, TLV_OUI_LEN) == 0);
  3055. }
  3056. static s32
  3057. brcmf_configure_wpaie(struct brcmf_if *ifp,
  3058. const struct brcmf_vs_tlv *wpa_ie,
  3059. bool is_rsn_ie)
  3060. {
  3061. u32 auth = 0; /* d11 open authentication */
  3062. u16 count;
  3063. s32 err = 0;
  3064. s32 len = 0;
  3065. u32 i;
  3066. u32 wsec;
  3067. u32 pval = 0;
  3068. u32 gval = 0;
  3069. u32 wpa_auth = 0;
  3070. u32 offset;
  3071. u8 *data;
  3072. u16 rsn_cap;
  3073. u32 wme_bss_disable;
  3074. brcmf_dbg(TRACE, "Enter\n");
  3075. if (wpa_ie == NULL)
  3076. goto exit;
  3077. len = wpa_ie->len + TLV_HDR_LEN;
  3078. data = (u8 *)wpa_ie;
  3079. offset = TLV_HDR_LEN;
  3080. if (!is_rsn_ie)
  3081. offset += VS_IE_FIXED_HDR_LEN;
  3082. else
  3083. offset += WPA_IE_VERSION_LEN;
  3084. /* check for multicast cipher suite */
  3085. if (offset + WPA_IE_MIN_OUI_LEN > len) {
  3086. err = -EINVAL;
  3087. brcmf_err("no multicast cipher suite\n");
  3088. goto exit;
  3089. }
  3090. if (!brcmf_valid_wpa_oui(&data[offset], is_rsn_ie)) {
  3091. err = -EINVAL;
  3092. brcmf_err("ivalid OUI\n");
  3093. goto exit;
  3094. }
  3095. offset += TLV_OUI_LEN;
  3096. /* pick up multicast cipher */
  3097. switch (data[offset]) {
  3098. case WPA_CIPHER_NONE:
  3099. gval = 0;
  3100. break;
  3101. case WPA_CIPHER_WEP_40:
  3102. case WPA_CIPHER_WEP_104:
  3103. gval = WEP_ENABLED;
  3104. break;
  3105. case WPA_CIPHER_TKIP:
  3106. gval = TKIP_ENABLED;
  3107. break;
  3108. case WPA_CIPHER_AES_CCM:
  3109. gval = AES_ENABLED;
  3110. break;
  3111. default:
  3112. err = -EINVAL;
  3113. brcmf_err("Invalid multi cast cipher info\n");
  3114. goto exit;
  3115. }
  3116. offset++;
  3117. /* walk thru unicast cipher list and pick up what we recognize */
  3118. count = data[offset] + (data[offset + 1] << 8);
  3119. offset += WPA_IE_SUITE_COUNT_LEN;
  3120. /* Check for unicast suite(s) */
  3121. if (offset + (WPA_IE_MIN_OUI_LEN * count) > len) {
  3122. err = -EINVAL;
  3123. brcmf_err("no unicast cipher suite\n");
  3124. goto exit;
  3125. }
  3126. for (i = 0; i < count; i++) {
  3127. if (!brcmf_valid_wpa_oui(&data[offset], is_rsn_ie)) {
  3128. err = -EINVAL;
  3129. brcmf_err("ivalid OUI\n");
  3130. goto exit;
  3131. }
  3132. offset += TLV_OUI_LEN;
  3133. switch (data[offset]) {
  3134. case WPA_CIPHER_NONE:
  3135. break;
  3136. case WPA_CIPHER_WEP_40:
  3137. case WPA_CIPHER_WEP_104:
  3138. pval |= WEP_ENABLED;
  3139. break;
  3140. case WPA_CIPHER_TKIP:
  3141. pval |= TKIP_ENABLED;
  3142. break;
  3143. case WPA_CIPHER_AES_CCM:
  3144. pval |= AES_ENABLED;
  3145. break;
  3146. default:
  3147. brcmf_err("Ivalid unicast security info\n");
  3148. }
  3149. offset++;
  3150. }
  3151. /* walk thru auth management suite list and pick up what we recognize */
  3152. count = data[offset] + (data[offset + 1] << 8);
  3153. offset += WPA_IE_SUITE_COUNT_LEN;
  3154. /* Check for auth key management suite(s) */
  3155. if (offset + (WPA_IE_MIN_OUI_LEN * count) > len) {
  3156. err = -EINVAL;
  3157. brcmf_err("no auth key mgmt suite\n");
  3158. goto exit;
  3159. }
  3160. for (i = 0; i < count; i++) {
  3161. if (!brcmf_valid_wpa_oui(&data[offset], is_rsn_ie)) {
  3162. err = -EINVAL;
  3163. brcmf_err("ivalid OUI\n");
  3164. goto exit;
  3165. }
  3166. offset += TLV_OUI_LEN;
  3167. switch (data[offset]) {
  3168. case RSN_AKM_NONE:
  3169. brcmf_dbg(TRACE, "RSN_AKM_NONE\n");
  3170. wpa_auth |= WPA_AUTH_NONE;
  3171. break;
  3172. case RSN_AKM_UNSPECIFIED:
  3173. brcmf_dbg(TRACE, "RSN_AKM_UNSPECIFIED\n");
  3174. is_rsn_ie ? (wpa_auth |= WPA2_AUTH_UNSPECIFIED) :
  3175. (wpa_auth |= WPA_AUTH_UNSPECIFIED);
  3176. break;
  3177. case RSN_AKM_PSK:
  3178. brcmf_dbg(TRACE, "RSN_AKM_PSK\n");
  3179. is_rsn_ie ? (wpa_auth |= WPA2_AUTH_PSK) :
  3180. (wpa_auth |= WPA_AUTH_PSK);
  3181. break;
  3182. default:
  3183. brcmf_err("Ivalid key mgmt info\n");
  3184. }
  3185. offset++;
  3186. }
  3187. if (is_rsn_ie) {
  3188. wme_bss_disable = 1;
  3189. if ((offset + RSN_CAP_LEN) <= len) {
  3190. rsn_cap = data[offset] + (data[offset + 1] << 8);
  3191. if (rsn_cap & RSN_CAP_PTK_REPLAY_CNTR_MASK)
  3192. wme_bss_disable = 0;
  3193. }
  3194. /* set wme_bss_disable to sync RSN Capabilities */
  3195. err = brcmf_fil_bsscfg_int_set(ifp, "wme_bss_disable",
  3196. wme_bss_disable);
  3197. if (err < 0) {
  3198. brcmf_err("wme_bss_disable error %d\n", err);
  3199. goto exit;
  3200. }
  3201. }
  3202. /* FOR WPS , set SES_OW_ENABLED */
  3203. wsec = (pval | gval | SES_OW_ENABLED);
  3204. /* set auth */
  3205. err = brcmf_fil_bsscfg_int_set(ifp, "auth", auth);
  3206. if (err < 0) {
  3207. brcmf_err("auth error %d\n", err);
  3208. goto exit;
  3209. }
  3210. /* set wsec */
  3211. err = brcmf_fil_bsscfg_int_set(ifp, "wsec", wsec);
  3212. if (err < 0) {
  3213. brcmf_err("wsec error %d\n", err);
  3214. goto exit;
  3215. }
  3216. /* set upper-layer auth */
  3217. err = brcmf_fil_bsscfg_int_set(ifp, "wpa_auth", wpa_auth);
  3218. if (err < 0) {
  3219. brcmf_err("wpa_auth error %d\n", err);
  3220. goto exit;
  3221. }
  3222. exit:
  3223. return err;
  3224. }
  3225. static s32
  3226. brcmf_parse_vndr_ies(const u8 *vndr_ie_buf, u32 vndr_ie_len,
  3227. struct parsed_vndr_ies *vndr_ies)
  3228. {
  3229. struct brcmf_vs_tlv *vndrie;
  3230. struct brcmf_tlv *ie;
  3231. struct parsed_vndr_ie_info *parsed_info;
  3232. s32 remaining_len;
  3233. remaining_len = (s32)vndr_ie_len;
  3234. memset(vndr_ies, 0, sizeof(*vndr_ies));
  3235. ie = (struct brcmf_tlv *)vndr_ie_buf;
  3236. while (ie) {
  3237. if (ie->id != WLAN_EID_VENDOR_SPECIFIC)
  3238. goto next;
  3239. vndrie = (struct brcmf_vs_tlv *)ie;
  3240. /* len should be bigger than OUI length + one */
  3241. if (vndrie->len < (VS_IE_FIXED_HDR_LEN - TLV_HDR_LEN + 1)) {
  3242. brcmf_err("invalid vndr ie. length is too small %d\n",
  3243. vndrie->len);
  3244. goto next;
  3245. }
  3246. /* if wpa or wme ie, do not add ie */
  3247. if (!memcmp(vndrie->oui, (u8 *)WPA_OUI, TLV_OUI_LEN) &&
  3248. ((vndrie->oui_type == WPA_OUI_TYPE) ||
  3249. (vndrie->oui_type == WME_OUI_TYPE))) {
  3250. brcmf_dbg(TRACE, "Found WPA/WME oui. Do not add it\n");
  3251. goto next;
  3252. }
  3253. parsed_info = &vndr_ies->ie_info[vndr_ies->count];
  3254. /* save vndr ie information */
  3255. parsed_info->ie_ptr = (char *)vndrie;
  3256. parsed_info->ie_len = vndrie->len + TLV_HDR_LEN;
  3257. memcpy(&parsed_info->vndrie, vndrie, sizeof(*vndrie));
  3258. vndr_ies->count++;
  3259. brcmf_dbg(TRACE, "** OUI %02x %02x %02x, type 0x%02x\n",
  3260. parsed_info->vndrie.oui[0],
  3261. parsed_info->vndrie.oui[1],
  3262. parsed_info->vndrie.oui[2],
  3263. parsed_info->vndrie.oui_type);
  3264. if (vndr_ies->count >= VNDR_IE_PARSE_LIMIT)
  3265. break;
  3266. next:
  3267. remaining_len -= (ie->len + TLV_HDR_LEN);
  3268. if (remaining_len <= TLV_HDR_LEN)
  3269. ie = NULL;
  3270. else
  3271. ie = (struct brcmf_tlv *)(((u8 *)ie) + ie->len +
  3272. TLV_HDR_LEN);
  3273. }
  3274. return 0;
  3275. }
  3276. static u32
  3277. brcmf_vndr_ie(u8 *iebuf, s32 pktflag, u8 *ie_ptr, u32 ie_len, s8 *add_del_cmd)
  3278. {
  3279. strncpy(iebuf, add_del_cmd, VNDR_IE_CMD_LEN - 1);
  3280. iebuf[VNDR_IE_CMD_LEN - 1] = '\0';
  3281. put_unaligned_le32(1, &iebuf[VNDR_IE_COUNT_OFFSET]);
  3282. put_unaligned_le32(pktflag, &iebuf[VNDR_IE_PKTFLAG_OFFSET]);
  3283. memcpy(&iebuf[VNDR_IE_VSIE_OFFSET], ie_ptr, ie_len);
  3284. return ie_len + VNDR_IE_HDR_SIZE;
  3285. }
  3286. s32 brcmf_vif_set_mgmt_ie(struct brcmf_cfg80211_vif *vif, s32 pktflag,
  3287. const u8 *vndr_ie_buf, u32 vndr_ie_len)
  3288. {
  3289. struct brcmf_if *ifp;
  3290. struct vif_saved_ie *saved_ie;
  3291. s32 err = 0;
  3292. u8 *iovar_ie_buf;
  3293. u8 *curr_ie_buf;
  3294. u8 *mgmt_ie_buf = NULL;
  3295. int mgmt_ie_buf_len;
  3296. u32 *mgmt_ie_len;
  3297. u32 del_add_ie_buf_len = 0;
  3298. u32 total_ie_buf_len = 0;
  3299. u32 parsed_ie_buf_len = 0;
  3300. struct parsed_vndr_ies old_vndr_ies;
  3301. struct parsed_vndr_ies new_vndr_ies;
  3302. struct parsed_vndr_ie_info *vndrie_info;
  3303. s32 i;
  3304. u8 *ptr;
  3305. int remained_buf_len;
  3306. if (!vif)
  3307. return -ENODEV;
  3308. ifp = vif->ifp;
  3309. saved_ie = &vif->saved_ie;
  3310. brcmf_dbg(TRACE, "bssidx %d, pktflag : 0x%02X\n", ifp->bssidx, pktflag);
  3311. iovar_ie_buf = kzalloc(WL_EXTRA_BUF_MAX, GFP_KERNEL);
  3312. if (!iovar_ie_buf)
  3313. return -ENOMEM;
  3314. curr_ie_buf = iovar_ie_buf;
  3315. switch (pktflag) {
  3316. case BRCMF_VNDR_IE_PRBREQ_FLAG:
  3317. mgmt_ie_buf = saved_ie->probe_req_ie;
  3318. mgmt_ie_len = &saved_ie->probe_req_ie_len;
  3319. mgmt_ie_buf_len = sizeof(saved_ie->probe_req_ie);
  3320. break;
  3321. case BRCMF_VNDR_IE_PRBRSP_FLAG:
  3322. mgmt_ie_buf = saved_ie->probe_res_ie;
  3323. mgmt_ie_len = &saved_ie->probe_res_ie_len;
  3324. mgmt_ie_buf_len = sizeof(saved_ie->probe_res_ie);
  3325. break;
  3326. case BRCMF_VNDR_IE_BEACON_FLAG:
  3327. mgmt_ie_buf = saved_ie->beacon_ie;
  3328. mgmt_ie_len = &saved_ie->beacon_ie_len;
  3329. mgmt_ie_buf_len = sizeof(saved_ie->beacon_ie);
  3330. break;
  3331. case BRCMF_VNDR_IE_ASSOCREQ_FLAG:
  3332. mgmt_ie_buf = saved_ie->assoc_req_ie;
  3333. mgmt_ie_len = &saved_ie->assoc_req_ie_len;
  3334. mgmt_ie_buf_len = sizeof(saved_ie->assoc_req_ie);
  3335. break;
  3336. default:
  3337. err = -EPERM;
  3338. brcmf_err("not suitable type\n");
  3339. goto exit;
  3340. }
  3341. if (vndr_ie_len > mgmt_ie_buf_len) {
  3342. err = -ENOMEM;
  3343. brcmf_err("extra IE size too big\n");
  3344. goto exit;
  3345. }
  3346. /* parse and save new vndr_ie in curr_ie_buff before comparing it */
  3347. if (vndr_ie_buf && vndr_ie_len && curr_ie_buf) {
  3348. ptr = curr_ie_buf;
  3349. brcmf_parse_vndr_ies(vndr_ie_buf, vndr_ie_len, &new_vndr_ies);
  3350. for (i = 0; i < new_vndr_ies.count; i++) {
  3351. vndrie_info = &new_vndr_ies.ie_info[i];
  3352. memcpy(ptr + parsed_ie_buf_len, vndrie_info->ie_ptr,
  3353. vndrie_info->ie_len);
  3354. parsed_ie_buf_len += vndrie_info->ie_len;
  3355. }
  3356. }
  3357. if (mgmt_ie_buf && *mgmt_ie_len) {
  3358. if (parsed_ie_buf_len && (parsed_ie_buf_len == *mgmt_ie_len) &&
  3359. (memcmp(mgmt_ie_buf, curr_ie_buf,
  3360. parsed_ie_buf_len) == 0)) {
  3361. brcmf_dbg(TRACE, "Previous mgmt IE equals to current IE\n");
  3362. goto exit;
  3363. }
  3364. /* parse old vndr_ie */
  3365. brcmf_parse_vndr_ies(mgmt_ie_buf, *mgmt_ie_len, &old_vndr_ies);
  3366. /* make a command to delete old ie */
  3367. for (i = 0; i < old_vndr_ies.count; i++) {
  3368. vndrie_info = &old_vndr_ies.ie_info[i];
  3369. brcmf_dbg(TRACE, "DEL ID : %d, Len: %d , OUI:%02x:%02x:%02x\n",
  3370. vndrie_info->vndrie.id,
  3371. vndrie_info->vndrie.len,
  3372. vndrie_info->vndrie.oui[0],
  3373. vndrie_info->vndrie.oui[1],
  3374. vndrie_info->vndrie.oui[2]);
  3375. del_add_ie_buf_len = brcmf_vndr_ie(curr_ie_buf, pktflag,
  3376. vndrie_info->ie_ptr,
  3377. vndrie_info->ie_len,
  3378. "del");
  3379. curr_ie_buf += del_add_ie_buf_len;
  3380. total_ie_buf_len += del_add_ie_buf_len;
  3381. }
  3382. }
  3383. *mgmt_ie_len = 0;
  3384. /* Add if there is any extra IE */
  3385. if (mgmt_ie_buf && parsed_ie_buf_len) {
  3386. ptr = mgmt_ie_buf;
  3387. remained_buf_len = mgmt_ie_buf_len;
  3388. /* make a command to add new ie */
  3389. for (i = 0; i < new_vndr_ies.count; i++) {
  3390. vndrie_info = &new_vndr_ies.ie_info[i];
  3391. /* verify remained buf size before copy data */
  3392. if (remained_buf_len < (vndrie_info->vndrie.len +
  3393. VNDR_IE_VSIE_OFFSET)) {
  3394. brcmf_err("no space in mgmt_ie_buf: len left %d",
  3395. remained_buf_len);
  3396. break;
  3397. }
  3398. remained_buf_len -= (vndrie_info->ie_len +
  3399. VNDR_IE_VSIE_OFFSET);
  3400. brcmf_dbg(TRACE, "ADDED ID : %d, Len: %d, OUI:%02x:%02x:%02x\n",
  3401. vndrie_info->vndrie.id,
  3402. vndrie_info->vndrie.len,
  3403. vndrie_info->vndrie.oui[0],
  3404. vndrie_info->vndrie.oui[1],
  3405. vndrie_info->vndrie.oui[2]);
  3406. del_add_ie_buf_len = brcmf_vndr_ie(curr_ie_buf, pktflag,
  3407. vndrie_info->ie_ptr,
  3408. vndrie_info->ie_len,
  3409. "add");
  3410. /* save the parsed IE in wl struct */
  3411. memcpy(ptr + (*mgmt_ie_len), vndrie_info->ie_ptr,
  3412. vndrie_info->ie_len);
  3413. *mgmt_ie_len += vndrie_info->ie_len;
  3414. curr_ie_buf += del_add_ie_buf_len;
  3415. total_ie_buf_len += del_add_ie_buf_len;
  3416. }
  3417. }
  3418. if (total_ie_buf_len) {
  3419. err = brcmf_fil_bsscfg_data_set(ifp, "vndr_ie", iovar_ie_buf,
  3420. total_ie_buf_len);
  3421. if (err)
  3422. brcmf_err("vndr ie set error : %d\n", err);
  3423. }
  3424. exit:
  3425. kfree(iovar_ie_buf);
  3426. return err;
  3427. }
  3428. s32 brcmf_vif_clear_mgmt_ies(struct brcmf_cfg80211_vif *vif)
  3429. {
  3430. s32 pktflags[] = {
  3431. BRCMF_VNDR_IE_PRBREQ_FLAG,
  3432. BRCMF_VNDR_IE_PRBRSP_FLAG,
  3433. BRCMF_VNDR_IE_BEACON_FLAG
  3434. };
  3435. int i;
  3436. for (i = 0; i < ARRAY_SIZE(pktflags); i++)
  3437. brcmf_vif_set_mgmt_ie(vif, pktflags[i], NULL, 0);
  3438. memset(&vif->saved_ie, 0, sizeof(vif->saved_ie));
  3439. return 0;
  3440. }
  3441. static s32
  3442. brcmf_config_ap_mgmt_ie(struct brcmf_cfg80211_vif *vif,
  3443. struct cfg80211_beacon_data *beacon)
  3444. {
  3445. s32 err;
  3446. /* Set Beacon IEs to FW */
  3447. err = brcmf_vif_set_mgmt_ie(vif, BRCMF_VNDR_IE_BEACON_FLAG,
  3448. beacon->tail, beacon->tail_len);
  3449. if (err) {
  3450. brcmf_err("Set Beacon IE Failed\n");
  3451. return err;
  3452. }
  3453. brcmf_dbg(TRACE, "Applied Vndr IEs for Beacon\n");
  3454. /* Set Probe Response IEs to FW */
  3455. err = brcmf_vif_set_mgmt_ie(vif, BRCMF_VNDR_IE_PRBRSP_FLAG,
  3456. beacon->proberesp_ies,
  3457. beacon->proberesp_ies_len);
  3458. if (err)
  3459. brcmf_err("Set Probe Resp IE Failed\n");
  3460. else
  3461. brcmf_dbg(TRACE, "Applied Vndr IEs for Probe Resp\n");
  3462. return err;
  3463. }
  3464. static s32
  3465. brcmf_cfg80211_start_ap(struct wiphy *wiphy, struct net_device *ndev,
  3466. struct cfg80211_ap_settings *settings)
  3467. {
  3468. s32 ie_offset;
  3469. struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
  3470. struct brcmf_if *ifp = netdev_priv(ndev);
  3471. const struct brcmf_tlv *ssid_ie;
  3472. const struct brcmf_tlv *country_ie;
  3473. struct brcmf_ssid_le ssid_le;
  3474. s32 err = -EPERM;
  3475. const struct brcmf_tlv *rsn_ie;
  3476. const struct brcmf_vs_tlv *wpa_ie;
  3477. struct brcmf_join_params join_params;
  3478. enum nl80211_iftype dev_role;
  3479. struct brcmf_fil_bss_enable_le bss_enable;
  3480. u16 chanspec;
  3481. bool mbss;
  3482. int is_11d;
  3483. brcmf_dbg(TRACE, "ctrlchn=%d, center=%d, bw=%d, beacon_interval=%d, dtim_period=%d,\n",
  3484. settings->chandef.chan->hw_value,
  3485. settings->chandef.center_freq1, settings->chandef.width,
  3486. settings->beacon_interval, settings->dtim_period);
  3487. brcmf_dbg(TRACE, "ssid=%s(%zu), auth_type=%d, inactivity_timeout=%d\n",
  3488. settings->ssid, settings->ssid_len, settings->auth_type,
  3489. settings->inactivity_timeout);
  3490. dev_role = ifp->vif->wdev.iftype;
  3491. mbss = ifp->vif->mbss;
  3492. /* store current 11d setting */
  3493. brcmf_fil_cmd_int_get(ifp, BRCMF_C_GET_REGULATORY, &ifp->vif->is_11d);
  3494. country_ie = brcmf_parse_tlvs((u8 *)settings->beacon.tail,
  3495. settings->beacon.tail_len,
  3496. WLAN_EID_COUNTRY);
  3497. is_11d = country_ie ? 1 : 0;
  3498. memset(&ssid_le, 0, sizeof(ssid_le));
  3499. if (settings->ssid == NULL || settings->ssid_len == 0) {
  3500. ie_offset = DOT11_MGMT_HDR_LEN + DOT11_BCN_PRB_FIXED_LEN;
  3501. ssid_ie = brcmf_parse_tlvs(
  3502. (u8 *)&settings->beacon.head[ie_offset],
  3503. settings->beacon.head_len - ie_offset,
  3504. WLAN_EID_SSID);
  3505. if (!ssid_ie)
  3506. return -EINVAL;
  3507. memcpy(ssid_le.SSID, ssid_ie->data, ssid_ie->len);
  3508. ssid_le.SSID_len = cpu_to_le32(ssid_ie->len);
  3509. brcmf_dbg(TRACE, "SSID is (%s) in Head\n", ssid_le.SSID);
  3510. } else {
  3511. memcpy(ssid_le.SSID, settings->ssid, settings->ssid_len);
  3512. ssid_le.SSID_len = cpu_to_le32((u32)settings->ssid_len);
  3513. }
  3514. if (!mbss) {
  3515. brcmf_set_mpc(ifp, 0);
  3516. brcmf_configure_arp_offload(ifp, false);
  3517. }
  3518. /* find the RSN_IE */
  3519. rsn_ie = brcmf_parse_tlvs((u8 *)settings->beacon.tail,
  3520. settings->beacon.tail_len, WLAN_EID_RSN);
  3521. /* find the WPA_IE */
  3522. wpa_ie = brcmf_find_wpaie((u8 *)settings->beacon.tail,
  3523. settings->beacon.tail_len);
  3524. if ((wpa_ie != NULL || rsn_ie != NULL)) {
  3525. brcmf_dbg(TRACE, "WPA(2) IE is found\n");
  3526. if (wpa_ie != NULL) {
  3527. /* WPA IE */
  3528. err = brcmf_configure_wpaie(ifp, wpa_ie, false);
  3529. if (err < 0)
  3530. goto exit;
  3531. } else {
  3532. struct brcmf_vs_tlv *tmp_ie;
  3533. tmp_ie = (struct brcmf_vs_tlv *)rsn_ie;
  3534. /* RSN IE */
  3535. err = brcmf_configure_wpaie(ifp, tmp_ie, true);
  3536. if (err < 0)
  3537. goto exit;
  3538. }
  3539. } else {
  3540. brcmf_dbg(TRACE, "No WPA(2) IEs found\n");
  3541. brcmf_configure_opensecurity(ifp);
  3542. }
  3543. brcmf_config_ap_mgmt_ie(ifp->vif, &settings->beacon);
  3544. if (!mbss) {
  3545. chanspec = chandef_to_chanspec(&cfg->d11inf,
  3546. &settings->chandef);
  3547. err = brcmf_fil_iovar_int_set(ifp, "chanspec", chanspec);
  3548. if (err < 0) {
  3549. brcmf_err("Set Channel failed: chspec=%d, %d\n",
  3550. chanspec, err);
  3551. goto exit;
  3552. }
  3553. if (is_11d != ifp->vif->is_11d) {
  3554. err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_REGULATORY,
  3555. is_11d);
  3556. if (err < 0) {
  3557. brcmf_err("Regulatory Set Error, %d\n", err);
  3558. goto exit;
  3559. }
  3560. }
  3561. if (settings->beacon_interval) {
  3562. err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_BCNPRD,
  3563. settings->beacon_interval);
  3564. if (err < 0) {
  3565. brcmf_err("Beacon Interval Set Error, %d\n",
  3566. err);
  3567. goto exit;
  3568. }
  3569. }
  3570. if (settings->dtim_period) {
  3571. err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_DTIMPRD,
  3572. settings->dtim_period);
  3573. if (err < 0) {
  3574. brcmf_err("DTIM Interval Set Error, %d\n", err);
  3575. goto exit;
  3576. }
  3577. }
  3578. if (dev_role == NL80211_IFTYPE_AP) {
  3579. err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_DOWN, 1);
  3580. if (err < 0) {
  3581. brcmf_err("BRCMF_C_DOWN error %d\n", err);
  3582. goto exit;
  3583. }
  3584. brcmf_fil_iovar_int_set(ifp, "apsta", 0);
  3585. }
  3586. err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_INFRA, 1);
  3587. if (err < 0) {
  3588. brcmf_err("SET INFRA error %d\n", err);
  3589. goto exit;
  3590. }
  3591. } else if (WARN_ON(is_11d != ifp->vif->is_11d)) {
  3592. /* Multiple-BSS should use same 11d configuration */
  3593. err = -EINVAL;
  3594. goto exit;
  3595. }
  3596. if (dev_role == NL80211_IFTYPE_AP) {
  3597. if ((brcmf_feat_is_enabled(ifp, BRCMF_FEAT_MBSS)) && (!mbss))
  3598. brcmf_fil_iovar_int_set(ifp, "mbss", 1);
  3599. err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_AP, 1);
  3600. if (err < 0) {
  3601. brcmf_err("setting AP mode failed %d\n", err);
  3602. goto exit;
  3603. }
  3604. err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_UP, 1);
  3605. if (err < 0) {
  3606. brcmf_err("BRCMF_C_UP error (%d)\n", err);
  3607. goto exit;
  3608. }
  3609. /* On DOWN the firmware removes the WEP keys, reconfigure
  3610. * them if they were set.
  3611. */
  3612. brcmf_cfg80211_reconfigure_wep(ifp);
  3613. memset(&join_params, 0, sizeof(join_params));
  3614. /* join parameters starts with ssid */
  3615. memcpy(&join_params.ssid_le, &ssid_le, sizeof(ssid_le));
  3616. /* create softap */
  3617. err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_SSID,
  3618. &join_params, sizeof(join_params));
  3619. if (err < 0) {
  3620. brcmf_err("SET SSID error (%d)\n", err);
  3621. goto exit;
  3622. }
  3623. brcmf_dbg(TRACE, "AP mode configuration complete\n");
  3624. } else {
  3625. err = brcmf_fil_bsscfg_data_set(ifp, "ssid", &ssid_le,
  3626. sizeof(ssid_le));
  3627. if (err < 0) {
  3628. brcmf_err("setting ssid failed %d\n", err);
  3629. goto exit;
  3630. }
  3631. bss_enable.bsscfg_idx = cpu_to_le32(ifp->bssidx);
  3632. bss_enable.enable = cpu_to_le32(1);
  3633. err = brcmf_fil_iovar_data_set(ifp, "bss", &bss_enable,
  3634. sizeof(bss_enable));
  3635. if (err < 0) {
  3636. brcmf_err("bss_enable config failed %d\n", err);
  3637. goto exit;
  3638. }
  3639. brcmf_dbg(TRACE, "GO mode configuration complete\n");
  3640. }
  3641. clear_bit(BRCMF_VIF_STATUS_AP_CREATING, &ifp->vif->sme_state);
  3642. set_bit(BRCMF_VIF_STATUS_AP_CREATED, &ifp->vif->sme_state);
  3643. exit:
  3644. if ((err) && (!mbss)) {
  3645. brcmf_set_mpc(ifp, 1);
  3646. brcmf_configure_arp_offload(ifp, true);
  3647. }
  3648. return err;
  3649. }
  3650. static int brcmf_cfg80211_stop_ap(struct wiphy *wiphy, struct net_device *ndev)
  3651. {
  3652. struct brcmf_if *ifp = netdev_priv(ndev);
  3653. s32 err;
  3654. struct brcmf_fil_bss_enable_le bss_enable;
  3655. struct brcmf_join_params join_params;
  3656. brcmf_dbg(TRACE, "Enter\n");
  3657. if (ifp->vif->wdev.iftype == NL80211_IFTYPE_AP) {
  3658. /* Due to most likely deauths outstanding we sleep */
  3659. /* first to make sure they get processed by fw. */
  3660. msleep(400);
  3661. if (ifp->vif->mbss) {
  3662. err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_DOWN, 1);
  3663. return err;
  3664. }
  3665. memset(&join_params, 0, sizeof(join_params));
  3666. err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_SSID,
  3667. &join_params, sizeof(join_params));
  3668. if (err < 0)
  3669. brcmf_err("SET SSID error (%d)\n", err);
  3670. err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_DOWN, 1);
  3671. if (err < 0)
  3672. brcmf_err("BRCMF_C_DOWN error %d\n", err);
  3673. err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_AP, 0);
  3674. if (err < 0)
  3675. brcmf_err("setting AP mode failed %d\n", err);
  3676. err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_INFRA, 0);
  3677. if (err < 0)
  3678. brcmf_err("setting INFRA mode failed %d\n", err);
  3679. if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_MBSS))
  3680. brcmf_fil_iovar_int_set(ifp, "mbss", 0);
  3681. err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_REGULATORY,
  3682. ifp->vif->is_11d);
  3683. if (err < 0)
  3684. brcmf_err("restoring REGULATORY setting failed %d\n",
  3685. err);
  3686. /* Bring device back up so it can be used again */
  3687. err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_UP, 1);
  3688. if (err < 0)
  3689. brcmf_err("BRCMF_C_UP error %d\n", err);
  3690. } else {
  3691. bss_enable.bsscfg_idx = cpu_to_le32(ifp->bssidx);
  3692. bss_enable.enable = cpu_to_le32(0);
  3693. err = brcmf_fil_iovar_data_set(ifp, "bss", &bss_enable,
  3694. sizeof(bss_enable));
  3695. if (err < 0)
  3696. brcmf_err("bss_enable config failed %d\n", err);
  3697. }
  3698. brcmf_set_mpc(ifp, 1);
  3699. brcmf_configure_arp_offload(ifp, true);
  3700. set_bit(BRCMF_VIF_STATUS_AP_CREATING, &ifp->vif->sme_state);
  3701. clear_bit(BRCMF_VIF_STATUS_AP_CREATED, &ifp->vif->sme_state);
  3702. return err;
  3703. }
  3704. static s32
  3705. brcmf_cfg80211_change_beacon(struct wiphy *wiphy, struct net_device *ndev,
  3706. struct cfg80211_beacon_data *info)
  3707. {
  3708. struct brcmf_if *ifp = netdev_priv(ndev);
  3709. s32 err;
  3710. brcmf_dbg(TRACE, "Enter\n");
  3711. err = brcmf_config_ap_mgmt_ie(ifp->vif, info);
  3712. return err;
  3713. }
  3714. static int
  3715. brcmf_cfg80211_del_station(struct wiphy *wiphy, struct net_device *ndev,
  3716. struct station_del_parameters *params)
  3717. {
  3718. struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
  3719. struct brcmf_scb_val_le scbval;
  3720. struct brcmf_if *ifp = netdev_priv(ndev);
  3721. s32 err;
  3722. if (!params->mac)
  3723. return -EFAULT;
  3724. brcmf_dbg(TRACE, "Enter %pM\n", params->mac);
  3725. if (ifp->vif == cfg->p2p.bss_idx[P2PAPI_BSSCFG_DEVICE].vif)
  3726. ifp = cfg->p2p.bss_idx[P2PAPI_BSSCFG_PRIMARY].vif->ifp;
  3727. if (!check_vif_up(ifp->vif))
  3728. return -EIO;
  3729. memcpy(&scbval.ea, params->mac, ETH_ALEN);
  3730. scbval.val = cpu_to_le32(WLAN_REASON_DEAUTH_LEAVING);
  3731. err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SCB_DEAUTHENTICATE_FOR_REASON,
  3732. &scbval, sizeof(scbval));
  3733. if (err)
  3734. brcmf_err("SCB_DEAUTHENTICATE_FOR_REASON failed %d\n", err);
  3735. brcmf_dbg(TRACE, "Exit\n");
  3736. return err;
  3737. }
  3738. static int
  3739. brcmf_cfg80211_change_station(struct wiphy *wiphy, struct net_device *ndev,
  3740. const u8 *mac, struct station_parameters *params)
  3741. {
  3742. struct brcmf_if *ifp = netdev_priv(ndev);
  3743. s32 err;
  3744. brcmf_dbg(TRACE, "Enter, MAC %pM, mask 0x%04x set 0x%04x\n", mac,
  3745. params->sta_flags_mask, params->sta_flags_set);
  3746. /* Ignore all 00 MAC */
  3747. if (is_zero_ether_addr(mac))
  3748. return 0;
  3749. if (!(params->sta_flags_mask & BIT(NL80211_STA_FLAG_AUTHORIZED)))
  3750. return 0;
  3751. if (params->sta_flags_set & BIT(NL80211_STA_FLAG_AUTHORIZED))
  3752. err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_SCB_AUTHORIZE,
  3753. (void *)mac, ETH_ALEN);
  3754. else
  3755. err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_SCB_DEAUTHORIZE,
  3756. (void *)mac, ETH_ALEN);
  3757. if (err < 0)
  3758. brcmf_err("Setting SCB (de-)authorize failed, %d\n", err);
  3759. return err;
  3760. }
  3761. static void
  3762. brcmf_cfg80211_mgmt_frame_register(struct wiphy *wiphy,
  3763. struct wireless_dev *wdev,
  3764. u16 frame_type, bool reg)
  3765. {
  3766. struct brcmf_cfg80211_vif *vif;
  3767. u16 mgmt_type;
  3768. brcmf_dbg(TRACE, "Enter, frame_type %04x, reg=%d\n", frame_type, reg);
  3769. mgmt_type = (frame_type & IEEE80211_FCTL_STYPE) >> 4;
  3770. vif = container_of(wdev, struct brcmf_cfg80211_vif, wdev);
  3771. if (reg)
  3772. vif->mgmt_rx_reg |= BIT(mgmt_type);
  3773. else
  3774. vif->mgmt_rx_reg &= ~BIT(mgmt_type);
  3775. }
  3776. static int
  3777. brcmf_cfg80211_mgmt_tx(struct wiphy *wiphy, struct wireless_dev *wdev,
  3778. struct cfg80211_mgmt_tx_params *params, u64 *cookie)
  3779. {
  3780. struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
  3781. struct ieee80211_channel *chan = params->chan;
  3782. const u8 *buf = params->buf;
  3783. size_t len = params->len;
  3784. const struct ieee80211_mgmt *mgmt;
  3785. struct brcmf_cfg80211_vif *vif;
  3786. s32 err = 0;
  3787. s32 ie_offset;
  3788. s32 ie_len;
  3789. struct brcmf_fil_action_frame_le *action_frame;
  3790. struct brcmf_fil_af_params_le *af_params;
  3791. bool ack;
  3792. s32 chan_nr;
  3793. u32 freq;
  3794. brcmf_dbg(TRACE, "Enter\n");
  3795. *cookie = 0;
  3796. mgmt = (const struct ieee80211_mgmt *)buf;
  3797. if (!ieee80211_is_mgmt(mgmt->frame_control)) {
  3798. brcmf_err("Driver only allows MGMT packet type\n");
  3799. return -EPERM;
  3800. }
  3801. vif = container_of(wdev, struct brcmf_cfg80211_vif, wdev);
  3802. if (ieee80211_is_probe_resp(mgmt->frame_control)) {
  3803. /* Right now the only reason to get a probe response */
  3804. /* is for p2p listen response or for p2p GO from */
  3805. /* wpa_supplicant. Unfortunately the probe is send */
  3806. /* on primary ndev, while dongle wants it on the p2p */
  3807. /* vif. Since this is only reason for a probe */
  3808. /* response to be sent, the vif is taken from cfg. */
  3809. /* If ever desired to send proberesp for non p2p */
  3810. /* response then data should be checked for */
  3811. /* "DIRECT-". Note in future supplicant will take */
  3812. /* dedicated p2p wdev to do this and then this 'hack'*/
  3813. /* is not needed anymore. */
  3814. ie_offset = DOT11_MGMT_HDR_LEN +
  3815. DOT11_BCN_PRB_FIXED_LEN;
  3816. ie_len = len - ie_offset;
  3817. if (vif == cfg->p2p.bss_idx[P2PAPI_BSSCFG_PRIMARY].vif)
  3818. vif = cfg->p2p.bss_idx[P2PAPI_BSSCFG_DEVICE].vif;
  3819. err = brcmf_vif_set_mgmt_ie(vif,
  3820. BRCMF_VNDR_IE_PRBRSP_FLAG,
  3821. &buf[ie_offset],
  3822. ie_len);
  3823. cfg80211_mgmt_tx_status(wdev, *cookie, buf, len, true,
  3824. GFP_KERNEL);
  3825. } else if (ieee80211_is_action(mgmt->frame_control)) {
  3826. af_params = kzalloc(sizeof(*af_params), GFP_KERNEL);
  3827. if (af_params == NULL) {
  3828. brcmf_err("unable to allocate frame\n");
  3829. err = -ENOMEM;
  3830. goto exit;
  3831. }
  3832. action_frame = &af_params->action_frame;
  3833. /* Add the packet Id */
  3834. action_frame->packet_id = cpu_to_le32(*cookie);
  3835. /* Add BSSID */
  3836. memcpy(&action_frame->da[0], &mgmt->da[0], ETH_ALEN);
  3837. memcpy(&af_params->bssid[0], &mgmt->bssid[0], ETH_ALEN);
  3838. /* Add the length exepted for 802.11 header */
  3839. action_frame->len = cpu_to_le16(len - DOT11_MGMT_HDR_LEN);
  3840. /* Add the channel. Use the one specified as parameter if any or
  3841. * the current one (got from the firmware) otherwise
  3842. */
  3843. if (chan)
  3844. freq = chan->center_freq;
  3845. else
  3846. brcmf_fil_cmd_int_get(vif->ifp, BRCMF_C_GET_CHANNEL,
  3847. &freq);
  3848. chan_nr = ieee80211_frequency_to_channel(freq);
  3849. af_params->channel = cpu_to_le32(chan_nr);
  3850. memcpy(action_frame->data, &buf[DOT11_MGMT_HDR_LEN],
  3851. le16_to_cpu(action_frame->len));
  3852. brcmf_dbg(TRACE, "Action frame, cookie=%lld, len=%d, freq=%d\n",
  3853. *cookie, le16_to_cpu(action_frame->len), freq);
  3854. ack = brcmf_p2p_send_action_frame(cfg, cfg_to_ndev(cfg),
  3855. af_params);
  3856. cfg80211_mgmt_tx_status(wdev, *cookie, buf, len, ack,
  3857. GFP_KERNEL);
  3858. kfree(af_params);
  3859. } else {
  3860. brcmf_dbg(TRACE, "Unhandled, fc=%04x!!\n", mgmt->frame_control);
  3861. brcmf_dbg_hex_dump(true, buf, len, "payload, len=%Zu\n", len);
  3862. }
  3863. exit:
  3864. return err;
  3865. }
  3866. static int
  3867. brcmf_cfg80211_cancel_remain_on_channel(struct wiphy *wiphy,
  3868. struct wireless_dev *wdev,
  3869. u64 cookie)
  3870. {
  3871. struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
  3872. struct brcmf_cfg80211_vif *vif;
  3873. int err = 0;
  3874. brcmf_dbg(TRACE, "Enter p2p listen cancel\n");
  3875. vif = cfg->p2p.bss_idx[P2PAPI_BSSCFG_DEVICE].vif;
  3876. if (vif == NULL) {
  3877. brcmf_err("No p2p device available for probe response\n");
  3878. err = -ENODEV;
  3879. goto exit;
  3880. }
  3881. brcmf_p2p_cancel_remain_on_channel(vif->ifp);
  3882. exit:
  3883. return err;
  3884. }
  3885. static int brcmf_cfg80211_crit_proto_start(struct wiphy *wiphy,
  3886. struct wireless_dev *wdev,
  3887. enum nl80211_crit_proto_id proto,
  3888. u16 duration)
  3889. {
  3890. struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
  3891. struct brcmf_cfg80211_vif *vif;
  3892. vif = container_of(wdev, struct brcmf_cfg80211_vif, wdev);
  3893. /* only DHCP support for now */
  3894. if (proto != NL80211_CRIT_PROTO_DHCP)
  3895. return -EINVAL;
  3896. /* suppress and abort scanning */
  3897. set_bit(BRCMF_SCAN_STATUS_SUPPRESS, &cfg->scan_status);
  3898. brcmf_abort_scanning(cfg);
  3899. return brcmf_btcoex_set_mode(vif, BRCMF_BTCOEX_DISABLED, duration);
  3900. }
  3901. static void brcmf_cfg80211_crit_proto_stop(struct wiphy *wiphy,
  3902. struct wireless_dev *wdev)
  3903. {
  3904. struct brcmf_cfg80211_info *cfg = wiphy_to_cfg(wiphy);
  3905. struct brcmf_cfg80211_vif *vif;
  3906. vif = container_of(wdev, struct brcmf_cfg80211_vif, wdev);
  3907. brcmf_btcoex_set_mode(vif, BRCMF_BTCOEX_ENABLED, 0);
  3908. clear_bit(BRCMF_SCAN_STATUS_SUPPRESS, &cfg->scan_status);
  3909. }
  3910. static s32
  3911. brcmf_notify_tdls_peer_event(struct brcmf_if *ifp,
  3912. const struct brcmf_event_msg *e, void *data)
  3913. {
  3914. switch (e->reason) {
  3915. case BRCMF_E_REASON_TDLS_PEER_DISCOVERED:
  3916. brcmf_dbg(TRACE, "TDLS Peer Discovered\n");
  3917. break;
  3918. case BRCMF_E_REASON_TDLS_PEER_CONNECTED:
  3919. brcmf_dbg(TRACE, "TDLS Peer Connected\n");
  3920. brcmf_proto_add_tdls_peer(ifp->drvr, ifp->ifidx, (u8 *)e->addr);
  3921. break;
  3922. case BRCMF_E_REASON_TDLS_PEER_DISCONNECTED:
  3923. brcmf_dbg(TRACE, "TDLS Peer Disconnected\n");
  3924. brcmf_proto_delete_peer(ifp->drvr, ifp->ifidx, (u8 *)e->addr);
  3925. break;
  3926. }
  3927. return 0;
  3928. }
  3929. static int brcmf_convert_nl80211_tdls_oper(enum nl80211_tdls_operation oper)
  3930. {
  3931. int ret;
  3932. switch (oper) {
  3933. case NL80211_TDLS_DISCOVERY_REQ:
  3934. ret = BRCMF_TDLS_MANUAL_EP_DISCOVERY;
  3935. break;
  3936. case NL80211_TDLS_SETUP:
  3937. ret = BRCMF_TDLS_MANUAL_EP_CREATE;
  3938. break;
  3939. case NL80211_TDLS_TEARDOWN:
  3940. ret = BRCMF_TDLS_MANUAL_EP_DELETE;
  3941. break;
  3942. default:
  3943. brcmf_err("unsupported operation: %d\n", oper);
  3944. ret = -EOPNOTSUPP;
  3945. }
  3946. return ret;
  3947. }
  3948. static int brcmf_cfg80211_tdls_oper(struct wiphy *wiphy,
  3949. struct net_device *ndev, const u8 *peer,
  3950. enum nl80211_tdls_operation oper)
  3951. {
  3952. struct brcmf_if *ifp;
  3953. struct brcmf_tdls_iovar_le info;
  3954. int ret = 0;
  3955. ret = brcmf_convert_nl80211_tdls_oper(oper);
  3956. if (ret < 0)
  3957. return ret;
  3958. ifp = netdev_priv(ndev);
  3959. memset(&info, 0, sizeof(info));
  3960. info.mode = (u8)ret;
  3961. if (peer)
  3962. memcpy(info.ea, peer, ETH_ALEN);
  3963. ret = brcmf_fil_iovar_data_set(ifp, "tdls_endpoint",
  3964. &info, sizeof(info));
  3965. if (ret < 0)
  3966. brcmf_err("tdls_endpoint iovar failed: ret=%d\n", ret);
  3967. return ret;
  3968. }
  3969. static struct cfg80211_ops wl_cfg80211_ops = {
  3970. .add_virtual_intf = brcmf_cfg80211_add_iface,
  3971. .del_virtual_intf = brcmf_cfg80211_del_iface,
  3972. .change_virtual_intf = brcmf_cfg80211_change_iface,
  3973. .scan = brcmf_cfg80211_scan,
  3974. .set_wiphy_params = brcmf_cfg80211_set_wiphy_params,
  3975. .join_ibss = brcmf_cfg80211_join_ibss,
  3976. .leave_ibss = brcmf_cfg80211_leave_ibss,
  3977. .get_station = brcmf_cfg80211_get_station,
  3978. .set_tx_power = brcmf_cfg80211_set_tx_power,
  3979. .get_tx_power = brcmf_cfg80211_get_tx_power,
  3980. .add_key = brcmf_cfg80211_add_key,
  3981. .del_key = brcmf_cfg80211_del_key,
  3982. .get_key = brcmf_cfg80211_get_key,
  3983. .set_default_key = brcmf_cfg80211_config_default_key,
  3984. .set_default_mgmt_key = brcmf_cfg80211_config_default_mgmt_key,
  3985. .set_power_mgmt = brcmf_cfg80211_set_power_mgmt,
  3986. .connect = brcmf_cfg80211_connect,
  3987. .disconnect = brcmf_cfg80211_disconnect,
  3988. .suspend = brcmf_cfg80211_suspend,
  3989. .resume = brcmf_cfg80211_resume,
  3990. .set_pmksa = brcmf_cfg80211_set_pmksa,
  3991. .del_pmksa = brcmf_cfg80211_del_pmksa,
  3992. .flush_pmksa = brcmf_cfg80211_flush_pmksa,
  3993. .start_ap = brcmf_cfg80211_start_ap,
  3994. .stop_ap = brcmf_cfg80211_stop_ap,
  3995. .change_beacon = brcmf_cfg80211_change_beacon,
  3996. .del_station = brcmf_cfg80211_del_station,
  3997. .change_station = brcmf_cfg80211_change_station,
  3998. .sched_scan_start = brcmf_cfg80211_sched_scan_start,
  3999. .sched_scan_stop = brcmf_cfg80211_sched_scan_stop,
  4000. .mgmt_frame_register = brcmf_cfg80211_mgmt_frame_register,
  4001. .mgmt_tx = brcmf_cfg80211_mgmt_tx,
  4002. .remain_on_channel = brcmf_p2p_remain_on_channel,
  4003. .cancel_remain_on_channel = brcmf_cfg80211_cancel_remain_on_channel,
  4004. .start_p2p_device = brcmf_p2p_start_device,
  4005. .stop_p2p_device = brcmf_p2p_stop_device,
  4006. .crit_proto_start = brcmf_cfg80211_crit_proto_start,
  4007. .crit_proto_stop = brcmf_cfg80211_crit_proto_stop,
  4008. .tdls_oper = brcmf_cfg80211_tdls_oper,
  4009. };
  4010. struct brcmf_cfg80211_vif *brcmf_alloc_vif(struct brcmf_cfg80211_info *cfg,
  4011. enum nl80211_iftype type,
  4012. bool pm_block)
  4013. {
  4014. struct brcmf_cfg80211_vif *vif_walk;
  4015. struct brcmf_cfg80211_vif *vif;
  4016. bool mbss;
  4017. brcmf_dbg(TRACE, "allocating virtual interface (size=%zu)\n",
  4018. sizeof(*vif));
  4019. vif = kzalloc(sizeof(*vif), GFP_KERNEL);
  4020. if (!vif)
  4021. return ERR_PTR(-ENOMEM);
  4022. vif->wdev.wiphy = cfg->wiphy;
  4023. vif->wdev.iftype = type;
  4024. vif->pm_block = pm_block;
  4025. vif->roam_off = -1;
  4026. brcmf_init_prof(&vif->profile);
  4027. if (type == NL80211_IFTYPE_AP) {
  4028. mbss = false;
  4029. list_for_each_entry(vif_walk, &cfg->vif_list, list) {
  4030. if (vif_walk->wdev.iftype == NL80211_IFTYPE_AP) {
  4031. mbss = true;
  4032. break;
  4033. }
  4034. }
  4035. vif->mbss = mbss;
  4036. }
  4037. list_add_tail(&vif->list, &cfg->vif_list);
  4038. return vif;
  4039. }
  4040. void brcmf_free_vif(struct brcmf_cfg80211_vif *vif)
  4041. {
  4042. list_del(&vif->list);
  4043. kfree(vif);
  4044. }
  4045. void brcmf_cfg80211_free_netdev(struct net_device *ndev)
  4046. {
  4047. struct brcmf_cfg80211_vif *vif;
  4048. struct brcmf_if *ifp;
  4049. ifp = netdev_priv(ndev);
  4050. vif = ifp->vif;
  4051. brcmf_free_vif(vif);
  4052. free_netdev(ndev);
  4053. }
  4054. static bool brcmf_is_linkup(const struct brcmf_event_msg *e)
  4055. {
  4056. u32 event = e->event_code;
  4057. u32 status = e->status;
  4058. if (event == BRCMF_E_SET_SSID && status == BRCMF_E_STATUS_SUCCESS) {
  4059. brcmf_dbg(CONN, "Processing set ssid\n");
  4060. return true;
  4061. }
  4062. return false;
  4063. }
  4064. static bool brcmf_is_linkdown(const struct brcmf_event_msg *e)
  4065. {
  4066. u32 event = e->event_code;
  4067. u16 flags = e->flags;
  4068. if ((event == BRCMF_E_DEAUTH) || (event == BRCMF_E_DEAUTH_IND) ||
  4069. (event == BRCMF_E_DISASSOC_IND) ||
  4070. ((event == BRCMF_E_LINK) && (!(flags & BRCMF_EVENT_MSG_LINK)))) {
  4071. brcmf_dbg(CONN, "Processing link down\n");
  4072. return true;
  4073. }
  4074. return false;
  4075. }
  4076. static bool brcmf_is_nonetwork(struct brcmf_cfg80211_info *cfg,
  4077. const struct brcmf_event_msg *e)
  4078. {
  4079. u32 event = e->event_code;
  4080. u32 status = e->status;
  4081. if (event == BRCMF_E_LINK && status == BRCMF_E_STATUS_NO_NETWORKS) {
  4082. brcmf_dbg(CONN, "Processing Link %s & no network found\n",
  4083. e->flags & BRCMF_EVENT_MSG_LINK ? "up" : "down");
  4084. return true;
  4085. }
  4086. if (event == BRCMF_E_SET_SSID && status != BRCMF_E_STATUS_SUCCESS) {
  4087. brcmf_dbg(CONN, "Processing connecting & no network found\n");
  4088. return true;
  4089. }
  4090. return false;
  4091. }
  4092. static void brcmf_clear_assoc_ies(struct brcmf_cfg80211_info *cfg)
  4093. {
  4094. struct brcmf_cfg80211_connect_info *conn_info = cfg_to_conn(cfg);
  4095. kfree(conn_info->req_ie);
  4096. conn_info->req_ie = NULL;
  4097. conn_info->req_ie_len = 0;
  4098. kfree(conn_info->resp_ie);
  4099. conn_info->resp_ie = NULL;
  4100. conn_info->resp_ie_len = 0;
  4101. }
  4102. static s32 brcmf_get_assoc_ies(struct brcmf_cfg80211_info *cfg,
  4103. struct brcmf_if *ifp)
  4104. {
  4105. struct brcmf_cfg80211_assoc_ielen_le *assoc_info;
  4106. struct brcmf_cfg80211_connect_info *conn_info = cfg_to_conn(cfg);
  4107. u32 req_len;
  4108. u32 resp_len;
  4109. s32 err = 0;
  4110. brcmf_clear_assoc_ies(cfg);
  4111. err = brcmf_fil_iovar_data_get(ifp, "assoc_info",
  4112. cfg->extra_buf, WL_ASSOC_INFO_MAX);
  4113. if (err) {
  4114. brcmf_err("could not get assoc info (%d)\n", err);
  4115. return err;
  4116. }
  4117. assoc_info =
  4118. (struct brcmf_cfg80211_assoc_ielen_le *)cfg->extra_buf;
  4119. req_len = le32_to_cpu(assoc_info->req_len);
  4120. resp_len = le32_to_cpu(assoc_info->resp_len);
  4121. if (req_len) {
  4122. err = brcmf_fil_iovar_data_get(ifp, "assoc_req_ies",
  4123. cfg->extra_buf,
  4124. WL_ASSOC_INFO_MAX);
  4125. if (err) {
  4126. brcmf_err("could not get assoc req (%d)\n", err);
  4127. return err;
  4128. }
  4129. conn_info->req_ie_len = req_len;
  4130. conn_info->req_ie =
  4131. kmemdup(cfg->extra_buf, conn_info->req_ie_len,
  4132. GFP_KERNEL);
  4133. } else {
  4134. conn_info->req_ie_len = 0;
  4135. conn_info->req_ie = NULL;
  4136. }
  4137. if (resp_len) {
  4138. err = brcmf_fil_iovar_data_get(ifp, "assoc_resp_ies",
  4139. cfg->extra_buf,
  4140. WL_ASSOC_INFO_MAX);
  4141. if (err) {
  4142. brcmf_err("could not get assoc resp (%d)\n", err);
  4143. return err;
  4144. }
  4145. conn_info->resp_ie_len = resp_len;
  4146. conn_info->resp_ie =
  4147. kmemdup(cfg->extra_buf, conn_info->resp_ie_len,
  4148. GFP_KERNEL);
  4149. } else {
  4150. conn_info->resp_ie_len = 0;
  4151. conn_info->resp_ie = NULL;
  4152. }
  4153. brcmf_dbg(CONN, "req len (%d) resp len (%d)\n",
  4154. conn_info->req_ie_len, conn_info->resp_ie_len);
  4155. return err;
  4156. }
  4157. static s32
  4158. brcmf_bss_roaming_done(struct brcmf_cfg80211_info *cfg,
  4159. struct net_device *ndev,
  4160. const struct brcmf_event_msg *e)
  4161. {
  4162. struct brcmf_if *ifp = netdev_priv(ndev);
  4163. struct brcmf_cfg80211_profile *profile = &ifp->vif->profile;
  4164. struct brcmf_cfg80211_connect_info *conn_info = cfg_to_conn(cfg);
  4165. struct wiphy *wiphy = cfg_to_wiphy(cfg);
  4166. struct ieee80211_channel *notify_channel = NULL;
  4167. struct ieee80211_supported_band *band;
  4168. struct brcmf_bss_info_le *bi;
  4169. struct brcmu_chan ch;
  4170. u32 freq;
  4171. s32 err = 0;
  4172. u8 *buf;
  4173. brcmf_dbg(TRACE, "Enter\n");
  4174. brcmf_get_assoc_ies(cfg, ifp);
  4175. memcpy(profile->bssid, e->addr, ETH_ALEN);
  4176. brcmf_update_bss_info(cfg, ifp);
  4177. buf = kzalloc(WL_BSS_INFO_MAX, GFP_KERNEL);
  4178. if (buf == NULL) {
  4179. err = -ENOMEM;
  4180. goto done;
  4181. }
  4182. /* data sent to dongle has to be little endian */
  4183. *(__le32 *)buf = cpu_to_le32(WL_BSS_INFO_MAX);
  4184. err = brcmf_fil_cmd_data_get(ifp, BRCMF_C_GET_BSS_INFO,
  4185. buf, WL_BSS_INFO_MAX);
  4186. if (err)
  4187. goto done;
  4188. bi = (struct brcmf_bss_info_le *)(buf + 4);
  4189. ch.chspec = le16_to_cpu(bi->chanspec);
  4190. cfg->d11inf.decchspec(&ch);
  4191. if (ch.band == BRCMU_CHAN_BAND_2G)
  4192. band = wiphy->bands[IEEE80211_BAND_2GHZ];
  4193. else
  4194. band = wiphy->bands[IEEE80211_BAND_5GHZ];
  4195. freq = ieee80211_channel_to_frequency(ch.chnum, band->band);
  4196. notify_channel = ieee80211_get_channel(wiphy, freq);
  4197. done:
  4198. kfree(buf);
  4199. cfg80211_roamed(ndev, notify_channel, (u8 *)profile->bssid,
  4200. conn_info->req_ie, conn_info->req_ie_len,
  4201. conn_info->resp_ie, conn_info->resp_ie_len, GFP_KERNEL);
  4202. brcmf_dbg(CONN, "Report roaming result\n");
  4203. set_bit(BRCMF_VIF_STATUS_CONNECTED, &ifp->vif->sme_state);
  4204. brcmf_dbg(TRACE, "Exit\n");
  4205. return err;
  4206. }
  4207. static s32
  4208. brcmf_bss_connect_done(struct brcmf_cfg80211_info *cfg,
  4209. struct net_device *ndev, const struct brcmf_event_msg *e,
  4210. bool completed)
  4211. {
  4212. struct brcmf_if *ifp = netdev_priv(ndev);
  4213. struct brcmf_cfg80211_profile *profile = &ifp->vif->profile;
  4214. struct brcmf_cfg80211_connect_info *conn_info = cfg_to_conn(cfg);
  4215. brcmf_dbg(TRACE, "Enter\n");
  4216. if (test_and_clear_bit(BRCMF_VIF_STATUS_CONNECTING,
  4217. &ifp->vif->sme_state)) {
  4218. if (completed) {
  4219. brcmf_get_assoc_ies(cfg, ifp);
  4220. memcpy(profile->bssid, e->addr, ETH_ALEN);
  4221. brcmf_update_bss_info(cfg, ifp);
  4222. set_bit(BRCMF_VIF_STATUS_CONNECTED,
  4223. &ifp->vif->sme_state);
  4224. }
  4225. cfg80211_connect_result(ndev,
  4226. (u8 *)profile->bssid,
  4227. conn_info->req_ie,
  4228. conn_info->req_ie_len,
  4229. conn_info->resp_ie,
  4230. conn_info->resp_ie_len,
  4231. completed ? WLAN_STATUS_SUCCESS :
  4232. WLAN_STATUS_AUTH_TIMEOUT,
  4233. GFP_KERNEL);
  4234. brcmf_dbg(CONN, "Report connect result - connection %s\n",
  4235. completed ? "succeeded" : "failed");
  4236. }
  4237. brcmf_dbg(TRACE, "Exit\n");
  4238. return 0;
  4239. }
  4240. static s32
  4241. brcmf_notify_connect_status_ap(struct brcmf_cfg80211_info *cfg,
  4242. struct net_device *ndev,
  4243. const struct brcmf_event_msg *e, void *data)
  4244. {
  4245. struct brcmf_if *ifp = netdev_priv(ndev);
  4246. static int generation;
  4247. u32 event = e->event_code;
  4248. u32 reason = e->reason;
  4249. struct station_info sinfo;
  4250. brcmf_dbg(CONN, "event %d, reason %d\n", event, reason);
  4251. if (event == BRCMF_E_LINK && reason == BRCMF_E_REASON_LINK_BSSCFG_DIS &&
  4252. ndev != cfg_to_ndev(cfg)) {
  4253. brcmf_dbg(CONN, "AP mode link down\n");
  4254. complete(&cfg->vif_disabled);
  4255. if (ifp->vif->mbss)
  4256. brcmf_remove_interface(ifp->drvr, ifp->bssidx);
  4257. return 0;
  4258. }
  4259. if (((event == BRCMF_E_ASSOC_IND) || (event == BRCMF_E_REASSOC_IND)) &&
  4260. (reason == BRCMF_E_STATUS_SUCCESS)) {
  4261. memset(&sinfo, 0, sizeof(sinfo));
  4262. if (!data) {
  4263. brcmf_err("No IEs present in ASSOC/REASSOC_IND");
  4264. return -EINVAL;
  4265. }
  4266. sinfo.assoc_req_ies = data;
  4267. sinfo.assoc_req_ies_len = e->datalen;
  4268. generation++;
  4269. sinfo.generation = generation;
  4270. cfg80211_new_sta(ndev, e->addr, &sinfo, GFP_KERNEL);
  4271. } else if ((event == BRCMF_E_DISASSOC_IND) ||
  4272. (event == BRCMF_E_DEAUTH_IND) ||
  4273. (event == BRCMF_E_DEAUTH)) {
  4274. cfg80211_del_sta(ndev, e->addr, GFP_KERNEL);
  4275. }
  4276. return 0;
  4277. }
  4278. static s32
  4279. brcmf_notify_connect_status(struct brcmf_if *ifp,
  4280. const struct brcmf_event_msg *e, void *data)
  4281. {
  4282. struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
  4283. struct net_device *ndev = ifp->ndev;
  4284. struct brcmf_cfg80211_profile *profile = &ifp->vif->profile;
  4285. struct ieee80211_channel *chan;
  4286. s32 err = 0;
  4287. if ((e->event_code == BRCMF_E_DEAUTH) ||
  4288. (e->event_code == BRCMF_E_DEAUTH_IND) ||
  4289. (e->event_code == BRCMF_E_DISASSOC_IND) ||
  4290. ((e->event_code == BRCMF_E_LINK) && (!e->flags))) {
  4291. brcmf_proto_delete_peer(ifp->drvr, ifp->ifidx, (u8 *)e->addr);
  4292. }
  4293. if (brcmf_is_apmode(ifp->vif)) {
  4294. err = brcmf_notify_connect_status_ap(cfg, ndev, e, data);
  4295. } else if (brcmf_is_linkup(e)) {
  4296. brcmf_dbg(CONN, "Linkup\n");
  4297. if (brcmf_is_ibssmode(ifp->vif)) {
  4298. chan = ieee80211_get_channel(cfg->wiphy, cfg->channel);
  4299. memcpy(profile->bssid, e->addr, ETH_ALEN);
  4300. wl_inform_ibss(cfg, ndev, e->addr);
  4301. cfg80211_ibss_joined(ndev, e->addr, chan, GFP_KERNEL);
  4302. clear_bit(BRCMF_VIF_STATUS_CONNECTING,
  4303. &ifp->vif->sme_state);
  4304. set_bit(BRCMF_VIF_STATUS_CONNECTED,
  4305. &ifp->vif->sme_state);
  4306. } else
  4307. brcmf_bss_connect_done(cfg, ndev, e, true);
  4308. } else if (brcmf_is_linkdown(e)) {
  4309. brcmf_dbg(CONN, "Linkdown\n");
  4310. if (!brcmf_is_ibssmode(ifp->vif)) {
  4311. brcmf_bss_connect_done(cfg, ndev, e, false);
  4312. }
  4313. brcmf_link_down(ifp->vif, brcmf_map_fw_linkdown_reason(e));
  4314. brcmf_init_prof(ndev_to_prof(ndev));
  4315. if (ndev != cfg_to_ndev(cfg))
  4316. complete(&cfg->vif_disabled);
  4317. } else if (brcmf_is_nonetwork(cfg, e)) {
  4318. if (brcmf_is_ibssmode(ifp->vif))
  4319. clear_bit(BRCMF_VIF_STATUS_CONNECTING,
  4320. &ifp->vif->sme_state);
  4321. else
  4322. brcmf_bss_connect_done(cfg, ndev, e, false);
  4323. }
  4324. return err;
  4325. }
  4326. static s32
  4327. brcmf_notify_roaming_status(struct brcmf_if *ifp,
  4328. const struct brcmf_event_msg *e, void *data)
  4329. {
  4330. struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
  4331. u32 event = e->event_code;
  4332. u32 status = e->status;
  4333. if (event == BRCMF_E_ROAM && status == BRCMF_E_STATUS_SUCCESS) {
  4334. if (test_bit(BRCMF_VIF_STATUS_CONNECTED, &ifp->vif->sme_state))
  4335. brcmf_bss_roaming_done(cfg, ifp->ndev, e);
  4336. else
  4337. brcmf_bss_connect_done(cfg, ifp->ndev, e, true);
  4338. }
  4339. return 0;
  4340. }
  4341. static s32
  4342. brcmf_notify_mic_status(struct brcmf_if *ifp,
  4343. const struct brcmf_event_msg *e, void *data)
  4344. {
  4345. u16 flags = e->flags;
  4346. enum nl80211_key_type key_type;
  4347. if (flags & BRCMF_EVENT_MSG_GROUP)
  4348. key_type = NL80211_KEYTYPE_GROUP;
  4349. else
  4350. key_type = NL80211_KEYTYPE_PAIRWISE;
  4351. cfg80211_michael_mic_failure(ifp->ndev, (u8 *)&e->addr, key_type, -1,
  4352. NULL, GFP_KERNEL);
  4353. return 0;
  4354. }
  4355. static s32 brcmf_notify_vif_event(struct brcmf_if *ifp,
  4356. const struct brcmf_event_msg *e, void *data)
  4357. {
  4358. struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
  4359. struct brcmf_if_event *ifevent = (struct brcmf_if_event *)data;
  4360. struct brcmf_cfg80211_vif_event *event = &cfg->vif_event;
  4361. struct brcmf_cfg80211_vif *vif;
  4362. brcmf_dbg(TRACE, "Enter: action %u flags %u ifidx %u bsscfg %u\n",
  4363. ifevent->action, ifevent->flags, ifevent->ifidx,
  4364. ifevent->bssidx);
  4365. mutex_lock(&event->vif_event_lock);
  4366. event->action = ifevent->action;
  4367. vif = event->vif;
  4368. switch (ifevent->action) {
  4369. case BRCMF_E_IF_ADD:
  4370. /* waiting process may have timed out */
  4371. if (!cfg->vif_event.vif) {
  4372. mutex_unlock(&event->vif_event_lock);
  4373. return -EBADF;
  4374. }
  4375. ifp->vif = vif;
  4376. vif->ifp = ifp;
  4377. if (ifp->ndev) {
  4378. vif->wdev.netdev = ifp->ndev;
  4379. ifp->ndev->ieee80211_ptr = &vif->wdev;
  4380. SET_NETDEV_DEV(ifp->ndev, wiphy_dev(cfg->wiphy));
  4381. }
  4382. mutex_unlock(&event->vif_event_lock);
  4383. wake_up(&event->vif_wq);
  4384. return 0;
  4385. case BRCMF_E_IF_DEL:
  4386. mutex_unlock(&event->vif_event_lock);
  4387. /* event may not be upon user request */
  4388. if (brcmf_cfg80211_vif_event_armed(cfg))
  4389. wake_up(&event->vif_wq);
  4390. return 0;
  4391. case BRCMF_E_IF_CHANGE:
  4392. mutex_unlock(&event->vif_event_lock);
  4393. wake_up(&event->vif_wq);
  4394. return 0;
  4395. default:
  4396. mutex_unlock(&event->vif_event_lock);
  4397. break;
  4398. }
  4399. return -EINVAL;
  4400. }
  4401. static void brcmf_init_conf(struct brcmf_cfg80211_conf *conf)
  4402. {
  4403. conf->frag_threshold = (u32)-1;
  4404. conf->rts_threshold = (u32)-1;
  4405. conf->retry_short = (u32)-1;
  4406. conf->retry_long = (u32)-1;
  4407. conf->tx_power = -1;
  4408. }
  4409. static void brcmf_register_event_handlers(struct brcmf_cfg80211_info *cfg)
  4410. {
  4411. brcmf_fweh_register(cfg->pub, BRCMF_E_LINK,
  4412. brcmf_notify_connect_status);
  4413. brcmf_fweh_register(cfg->pub, BRCMF_E_DEAUTH_IND,
  4414. brcmf_notify_connect_status);
  4415. brcmf_fweh_register(cfg->pub, BRCMF_E_DEAUTH,
  4416. brcmf_notify_connect_status);
  4417. brcmf_fweh_register(cfg->pub, BRCMF_E_DISASSOC_IND,
  4418. brcmf_notify_connect_status);
  4419. brcmf_fweh_register(cfg->pub, BRCMF_E_ASSOC_IND,
  4420. brcmf_notify_connect_status);
  4421. brcmf_fweh_register(cfg->pub, BRCMF_E_REASSOC_IND,
  4422. brcmf_notify_connect_status);
  4423. brcmf_fweh_register(cfg->pub, BRCMF_E_ROAM,
  4424. brcmf_notify_roaming_status);
  4425. brcmf_fweh_register(cfg->pub, BRCMF_E_MIC_ERROR,
  4426. brcmf_notify_mic_status);
  4427. brcmf_fweh_register(cfg->pub, BRCMF_E_SET_SSID,
  4428. brcmf_notify_connect_status);
  4429. brcmf_fweh_register(cfg->pub, BRCMF_E_PFN_NET_FOUND,
  4430. brcmf_notify_sched_scan_results);
  4431. brcmf_fweh_register(cfg->pub, BRCMF_E_IF,
  4432. brcmf_notify_vif_event);
  4433. brcmf_fweh_register(cfg->pub, BRCMF_E_P2P_PROBEREQ_MSG,
  4434. brcmf_p2p_notify_rx_mgmt_p2p_probereq);
  4435. brcmf_fweh_register(cfg->pub, BRCMF_E_P2P_DISC_LISTEN_COMPLETE,
  4436. brcmf_p2p_notify_listen_complete);
  4437. brcmf_fweh_register(cfg->pub, BRCMF_E_ACTION_FRAME_RX,
  4438. brcmf_p2p_notify_action_frame_rx);
  4439. brcmf_fweh_register(cfg->pub, BRCMF_E_ACTION_FRAME_COMPLETE,
  4440. brcmf_p2p_notify_action_tx_complete);
  4441. brcmf_fweh_register(cfg->pub, BRCMF_E_ACTION_FRAME_OFF_CHAN_COMPLETE,
  4442. brcmf_p2p_notify_action_tx_complete);
  4443. }
  4444. static void brcmf_deinit_priv_mem(struct brcmf_cfg80211_info *cfg)
  4445. {
  4446. kfree(cfg->conf);
  4447. cfg->conf = NULL;
  4448. kfree(cfg->escan_ioctl_buf);
  4449. cfg->escan_ioctl_buf = NULL;
  4450. kfree(cfg->extra_buf);
  4451. cfg->extra_buf = NULL;
  4452. kfree(cfg->pmk_list);
  4453. cfg->pmk_list = NULL;
  4454. }
  4455. static s32 brcmf_init_priv_mem(struct brcmf_cfg80211_info *cfg)
  4456. {
  4457. cfg->conf = kzalloc(sizeof(*cfg->conf), GFP_KERNEL);
  4458. if (!cfg->conf)
  4459. goto init_priv_mem_out;
  4460. cfg->escan_ioctl_buf = kzalloc(BRCMF_DCMD_MEDLEN, GFP_KERNEL);
  4461. if (!cfg->escan_ioctl_buf)
  4462. goto init_priv_mem_out;
  4463. cfg->extra_buf = kzalloc(WL_EXTRA_BUF_MAX, GFP_KERNEL);
  4464. if (!cfg->extra_buf)
  4465. goto init_priv_mem_out;
  4466. cfg->pmk_list = kzalloc(sizeof(*cfg->pmk_list), GFP_KERNEL);
  4467. if (!cfg->pmk_list)
  4468. goto init_priv_mem_out;
  4469. return 0;
  4470. init_priv_mem_out:
  4471. brcmf_deinit_priv_mem(cfg);
  4472. return -ENOMEM;
  4473. }
  4474. static s32 wl_init_priv(struct brcmf_cfg80211_info *cfg)
  4475. {
  4476. s32 err = 0;
  4477. cfg->scan_request = NULL;
  4478. cfg->pwr_save = true;
  4479. cfg->active_scan = true; /* we do active scan per default */
  4480. cfg->dongle_up = false; /* dongle is not up yet */
  4481. err = brcmf_init_priv_mem(cfg);
  4482. if (err)
  4483. return err;
  4484. brcmf_register_event_handlers(cfg);
  4485. mutex_init(&cfg->usr_sync);
  4486. brcmf_init_escan(cfg);
  4487. brcmf_init_conf(cfg->conf);
  4488. init_completion(&cfg->vif_disabled);
  4489. return err;
  4490. }
  4491. static void wl_deinit_priv(struct brcmf_cfg80211_info *cfg)
  4492. {
  4493. cfg->dongle_up = false; /* dongle down */
  4494. brcmf_abort_scanning(cfg);
  4495. brcmf_deinit_priv_mem(cfg);
  4496. }
  4497. static void init_vif_event(struct brcmf_cfg80211_vif_event *event)
  4498. {
  4499. init_waitqueue_head(&event->vif_wq);
  4500. mutex_init(&event->vif_event_lock);
  4501. }
  4502. static s32
  4503. brcmf_dongle_roam(struct brcmf_if *ifp, u32 bcn_timeout)
  4504. {
  4505. s32 err = 0;
  4506. __le32 roamtrigger[2];
  4507. __le32 roam_delta[2];
  4508. /*
  4509. * Setup timeout if Beacons are lost and roam is
  4510. * off to report link down
  4511. */
  4512. if (brcmf_roamoff) {
  4513. err = brcmf_fil_iovar_int_set(ifp, "bcn_timeout", bcn_timeout);
  4514. if (err) {
  4515. brcmf_err("bcn_timeout error (%d)\n", err);
  4516. goto dongle_rom_out;
  4517. }
  4518. }
  4519. /*
  4520. * Enable/Disable built-in roaming to allow supplicant
  4521. * to take care of roaming
  4522. */
  4523. brcmf_dbg(INFO, "Internal Roaming = %s\n",
  4524. brcmf_roamoff ? "Off" : "On");
  4525. err = brcmf_fil_iovar_int_set(ifp, "roam_off", !!(brcmf_roamoff));
  4526. if (err) {
  4527. brcmf_err("roam_off error (%d)\n", err);
  4528. goto dongle_rom_out;
  4529. }
  4530. roamtrigger[0] = cpu_to_le32(WL_ROAM_TRIGGER_LEVEL);
  4531. roamtrigger[1] = cpu_to_le32(BRCM_BAND_ALL);
  4532. err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_ROAM_TRIGGER,
  4533. (void *)roamtrigger, sizeof(roamtrigger));
  4534. if (err) {
  4535. brcmf_err("WLC_SET_ROAM_TRIGGER error (%d)\n", err);
  4536. goto dongle_rom_out;
  4537. }
  4538. roam_delta[0] = cpu_to_le32(WL_ROAM_DELTA);
  4539. roam_delta[1] = cpu_to_le32(BRCM_BAND_ALL);
  4540. err = brcmf_fil_cmd_data_set(ifp, BRCMF_C_SET_ROAM_DELTA,
  4541. (void *)roam_delta, sizeof(roam_delta));
  4542. if (err) {
  4543. brcmf_err("WLC_SET_ROAM_DELTA error (%d)\n", err);
  4544. goto dongle_rom_out;
  4545. }
  4546. dongle_rom_out:
  4547. return err;
  4548. }
  4549. static s32
  4550. brcmf_dongle_scantime(struct brcmf_if *ifp, s32 scan_assoc_time,
  4551. s32 scan_unassoc_time, s32 scan_passive_time)
  4552. {
  4553. s32 err = 0;
  4554. err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_SCAN_CHANNEL_TIME,
  4555. scan_assoc_time);
  4556. if (err) {
  4557. if (err == -EOPNOTSUPP)
  4558. brcmf_dbg(INFO, "Scan assoc time is not supported\n");
  4559. else
  4560. brcmf_err("Scan assoc time error (%d)\n", err);
  4561. goto dongle_scantime_out;
  4562. }
  4563. err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_SCAN_UNASSOC_TIME,
  4564. scan_unassoc_time);
  4565. if (err) {
  4566. if (err == -EOPNOTSUPP)
  4567. brcmf_dbg(INFO, "Scan unassoc time is not supported\n");
  4568. else
  4569. brcmf_err("Scan unassoc time error (%d)\n", err);
  4570. goto dongle_scantime_out;
  4571. }
  4572. err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_SCAN_PASSIVE_TIME,
  4573. scan_passive_time);
  4574. if (err) {
  4575. if (err == -EOPNOTSUPP)
  4576. brcmf_dbg(INFO, "Scan passive time is not supported\n");
  4577. else
  4578. brcmf_err("Scan passive time error (%d)\n", err);
  4579. goto dongle_scantime_out;
  4580. }
  4581. dongle_scantime_out:
  4582. return err;
  4583. }
  4584. /* Filter the list of channels received from firmware counting only
  4585. * the 20MHz channels. The wiphy band data only needs those which get
  4586. * flagged to indicate if they can take part in higher bandwidth.
  4587. */
  4588. static void brcmf_count_20mhz_channels(struct brcmf_cfg80211_info *cfg,
  4589. struct brcmf_chanspec_list *chlist,
  4590. u32 chcnt[])
  4591. {
  4592. u32 total = le32_to_cpu(chlist->count);
  4593. struct brcmu_chan ch;
  4594. int i;
  4595. for (i = 0; i < total; i++) {
  4596. ch.chspec = (u16)le32_to_cpu(chlist->element[i]);
  4597. cfg->d11inf.decchspec(&ch);
  4598. /* Firmware gives a ordered list. We skip non-20MHz
  4599. * channels is 2G. For 5G we can abort upon reaching
  4600. * a non-20MHz channel in the list.
  4601. */
  4602. if (ch.bw != BRCMU_CHAN_BW_20) {
  4603. if (ch.band == BRCMU_CHAN_BAND_5G)
  4604. break;
  4605. else
  4606. continue;
  4607. }
  4608. if (ch.band == BRCMU_CHAN_BAND_2G)
  4609. chcnt[0] += 1;
  4610. else if (ch.band == BRCMU_CHAN_BAND_5G)
  4611. chcnt[1] += 1;
  4612. }
  4613. }
  4614. static void brcmf_update_bw40_channel_flag(struct ieee80211_channel *channel,
  4615. struct brcmu_chan *ch)
  4616. {
  4617. u32 ht40_flag;
  4618. ht40_flag = channel->flags & IEEE80211_CHAN_NO_HT40;
  4619. if (ch->sb == BRCMU_CHAN_SB_U) {
  4620. if (ht40_flag == IEEE80211_CHAN_NO_HT40)
  4621. channel->flags &= ~IEEE80211_CHAN_NO_HT40;
  4622. channel->flags |= IEEE80211_CHAN_NO_HT40PLUS;
  4623. } else {
  4624. /* It should be one of
  4625. * IEEE80211_CHAN_NO_HT40 or
  4626. * IEEE80211_CHAN_NO_HT40PLUS
  4627. */
  4628. channel->flags &= ~IEEE80211_CHAN_NO_HT40;
  4629. if (ht40_flag == IEEE80211_CHAN_NO_HT40)
  4630. channel->flags |= IEEE80211_CHAN_NO_HT40MINUS;
  4631. }
  4632. }
  4633. static int brcmf_construct_chaninfo(struct brcmf_cfg80211_info *cfg,
  4634. u32 bw_cap[])
  4635. {
  4636. struct brcmf_if *ifp = netdev_priv(cfg_to_ndev(cfg));
  4637. struct ieee80211_supported_band *band;
  4638. struct ieee80211_channel *channel;
  4639. struct wiphy *wiphy;
  4640. struct brcmf_chanspec_list *list;
  4641. struct brcmu_chan ch;
  4642. int err;
  4643. u8 *pbuf;
  4644. u32 i, j;
  4645. u32 total;
  4646. u32 chaninfo;
  4647. u32 chcnt[2] = { 0, 0 };
  4648. u32 index;
  4649. pbuf = kzalloc(BRCMF_DCMD_MEDLEN, GFP_KERNEL);
  4650. if (pbuf == NULL)
  4651. return -ENOMEM;
  4652. list = (struct brcmf_chanspec_list *)pbuf;
  4653. err = brcmf_fil_iovar_data_get(ifp, "chanspecs", pbuf,
  4654. BRCMF_DCMD_MEDLEN);
  4655. if (err) {
  4656. brcmf_err("get chanspecs error (%d)\n", err);
  4657. goto fail_pbuf;
  4658. }
  4659. brcmf_count_20mhz_channels(cfg, list, chcnt);
  4660. wiphy = cfg_to_wiphy(cfg);
  4661. if (chcnt[0]) {
  4662. band = kmemdup(&__wl_band_2ghz, sizeof(__wl_band_2ghz),
  4663. GFP_KERNEL);
  4664. if (band == NULL) {
  4665. err = -ENOMEM;
  4666. goto fail_pbuf;
  4667. }
  4668. band->channels = kcalloc(chcnt[0], sizeof(*channel),
  4669. GFP_KERNEL);
  4670. if (band->channels == NULL) {
  4671. kfree(band);
  4672. err = -ENOMEM;
  4673. goto fail_pbuf;
  4674. }
  4675. band->n_channels = 0;
  4676. wiphy->bands[IEEE80211_BAND_2GHZ] = band;
  4677. }
  4678. if (chcnt[1]) {
  4679. band = kmemdup(&__wl_band_5ghz_a, sizeof(__wl_band_5ghz_a),
  4680. GFP_KERNEL);
  4681. if (band == NULL) {
  4682. err = -ENOMEM;
  4683. goto fail_band2g;
  4684. }
  4685. band->channels = kcalloc(chcnt[1], sizeof(*channel),
  4686. GFP_KERNEL);
  4687. if (band->channels == NULL) {
  4688. kfree(band);
  4689. err = -ENOMEM;
  4690. goto fail_band2g;
  4691. }
  4692. band->n_channels = 0;
  4693. wiphy->bands[IEEE80211_BAND_5GHZ] = band;
  4694. }
  4695. total = le32_to_cpu(list->count);
  4696. for (i = 0; i < total; i++) {
  4697. ch.chspec = (u16)le32_to_cpu(list->element[i]);
  4698. cfg->d11inf.decchspec(&ch);
  4699. if (ch.band == BRCMU_CHAN_BAND_2G) {
  4700. band = wiphy->bands[IEEE80211_BAND_2GHZ];
  4701. } else if (ch.band == BRCMU_CHAN_BAND_5G) {
  4702. band = wiphy->bands[IEEE80211_BAND_5GHZ];
  4703. } else {
  4704. brcmf_err("Invalid channel Spec. 0x%x.\n", ch.chspec);
  4705. continue;
  4706. }
  4707. if (!(bw_cap[band->band] & WLC_BW_40MHZ_BIT) &&
  4708. ch.bw == BRCMU_CHAN_BW_40)
  4709. continue;
  4710. if (!(bw_cap[band->band] & WLC_BW_80MHZ_BIT) &&
  4711. ch.bw == BRCMU_CHAN_BW_80)
  4712. continue;
  4713. channel = band->channels;
  4714. index = band->n_channels;
  4715. for (j = 0; j < band->n_channels; j++) {
  4716. if (channel[j].hw_value == ch.chnum) {
  4717. index = j;
  4718. break;
  4719. }
  4720. }
  4721. channel[index].center_freq =
  4722. ieee80211_channel_to_frequency(ch.chnum, band->band);
  4723. channel[index].hw_value = ch.chnum;
  4724. /* assuming the chanspecs order is HT20,
  4725. * HT40 upper, HT40 lower, and VHT80.
  4726. */
  4727. if (ch.bw == BRCMU_CHAN_BW_80) {
  4728. channel[index].flags &= ~IEEE80211_CHAN_NO_80MHZ;
  4729. } else if (ch.bw == BRCMU_CHAN_BW_40) {
  4730. brcmf_update_bw40_channel_flag(&channel[index], &ch);
  4731. } else {
  4732. /* disable other bandwidths for now as mentioned
  4733. * order assure they are enabled for subsequent
  4734. * chanspecs.
  4735. */
  4736. channel[index].flags = IEEE80211_CHAN_NO_HT40 |
  4737. IEEE80211_CHAN_NO_80MHZ;
  4738. ch.bw = BRCMU_CHAN_BW_20;
  4739. cfg->d11inf.encchspec(&ch);
  4740. chaninfo = ch.chspec;
  4741. err = brcmf_fil_bsscfg_int_get(ifp, "per_chan_info",
  4742. &chaninfo);
  4743. if (!err) {
  4744. if (chaninfo & WL_CHAN_RADAR)
  4745. channel[index].flags |=
  4746. (IEEE80211_CHAN_RADAR |
  4747. IEEE80211_CHAN_NO_IR);
  4748. if (chaninfo & WL_CHAN_PASSIVE)
  4749. channel[index].flags |=
  4750. IEEE80211_CHAN_NO_IR;
  4751. }
  4752. }
  4753. if (index == band->n_channels)
  4754. band->n_channels++;
  4755. }
  4756. kfree(pbuf);
  4757. return 0;
  4758. fail_band2g:
  4759. kfree(wiphy->bands[IEEE80211_BAND_2GHZ]->channels);
  4760. kfree(wiphy->bands[IEEE80211_BAND_2GHZ]);
  4761. wiphy->bands[IEEE80211_BAND_2GHZ] = NULL;
  4762. fail_pbuf:
  4763. kfree(pbuf);
  4764. return err;
  4765. }
  4766. static int brcmf_enable_bw40_2g(struct brcmf_cfg80211_info *cfg)
  4767. {
  4768. struct brcmf_if *ifp = netdev_priv(cfg_to_ndev(cfg));
  4769. struct ieee80211_supported_band *band;
  4770. struct brcmf_fil_bwcap_le band_bwcap;
  4771. struct brcmf_chanspec_list *list;
  4772. u8 *pbuf;
  4773. u32 val;
  4774. int err;
  4775. struct brcmu_chan ch;
  4776. u32 num_chan;
  4777. int i, j;
  4778. /* verify support for bw_cap command */
  4779. val = WLC_BAND_5G;
  4780. err = brcmf_fil_iovar_int_get(ifp, "bw_cap", &val);
  4781. if (!err) {
  4782. /* only set 2G bandwidth using bw_cap command */
  4783. band_bwcap.band = cpu_to_le32(WLC_BAND_2G);
  4784. band_bwcap.bw_cap = cpu_to_le32(WLC_BW_CAP_40MHZ);
  4785. err = brcmf_fil_iovar_data_set(ifp, "bw_cap", &band_bwcap,
  4786. sizeof(band_bwcap));
  4787. } else {
  4788. brcmf_dbg(INFO, "fallback to mimo_bw_cap\n");
  4789. val = WLC_N_BW_40ALL;
  4790. err = brcmf_fil_iovar_int_set(ifp, "mimo_bw_cap", val);
  4791. }
  4792. if (!err) {
  4793. /* update channel info in 2G band */
  4794. pbuf = kzalloc(BRCMF_DCMD_MEDLEN, GFP_KERNEL);
  4795. if (pbuf == NULL)
  4796. return -ENOMEM;
  4797. ch.band = BRCMU_CHAN_BAND_2G;
  4798. ch.bw = BRCMU_CHAN_BW_40;
  4799. ch.sb = BRCMU_CHAN_SB_NONE;
  4800. ch.chnum = 0;
  4801. cfg->d11inf.encchspec(&ch);
  4802. /* pass encoded chanspec in query */
  4803. *(__le16 *)pbuf = cpu_to_le16(ch.chspec);
  4804. err = brcmf_fil_iovar_data_get(ifp, "chanspecs", pbuf,
  4805. BRCMF_DCMD_MEDLEN);
  4806. if (err) {
  4807. brcmf_err("get chanspecs error (%d)\n", err);
  4808. kfree(pbuf);
  4809. return err;
  4810. }
  4811. band = cfg_to_wiphy(cfg)->bands[IEEE80211_BAND_2GHZ];
  4812. list = (struct brcmf_chanspec_list *)pbuf;
  4813. num_chan = le32_to_cpu(list->count);
  4814. for (i = 0; i < num_chan; i++) {
  4815. ch.chspec = (u16)le32_to_cpu(list->element[i]);
  4816. cfg->d11inf.decchspec(&ch);
  4817. if (WARN_ON(ch.band != BRCMU_CHAN_BAND_2G))
  4818. continue;
  4819. if (WARN_ON(ch.bw != BRCMU_CHAN_BW_40))
  4820. continue;
  4821. for (j = 0; j < band->n_channels; j++) {
  4822. if (band->channels[j].hw_value == ch.chnum)
  4823. break;
  4824. }
  4825. if (WARN_ON(j == band->n_channels))
  4826. continue;
  4827. brcmf_update_bw40_channel_flag(&band->channels[j], &ch);
  4828. }
  4829. kfree(pbuf);
  4830. }
  4831. return err;
  4832. }
  4833. static void brcmf_get_bwcap(struct brcmf_if *ifp, u32 bw_cap[])
  4834. {
  4835. u32 band, mimo_bwcap;
  4836. int err;
  4837. band = WLC_BAND_2G;
  4838. err = brcmf_fil_iovar_int_get(ifp, "bw_cap", &band);
  4839. if (!err) {
  4840. bw_cap[IEEE80211_BAND_2GHZ] = band;
  4841. band = WLC_BAND_5G;
  4842. err = brcmf_fil_iovar_int_get(ifp, "bw_cap", &band);
  4843. if (!err) {
  4844. bw_cap[IEEE80211_BAND_5GHZ] = band;
  4845. return;
  4846. }
  4847. WARN_ON(1);
  4848. return;
  4849. }
  4850. brcmf_dbg(INFO, "fallback to mimo_bw_cap info\n");
  4851. mimo_bwcap = 0;
  4852. err = brcmf_fil_iovar_int_get(ifp, "mimo_bw_cap", &mimo_bwcap);
  4853. if (err)
  4854. /* assume 20MHz if firmware does not give a clue */
  4855. mimo_bwcap = WLC_N_BW_20ALL;
  4856. switch (mimo_bwcap) {
  4857. case WLC_N_BW_40ALL:
  4858. bw_cap[IEEE80211_BAND_2GHZ] |= WLC_BW_40MHZ_BIT;
  4859. /* fall-thru */
  4860. case WLC_N_BW_20IN2G_40IN5G:
  4861. bw_cap[IEEE80211_BAND_5GHZ] |= WLC_BW_40MHZ_BIT;
  4862. /* fall-thru */
  4863. case WLC_N_BW_20ALL:
  4864. bw_cap[IEEE80211_BAND_2GHZ] |= WLC_BW_20MHZ_BIT;
  4865. bw_cap[IEEE80211_BAND_5GHZ] |= WLC_BW_20MHZ_BIT;
  4866. break;
  4867. default:
  4868. brcmf_err("invalid mimo_bw_cap value\n");
  4869. }
  4870. }
  4871. static void brcmf_update_ht_cap(struct ieee80211_supported_band *band,
  4872. u32 bw_cap[2], u32 nchain)
  4873. {
  4874. band->ht_cap.ht_supported = true;
  4875. if (bw_cap[band->band] & WLC_BW_40MHZ_BIT) {
  4876. band->ht_cap.cap |= IEEE80211_HT_CAP_SGI_40;
  4877. band->ht_cap.cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
  4878. }
  4879. band->ht_cap.cap |= IEEE80211_HT_CAP_SGI_20;
  4880. band->ht_cap.cap |= IEEE80211_HT_CAP_DSSSCCK40;
  4881. band->ht_cap.ampdu_factor = IEEE80211_HT_MAX_AMPDU_64K;
  4882. band->ht_cap.ampdu_density = IEEE80211_HT_MPDU_DENSITY_16;
  4883. memset(band->ht_cap.mcs.rx_mask, 0xff, nchain);
  4884. band->ht_cap.mcs.tx_params = IEEE80211_HT_MCS_TX_DEFINED;
  4885. }
  4886. static __le16 brcmf_get_mcs_map(u32 nchain, enum ieee80211_vht_mcs_support supp)
  4887. {
  4888. u16 mcs_map;
  4889. int i;
  4890. for (i = 0, mcs_map = 0xFFFF; i < nchain; i++)
  4891. mcs_map = (mcs_map << 2) | supp;
  4892. return cpu_to_le16(mcs_map);
  4893. }
  4894. static void brcmf_update_vht_cap(struct ieee80211_supported_band *band,
  4895. u32 bw_cap[2], u32 nchain)
  4896. {
  4897. __le16 mcs_map;
  4898. /* not allowed in 2.4G band */
  4899. if (band->band == IEEE80211_BAND_2GHZ)
  4900. return;
  4901. band->vht_cap.vht_supported = true;
  4902. /* 80MHz is mandatory */
  4903. band->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_80;
  4904. if (bw_cap[band->band] & WLC_BW_160MHZ_BIT) {
  4905. band->vht_cap.cap |= IEEE80211_VHT_CAP_SUPP_CHAN_WIDTH_160MHZ;
  4906. band->vht_cap.cap |= IEEE80211_VHT_CAP_SHORT_GI_160;
  4907. }
  4908. /* all support 256-QAM */
  4909. mcs_map = brcmf_get_mcs_map(nchain, IEEE80211_VHT_MCS_SUPPORT_0_9);
  4910. band->vht_cap.vht_mcs.rx_mcs_map = mcs_map;
  4911. band->vht_cap.vht_mcs.tx_mcs_map = mcs_map;
  4912. }
  4913. static int brcmf_setup_wiphybands(struct wiphy *wiphy)
  4914. {
  4915. struct brcmf_cfg80211_info *cfg = wiphy_priv(wiphy);
  4916. struct brcmf_if *ifp = netdev_priv(cfg_to_ndev(cfg));
  4917. u32 nmode = 0;
  4918. u32 vhtmode = 0;
  4919. u32 bw_cap[2] = { WLC_BW_20MHZ_BIT, WLC_BW_20MHZ_BIT };
  4920. u32 rxchain;
  4921. u32 nchain;
  4922. int err;
  4923. s32 i;
  4924. struct ieee80211_supported_band *band;
  4925. (void)brcmf_fil_iovar_int_get(ifp, "vhtmode", &vhtmode);
  4926. err = brcmf_fil_iovar_int_get(ifp, "nmode", &nmode);
  4927. if (err) {
  4928. brcmf_err("nmode error (%d)\n", err);
  4929. } else {
  4930. brcmf_get_bwcap(ifp, bw_cap);
  4931. }
  4932. brcmf_dbg(INFO, "nmode=%d, vhtmode=%d, bw_cap=(%d, %d)\n",
  4933. nmode, vhtmode, bw_cap[IEEE80211_BAND_2GHZ],
  4934. bw_cap[IEEE80211_BAND_5GHZ]);
  4935. err = brcmf_fil_iovar_int_get(ifp, "rxchain", &rxchain);
  4936. if (err) {
  4937. brcmf_err("rxchain error (%d)\n", err);
  4938. nchain = 1;
  4939. } else {
  4940. for (nchain = 0; rxchain; nchain++)
  4941. rxchain = rxchain & (rxchain - 1);
  4942. }
  4943. brcmf_dbg(INFO, "nchain=%d\n", nchain);
  4944. err = brcmf_construct_chaninfo(cfg, bw_cap);
  4945. if (err) {
  4946. brcmf_err("brcmf_construct_chaninfo failed (%d)\n", err);
  4947. return err;
  4948. }
  4949. wiphy = cfg_to_wiphy(cfg);
  4950. for (i = 0; i < ARRAY_SIZE(wiphy->bands); i++) {
  4951. band = wiphy->bands[i];
  4952. if (band == NULL)
  4953. continue;
  4954. if (nmode)
  4955. brcmf_update_ht_cap(band, bw_cap, nchain);
  4956. if (vhtmode)
  4957. brcmf_update_vht_cap(band, bw_cap, nchain);
  4958. }
  4959. return 0;
  4960. }
  4961. static const struct ieee80211_iface_limit brcmf_iface_limits_mbss[] = {
  4962. {
  4963. .max = 1,
  4964. .types = BIT(NL80211_IFTYPE_STATION) |
  4965. BIT(NL80211_IFTYPE_ADHOC)
  4966. },
  4967. {
  4968. .max = 4,
  4969. .types = BIT(NL80211_IFTYPE_AP)
  4970. },
  4971. {
  4972. .max = 1,
  4973. .types = BIT(NL80211_IFTYPE_P2P_CLIENT) |
  4974. BIT(NL80211_IFTYPE_P2P_GO)
  4975. },
  4976. {
  4977. .max = 1,
  4978. .types = BIT(NL80211_IFTYPE_P2P_DEVICE)
  4979. }
  4980. };
  4981. static const struct ieee80211_iface_limit brcmf_iface_limits_sbss[] = {
  4982. {
  4983. .max = 2,
  4984. .types = BIT(NL80211_IFTYPE_STATION) |
  4985. BIT(NL80211_IFTYPE_ADHOC) |
  4986. BIT(NL80211_IFTYPE_AP)
  4987. },
  4988. {
  4989. .max = 1,
  4990. .types = BIT(NL80211_IFTYPE_P2P_CLIENT) |
  4991. BIT(NL80211_IFTYPE_P2P_GO)
  4992. },
  4993. {
  4994. .max = 1,
  4995. .types = BIT(NL80211_IFTYPE_P2P_DEVICE)
  4996. }
  4997. };
  4998. static struct ieee80211_iface_combination brcmf_iface_combos[] = {
  4999. {
  5000. .max_interfaces = BRCMF_IFACE_MAX_CNT,
  5001. .num_different_channels = 1,
  5002. .n_limits = ARRAY_SIZE(brcmf_iface_limits_sbss),
  5003. .limits = brcmf_iface_limits_sbss,
  5004. }
  5005. };
  5006. static const struct ieee80211_txrx_stypes
  5007. brcmf_txrx_stypes[NUM_NL80211_IFTYPES] = {
  5008. [NL80211_IFTYPE_STATION] = {
  5009. .tx = 0xffff,
  5010. .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  5011. BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
  5012. },
  5013. [NL80211_IFTYPE_P2P_CLIENT] = {
  5014. .tx = 0xffff,
  5015. .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  5016. BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
  5017. },
  5018. [NL80211_IFTYPE_P2P_GO] = {
  5019. .tx = 0xffff,
  5020. .rx = BIT(IEEE80211_STYPE_ASSOC_REQ >> 4) |
  5021. BIT(IEEE80211_STYPE_REASSOC_REQ >> 4) |
  5022. BIT(IEEE80211_STYPE_PROBE_REQ >> 4) |
  5023. BIT(IEEE80211_STYPE_DISASSOC >> 4) |
  5024. BIT(IEEE80211_STYPE_AUTH >> 4) |
  5025. BIT(IEEE80211_STYPE_DEAUTH >> 4) |
  5026. BIT(IEEE80211_STYPE_ACTION >> 4)
  5027. },
  5028. [NL80211_IFTYPE_P2P_DEVICE] = {
  5029. .tx = 0xffff,
  5030. .rx = BIT(IEEE80211_STYPE_ACTION >> 4) |
  5031. BIT(IEEE80211_STYPE_PROBE_REQ >> 4)
  5032. }
  5033. };
  5034. static void brcmf_wiphy_pno_params(struct wiphy *wiphy)
  5035. {
  5036. /* scheduled scan settings */
  5037. wiphy->max_sched_scan_ssids = BRCMF_PNO_MAX_PFN_COUNT;
  5038. wiphy->max_match_sets = BRCMF_PNO_MAX_PFN_COUNT;
  5039. wiphy->max_sched_scan_ie_len = BRCMF_SCAN_IE_LEN_MAX;
  5040. wiphy->flags |= WIPHY_FLAG_SUPPORTS_SCHED_SCAN;
  5041. }
  5042. #ifdef CONFIG_PM
  5043. static const struct wiphy_wowlan_support brcmf_wowlan_support = {
  5044. .flags = WIPHY_WOWLAN_MAGIC_PKT | WIPHY_WOWLAN_DISCONNECT,
  5045. .n_patterns = BRCMF_WOWL_MAXPATTERNS,
  5046. .pattern_max_len = BRCMF_WOWL_MAXPATTERNSIZE,
  5047. .pattern_min_len = 1,
  5048. .max_pkt_offset = 1500,
  5049. };
  5050. #endif
  5051. static void brcmf_wiphy_wowl_params(struct wiphy *wiphy)
  5052. {
  5053. #ifdef CONFIG_PM
  5054. /* wowl settings */
  5055. wiphy->wowlan = &brcmf_wowlan_support;
  5056. #endif
  5057. }
  5058. static int brcmf_setup_wiphy(struct wiphy *wiphy, struct brcmf_if *ifp)
  5059. {
  5060. struct ieee80211_iface_combination ifc_combo;
  5061. wiphy->max_scan_ssids = WL_NUM_SCAN_MAX;
  5062. wiphy->max_scan_ie_len = BRCMF_SCAN_IE_LEN_MAX;
  5063. wiphy->max_num_pmkids = WL_NUM_PMKIDS_MAX;
  5064. wiphy->interface_modes = BIT(NL80211_IFTYPE_STATION) |
  5065. BIT(NL80211_IFTYPE_ADHOC) |
  5066. BIT(NL80211_IFTYPE_AP) |
  5067. BIT(NL80211_IFTYPE_P2P_CLIENT) |
  5068. BIT(NL80211_IFTYPE_P2P_GO) |
  5069. BIT(NL80211_IFTYPE_P2P_DEVICE);
  5070. /* need VSDB firmware feature for concurrent channels */
  5071. ifc_combo = brcmf_iface_combos[0];
  5072. if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_MCHAN))
  5073. ifc_combo.num_different_channels = 2;
  5074. if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_MBSS)) {
  5075. ifc_combo.n_limits = ARRAY_SIZE(brcmf_iface_limits_mbss),
  5076. ifc_combo.limits = brcmf_iface_limits_mbss;
  5077. }
  5078. wiphy->iface_combinations = kmemdup(&ifc_combo,
  5079. sizeof(ifc_combo),
  5080. GFP_KERNEL);
  5081. wiphy->n_iface_combinations = ARRAY_SIZE(brcmf_iface_combos);
  5082. wiphy->signal_type = CFG80211_SIGNAL_TYPE_MBM;
  5083. wiphy->cipher_suites = __wl_cipher_suites;
  5084. wiphy->n_cipher_suites = ARRAY_SIZE(__wl_cipher_suites);
  5085. wiphy->flags |= WIPHY_FLAG_PS_ON_BY_DEFAULT |
  5086. WIPHY_FLAG_OFFCHAN_TX |
  5087. WIPHY_FLAG_HAS_REMAIN_ON_CHANNEL |
  5088. WIPHY_FLAG_SUPPORTS_TDLS;
  5089. if (!brcmf_roamoff)
  5090. wiphy->flags |= WIPHY_FLAG_SUPPORTS_FW_ROAM;
  5091. wiphy->mgmt_stypes = brcmf_txrx_stypes;
  5092. wiphy->max_remain_on_channel_duration = 5000;
  5093. brcmf_wiphy_pno_params(wiphy);
  5094. /* vendor commands/events support */
  5095. wiphy->vendor_commands = brcmf_vendor_cmds;
  5096. wiphy->n_vendor_commands = BRCMF_VNDR_CMDS_LAST - 1;
  5097. if (brcmf_feat_is_enabled(ifp, BRCMF_FEAT_WOWL))
  5098. brcmf_wiphy_wowl_params(wiphy);
  5099. return brcmf_setup_wiphybands(wiphy);
  5100. }
  5101. static s32 brcmf_config_dongle(struct brcmf_cfg80211_info *cfg)
  5102. {
  5103. struct net_device *ndev;
  5104. struct wireless_dev *wdev;
  5105. struct brcmf_if *ifp;
  5106. s32 power_mode;
  5107. s32 err = 0;
  5108. if (cfg->dongle_up)
  5109. return err;
  5110. ndev = cfg_to_ndev(cfg);
  5111. wdev = ndev->ieee80211_ptr;
  5112. ifp = netdev_priv(ndev);
  5113. /* make sure RF is ready for work */
  5114. brcmf_fil_cmd_int_set(ifp, BRCMF_C_UP, 0);
  5115. brcmf_dongle_scantime(ifp, WL_SCAN_CHANNEL_TIME,
  5116. WL_SCAN_UNASSOC_TIME, WL_SCAN_PASSIVE_TIME);
  5117. power_mode = cfg->pwr_save ? PM_FAST : PM_OFF;
  5118. err = brcmf_fil_cmd_int_set(ifp, BRCMF_C_SET_PM, power_mode);
  5119. if (err)
  5120. goto default_conf_out;
  5121. brcmf_dbg(INFO, "power save set to %s\n",
  5122. (power_mode ? "enabled" : "disabled"));
  5123. err = brcmf_dongle_roam(ifp, WL_BEACON_TIMEOUT);
  5124. if (err)
  5125. goto default_conf_out;
  5126. err = brcmf_cfg80211_change_iface(wdev->wiphy, ndev, wdev->iftype,
  5127. NULL, NULL);
  5128. if (err)
  5129. goto default_conf_out;
  5130. brcmf_configure_arp_offload(ifp, true);
  5131. cfg->dongle_up = true;
  5132. default_conf_out:
  5133. return err;
  5134. }
  5135. static s32 __brcmf_cfg80211_up(struct brcmf_if *ifp)
  5136. {
  5137. set_bit(BRCMF_VIF_STATUS_READY, &ifp->vif->sme_state);
  5138. return brcmf_config_dongle(ifp->drvr->config);
  5139. }
  5140. static s32 __brcmf_cfg80211_down(struct brcmf_if *ifp)
  5141. {
  5142. struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
  5143. /*
  5144. * While going down, if associated with AP disassociate
  5145. * from AP to save power
  5146. */
  5147. if (check_vif_up(ifp->vif)) {
  5148. brcmf_link_down(ifp->vif, WLAN_REASON_UNSPECIFIED);
  5149. /* Make sure WPA_Supplicant receives all the event
  5150. generated due to DISASSOC call to the fw to keep
  5151. the state fw and WPA_Supplicant state consistent
  5152. */
  5153. brcmf_delay(500);
  5154. }
  5155. brcmf_abort_scanning(cfg);
  5156. clear_bit(BRCMF_VIF_STATUS_READY, &ifp->vif->sme_state);
  5157. return 0;
  5158. }
  5159. s32 brcmf_cfg80211_up(struct net_device *ndev)
  5160. {
  5161. struct brcmf_if *ifp = netdev_priv(ndev);
  5162. struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
  5163. s32 err = 0;
  5164. mutex_lock(&cfg->usr_sync);
  5165. err = __brcmf_cfg80211_up(ifp);
  5166. mutex_unlock(&cfg->usr_sync);
  5167. return err;
  5168. }
  5169. s32 brcmf_cfg80211_down(struct net_device *ndev)
  5170. {
  5171. struct brcmf_if *ifp = netdev_priv(ndev);
  5172. struct brcmf_cfg80211_info *cfg = ifp->drvr->config;
  5173. s32 err = 0;
  5174. mutex_lock(&cfg->usr_sync);
  5175. err = __brcmf_cfg80211_down(ifp);
  5176. mutex_unlock(&cfg->usr_sync);
  5177. return err;
  5178. }
  5179. enum nl80211_iftype brcmf_cfg80211_get_iftype(struct brcmf_if *ifp)
  5180. {
  5181. struct wireless_dev *wdev = &ifp->vif->wdev;
  5182. return wdev->iftype;
  5183. }
  5184. bool brcmf_get_vif_state_any(struct brcmf_cfg80211_info *cfg,
  5185. unsigned long state)
  5186. {
  5187. struct brcmf_cfg80211_vif *vif;
  5188. list_for_each_entry(vif, &cfg->vif_list, list) {
  5189. if (test_bit(state, &vif->sme_state))
  5190. return true;
  5191. }
  5192. return false;
  5193. }
  5194. static inline bool vif_event_equals(struct brcmf_cfg80211_vif_event *event,
  5195. u8 action)
  5196. {
  5197. u8 evt_action;
  5198. mutex_lock(&event->vif_event_lock);
  5199. evt_action = event->action;
  5200. mutex_unlock(&event->vif_event_lock);
  5201. return evt_action == action;
  5202. }
  5203. void brcmf_cfg80211_arm_vif_event(struct brcmf_cfg80211_info *cfg,
  5204. struct brcmf_cfg80211_vif *vif)
  5205. {
  5206. struct brcmf_cfg80211_vif_event *event = &cfg->vif_event;
  5207. mutex_lock(&event->vif_event_lock);
  5208. event->vif = vif;
  5209. event->action = 0;
  5210. mutex_unlock(&event->vif_event_lock);
  5211. }
  5212. bool brcmf_cfg80211_vif_event_armed(struct brcmf_cfg80211_info *cfg)
  5213. {
  5214. struct brcmf_cfg80211_vif_event *event = &cfg->vif_event;
  5215. bool armed;
  5216. mutex_lock(&event->vif_event_lock);
  5217. armed = event->vif != NULL;
  5218. mutex_unlock(&event->vif_event_lock);
  5219. return armed;
  5220. }
  5221. int brcmf_cfg80211_wait_vif_event_timeout(struct brcmf_cfg80211_info *cfg,
  5222. u8 action, ulong timeout)
  5223. {
  5224. struct brcmf_cfg80211_vif_event *event = &cfg->vif_event;
  5225. return wait_event_timeout(event->vif_wq,
  5226. vif_event_equals(event, action), timeout);
  5227. }
  5228. static void brcmf_cfg80211_reg_notifier(struct wiphy *wiphy,
  5229. struct regulatory_request *req)
  5230. {
  5231. struct brcmf_cfg80211_info *cfg = wiphy_priv(wiphy);
  5232. struct brcmf_if *ifp = netdev_priv(cfg_to_ndev(cfg));
  5233. struct brcmf_fil_country_le ccreq;
  5234. int i;
  5235. brcmf_dbg(TRACE, "enter: initiator=%d, alpha=%c%c\n", req->initiator,
  5236. req->alpha2[0], req->alpha2[1]);
  5237. /* ignore non-ISO3166 country codes */
  5238. for (i = 0; i < sizeof(req->alpha2); i++)
  5239. if (req->alpha2[i] < 'A' || req->alpha2[i] > 'Z') {
  5240. brcmf_err("not a ISO3166 code\n");
  5241. return;
  5242. }
  5243. memset(&ccreq, 0, sizeof(ccreq));
  5244. ccreq.rev = cpu_to_le32(-1);
  5245. memcpy(ccreq.ccode, req->alpha2, sizeof(req->alpha2));
  5246. brcmf_fil_iovar_data_set(ifp, "country", &ccreq, sizeof(ccreq));
  5247. }
  5248. static void brcmf_free_wiphy(struct wiphy *wiphy)
  5249. {
  5250. kfree(wiphy->iface_combinations);
  5251. if (wiphy->bands[IEEE80211_BAND_2GHZ]) {
  5252. kfree(wiphy->bands[IEEE80211_BAND_2GHZ]->channels);
  5253. kfree(wiphy->bands[IEEE80211_BAND_2GHZ]);
  5254. }
  5255. if (wiphy->bands[IEEE80211_BAND_5GHZ]) {
  5256. kfree(wiphy->bands[IEEE80211_BAND_5GHZ]->channels);
  5257. kfree(wiphy->bands[IEEE80211_BAND_5GHZ]);
  5258. }
  5259. wiphy_free(wiphy);
  5260. }
  5261. struct brcmf_cfg80211_info *brcmf_cfg80211_attach(struct brcmf_pub *drvr,
  5262. struct device *busdev)
  5263. {
  5264. struct net_device *ndev = drvr->iflist[0]->ndev;
  5265. struct brcmf_cfg80211_info *cfg;
  5266. struct wiphy *wiphy;
  5267. struct brcmf_cfg80211_vif *vif;
  5268. struct brcmf_if *ifp;
  5269. s32 err = 0;
  5270. s32 io_type;
  5271. u16 *cap = NULL;
  5272. if (!ndev) {
  5273. brcmf_err("ndev is invalid\n");
  5274. return NULL;
  5275. }
  5276. ifp = netdev_priv(ndev);
  5277. wiphy = wiphy_new(&wl_cfg80211_ops, sizeof(struct brcmf_cfg80211_info));
  5278. if (!wiphy) {
  5279. brcmf_err("Could not allocate wiphy device\n");
  5280. return NULL;
  5281. }
  5282. set_wiphy_dev(wiphy, busdev);
  5283. cfg = wiphy_priv(wiphy);
  5284. cfg->wiphy = wiphy;
  5285. cfg->pub = drvr;
  5286. init_vif_event(&cfg->vif_event);
  5287. INIT_LIST_HEAD(&cfg->vif_list);
  5288. vif = brcmf_alloc_vif(cfg, NL80211_IFTYPE_STATION, false);
  5289. if (IS_ERR(vif))
  5290. goto wiphy_out;
  5291. vif->ifp = ifp;
  5292. vif->wdev.netdev = ndev;
  5293. ndev->ieee80211_ptr = &vif->wdev;
  5294. SET_NETDEV_DEV(ndev, wiphy_dev(cfg->wiphy));
  5295. err = wl_init_priv(cfg);
  5296. if (err) {
  5297. brcmf_err("Failed to init iwm_priv (%d)\n", err);
  5298. brcmf_free_vif(vif);
  5299. goto wiphy_out;
  5300. }
  5301. ifp->vif = vif;
  5302. /* determine d11 io type before wiphy setup */
  5303. err = brcmf_fil_cmd_int_get(ifp, BRCMF_C_GET_VERSION, &io_type);
  5304. if (err) {
  5305. brcmf_err("Failed to get D11 version (%d)\n", err);
  5306. goto priv_out;
  5307. }
  5308. cfg->d11inf.io_type = (u8)io_type;
  5309. brcmu_d11_attach(&cfg->d11inf);
  5310. err = brcmf_setup_wiphy(wiphy, ifp);
  5311. if (err < 0)
  5312. goto priv_out;
  5313. brcmf_dbg(INFO, "Registering custom regulatory\n");
  5314. wiphy->reg_notifier = brcmf_cfg80211_reg_notifier;
  5315. wiphy->regulatory_flags |= REGULATORY_CUSTOM_REG;
  5316. wiphy_apply_custom_regulatory(wiphy, &brcmf_regdom);
  5317. /* firmware defaults to 40MHz disabled in 2G band. We signal
  5318. * cfg80211 here that we do and have it decide we can enable
  5319. * it. But first check if device does support 2G operation.
  5320. */
  5321. if (wiphy->bands[IEEE80211_BAND_2GHZ]) {
  5322. cap = &wiphy->bands[IEEE80211_BAND_2GHZ]->ht_cap.cap;
  5323. *cap |= IEEE80211_HT_CAP_SUP_WIDTH_20_40;
  5324. }
  5325. err = wiphy_register(wiphy);
  5326. if (err < 0) {
  5327. brcmf_err("Could not register wiphy device (%d)\n", err);
  5328. goto priv_out;
  5329. }
  5330. /* If cfg80211 didn't disable 40MHz HT CAP in wiphy_register(),
  5331. * setup 40MHz in 2GHz band and enable OBSS scanning.
  5332. */
  5333. if (cap && (*cap & IEEE80211_HT_CAP_SUP_WIDTH_20_40)) {
  5334. err = brcmf_enable_bw40_2g(cfg);
  5335. if (!err)
  5336. err = brcmf_fil_iovar_int_set(ifp, "obss_coex",
  5337. BRCMF_OBSS_COEX_AUTO);
  5338. else
  5339. *cap &= ~IEEE80211_HT_CAP_SUP_WIDTH_20_40;
  5340. }
  5341. err = brcmf_p2p_attach(cfg);
  5342. if (err) {
  5343. brcmf_err("P2P initilisation failed (%d)\n", err);
  5344. goto wiphy_unreg_out;
  5345. }
  5346. err = brcmf_btcoex_attach(cfg);
  5347. if (err) {
  5348. brcmf_err("BT-coex initialisation failed (%d)\n", err);
  5349. brcmf_p2p_detach(&cfg->p2p);
  5350. goto wiphy_unreg_out;
  5351. }
  5352. err = brcmf_fil_iovar_int_set(ifp, "tdls_enable", 1);
  5353. if (err) {
  5354. brcmf_dbg(INFO, "TDLS not enabled (%d)\n", err);
  5355. wiphy->flags &= ~WIPHY_FLAG_SUPPORTS_TDLS;
  5356. } else {
  5357. brcmf_fweh_register(cfg->pub, BRCMF_E_TDLS_PEER_EVENT,
  5358. brcmf_notify_tdls_peer_event);
  5359. }
  5360. return cfg;
  5361. wiphy_unreg_out:
  5362. wiphy_unregister(cfg->wiphy);
  5363. priv_out:
  5364. wl_deinit_priv(cfg);
  5365. brcmf_free_vif(vif);
  5366. wiphy_out:
  5367. brcmf_free_wiphy(wiphy);
  5368. return NULL;
  5369. }
  5370. void brcmf_cfg80211_detach(struct brcmf_cfg80211_info *cfg)
  5371. {
  5372. if (!cfg)
  5373. return;
  5374. WARN_ON(!list_empty(&cfg->vif_list));
  5375. wiphy_unregister(cfg->wiphy);
  5376. brcmf_btcoex_detach(cfg);
  5377. brcmf_p2p_detach(&cfg->p2p);
  5378. wl_deinit_priv(cfg);
  5379. brcmf_free_wiphy(cfg->wiphy);
  5380. }