cfg80211.c 187 KB

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