cfg80211.c 188 KB

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