cfg80211.c 183 KB

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