cfg80211.c 169 KB

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