cfg80211.c 189 KB

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