cfg80211.c 186 KB

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