cfg80211.c 189 KB

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