cfg80211.c 193 KB

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