driver_nl80211.c 243 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152
  1. /*
  2. * Driver interaction with Linux nl80211/cfg80211
  3. * Copyright (c) 2002-2015, Jouni Malinen <j@w1.fi>
  4. * Copyright (c) 2003-2004, Instant802 Networks, Inc.
  5. * Copyright (c) 2005-2006, Devicescape Software, Inc.
  6. * Copyright (c) 2007, Johannes Berg <johannes@sipsolutions.net>
  7. * Copyright (c) 2009-2010, Atheros Communications
  8. *
  9. * This software may be distributed under the terms of the BSD license.
  10. * See README for more details.
  11. */
  12. #include "includes.h"
  13. #include <sys/types.h>
  14. #include <fcntl.h>
  15. #include <net/if.h>
  16. #include <netlink/genl/genl.h>
  17. #include <netlink/genl/ctrl.h>
  18. #ifdef CONFIG_LIBNL3_ROUTE
  19. #include <netlink/route/neighbour.h>
  20. #endif /* CONFIG_LIBNL3_ROUTE */
  21. #include <linux/rtnetlink.h>
  22. #include <netpacket/packet.h>
  23. #include <linux/errqueue.h>
  24. #include "common.h"
  25. #include "eloop.h"
  26. #include "common/qca-vendor.h"
  27. #include "common/qca-vendor-attr.h"
  28. #include "common/ieee802_11_defs.h"
  29. #include "common/ieee802_11_common.h"
  30. #include "l2_packet/l2_packet.h"
  31. #include "netlink.h"
  32. #include "linux_defines.h"
  33. #include "linux_ioctl.h"
  34. #include "radiotap.h"
  35. #include "radiotap_iter.h"
  36. #include "rfkill.h"
  37. #include "driver_nl80211.h"
  38. #ifndef CONFIG_LIBNL20
  39. /*
  40. * libnl 1.1 has a bug, it tries to allocate socket numbers densely
  41. * but when you free a socket again it will mess up its bitmap and
  42. * and use the wrong number the next time it needs a socket ID.
  43. * Therefore, we wrap the handle alloc/destroy and add our own pid
  44. * accounting.
  45. */
  46. static uint32_t port_bitmap[32] = { 0 };
  47. static struct nl_handle *nl80211_handle_alloc(void *cb)
  48. {
  49. struct nl_handle *handle;
  50. uint32_t pid = getpid() & 0x3FFFFF;
  51. int i;
  52. handle = nl_handle_alloc_cb(cb);
  53. for (i = 0; i < 1024; i++) {
  54. if (port_bitmap[i / 32] & (1 << (i % 32)))
  55. continue;
  56. port_bitmap[i / 32] |= 1 << (i % 32);
  57. pid += i << 22;
  58. break;
  59. }
  60. nl_socket_set_local_port(handle, pid);
  61. return handle;
  62. }
  63. static void nl80211_handle_destroy(struct nl_handle *handle)
  64. {
  65. uint32_t port = nl_socket_get_local_port(handle);
  66. port >>= 22;
  67. port_bitmap[port / 32] &= ~(1 << (port % 32));
  68. nl_handle_destroy(handle);
  69. }
  70. #endif /* CONFIG_LIBNL20 */
  71. #ifdef ANDROID
  72. /* system/core/libnl_2 does not include nl_socket_set_nonblocking() */
  73. #undef nl_socket_set_nonblocking
  74. #define nl_socket_set_nonblocking(h) android_nl_socket_set_nonblocking(h)
  75. #endif /* ANDROID */
  76. static struct nl_handle * nl_create_handle(struct nl_cb *cb, const char *dbg)
  77. {
  78. struct nl_handle *handle;
  79. handle = nl80211_handle_alloc(cb);
  80. if (handle == NULL) {
  81. wpa_printf(MSG_ERROR, "nl80211: Failed to allocate netlink "
  82. "callbacks (%s)", dbg);
  83. return NULL;
  84. }
  85. if (genl_connect(handle)) {
  86. wpa_printf(MSG_ERROR, "nl80211: Failed to connect to generic "
  87. "netlink (%s)", dbg);
  88. nl80211_handle_destroy(handle);
  89. return NULL;
  90. }
  91. return handle;
  92. }
  93. static void nl_destroy_handles(struct nl_handle **handle)
  94. {
  95. if (*handle == NULL)
  96. return;
  97. nl80211_handle_destroy(*handle);
  98. *handle = NULL;
  99. }
  100. #if __WORDSIZE == 64
  101. #define ELOOP_SOCKET_INVALID (intptr_t) 0x8888888888888889ULL
  102. #else
  103. #define ELOOP_SOCKET_INVALID (intptr_t) 0x88888889ULL
  104. #endif
  105. static void nl80211_register_eloop_read(struct nl_handle **handle,
  106. eloop_sock_handler handler,
  107. void *eloop_data)
  108. {
  109. #ifdef CONFIG_LIBNL20
  110. /*
  111. * libnl uses a pretty small buffer (32 kB that gets converted to 64 kB)
  112. * by default. It is possible to hit that limit in some cases where
  113. * operations are blocked, e.g., with a burst of Deauthentication frames
  114. * to hostapd and STA entry deletion. Try to increase the buffer to make
  115. * this less likely to occur.
  116. */
  117. if (nl_socket_set_buffer_size(*handle, 262144, 0) < 0) {
  118. wpa_printf(MSG_DEBUG,
  119. "nl80211: Could not set nl_socket RX buffer size: %s",
  120. strerror(errno));
  121. /* continue anyway with the default (smaller) buffer */
  122. }
  123. #endif /* CONFIG_LIBNL20 */
  124. nl_socket_set_nonblocking(*handle);
  125. eloop_register_read_sock(nl_socket_get_fd(*handle), handler,
  126. eloop_data, *handle);
  127. *handle = (void *) (((intptr_t) *handle) ^ ELOOP_SOCKET_INVALID);
  128. }
  129. static void nl80211_destroy_eloop_handle(struct nl_handle **handle)
  130. {
  131. *handle = (void *) (((intptr_t) *handle) ^ ELOOP_SOCKET_INVALID);
  132. eloop_unregister_read_sock(nl_socket_get_fd(*handle));
  133. nl_destroy_handles(handle);
  134. }
  135. static void nl80211_global_deinit(void *priv);
  136. static void nl80211_check_global(struct nl80211_global *global);
  137. static void wpa_driver_nl80211_deinit(struct i802_bss *bss);
  138. static int wpa_driver_nl80211_set_mode_ibss(struct i802_bss *bss,
  139. struct hostapd_freq_params *freq);
  140. static int
  141. wpa_driver_nl80211_finish_drv_init(struct wpa_driver_nl80211_data *drv,
  142. const u8 *set_addr, int first,
  143. const char *driver_params);
  144. static int nl80211_send_frame_cmd(struct i802_bss *bss,
  145. unsigned int freq, unsigned int wait,
  146. const u8 *buf, size_t buf_len, u64 *cookie,
  147. int no_cck, int no_ack, int offchanok,
  148. const u16 *csa_offs, size_t csa_offs_len);
  149. static int wpa_driver_nl80211_probe_req_report(struct i802_bss *bss,
  150. int report);
  151. #define IFIDX_ANY -1
  152. static void add_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx,
  153. int ifidx_reason);
  154. static void del_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx,
  155. int ifidx_reason);
  156. static int have_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx,
  157. int ifidx_reason);
  158. static int nl80211_set_channel(struct i802_bss *bss,
  159. struct hostapd_freq_params *freq, int set_chan);
  160. static int nl80211_disable_11b_rates(struct wpa_driver_nl80211_data *drv,
  161. int ifindex, int disabled);
  162. static int nl80211_leave_ibss(struct wpa_driver_nl80211_data *drv,
  163. int reset_mode);
  164. static int i802_set_iface_flags(struct i802_bss *bss, int up);
  165. static int nl80211_set_param(void *priv, const char *param);
  166. /* Converts nl80211_chan_width to a common format */
  167. enum chan_width convert2width(int width)
  168. {
  169. switch (width) {
  170. case NL80211_CHAN_WIDTH_20_NOHT:
  171. return CHAN_WIDTH_20_NOHT;
  172. case NL80211_CHAN_WIDTH_20:
  173. return CHAN_WIDTH_20;
  174. case NL80211_CHAN_WIDTH_40:
  175. return CHAN_WIDTH_40;
  176. case NL80211_CHAN_WIDTH_80:
  177. return CHAN_WIDTH_80;
  178. case NL80211_CHAN_WIDTH_80P80:
  179. return CHAN_WIDTH_80P80;
  180. case NL80211_CHAN_WIDTH_160:
  181. return CHAN_WIDTH_160;
  182. }
  183. return CHAN_WIDTH_UNKNOWN;
  184. }
  185. int is_ap_interface(enum nl80211_iftype nlmode)
  186. {
  187. return nlmode == NL80211_IFTYPE_AP ||
  188. nlmode == NL80211_IFTYPE_P2P_GO;
  189. }
  190. int is_sta_interface(enum nl80211_iftype nlmode)
  191. {
  192. return nlmode == NL80211_IFTYPE_STATION ||
  193. nlmode == NL80211_IFTYPE_P2P_CLIENT;
  194. }
  195. static int is_p2p_net_interface(enum nl80211_iftype nlmode)
  196. {
  197. return nlmode == NL80211_IFTYPE_P2P_CLIENT ||
  198. nlmode == NL80211_IFTYPE_P2P_GO;
  199. }
  200. struct i802_bss * get_bss_ifindex(struct wpa_driver_nl80211_data *drv,
  201. int ifindex)
  202. {
  203. struct i802_bss *bss;
  204. for (bss = drv->first_bss; bss; bss = bss->next) {
  205. if (bss->ifindex == ifindex)
  206. return bss;
  207. }
  208. return NULL;
  209. }
  210. static int is_mesh_interface(enum nl80211_iftype nlmode)
  211. {
  212. return nlmode == NL80211_IFTYPE_MESH_POINT;
  213. }
  214. void nl80211_mark_disconnected(struct wpa_driver_nl80211_data *drv)
  215. {
  216. if (drv->associated)
  217. os_memcpy(drv->prev_bssid, drv->bssid, ETH_ALEN);
  218. drv->associated = 0;
  219. os_memset(drv->bssid, 0, ETH_ALEN);
  220. }
  221. /* nl80211 code */
  222. static int ack_handler(struct nl_msg *msg, void *arg)
  223. {
  224. int *err = arg;
  225. *err = 0;
  226. return NL_STOP;
  227. }
  228. static int finish_handler(struct nl_msg *msg, void *arg)
  229. {
  230. int *ret = arg;
  231. *ret = 0;
  232. return NL_SKIP;
  233. }
  234. static int error_handler(struct sockaddr_nl *nla, struct nlmsgerr *err,
  235. void *arg)
  236. {
  237. int *ret = arg;
  238. *ret = err->error;
  239. return NL_SKIP;
  240. }
  241. static int no_seq_check(struct nl_msg *msg, void *arg)
  242. {
  243. return NL_OK;
  244. }
  245. static void nl80211_nlmsg_clear(struct nl_msg *msg)
  246. {
  247. /*
  248. * Clear nlmsg data, e.g., to make sure key material is not left in
  249. * heap memory for unnecessarily long time.
  250. */
  251. if (msg) {
  252. struct nlmsghdr *hdr = nlmsg_hdr(msg);
  253. void *data = nlmsg_data(hdr);
  254. /*
  255. * This would use nlmsg_datalen() or the older nlmsg_len() if
  256. * only libnl were to maintain a stable API.. Neither will work
  257. * with all released versions, so just calculate the length
  258. * here.
  259. */
  260. int len = hdr->nlmsg_len - NLMSG_HDRLEN;
  261. os_memset(data, 0, len);
  262. }
  263. }
  264. static int send_and_recv(struct nl80211_global *global,
  265. struct nl_handle *nl_handle, struct nl_msg *msg,
  266. int (*valid_handler)(struct nl_msg *, void *),
  267. void *valid_data)
  268. {
  269. struct nl_cb *cb;
  270. int err = -ENOMEM;
  271. if (!msg)
  272. return -ENOMEM;
  273. cb = nl_cb_clone(global->nl_cb);
  274. if (!cb)
  275. goto out;
  276. err = nl_send_auto_complete(nl_handle, msg);
  277. if (err < 0)
  278. goto out;
  279. err = 1;
  280. nl_cb_err(cb, NL_CB_CUSTOM, error_handler, &err);
  281. nl_cb_set(cb, NL_CB_FINISH, NL_CB_CUSTOM, finish_handler, &err);
  282. nl_cb_set(cb, NL_CB_ACK, NL_CB_CUSTOM, ack_handler, &err);
  283. if (valid_handler)
  284. nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM,
  285. valid_handler, valid_data);
  286. while (err > 0) {
  287. int res = nl_recvmsgs(nl_handle, cb);
  288. if (res < 0) {
  289. wpa_printf(MSG_INFO,
  290. "nl80211: %s->nl_recvmsgs failed: %d",
  291. __func__, res);
  292. }
  293. }
  294. out:
  295. nl_cb_put(cb);
  296. if (!valid_handler && valid_data == (void *) -1)
  297. nl80211_nlmsg_clear(msg);
  298. nlmsg_free(msg);
  299. return err;
  300. }
  301. int send_and_recv_msgs(struct wpa_driver_nl80211_data *drv,
  302. struct nl_msg *msg,
  303. int (*valid_handler)(struct nl_msg *, void *),
  304. void *valid_data)
  305. {
  306. return send_and_recv(drv->global, drv->global->nl, msg,
  307. valid_handler, valid_data);
  308. }
  309. struct family_data {
  310. const char *group;
  311. int id;
  312. };
  313. static int family_handler(struct nl_msg *msg, void *arg)
  314. {
  315. struct family_data *res = arg;
  316. struct nlattr *tb[CTRL_ATTR_MAX + 1];
  317. struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
  318. struct nlattr *mcgrp;
  319. int i;
  320. nla_parse(tb, CTRL_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
  321. genlmsg_attrlen(gnlh, 0), NULL);
  322. if (!tb[CTRL_ATTR_MCAST_GROUPS])
  323. return NL_SKIP;
  324. nla_for_each_nested(mcgrp, tb[CTRL_ATTR_MCAST_GROUPS], i) {
  325. struct nlattr *tb2[CTRL_ATTR_MCAST_GRP_MAX + 1];
  326. nla_parse(tb2, CTRL_ATTR_MCAST_GRP_MAX, nla_data(mcgrp),
  327. nla_len(mcgrp), NULL);
  328. if (!tb2[CTRL_ATTR_MCAST_GRP_NAME] ||
  329. !tb2[CTRL_ATTR_MCAST_GRP_ID] ||
  330. os_strncmp(nla_data(tb2[CTRL_ATTR_MCAST_GRP_NAME]),
  331. res->group,
  332. nla_len(tb2[CTRL_ATTR_MCAST_GRP_NAME])) != 0)
  333. continue;
  334. res->id = nla_get_u32(tb2[CTRL_ATTR_MCAST_GRP_ID]);
  335. break;
  336. };
  337. return NL_SKIP;
  338. }
  339. static int nl_get_multicast_id(struct nl80211_global *global,
  340. const char *family, const char *group)
  341. {
  342. struct nl_msg *msg;
  343. int ret;
  344. struct family_data res = { group, -ENOENT };
  345. msg = nlmsg_alloc();
  346. if (!msg)
  347. return -ENOMEM;
  348. if (!genlmsg_put(msg, 0, 0, genl_ctrl_resolve(global->nl, "nlctrl"),
  349. 0, 0, CTRL_CMD_GETFAMILY, 0) ||
  350. nla_put_string(msg, CTRL_ATTR_FAMILY_NAME, family)) {
  351. nlmsg_free(msg);
  352. return -1;
  353. }
  354. ret = send_and_recv(global, global->nl, msg, family_handler, &res);
  355. if (ret == 0)
  356. ret = res.id;
  357. return ret;
  358. }
  359. void * nl80211_cmd(struct wpa_driver_nl80211_data *drv,
  360. struct nl_msg *msg, int flags, uint8_t cmd)
  361. {
  362. return genlmsg_put(msg, 0, 0, drv->global->nl80211_id,
  363. 0, flags, cmd, 0);
  364. }
  365. static int nl80211_set_iface_id(struct nl_msg *msg, struct i802_bss *bss)
  366. {
  367. if (bss->wdev_id_set)
  368. return nla_put_u64(msg, NL80211_ATTR_WDEV, bss->wdev_id);
  369. return nla_put_u32(msg, NL80211_ATTR_IFINDEX, bss->ifindex);
  370. }
  371. struct nl_msg * nl80211_cmd_msg(struct i802_bss *bss, int flags, uint8_t cmd)
  372. {
  373. struct nl_msg *msg;
  374. msg = nlmsg_alloc();
  375. if (!msg)
  376. return NULL;
  377. if (!nl80211_cmd(bss->drv, msg, flags, cmd) ||
  378. nl80211_set_iface_id(msg, bss) < 0) {
  379. nlmsg_free(msg);
  380. return NULL;
  381. }
  382. return msg;
  383. }
  384. static struct nl_msg *
  385. nl80211_ifindex_msg(struct wpa_driver_nl80211_data *drv, int ifindex,
  386. int flags, uint8_t cmd)
  387. {
  388. struct nl_msg *msg;
  389. msg = nlmsg_alloc();
  390. if (!msg)
  391. return NULL;
  392. if (!nl80211_cmd(drv, msg, flags, cmd) ||
  393. nla_put_u32(msg, NL80211_ATTR_IFINDEX, ifindex)) {
  394. nlmsg_free(msg);
  395. return NULL;
  396. }
  397. return msg;
  398. }
  399. struct nl_msg * nl80211_drv_msg(struct wpa_driver_nl80211_data *drv, int flags,
  400. uint8_t cmd)
  401. {
  402. return nl80211_ifindex_msg(drv, drv->ifindex, flags, cmd);
  403. }
  404. struct nl_msg * nl80211_bss_msg(struct i802_bss *bss, int flags, uint8_t cmd)
  405. {
  406. return nl80211_ifindex_msg(bss->drv, bss->ifindex, flags, cmd);
  407. }
  408. struct wiphy_idx_data {
  409. int wiphy_idx;
  410. enum nl80211_iftype nlmode;
  411. u8 *macaddr;
  412. };
  413. static int netdev_info_handler(struct nl_msg *msg, void *arg)
  414. {
  415. struct nlattr *tb[NL80211_ATTR_MAX + 1];
  416. struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
  417. struct wiphy_idx_data *info = arg;
  418. nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
  419. genlmsg_attrlen(gnlh, 0), NULL);
  420. if (tb[NL80211_ATTR_WIPHY])
  421. info->wiphy_idx = nla_get_u32(tb[NL80211_ATTR_WIPHY]);
  422. if (tb[NL80211_ATTR_IFTYPE])
  423. info->nlmode = nla_get_u32(tb[NL80211_ATTR_IFTYPE]);
  424. if (tb[NL80211_ATTR_MAC] && info->macaddr)
  425. os_memcpy(info->macaddr, nla_data(tb[NL80211_ATTR_MAC]),
  426. ETH_ALEN);
  427. return NL_SKIP;
  428. }
  429. int nl80211_get_wiphy_index(struct i802_bss *bss)
  430. {
  431. struct nl_msg *msg;
  432. struct wiphy_idx_data data = {
  433. .wiphy_idx = -1,
  434. .macaddr = NULL,
  435. };
  436. if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_GET_INTERFACE)))
  437. return -1;
  438. if (send_and_recv_msgs(bss->drv, msg, netdev_info_handler, &data) == 0)
  439. return data.wiphy_idx;
  440. return -1;
  441. }
  442. static enum nl80211_iftype nl80211_get_ifmode(struct i802_bss *bss)
  443. {
  444. struct nl_msg *msg;
  445. struct wiphy_idx_data data = {
  446. .nlmode = NL80211_IFTYPE_UNSPECIFIED,
  447. .macaddr = NULL,
  448. };
  449. if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_GET_INTERFACE)))
  450. return NL80211_IFTYPE_UNSPECIFIED;
  451. if (send_and_recv_msgs(bss->drv, msg, netdev_info_handler, &data) == 0)
  452. return data.nlmode;
  453. return NL80211_IFTYPE_UNSPECIFIED;
  454. }
  455. static int nl80211_get_macaddr(struct i802_bss *bss)
  456. {
  457. struct nl_msg *msg;
  458. struct wiphy_idx_data data = {
  459. .macaddr = bss->addr,
  460. };
  461. if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_GET_INTERFACE)))
  462. return -1;
  463. return send_and_recv_msgs(bss->drv, msg, netdev_info_handler, &data);
  464. }
  465. static int nl80211_register_beacons(struct wpa_driver_nl80211_data *drv,
  466. struct nl80211_wiphy_data *w)
  467. {
  468. struct nl_msg *msg;
  469. int ret;
  470. msg = nlmsg_alloc();
  471. if (!msg)
  472. return -1;
  473. if (!nl80211_cmd(drv, msg, 0, NL80211_CMD_REGISTER_BEACONS) ||
  474. nla_put_u32(msg, NL80211_ATTR_WIPHY, w->wiphy_idx)) {
  475. nlmsg_free(msg);
  476. return -1;
  477. }
  478. ret = send_and_recv(drv->global, w->nl_beacons, msg, NULL, NULL);
  479. if (ret) {
  480. wpa_printf(MSG_DEBUG, "nl80211: Register beacons command "
  481. "failed: ret=%d (%s)",
  482. ret, strerror(-ret));
  483. }
  484. return ret;
  485. }
  486. static void nl80211_recv_beacons(int sock, void *eloop_ctx, void *handle)
  487. {
  488. struct nl80211_wiphy_data *w = eloop_ctx;
  489. int res;
  490. wpa_printf(MSG_EXCESSIVE, "nl80211: Beacon event message available");
  491. res = nl_recvmsgs(handle, w->nl_cb);
  492. if (res < 0) {
  493. wpa_printf(MSG_INFO, "nl80211: %s->nl_recvmsgs failed: %d",
  494. __func__, res);
  495. }
  496. }
  497. static int process_beacon_event(struct nl_msg *msg, void *arg)
  498. {
  499. struct nl80211_wiphy_data *w = arg;
  500. struct wpa_driver_nl80211_data *drv;
  501. struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
  502. struct nlattr *tb[NL80211_ATTR_MAX + 1];
  503. union wpa_event_data event;
  504. nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
  505. genlmsg_attrlen(gnlh, 0), NULL);
  506. if (gnlh->cmd != NL80211_CMD_FRAME) {
  507. wpa_printf(MSG_DEBUG, "nl80211: Unexpected beacon event? (%d)",
  508. gnlh->cmd);
  509. return NL_SKIP;
  510. }
  511. if (!tb[NL80211_ATTR_FRAME])
  512. return NL_SKIP;
  513. dl_list_for_each(drv, &w->drvs, struct wpa_driver_nl80211_data,
  514. wiphy_list) {
  515. os_memset(&event, 0, sizeof(event));
  516. event.rx_mgmt.frame = nla_data(tb[NL80211_ATTR_FRAME]);
  517. event.rx_mgmt.frame_len = nla_len(tb[NL80211_ATTR_FRAME]);
  518. wpa_supplicant_event(drv->ctx, EVENT_RX_MGMT, &event);
  519. }
  520. return NL_SKIP;
  521. }
  522. static struct nl80211_wiphy_data *
  523. nl80211_get_wiphy_data_ap(struct i802_bss *bss)
  524. {
  525. static DEFINE_DL_LIST(nl80211_wiphys);
  526. struct nl80211_wiphy_data *w;
  527. int wiphy_idx, found = 0;
  528. struct i802_bss *tmp_bss;
  529. if (bss->wiphy_data != NULL)
  530. return bss->wiphy_data;
  531. wiphy_idx = nl80211_get_wiphy_index(bss);
  532. dl_list_for_each(w, &nl80211_wiphys, struct nl80211_wiphy_data, list) {
  533. if (w->wiphy_idx == wiphy_idx)
  534. goto add;
  535. }
  536. /* alloc new one */
  537. w = os_zalloc(sizeof(*w));
  538. if (w == NULL)
  539. return NULL;
  540. w->wiphy_idx = wiphy_idx;
  541. dl_list_init(&w->bsss);
  542. dl_list_init(&w->drvs);
  543. w->nl_cb = nl_cb_alloc(NL_CB_DEFAULT);
  544. if (!w->nl_cb) {
  545. os_free(w);
  546. return NULL;
  547. }
  548. nl_cb_set(w->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM, no_seq_check, NULL);
  549. nl_cb_set(w->nl_cb, NL_CB_VALID, NL_CB_CUSTOM, process_beacon_event,
  550. w);
  551. w->nl_beacons = nl_create_handle(bss->drv->global->nl_cb,
  552. "wiphy beacons");
  553. if (w->nl_beacons == NULL) {
  554. os_free(w);
  555. return NULL;
  556. }
  557. if (nl80211_register_beacons(bss->drv, w)) {
  558. nl_destroy_handles(&w->nl_beacons);
  559. os_free(w);
  560. return NULL;
  561. }
  562. nl80211_register_eloop_read(&w->nl_beacons, nl80211_recv_beacons, w);
  563. dl_list_add(&nl80211_wiphys, &w->list);
  564. add:
  565. /* drv entry for this bss already there? */
  566. dl_list_for_each(tmp_bss, &w->bsss, struct i802_bss, wiphy_list) {
  567. if (tmp_bss->drv == bss->drv) {
  568. found = 1;
  569. break;
  570. }
  571. }
  572. /* if not add it */
  573. if (!found)
  574. dl_list_add(&w->drvs, &bss->drv->wiphy_list);
  575. dl_list_add(&w->bsss, &bss->wiphy_list);
  576. bss->wiphy_data = w;
  577. return w;
  578. }
  579. static void nl80211_put_wiphy_data_ap(struct i802_bss *bss)
  580. {
  581. struct nl80211_wiphy_data *w = bss->wiphy_data;
  582. struct i802_bss *tmp_bss;
  583. int found = 0;
  584. if (w == NULL)
  585. return;
  586. bss->wiphy_data = NULL;
  587. dl_list_del(&bss->wiphy_list);
  588. /* still any for this drv present? */
  589. dl_list_for_each(tmp_bss, &w->bsss, struct i802_bss, wiphy_list) {
  590. if (tmp_bss->drv == bss->drv) {
  591. found = 1;
  592. break;
  593. }
  594. }
  595. /* if not remove it */
  596. if (!found)
  597. dl_list_del(&bss->drv->wiphy_list);
  598. if (!dl_list_empty(&w->bsss))
  599. return;
  600. nl80211_destroy_eloop_handle(&w->nl_beacons);
  601. nl_cb_put(w->nl_cb);
  602. dl_list_del(&w->list);
  603. os_free(w);
  604. }
  605. static int wpa_driver_nl80211_get_bssid(void *priv, u8 *bssid)
  606. {
  607. struct i802_bss *bss = priv;
  608. struct wpa_driver_nl80211_data *drv = bss->drv;
  609. if (!drv->associated)
  610. return -1;
  611. os_memcpy(bssid, drv->bssid, ETH_ALEN);
  612. return 0;
  613. }
  614. static int wpa_driver_nl80211_get_ssid(void *priv, u8 *ssid)
  615. {
  616. struct i802_bss *bss = priv;
  617. struct wpa_driver_nl80211_data *drv = bss->drv;
  618. if (!drv->associated)
  619. return -1;
  620. os_memcpy(ssid, drv->ssid, drv->ssid_len);
  621. return drv->ssid_len;
  622. }
  623. static void wpa_driver_nl80211_event_newlink(
  624. struct wpa_driver_nl80211_data *drv, const char *ifname)
  625. {
  626. union wpa_event_data event;
  627. if (os_strcmp(drv->first_bss->ifname, ifname) == 0) {
  628. if (if_nametoindex(drv->first_bss->ifname) == 0) {
  629. wpa_printf(MSG_DEBUG, "nl80211: Interface %s does not exist - ignore RTM_NEWLINK",
  630. drv->first_bss->ifname);
  631. return;
  632. }
  633. if (!drv->if_removed)
  634. return;
  635. wpa_printf(MSG_DEBUG, "nl80211: Mark if_removed=0 for %s based on RTM_NEWLINK event",
  636. drv->first_bss->ifname);
  637. drv->if_removed = 0;
  638. }
  639. os_memset(&event, 0, sizeof(event));
  640. os_strlcpy(event.interface_status.ifname, ifname,
  641. sizeof(event.interface_status.ifname));
  642. event.interface_status.ievent = EVENT_INTERFACE_ADDED;
  643. wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_STATUS, &event);
  644. }
  645. static void wpa_driver_nl80211_event_dellink(
  646. struct wpa_driver_nl80211_data *drv, const char *ifname)
  647. {
  648. union wpa_event_data event;
  649. if (os_strcmp(drv->first_bss->ifname, ifname) == 0) {
  650. if (drv->if_removed) {
  651. wpa_printf(MSG_DEBUG, "nl80211: if_removed already set - ignore RTM_DELLINK event for %s",
  652. ifname);
  653. return;
  654. }
  655. wpa_printf(MSG_DEBUG, "RTM_DELLINK: Interface '%s' removed - mark if_removed=1",
  656. ifname);
  657. drv->if_removed = 1;
  658. } else {
  659. wpa_printf(MSG_DEBUG, "RTM_DELLINK: Interface '%s' removed",
  660. ifname);
  661. }
  662. os_memset(&event, 0, sizeof(event));
  663. os_strlcpy(event.interface_status.ifname, ifname,
  664. sizeof(event.interface_status.ifname));
  665. event.interface_status.ievent = EVENT_INTERFACE_REMOVED;
  666. wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_STATUS, &event);
  667. }
  668. static int wpa_driver_nl80211_own_ifname(struct wpa_driver_nl80211_data *drv,
  669. u8 *buf, size_t len)
  670. {
  671. int attrlen, rta_len;
  672. struct rtattr *attr;
  673. attrlen = len;
  674. attr = (struct rtattr *) buf;
  675. rta_len = RTA_ALIGN(sizeof(struct rtattr));
  676. while (RTA_OK(attr, attrlen)) {
  677. if (attr->rta_type == IFLA_IFNAME) {
  678. if (os_strcmp(((char *) attr) + rta_len,
  679. drv->first_bss->ifname) == 0)
  680. return 1;
  681. else
  682. break;
  683. }
  684. attr = RTA_NEXT(attr, attrlen);
  685. }
  686. return 0;
  687. }
  688. static int wpa_driver_nl80211_own_ifindex(struct wpa_driver_nl80211_data *drv,
  689. int ifindex, u8 *buf, size_t len)
  690. {
  691. if (drv->ifindex == ifindex)
  692. return 1;
  693. if (drv->if_removed && wpa_driver_nl80211_own_ifname(drv, buf, len)) {
  694. nl80211_check_global(drv->global);
  695. wpa_printf(MSG_DEBUG, "nl80211: Update ifindex for a removed "
  696. "interface");
  697. wpa_driver_nl80211_finish_drv_init(drv, NULL, 0, NULL);
  698. return 1;
  699. }
  700. return 0;
  701. }
  702. static struct wpa_driver_nl80211_data *
  703. nl80211_find_drv(struct nl80211_global *global, int idx, u8 *buf, size_t len)
  704. {
  705. struct wpa_driver_nl80211_data *drv;
  706. dl_list_for_each(drv, &global->interfaces,
  707. struct wpa_driver_nl80211_data, list) {
  708. if (wpa_driver_nl80211_own_ifindex(drv, idx, buf, len) ||
  709. have_ifidx(drv, idx, IFIDX_ANY))
  710. return drv;
  711. }
  712. return NULL;
  713. }
  714. static void wpa_driver_nl80211_event_rtm_newlink(void *ctx,
  715. struct ifinfomsg *ifi,
  716. u8 *buf, size_t len)
  717. {
  718. struct nl80211_global *global = ctx;
  719. struct wpa_driver_nl80211_data *drv;
  720. int attrlen;
  721. struct rtattr *attr;
  722. u32 brid = 0;
  723. char namebuf[IFNAMSIZ];
  724. char ifname[IFNAMSIZ + 1];
  725. char extra[100], *pos, *end;
  726. drv = nl80211_find_drv(global, ifi->ifi_index, buf, len);
  727. if (!drv) {
  728. wpa_printf(MSG_DEBUG, "nl80211: Ignore RTM_NEWLINK event for foreign ifindex %d",
  729. ifi->ifi_index);
  730. return;
  731. }
  732. extra[0] = '\0';
  733. pos = extra;
  734. end = pos + sizeof(extra);
  735. ifname[0] = '\0';
  736. attrlen = len;
  737. attr = (struct rtattr *) buf;
  738. while (RTA_OK(attr, attrlen)) {
  739. switch (attr->rta_type) {
  740. case IFLA_IFNAME:
  741. if (RTA_PAYLOAD(attr) >= IFNAMSIZ)
  742. break;
  743. os_memcpy(ifname, RTA_DATA(attr), RTA_PAYLOAD(attr));
  744. ifname[RTA_PAYLOAD(attr)] = '\0';
  745. break;
  746. case IFLA_MASTER:
  747. brid = nla_get_u32((struct nlattr *) attr);
  748. pos += os_snprintf(pos, end - pos, " master=%u", brid);
  749. break;
  750. case IFLA_WIRELESS:
  751. pos += os_snprintf(pos, end - pos, " wext");
  752. break;
  753. case IFLA_OPERSTATE:
  754. pos += os_snprintf(pos, end - pos, " operstate=%u",
  755. nla_get_u32((struct nlattr *) attr));
  756. break;
  757. case IFLA_LINKMODE:
  758. pos += os_snprintf(pos, end - pos, " linkmode=%u",
  759. nla_get_u32((struct nlattr *) attr));
  760. break;
  761. }
  762. attr = RTA_NEXT(attr, attrlen);
  763. }
  764. extra[sizeof(extra) - 1] = '\0';
  765. wpa_printf(MSG_DEBUG, "RTM_NEWLINK: ifi_index=%d ifname=%s%s ifi_family=%d ifi_flags=0x%x (%s%s%s%s)",
  766. ifi->ifi_index, ifname, extra, ifi->ifi_family,
  767. ifi->ifi_flags,
  768. (ifi->ifi_flags & IFF_UP) ? "[UP]" : "",
  769. (ifi->ifi_flags & IFF_RUNNING) ? "[RUNNING]" : "",
  770. (ifi->ifi_flags & IFF_LOWER_UP) ? "[LOWER_UP]" : "",
  771. (ifi->ifi_flags & IFF_DORMANT) ? "[DORMANT]" : "");
  772. if (!drv->if_disabled && !(ifi->ifi_flags & IFF_UP)) {
  773. namebuf[0] = '\0';
  774. if (if_indextoname(ifi->ifi_index, namebuf) &&
  775. linux_iface_up(drv->global->ioctl_sock, namebuf) > 0) {
  776. wpa_printf(MSG_DEBUG, "nl80211: Ignore interface down "
  777. "event since interface %s is up", namebuf);
  778. drv->ignore_if_down_event = 0;
  779. return;
  780. }
  781. wpa_printf(MSG_DEBUG, "nl80211: Interface down (%s/%s)",
  782. namebuf, ifname);
  783. if (os_strcmp(drv->first_bss->ifname, ifname) != 0) {
  784. wpa_printf(MSG_DEBUG,
  785. "nl80211: Not the main interface (%s) - do not indicate interface down",
  786. drv->first_bss->ifname);
  787. } else if (drv->ignore_if_down_event) {
  788. wpa_printf(MSG_DEBUG, "nl80211: Ignore interface down "
  789. "event generated by mode change");
  790. drv->ignore_if_down_event = 0;
  791. } else {
  792. drv->if_disabled = 1;
  793. wpa_supplicant_event(drv->ctx,
  794. EVENT_INTERFACE_DISABLED, NULL);
  795. /*
  796. * Try to get drv again, since it may be removed as
  797. * part of the EVENT_INTERFACE_DISABLED handling for
  798. * dynamic interfaces
  799. */
  800. drv = nl80211_find_drv(global, ifi->ifi_index,
  801. buf, len);
  802. if (!drv)
  803. return;
  804. }
  805. }
  806. if (drv->if_disabled && (ifi->ifi_flags & IFF_UP)) {
  807. if (if_indextoname(ifi->ifi_index, namebuf) &&
  808. linux_iface_up(drv->global->ioctl_sock, namebuf) == 0) {
  809. wpa_printf(MSG_DEBUG, "nl80211: Ignore interface up "
  810. "event since interface %s is down",
  811. namebuf);
  812. } else if (if_nametoindex(drv->first_bss->ifname) == 0) {
  813. wpa_printf(MSG_DEBUG, "nl80211: Ignore interface up "
  814. "event since interface %s does not exist",
  815. drv->first_bss->ifname);
  816. } else if (drv->if_removed) {
  817. wpa_printf(MSG_DEBUG, "nl80211: Ignore interface up "
  818. "event since interface %s is marked "
  819. "removed", drv->first_bss->ifname);
  820. } else {
  821. struct i802_bss *bss;
  822. u8 addr[ETH_ALEN];
  823. /* Re-read MAC address as it may have changed */
  824. bss = get_bss_ifindex(drv, ifi->ifi_index);
  825. if (bss &&
  826. linux_get_ifhwaddr(drv->global->ioctl_sock,
  827. bss->ifname, addr) < 0) {
  828. wpa_printf(MSG_DEBUG,
  829. "nl80211: %s: failed to re-read MAC address",
  830. bss->ifname);
  831. } else if (bss &&
  832. os_memcmp(addr, bss->addr, ETH_ALEN) != 0) {
  833. wpa_printf(MSG_DEBUG,
  834. "nl80211: Own MAC address on ifindex %d (%s) changed from "
  835. MACSTR " to " MACSTR,
  836. ifi->ifi_index, bss->ifname,
  837. MAC2STR(bss->addr),
  838. MAC2STR(addr));
  839. os_memcpy(bss->addr, addr, ETH_ALEN);
  840. }
  841. wpa_printf(MSG_DEBUG, "nl80211: Interface up");
  842. drv->if_disabled = 0;
  843. wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_ENABLED,
  844. NULL);
  845. }
  846. }
  847. /*
  848. * Some drivers send the association event before the operup event--in
  849. * this case, lifting operstate in wpa_driver_nl80211_set_operstate()
  850. * fails. This will hit us when wpa_supplicant does not need to do
  851. * IEEE 802.1X authentication
  852. */
  853. if (drv->operstate == 1 &&
  854. (ifi->ifi_flags & (IFF_LOWER_UP | IFF_DORMANT)) == IFF_LOWER_UP &&
  855. !(ifi->ifi_flags & IFF_RUNNING)) {
  856. wpa_printf(MSG_DEBUG, "nl80211: Set IF_OPER_UP again based on ifi_flags and expected operstate");
  857. netlink_send_oper_ifla(drv->global->netlink, drv->ifindex,
  858. -1, IF_OPER_UP);
  859. }
  860. if (ifname[0])
  861. wpa_driver_nl80211_event_newlink(drv, ifname);
  862. if (ifi->ifi_family == AF_BRIDGE && brid) {
  863. struct i802_bss *bss;
  864. /* device has been added to bridge */
  865. if (!if_indextoname(brid, namebuf)) {
  866. wpa_printf(MSG_DEBUG,
  867. "nl80211: Could not find bridge ifname for ifindex %u",
  868. brid);
  869. return;
  870. }
  871. wpa_printf(MSG_DEBUG, "nl80211: Add ifindex %u for bridge %s",
  872. brid, namebuf);
  873. add_ifidx(drv, brid, ifi->ifi_index);
  874. for (bss = drv->first_bss; bss; bss = bss->next) {
  875. if (os_strcmp(ifname, bss->ifname) == 0) {
  876. os_strlcpy(bss->brname, namebuf, IFNAMSIZ);
  877. break;
  878. }
  879. }
  880. }
  881. }
  882. static void wpa_driver_nl80211_event_rtm_dellink(void *ctx,
  883. struct ifinfomsg *ifi,
  884. u8 *buf, size_t len)
  885. {
  886. struct nl80211_global *global = ctx;
  887. struct wpa_driver_nl80211_data *drv;
  888. int attrlen;
  889. struct rtattr *attr;
  890. u32 brid = 0;
  891. char ifname[IFNAMSIZ + 1];
  892. char extra[100], *pos, *end;
  893. drv = nl80211_find_drv(global, ifi->ifi_index, buf, len);
  894. if (!drv) {
  895. wpa_printf(MSG_DEBUG, "nl80211: Ignore RTM_DELLINK event for foreign ifindex %d",
  896. ifi->ifi_index);
  897. return;
  898. }
  899. extra[0] = '\0';
  900. pos = extra;
  901. end = pos + sizeof(extra);
  902. ifname[0] = '\0';
  903. attrlen = len;
  904. attr = (struct rtattr *) buf;
  905. while (RTA_OK(attr, attrlen)) {
  906. switch (attr->rta_type) {
  907. case IFLA_IFNAME:
  908. if (RTA_PAYLOAD(attr) >= IFNAMSIZ)
  909. break;
  910. os_memcpy(ifname, RTA_DATA(attr), RTA_PAYLOAD(attr));
  911. ifname[RTA_PAYLOAD(attr)] = '\0';
  912. break;
  913. case IFLA_MASTER:
  914. brid = nla_get_u32((struct nlattr *) attr);
  915. pos += os_snprintf(pos, end - pos, " master=%u", brid);
  916. break;
  917. case IFLA_OPERSTATE:
  918. pos += os_snprintf(pos, end - pos, " operstate=%u",
  919. nla_get_u32((struct nlattr *) attr));
  920. break;
  921. case IFLA_LINKMODE:
  922. pos += os_snprintf(pos, end - pos, " linkmode=%u",
  923. nla_get_u32((struct nlattr *) attr));
  924. break;
  925. }
  926. attr = RTA_NEXT(attr, attrlen);
  927. }
  928. extra[sizeof(extra) - 1] = '\0';
  929. wpa_printf(MSG_DEBUG, "RTM_DELLINK: ifi_index=%d ifname=%s%s ifi_family=%d ifi_flags=0x%x (%s%s%s%s)",
  930. ifi->ifi_index, ifname, extra, ifi->ifi_family,
  931. ifi->ifi_flags,
  932. (ifi->ifi_flags & IFF_UP) ? "[UP]" : "",
  933. (ifi->ifi_flags & IFF_RUNNING) ? "[RUNNING]" : "",
  934. (ifi->ifi_flags & IFF_LOWER_UP) ? "[LOWER_UP]" : "",
  935. (ifi->ifi_flags & IFF_DORMANT) ? "[DORMANT]" : "");
  936. if (ifname[0] && (ifi->ifi_family != AF_BRIDGE || !brid))
  937. wpa_driver_nl80211_event_dellink(drv, ifname);
  938. if (ifi->ifi_family == AF_BRIDGE && brid) {
  939. /* device has been removed from bridge */
  940. char namebuf[IFNAMSIZ];
  941. if (!if_indextoname(brid, namebuf)) {
  942. wpa_printf(MSG_DEBUG,
  943. "nl80211: Could not find bridge ifname for ifindex %u",
  944. brid);
  945. } else {
  946. wpa_printf(MSG_DEBUG,
  947. "nl80211: Remove ifindex %u for bridge %s",
  948. brid, namebuf);
  949. }
  950. del_ifidx(drv, brid, ifi->ifi_index);
  951. }
  952. }
  953. unsigned int nl80211_get_assoc_freq(struct wpa_driver_nl80211_data *drv)
  954. {
  955. struct nl_msg *msg;
  956. int ret;
  957. struct nl80211_bss_info_arg arg;
  958. msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SCAN);
  959. os_memset(&arg, 0, sizeof(arg));
  960. arg.drv = drv;
  961. ret = send_and_recv_msgs(drv, msg, bss_info_handler, &arg);
  962. if (ret == 0) {
  963. unsigned int freq = drv->nlmode == NL80211_IFTYPE_ADHOC ?
  964. arg.ibss_freq : arg.assoc_freq;
  965. wpa_printf(MSG_DEBUG, "nl80211: Operating frequency for the "
  966. "associated BSS from scan results: %u MHz", freq);
  967. if (freq)
  968. drv->assoc_freq = freq;
  969. return drv->assoc_freq;
  970. }
  971. wpa_printf(MSG_DEBUG, "nl80211: Scan result fetch failed: ret=%d "
  972. "(%s)", ret, strerror(-ret));
  973. return drv->assoc_freq;
  974. }
  975. static int get_link_signal(struct nl_msg *msg, void *arg)
  976. {
  977. struct nlattr *tb[NL80211_ATTR_MAX + 1];
  978. struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
  979. struct nlattr *sinfo[NL80211_STA_INFO_MAX + 1];
  980. static struct nla_policy policy[NL80211_STA_INFO_MAX + 1] = {
  981. [NL80211_STA_INFO_SIGNAL] = { .type = NLA_U8 },
  982. [NL80211_STA_INFO_SIGNAL_AVG] = { .type = NLA_U8 },
  983. [NL80211_STA_INFO_BEACON_SIGNAL_AVG] = { .type = NLA_U8 },
  984. };
  985. struct nlattr *rinfo[NL80211_RATE_INFO_MAX + 1];
  986. static struct nla_policy rate_policy[NL80211_RATE_INFO_MAX + 1] = {
  987. [NL80211_RATE_INFO_BITRATE] = { .type = NLA_U16 },
  988. [NL80211_RATE_INFO_MCS] = { .type = NLA_U8 },
  989. [NL80211_RATE_INFO_40_MHZ_WIDTH] = { .type = NLA_FLAG },
  990. [NL80211_RATE_INFO_SHORT_GI] = { .type = NLA_FLAG },
  991. };
  992. struct wpa_signal_info *sig_change = arg;
  993. nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
  994. genlmsg_attrlen(gnlh, 0), NULL);
  995. if (!tb[NL80211_ATTR_STA_INFO] ||
  996. nla_parse_nested(sinfo, NL80211_STA_INFO_MAX,
  997. tb[NL80211_ATTR_STA_INFO], policy))
  998. return NL_SKIP;
  999. if (!sinfo[NL80211_STA_INFO_SIGNAL])
  1000. return NL_SKIP;
  1001. sig_change->current_signal =
  1002. (s8) nla_get_u8(sinfo[NL80211_STA_INFO_SIGNAL]);
  1003. if (sinfo[NL80211_STA_INFO_SIGNAL_AVG])
  1004. sig_change->avg_signal =
  1005. (s8) nla_get_u8(sinfo[NL80211_STA_INFO_SIGNAL_AVG]);
  1006. else
  1007. sig_change->avg_signal = 0;
  1008. if (sinfo[NL80211_STA_INFO_BEACON_SIGNAL_AVG])
  1009. sig_change->avg_beacon_signal =
  1010. (s8)
  1011. nla_get_u8(sinfo[NL80211_STA_INFO_BEACON_SIGNAL_AVG]);
  1012. else
  1013. sig_change->avg_beacon_signal = 0;
  1014. if (sinfo[NL80211_STA_INFO_TX_BITRATE]) {
  1015. if (nla_parse_nested(rinfo, NL80211_RATE_INFO_MAX,
  1016. sinfo[NL80211_STA_INFO_TX_BITRATE],
  1017. rate_policy)) {
  1018. sig_change->current_txrate = 0;
  1019. } else {
  1020. if (rinfo[NL80211_RATE_INFO_BITRATE]) {
  1021. sig_change->current_txrate =
  1022. nla_get_u16(rinfo[
  1023. NL80211_RATE_INFO_BITRATE]) * 100;
  1024. }
  1025. }
  1026. }
  1027. return NL_SKIP;
  1028. }
  1029. int nl80211_get_link_signal(struct wpa_driver_nl80211_data *drv,
  1030. struct wpa_signal_info *sig)
  1031. {
  1032. struct nl_msg *msg;
  1033. sig->current_signal = -9999;
  1034. sig->current_txrate = 0;
  1035. if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_GET_STATION)) ||
  1036. nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, drv->bssid)) {
  1037. nlmsg_free(msg);
  1038. return -ENOBUFS;
  1039. }
  1040. return send_and_recv_msgs(drv, msg, get_link_signal, sig);
  1041. }
  1042. static int get_link_noise(struct nl_msg *msg, void *arg)
  1043. {
  1044. struct nlattr *tb[NL80211_ATTR_MAX + 1];
  1045. struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
  1046. struct nlattr *sinfo[NL80211_SURVEY_INFO_MAX + 1];
  1047. static struct nla_policy survey_policy[NL80211_SURVEY_INFO_MAX + 1] = {
  1048. [NL80211_SURVEY_INFO_FREQUENCY] = { .type = NLA_U32 },
  1049. [NL80211_SURVEY_INFO_NOISE] = { .type = NLA_U8 },
  1050. };
  1051. struct wpa_signal_info *sig_change = arg;
  1052. nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
  1053. genlmsg_attrlen(gnlh, 0), NULL);
  1054. if (!tb[NL80211_ATTR_SURVEY_INFO]) {
  1055. wpa_printf(MSG_DEBUG, "nl80211: survey data missing!");
  1056. return NL_SKIP;
  1057. }
  1058. if (nla_parse_nested(sinfo, NL80211_SURVEY_INFO_MAX,
  1059. tb[NL80211_ATTR_SURVEY_INFO],
  1060. survey_policy)) {
  1061. wpa_printf(MSG_DEBUG, "nl80211: failed to parse nested "
  1062. "attributes!");
  1063. return NL_SKIP;
  1064. }
  1065. if (!sinfo[NL80211_SURVEY_INFO_FREQUENCY])
  1066. return NL_SKIP;
  1067. if (nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]) !=
  1068. sig_change->frequency)
  1069. return NL_SKIP;
  1070. if (!sinfo[NL80211_SURVEY_INFO_NOISE])
  1071. return NL_SKIP;
  1072. sig_change->current_noise =
  1073. (s8) nla_get_u8(sinfo[NL80211_SURVEY_INFO_NOISE]);
  1074. return NL_SKIP;
  1075. }
  1076. int nl80211_get_link_noise(struct wpa_driver_nl80211_data *drv,
  1077. struct wpa_signal_info *sig_change)
  1078. {
  1079. struct nl_msg *msg;
  1080. sig_change->current_noise = 9999;
  1081. sig_change->frequency = drv->assoc_freq;
  1082. msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SURVEY);
  1083. return send_and_recv_msgs(drv, msg, get_link_noise, sig_change);
  1084. }
  1085. static void wpa_driver_nl80211_event_receive(int sock, void *eloop_ctx,
  1086. void *handle)
  1087. {
  1088. struct nl_cb *cb = eloop_ctx;
  1089. int res;
  1090. wpa_printf(MSG_MSGDUMP, "nl80211: Event message available");
  1091. res = nl_recvmsgs(handle, cb);
  1092. if (res < 0) {
  1093. wpa_printf(MSG_INFO, "nl80211: %s->nl_recvmsgs failed: %d",
  1094. __func__, res);
  1095. }
  1096. }
  1097. /**
  1098. * wpa_driver_nl80211_set_country - ask nl80211 to set the regulatory domain
  1099. * @priv: driver_nl80211 private data
  1100. * @alpha2_arg: country to which to switch to
  1101. * Returns: 0 on success, -1 on failure
  1102. *
  1103. * This asks nl80211 to set the regulatory domain for given
  1104. * country ISO / IEC alpha2.
  1105. */
  1106. static int wpa_driver_nl80211_set_country(void *priv, const char *alpha2_arg)
  1107. {
  1108. struct i802_bss *bss = priv;
  1109. struct wpa_driver_nl80211_data *drv = bss->drv;
  1110. char alpha2[3];
  1111. struct nl_msg *msg;
  1112. msg = nlmsg_alloc();
  1113. if (!msg)
  1114. return -ENOMEM;
  1115. alpha2[0] = alpha2_arg[0];
  1116. alpha2[1] = alpha2_arg[1];
  1117. alpha2[2] = '\0';
  1118. if (!nl80211_cmd(drv, msg, 0, NL80211_CMD_REQ_SET_REG) ||
  1119. nla_put_string(msg, NL80211_ATTR_REG_ALPHA2, alpha2)) {
  1120. nlmsg_free(msg);
  1121. return -EINVAL;
  1122. }
  1123. if (send_and_recv_msgs(drv, msg, NULL, NULL))
  1124. return -EINVAL;
  1125. return 0;
  1126. }
  1127. static int nl80211_get_country(struct nl_msg *msg, void *arg)
  1128. {
  1129. char *alpha2 = arg;
  1130. struct nlattr *tb_msg[NL80211_ATTR_MAX + 1];
  1131. struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
  1132. nla_parse(tb_msg, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
  1133. genlmsg_attrlen(gnlh, 0), NULL);
  1134. if (!tb_msg[NL80211_ATTR_REG_ALPHA2]) {
  1135. wpa_printf(MSG_DEBUG, "nl80211: No country information available");
  1136. return NL_SKIP;
  1137. }
  1138. os_strlcpy(alpha2, nla_data(tb_msg[NL80211_ATTR_REG_ALPHA2]), 3);
  1139. return NL_SKIP;
  1140. }
  1141. static int wpa_driver_nl80211_get_country(void *priv, char *alpha2)
  1142. {
  1143. struct i802_bss *bss = priv;
  1144. struct wpa_driver_nl80211_data *drv = bss->drv;
  1145. struct nl_msg *msg;
  1146. int ret;
  1147. msg = nlmsg_alloc();
  1148. if (!msg)
  1149. return -ENOMEM;
  1150. nl80211_cmd(drv, msg, 0, NL80211_CMD_GET_REG);
  1151. alpha2[0] = '\0';
  1152. ret = send_and_recv_msgs(drv, msg, nl80211_get_country, alpha2);
  1153. if (!alpha2[0])
  1154. ret = -1;
  1155. return ret;
  1156. }
  1157. static int wpa_driver_nl80211_init_nl_global(struct nl80211_global *global)
  1158. {
  1159. int ret;
  1160. global->nl_cb = nl_cb_alloc(NL_CB_DEFAULT);
  1161. if (global->nl_cb == NULL) {
  1162. wpa_printf(MSG_ERROR, "nl80211: Failed to allocate netlink "
  1163. "callbacks");
  1164. return -1;
  1165. }
  1166. global->nl = nl_create_handle(global->nl_cb, "nl");
  1167. if (global->nl == NULL)
  1168. goto err;
  1169. global->nl80211_id = genl_ctrl_resolve(global->nl, "nl80211");
  1170. if (global->nl80211_id < 0) {
  1171. wpa_printf(MSG_ERROR, "nl80211: 'nl80211' generic netlink not "
  1172. "found");
  1173. goto err;
  1174. }
  1175. global->nl_event = nl_create_handle(global->nl_cb, "event");
  1176. if (global->nl_event == NULL)
  1177. goto err;
  1178. ret = nl_get_multicast_id(global, "nl80211", "scan");
  1179. if (ret >= 0)
  1180. ret = nl_socket_add_membership(global->nl_event, ret);
  1181. if (ret < 0) {
  1182. wpa_printf(MSG_ERROR, "nl80211: Could not add multicast "
  1183. "membership for scan events: %d (%s)",
  1184. ret, strerror(-ret));
  1185. goto err;
  1186. }
  1187. ret = nl_get_multicast_id(global, "nl80211", "mlme");
  1188. if (ret >= 0)
  1189. ret = nl_socket_add_membership(global->nl_event, ret);
  1190. if (ret < 0) {
  1191. wpa_printf(MSG_ERROR, "nl80211: Could not add multicast "
  1192. "membership for mlme events: %d (%s)",
  1193. ret, strerror(-ret));
  1194. goto err;
  1195. }
  1196. ret = nl_get_multicast_id(global, "nl80211", "regulatory");
  1197. if (ret >= 0)
  1198. ret = nl_socket_add_membership(global->nl_event, ret);
  1199. if (ret < 0) {
  1200. wpa_printf(MSG_DEBUG, "nl80211: Could not add multicast "
  1201. "membership for regulatory events: %d (%s)",
  1202. ret, strerror(-ret));
  1203. /* Continue without regulatory events */
  1204. }
  1205. ret = nl_get_multicast_id(global, "nl80211", "vendor");
  1206. if (ret >= 0)
  1207. ret = nl_socket_add_membership(global->nl_event, ret);
  1208. if (ret < 0) {
  1209. wpa_printf(MSG_DEBUG, "nl80211: Could not add multicast "
  1210. "membership for vendor events: %d (%s)",
  1211. ret, strerror(-ret));
  1212. /* Continue without vendor events */
  1213. }
  1214. nl_cb_set(global->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM,
  1215. no_seq_check, NULL);
  1216. nl_cb_set(global->nl_cb, NL_CB_VALID, NL_CB_CUSTOM,
  1217. process_global_event, global);
  1218. nl80211_register_eloop_read(&global->nl_event,
  1219. wpa_driver_nl80211_event_receive,
  1220. global->nl_cb);
  1221. return 0;
  1222. err:
  1223. nl_destroy_handles(&global->nl_event);
  1224. nl_destroy_handles(&global->nl);
  1225. nl_cb_put(global->nl_cb);
  1226. global->nl_cb = NULL;
  1227. return -1;
  1228. }
  1229. static void nl80211_check_global(struct nl80211_global *global)
  1230. {
  1231. struct nl_handle *handle;
  1232. const char *groups[] = { "scan", "mlme", "regulatory", "vendor", NULL };
  1233. int ret;
  1234. unsigned int i;
  1235. /*
  1236. * Try to re-add memberships to handle case of cfg80211 getting reloaded
  1237. * and all registration having been cleared.
  1238. */
  1239. handle = (void *) (((intptr_t) global->nl_event) ^
  1240. ELOOP_SOCKET_INVALID);
  1241. for (i = 0; groups[i]; i++) {
  1242. ret = nl_get_multicast_id(global, "nl80211", groups[i]);
  1243. if (ret >= 0)
  1244. ret = nl_socket_add_membership(handle, ret);
  1245. if (ret < 0) {
  1246. wpa_printf(MSG_INFO,
  1247. "nl80211: Could not re-add multicast membership for %s events: %d (%s)",
  1248. groups[i], ret, strerror(-ret));
  1249. }
  1250. }
  1251. }
  1252. static void wpa_driver_nl80211_rfkill_blocked(void *ctx)
  1253. {
  1254. struct wpa_driver_nl80211_data *drv = ctx;
  1255. wpa_printf(MSG_DEBUG, "nl80211: RFKILL blocked");
  1256. /*
  1257. * rtnetlink ifdown handler will report interfaces other than the P2P
  1258. * Device interface as disabled.
  1259. */
  1260. if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE)
  1261. wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_DISABLED, NULL);
  1262. }
  1263. static void wpa_driver_nl80211_rfkill_unblocked(void *ctx)
  1264. {
  1265. struct wpa_driver_nl80211_data *drv = ctx;
  1266. wpa_printf(MSG_DEBUG, "nl80211: RFKILL unblocked");
  1267. if (i802_set_iface_flags(drv->first_bss, 1)) {
  1268. wpa_printf(MSG_DEBUG, "nl80211: Could not set interface UP "
  1269. "after rfkill unblock");
  1270. return;
  1271. }
  1272. if (is_p2p_net_interface(drv->nlmode))
  1273. nl80211_disable_11b_rates(drv, drv->ifindex, 1);
  1274. /*
  1275. * rtnetlink ifup handler will report interfaces other than the P2P
  1276. * Device interface as enabled.
  1277. */
  1278. if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE)
  1279. wpa_supplicant_event(drv->ctx, EVENT_INTERFACE_ENABLED, NULL);
  1280. }
  1281. static void wpa_driver_nl80211_handle_eapol_tx_status(int sock,
  1282. void *eloop_ctx,
  1283. void *handle)
  1284. {
  1285. struct wpa_driver_nl80211_data *drv = eloop_ctx;
  1286. u8 data[2048];
  1287. struct msghdr msg;
  1288. struct iovec entry;
  1289. u8 control[512];
  1290. struct cmsghdr *cmsg;
  1291. int res, found_ee = 0, found_wifi = 0, acked = 0;
  1292. union wpa_event_data event;
  1293. memset(&msg, 0, sizeof(msg));
  1294. msg.msg_iov = &entry;
  1295. msg.msg_iovlen = 1;
  1296. entry.iov_base = data;
  1297. entry.iov_len = sizeof(data);
  1298. msg.msg_control = &control;
  1299. msg.msg_controllen = sizeof(control);
  1300. res = recvmsg(sock, &msg, MSG_ERRQUEUE);
  1301. /* if error or not fitting 802.3 header, return */
  1302. if (res < 14)
  1303. return;
  1304. for (cmsg = CMSG_FIRSTHDR(&msg); cmsg; cmsg = CMSG_NXTHDR(&msg, cmsg))
  1305. {
  1306. if (cmsg->cmsg_level == SOL_SOCKET &&
  1307. cmsg->cmsg_type == SCM_WIFI_STATUS) {
  1308. int *ack;
  1309. found_wifi = 1;
  1310. ack = (void *)CMSG_DATA(cmsg);
  1311. acked = *ack;
  1312. }
  1313. if (cmsg->cmsg_level == SOL_PACKET &&
  1314. cmsg->cmsg_type == PACKET_TX_TIMESTAMP) {
  1315. struct sock_extended_err *err =
  1316. (struct sock_extended_err *)CMSG_DATA(cmsg);
  1317. if (err->ee_origin == SO_EE_ORIGIN_TXSTATUS)
  1318. found_ee = 1;
  1319. }
  1320. }
  1321. if (!found_ee || !found_wifi)
  1322. return;
  1323. memset(&event, 0, sizeof(event));
  1324. event.eapol_tx_status.dst = data;
  1325. event.eapol_tx_status.data = data + 14;
  1326. event.eapol_tx_status.data_len = res - 14;
  1327. event.eapol_tx_status.ack = acked;
  1328. wpa_supplicant_event(drv->ctx, EVENT_EAPOL_TX_STATUS, &event);
  1329. }
  1330. static int nl80211_init_bss(struct i802_bss *bss)
  1331. {
  1332. bss->nl_cb = nl_cb_alloc(NL_CB_DEFAULT);
  1333. if (!bss->nl_cb)
  1334. return -1;
  1335. nl_cb_set(bss->nl_cb, NL_CB_SEQ_CHECK, NL_CB_CUSTOM,
  1336. no_seq_check, NULL);
  1337. nl_cb_set(bss->nl_cb, NL_CB_VALID, NL_CB_CUSTOM,
  1338. process_bss_event, bss);
  1339. return 0;
  1340. }
  1341. static void nl80211_destroy_bss(struct i802_bss *bss)
  1342. {
  1343. nl_cb_put(bss->nl_cb);
  1344. bss->nl_cb = NULL;
  1345. }
  1346. static void
  1347. wpa_driver_nl80211_drv_init_rfkill(struct wpa_driver_nl80211_data *drv)
  1348. {
  1349. struct rfkill_config *rcfg;
  1350. if (drv->rfkill)
  1351. return;
  1352. rcfg = os_zalloc(sizeof(*rcfg));
  1353. if (!rcfg)
  1354. return;
  1355. rcfg->ctx = drv;
  1356. /* rfkill uses netdev sysfs for initialization. However, P2P Device is
  1357. * not associated with a netdev, so use the name of some other interface
  1358. * sharing the same wiphy as the P2P Device interface.
  1359. *
  1360. * Note: This is valid, as a P2P Device interface is always dynamically
  1361. * created and is created only once another wpa_s interface was added.
  1362. */
  1363. if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) {
  1364. struct nl80211_global *global = drv->global;
  1365. struct wpa_driver_nl80211_data *tmp1;
  1366. dl_list_for_each(tmp1, &global->interfaces,
  1367. struct wpa_driver_nl80211_data, list) {
  1368. if (drv == tmp1 || drv->wiphy_idx != tmp1->wiphy_idx ||
  1369. !tmp1->rfkill)
  1370. continue;
  1371. wpa_printf(MSG_DEBUG,
  1372. "nl80211: Use (%s) to initialize P2P Device rfkill",
  1373. tmp1->first_bss->ifname);
  1374. os_strlcpy(rcfg->ifname, tmp1->first_bss->ifname,
  1375. sizeof(rcfg->ifname));
  1376. break;
  1377. }
  1378. } else {
  1379. os_strlcpy(rcfg->ifname, drv->first_bss->ifname,
  1380. sizeof(rcfg->ifname));
  1381. }
  1382. rcfg->blocked_cb = wpa_driver_nl80211_rfkill_blocked;
  1383. rcfg->unblocked_cb = wpa_driver_nl80211_rfkill_unblocked;
  1384. drv->rfkill = rfkill_init(rcfg);
  1385. if (!drv->rfkill) {
  1386. wpa_printf(MSG_DEBUG, "nl80211: RFKILL status not available");
  1387. os_free(rcfg);
  1388. }
  1389. }
  1390. static void * wpa_driver_nl80211_drv_init(void *ctx, const char *ifname,
  1391. void *global_priv, int hostapd,
  1392. const u8 *set_addr,
  1393. const char *driver_params)
  1394. {
  1395. struct wpa_driver_nl80211_data *drv;
  1396. struct i802_bss *bss;
  1397. if (global_priv == NULL)
  1398. return NULL;
  1399. drv = os_zalloc(sizeof(*drv));
  1400. if (drv == NULL)
  1401. return NULL;
  1402. drv->global = global_priv;
  1403. drv->ctx = ctx;
  1404. drv->hostapd = !!hostapd;
  1405. drv->eapol_sock = -1;
  1406. /*
  1407. * There is no driver capability flag for this, so assume it is
  1408. * supported and disable this on first attempt to use if the driver
  1409. * rejects the command due to missing support.
  1410. */
  1411. drv->set_rekey_offload = 1;
  1412. drv->num_if_indices = sizeof(drv->default_if_indices) / sizeof(int);
  1413. drv->if_indices = drv->default_if_indices;
  1414. drv->if_indices_reason = drv->default_if_indices_reason;
  1415. drv->first_bss = os_zalloc(sizeof(*drv->first_bss));
  1416. if (!drv->first_bss) {
  1417. os_free(drv);
  1418. return NULL;
  1419. }
  1420. bss = drv->first_bss;
  1421. bss->drv = drv;
  1422. bss->ctx = ctx;
  1423. os_strlcpy(bss->ifname, ifname, sizeof(bss->ifname));
  1424. drv->monitor_ifidx = -1;
  1425. drv->monitor_sock = -1;
  1426. drv->eapol_tx_sock = -1;
  1427. drv->ap_scan_as_station = NL80211_IFTYPE_UNSPECIFIED;
  1428. if (nl80211_init_bss(bss))
  1429. goto failed;
  1430. if (wpa_driver_nl80211_finish_drv_init(drv, set_addr, 1, driver_params))
  1431. goto failed;
  1432. drv->eapol_tx_sock = socket(PF_PACKET, SOCK_DGRAM, 0);
  1433. if (drv->eapol_tx_sock < 0)
  1434. goto failed;
  1435. if (drv->data_tx_status) {
  1436. int enabled = 1;
  1437. if (setsockopt(drv->eapol_tx_sock, SOL_SOCKET, SO_WIFI_STATUS,
  1438. &enabled, sizeof(enabled)) < 0) {
  1439. wpa_printf(MSG_DEBUG,
  1440. "nl80211: wifi status sockopt failed\n");
  1441. drv->data_tx_status = 0;
  1442. if (!drv->use_monitor)
  1443. drv->capa.flags &=
  1444. ~WPA_DRIVER_FLAGS_EAPOL_TX_STATUS;
  1445. } else {
  1446. eloop_register_read_sock(drv->eapol_tx_sock,
  1447. wpa_driver_nl80211_handle_eapol_tx_status,
  1448. drv, NULL);
  1449. }
  1450. }
  1451. if (drv->global) {
  1452. nl80211_check_global(drv->global);
  1453. dl_list_add(&drv->global->interfaces, &drv->list);
  1454. drv->in_interface_list = 1;
  1455. }
  1456. return bss;
  1457. failed:
  1458. wpa_driver_nl80211_deinit(bss);
  1459. return NULL;
  1460. }
  1461. /**
  1462. * wpa_driver_nl80211_init - Initialize nl80211 driver interface
  1463. * @ctx: context to be used when calling wpa_supplicant functions,
  1464. * e.g., wpa_supplicant_event()
  1465. * @ifname: interface name, e.g., wlan0
  1466. * @global_priv: private driver global data from global_init()
  1467. * Returns: Pointer to private data, %NULL on failure
  1468. */
  1469. static void * wpa_driver_nl80211_init(void *ctx, const char *ifname,
  1470. void *global_priv)
  1471. {
  1472. return wpa_driver_nl80211_drv_init(ctx, ifname, global_priv, 0, NULL,
  1473. NULL);
  1474. }
  1475. static int nl80211_register_frame(struct i802_bss *bss,
  1476. struct nl_handle *nl_handle,
  1477. u16 type, const u8 *match, size_t match_len)
  1478. {
  1479. struct wpa_driver_nl80211_data *drv = bss->drv;
  1480. struct nl_msg *msg;
  1481. int ret;
  1482. char buf[30];
  1483. buf[0] = '\0';
  1484. wpa_snprintf_hex(buf, sizeof(buf), match, match_len);
  1485. wpa_printf(MSG_DEBUG, "nl80211: Register frame type=0x%x (%s) nl_handle=%p match=%s",
  1486. type, fc2str(type), nl_handle, buf);
  1487. if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_REGISTER_ACTION)) ||
  1488. nla_put_u16(msg, NL80211_ATTR_FRAME_TYPE, type) ||
  1489. nla_put(msg, NL80211_ATTR_FRAME_MATCH, match_len, match)) {
  1490. nlmsg_free(msg);
  1491. return -1;
  1492. }
  1493. ret = send_and_recv(drv->global, nl_handle, msg, NULL, NULL);
  1494. if (ret) {
  1495. wpa_printf(MSG_DEBUG, "nl80211: Register frame command "
  1496. "failed (type=%u): ret=%d (%s)",
  1497. type, ret, strerror(-ret));
  1498. wpa_hexdump(MSG_DEBUG, "nl80211: Register frame match",
  1499. match, match_len);
  1500. }
  1501. return ret;
  1502. }
  1503. static int nl80211_alloc_mgmt_handle(struct i802_bss *bss)
  1504. {
  1505. if (bss->nl_mgmt) {
  1506. wpa_printf(MSG_DEBUG, "nl80211: Mgmt reporting "
  1507. "already on! (nl_mgmt=%p)", bss->nl_mgmt);
  1508. return -1;
  1509. }
  1510. bss->nl_mgmt = nl_create_handle(bss->nl_cb, "mgmt");
  1511. if (bss->nl_mgmt == NULL)
  1512. return -1;
  1513. return 0;
  1514. }
  1515. static void nl80211_mgmt_handle_register_eloop(struct i802_bss *bss)
  1516. {
  1517. nl80211_register_eloop_read(&bss->nl_mgmt,
  1518. wpa_driver_nl80211_event_receive,
  1519. bss->nl_cb);
  1520. }
  1521. static int nl80211_register_action_frame(struct i802_bss *bss,
  1522. const u8 *match, size_t match_len)
  1523. {
  1524. u16 type = (WLAN_FC_TYPE_MGMT << 2) | (WLAN_FC_STYPE_ACTION << 4);
  1525. return nl80211_register_frame(bss, bss->nl_mgmt,
  1526. type, match, match_len);
  1527. }
  1528. static int nl80211_mgmt_subscribe_non_ap(struct i802_bss *bss)
  1529. {
  1530. struct wpa_driver_nl80211_data *drv = bss->drv;
  1531. int ret = 0;
  1532. if (nl80211_alloc_mgmt_handle(bss))
  1533. return -1;
  1534. wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with non-AP "
  1535. "handle %p", bss->nl_mgmt);
  1536. if (drv->nlmode == NL80211_IFTYPE_ADHOC) {
  1537. u16 type = (WLAN_FC_TYPE_MGMT << 2) | (WLAN_FC_STYPE_AUTH << 4);
  1538. /* register for any AUTH message */
  1539. nl80211_register_frame(bss, bss->nl_mgmt, type, NULL, 0);
  1540. }
  1541. #ifdef CONFIG_INTERWORKING
  1542. /* QoS Map Configure */
  1543. if (nl80211_register_action_frame(bss, (u8 *) "\x01\x04", 2) < 0)
  1544. ret = -1;
  1545. #endif /* CONFIG_INTERWORKING */
  1546. #if defined(CONFIG_P2P) || defined(CONFIG_INTERWORKING)
  1547. /* GAS Initial Request */
  1548. if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0a", 2) < 0)
  1549. ret = -1;
  1550. /* GAS Initial Response */
  1551. if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0b", 2) < 0)
  1552. ret = -1;
  1553. /* GAS Comeback Request */
  1554. if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0c", 2) < 0)
  1555. ret = -1;
  1556. /* GAS Comeback Response */
  1557. if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0d", 2) < 0)
  1558. ret = -1;
  1559. /* Protected GAS Initial Request */
  1560. if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0a", 2) < 0)
  1561. ret = -1;
  1562. /* Protected GAS Initial Response */
  1563. if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0b", 2) < 0)
  1564. ret = -1;
  1565. /* Protected GAS Comeback Request */
  1566. if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0c", 2) < 0)
  1567. ret = -1;
  1568. /* Protected GAS Comeback Response */
  1569. if (nl80211_register_action_frame(bss, (u8 *) "\x09\x0d", 2) < 0)
  1570. ret = -1;
  1571. #endif /* CONFIG_P2P || CONFIG_INTERWORKING */
  1572. #ifdef CONFIG_P2P
  1573. /* P2P Public Action */
  1574. if (nl80211_register_action_frame(bss,
  1575. (u8 *) "\x04\x09\x50\x6f\x9a\x09",
  1576. 6) < 0)
  1577. ret = -1;
  1578. /* P2P Action */
  1579. if (nl80211_register_action_frame(bss,
  1580. (u8 *) "\x7f\x50\x6f\x9a\x09",
  1581. 5) < 0)
  1582. ret = -1;
  1583. #endif /* CONFIG_P2P */
  1584. #ifdef CONFIG_IEEE80211W
  1585. /* SA Query Response */
  1586. if (nl80211_register_action_frame(bss, (u8 *) "\x08\x01", 2) < 0)
  1587. ret = -1;
  1588. #endif /* CONFIG_IEEE80211W */
  1589. #ifdef CONFIG_TDLS
  1590. if ((drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT)) {
  1591. /* TDLS Discovery Response */
  1592. if (nl80211_register_action_frame(bss, (u8 *) "\x04\x0e", 2) <
  1593. 0)
  1594. ret = -1;
  1595. }
  1596. #endif /* CONFIG_TDLS */
  1597. #ifdef CONFIG_FST
  1598. /* FST Action frames */
  1599. if (nl80211_register_action_frame(bss, (u8 *) "\x12", 1) < 0)
  1600. ret = -1;
  1601. #endif /* CONFIG_FST */
  1602. /* FT Action frames */
  1603. if (nl80211_register_action_frame(bss, (u8 *) "\x06", 1) < 0)
  1604. ret = -1;
  1605. else
  1606. drv->capa.key_mgmt |= WPA_DRIVER_CAPA_KEY_MGMT_FT |
  1607. WPA_DRIVER_CAPA_KEY_MGMT_FT_PSK;
  1608. /* WNM - BSS Transition Management Request */
  1609. if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x07", 2) < 0)
  1610. ret = -1;
  1611. /* WNM-Sleep Mode Response */
  1612. if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x11", 2) < 0)
  1613. ret = -1;
  1614. #ifdef CONFIG_HS20
  1615. /* WNM-Notification */
  1616. if (nl80211_register_action_frame(bss, (u8 *) "\x0a\x1a", 2) < 0)
  1617. ret = -1;
  1618. #endif /* CONFIG_HS20 */
  1619. /* WMM-AC ADDTS Response */
  1620. if (nl80211_register_action_frame(bss, (u8 *) "\x11\x01", 2) < 0)
  1621. ret = -1;
  1622. /* WMM-AC DELTS */
  1623. if (nl80211_register_action_frame(bss, (u8 *) "\x11\x02", 2) < 0)
  1624. ret = -1;
  1625. /* Radio Measurement - Neighbor Report Response */
  1626. if (nl80211_register_action_frame(bss, (u8 *) "\x05\x05", 2) < 0)
  1627. ret = -1;
  1628. /* Radio Measurement - Link Measurement Request */
  1629. if ((drv->capa.rrm_flags & WPA_DRIVER_FLAGS_TX_POWER_INSERTION) &&
  1630. (nl80211_register_action_frame(bss, (u8 *) "\x05\x02", 2) < 0))
  1631. ret = -1;
  1632. nl80211_mgmt_handle_register_eloop(bss);
  1633. return ret;
  1634. }
  1635. static int nl80211_mgmt_subscribe_mesh(struct i802_bss *bss)
  1636. {
  1637. int ret = 0;
  1638. if (nl80211_alloc_mgmt_handle(bss))
  1639. return -1;
  1640. wpa_printf(MSG_DEBUG,
  1641. "nl80211: Subscribe to mgmt frames with mesh handle %p",
  1642. bss->nl_mgmt);
  1643. /* Auth frames for mesh SAE */
  1644. if (nl80211_register_frame(bss, bss->nl_mgmt,
  1645. (WLAN_FC_TYPE_MGMT << 2) |
  1646. (WLAN_FC_STYPE_AUTH << 4),
  1647. NULL, 0) < 0)
  1648. ret = -1;
  1649. /* Mesh peering open */
  1650. if (nl80211_register_action_frame(bss, (u8 *) "\x0f\x01", 2) < 0)
  1651. ret = -1;
  1652. /* Mesh peering confirm */
  1653. if (nl80211_register_action_frame(bss, (u8 *) "\x0f\x02", 2) < 0)
  1654. ret = -1;
  1655. /* Mesh peering close */
  1656. if (nl80211_register_action_frame(bss, (u8 *) "\x0f\x03", 2) < 0)
  1657. ret = -1;
  1658. nl80211_mgmt_handle_register_eloop(bss);
  1659. return ret;
  1660. }
  1661. static int nl80211_register_spurious_class3(struct i802_bss *bss)
  1662. {
  1663. struct nl_msg *msg;
  1664. int ret;
  1665. msg = nl80211_bss_msg(bss, 0, NL80211_CMD_UNEXPECTED_FRAME);
  1666. ret = send_and_recv(bss->drv->global, bss->nl_mgmt, msg, NULL, NULL);
  1667. if (ret) {
  1668. wpa_printf(MSG_DEBUG, "nl80211: Register spurious class3 "
  1669. "failed: ret=%d (%s)",
  1670. ret, strerror(-ret));
  1671. }
  1672. return ret;
  1673. }
  1674. static int nl80211_mgmt_subscribe_ap(struct i802_bss *bss)
  1675. {
  1676. static const int stypes[] = {
  1677. WLAN_FC_STYPE_AUTH,
  1678. WLAN_FC_STYPE_ASSOC_REQ,
  1679. WLAN_FC_STYPE_REASSOC_REQ,
  1680. WLAN_FC_STYPE_DISASSOC,
  1681. WLAN_FC_STYPE_DEAUTH,
  1682. WLAN_FC_STYPE_ACTION,
  1683. WLAN_FC_STYPE_PROBE_REQ,
  1684. /* Beacon doesn't work as mac80211 doesn't currently allow
  1685. * it, but it wouldn't really be the right thing anyway as
  1686. * it isn't per interface ... maybe just dump the scan
  1687. * results periodically for OLBC?
  1688. */
  1689. /* WLAN_FC_STYPE_BEACON, */
  1690. };
  1691. unsigned int i;
  1692. if (nl80211_alloc_mgmt_handle(bss))
  1693. return -1;
  1694. wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with AP "
  1695. "handle %p", bss->nl_mgmt);
  1696. for (i = 0; i < ARRAY_SIZE(stypes); i++) {
  1697. if (nl80211_register_frame(bss, bss->nl_mgmt,
  1698. (WLAN_FC_TYPE_MGMT << 2) |
  1699. (stypes[i] << 4),
  1700. NULL, 0) < 0) {
  1701. goto out_err;
  1702. }
  1703. }
  1704. if (nl80211_register_spurious_class3(bss))
  1705. goto out_err;
  1706. if (nl80211_get_wiphy_data_ap(bss) == NULL)
  1707. goto out_err;
  1708. nl80211_mgmt_handle_register_eloop(bss);
  1709. return 0;
  1710. out_err:
  1711. nl_destroy_handles(&bss->nl_mgmt);
  1712. return -1;
  1713. }
  1714. static int nl80211_mgmt_subscribe_ap_dev_sme(struct i802_bss *bss)
  1715. {
  1716. if (nl80211_alloc_mgmt_handle(bss))
  1717. return -1;
  1718. wpa_printf(MSG_DEBUG, "nl80211: Subscribe to mgmt frames with AP "
  1719. "handle %p (device SME)", bss->nl_mgmt);
  1720. if (nl80211_register_frame(bss, bss->nl_mgmt,
  1721. (WLAN_FC_TYPE_MGMT << 2) |
  1722. (WLAN_FC_STYPE_ACTION << 4),
  1723. NULL, 0) < 0)
  1724. goto out_err;
  1725. nl80211_mgmt_handle_register_eloop(bss);
  1726. return 0;
  1727. out_err:
  1728. nl_destroy_handles(&bss->nl_mgmt);
  1729. return -1;
  1730. }
  1731. static void nl80211_mgmt_unsubscribe(struct i802_bss *bss, const char *reason)
  1732. {
  1733. if (bss->nl_mgmt == NULL)
  1734. return;
  1735. wpa_printf(MSG_DEBUG, "nl80211: Unsubscribe mgmt frames handle %p "
  1736. "(%s)", bss->nl_mgmt, reason);
  1737. nl80211_destroy_eloop_handle(&bss->nl_mgmt);
  1738. nl80211_put_wiphy_data_ap(bss);
  1739. }
  1740. static void wpa_driver_nl80211_send_rfkill(void *eloop_ctx, void *timeout_ctx)
  1741. {
  1742. wpa_supplicant_event(timeout_ctx, EVENT_INTERFACE_DISABLED, NULL);
  1743. }
  1744. static void nl80211_del_p2pdev(struct i802_bss *bss)
  1745. {
  1746. struct nl_msg *msg;
  1747. int ret;
  1748. msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_DEL_INTERFACE);
  1749. ret = send_and_recv_msgs(bss->drv, msg, NULL, NULL);
  1750. wpa_printf(MSG_DEBUG, "nl80211: Delete P2P Device %s (0x%llx): %s",
  1751. bss->ifname, (long long unsigned int) bss->wdev_id,
  1752. strerror(-ret));
  1753. }
  1754. static int nl80211_set_p2pdev(struct i802_bss *bss, int start)
  1755. {
  1756. struct nl_msg *msg;
  1757. int ret;
  1758. msg = nl80211_cmd_msg(bss, 0, start ? NL80211_CMD_START_P2P_DEVICE :
  1759. NL80211_CMD_STOP_P2P_DEVICE);
  1760. ret = send_and_recv_msgs(bss->drv, msg, NULL, NULL);
  1761. wpa_printf(MSG_DEBUG, "nl80211: %s P2P Device %s (0x%llx): %s",
  1762. start ? "Start" : "Stop",
  1763. bss->ifname, (long long unsigned int) bss->wdev_id,
  1764. strerror(-ret));
  1765. return ret;
  1766. }
  1767. static int i802_set_iface_flags(struct i802_bss *bss, int up)
  1768. {
  1769. enum nl80211_iftype nlmode;
  1770. nlmode = nl80211_get_ifmode(bss);
  1771. if (nlmode != NL80211_IFTYPE_P2P_DEVICE) {
  1772. return linux_set_iface_flags(bss->drv->global->ioctl_sock,
  1773. bss->ifname, up);
  1774. }
  1775. /* P2P Device has start/stop which is equivalent */
  1776. return nl80211_set_p2pdev(bss, up);
  1777. }
  1778. #ifdef CONFIG_TESTING_OPTIONS
  1779. static int qca_vendor_test_cmd_handler(struct nl_msg *msg, void *arg)
  1780. {
  1781. /* struct wpa_driver_nl80211_data *drv = arg; */
  1782. struct nlattr *tb[NL80211_ATTR_MAX + 1];
  1783. struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
  1784. wpa_printf(MSG_DEBUG,
  1785. "nl80211: QCA vendor test command response received");
  1786. nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
  1787. genlmsg_attrlen(gnlh, 0), NULL);
  1788. if (!tb[NL80211_ATTR_VENDOR_DATA]) {
  1789. wpa_printf(MSG_DEBUG, "nl80211: No vendor data attribute");
  1790. return NL_SKIP;
  1791. }
  1792. wpa_hexdump(MSG_DEBUG,
  1793. "nl80211: Received QCA vendor test command response",
  1794. nla_data(tb[NL80211_ATTR_VENDOR_DATA]),
  1795. nla_len(tb[NL80211_ATTR_VENDOR_DATA]));
  1796. return NL_SKIP;
  1797. }
  1798. #endif /* CONFIG_TESTING_OPTIONS */
  1799. static void qca_vendor_test(struct wpa_driver_nl80211_data *drv)
  1800. {
  1801. #ifdef CONFIG_TESTING_OPTIONS
  1802. struct nl_msg *msg;
  1803. struct nlattr *params;
  1804. int ret;
  1805. if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
  1806. nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
  1807. nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
  1808. QCA_NL80211_VENDOR_SUBCMD_TEST) ||
  1809. !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
  1810. nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_TEST, 123)) {
  1811. nlmsg_free(msg);
  1812. return;
  1813. }
  1814. nla_nest_end(msg, params);
  1815. ret = send_and_recv_msgs(drv, msg, qca_vendor_test_cmd_handler, drv);
  1816. wpa_printf(MSG_DEBUG,
  1817. "nl80211: QCA vendor test command returned %d (%s)",
  1818. ret, strerror(-ret));
  1819. #endif /* CONFIG_TESTING_OPTIONS */
  1820. }
  1821. static int
  1822. wpa_driver_nl80211_finish_drv_init(struct wpa_driver_nl80211_data *drv,
  1823. const u8 *set_addr, int first,
  1824. const char *driver_params)
  1825. {
  1826. struct i802_bss *bss = drv->first_bss;
  1827. int send_rfkill_event = 0;
  1828. enum nl80211_iftype nlmode;
  1829. drv->ifindex = if_nametoindex(bss->ifname);
  1830. bss->ifindex = drv->ifindex;
  1831. bss->wdev_id = drv->global->if_add_wdevid;
  1832. bss->wdev_id_set = drv->global->if_add_wdevid_set;
  1833. bss->if_dynamic = drv->ifindex == drv->global->if_add_ifindex;
  1834. bss->if_dynamic = bss->if_dynamic || drv->global->if_add_wdevid_set;
  1835. drv->global->if_add_wdevid_set = 0;
  1836. if (!bss->if_dynamic && nl80211_get_ifmode(bss) == NL80211_IFTYPE_AP)
  1837. bss->static_ap = 1;
  1838. if (first &&
  1839. nl80211_get_ifmode(bss) != NL80211_IFTYPE_P2P_DEVICE &&
  1840. linux_iface_up(drv->global->ioctl_sock, bss->ifname) > 0)
  1841. drv->start_iface_up = 1;
  1842. if (wpa_driver_nl80211_capa(drv))
  1843. return -1;
  1844. if (driver_params && nl80211_set_param(bss, driver_params) < 0)
  1845. return -1;
  1846. wpa_printf(MSG_DEBUG, "nl80211: interface %s in phy %s",
  1847. bss->ifname, drv->phyname);
  1848. if (set_addr &&
  1849. (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 0) ||
  1850. linux_set_ifhwaddr(drv->global->ioctl_sock, bss->ifname,
  1851. set_addr)))
  1852. return -1;
  1853. if (first && nl80211_get_ifmode(bss) == NL80211_IFTYPE_AP)
  1854. drv->start_mode_ap = 1;
  1855. if (drv->hostapd || bss->static_ap)
  1856. nlmode = NL80211_IFTYPE_AP;
  1857. else if (bss->if_dynamic)
  1858. nlmode = nl80211_get_ifmode(bss);
  1859. else
  1860. nlmode = NL80211_IFTYPE_STATION;
  1861. if (wpa_driver_nl80211_set_mode(bss, nlmode) < 0) {
  1862. wpa_printf(MSG_ERROR, "nl80211: Could not configure driver mode");
  1863. return -1;
  1864. }
  1865. if (nlmode == NL80211_IFTYPE_P2P_DEVICE)
  1866. nl80211_get_macaddr(bss);
  1867. wpa_driver_nl80211_drv_init_rfkill(drv);
  1868. if (!rfkill_is_blocked(drv->rfkill)) {
  1869. int ret = i802_set_iface_flags(bss, 1);
  1870. if (ret) {
  1871. wpa_printf(MSG_ERROR, "nl80211: Could not set "
  1872. "interface '%s' UP", bss->ifname);
  1873. return ret;
  1874. }
  1875. if (is_p2p_net_interface(nlmode))
  1876. nl80211_disable_11b_rates(bss->drv,
  1877. bss->drv->ifindex, 1);
  1878. if (nlmode == NL80211_IFTYPE_P2P_DEVICE)
  1879. return ret;
  1880. } else {
  1881. wpa_printf(MSG_DEBUG, "nl80211: Could not yet enable "
  1882. "interface '%s' due to rfkill", bss->ifname);
  1883. if (nlmode != NL80211_IFTYPE_P2P_DEVICE)
  1884. drv->if_disabled = 1;
  1885. send_rfkill_event = 1;
  1886. }
  1887. if (!drv->hostapd && nlmode != NL80211_IFTYPE_P2P_DEVICE)
  1888. netlink_send_oper_ifla(drv->global->netlink, drv->ifindex,
  1889. 1, IF_OPER_DORMANT);
  1890. if (nlmode != NL80211_IFTYPE_P2P_DEVICE) {
  1891. if (linux_get_ifhwaddr(drv->global->ioctl_sock, bss->ifname,
  1892. bss->addr))
  1893. return -1;
  1894. os_memcpy(drv->perm_addr, bss->addr, ETH_ALEN);
  1895. }
  1896. if (send_rfkill_event) {
  1897. eloop_register_timeout(0, 0, wpa_driver_nl80211_send_rfkill,
  1898. drv, drv->ctx);
  1899. }
  1900. if (drv->vendor_cmd_test_avail)
  1901. qca_vendor_test(drv);
  1902. return 0;
  1903. }
  1904. static int wpa_driver_nl80211_del_beacon(struct wpa_driver_nl80211_data *drv)
  1905. {
  1906. struct nl_msg *msg;
  1907. wpa_printf(MSG_DEBUG, "nl80211: Remove beacon (ifindex=%d)",
  1908. drv->ifindex);
  1909. msg = nl80211_drv_msg(drv, 0, NL80211_CMD_DEL_BEACON);
  1910. return send_and_recv_msgs(drv, msg, NULL, NULL);
  1911. }
  1912. /**
  1913. * wpa_driver_nl80211_deinit - Deinitialize nl80211 driver interface
  1914. * @bss: Pointer to private nl80211 data from wpa_driver_nl80211_init()
  1915. *
  1916. * Shut down driver interface and processing of driver events. Free
  1917. * private data buffer if one was allocated in wpa_driver_nl80211_init().
  1918. */
  1919. static void wpa_driver_nl80211_deinit(struct i802_bss *bss)
  1920. {
  1921. struct wpa_driver_nl80211_data *drv = bss->drv;
  1922. wpa_printf(MSG_INFO, "nl80211: deinit ifname=%s disabled_11b_rates=%d",
  1923. bss->ifname, drv->disabled_11b_rates);
  1924. bss->in_deinit = 1;
  1925. if (drv->data_tx_status)
  1926. eloop_unregister_read_sock(drv->eapol_tx_sock);
  1927. if (drv->eapol_tx_sock >= 0)
  1928. close(drv->eapol_tx_sock);
  1929. if (bss->nl_preq)
  1930. wpa_driver_nl80211_probe_req_report(bss, 0);
  1931. if (bss->added_if_into_bridge) {
  1932. if (linux_br_del_if(drv->global->ioctl_sock, bss->brname,
  1933. bss->ifname) < 0)
  1934. wpa_printf(MSG_INFO, "nl80211: Failed to remove "
  1935. "interface %s from bridge %s: %s",
  1936. bss->ifname, bss->brname, strerror(errno));
  1937. if (drv->rtnl_sk)
  1938. nl80211_handle_destroy(drv->rtnl_sk);
  1939. }
  1940. if (bss->added_bridge) {
  1941. if (linux_set_iface_flags(drv->global->ioctl_sock, bss->brname,
  1942. 0) < 0)
  1943. wpa_printf(MSG_INFO,
  1944. "nl80211: Could not set bridge %s down",
  1945. bss->brname);
  1946. if (linux_br_del(drv->global->ioctl_sock, bss->brname) < 0)
  1947. wpa_printf(MSG_INFO, "nl80211: Failed to remove "
  1948. "bridge %s: %s",
  1949. bss->brname, strerror(errno));
  1950. }
  1951. nl80211_remove_monitor_interface(drv);
  1952. if (is_ap_interface(drv->nlmode))
  1953. wpa_driver_nl80211_del_beacon(drv);
  1954. if (drv->eapol_sock >= 0) {
  1955. eloop_unregister_read_sock(drv->eapol_sock);
  1956. close(drv->eapol_sock);
  1957. }
  1958. if (drv->if_indices != drv->default_if_indices)
  1959. os_free(drv->if_indices);
  1960. if (drv->if_indices_reason != drv->default_if_indices_reason)
  1961. os_free(drv->if_indices_reason);
  1962. if (drv->disabled_11b_rates)
  1963. nl80211_disable_11b_rates(drv, drv->ifindex, 0);
  1964. netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, 0,
  1965. IF_OPER_UP);
  1966. eloop_cancel_timeout(wpa_driver_nl80211_send_rfkill, drv, drv->ctx);
  1967. rfkill_deinit(drv->rfkill);
  1968. eloop_cancel_timeout(wpa_driver_nl80211_scan_timeout, drv, drv->ctx);
  1969. if (!drv->start_iface_up)
  1970. (void) i802_set_iface_flags(bss, 0);
  1971. if (drv->addr_changed) {
  1972. if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname,
  1973. 0) < 0) {
  1974. wpa_printf(MSG_DEBUG,
  1975. "nl80211: Could not set interface down to restore permanent MAC address");
  1976. }
  1977. if (linux_set_ifhwaddr(drv->global->ioctl_sock, bss->ifname,
  1978. drv->perm_addr) < 0) {
  1979. wpa_printf(MSG_DEBUG,
  1980. "nl80211: Could not restore permanent MAC address");
  1981. }
  1982. }
  1983. if (drv->nlmode != NL80211_IFTYPE_P2P_DEVICE) {
  1984. if (!drv->hostapd || !drv->start_mode_ap)
  1985. wpa_driver_nl80211_set_mode(bss,
  1986. NL80211_IFTYPE_STATION);
  1987. nl80211_mgmt_unsubscribe(bss, "deinit");
  1988. } else {
  1989. nl80211_mgmt_unsubscribe(bss, "deinit");
  1990. nl80211_del_p2pdev(bss);
  1991. }
  1992. nl80211_destroy_bss(drv->first_bss);
  1993. os_free(drv->filter_ssids);
  1994. os_free(drv->auth_ie);
  1995. if (drv->in_interface_list)
  1996. dl_list_del(&drv->list);
  1997. os_free(drv->extended_capa);
  1998. os_free(drv->extended_capa_mask);
  1999. os_free(drv->first_bss);
  2000. os_free(drv);
  2001. }
  2002. static u32 wpa_alg_to_cipher_suite(enum wpa_alg alg, size_t key_len)
  2003. {
  2004. switch (alg) {
  2005. case WPA_ALG_WEP:
  2006. if (key_len == 5)
  2007. return WLAN_CIPHER_SUITE_WEP40;
  2008. return WLAN_CIPHER_SUITE_WEP104;
  2009. case WPA_ALG_TKIP:
  2010. return WLAN_CIPHER_SUITE_TKIP;
  2011. case WPA_ALG_CCMP:
  2012. return WLAN_CIPHER_SUITE_CCMP;
  2013. case WPA_ALG_GCMP:
  2014. return WLAN_CIPHER_SUITE_GCMP;
  2015. case WPA_ALG_CCMP_256:
  2016. return WLAN_CIPHER_SUITE_CCMP_256;
  2017. case WPA_ALG_GCMP_256:
  2018. return WLAN_CIPHER_SUITE_GCMP_256;
  2019. case WPA_ALG_IGTK:
  2020. return WLAN_CIPHER_SUITE_AES_CMAC;
  2021. case WPA_ALG_BIP_GMAC_128:
  2022. return WLAN_CIPHER_SUITE_BIP_GMAC_128;
  2023. case WPA_ALG_BIP_GMAC_256:
  2024. return WLAN_CIPHER_SUITE_BIP_GMAC_256;
  2025. case WPA_ALG_BIP_CMAC_256:
  2026. return WLAN_CIPHER_SUITE_BIP_CMAC_256;
  2027. case WPA_ALG_SMS4:
  2028. return WLAN_CIPHER_SUITE_SMS4;
  2029. case WPA_ALG_KRK:
  2030. return WLAN_CIPHER_SUITE_KRK;
  2031. case WPA_ALG_NONE:
  2032. case WPA_ALG_PMK:
  2033. wpa_printf(MSG_ERROR, "nl80211: Unexpected encryption algorithm %d",
  2034. alg);
  2035. return 0;
  2036. }
  2037. wpa_printf(MSG_ERROR, "nl80211: Unsupported encryption algorithm %d",
  2038. alg);
  2039. return 0;
  2040. }
  2041. static u32 wpa_cipher_to_cipher_suite(unsigned int cipher)
  2042. {
  2043. switch (cipher) {
  2044. case WPA_CIPHER_CCMP_256:
  2045. return WLAN_CIPHER_SUITE_CCMP_256;
  2046. case WPA_CIPHER_GCMP_256:
  2047. return WLAN_CIPHER_SUITE_GCMP_256;
  2048. case WPA_CIPHER_CCMP:
  2049. return WLAN_CIPHER_SUITE_CCMP;
  2050. case WPA_CIPHER_GCMP:
  2051. return WLAN_CIPHER_SUITE_GCMP;
  2052. case WPA_CIPHER_TKIP:
  2053. return WLAN_CIPHER_SUITE_TKIP;
  2054. case WPA_CIPHER_WEP104:
  2055. return WLAN_CIPHER_SUITE_WEP104;
  2056. case WPA_CIPHER_WEP40:
  2057. return WLAN_CIPHER_SUITE_WEP40;
  2058. case WPA_CIPHER_GTK_NOT_USED:
  2059. return WLAN_CIPHER_SUITE_NO_GROUP_ADDR;
  2060. }
  2061. return 0;
  2062. }
  2063. static int wpa_cipher_to_cipher_suites(unsigned int ciphers, u32 suites[],
  2064. int max_suites)
  2065. {
  2066. int num_suites = 0;
  2067. if (num_suites < max_suites && ciphers & WPA_CIPHER_CCMP_256)
  2068. suites[num_suites++] = WLAN_CIPHER_SUITE_CCMP_256;
  2069. if (num_suites < max_suites && ciphers & WPA_CIPHER_GCMP_256)
  2070. suites[num_suites++] = WLAN_CIPHER_SUITE_GCMP_256;
  2071. if (num_suites < max_suites && ciphers & WPA_CIPHER_CCMP)
  2072. suites[num_suites++] = WLAN_CIPHER_SUITE_CCMP;
  2073. if (num_suites < max_suites && ciphers & WPA_CIPHER_GCMP)
  2074. suites[num_suites++] = WLAN_CIPHER_SUITE_GCMP;
  2075. if (num_suites < max_suites && ciphers & WPA_CIPHER_TKIP)
  2076. suites[num_suites++] = WLAN_CIPHER_SUITE_TKIP;
  2077. if (num_suites < max_suites && ciphers & WPA_CIPHER_WEP104)
  2078. suites[num_suites++] = WLAN_CIPHER_SUITE_WEP104;
  2079. if (num_suites < max_suites && ciphers & WPA_CIPHER_WEP40)
  2080. suites[num_suites++] = WLAN_CIPHER_SUITE_WEP40;
  2081. return num_suites;
  2082. }
  2083. #ifdef CONFIG_DRIVER_NL80211_QCA
  2084. static int issue_key_mgmt_set_key(struct wpa_driver_nl80211_data *drv,
  2085. const u8 *key, size_t key_len)
  2086. {
  2087. struct nl_msg *msg;
  2088. int ret;
  2089. if (!(drv->capa.flags & WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD))
  2090. return 0;
  2091. if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
  2092. nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
  2093. nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
  2094. QCA_NL80211_VENDOR_SUBCMD_KEY_MGMT_SET_KEY) ||
  2095. nla_put(msg, NL80211_ATTR_VENDOR_DATA, key_len, key)) {
  2096. nl80211_nlmsg_clear(msg);
  2097. nlmsg_free(msg);
  2098. return -1;
  2099. }
  2100. ret = send_and_recv_msgs(drv, msg, NULL, (void *) -1);
  2101. if (ret) {
  2102. wpa_printf(MSG_DEBUG,
  2103. "nl80211: Key management set key failed: ret=%d (%s)",
  2104. ret, strerror(-ret));
  2105. }
  2106. return ret;
  2107. }
  2108. #endif /* CONFIG_DRIVER_NL80211_QCA */
  2109. static int wpa_driver_nl80211_set_key(const char *ifname, struct i802_bss *bss,
  2110. enum wpa_alg alg, const u8 *addr,
  2111. int key_idx, int set_tx,
  2112. const u8 *seq, size_t seq_len,
  2113. const u8 *key, size_t key_len)
  2114. {
  2115. struct wpa_driver_nl80211_data *drv = bss->drv;
  2116. int ifindex;
  2117. struct nl_msg *msg = NULL;
  2118. int ret;
  2119. int tdls = 0;
  2120. /* Ignore for P2P Device */
  2121. if (drv->nlmode == NL80211_IFTYPE_P2P_DEVICE)
  2122. return 0;
  2123. ifindex = if_nametoindex(ifname);
  2124. wpa_printf(MSG_DEBUG, "%s: ifindex=%d (%s) alg=%d addr=%p key_idx=%d "
  2125. "set_tx=%d seq_len=%lu key_len=%lu",
  2126. __func__, ifindex, ifname, alg, addr, key_idx, set_tx,
  2127. (unsigned long) seq_len, (unsigned long) key_len);
  2128. #ifdef CONFIG_TDLS
  2129. if (key_idx == -1) {
  2130. key_idx = 0;
  2131. tdls = 1;
  2132. }
  2133. #endif /* CONFIG_TDLS */
  2134. #ifdef CONFIG_DRIVER_NL80211_QCA
  2135. if (alg == WPA_ALG_PMK &&
  2136. (drv->capa.flags & WPA_DRIVER_FLAGS_KEY_MGMT_OFFLOAD)) {
  2137. wpa_printf(MSG_DEBUG, "%s: calling issue_key_mgmt_set_key",
  2138. __func__);
  2139. ret = issue_key_mgmt_set_key(drv, key, key_len);
  2140. return ret;
  2141. }
  2142. #endif /* CONFIG_DRIVER_NL80211_QCA */
  2143. if (alg == WPA_ALG_NONE) {
  2144. msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_DEL_KEY);
  2145. if (!msg)
  2146. return -ENOBUFS;
  2147. } else {
  2148. u32 suite;
  2149. suite = wpa_alg_to_cipher_suite(alg, key_len);
  2150. if (!suite)
  2151. goto fail;
  2152. msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_NEW_KEY);
  2153. if (!msg ||
  2154. nla_put(msg, NL80211_ATTR_KEY_DATA, key_len, key) ||
  2155. nla_put_u32(msg, NL80211_ATTR_KEY_CIPHER, suite))
  2156. goto fail;
  2157. wpa_hexdump_key(MSG_DEBUG, "nl80211: KEY_DATA", key, key_len);
  2158. }
  2159. if (seq && seq_len) {
  2160. if (nla_put(msg, NL80211_ATTR_KEY_SEQ, seq_len, seq))
  2161. goto fail;
  2162. wpa_hexdump(MSG_DEBUG, "nl80211: KEY_SEQ", seq, seq_len);
  2163. }
  2164. if (addr && !is_broadcast_ether_addr(addr)) {
  2165. wpa_printf(MSG_DEBUG, " addr=" MACSTR, MAC2STR(addr));
  2166. if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
  2167. goto fail;
  2168. if (alg != WPA_ALG_WEP && key_idx && !set_tx) {
  2169. wpa_printf(MSG_DEBUG, " RSN IBSS RX GTK");
  2170. if (nla_put_u32(msg, NL80211_ATTR_KEY_TYPE,
  2171. NL80211_KEYTYPE_GROUP))
  2172. goto fail;
  2173. }
  2174. } else if (addr && is_broadcast_ether_addr(addr)) {
  2175. struct nlattr *types;
  2176. wpa_printf(MSG_DEBUG, " broadcast key");
  2177. types = nla_nest_start(msg, NL80211_ATTR_KEY_DEFAULT_TYPES);
  2178. if (!types ||
  2179. nla_put_flag(msg, NL80211_KEY_DEFAULT_TYPE_MULTICAST))
  2180. goto fail;
  2181. nla_nest_end(msg, types);
  2182. }
  2183. if (nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx))
  2184. goto fail;
  2185. ret = send_and_recv_msgs(drv, msg, NULL, key ? (void *) -1 : NULL);
  2186. if ((ret == -ENOENT || ret == -ENOLINK) && alg == WPA_ALG_NONE)
  2187. ret = 0;
  2188. if (ret)
  2189. wpa_printf(MSG_DEBUG, "nl80211: set_key failed; err=%d %s)",
  2190. ret, strerror(-ret));
  2191. /*
  2192. * If we failed or don't need to set the default TX key (below),
  2193. * we're done here.
  2194. */
  2195. if (ret || !set_tx || alg == WPA_ALG_NONE || tdls)
  2196. return ret;
  2197. if (is_ap_interface(drv->nlmode) && addr &&
  2198. !is_broadcast_ether_addr(addr))
  2199. return ret;
  2200. msg = nl80211_ifindex_msg(drv, ifindex, 0, NL80211_CMD_SET_KEY);
  2201. if (!msg ||
  2202. nla_put_u8(msg, NL80211_ATTR_KEY_IDX, key_idx) ||
  2203. nla_put_flag(msg, (alg == WPA_ALG_IGTK ||
  2204. alg == WPA_ALG_BIP_GMAC_128 ||
  2205. alg == WPA_ALG_BIP_GMAC_256 ||
  2206. alg == WPA_ALG_BIP_CMAC_256) ?
  2207. NL80211_ATTR_KEY_DEFAULT_MGMT :
  2208. NL80211_ATTR_KEY_DEFAULT))
  2209. goto fail;
  2210. if (addr && is_broadcast_ether_addr(addr)) {
  2211. struct nlattr *types;
  2212. types = nla_nest_start(msg, NL80211_ATTR_KEY_DEFAULT_TYPES);
  2213. if (!types ||
  2214. nla_put_flag(msg, NL80211_KEY_DEFAULT_TYPE_MULTICAST))
  2215. goto fail;
  2216. nla_nest_end(msg, types);
  2217. } else if (addr) {
  2218. struct nlattr *types;
  2219. types = nla_nest_start(msg, NL80211_ATTR_KEY_DEFAULT_TYPES);
  2220. if (!types ||
  2221. nla_put_flag(msg, NL80211_KEY_DEFAULT_TYPE_UNICAST))
  2222. goto fail;
  2223. nla_nest_end(msg, types);
  2224. }
  2225. ret = send_and_recv_msgs(drv, msg, NULL, NULL);
  2226. if (ret == -ENOENT)
  2227. ret = 0;
  2228. if (ret)
  2229. wpa_printf(MSG_DEBUG, "nl80211: set_key default failed; "
  2230. "err=%d %s)", ret, strerror(-ret));
  2231. return ret;
  2232. fail:
  2233. nl80211_nlmsg_clear(msg);
  2234. nlmsg_free(msg);
  2235. return -ENOBUFS;
  2236. }
  2237. static int nl_add_key(struct nl_msg *msg, enum wpa_alg alg,
  2238. int key_idx, int defkey,
  2239. const u8 *seq, size_t seq_len,
  2240. const u8 *key, size_t key_len)
  2241. {
  2242. struct nlattr *key_attr = nla_nest_start(msg, NL80211_ATTR_KEY);
  2243. u32 suite;
  2244. if (!key_attr)
  2245. return -1;
  2246. suite = wpa_alg_to_cipher_suite(alg, key_len);
  2247. if (!suite)
  2248. return -1;
  2249. if (defkey && alg == WPA_ALG_IGTK) {
  2250. if (nla_put_flag(msg, NL80211_KEY_DEFAULT_MGMT))
  2251. return -1;
  2252. } else if (defkey) {
  2253. if (nla_put_flag(msg, NL80211_KEY_DEFAULT))
  2254. return -1;
  2255. }
  2256. if (nla_put_u8(msg, NL80211_KEY_IDX, key_idx) ||
  2257. nla_put_u32(msg, NL80211_KEY_CIPHER, suite) ||
  2258. (seq && seq_len &&
  2259. nla_put(msg, NL80211_KEY_SEQ, seq_len, seq)) ||
  2260. nla_put(msg, NL80211_KEY_DATA, key_len, key))
  2261. return -1;
  2262. nla_nest_end(msg, key_attr);
  2263. return 0;
  2264. }
  2265. static int nl80211_set_conn_keys(struct wpa_driver_associate_params *params,
  2266. struct nl_msg *msg)
  2267. {
  2268. int i, privacy = 0;
  2269. struct nlattr *nl_keys, *nl_key;
  2270. for (i = 0; i < 4; i++) {
  2271. if (!params->wep_key[i])
  2272. continue;
  2273. privacy = 1;
  2274. break;
  2275. }
  2276. if (params->wps == WPS_MODE_PRIVACY)
  2277. privacy = 1;
  2278. if (params->pairwise_suite &&
  2279. params->pairwise_suite != WPA_CIPHER_NONE)
  2280. privacy = 1;
  2281. if (!privacy)
  2282. return 0;
  2283. if (nla_put_flag(msg, NL80211_ATTR_PRIVACY))
  2284. return -ENOBUFS;
  2285. nl_keys = nla_nest_start(msg, NL80211_ATTR_KEYS);
  2286. if (!nl_keys)
  2287. return -ENOBUFS;
  2288. for (i = 0; i < 4; i++) {
  2289. if (!params->wep_key[i])
  2290. continue;
  2291. nl_key = nla_nest_start(msg, i);
  2292. if (!nl_key ||
  2293. nla_put(msg, NL80211_KEY_DATA, params->wep_key_len[i],
  2294. params->wep_key[i]) ||
  2295. nla_put_u32(msg, NL80211_KEY_CIPHER,
  2296. params->wep_key_len[i] == 5 ?
  2297. WLAN_CIPHER_SUITE_WEP40 :
  2298. WLAN_CIPHER_SUITE_WEP104) ||
  2299. nla_put_u8(msg, NL80211_KEY_IDX, i) ||
  2300. (i == params->wep_tx_keyidx &&
  2301. nla_put_flag(msg, NL80211_KEY_DEFAULT)))
  2302. return -ENOBUFS;
  2303. nla_nest_end(msg, nl_key);
  2304. }
  2305. nla_nest_end(msg, nl_keys);
  2306. return 0;
  2307. }
  2308. int wpa_driver_nl80211_mlme(struct wpa_driver_nl80211_data *drv,
  2309. const u8 *addr, int cmd, u16 reason_code,
  2310. int local_state_change)
  2311. {
  2312. int ret;
  2313. struct nl_msg *msg;
  2314. if (!(msg = nl80211_drv_msg(drv, 0, cmd)) ||
  2315. nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code) ||
  2316. (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
  2317. (local_state_change &&
  2318. nla_put_flag(msg, NL80211_ATTR_LOCAL_STATE_CHANGE))) {
  2319. nlmsg_free(msg);
  2320. return -1;
  2321. }
  2322. ret = send_and_recv_msgs(drv, msg, NULL, NULL);
  2323. if (ret) {
  2324. wpa_dbg(drv->ctx, MSG_DEBUG,
  2325. "nl80211: MLME command failed: reason=%u ret=%d (%s)",
  2326. reason_code, ret, strerror(-ret));
  2327. }
  2328. return ret;
  2329. }
  2330. static int wpa_driver_nl80211_disconnect(struct wpa_driver_nl80211_data *drv,
  2331. int reason_code)
  2332. {
  2333. int ret;
  2334. wpa_printf(MSG_DEBUG, "%s(reason_code=%d)", __func__, reason_code);
  2335. nl80211_mark_disconnected(drv);
  2336. /* Disconnect command doesn't need BSSID - it uses cached value */
  2337. ret = wpa_driver_nl80211_mlme(drv, NULL, NL80211_CMD_DISCONNECT,
  2338. reason_code, 0);
  2339. /*
  2340. * For locally generated disconnect, supplicant already generates a
  2341. * DEAUTH event, so ignore the event from NL80211.
  2342. */
  2343. drv->ignore_next_local_disconnect = ret == 0;
  2344. return ret;
  2345. }
  2346. static int wpa_driver_nl80211_deauthenticate(struct i802_bss *bss,
  2347. const u8 *addr, int reason_code)
  2348. {
  2349. struct wpa_driver_nl80211_data *drv = bss->drv;
  2350. int ret;
  2351. if (drv->nlmode == NL80211_IFTYPE_ADHOC) {
  2352. nl80211_mark_disconnected(drv);
  2353. return nl80211_leave_ibss(drv, 1);
  2354. }
  2355. if (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME))
  2356. return wpa_driver_nl80211_disconnect(drv, reason_code);
  2357. wpa_printf(MSG_DEBUG, "%s(addr=" MACSTR " reason_code=%d)",
  2358. __func__, MAC2STR(addr), reason_code);
  2359. nl80211_mark_disconnected(drv);
  2360. ret = wpa_driver_nl80211_mlme(drv, addr, NL80211_CMD_DEAUTHENTICATE,
  2361. reason_code, 0);
  2362. /*
  2363. * For locally generated deauthenticate, supplicant already generates a
  2364. * DEAUTH event, so ignore the event from NL80211.
  2365. */
  2366. drv->ignore_next_local_deauth = ret == 0;
  2367. return ret;
  2368. }
  2369. static void nl80211_copy_auth_params(struct wpa_driver_nl80211_data *drv,
  2370. struct wpa_driver_auth_params *params)
  2371. {
  2372. int i;
  2373. drv->auth_freq = params->freq;
  2374. drv->auth_alg = params->auth_alg;
  2375. drv->auth_wep_tx_keyidx = params->wep_tx_keyidx;
  2376. drv->auth_local_state_change = params->local_state_change;
  2377. drv->auth_p2p = params->p2p;
  2378. if (params->bssid)
  2379. os_memcpy(drv->auth_bssid_, params->bssid, ETH_ALEN);
  2380. else
  2381. os_memset(drv->auth_bssid_, 0, ETH_ALEN);
  2382. if (params->ssid) {
  2383. os_memcpy(drv->auth_ssid, params->ssid, params->ssid_len);
  2384. drv->auth_ssid_len = params->ssid_len;
  2385. } else
  2386. drv->auth_ssid_len = 0;
  2387. os_free(drv->auth_ie);
  2388. drv->auth_ie = NULL;
  2389. drv->auth_ie_len = 0;
  2390. if (params->ie) {
  2391. drv->auth_ie = os_malloc(params->ie_len);
  2392. if (drv->auth_ie) {
  2393. os_memcpy(drv->auth_ie, params->ie, params->ie_len);
  2394. drv->auth_ie_len = params->ie_len;
  2395. }
  2396. }
  2397. for (i = 0; i < 4; i++) {
  2398. if (params->wep_key[i] && params->wep_key_len[i] &&
  2399. params->wep_key_len[i] <= 16) {
  2400. os_memcpy(drv->auth_wep_key[i], params->wep_key[i],
  2401. params->wep_key_len[i]);
  2402. drv->auth_wep_key_len[i] = params->wep_key_len[i];
  2403. } else
  2404. drv->auth_wep_key_len[i] = 0;
  2405. }
  2406. }
  2407. static void nl80211_unmask_11b_rates(struct i802_bss *bss)
  2408. {
  2409. struct wpa_driver_nl80211_data *drv = bss->drv;
  2410. if (is_p2p_net_interface(drv->nlmode) || !drv->disabled_11b_rates)
  2411. return;
  2412. /*
  2413. * Looks like we failed to unmask 11b rates previously. This could
  2414. * happen, e.g., if the interface was down at the point in time when a
  2415. * P2P group was terminated.
  2416. */
  2417. wpa_printf(MSG_DEBUG,
  2418. "nl80211: Interface %s mode is for non-P2P, but 11b rates were disabled - re-enable them",
  2419. bss->ifname);
  2420. nl80211_disable_11b_rates(drv, drv->ifindex, 0);
  2421. }
  2422. static int wpa_driver_nl80211_authenticate(
  2423. struct i802_bss *bss, struct wpa_driver_auth_params *params)
  2424. {
  2425. struct wpa_driver_nl80211_data *drv = bss->drv;
  2426. int ret = -1, i;
  2427. struct nl_msg *msg;
  2428. enum nl80211_auth_type type;
  2429. enum nl80211_iftype nlmode;
  2430. int count = 0;
  2431. int is_retry;
  2432. nl80211_unmask_11b_rates(bss);
  2433. is_retry = drv->retry_auth;
  2434. drv->retry_auth = 0;
  2435. drv->ignore_deauth_event = 0;
  2436. nl80211_mark_disconnected(drv);
  2437. os_memset(drv->auth_bssid, 0, ETH_ALEN);
  2438. if (params->bssid)
  2439. os_memcpy(drv->auth_attempt_bssid, params->bssid, ETH_ALEN);
  2440. else
  2441. os_memset(drv->auth_attempt_bssid, 0, ETH_ALEN);
  2442. /* FIX: IBSS mode */
  2443. nlmode = params->p2p ?
  2444. NL80211_IFTYPE_P2P_CLIENT : NL80211_IFTYPE_STATION;
  2445. if (drv->nlmode != nlmode &&
  2446. wpa_driver_nl80211_set_mode(bss, nlmode) < 0)
  2447. return -1;
  2448. retry:
  2449. wpa_printf(MSG_DEBUG, "nl80211: Authenticate (ifindex=%d)",
  2450. drv->ifindex);
  2451. msg = nl80211_drv_msg(drv, 0, NL80211_CMD_AUTHENTICATE);
  2452. if (!msg)
  2453. goto fail;
  2454. for (i = 0; i < 4; i++) {
  2455. if (!params->wep_key[i])
  2456. continue;
  2457. wpa_driver_nl80211_set_key(bss->ifname, bss, WPA_ALG_WEP,
  2458. NULL, i,
  2459. i == params->wep_tx_keyidx, NULL, 0,
  2460. params->wep_key[i],
  2461. params->wep_key_len[i]);
  2462. if (params->wep_tx_keyidx != i)
  2463. continue;
  2464. if (nl_add_key(msg, WPA_ALG_WEP, i, 1, NULL, 0,
  2465. params->wep_key[i], params->wep_key_len[i]))
  2466. goto fail;
  2467. }
  2468. if (params->bssid) {
  2469. wpa_printf(MSG_DEBUG, " * bssid=" MACSTR,
  2470. MAC2STR(params->bssid));
  2471. if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid))
  2472. goto fail;
  2473. }
  2474. if (params->freq) {
  2475. wpa_printf(MSG_DEBUG, " * freq=%d", params->freq);
  2476. if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, params->freq))
  2477. goto fail;
  2478. }
  2479. if (params->ssid) {
  2480. wpa_hexdump_ascii(MSG_DEBUG, " * SSID",
  2481. params->ssid, params->ssid_len);
  2482. if (nla_put(msg, NL80211_ATTR_SSID, params->ssid_len,
  2483. params->ssid))
  2484. goto fail;
  2485. }
  2486. wpa_hexdump(MSG_DEBUG, " * IEs", params->ie, params->ie_len);
  2487. if (params->ie &&
  2488. nla_put(msg, NL80211_ATTR_IE, params->ie_len, params->ie))
  2489. goto fail;
  2490. if (params->sae_data) {
  2491. wpa_hexdump(MSG_DEBUG, " * SAE data", params->sae_data,
  2492. params->sae_data_len);
  2493. if (nla_put(msg, NL80211_ATTR_SAE_DATA, params->sae_data_len,
  2494. params->sae_data))
  2495. goto fail;
  2496. }
  2497. if (params->auth_alg & WPA_AUTH_ALG_OPEN)
  2498. type = NL80211_AUTHTYPE_OPEN_SYSTEM;
  2499. else if (params->auth_alg & WPA_AUTH_ALG_SHARED)
  2500. type = NL80211_AUTHTYPE_SHARED_KEY;
  2501. else if (params->auth_alg & WPA_AUTH_ALG_LEAP)
  2502. type = NL80211_AUTHTYPE_NETWORK_EAP;
  2503. else if (params->auth_alg & WPA_AUTH_ALG_FT)
  2504. type = NL80211_AUTHTYPE_FT;
  2505. else if (params->auth_alg & WPA_AUTH_ALG_SAE)
  2506. type = NL80211_AUTHTYPE_SAE;
  2507. else
  2508. goto fail;
  2509. wpa_printf(MSG_DEBUG, " * Auth Type %d", type);
  2510. if (nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, type))
  2511. goto fail;
  2512. if (params->local_state_change) {
  2513. wpa_printf(MSG_DEBUG, " * Local state change only");
  2514. if (nla_put_flag(msg, NL80211_ATTR_LOCAL_STATE_CHANGE))
  2515. goto fail;
  2516. }
  2517. ret = send_and_recv_msgs(drv, msg, NULL, NULL);
  2518. msg = NULL;
  2519. if (ret) {
  2520. wpa_dbg(drv->ctx, MSG_DEBUG,
  2521. "nl80211: MLME command failed (auth): ret=%d (%s)",
  2522. ret, strerror(-ret));
  2523. count++;
  2524. if (ret == -EALREADY && count == 1 && params->bssid &&
  2525. !params->local_state_change) {
  2526. /*
  2527. * mac80211 does not currently accept new
  2528. * authentication if we are already authenticated. As a
  2529. * workaround, force deauthentication and try again.
  2530. */
  2531. wpa_printf(MSG_DEBUG, "nl80211: Retry authentication "
  2532. "after forced deauthentication");
  2533. drv->ignore_deauth_event = 1;
  2534. wpa_driver_nl80211_deauthenticate(
  2535. bss, params->bssid,
  2536. WLAN_REASON_PREV_AUTH_NOT_VALID);
  2537. nlmsg_free(msg);
  2538. goto retry;
  2539. }
  2540. if (ret == -ENOENT && params->freq && !is_retry) {
  2541. /*
  2542. * cfg80211 has likely expired the BSS entry even
  2543. * though it was previously available in our internal
  2544. * BSS table. To recover quickly, start a single
  2545. * channel scan on the specified channel.
  2546. */
  2547. struct wpa_driver_scan_params scan;
  2548. int freqs[2];
  2549. os_memset(&scan, 0, sizeof(scan));
  2550. scan.num_ssids = 1;
  2551. if (params->ssid) {
  2552. scan.ssids[0].ssid = params->ssid;
  2553. scan.ssids[0].ssid_len = params->ssid_len;
  2554. }
  2555. freqs[0] = params->freq;
  2556. freqs[1] = 0;
  2557. scan.freqs = freqs;
  2558. wpa_printf(MSG_DEBUG, "nl80211: Trigger single "
  2559. "channel scan to refresh cfg80211 BSS "
  2560. "entry");
  2561. ret = wpa_driver_nl80211_scan(bss, &scan);
  2562. if (ret == 0) {
  2563. nl80211_copy_auth_params(drv, params);
  2564. drv->scan_for_auth = 1;
  2565. }
  2566. } else if (is_retry) {
  2567. /*
  2568. * Need to indicate this with an event since the return
  2569. * value from the retry is not delivered to core code.
  2570. */
  2571. union wpa_event_data event;
  2572. wpa_printf(MSG_DEBUG, "nl80211: Authentication retry "
  2573. "failed");
  2574. os_memset(&event, 0, sizeof(event));
  2575. os_memcpy(event.timeout_event.addr, drv->auth_bssid_,
  2576. ETH_ALEN);
  2577. wpa_supplicant_event(drv->ctx, EVENT_AUTH_TIMED_OUT,
  2578. &event);
  2579. }
  2580. } else {
  2581. wpa_printf(MSG_DEBUG,
  2582. "nl80211: Authentication request send successfully");
  2583. }
  2584. fail:
  2585. nlmsg_free(msg);
  2586. return ret;
  2587. }
  2588. int wpa_driver_nl80211_authenticate_retry(struct wpa_driver_nl80211_data *drv)
  2589. {
  2590. struct wpa_driver_auth_params params;
  2591. struct i802_bss *bss = drv->first_bss;
  2592. int i;
  2593. wpa_printf(MSG_DEBUG, "nl80211: Try to authenticate again");
  2594. os_memset(&params, 0, sizeof(params));
  2595. params.freq = drv->auth_freq;
  2596. params.auth_alg = drv->auth_alg;
  2597. params.wep_tx_keyidx = drv->auth_wep_tx_keyidx;
  2598. params.local_state_change = drv->auth_local_state_change;
  2599. params.p2p = drv->auth_p2p;
  2600. if (!is_zero_ether_addr(drv->auth_bssid_))
  2601. params.bssid = drv->auth_bssid_;
  2602. if (drv->auth_ssid_len) {
  2603. params.ssid = drv->auth_ssid;
  2604. params.ssid_len = drv->auth_ssid_len;
  2605. }
  2606. params.ie = drv->auth_ie;
  2607. params.ie_len = drv->auth_ie_len;
  2608. for (i = 0; i < 4; i++) {
  2609. if (drv->auth_wep_key_len[i]) {
  2610. params.wep_key[i] = drv->auth_wep_key[i];
  2611. params.wep_key_len[i] = drv->auth_wep_key_len[i];
  2612. }
  2613. }
  2614. drv->retry_auth = 1;
  2615. return wpa_driver_nl80211_authenticate(bss, &params);
  2616. }
  2617. static int wpa_driver_nl80211_send_frame(struct i802_bss *bss,
  2618. const void *data, size_t len,
  2619. int encrypt, int noack,
  2620. unsigned int freq, int no_cck,
  2621. int offchanok, unsigned int wait_time,
  2622. const u16 *csa_offs,
  2623. size_t csa_offs_len)
  2624. {
  2625. struct wpa_driver_nl80211_data *drv = bss->drv;
  2626. u64 cookie;
  2627. int res;
  2628. if (freq == 0 && drv->nlmode == NL80211_IFTYPE_ADHOC) {
  2629. freq = nl80211_get_assoc_freq(drv);
  2630. wpa_printf(MSG_DEBUG,
  2631. "nl80211: send_frame - Use assoc_freq=%u for IBSS",
  2632. freq);
  2633. }
  2634. if (freq == 0) {
  2635. wpa_printf(MSG_DEBUG, "nl80211: send_frame - Use bss->freq=%u",
  2636. bss->freq);
  2637. freq = bss->freq;
  2638. }
  2639. if (drv->use_monitor) {
  2640. wpa_printf(MSG_DEBUG, "nl80211: send_frame(freq=%u bss->freq=%u) -> send_monitor",
  2641. freq, bss->freq);
  2642. return nl80211_send_monitor(drv, data, len, encrypt, noack);
  2643. }
  2644. wpa_printf(MSG_DEBUG, "nl80211: send_frame -> send_frame_cmd");
  2645. res = nl80211_send_frame_cmd(bss, freq, wait_time, data, len,
  2646. &cookie, no_cck, noack, offchanok,
  2647. csa_offs, csa_offs_len);
  2648. if (res == 0 && !noack) {
  2649. const struct ieee80211_mgmt *mgmt;
  2650. u16 fc;
  2651. mgmt = (const struct ieee80211_mgmt *) data;
  2652. fc = le_to_host16(mgmt->frame_control);
  2653. if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
  2654. WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_ACTION) {
  2655. wpa_printf(MSG_MSGDUMP,
  2656. "nl80211: Update send_action_cookie from 0x%llx to 0x%llx",
  2657. (long long unsigned int)
  2658. drv->send_action_cookie,
  2659. (long long unsigned int) cookie);
  2660. drv->send_action_cookie = cookie;
  2661. }
  2662. }
  2663. return res;
  2664. }
  2665. static int wpa_driver_nl80211_send_mlme(struct i802_bss *bss, const u8 *data,
  2666. size_t data_len, int noack,
  2667. unsigned int freq, int no_cck,
  2668. int offchanok,
  2669. unsigned int wait_time,
  2670. const u16 *csa_offs,
  2671. size_t csa_offs_len)
  2672. {
  2673. struct wpa_driver_nl80211_data *drv = bss->drv;
  2674. struct ieee80211_mgmt *mgmt;
  2675. int encrypt = 1;
  2676. u16 fc;
  2677. mgmt = (struct ieee80211_mgmt *) data;
  2678. fc = le_to_host16(mgmt->frame_control);
  2679. wpa_printf(MSG_DEBUG, "nl80211: send_mlme - da= " MACSTR
  2680. " noack=%d freq=%u no_cck=%d offchanok=%d wait_time=%u fc=0x%x (%s) nlmode=%d",
  2681. MAC2STR(mgmt->da), noack, freq, no_cck, offchanok, wait_time,
  2682. fc, fc2str(fc), drv->nlmode);
  2683. if ((is_sta_interface(drv->nlmode) ||
  2684. drv->nlmode == NL80211_IFTYPE_P2P_DEVICE) &&
  2685. WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
  2686. WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_PROBE_RESP) {
  2687. /*
  2688. * The use of last_mgmt_freq is a bit of a hack,
  2689. * but it works due to the single-threaded nature
  2690. * of wpa_supplicant.
  2691. */
  2692. if (freq == 0) {
  2693. wpa_printf(MSG_DEBUG, "nl80211: Use last_mgmt_freq=%d",
  2694. drv->last_mgmt_freq);
  2695. freq = drv->last_mgmt_freq;
  2696. }
  2697. return nl80211_send_frame_cmd(bss, freq, 0,
  2698. data, data_len, NULL, 1, noack,
  2699. 1, csa_offs, csa_offs_len);
  2700. }
  2701. if (drv->device_ap_sme && is_ap_interface(drv->nlmode)) {
  2702. if (freq == 0) {
  2703. wpa_printf(MSG_DEBUG, "nl80211: Use bss->freq=%d",
  2704. bss->freq);
  2705. freq = bss->freq;
  2706. }
  2707. return nl80211_send_frame_cmd(bss, freq,
  2708. (int) freq == bss->freq ? 0 :
  2709. wait_time,
  2710. data, data_len,
  2711. &drv->send_action_cookie,
  2712. no_cck, noack, offchanok,
  2713. csa_offs, csa_offs_len);
  2714. }
  2715. if (WLAN_FC_GET_TYPE(fc) == WLAN_FC_TYPE_MGMT &&
  2716. WLAN_FC_GET_STYPE(fc) == WLAN_FC_STYPE_AUTH) {
  2717. /*
  2718. * Only one of the authentication frame types is encrypted.
  2719. * In order for static WEP encryption to work properly (i.e.,
  2720. * to not encrypt the frame), we need to tell mac80211 about
  2721. * the frames that must not be encrypted.
  2722. */
  2723. u16 auth_alg = le_to_host16(mgmt->u.auth.auth_alg);
  2724. u16 auth_trans = le_to_host16(mgmt->u.auth.auth_transaction);
  2725. if (auth_alg != WLAN_AUTH_SHARED_KEY || auth_trans != 3)
  2726. encrypt = 0;
  2727. }
  2728. wpa_printf(MSG_DEBUG, "nl80211: send_mlme -> send_frame");
  2729. return wpa_driver_nl80211_send_frame(bss, data, data_len, encrypt,
  2730. noack, freq, no_cck, offchanok,
  2731. wait_time, csa_offs,
  2732. csa_offs_len);
  2733. }
  2734. static int nl80211_put_basic_rates(struct nl_msg *msg, const int *basic_rates)
  2735. {
  2736. u8 rates[NL80211_MAX_SUPP_RATES];
  2737. u8 rates_len = 0;
  2738. int i;
  2739. if (!basic_rates)
  2740. return 0;
  2741. for (i = 0; i < NL80211_MAX_SUPP_RATES && basic_rates[i] >= 0; i++)
  2742. rates[rates_len++] = basic_rates[i] / 5;
  2743. return nla_put(msg, NL80211_ATTR_BSS_BASIC_RATES, rates_len, rates);
  2744. }
  2745. static int nl80211_set_bss(struct i802_bss *bss, int cts, int preamble,
  2746. int slot, int ht_opmode, int ap_isolate,
  2747. const int *basic_rates)
  2748. {
  2749. struct wpa_driver_nl80211_data *drv = bss->drv;
  2750. struct nl_msg *msg;
  2751. if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_BSS)) ||
  2752. (cts >= 0 &&
  2753. nla_put_u8(msg, NL80211_ATTR_BSS_CTS_PROT, cts)) ||
  2754. (preamble >= 0 &&
  2755. nla_put_u8(msg, NL80211_ATTR_BSS_SHORT_PREAMBLE, preamble)) ||
  2756. (slot >= 0 &&
  2757. nla_put_u8(msg, NL80211_ATTR_BSS_SHORT_SLOT_TIME, slot)) ||
  2758. (ht_opmode >= 0 &&
  2759. nla_put_u16(msg, NL80211_ATTR_BSS_HT_OPMODE, ht_opmode)) ||
  2760. (ap_isolate >= 0 &&
  2761. nla_put_u8(msg, NL80211_ATTR_AP_ISOLATE, ap_isolate)) ||
  2762. nl80211_put_basic_rates(msg, basic_rates)) {
  2763. nlmsg_free(msg);
  2764. return -ENOBUFS;
  2765. }
  2766. return send_and_recv_msgs(drv, msg, NULL, NULL);
  2767. }
  2768. static int wpa_driver_nl80211_set_acl(void *priv,
  2769. struct hostapd_acl_params *params)
  2770. {
  2771. struct i802_bss *bss = priv;
  2772. struct wpa_driver_nl80211_data *drv = bss->drv;
  2773. struct nl_msg *msg;
  2774. struct nl_msg *acl;
  2775. unsigned int i;
  2776. int ret;
  2777. if (!(drv->capa.max_acl_mac_addrs))
  2778. return -ENOTSUP;
  2779. if (params->num_mac_acl > drv->capa.max_acl_mac_addrs)
  2780. return -ENOTSUP;
  2781. wpa_printf(MSG_DEBUG, "nl80211: Set %s ACL (num_mac_acl=%u)",
  2782. params->acl_policy ? "Accept" : "Deny", params->num_mac_acl);
  2783. acl = nlmsg_alloc();
  2784. if (!acl)
  2785. return -ENOMEM;
  2786. for (i = 0; i < params->num_mac_acl; i++) {
  2787. if (nla_put(acl, i + 1, ETH_ALEN, params->mac_acl[i].addr)) {
  2788. nlmsg_free(acl);
  2789. return -ENOMEM;
  2790. }
  2791. }
  2792. if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_MAC_ACL)) ||
  2793. nla_put_u32(msg, NL80211_ATTR_ACL_POLICY, params->acl_policy ?
  2794. NL80211_ACL_POLICY_DENY_UNLESS_LISTED :
  2795. NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED) ||
  2796. nla_put_nested(msg, NL80211_ATTR_MAC_ADDRS, acl)) {
  2797. nlmsg_free(msg);
  2798. nlmsg_free(acl);
  2799. return -ENOMEM;
  2800. }
  2801. nlmsg_free(acl);
  2802. ret = send_and_recv_msgs(drv, msg, NULL, NULL);
  2803. if (ret) {
  2804. wpa_printf(MSG_DEBUG, "nl80211: Failed to set MAC ACL: %d (%s)",
  2805. ret, strerror(-ret));
  2806. }
  2807. return ret;
  2808. }
  2809. static int nl80211_put_beacon_int(struct nl_msg *msg, int beacon_int)
  2810. {
  2811. if (beacon_int > 0) {
  2812. wpa_printf(MSG_DEBUG, " * beacon_int=%d", beacon_int);
  2813. return nla_put_u32(msg, NL80211_ATTR_BEACON_INTERVAL,
  2814. beacon_int);
  2815. }
  2816. return 0;
  2817. }
  2818. static int wpa_driver_nl80211_set_ap(void *priv,
  2819. struct wpa_driver_ap_params *params)
  2820. {
  2821. struct i802_bss *bss = priv;
  2822. struct wpa_driver_nl80211_data *drv = bss->drv;
  2823. struct nl_msg *msg;
  2824. u8 cmd = NL80211_CMD_NEW_BEACON;
  2825. int ret;
  2826. int beacon_set;
  2827. int num_suites;
  2828. int smps_mode;
  2829. u32 suites[10], suite;
  2830. u32 ver;
  2831. beacon_set = params->reenable ? 0 : bss->beacon_set;
  2832. wpa_printf(MSG_DEBUG, "nl80211: Set beacon (beacon_set=%d)",
  2833. beacon_set);
  2834. if (beacon_set)
  2835. cmd = NL80211_CMD_SET_BEACON;
  2836. wpa_hexdump(MSG_DEBUG, "nl80211: Beacon head",
  2837. params->head, params->head_len);
  2838. wpa_hexdump(MSG_DEBUG, "nl80211: Beacon tail",
  2839. params->tail, params->tail_len);
  2840. wpa_printf(MSG_DEBUG, "nl80211: ifindex=%d", bss->ifindex);
  2841. wpa_printf(MSG_DEBUG, "nl80211: beacon_int=%d", params->beacon_int);
  2842. wpa_printf(MSG_DEBUG, "nl80211: dtim_period=%d", params->dtim_period);
  2843. wpa_hexdump_ascii(MSG_DEBUG, "nl80211: ssid",
  2844. params->ssid, params->ssid_len);
  2845. if (!(msg = nl80211_bss_msg(bss, 0, cmd)) ||
  2846. nla_put(msg, NL80211_ATTR_BEACON_HEAD, params->head_len,
  2847. params->head) ||
  2848. nla_put(msg, NL80211_ATTR_BEACON_TAIL, params->tail_len,
  2849. params->tail) ||
  2850. nl80211_put_beacon_int(msg, params->beacon_int) ||
  2851. nla_put_u32(msg, NL80211_ATTR_DTIM_PERIOD, params->dtim_period) ||
  2852. nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, params->ssid))
  2853. goto fail;
  2854. if (params->proberesp && params->proberesp_len) {
  2855. wpa_hexdump(MSG_DEBUG, "nl80211: proberesp (offload)",
  2856. params->proberesp, params->proberesp_len);
  2857. if (nla_put(msg, NL80211_ATTR_PROBE_RESP, params->proberesp_len,
  2858. params->proberesp))
  2859. goto fail;
  2860. }
  2861. switch (params->hide_ssid) {
  2862. case NO_SSID_HIDING:
  2863. wpa_printf(MSG_DEBUG, "nl80211: hidden SSID not in use");
  2864. if (nla_put_u32(msg, NL80211_ATTR_HIDDEN_SSID,
  2865. NL80211_HIDDEN_SSID_NOT_IN_USE))
  2866. goto fail;
  2867. break;
  2868. case HIDDEN_SSID_ZERO_LEN:
  2869. wpa_printf(MSG_DEBUG, "nl80211: hidden SSID zero len");
  2870. if (nla_put_u32(msg, NL80211_ATTR_HIDDEN_SSID,
  2871. NL80211_HIDDEN_SSID_ZERO_LEN))
  2872. goto fail;
  2873. break;
  2874. case HIDDEN_SSID_ZERO_CONTENTS:
  2875. wpa_printf(MSG_DEBUG, "nl80211: hidden SSID zero contents");
  2876. if (nla_put_u32(msg, NL80211_ATTR_HIDDEN_SSID,
  2877. NL80211_HIDDEN_SSID_ZERO_CONTENTS))
  2878. goto fail;
  2879. break;
  2880. }
  2881. wpa_printf(MSG_DEBUG, "nl80211: privacy=%d", params->privacy);
  2882. if (params->privacy &&
  2883. nla_put_flag(msg, NL80211_ATTR_PRIVACY))
  2884. goto fail;
  2885. wpa_printf(MSG_DEBUG, "nl80211: auth_algs=0x%x", params->auth_algs);
  2886. if ((params->auth_algs & (WPA_AUTH_ALG_OPEN | WPA_AUTH_ALG_SHARED)) ==
  2887. (WPA_AUTH_ALG_OPEN | WPA_AUTH_ALG_SHARED)) {
  2888. /* Leave out the attribute */
  2889. } else if (params->auth_algs & WPA_AUTH_ALG_SHARED) {
  2890. if (nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE,
  2891. NL80211_AUTHTYPE_SHARED_KEY))
  2892. goto fail;
  2893. } else {
  2894. if (nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE,
  2895. NL80211_AUTHTYPE_OPEN_SYSTEM))
  2896. goto fail;
  2897. }
  2898. wpa_printf(MSG_DEBUG, "nl80211: wpa_version=0x%x", params->wpa_version);
  2899. ver = 0;
  2900. if (params->wpa_version & WPA_PROTO_WPA)
  2901. ver |= NL80211_WPA_VERSION_1;
  2902. if (params->wpa_version & WPA_PROTO_RSN)
  2903. ver |= NL80211_WPA_VERSION_2;
  2904. if (ver &&
  2905. nla_put_u32(msg, NL80211_ATTR_WPA_VERSIONS, ver))
  2906. goto fail;
  2907. wpa_printf(MSG_DEBUG, "nl80211: key_mgmt_suites=0x%x",
  2908. params->key_mgmt_suites);
  2909. num_suites = 0;
  2910. if (params->key_mgmt_suites & WPA_KEY_MGMT_IEEE8021X)
  2911. suites[num_suites++] = WLAN_AKM_SUITE_8021X;
  2912. if (params->key_mgmt_suites & WPA_KEY_MGMT_PSK)
  2913. suites[num_suites++] = WLAN_AKM_SUITE_PSK;
  2914. if (num_suites &&
  2915. nla_put(msg, NL80211_ATTR_AKM_SUITES, num_suites * sizeof(u32),
  2916. suites))
  2917. goto fail;
  2918. if (params->key_mgmt_suites & WPA_KEY_MGMT_IEEE8021X_NO_WPA &&
  2919. params->pairwise_ciphers & (WPA_CIPHER_WEP104 | WPA_CIPHER_WEP40) &&
  2920. nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT))
  2921. goto fail;
  2922. wpa_printf(MSG_DEBUG, "nl80211: pairwise_ciphers=0x%x",
  2923. params->pairwise_ciphers);
  2924. num_suites = wpa_cipher_to_cipher_suites(params->pairwise_ciphers,
  2925. suites, ARRAY_SIZE(suites));
  2926. if (num_suites &&
  2927. nla_put(msg, NL80211_ATTR_CIPHER_SUITES_PAIRWISE,
  2928. num_suites * sizeof(u32), suites))
  2929. goto fail;
  2930. wpa_printf(MSG_DEBUG, "nl80211: group_cipher=0x%x",
  2931. params->group_cipher);
  2932. suite = wpa_cipher_to_cipher_suite(params->group_cipher);
  2933. if (suite &&
  2934. nla_put_u32(msg, NL80211_ATTR_CIPHER_SUITE_GROUP, suite))
  2935. goto fail;
  2936. if (params->ht_opmode != -1) {
  2937. switch (params->smps_mode) {
  2938. case HT_CAP_INFO_SMPS_DYNAMIC:
  2939. wpa_printf(MSG_DEBUG, "nl80211: SMPS mode - dynamic");
  2940. smps_mode = NL80211_SMPS_DYNAMIC;
  2941. break;
  2942. case HT_CAP_INFO_SMPS_STATIC:
  2943. wpa_printf(MSG_DEBUG, "nl80211: SMPS mode - static");
  2944. smps_mode = NL80211_SMPS_STATIC;
  2945. break;
  2946. default:
  2947. /* invalid - fallback to smps off */
  2948. case HT_CAP_INFO_SMPS_DISABLED:
  2949. wpa_printf(MSG_DEBUG, "nl80211: SMPS mode - off");
  2950. smps_mode = NL80211_SMPS_OFF;
  2951. break;
  2952. }
  2953. if (nla_put_u32(msg, NL80211_ATTR_SMPS_MODE, smps_mode))
  2954. goto fail;
  2955. }
  2956. if (params->beacon_ies) {
  2957. wpa_hexdump_buf(MSG_DEBUG, "nl80211: beacon_ies",
  2958. params->beacon_ies);
  2959. if (nla_put(msg, NL80211_ATTR_IE,
  2960. wpabuf_len(params->beacon_ies),
  2961. wpabuf_head(params->beacon_ies)))
  2962. goto fail;
  2963. }
  2964. if (params->proberesp_ies) {
  2965. wpa_hexdump_buf(MSG_DEBUG, "nl80211: proberesp_ies",
  2966. params->proberesp_ies);
  2967. if (nla_put(msg, NL80211_ATTR_IE_PROBE_RESP,
  2968. wpabuf_len(params->proberesp_ies),
  2969. wpabuf_head(params->proberesp_ies)))
  2970. goto fail;
  2971. }
  2972. if (params->assocresp_ies) {
  2973. wpa_hexdump_buf(MSG_DEBUG, "nl80211: assocresp_ies",
  2974. params->assocresp_ies);
  2975. if (nla_put(msg, NL80211_ATTR_IE_ASSOC_RESP,
  2976. wpabuf_len(params->assocresp_ies),
  2977. wpabuf_head(params->assocresp_ies)))
  2978. goto fail;
  2979. }
  2980. if (drv->capa.flags & WPA_DRIVER_FLAGS_INACTIVITY_TIMER) {
  2981. wpa_printf(MSG_DEBUG, "nl80211: ap_max_inactivity=%d",
  2982. params->ap_max_inactivity);
  2983. if (nla_put_u16(msg, NL80211_ATTR_INACTIVITY_TIMEOUT,
  2984. params->ap_max_inactivity))
  2985. goto fail;
  2986. }
  2987. #ifdef CONFIG_P2P
  2988. if (params->p2p_go_ctwindow > 0) {
  2989. if (drv->p2p_go_ctwindow_supported) {
  2990. wpa_printf(MSG_DEBUG, "nl80211: P2P GO ctwindow=%d",
  2991. params->p2p_go_ctwindow);
  2992. if (nla_put_u8(msg, NL80211_ATTR_P2P_CTWINDOW,
  2993. params->p2p_go_ctwindow))
  2994. goto fail;
  2995. } else {
  2996. wpa_printf(MSG_INFO,
  2997. "nl80211: Driver does not support CTWindow configuration - ignore this parameter");
  2998. }
  2999. }
  3000. #endif /* CONFIG_P2P */
  3001. if (params->pbss) {
  3002. wpa_printf(MSG_DEBUG, "nl80211: PBSS");
  3003. if (nla_put_flag(msg, NL80211_ATTR_PBSS))
  3004. goto fail;
  3005. }
  3006. ret = send_and_recv_msgs(drv, msg, NULL, NULL);
  3007. if (ret) {
  3008. wpa_printf(MSG_DEBUG, "nl80211: Beacon set failed: %d (%s)",
  3009. ret, strerror(-ret));
  3010. } else {
  3011. bss->beacon_set = 1;
  3012. nl80211_set_bss(bss, params->cts_protect, params->preamble,
  3013. params->short_slot_time, params->ht_opmode,
  3014. params->isolate, params->basic_rates);
  3015. if (beacon_set && params->freq &&
  3016. params->freq->bandwidth != bss->bandwidth) {
  3017. wpa_printf(MSG_DEBUG,
  3018. "nl80211: Update BSS %s bandwidth: %d -> %d",
  3019. bss->ifname, bss->bandwidth,
  3020. params->freq->bandwidth);
  3021. ret = nl80211_set_channel(bss, params->freq, 1);
  3022. if (ret) {
  3023. wpa_printf(MSG_DEBUG,
  3024. "nl80211: Frequency set failed: %d (%s)",
  3025. ret, strerror(-ret));
  3026. } else {
  3027. wpa_printf(MSG_DEBUG,
  3028. "nl80211: Frequency set succeeded for ht2040 coex");
  3029. bss->bandwidth = params->freq->bandwidth;
  3030. }
  3031. } else if (!beacon_set) {
  3032. /*
  3033. * cfg80211 updates the driver on frequence change in AP
  3034. * mode only at the point when beaconing is started, so
  3035. * set the initial value here.
  3036. */
  3037. bss->bandwidth = params->freq->bandwidth;
  3038. }
  3039. }
  3040. return ret;
  3041. fail:
  3042. nlmsg_free(msg);
  3043. return -ENOBUFS;
  3044. }
  3045. static int nl80211_put_freq_params(struct nl_msg *msg,
  3046. const struct hostapd_freq_params *freq)
  3047. {
  3048. wpa_printf(MSG_DEBUG, " * freq=%d", freq->freq);
  3049. if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq->freq))
  3050. return -ENOBUFS;
  3051. wpa_printf(MSG_DEBUG, " * vht_enabled=%d", freq->vht_enabled);
  3052. wpa_printf(MSG_DEBUG, " * ht_enabled=%d", freq->ht_enabled);
  3053. if (freq->vht_enabled) {
  3054. enum nl80211_chan_width cw;
  3055. wpa_printf(MSG_DEBUG, " * bandwidth=%d", freq->bandwidth);
  3056. switch (freq->bandwidth) {
  3057. case 20:
  3058. cw = NL80211_CHAN_WIDTH_20;
  3059. break;
  3060. case 40:
  3061. cw = NL80211_CHAN_WIDTH_40;
  3062. break;
  3063. case 80:
  3064. if (freq->center_freq2)
  3065. cw = NL80211_CHAN_WIDTH_80P80;
  3066. else
  3067. cw = NL80211_CHAN_WIDTH_80;
  3068. break;
  3069. case 160:
  3070. cw = NL80211_CHAN_WIDTH_160;
  3071. break;
  3072. default:
  3073. return -EINVAL;
  3074. }
  3075. wpa_printf(MSG_DEBUG, " * channel_width=%d", cw);
  3076. wpa_printf(MSG_DEBUG, " * center_freq1=%d",
  3077. freq->center_freq1);
  3078. wpa_printf(MSG_DEBUG, " * center_freq2=%d",
  3079. freq->center_freq2);
  3080. if (nla_put_u32(msg, NL80211_ATTR_CHANNEL_WIDTH, cw) ||
  3081. nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ1,
  3082. freq->center_freq1) ||
  3083. (freq->center_freq2 &&
  3084. nla_put_u32(msg, NL80211_ATTR_CENTER_FREQ2,
  3085. freq->center_freq2)))
  3086. return -ENOBUFS;
  3087. } else if (freq->ht_enabled) {
  3088. enum nl80211_channel_type ct;
  3089. wpa_printf(MSG_DEBUG, " * sec_channel_offset=%d",
  3090. freq->sec_channel_offset);
  3091. switch (freq->sec_channel_offset) {
  3092. case -1:
  3093. ct = NL80211_CHAN_HT40MINUS;
  3094. break;
  3095. case 1:
  3096. ct = NL80211_CHAN_HT40PLUS;
  3097. break;
  3098. default:
  3099. ct = NL80211_CHAN_HT20;
  3100. break;
  3101. }
  3102. wpa_printf(MSG_DEBUG, " * channel_type=%d", ct);
  3103. if (nla_put_u32(msg, NL80211_ATTR_WIPHY_CHANNEL_TYPE, ct))
  3104. return -ENOBUFS;
  3105. }
  3106. return 0;
  3107. }
  3108. static int nl80211_set_channel(struct i802_bss *bss,
  3109. struct hostapd_freq_params *freq, int set_chan)
  3110. {
  3111. struct wpa_driver_nl80211_data *drv = bss->drv;
  3112. struct nl_msg *msg;
  3113. int ret;
  3114. wpa_printf(MSG_DEBUG,
  3115. "nl80211: Set freq %d (ht_enabled=%d, vht_enabled=%d, bandwidth=%d MHz, cf1=%d MHz, cf2=%d MHz)",
  3116. freq->freq, freq->ht_enabled, freq->vht_enabled,
  3117. freq->bandwidth, freq->center_freq1, freq->center_freq2);
  3118. msg = nl80211_drv_msg(drv, 0, set_chan ? NL80211_CMD_SET_CHANNEL :
  3119. NL80211_CMD_SET_WIPHY);
  3120. if (!msg || nl80211_put_freq_params(msg, freq) < 0) {
  3121. nlmsg_free(msg);
  3122. return -1;
  3123. }
  3124. ret = send_and_recv_msgs(drv, msg, NULL, NULL);
  3125. if (ret == 0) {
  3126. bss->freq = freq->freq;
  3127. return 0;
  3128. }
  3129. wpa_printf(MSG_DEBUG, "nl80211: Failed to set channel (freq=%d): "
  3130. "%d (%s)", freq->freq, ret, strerror(-ret));
  3131. return -1;
  3132. }
  3133. static u32 sta_flags_nl80211(int flags)
  3134. {
  3135. u32 f = 0;
  3136. if (flags & WPA_STA_AUTHORIZED)
  3137. f |= BIT(NL80211_STA_FLAG_AUTHORIZED);
  3138. if (flags & WPA_STA_WMM)
  3139. f |= BIT(NL80211_STA_FLAG_WME);
  3140. if (flags & WPA_STA_SHORT_PREAMBLE)
  3141. f |= BIT(NL80211_STA_FLAG_SHORT_PREAMBLE);
  3142. if (flags & WPA_STA_MFP)
  3143. f |= BIT(NL80211_STA_FLAG_MFP);
  3144. if (flags & WPA_STA_TDLS_PEER)
  3145. f |= BIT(NL80211_STA_FLAG_TDLS_PEER);
  3146. if (flags & WPA_STA_AUTHENTICATED)
  3147. f |= BIT(NL80211_STA_FLAG_AUTHENTICATED);
  3148. if (flags & WPA_STA_ASSOCIATED)
  3149. f |= BIT(NL80211_STA_FLAG_ASSOCIATED);
  3150. return f;
  3151. }
  3152. #ifdef CONFIG_MESH
  3153. static u32 sta_plink_state_nl80211(enum mesh_plink_state state)
  3154. {
  3155. switch (state) {
  3156. case PLINK_LISTEN:
  3157. return NL80211_PLINK_LISTEN;
  3158. case PLINK_OPEN_SENT:
  3159. return NL80211_PLINK_OPN_SNT;
  3160. case PLINK_OPEN_RCVD:
  3161. return NL80211_PLINK_OPN_RCVD;
  3162. case PLINK_CNF_RCVD:
  3163. return NL80211_PLINK_CNF_RCVD;
  3164. case PLINK_ESTAB:
  3165. return NL80211_PLINK_ESTAB;
  3166. case PLINK_HOLDING:
  3167. return NL80211_PLINK_HOLDING;
  3168. case PLINK_BLOCKED:
  3169. return NL80211_PLINK_BLOCKED;
  3170. default:
  3171. wpa_printf(MSG_ERROR, "nl80211: Invalid mesh plink state %d",
  3172. state);
  3173. }
  3174. return -1;
  3175. }
  3176. #endif /* CONFIG_MESH */
  3177. static int wpa_driver_nl80211_sta_add(void *priv,
  3178. struct hostapd_sta_add_params *params)
  3179. {
  3180. struct i802_bss *bss = priv;
  3181. struct wpa_driver_nl80211_data *drv = bss->drv;
  3182. struct nl_msg *msg;
  3183. struct nl80211_sta_flag_update upd;
  3184. int ret = -ENOBUFS;
  3185. if ((params->flags & WPA_STA_TDLS_PEER) &&
  3186. !(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT))
  3187. return -EOPNOTSUPP;
  3188. wpa_printf(MSG_DEBUG, "nl80211: %s STA " MACSTR,
  3189. params->set ? "Set" : "Add", MAC2STR(params->addr));
  3190. msg = nl80211_bss_msg(bss, 0, params->set ? NL80211_CMD_SET_STATION :
  3191. NL80211_CMD_NEW_STATION);
  3192. if (!msg || nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->addr))
  3193. goto fail;
  3194. /*
  3195. * Set the below properties only in one of the following cases:
  3196. * 1. New station is added, already associated.
  3197. * 2. Set WPA_STA_TDLS_PEER station.
  3198. * 3. Set an already added unassociated station, if driver supports
  3199. * full AP client state. (Set these properties after station became
  3200. * associated will be rejected by the driver).
  3201. */
  3202. if (!params->set || (params->flags & WPA_STA_TDLS_PEER) ||
  3203. (params->set && FULL_AP_CLIENT_STATE_SUPP(drv->capa.flags) &&
  3204. (params->flags & WPA_STA_ASSOCIATED))) {
  3205. wpa_hexdump(MSG_DEBUG, " * supported rates",
  3206. params->supp_rates, params->supp_rates_len);
  3207. wpa_printf(MSG_DEBUG, " * capability=0x%x",
  3208. params->capability);
  3209. if (nla_put(msg, NL80211_ATTR_STA_SUPPORTED_RATES,
  3210. params->supp_rates_len, params->supp_rates) ||
  3211. nla_put_u16(msg, NL80211_ATTR_STA_CAPABILITY,
  3212. params->capability))
  3213. goto fail;
  3214. if (params->ht_capabilities) {
  3215. wpa_hexdump(MSG_DEBUG, " * ht_capabilities",
  3216. (u8 *) params->ht_capabilities,
  3217. sizeof(*params->ht_capabilities));
  3218. if (nla_put(msg, NL80211_ATTR_HT_CAPABILITY,
  3219. sizeof(*params->ht_capabilities),
  3220. params->ht_capabilities))
  3221. goto fail;
  3222. }
  3223. if (params->vht_capabilities) {
  3224. wpa_hexdump(MSG_DEBUG, " * vht_capabilities",
  3225. (u8 *) params->vht_capabilities,
  3226. sizeof(*params->vht_capabilities));
  3227. if (nla_put(msg, NL80211_ATTR_VHT_CAPABILITY,
  3228. sizeof(*params->vht_capabilities),
  3229. params->vht_capabilities))
  3230. goto fail;
  3231. }
  3232. if (params->ext_capab) {
  3233. wpa_hexdump(MSG_DEBUG, " * ext_capab",
  3234. params->ext_capab, params->ext_capab_len);
  3235. if (nla_put(msg, NL80211_ATTR_STA_EXT_CAPABILITY,
  3236. params->ext_capab_len, params->ext_capab))
  3237. goto fail;
  3238. }
  3239. }
  3240. if (!params->set) {
  3241. if (params->aid) {
  3242. wpa_printf(MSG_DEBUG, " * aid=%u", params->aid);
  3243. if (nla_put_u16(msg, NL80211_ATTR_STA_AID, params->aid))
  3244. goto fail;
  3245. } else {
  3246. /*
  3247. * cfg80211 validates that AID is non-zero, so we have
  3248. * to make this a non-zero value for the TDLS case where
  3249. * a dummy STA entry is used for now and for a station
  3250. * that is still not associated.
  3251. */
  3252. wpa_printf(MSG_DEBUG, " * aid=1 (%s workaround)",
  3253. (params->flags & WPA_STA_TDLS_PEER) ?
  3254. "TDLS" : "UNASSOC_STA");
  3255. if (nla_put_u16(msg, NL80211_ATTR_STA_AID, 1))
  3256. goto fail;
  3257. }
  3258. wpa_printf(MSG_DEBUG, " * listen_interval=%u",
  3259. params->listen_interval);
  3260. if (nla_put_u16(msg, NL80211_ATTR_STA_LISTEN_INTERVAL,
  3261. params->listen_interval))
  3262. goto fail;
  3263. } else if (params->aid && (params->flags & WPA_STA_TDLS_PEER)) {
  3264. wpa_printf(MSG_DEBUG, " * peer_aid=%u", params->aid);
  3265. if (nla_put_u16(msg, NL80211_ATTR_PEER_AID, params->aid))
  3266. goto fail;
  3267. } else if (FULL_AP_CLIENT_STATE_SUPP(drv->capa.flags) &&
  3268. (params->flags & WPA_STA_ASSOCIATED)) {
  3269. wpa_printf(MSG_DEBUG, " * aid=%u", params->aid);
  3270. wpa_printf(MSG_DEBUG, " * listen_interval=%u",
  3271. params->listen_interval);
  3272. if (nla_put_u16(msg, NL80211_ATTR_STA_AID, params->aid) ||
  3273. nla_put_u16(msg, NL80211_ATTR_STA_LISTEN_INTERVAL,
  3274. params->listen_interval))
  3275. goto fail;
  3276. }
  3277. if (params->vht_opmode_enabled) {
  3278. wpa_printf(MSG_DEBUG, " * opmode=%u", params->vht_opmode);
  3279. if (nla_put_u8(msg, NL80211_ATTR_OPMODE_NOTIF,
  3280. params->vht_opmode))
  3281. goto fail;
  3282. }
  3283. if (params->supp_channels) {
  3284. wpa_hexdump(MSG_DEBUG, " * supported channels",
  3285. params->supp_channels, params->supp_channels_len);
  3286. if (nla_put(msg, NL80211_ATTR_STA_SUPPORTED_CHANNELS,
  3287. params->supp_channels_len, params->supp_channels))
  3288. goto fail;
  3289. }
  3290. if (params->supp_oper_classes) {
  3291. wpa_hexdump(MSG_DEBUG, " * supported operating classes",
  3292. params->supp_oper_classes,
  3293. params->supp_oper_classes_len);
  3294. if (nla_put(msg, NL80211_ATTR_STA_SUPPORTED_OPER_CLASSES,
  3295. params->supp_oper_classes_len,
  3296. params->supp_oper_classes))
  3297. goto fail;
  3298. }
  3299. os_memset(&upd, 0, sizeof(upd));
  3300. upd.set = sta_flags_nl80211(params->flags);
  3301. upd.mask = upd.set | sta_flags_nl80211(params->flags_mask);
  3302. /*
  3303. * If the driver doesn't support full AP client state, ignore ASSOC/AUTH
  3304. * flags, as nl80211 driver moves a new station, by default, into
  3305. * associated state.
  3306. *
  3307. * On the other hand, if the driver supports that feature and the
  3308. * station is added in unauthenticated state, set the
  3309. * authenticated/associated bits in the mask to prevent moving this
  3310. * station to associated state before it is actually associated.
  3311. *
  3312. * This is irrelevant for mesh mode where the station is added to the
  3313. * driver as authenticated already, and ASSOCIATED isn't part of the
  3314. * nl80211 API.
  3315. */
  3316. if (!is_mesh_interface(drv->nlmode)) {
  3317. if (!FULL_AP_CLIENT_STATE_SUPP(drv->capa.flags)) {
  3318. wpa_printf(MSG_DEBUG,
  3319. "nl80211: Ignore ASSOC/AUTH flags since driver doesn't support full AP client state");
  3320. upd.mask &= ~(BIT(NL80211_STA_FLAG_ASSOCIATED) |
  3321. BIT(NL80211_STA_FLAG_AUTHENTICATED));
  3322. } else if (!params->set &&
  3323. !(params->flags & WPA_STA_TDLS_PEER)) {
  3324. if (!(params->flags & WPA_STA_AUTHENTICATED))
  3325. upd.mask |= BIT(NL80211_STA_FLAG_AUTHENTICATED);
  3326. if (!(params->flags & WPA_STA_ASSOCIATED))
  3327. upd.mask |= BIT(NL80211_STA_FLAG_ASSOCIATED);
  3328. }
  3329. }
  3330. wpa_printf(MSG_DEBUG, " * flags set=0x%x mask=0x%x",
  3331. upd.set, upd.mask);
  3332. if (nla_put(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd))
  3333. goto fail;
  3334. #ifdef CONFIG_MESH
  3335. if (params->plink_state &&
  3336. nla_put_u8(msg, NL80211_ATTR_STA_PLINK_STATE,
  3337. sta_plink_state_nl80211(params->plink_state)))
  3338. goto fail;
  3339. #endif /* CONFIG_MESH */
  3340. if (params->flags & WPA_STA_WMM) {
  3341. struct nlattr *wme = nla_nest_start(msg, NL80211_ATTR_STA_WME);
  3342. wpa_printf(MSG_DEBUG, " * qosinfo=0x%x", params->qosinfo);
  3343. if (!wme ||
  3344. nla_put_u8(msg, NL80211_STA_WME_UAPSD_QUEUES,
  3345. params->qosinfo & WMM_QOSINFO_STA_AC_MASK) ||
  3346. nla_put_u8(msg, NL80211_STA_WME_MAX_SP,
  3347. (params->qosinfo >> WMM_QOSINFO_STA_SP_SHIFT) &
  3348. WMM_QOSINFO_STA_SP_MASK))
  3349. goto fail;
  3350. nla_nest_end(msg, wme);
  3351. }
  3352. ret = send_and_recv_msgs(drv, msg, NULL, NULL);
  3353. msg = NULL;
  3354. if (ret)
  3355. wpa_printf(MSG_DEBUG, "nl80211: NL80211_CMD_%s_STATION "
  3356. "result: %d (%s)", params->set ? "SET" : "NEW", ret,
  3357. strerror(-ret));
  3358. if (ret == -EEXIST)
  3359. ret = 0;
  3360. fail:
  3361. nlmsg_free(msg);
  3362. return ret;
  3363. }
  3364. static void rtnl_neigh_delete_fdb_entry(struct i802_bss *bss, const u8 *addr)
  3365. {
  3366. #ifdef CONFIG_LIBNL3_ROUTE
  3367. struct wpa_driver_nl80211_data *drv = bss->drv;
  3368. struct rtnl_neigh *rn;
  3369. struct nl_addr *nl_addr;
  3370. int err;
  3371. rn = rtnl_neigh_alloc();
  3372. if (!rn)
  3373. return;
  3374. rtnl_neigh_set_family(rn, AF_BRIDGE);
  3375. rtnl_neigh_set_ifindex(rn, bss->ifindex);
  3376. nl_addr = nl_addr_build(AF_BRIDGE, (void *) addr, ETH_ALEN);
  3377. if (!nl_addr) {
  3378. rtnl_neigh_put(rn);
  3379. return;
  3380. }
  3381. rtnl_neigh_set_lladdr(rn, nl_addr);
  3382. err = rtnl_neigh_delete(drv->rtnl_sk, rn, 0);
  3383. if (err < 0) {
  3384. wpa_printf(MSG_DEBUG, "nl80211: bridge FDB entry delete for "
  3385. MACSTR " ifindex=%d failed: %s", MAC2STR(addr),
  3386. bss->ifindex, nl_geterror(err));
  3387. } else {
  3388. wpa_printf(MSG_DEBUG, "nl80211: deleted bridge FDB entry for "
  3389. MACSTR, MAC2STR(addr));
  3390. }
  3391. nl_addr_put(nl_addr);
  3392. rtnl_neigh_put(rn);
  3393. #endif /* CONFIG_LIBNL3_ROUTE */
  3394. }
  3395. static int wpa_driver_nl80211_sta_remove(struct i802_bss *bss, const u8 *addr,
  3396. int deauth, u16 reason_code)
  3397. {
  3398. struct wpa_driver_nl80211_data *drv = bss->drv;
  3399. struct nl_msg *msg;
  3400. int ret;
  3401. if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_DEL_STATION)) ||
  3402. nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
  3403. (deauth == 0 &&
  3404. nla_put_u8(msg, NL80211_ATTR_MGMT_SUBTYPE,
  3405. WLAN_FC_STYPE_DISASSOC)) ||
  3406. (deauth == 1 &&
  3407. nla_put_u8(msg, NL80211_ATTR_MGMT_SUBTYPE,
  3408. WLAN_FC_STYPE_DEAUTH)) ||
  3409. (reason_code &&
  3410. nla_put_u16(msg, NL80211_ATTR_REASON_CODE, reason_code))) {
  3411. nlmsg_free(msg);
  3412. return -ENOBUFS;
  3413. }
  3414. ret = send_and_recv_msgs(drv, msg, NULL, NULL);
  3415. wpa_printf(MSG_DEBUG, "nl80211: sta_remove -> DEL_STATION %s " MACSTR
  3416. " --> %d (%s)",
  3417. bss->ifname, MAC2STR(addr), ret, strerror(-ret));
  3418. if (drv->rtnl_sk)
  3419. rtnl_neigh_delete_fdb_entry(bss, addr);
  3420. if (ret == -ENOENT)
  3421. return 0;
  3422. return ret;
  3423. }
  3424. void nl80211_remove_iface(struct wpa_driver_nl80211_data *drv, int ifidx)
  3425. {
  3426. struct nl_msg *msg;
  3427. struct wpa_driver_nl80211_data *drv2;
  3428. wpa_printf(MSG_DEBUG, "nl80211: Remove interface ifindex=%d", ifidx);
  3429. /* stop listening for EAPOL on this interface */
  3430. dl_list_for_each(drv2, &drv->global->interfaces,
  3431. struct wpa_driver_nl80211_data, list)
  3432. {
  3433. del_ifidx(drv2, ifidx, IFIDX_ANY);
  3434. /* Remove all bridges learned for this iface */
  3435. del_ifidx(drv2, IFIDX_ANY, ifidx);
  3436. }
  3437. msg = nl80211_ifindex_msg(drv, ifidx, 0, NL80211_CMD_DEL_INTERFACE);
  3438. if (send_and_recv_msgs(drv, msg, NULL, NULL) == 0)
  3439. return;
  3440. wpa_printf(MSG_ERROR, "Failed to remove interface (ifidx=%d)", ifidx);
  3441. }
  3442. static const char * nl80211_iftype_str(enum nl80211_iftype mode)
  3443. {
  3444. switch (mode) {
  3445. case NL80211_IFTYPE_ADHOC:
  3446. return "ADHOC";
  3447. case NL80211_IFTYPE_STATION:
  3448. return "STATION";
  3449. case NL80211_IFTYPE_AP:
  3450. return "AP";
  3451. case NL80211_IFTYPE_AP_VLAN:
  3452. return "AP_VLAN";
  3453. case NL80211_IFTYPE_WDS:
  3454. return "WDS";
  3455. case NL80211_IFTYPE_MONITOR:
  3456. return "MONITOR";
  3457. case NL80211_IFTYPE_MESH_POINT:
  3458. return "MESH_POINT";
  3459. case NL80211_IFTYPE_P2P_CLIENT:
  3460. return "P2P_CLIENT";
  3461. case NL80211_IFTYPE_P2P_GO:
  3462. return "P2P_GO";
  3463. case NL80211_IFTYPE_P2P_DEVICE:
  3464. return "P2P_DEVICE";
  3465. default:
  3466. return "unknown";
  3467. }
  3468. }
  3469. static int nl80211_create_iface_once(struct wpa_driver_nl80211_data *drv,
  3470. const char *ifname,
  3471. enum nl80211_iftype iftype,
  3472. const u8 *addr, int wds,
  3473. int (*handler)(struct nl_msg *, void *),
  3474. void *arg)
  3475. {
  3476. struct nl_msg *msg;
  3477. int ifidx;
  3478. int ret = -ENOBUFS;
  3479. wpa_printf(MSG_DEBUG, "nl80211: Create interface iftype %d (%s)",
  3480. iftype, nl80211_iftype_str(iftype));
  3481. msg = nl80211_cmd_msg(drv->first_bss, 0, NL80211_CMD_NEW_INTERFACE);
  3482. if (!msg ||
  3483. nla_put_string(msg, NL80211_ATTR_IFNAME, ifname) ||
  3484. nla_put_u32(msg, NL80211_ATTR_IFTYPE, iftype))
  3485. goto fail;
  3486. if (iftype == NL80211_IFTYPE_MONITOR) {
  3487. struct nlattr *flags;
  3488. flags = nla_nest_start(msg, NL80211_ATTR_MNTR_FLAGS);
  3489. if (!flags ||
  3490. nla_put_flag(msg, NL80211_MNTR_FLAG_COOK_FRAMES))
  3491. goto fail;
  3492. nla_nest_end(msg, flags);
  3493. } else if (wds) {
  3494. if (nla_put_u8(msg, NL80211_ATTR_4ADDR, wds))
  3495. goto fail;
  3496. }
  3497. /*
  3498. * Tell cfg80211 that the interface belongs to the socket that created
  3499. * it, and the interface should be deleted when the socket is closed.
  3500. */
  3501. if (nla_put_flag(msg, NL80211_ATTR_IFACE_SOCKET_OWNER))
  3502. goto fail;
  3503. ret = send_and_recv_msgs(drv, msg, handler, arg);
  3504. msg = NULL;
  3505. if (ret) {
  3506. fail:
  3507. nlmsg_free(msg);
  3508. wpa_printf(MSG_ERROR, "Failed to create interface %s: %d (%s)",
  3509. ifname, ret, strerror(-ret));
  3510. return ret;
  3511. }
  3512. if (iftype == NL80211_IFTYPE_P2P_DEVICE)
  3513. return 0;
  3514. ifidx = if_nametoindex(ifname);
  3515. wpa_printf(MSG_DEBUG, "nl80211: New interface %s created: ifindex=%d",
  3516. ifname, ifidx);
  3517. if (ifidx <= 0)
  3518. return -1;
  3519. /*
  3520. * Some virtual interfaces need to process EAPOL packets and events on
  3521. * the parent interface. This is used mainly with hostapd.
  3522. */
  3523. if (drv->hostapd ||
  3524. iftype == NL80211_IFTYPE_AP_VLAN ||
  3525. iftype == NL80211_IFTYPE_WDS ||
  3526. iftype == NL80211_IFTYPE_MONITOR) {
  3527. /* start listening for EAPOL on this interface */
  3528. add_ifidx(drv, ifidx, IFIDX_ANY);
  3529. }
  3530. if (addr && iftype != NL80211_IFTYPE_MONITOR &&
  3531. linux_set_ifhwaddr(drv->global->ioctl_sock, ifname, addr)) {
  3532. nl80211_remove_iface(drv, ifidx);
  3533. return -1;
  3534. }
  3535. return ifidx;
  3536. }
  3537. int nl80211_create_iface(struct wpa_driver_nl80211_data *drv,
  3538. const char *ifname, enum nl80211_iftype iftype,
  3539. const u8 *addr, int wds,
  3540. int (*handler)(struct nl_msg *, void *),
  3541. void *arg, int use_existing)
  3542. {
  3543. int ret;
  3544. ret = nl80211_create_iface_once(drv, ifname, iftype, addr, wds, handler,
  3545. arg);
  3546. /* if error occurred and interface exists already */
  3547. if (ret == -ENFILE && if_nametoindex(ifname)) {
  3548. if (use_existing) {
  3549. wpa_printf(MSG_DEBUG, "nl80211: Continue using existing interface %s",
  3550. ifname);
  3551. if (addr && iftype != NL80211_IFTYPE_MONITOR &&
  3552. linux_set_ifhwaddr(drv->global->ioctl_sock, ifname,
  3553. addr) < 0 &&
  3554. (linux_set_iface_flags(drv->global->ioctl_sock,
  3555. ifname, 0) < 0 ||
  3556. linux_set_ifhwaddr(drv->global->ioctl_sock, ifname,
  3557. addr) < 0 ||
  3558. linux_set_iface_flags(drv->global->ioctl_sock,
  3559. ifname, 1) < 0))
  3560. return -1;
  3561. return -ENFILE;
  3562. }
  3563. wpa_printf(MSG_INFO, "Try to remove and re-create %s", ifname);
  3564. /* Try to remove the interface that was already there. */
  3565. nl80211_remove_iface(drv, if_nametoindex(ifname));
  3566. /* Try to create the interface again */
  3567. ret = nl80211_create_iface_once(drv, ifname, iftype, addr,
  3568. wds, handler, arg);
  3569. }
  3570. if (ret >= 0 && is_p2p_net_interface(iftype)) {
  3571. wpa_printf(MSG_DEBUG,
  3572. "nl80211: Interface %s created for P2P - disable 11b rates",
  3573. ifname);
  3574. nl80211_disable_11b_rates(drv, ret, 1);
  3575. }
  3576. return ret;
  3577. }
  3578. static int nl80211_setup_ap(struct i802_bss *bss)
  3579. {
  3580. struct wpa_driver_nl80211_data *drv = bss->drv;
  3581. wpa_printf(MSG_DEBUG, "nl80211: Setup AP(%s) - device_ap_sme=%d use_monitor=%d",
  3582. bss->ifname, drv->device_ap_sme, drv->use_monitor);
  3583. /*
  3584. * Disable Probe Request reporting unless we need it in this way for
  3585. * devices that include the AP SME, in the other case (unless using
  3586. * monitor iface) we'll get it through the nl_mgmt socket instead.
  3587. */
  3588. if (!drv->device_ap_sme)
  3589. wpa_driver_nl80211_probe_req_report(bss, 0);
  3590. if (!drv->device_ap_sme && !drv->use_monitor)
  3591. if (nl80211_mgmt_subscribe_ap(bss))
  3592. return -1;
  3593. if (drv->device_ap_sme && !drv->use_monitor)
  3594. if (nl80211_mgmt_subscribe_ap_dev_sme(bss))
  3595. return -1;
  3596. if (!drv->device_ap_sme && drv->use_monitor &&
  3597. nl80211_create_monitor_interface(drv) &&
  3598. !drv->device_ap_sme)
  3599. return -1;
  3600. if (drv->device_ap_sme &&
  3601. wpa_driver_nl80211_probe_req_report(bss, 1) < 0) {
  3602. wpa_printf(MSG_DEBUG, "nl80211: Failed to enable "
  3603. "Probe Request frame reporting in AP mode");
  3604. /* Try to survive without this */
  3605. }
  3606. return 0;
  3607. }
  3608. static void nl80211_teardown_ap(struct i802_bss *bss)
  3609. {
  3610. struct wpa_driver_nl80211_data *drv = bss->drv;
  3611. wpa_printf(MSG_DEBUG, "nl80211: Teardown AP(%s) - device_ap_sme=%d use_monitor=%d",
  3612. bss->ifname, drv->device_ap_sme, drv->use_monitor);
  3613. if (drv->device_ap_sme) {
  3614. wpa_driver_nl80211_probe_req_report(bss, 0);
  3615. if (!drv->use_monitor)
  3616. nl80211_mgmt_unsubscribe(bss, "AP teardown (dev SME)");
  3617. } else if (drv->use_monitor)
  3618. nl80211_remove_monitor_interface(drv);
  3619. else
  3620. nl80211_mgmt_unsubscribe(bss, "AP teardown");
  3621. bss->beacon_set = 0;
  3622. }
  3623. static int nl80211_send_eapol_data(struct i802_bss *bss,
  3624. const u8 *addr, const u8 *data,
  3625. size_t data_len)
  3626. {
  3627. struct sockaddr_ll ll;
  3628. int ret;
  3629. if (bss->drv->eapol_tx_sock < 0) {
  3630. wpa_printf(MSG_DEBUG, "nl80211: No socket to send EAPOL");
  3631. return -1;
  3632. }
  3633. os_memset(&ll, 0, sizeof(ll));
  3634. ll.sll_family = AF_PACKET;
  3635. ll.sll_ifindex = bss->ifindex;
  3636. ll.sll_protocol = htons(ETH_P_PAE);
  3637. ll.sll_halen = ETH_ALEN;
  3638. os_memcpy(ll.sll_addr, addr, ETH_ALEN);
  3639. ret = sendto(bss->drv->eapol_tx_sock, data, data_len, 0,
  3640. (struct sockaddr *) &ll, sizeof(ll));
  3641. if (ret < 0)
  3642. wpa_printf(MSG_ERROR, "nl80211: EAPOL TX: %s",
  3643. strerror(errno));
  3644. return ret;
  3645. }
  3646. static const u8 rfc1042_header[6] = { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
  3647. static int wpa_driver_nl80211_hapd_send_eapol(
  3648. void *priv, const u8 *addr, const u8 *data,
  3649. size_t data_len, int encrypt, const u8 *own_addr, u32 flags)
  3650. {
  3651. struct i802_bss *bss = priv;
  3652. struct wpa_driver_nl80211_data *drv = bss->drv;
  3653. struct ieee80211_hdr *hdr;
  3654. size_t len;
  3655. u8 *pos;
  3656. int res;
  3657. int qos = flags & WPA_STA_WMM;
  3658. if (drv->device_ap_sme || !drv->use_monitor)
  3659. return nl80211_send_eapol_data(bss, addr, data, data_len);
  3660. len = sizeof(*hdr) + (qos ? 2 : 0) + sizeof(rfc1042_header) + 2 +
  3661. data_len;
  3662. hdr = os_zalloc(len);
  3663. if (hdr == NULL) {
  3664. wpa_printf(MSG_INFO, "nl80211: Failed to allocate EAPOL buffer(len=%lu)",
  3665. (unsigned long) len);
  3666. return -1;
  3667. }
  3668. hdr->frame_control =
  3669. IEEE80211_FC(WLAN_FC_TYPE_DATA, WLAN_FC_STYPE_DATA);
  3670. hdr->frame_control |= host_to_le16(WLAN_FC_FROMDS);
  3671. if (encrypt)
  3672. hdr->frame_control |= host_to_le16(WLAN_FC_ISWEP);
  3673. if (qos) {
  3674. hdr->frame_control |=
  3675. host_to_le16(WLAN_FC_STYPE_QOS_DATA << 4);
  3676. }
  3677. memcpy(hdr->IEEE80211_DA_FROMDS, addr, ETH_ALEN);
  3678. memcpy(hdr->IEEE80211_BSSID_FROMDS, own_addr, ETH_ALEN);
  3679. memcpy(hdr->IEEE80211_SA_FROMDS, own_addr, ETH_ALEN);
  3680. pos = (u8 *) (hdr + 1);
  3681. if (qos) {
  3682. /* Set highest priority in QoS header */
  3683. pos[0] = 7;
  3684. pos[1] = 0;
  3685. pos += 2;
  3686. }
  3687. memcpy(pos, rfc1042_header, sizeof(rfc1042_header));
  3688. pos += sizeof(rfc1042_header);
  3689. WPA_PUT_BE16(pos, ETH_P_PAE);
  3690. pos += 2;
  3691. memcpy(pos, data, data_len);
  3692. res = wpa_driver_nl80211_send_frame(bss, (u8 *) hdr, len, encrypt, 0,
  3693. 0, 0, 0, 0, NULL, 0);
  3694. if (res < 0) {
  3695. wpa_printf(MSG_ERROR, "i802_send_eapol - packet len: %lu - "
  3696. "failed: %d (%s)",
  3697. (unsigned long) len, errno, strerror(errno));
  3698. }
  3699. os_free(hdr);
  3700. return res;
  3701. }
  3702. static int wpa_driver_nl80211_sta_set_flags(void *priv, const u8 *addr,
  3703. unsigned int total_flags,
  3704. unsigned int flags_or,
  3705. unsigned int flags_and)
  3706. {
  3707. struct i802_bss *bss = priv;
  3708. struct nl_msg *msg;
  3709. struct nlattr *flags;
  3710. struct nl80211_sta_flag_update upd;
  3711. wpa_printf(MSG_DEBUG, "nl80211: Set STA flags - ifname=%s addr=" MACSTR
  3712. " total_flags=0x%x flags_or=0x%x flags_and=0x%x authorized=%d",
  3713. bss->ifname, MAC2STR(addr), total_flags, flags_or, flags_and,
  3714. !!(total_flags & WPA_STA_AUTHORIZED));
  3715. if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) ||
  3716. nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr))
  3717. goto fail;
  3718. /*
  3719. * Backwards compatibility version using NL80211_ATTR_STA_FLAGS. This
  3720. * can be removed eventually.
  3721. */
  3722. flags = nla_nest_start(msg, NL80211_ATTR_STA_FLAGS);
  3723. if (!flags ||
  3724. ((total_flags & WPA_STA_AUTHORIZED) &&
  3725. nla_put_flag(msg, NL80211_STA_FLAG_AUTHORIZED)) ||
  3726. ((total_flags & WPA_STA_WMM) &&
  3727. nla_put_flag(msg, NL80211_STA_FLAG_WME)) ||
  3728. ((total_flags & WPA_STA_SHORT_PREAMBLE) &&
  3729. nla_put_flag(msg, NL80211_STA_FLAG_SHORT_PREAMBLE)) ||
  3730. ((total_flags & WPA_STA_MFP) &&
  3731. nla_put_flag(msg, NL80211_STA_FLAG_MFP)) ||
  3732. ((total_flags & WPA_STA_TDLS_PEER) &&
  3733. nla_put_flag(msg, NL80211_STA_FLAG_TDLS_PEER)))
  3734. goto fail;
  3735. nla_nest_end(msg, flags);
  3736. os_memset(&upd, 0, sizeof(upd));
  3737. upd.mask = sta_flags_nl80211(flags_or | ~flags_and);
  3738. upd.set = sta_flags_nl80211(flags_or);
  3739. if (nla_put(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd))
  3740. goto fail;
  3741. return send_and_recv_msgs(bss->drv, msg, NULL, NULL);
  3742. fail:
  3743. nlmsg_free(msg);
  3744. return -ENOBUFS;
  3745. }
  3746. static int wpa_driver_nl80211_ap(struct wpa_driver_nl80211_data *drv,
  3747. struct wpa_driver_associate_params *params)
  3748. {
  3749. enum nl80211_iftype nlmode, old_mode;
  3750. if (params->p2p) {
  3751. wpa_printf(MSG_DEBUG, "nl80211: Setup AP operations for P2P "
  3752. "group (GO)");
  3753. nlmode = NL80211_IFTYPE_P2P_GO;
  3754. } else
  3755. nlmode = NL80211_IFTYPE_AP;
  3756. old_mode = drv->nlmode;
  3757. if (wpa_driver_nl80211_set_mode(drv->first_bss, nlmode)) {
  3758. nl80211_remove_monitor_interface(drv);
  3759. return -1;
  3760. }
  3761. if (params->freq.freq &&
  3762. nl80211_set_channel(drv->first_bss, &params->freq, 0)) {
  3763. if (old_mode != nlmode)
  3764. wpa_driver_nl80211_set_mode(drv->first_bss, old_mode);
  3765. nl80211_remove_monitor_interface(drv);
  3766. return -1;
  3767. }
  3768. return 0;
  3769. }
  3770. static int nl80211_leave_ibss(struct wpa_driver_nl80211_data *drv,
  3771. int reset_mode)
  3772. {
  3773. struct nl_msg *msg;
  3774. int ret;
  3775. msg = nl80211_drv_msg(drv, 0, NL80211_CMD_LEAVE_IBSS);
  3776. ret = send_and_recv_msgs(drv, msg, NULL, NULL);
  3777. if (ret) {
  3778. wpa_printf(MSG_DEBUG, "nl80211: Leave IBSS failed: ret=%d "
  3779. "(%s)", ret, strerror(-ret));
  3780. } else {
  3781. wpa_printf(MSG_DEBUG,
  3782. "nl80211: Leave IBSS request sent successfully");
  3783. }
  3784. if (reset_mode &&
  3785. wpa_driver_nl80211_set_mode(drv->first_bss,
  3786. NL80211_IFTYPE_STATION)) {
  3787. wpa_printf(MSG_INFO, "nl80211: Failed to set interface into "
  3788. "station mode");
  3789. }
  3790. return ret;
  3791. }
  3792. static int nl80211_ht_vht_overrides(struct nl_msg *msg,
  3793. struct wpa_driver_associate_params *params)
  3794. {
  3795. if (params->disable_ht && nla_put_flag(msg, NL80211_ATTR_DISABLE_HT))
  3796. return -1;
  3797. if (params->htcaps && params->htcaps_mask) {
  3798. int sz = sizeof(struct ieee80211_ht_capabilities);
  3799. wpa_hexdump(MSG_DEBUG, " * htcaps", params->htcaps, sz);
  3800. wpa_hexdump(MSG_DEBUG, " * htcaps_mask",
  3801. params->htcaps_mask, sz);
  3802. if (nla_put(msg, NL80211_ATTR_HT_CAPABILITY, sz,
  3803. params->htcaps) ||
  3804. nla_put(msg, NL80211_ATTR_HT_CAPABILITY_MASK, sz,
  3805. params->htcaps_mask))
  3806. return -1;
  3807. }
  3808. #ifdef CONFIG_VHT_OVERRIDES
  3809. if (params->disable_vht) {
  3810. wpa_printf(MSG_DEBUG, " * VHT disabled");
  3811. if (nla_put_flag(msg, NL80211_ATTR_DISABLE_VHT))
  3812. return -1;
  3813. }
  3814. if (params->vhtcaps && params->vhtcaps_mask) {
  3815. int sz = sizeof(struct ieee80211_vht_capabilities);
  3816. wpa_hexdump(MSG_DEBUG, " * vhtcaps", params->vhtcaps, sz);
  3817. wpa_hexdump(MSG_DEBUG, " * vhtcaps_mask",
  3818. params->vhtcaps_mask, sz);
  3819. if (nla_put(msg, NL80211_ATTR_VHT_CAPABILITY, sz,
  3820. params->vhtcaps) ||
  3821. nla_put(msg, NL80211_ATTR_VHT_CAPABILITY_MASK, sz,
  3822. params->vhtcaps_mask))
  3823. return -1;
  3824. }
  3825. #endif /* CONFIG_VHT_OVERRIDES */
  3826. return 0;
  3827. }
  3828. static int wpa_driver_nl80211_ibss(struct wpa_driver_nl80211_data *drv,
  3829. struct wpa_driver_associate_params *params)
  3830. {
  3831. struct nl_msg *msg;
  3832. int ret = -1;
  3833. int count = 0;
  3834. wpa_printf(MSG_DEBUG, "nl80211: Join IBSS (ifindex=%d)", drv->ifindex);
  3835. if (wpa_driver_nl80211_set_mode_ibss(drv->first_bss, &params->freq)) {
  3836. wpa_printf(MSG_INFO, "nl80211: Failed to set interface into "
  3837. "IBSS mode");
  3838. return -1;
  3839. }
  3840. retry:
  3841. if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_JOIN_IBSS)) ||
  3842. params->ssid == NULL || params->ssid_len > sizeof(drv->ssid))
  3843. goto fail;
  3844. wpa_hexdump_ascii(MSG_DEBUG, " * SSID",
  3845. params->ssid, params->ssid_len);
  3846. if (nla_put(msg, NL80211_ATTR_SSID, params->ssid_len, params->ssid))
  3847. goto fail;
  3848. os_memcpy(drv->ssid, params->ssid, params->ssid_len);
  3849. drv->ssid_len = params->ssid_len;
  3850. if (nl80211_put_freq_params(msg, &params->freq) < 0 ||
  3851. nl80211_put_beacon_int(msg, params->beacon_int))
  3852. goto fail;
  3853. ret = nl80211_set_conn_keys(params, msg);
  3854. if (ret)
  3855. goto fail;
  3856. if (params->bssid && params->fixed_bssid) {
  3857. wpa_printf(MSG_DEBUG, " * BSSID=" MACSTR,
  3858. MAC2STR(params->bssid));
  3859. if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid))
  3860. goto fail;
  3861. }
  3862. if (params->fixed_freq) {
  3863. wpa_printf(MSG_DEBUG, " * fixed_freq");
  3864. if (nla_put_flag(msg, NL80211_ATTR_FREQ_FIXED))
  3865. goto fail;
  3866. }
  3867. if (params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X ||
  3868. params->key_mgmt_suite == WPA_KEY_MGMT_PSK ||
  3869. params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SHA256 ||
  3870. params->key_mgmt_suite == WPA_KEY_MGMT_PSK_SHA256) {
  3871. wpa_printf(MSG_DEBUG, " * control port");
  3872. if (nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT))
  3873. goto fail;
  3874. }
  3875. if (params->wpa_ie) {
  3876. wpa_hexdump(MSG_DEBUG,
  3877. " * Extra IEs for Beacon/Probe Response frames",
  3878. params->wpa_ie, params->wpa_ie_len);
  3879. if (nla_put(msg, NL80211_ATTR_IE, params->wpa_ie_len,
  3880. params->wpa_ie))
  3881. goto fail;
  3882. }
  3883. ret = nl80211_ht_vht_overrides(msg, params);
  3884. if (ret < 0)
  3885. goto fail;
  3886. ret = send_and_recv_msgs(drv, msg, NULL, NULL);
  3887. msg = NULL;
  3888. if (ret) {
  3889. wpa_printf(MSG_DEBUG, "nl80211: Join IBSS failed: ret=%d (%s)",
  3890. ret, strerror(-ret));
  3891. count++;
  3892. if (ret == -EALREADY && count == 1) {
  3893. wpa_printf(MSG_DEBUG, "nl80211: Retry IBSS join after "
  3894. "forced leave");
  3895. nl80211_leave_ibss(drv, 0);
  3896. nlmsg_free(msg);
  3897. goto retry;
  3898. }
  3899. } else {
  3900. wpa_printf(MSG_DEBUG,
  3901. "nl80211: Join IBSS request sent successfully");
  3902. }
  3903. fail:
  3904. nlmsg_free(msg);
  3905. return ret;
  3906. }
  3907. static int nl80211_connect_common(struct wpa_driver_nl80211_data *drv,
  3908. struct wpa_driver_associate_params *params,
  3909. struct nl_msg *msg)
  3910. {
  3911. if (params->bssid) {
  3912. wpa_printf(MSG_DEBUG, " * bssid=" MACSTR,
  3913. MAC2STR(params->bssid));
  3914. if (nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, params->bssid))
  3915. return -1;
  3916. }
  3917. if (params->bssid_hint) {
  3918. wpa_printf(MSG_DEBUG, " * bssid_hint=" MACSTR,
  3919. MAC2STR(params->bssid_hint));
  3920. if (nla_put(msg, NL80211_ATTR_MAC_HINT, ETH_ALEN,
  3921. params->bssid_hint))
  3922. return -1;
  3923. }
  3924. if (params->freq.freq) {
  3925. wpa_printf(MSG_DEBUG, " * freq=%d", params->freq.freq);
  3926. if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ,
  3927. params->freq.freq))
  3928. return -1;
  3929. drv->assoc_freq = params->freq.freq;
  3930. } else
  3931. drv->assoc_freq = 0;
  3932. if (params->freq_hint) {
  3933. wpa_printf(MSG_DEBUG, " * freq_hint=%d", params->freq_hint);
  3934. if (nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ_HINT,
  3935. params->freq_hint))
  3936. return -1;
  3937. }
  3938. if (params->bg_scan_period >= 0) {
  3939. wpa_printf(MSG_DEBUG, " * bg scan period=%d",
  3940. params->bg_scan_period);
  3941. if (nla_put_u16(msg, NL80211_ATTR_BG_SCAN_PERIOD,
  3942. params->bg_scan_period))
  3943. return -1;
  3944. }
  3945. if (params->ssid) {
  3946. wpa_hexdump_ascii(MSG_DEBUG, " * SSID",
  3947. params->ssid, params->ssid_len);
  3948. if (nla_put(msg, NL80211_ATTR_SSID, params->ssid_len,
  3949. params->ssid))
  3950. return -1;
  3951. if (params->ssid_len > sizeof(drv->ssid))
  3952. return -1;
  3953. os_memcpy(drv->ssid, params->ssid, params->ssid_len);
  3954. drv->ssid_len = params->ssid_len;
  3955. }
  3956. wpa_hexdump(MSG_DEBUG, " * IEs", params->wpa_ie, params->wpa_ie_len);
  3957. if (params->wpa_ie &&
  3958. nla_put(msg, NL80211_ATTR_IE, params->wpa_ie_len, params->wpa_ie))
  3959. return -1;
  3960. if (params->wpa_proto) {
  3961. enum nl80211_wpa_versions ver = 0;
  3962. if (params->wpa_proto & WPA_PROTO_WPA)
  3963. ver |= NL80211_WPA_VERSION_1;
  3964. if (params->wpa_proto & WPA_PROTO_RSN)
  3965. ver |= NL80211_WPA_VERSION_2;
  3966. wpa_printf(MSG_DEBUG, " * WPA Versions 0x%x", ver);
  3967. if (nla_put_u32(msg, NL80211_ATTR_WPA_VERSIONS, ver))
  3968. return -1;
  3969. }
  3970. if (params->pairwise_suite != WPA_CIPHER_NONE) {
  3971. u32 cipher = wpa_cipher_to_cipher_suite(params->pairwise_suite);
  3972. wpa_printf(MSG_DEBUG, " * pairwise=0x%x", cipher);
  3973. if (nla_put_u32(msg, NL80211_ATTR_CIPHER_SUITES_PAIRWISE,
  3974. cipher))
  3975. return -1;
  3976. }
  3977. if (params->group_suite == WPA_CIPHER_GTK_NOT_USED &&
  3978. !(drv->capa.enc & WPA_DRIVER_CAPA_ENC_GTK_NOT_USED)) {
  3979. /*
  3980. * This is likely to work even though many drivers do not
  3981. * advertise support for operations without GTK.
  3982. */
  3983. wpa_printf(MSG_DEBUG, " * skip group cipher configuration for GTK_NOT_USED due to missing driver support advertisement");
  3984. } else if (params->group_suite != WPA_CIPHER_NONE) {
  3985. u32 cipher = wpa_cipher_to_cipher_suite(params->group_suite);
  3986. wpa_printf(MSG_DEBUG, " * group=0x%x", cipher);
  3987. if (nla_put_u32(msg, NL80211_ATTR_CIPHER_SUITE_GROUP, cipher))
  3988. return -1;
  3989. }
  3990. if (params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X ||
  3991. params->key_mgmt_suite == WPA_KEY_MGMT_PSK ||
  3992. params->key_mgmt_suite == WPA_KEY_MGMT_FT_IEEE8021X ||
  3993. params->key_mgmt_suite == WPA_KEY_MGMT_FT_PSK ||
  3994. params->key_mgmt_suite == WPA_KEY_MGMT_CCKM ||
  3995. params->key_mgmt_suite == WPA_KEY_MGMT_OSEN ||
  3996. params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SHA256 ||
  3997. params->key_mgmt_suite == WPA_KEY_MGMT_PSK_SHA256 ||
  3998. params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SUITE_B ||
  3999. params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SUITE_B_192) {
  4000. int mgmt = WLAN_AKM_SUITE_PSK;
  4001. switch (params->key_mgmt_suite) {
  4002. case WPA_KEY_MGMT_CCKM:
  4003. mgmt = WLAN_AKM_SUITE_CCKM;
  4004. break;
  4005. case WPA_KEY_MGMT_IEEE8021X:
  4006. mgmt = WLAN_AKM_SUITE_8021X;
  4007. break;
  4008. case WPA_KEY_MGMT_FT_IEEE8021X:
  4009. mgmt = WLAN_AKM_SUITE_FT_8021X;
  4010. break;
  4011. case WPA_KEY_MGMT_FT_PSK:
  4012. mgmt = WLAN_AKM_SUITE_FT_PSK;
  4013. break;
  4014. case WPA_KEY_MGMT_IEEE8021X_SHA256:
  4015. mgmt = WLAN_AKM_SUITE_8021X_SHA256;
  4016. break;
  4017. case WPA_KEY_MGMT_PSK_SHA256:
  4018. mgmt = WLAN_AKM_SUITE_PSK_SHA256;
  4019. break;
  4020. case WPA_KEY_MGMT_OSEN:
  4021. mgmt = WLAN_AKM_SUITE_OSEN;
  4022. break;
  4023. case WPA_KEY_MGMT_IEEE8021X_SUITE_B:
  4024. mgmt = WLAN_AKM_SUITE_8021X_SUITE_B;
  4025. break;
  4026. case WPA_KEY_MGMT_IEEE8021X_SUITE_B_192:
  4027. mgmt = WLAN_AKM_SUITE_8021X_SUITE_B_192;
  4028. break;
  4029. case WPA_KEY_MGMT_PSK:
  4030. default:
  4031. mgmt = WLAN_AKM_SUITE_PSK;
  4032. break;
  4033. }
  4034. wpa_printf(MSG_DEBUG, " * akm=0x%x", mgmt);
  4035. if (nla_put_u32(msg, NL80211_ATTR_AKM_SUITES, mgmt))
  4036. return -1;
  4037. }
  4038. if (nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT))
  4039. return -1;
  4040. if (params->mgmt_frame_protection == MGMT_FRAME_PROTECTION_REQUIRED &&
  4041. nla_put_u32(msg, NL80211_ATTR_USE_MFP, NL80211_MFP_REQUIRED))
  4042. return -1;
  4043. if (params->rrm_used) {
  4044. u32 drv_rrm_flags = drv->capa.rrm_flags;
  4045. if (!(drv_rrm_flags &
  4046. WPA_DRIVER_FLAGS_DS_PARAM_SET_IE_IN_PROBES) ||
  4047. !(drv_rrm_flags & WPA_DRIVER_FLAGS_QUIET) ||
  4048. nla_put_flag(msg, NL80211_ATTR_USE_RRM))
  4049. return -1;
  4050. }
  4051. if (nl80211_ht_vht_overrides(msg, params) < 0)
  4052. return -1;
  4053. if (params->p2p)
  4054. wpa_printf(MSG_DEBUG, " * P2P group");
  4055. if (params->pbss) {
  4056. wpa_printf(MSG_DEBUG, " * PBSS");
  4057. if (nla_put_flag(msg, NL80211_ATTR_PBSS))
  4058. return -1;
  4059. }
  4060. return 0;
  4061. }
  4062. static int wpa_driver_nl80211_try_connect(
  4063. struct wpa_driver_nl80211_data *drv,
  4064. struct wpa_driver_associate_params *params)
  4065. {
  4066. struct nl_msg *msg;
  4067. enum nl80211_auth_type type;
  4068. int ret;
  4069. int algs;
  4070. #ifdef CONFIG_DRIVER_NL80211_QCA
  4071. if (params->req_key_mgmt_offload && params->psk &&
  4072. (params->key_mgmt_suite == WPA_KEY_MGMT_PSK ||
  4073. params->key_mgmt_suite == WPA_KEY_MGMT_PSK_SHA256 ||
  4074. params->key_mgmt_suite == WPA_KEY_MGMT_FT_PSK)) {
  4075. wpa_printf(MSG_DEBUG, "nl80211: Key management set PSK");
  4076. ret = issue_key_mgmt_set_key(drv, params->psk, 32);
  4077. if (ret)
  4078. return ret;
  4079. }
  4080. #endif /* CONFIG_DRIVER_NL80211_QCA */
  4081. wpa_printf(MSG_DEBUG, "nl80211: Connect (ifindex=%d)", drv->ifindex);
  4082. msg = nl80211_drv_msg(drv, 0, NL80211_CMD_CONNECT);
  4083. if (!msg)
  4084. return -1;
  4085. ret = nl80211_connect_common(drv, params, msg);
  4086. if (ret)
  4087. goto fail;
  4088. algs = 0;
  4089. if (params->auth_alg & WPA_AUTH_ALG_OPEN)
  4090. algs++;
  4091. if (params->auth_alg & WPA_AUTH_ALG_SHARED)
  4092. algs++;
  4093. if (params->auth_alg & WPA_AUTH_ALG_LEAP)
  4094. algs++;
  4095. if (algs > 1) {
  4096. wpa_printf(MSG_DEBUG, " * Leave out Auth Type for automatic "
  4097. "selection");
  4098. goto skip_auth_type;
  4099. }
  4100. if (params->auth_alg & WPA_AUTH_ALG_OPEN)
  4101. type = NL80211_AUTHTYPE_OPEN_SYSTEM;
  4102. else if (params->auth_alg & WPA_AUTH_ALG_SHARED)
  4103. type = NL80211_AUTHTYPE_SHARED_KEY;
  4104. else if (params->auth_alg & WPA_AUTH_ALG_LEAP)
  4105. type = NL80211_AUTHTYPE_NETWORK_EAP;
  4106. else if (params->auth_alg & WPA_AUTH_ALG_FT)
  4107. type = NL80211_AUTHTYPE_FT;
  4108. else
  4109. goto fail;
  4110. wpa_printf(MSG_DEBUG, " * Auth Type %d", type);
  4111. if (nla_put_u32(msg, NL80211_ATTR_AUTH_TYPE, type))
  4112. goto fail;
  4113. skip_auth_type:
  4114. ret = nl80211_set_conn_keys(params, msg);
  4115. if (ret)
  4116. goto fail;
  4117. ret = send_and_recv_msgs(drv, msg, NULL, NULL);
  4118. msg = NULL;
  4119. if (ret) {
  4120. wpa_printf(MSG_DEBUG, "nl80211: MLME connect failed: ret=%d "
  4121. "(%s)", ret, strerror(-ret));
  4122. } else {
  4123. wpa_printf(MSG_DEBUG,
  4124. "nl80211: Connect request send successfully");
  4125. }
  4126. fail:
  4127. nlmsg_free(msg);
  4128. return ret;
  4129. }
  4130. static int wpa_driver_nl80211_connect(
  4131. struct wpa_driver_nl80211_data *drv,
  4132. struct wpa_driver_associate_params *params)
  4133. {
  4134. int ret;
  4135. /* Store the connection attempted bssid for future use */
  4136. if (params->bssid)
  4137. os_memcpy(drv->auth_attempt_bssid, params->bssid, ETH_ALEN);
  4138. else
  4139. os_memset(drv->auth_attempt_bssid, 0, ETH_ALEN);
  4140. ret = wpa_driver_nl80211_try_connect(drv, params);
  4141. if (ret == -EALREADY) {
  4142. /*
  4143. * cfg80211 does not currently accept new connections if
  4144. * we are already connected. As a workaround, force
  4145. * disconnection and try again.
  4146. */
  4147. wpa_printf(MSG_DEBUG, "nl80211: Explicitly "
  4148. "disconnecting before reassociation "
  4149. "attempt");
  4150. if (wpa_driver_nl80211_disconnect(
  4151. drv, WLAN_REASON_PREV_AUTH_NOT_VALID))
  4152. return -1;
  4153. ret = wpa_driver_nl80211_try_connect(drv, params);
  4154. }
  4155. return ret;
  4156. }
  4157. static int wpa_driver_nl80211_associate(
  4158. void *priv, struct wpa_driver_associate_params *params)
  4159. {
  4160. struct i802_bss *bss = priv;
  4161. struct wpa_driver_nl80211_data *drv = bss->drv;
  4162. int ret = -1;
  4163. struct nl_msg *msg;
  4164. nl80211_unmask_11b_rates(bss);
  4165. if (params->mode == IEEE80211_MODE_AP)
  4166. return wpa_driver_nl80211_ap(drv, params);
  4167. if (params->mode == IEEE80211_MODE_IBSS)
  4168. return wpa_driver_nl80211_ibss(drv, params);
  4169. if (!(drv->capa.flags & WPA_DRIVER_FLAGS_SME)) {
  4170. enum nl80211_iftype nlmode = params->p2p ?
  4171. NL80211_IFTYPE_P2P_CLIENT : NL80211_IFTYPE_STATION;
  4172. if (wpa_driver_nl80211_set_mode(priv, nlmode) < 0)
  4173. return -1;
  4174. return wpa_driver_nl80211_connect(drv, params);
  4175. }
  4176. nl80211_mark_disconnected(drv);
  4177. wpa_printf(MSG_DEBUG, "nl80211: Associate (ifindex=%d)",
  4178. drv->ifindex);
  4179. msg = nl80211_drv_msg(drv, 0, NL80211_CMD_ASSOCIATE);
  4180. if (!msg)
  4181. return -1;
  4182. ret = nl80211_connect_common(drv, params, msg);
  4183. if (ret)
  4184. goto fail;
  4185. if (params->prev_bssid) {
  4186. wpa_printf(MSG_DEBUG, " * prev_bssid=" MACSTR,
  4187. MAC2STR(params->prev_bssid));
  4188. if (nla_put(msg, NL80211_ATTR_PREV_BSSID, ETH_ALEN,
  4189. params->prev_bssid))
  4190. goto fail;
  4191. }
  4192. ret = send_and_recv_msgs(drv, msg, NULL, NULL);
  4193. msg = NULL;
  4194. if (ret) {
  4195. wpa_dbg(drv->ctx, MSG_DEBUG,
  4196. "nl80211: MLME command failed (assoc): ret=%d (%s)",
  4197. ret, strerror(-ret));
  4198. nl80211_dump_scan(drv);
  4199. } else {
  4200. wpa_printf(MSG_DEBUG,
  4201. "nl80211: Association request send successfully");
  4202. }
  4203. fail:
  4204. nlmsg_free(msg);
  4205. return ret;
  4206. }
  4207. static int nl80211_set_mode(struct wpa_driver_nl80211_data *drv,
  4208. int ifindex, enum nl80211_iftype mode)
  4209. {
  4210. struct nl_msg *msg;
  4211. int ret = -ENOBUFS;
  4212. wpa_printf(MSG_DEBUG, "nl80211: Set mode ifindex %d iftype %d (%s)",
  4213. ifindex, mode, nl80211_iftype_str(mode));
  4214. msg = nl80211_cmd_msg(drv->first_bss, 0, NL80211_CMD_SET_INTERFACE);
  4215. if (!msg || nla_put_u32(msg, NL80211_ATTR_IFTYPE, mode))
  4216. goto fail;
  4217. ret = send_and_recv_msgs(drv, msg, NULL, NULL);
  4218. msg = NULL;
  4219. if (!ret)
  4220. return 0;
  4221. fail:
  4222. nlmsg_free(msg);
  4223. wpa_printf(MSG_DEBUG, "nl80211: Failed to set interface %d to mode %d:"
  4224. " %d (%s)", ifindex, mode, ret, strerror(-ret));
  4225. return ret;
  4226. }
  4227. static int wpa_driver_nl80211_set_mode_impl(
  4228. struct i802_bss *bss,
  4229. enum nl80211_iftype nlmode,
  4230. struct hostapd_freq_params *desired_freq_params)
  4231. {
  4232. struct wpa_driver_nl80211_data *drv = bss->drv;
  4233. int ret = -1;
  4234. int i;
  4235. int was_ap = is_ap_interface(drv->nlmode);
  4236. int res;
  4237. int mode_switch_res;
  4238. mode_switch_res = nl80211_set_mode(drv, drv->ifindex, nlmode);
  4239. if (mode_switch_res && nlmode == nl80211_get_ifmode(bss))
  4240. mode_switch_res = 0;
  4241. if (mode_switch_res == 0) {
  4242. drv->nlmode = nlmode;
  4243. ret = 0;
  4244. goto done;
  4245. }
  4246. if (mode_switch_res == -ENODEV)
  4247. return -1;
  4248. if (nlmode == drv->nlmode) {
  4249. wpa_printf(MSG_DEBUG, "nl80211: Interface already in "
  4250. "requested mode - ignore error");
  4251. ret = 0;
  4252. goto done; /* Already in the requested mode */
  4253. }
  4254. /* mac80211 doesn't allow mode changes while the device is up, so
  4255. * take the device down, try to set the mode again, and bring the
  4256. * device back up.
  4257. */
  4258. wpa_printf(MSG_DEBUG, "nl80211: Try mode change after setting "
  4259. "interface down");
  4260. for (i = 0; i < 10; i++) {
  4261. res = i802_set_iface_flags(bss, 0);
  4262. if (res == -EACCES || res == -ENODEV)
  4263. break;
  4264. if (res != 0) {
  4265. wpa_printf(MSG_DEBUG, "nl80211: Failed to set "
  4266. "interface down");
  4267. os_sleep(0, 100000);
  4268. continue;
  4269. }
  4270. /*
  4271. * Setting the mode will fail for some drivers if the phy is
  4272. * on a frequency that the mode is disallowed in.
  4273. */
  4274. if (desired_freq_params) {
  4275. res = nl80211_set_channel(bss, desired_freq_params, 0);
  4276. if (res) {
  4277. wpa_printf(MSG_DEBUG,
  4278. "nl80211: Failed to set frequency on interface");
  4279. }
  4280. }
  4281. /* Try to set the mode again while the interface is down */
  4282. mode_switch_res = nl80211_set_mode(drv, drv->ifindex, nlmode);
  4283. if (mode_switch_res == -EBUSY) {
  4284. wpa_printf(MSG_DEBUG,
  4285. "nl80211: Delaying mode set while interface going down");
  4286. os_sleep(0, 100000);
  4287. continue;
  4288. }
  4289. ret = mode_switch_res;
  4290. break;
  4291. }
  4292. if (!ret) {
  4293. wpa_printf(MSG_DEBUG, "nl80211: Mode change succeeded while "
  4294. "interface is down");
  4295. drv->nlmode = nlmode;
  4296. drv->ignore_if_down_event = 1;
  4297. }
  4298. /* Bring the interface back up */
  4299. res = linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 1);
  4300. if (res != 0) {
  4301. wpa_printf(MSG_DEBUG,
  4302. "nl80211: Failed to set interface up after switching mode");
  4303. ret = -1;
  4304. }
  4305. done:
  4306. if (ret) {
  4307. wpa_printf(MSG_DEBUG, "nl80211: Interface mode change to %d "
  4308. "from %d failed", nlmode, drv->nlmode);
  4309. return ret;
  4310. }
  4311. if (is_p2p_net_interface(nlmode)) {
  4312. wpa_printf(MSG_DEBUG,
  4313. "nl80211: Interface %s mode change to P2P - disable 11b rates",
  4314. bss->ifname);
  4315. nl80211_disable_11b_rates(drv, drv->ifindex, 1);
  4316. } else if (drv->disabled_11b_rates) {
  4317. wpa_printf(MSG_DEBUG,
  4318. "nl80211: Interface %s mode changed to non-P2P - re-enable 11b rates",
  4319. bss->ifname);
  4320. nl80211_disable_11b_rates(drv, drv->ifindex, 0);
  4321. }
  4322. if (is_ap_interface(nlmode)) {
  4323. nl80211_mgmt_unsubscribe(bss, "start AP");
  4324. /* Setup additional AP mode functionality if needed */
  4325. if (nl80211_setup_ap(bss))
  4326. return -1;
  4327. } else if (was_ap) {
  4328. /* Remove additional AP mode functionality */
  4329. nl80211_teardown_ap(bss);
  4330. } else {
  4331. nl80211_mgmt_unsubscribe(bss, "mode change");
  4332. }
  4333. if (is_mesh_interface(nlmode) &&
  4334. nl80211_mgmt_subscribe_mesh(bss))
  4335. return -1;
  4336. if (!bss->in_deinit && !is_ap_interface(nlmode) &&
  4337. !is_mesh_interface(nlmode) &&
  4338. nl80211_mgmt_subscribe_non_ap(bss) < 0)
  4339. wpa_printf(MSG_DEBUG, "nl80211: Failed to register Action "
  4340. "frame processing - ignore for now");
  4341. return 0;
  4342. }
  4343. int wpa_driver_nl80211_set_mode(struct i802_bss *bss,
  4344. enum nl80211_iftype nlmode)
  4345. {
  4346. return wpa_driver_nl80211_set_mode_impl(bss, nlmode, NULL);
  4347. }
  4348. static int wpa_driver_nl80211_set_mode_ibss(struct i802_bss *bss,
  4349. struct hostapd_freq_params *freq)
  4350. {
  4351. return wpa_driver_nl80211_set_mode_impl(bss, NL80211_IFTYPE_ADHOC,
  4352. freq);
  4353. }
  4354. static int wpa_driver_nl80211_get_capa(void *priv,
  4355. struct wpa_driver_capa *capa)
  4356. {
  4357. struct i802_bss *bss = priv;
  4358. struct wpa_driver_nl80211_data *drv = bss->drv;
  4359. if (!drv->has_capability)
  4360. return -1;
  4361. os_memcpy(capa, &drv->capa, sizeof(*capa));
  4362. if (drv->extended_capa && drv->extended_capa_mask) {
  4363. capa->extended_capa = drv->extended_capa;
  4364. capa->extended_capa_mask = drv->extended_capa_mask;
  4365. capa->extended_capa_len = drv->extended_capa_len;
  4366. }
  4367. return 0;
  4368. }
  4369. static int wpa_driver_nl80211_set_operstate(void *priv, int state)
  4370. {
  4371. struct i802_bss *bss = priv;
  4372. struct wpa_driver_nl80211_data *drv = bss->drv;
  4373. wpa_printf(MSG_DEBUG, "nl80211: Set %s operstate %d->%d (%s)",
  4374. bss->ifname, drv->operstate, state,
  4375. state ? "UP" : "DORMANT");
  4376. drv->operstate = state;
  4377. return netlink_send_oper_ifla(drv->global->netlink, drv->ifindex, -1,
  4378. state ? IF_OPER_UP : IF_OPER_DORMANT);
  4379. }
  4380. static int wpa_driver_nl80211_set_supp_port(void *priv, int authorized)
  4381. {
  4382. struct i802_bss *bss = priv;
  4383. struct wpa_driver_nl80211_data *drv = bss->drv;
  4384. struct nl_msg *msg;
  4385. struct nl80211_sta_flag_update upd;
  4386. int ret;
  4387. if (!drv->associated && is_zero_ether_addr(drv->bssid) && !authorized) {
  4388. wpa_printf(MSG_DEBUG, "nl80211: Skip set_supp_port(unauthorized) while not associated");
  4389. return 0;
  4390. }
  4391. wpa_printf(MSG_DEBUG, "nl80211: Set supplicant port %sauthorized for "
  4392. MACSTR, authorized ? "" : "un", MAC2STR(drv->bssid));
  4393. os_memset(&upd, 0, sizeof(upd));
  4394. upd.mask = BIT(NL80211_STA_FLAG_AUTHORIZED);
  4395. if (authorized)
  4396. upd.set = BIT(NL80211_STA_FLAG_AUTHORIZED);
  4397. if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) ||
  4398. nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, drv->bssid) ||
  4399. nla_put(msg, NL80211_ATTR_STA_FLAGS2, sizeof(upd), &upd)) {
  4400. nlmsg_free(msg);
  4401. return -ENOBUFS;
  4402. }
  4403. ret = send_and_recv_msgs(drv, msg, NULL, NULL);
  4404. if (!ret)
  4405. return 0;
  4406. wpa_printf(MSG_DEBUG, "nl80211: Failed to set STA flag: %d (%s)",
  4407. ret, strerror(-ret));
  4408. return ret;
  4409. }
  4410. /* Set kernel driver on given frequency (MHz) */
  4411. static int i802_set_freq(void *priv, struct hostapd_freq_params *freq)
  4412. {
  4413. struct i802_bss *bss = priv;
  4414. return nl80211_set_channel(bss, freq, 0);
  4415. }
  4416. static inline int min_int(int a, int b)
  4417. {
  4418. if (a < b)
  4419. return a;
  4420. return b;
  4421. }
  4422. static int get_key_handler(struct nl_msg *msg, void *arg)
  4423. {
  4424. struct nlattr *tb[NL80211_ATTR_MAX + 1];
  4425. struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
  4426. nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
  4427. genlmsg_attrlen(gnlh, 0), NULL);
  4428. /*
  4429. * TODO: validate the key index and mac address!
  4430. * Otherwise, there's a race condition as soon as
  4431. * the kernel starts sending key notifications.
  4432. */
  4433. if (tb[NL80211_ATTR_KEY_SEQ])
  4434. memcpy(arg, nla_data(tb[NL80211_ATTR_KEY_SEQ]),
  4435. min_int(nla_len(tb[NL80211_ATTR_KEY_SEQ]), 6));
  4436. return NL_SKIP;
  4437. }
  4438. static int i802_get_seqnum(const char *iface, void *priv, const u8 *addr,
  4439. int idx, u8 *seq)
  4440. {
  4441. struct i802_bss *bss = priv;
  4442. struct wpa_driver_nl80211_data *drv = bss->drv;
  4443. struct nl_msg *msg;
  4444. msg = nl80211_ifindex_msg(drv, if_nametoindex(iface), 0,
  4445. NL80211_CMD_GET_KEY);
  4446. if (!msg ||
  4447. (addr && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) ||
  4448. nla_put_u8(msg, NL80211_ATTR_KEY_IDX, idx)) {
  4449. nlmsg_free(msg);
  4450. return -ENOBUFS;
  4451. }
  4452. memset(seq, 0, 6);
  4453. return send_and_recv_msgs(drv, msg, get_key_handler, seq);
  4454. }
  4455. static int i802_set_rts(void *priv, int rts)
  4456. {
  4457. struct i802_bss *bss = priv;
  4458. struct wpa_driver_nl80211_data *drv = bss->drv;
  4459. struct nl_msg *msg;
  4460. int ret;
  4461. u32 val;
  4462. if (rts >= 2347)
  4463. val = (u32) -1;
  4464. else
  4465. val = rts;
  4466. if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_WIPHY)) ||
  4467. nla_put_u32(msg, NL80211_ATTR_WIPHY_RTS_THRESHOLD, val)) {
  4468. nlmsg_free(msg);
  4469. return -ENOBUFS;
  4470. }
  4471. ret = send_and_recv_msgs(drv, msg, NULL, NULL);
  4472. if (!ret)
  4473. return 0;
  4474. wpa_printf(MSG_DEBUG, "nl80211: Failed to set RTS threshold %d: "
  4475. "%d (%s)", rts, ret, strerror(-ret));
  4476. return ret;
  4477. }
  4478. static int i802_set_frag(void *priv, int frag)
  4479. {
  4480. struct i802_bss *bss = priv;
  4481. struct wpa_driver_nl80211_data *drv = bss->drv;
  4482. struct nl_msg *msg;
  4483. int ret;
  4484. u32 val;
  4485. if (frag >= 2346)
  4486. val = (u32) -1;
  4487. else
  4488. val = frag;
  4489. if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_WIPHY)) ||
  4490. nla_put_u32(msg, NL80211_ATTR_WIPHY_FRAG_THRESHOLD, val)) {
  4491. nlmsg_free(msg);
  4492. return -ENOBUFS;
  4493. }
  4494. ret = send_and_recv_msgs(drv, msg, NULL, NULL);
  4495. if (!ret)
  4496. return 0;
  4497. wpa_printf(MSG_DEBUG, "nl80211: Failed to set fragmentation threshold "
  4498. "%d: %d (%s)", frag, ret, strerror(-ret));
  4499. return ret;
  4500. }
  4501. static int i802_flush(void *priv)
  4502. {
  4503. struct i802_bss *bss = priv;
  4504. struct nl_msg *msg;
  4505. int res;
  4506. wpa_printf(MSG_DEBUG, "nl80211: flush -> DEL_STATION %s (all)",
  4507. bss->ifname);
  4508. /*
  4509. * XXX: FIX! this needs to flush all VLANs too
  4510. */
  4511. msg = nl80211_bss_msg(bss, 0, NL80211_CMD_DEL_STATION);
  4512. res = send_and_recv_msgs(bss->drv, msg, NULL, NULL);
  4513. if (res) {
  4514. wpa_printf(MSG_DEBUG, "nl80211: Station flush failed: ret=%d "
  4515. "(%s)", res, strerror(-res));
  4516. }
  4517. return res;
  4518. }
  4519. static int get_sta_handler(struct nl_msg *msg, void *arg)
  4520. {
  4521. struct nlattr *tb[NL80211_ATTR_MAX + 1];
  4522. struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
  4523. struct hostap_sta_driver_data *data = arg;
  4524. struct nlattr *stats[NL80211_STA_INFO_MAX + 1];
  4525. static struct nla_policy stats_policy[NL80211_STA_INFO_MAX + 1] = {
  4526. [NL80211_STA_INFO_INACTIVE_TIME] = { .type = NLA_U32 },
  4527. [NL80211_STA_INFO_RX_BYTES] = { .type = NLA_U32 },
  4528. [NL80211_STA_INFO_TX_BYTES] = { .type = NLA_U32 },
  4529. [NL80211_STA_INFO_RX_PACKETS] = { .type = NLA_U32 },
  4530. [NL80211_STA_INFO_TX_PACKETS] = { .type = NLA_U32 },
  4531. [NL80211_STA_INFO_TX_FAILED] = { .type = NLA_U32 },
  4532. [NL80211_STA_INFO_RX_BYTES64] = { .type = NLA_U64 },
  4533. [NL80211_STA_INFO_TX_BYTES64] = { .type = NLA_U64 },
  4534. };
  4535. nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
  4536. genlmsg_attrlen(gnlh, 0), NULL);
  4537. /*
  4538. * TODO: validate the interface and mac address!
  4539. * Otherwise, there's a race condition as soon as
  4540. * the kernel starts sending station notifications.
  4541. */
  4542. if (!tb[NL80211_ATTR_STA_INFO]) {
  4543. wpa_printf(MSG_DEBUG, "sta stats missing!");
  4544. return NL_SKIP;
  4545. }
  4546. if (nla_parse_nested(stats, NL80211_STA_INFO_MAX,
  4547. tb[NL80211_ATTR_STA_INFO],
  4548. stats_policy)) {
  4549. wpa_printf(MSG_DEBUG, "failed to parse nested attributes!");
  4550. return NL_SKIP;
  4551. }
  4552. if (stats[NL80211_STA_INFO_INACTIVE_TIME])
  4553. data->inactive_msec =
  4554. nla_get_u32(stats[NL80211_STA_INFO_INACTIVE_TIME]);
  4555. /* For backwards compatibility, fetch the 32-bit counters first. */
  4556. if (stats[NL80211_STA_INFO_RX_BYTES])
  4557. data->rx_bytes = nla_get_u32(stats[NL80211_STA_INFO_RX_BYTES]);
  4558. if (stats[NL80211_STA_INFO_TX_BYTES])
  4559. data->tx_bytes = nla_get_u32(stats[NL80211_STA_INFO_TX_BYTES]);
  4560. if (stats[NL80211_STA_INFO_RX_BYTES64] &&
  4561. stats[NL80211_STA_INFO_TX_BYTES64]) {
  4562. /*
  4563. * The driver supports 64-bit counters, so use them to override
  4564. * the 32-bit values.
  4565. */
  4566. data->rx_bytes =
  4567. nla_get_u64(stats[NL80211_STA_INFO_RX_BYTES64]);
  4568. data->tx_bytes =
  4569. nla_get_u64(stats[NL80211_STA_INFO_TX_BYTES64]);
  4570. data->bytes_64bit = 1;
  4571. }
  4572. if (stats[NL80211_STA_INFO_RX_PACKETS])
  4573. data->rx_packets =
  4574. nla_get_u32(stats[NL80211_STA_INFO_RX_PACKETS]);
  4575. if (stats[NL80211_STA_INFO_TX_PACKETS])
  4576. data->tx_packets =
  4577. nla_get_u32(stats[NL80211_STA_INFO_TX_PACKETS]);
  4578. if (stats[NL80211_STA_INFO_TX_FAILED])
  4579. data->tx_retry_failed =
  4580. nla_get_u32(stats[NL80211_STA_INFO_TX_FAILED]);
  4581. return NL_SKIP;
  4582. }
  4583. static int i802_read_sta_data(struct i802_bss *bss,
  4584. struct hostap_sta_driver_data *data,
  4585. const u8 *addr)
  4586. {
  4587. struct nl_msg *msg;
  4588. os_memset(data, 0, sizeof(*data));
  4589. if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_GET_STATION)) ||
  4590. nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) {
  4591. nlmsg_free(msg);
  4592. return -ENOBUFS;
  4593. }
  4594. return send_and_recv_msgs(bss->drv, msg, get_sta_handler, data);
  4595. }
  4596. static int i802_set_tx_queue_params(void *priv, int queue, int aifs,
  4597. int cw_min, int cw_max, int burst_time)
  4598. {
  4599. struct i802_bss *bss = priv;
  4600. struct wpa_driver_nl80211_data *drv = bss->drv;
  4601. struct nl_msg *msg;
  4602. struct nlattr *txq, *params;
  4603. msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_WIPHY);
  4604. if (!msg)
  4605. return -1;
  4606. txq = nla_nest_start(msg, NL80211_ATTR_WIPHY_TXQ_PARAMS);
  4607. if (!txq)
  4608. goto fail;
  4609. /* We are only sending parameters for a single TXQ at a time */
  4610. params = nla_nest_start(msg, 1);
  4611. if (!params)
  4612. goto fail;
  4613. switch (queue) {
  4614. case 0:
  4615. if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_VO))
  4616. goto fail;
  4617. break;
  4618. case 1:
  4619. if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_VI))
  4620. goto fail;
  4621. break;
  4622. case 2:
  4623. if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_BE))
  4624. goto fail;
  4625. break;
  4626. case 3:
  4627. if (nla_put_u8(msg, NL80211_TXQ_ATTR_QUEUE, NL80211_TXQ_Q_BK))
  4628. goto fail;
  4629. break;
  4630. }
  4631. /* Burst time is configured in units of 0.1 msec and TXOP parameter in
  4632. * 32 usec, so need to convert the value here. */
  4633. if (nla_put_u16(msg, NL80211_TXQ_ATTR_TXOP,
  4634. (burst_time * 100 + 16) / 32) ||
  4635. nla_put_u16(msg, NL80211_TXQ_ATTR_CWMIN, cw_min) ||
  4636. nla_put_u16(msg, NL80211_TXQ_ATTR_CWMAX, cw_max) ||
  4637. nla_put_u8(msg, NL80211_TXQ_ATTR_AIFS, aifs))
  4638. goto fail;
  4639. nla_nest_end(msg, params);
  4640. nla_nest_end(msg, txq);
  4641. if (send_and_recv_msgs(drv, msg, NULL, NULL) == 0)
  4642. return 0;
  4643. msg = NULL;
  4644. fail:
  4645. nlmsg_free(msg);
  4646. return -1;
  4647. }
  4648. static int i802_set_sta_vlan(struct i802_bss *bss, const u8 *addr,
  4649. const char *ifname, int vlan_id)
  4650. {
  4651. struct wpa_driver_nl80211_data *drv = bss->drv;
  4652. struct nl_msg *msg;
  4653. int ret;
  4654. wpa_printf(MSG_DEBUG, "nl80211: %s[%d]: set_sta_vlan(" MACSTR
  4655. ", ifname=%s[%d], vlan_id=%d)",
  4656. bss->ifname, if_nametoindex(bss->ifname),
  4657. MAC2STR(addr), ifname, if_nametoindex(ifname), vlan_id);
  4658. if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_STATION)) ||
  4659. nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
  4660. nla_put_u32(msg, NL80211_ATTR_STA_VLAN, if_nametoindex(ifname))) {
  4661. nlmsg_free(msg);
  4662. return -ENOBUFS;
  4663. }
  4664. ret = send_and_recv_msgs(drv, msg, NULL, NULL);
  4665. if (ret < 0) {
  4666. wpa_printf(MSG_ERROR, "nl80211: NL80211_ATTR_STA_VLAN (addr="
  4667. MACSTR " ifname=%s vlan_id=%d) failed: %d (%s)",
  4668. MAC2STR(addr), ifname, vlan_id, ret,
  4669. strerror(-ret));
  4670. }
  4671. return ret;
  4672. }
  4673. static int i802_get_inact_sec(void *priv, const u8 *addr)
  4674. {
  4675. struct hostap_sta_driver_data data;
  4676. int ret;
  4677. data.inactive_msec = (unsigned long) -1;
  4678. ret = i802_read_sta_data(priv, &data, addr);
  4679. if (ret == -ENOENT)
  4680. return -ENOENT;
  4681. if (ret || data.inactive_msec == (unsigned long) -1)
  4682. return -1;
  4683. return data.inactive_msec / 1000;
  4684. }
  4685. static int i802_sta_clear_stats(void *priv, const u8 *addr)
  4686. {
  4687. #if 0
  4688. /* TODO */
  4689. #endif
  4690. return 0;
  4691. }
  4692. static int i802_sta_deauth(void *priv, const u8 *own_addr, const u8 *addr,
  4693. int reason)
  4694. {
  4695. struct i802_bss *bss = priv;
  4696. struct wpa_driver_nl80211_data *drv = bss->drv;
  4697. struct ieee80211_mgmt mgmt;
  4698. if (is_mesh_interface(drv->nlmode))
  4699. return -1;
  4700. if (drv->device_ap_sme)
  4701. return wpa_driver_nl80211_sta_remove(bss, addr, 1, reason);
  4702. memset(&mgmt, 0, sizeof(mgmt));
  4703. mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
  4704. WLAN_FC_STYPE_DEAUTH);
  4705. memcpy(mgmt.da, addr, ETH_ALEN);
  4706. memcpy(mgmt.sa, own_addr, ETH_ALEN);
  4707. memcpy(mgmt.bssid, own_addr, ETH_ALEN);
  4708. mgmt.u.deauth.reason_code = host_to_le16(reason);
  4709. return wpa_driver_nl80211_send_mlme(bss, (u8 *) &mgmt,
  4710. IEEE80211_HDRLEN +
  4711. sizeof(mgmt.u.deauth), 0, 0, 0, 0,
  4712. 0, NULL, 0);
  4713. }
  4714. static int i802_sta_disassoc(void *priv, const u8 *own_addr, const u8 *addr,
  4715. int reason)
  4716. {
  4717. struct i802_bss *bss = priv;
  4718. struct wpa_driver_nl80211_data *drv = bss->drv;
  4719. struct ieee80211_mgmt mgmt;
  4720. if (is_mesh_interface(drv->nlmode))
  4721. return -1;
  4722. if (drv->device_ap_sme)
  4723. return wpa_driver_nl80211_sta_remove(bss, addr, 0, reason);
  4724. memset(&mgmt, 0, sizeof(mgmt));
  4725. mgmt.frame_control = IEEE80211_FC(WLAN_FC_TYPE_MGMT,
  4726. WLAN_FC_STYPE_DISASSOC);
  4727. memcpy(mgmt.da, addr, ETH_ALEN);
  4728. memcpy(mgmt.sa, own_addr, ETH_ALEN);
  4729. memcpy(mgmt.bssid, own_addr, ETH_ALEN);
  4730. mgmt.u.disassoc.reason_code = host_to_le16(reason);
  4731. return wpa_driver_nl80211_send_mlme(bss, (u8 *) &mgmt,
  4732. IEEE80211_HDRLEN +
  4733. sizeof(mgmt.u.disassoc), 0, 0, 0, 0,
  4734. 0, NULL, 0);
  4735. }
  4736. static void dump_ifidx(struct wpa_driver_nl80211_data *drv)
  4737. {
  4738. char buf[200], *pos, *end;
  4739. int i, res;
  4740. pos = buf;
  4741. end = pos + sizeof(buf);
  4742. for (i = 0; i < drv->num_if_indices; i++) {
  4743. if (!drv->if_indices[i])
  4744. continue;
  4745. res = os_snprintf(pos, end - pos, " %d(%d)",
  4746. drv->if_indices[i],
  4747. drv->if_indices_reason[i]);
  4748. if (os_snprintf_error(end - pos, res))
  4749. break;
  4750. pos += res;
  4751. }
  4752. *pos = '\0';
  4753. wpa_printf(MSG_DEBUG, "nl80211: if_indices[%d]:%s",
  4754. drv->num_if_indices, buf);
  4755. }
  4756. static void add_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx,
  4757. int ifidx_reason)
  4758. {
  4759. int i;
  4760. int *old, *old_reason;
  4761. wpa_printf(MSG_DEBUG,
  4762. "nl80211: Add own interface ifindex %d (ifidx_reason %d)",
  4763. ifidx, ifidx_reason);
  4764. if (have_ifidx(drv, ifidx, ifidx_reason)) {
  4765. wpa_printf(MSG_DEBUG, "nl80211: ifindex %d already in the list",
  4766. ifidx);
  4767. return;
  4768. }
  4769. for (i = 0; i < drv->num_if_indices; i++) {
  4770. if (drv->if_indices[i] == 0) {
  4771. drv->if_indices[i] = ifidx;
  4772. drv->if_indices_reason[i] = ifidx_reason;
  4773. dump_ifidx(drv);
  4774. return;
  4775. }
  4776. }
  4777. if (drv->if_indices != drv->default_if_indices)
  4778. old = drv->if_indices;
  4779. else
  4780. old = NULL;
  4781. if (drv->if_indices_reason != drv->default_if_indices_reason)
  4782. old_reason = drv->if_indices_reason;
  4783. else
  4784. old_reason = NULL;
  4785. drv->if_indices = os_realloc_array(old, drv->num_if_indices + 1,
  4786. sizeof(int));
  4787. drv->if_indices_reason = os_realloc_array(old_reason,
  4788. drv->num_if_indices + 1,
  4789. sizeof(int));
  4790. if (!drv->if_indices) {
  4791. if (!old)
  4792. drv->if_indices = drv->default_if_indices;
  4793. else
  4794. drv->if_indices = old;
  4795. }
  4796. if (!drv->if_indices_reason) {
  4797. if (!old_reason)
  4798. drv->if_indices_reason = drv->default_if_indices_reason;
  4799. else
  4800. drv->if_indices_reason = old_reason;
  4801. }
  4802. if (!drv->if_indices || !drv->if_indices_reason) {
  4803. wpa_printf(MSG_ERROR, "Failed to reallocate memory for "
  4804. "interfaces");
  4805. wpa_printf(MSG_ERROR, "Ignoring EAPOL on interface %d", ifidx);
  4806. return;
  4807. }
  4808. if (!old)
  4809. os_memcpy(drv->if_indices, drv->default_if_indices,
  4810. sizeof(drv->default_if_indices));
  4811. if (!old_reason)
  4812. os_memcpy(drv->if_indices_reason,
  4813. drv->default_if_indices_reason,
  4814. sizeof(drv->default_if_indices_reason));
  4815. drv->if_indices[drv->num_if_indices] = ifidx;
  4816. drv->if_indices_reason[drv->num_if_indices] = ifidx_reason;
  4817. drv->num_if_indices++;
  4818. dump_ifidx(drv);
  4819. }
  4820. static void del_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx,
  4821. int ifidx_reason)
  4822. {
  4823. int i;
  4824. for (i = 0; i < drv->num_if_indices; i++) {
  4825. if ((drv->if_indices[i] == ifidx || ifidx == IFIDX_ANY) &&
  4826. (drv->if_indices_reason[i] == ifidx_reason ||
  4827. ifidx_reason == IFIDX_ANY)) {
  4828. drv->if_indices[i] = 0;
  4829. break;
  4830. }
  4831. }
  4832. dump_ifidx(drv);
  4833. }
  4834. static int have_ifidx(struct wpa_driver_nl80211_data *drv, int ifidx,
  4835. int ifidx_reason)
  4836. {
  4837. int i;
  4838. for (i = 0; i < drv->num_if_indices; i++)
  4839. if (drv->if_indices[i] == ifidx &&
  4840. (drv->if_indices_reason[i] == ifidx_reason ||
  4841. ifidx_reason == IFIDX_ANY))
  4842. return 1;
  4843. return 0;
  4844. }
  4845. static int i802_set_wds_sta(void *priv, const u8 *addr, int aid, int val,
  4846. const char *bridge_ifname, char *ifname_wds)
  4847. {
  4848. struct i802_bss *bss = priv;
  4849. struct wpa_driver_nl80211_data *drv = bss->drv;
  4850. char name[IFNAMSIZ + 1];
  4851. os_snprintf(name, sizeof(name), "%s.sta%d", bss->ifname, aid);
  4852. if (ifname_wds)
  4853. os_strlcpy(ifname_wds, name, IFNAMSIZ + 1);
  4854. wpa_printf(MSG_DEBUG, "nl80211: Set WDS STA addr=" MACSTR
  4855. " aid=%d val=%d name=%s", MAC2STR(addr), aid, val, name);
  4856. if (val) {
  4857. if (!if_nametoindex(name)) {
  4858. if (nl80211_create_iface(drv, name,
  4859. NL80211_IFTYPE_AP_VLAN,
  4860. bss->addr, 1, NULL, NULL, 0) <
  4861. 0)
  4862. return -1;
  4863. if (bridge_ifname &&
  4864. linux_br_add_if(drv->global->ioctl_sock,
  4865. bridge_ifname, name) < 0)
  4866. return -1;
  4867. }
  4868. if (linux_set_iface_flags(drv->global->ioctl_sock, name, 1)) {
  4869. wpa_printf(MSG_ERROR, "nl80211: Failed to set WDS STA "
  4870. "interface %s up", name);
  4871. }
  4872. return i802_set_sta_vlan(priv, addr, name, 0);
  4873. } else {
  4874. if (bridge_ifname)
  4875. linux_br_del_if(drv->global->ioctl_sock, bridge_ifname,
  4876. name);
  4877. i802_set_sta_vlan(priv, addr, bss->ifname, 0);
  4878. nl80211_remove_iface(drv, if_nametoindex(name));
  4879. return 0;
  4880. }
  4881. }
  4882. static void handle_eapol(int sock, void *eloop_ctx, void *sock_ctx)
  4883. {
  4884. struct wpa_driver_nl80211_data *drv = eloop_ctx;
  4885. struct sockaddr_ll lladdr;
  4886. unsigned char buf[3000];
  4887. int len;
  4888. socklen_t fromlen = sizeof(lladdr);
  4889. len = recvfrom(sock, buf, sizeof(buf), 0,
  4890. (struct sockaddr *)&lladdr, &fromlen);
  4891. if (len < 0) {
  4892. wpa_printf(MSG_ERROR, "nl80211: EAPOL recv failed: %s",
  4893. strerror(errno));
  4894. return;
  4895. }
  4896. if (have_ifidx(drv, lladdr.sll_ifindex, IFIDX_ANY))
  4897. drv_event_eapol_rx(drv->ctx, lladdr.sll_addr, buf, len);
  4898. }
  4899. static int i802_check_bridge(struct wpa_driver_nl80211_data *drv,
  4900. struct i802_bss *bss,
  4901. const char *brname, const char *ifname)
  4902. {
  4903. int br_ifindex;
  4904. char in_br[IFNAMSIZ];
  4905. os_strlcpy(bss->brname, brname, IFNAMSIZ);
  4906. br_ifindex = if_nametoindex(brname);
  4907. if (br_ifindex == 0) {
  4908. /*
  4909. * Bridge was configured, but the bridge device does
  4910. * not exist. Try to add it now.
  4911. */
  4912. if (linux_br_add(drv->global->ioctl_sock, brname) < 0) {
  4913. wpa_printf(MSG_ERROR, "nl80211: Failed to add the "
  4914. "bridge interface %s: %s",
  4915. brname, strerror(errno));
  4916. return -1;
  4917. }
  4918. bss->added_bridge = 1;
  4919. br_ifindex = if_nametoindex(brname);
  4920. add_ifidx(drv, br_ifindex, drv->ifindex);
  4921. }
  4922. bss->br_ifindex = br_ifindex;
  4923. if (linux_br_get(in_br, ifname) == 0) {
  4924. if (os_strcmp(in_br, brname) == 0)
  4925. return 0; /* already in the bridge */
  4926. wpa_printf(MSG_DEBUG, "nl80211: Removing interface %s from "
  4927. "bridge %s", ifname, in_br);
  4928. if (linux_br_del_if(drv->global->ioctl_sock, in_br, ifname) <
  4929. 0) {
  4930. wpa_printf(MSG_ERROR, "nl80211: Failed to "
  4931. "remove interface %s from bridge "
  4932. "%s: %s",
  4933. ifname, brname, strerror(errno));
  4934. return -1;
  4935. }
  4936. }
  4937. wpa_printf(MSG_DEBUG, "nl80211: Adding interface %s into bridge %s",
  4938. ifname, brname);
  4939. if (linux_br_add_if(drv->global->ioctl_sock, brname, ifname) < 0) {
  4940. wpa_printf(MSG_ERROR, "nl80211: Failed to add interface %s "
  4941. "into bridge %s: %s",
  4942. ifname, brname, strerror(errno));
  4943. return -1;
  4944. }
  4945. bss->added_if_into_bridge = 1;
  4946. return 0;
  4947. }
  4948. static void *i802_init(struct hostapd_data *hapd,
  4949. struct wpa_init_params *params)
  4950. {
  4951. struct wpa_driver_nl80211_data *drv;
  4952. struct i802_bss *bss;
  4953. size_t i;
  4954. char master_ifname[IFNAMSIZ];
  4955. int ifindex, br_ifindex = 0;
  4956. int br_added = 0;
  4957. bss = wpa_driver_nl80211_drv_init(hapd, params->ifname,
  4958. params->global_priv, 1,
  4959. params->bssid, params->driver_params);
  4960. if (bss == NULL)
  4961. return NULL;
  4962. drv = bss->drv;
  4963. if (linux_br_get(master_ifname, params->ifname) == 0) {
  4964. wpa_printf(MSG_DEBUG, "nl80211: Interface %s is in bridge %s",
  4965. params->ifname, master_ifname);
  4966. br_ifindex = if_nametoindex(master_ifname);
  4967. os_strlcpy(bss->brname, master_ifname, IFNAMSIZ);
  4968. } else if ((params->num_bridge == 0 || !params->bridge[0]) &&
  4969. linux_master_get(master_ifname, params->ifname) == 0) {
  4970. wpa_printf(MSG_DEBUG, "nl80211: Interface %s is in master %s",
  4971. params->ifname, master_ifname);
  4972. /* start listening for EAPOL on the master interface */
  4973. add_ifidx(drv, if_nametoindex(master_ifname), drv->ifindex);
  4974. /* check if master itself is under bridge */
  4975. if (linux_br_get(master_ifname, master_ifname) == 0) {
  4976. wpa_printf(MSG_DEBUG, "nl80211: which is in bridge %s",
  4977. master_ifname);
  4978. br_ifindex = if_nametoindex(master_ifname);
  4979. os_strlcpy(bss->brname, master_ifname, IFNAMSIZ);
  4980. }
  4981. } else {
  4982. master_ifname[0] = '\0';
  4983. }
  4984. bss->br_ifindex = br_ifindex;
  4985. for (i = 0; i < params->num_bridge; i++) {
  4986. if (params->bridge[i]) {
  4987. ifindex = if_nametoindex(params->bridge[i]);
  4988. if (ifindex)
  4989. add_ifidx(drv, ifindex, drv->ifindex);
  4990. if (ifindex == br_ifindex)
  4991. br_added = 1;
  4992. }
  4993. }
  4994. /* start listening for EAPOL on the default AP interface */
  4995. add_ifidx(drv, drv->ifindex, IFIDX_ANY);
  4996. if (params->num_bridge && params->bridge[0]) {
  4997. if (i802_check_bridge(drv, bss, params->bridge[0],
  4998. params->ifname) < 0)
  4999. goto failed;
  5000. if (os_strcmp(params->bridge[0], master_ifname) != 0)
  5001. br_added = 1;
  5002. }
  5003. if (!br_added && br_ifindex &&
  5004. (params->num_bridge == 0 || !params->bridge[0]))
  5005. add_ifidx(drv, br_ifindex, drv->ifindex);
  5006. #ifdef CONFIG_LIBNL3_ROUTE
  5007. if (bss->added_if_into_bridge) {
  5008. drv->rtnl_sk = nl_socket_alloc();
  5009. if (drv->rtnl_sk == NULL) {
  5010. wpa_printf(MSG_ERROR, "nl80211: Failed to allocate nl_sock");
  5011. goto failed;
  5012. }
  5013. if (nl_connect(drv->rtnl_sk, NETLINK_ROUTE)) {
  5014. wpa_printf(MSG_ERROR, "nl80211: Failed to connect nl_sock to NETLINK_ROUTE: %s",
  5015. strerror(errno));
  5016. goto failed;
  5017. }
  5018. }
  5019. #endif /* CONFIG_LIBNL3_ROUTE */
  5020. drv->eapol_sock = socket(PF_PACKET, SOCK_DGRAM, htons(ETH_P_PAE));
  5021. if (drv->eapol_sock < 0) {
  5022. wpa_printf(MSG_ERROR, "nl80211: socket(PF_PACKET, SOCK_DGRAM, ETH_P_PAE) failed: %s",
  5023. strerror(errno));
  5024. goto failed;
  5025. }
  5026. if (eloop_register_read_sock(drv->eapol_sock, handle_eapol, drv, NULL))
  5027. {
  5028. wpa_printf(MSG_INFO, "nl80211: Could not register read socket for eapol");
  5029. goto failed;
  5030. }
  5031. if (linux_get_ifhwaddr(drv->global->ioctl_sock, bss->ifname,
  5032. params->own_addr))
  5033. goto failed;
  5034. os_memcpy(drv->perm_addr, params->own_addr, ETH_ALEN);
  5035. memcpy(bss->addr, params->own_addr, ETH_ALEN);
  5036. return bss;
  5037. failed:
  5038. wpa_driver_nl80211_deinit(bss);
  5039. return NULL;
  5040. }
  5041. static void i802_deinit(void *priv)
  5042. {
  5043. struct i802_bss *bss = priv;
  5044. wpa_driver_nl80211_deinit(bss);
  5045. }
  5046. static enum nl80211_iftype wpa_driver_nl80211_if_type(
  5047. enum wpa_driver_if_type type)
  5048. {
  5049. switch (type) {
  5050. case WPA_IF_STATION:
  5051. return NL80211_IFTYPE_STATION;
  5052. case WPA_IF_P2P_CLIENT:
  5053. case WPA_IF_P2P_GROUP:
  5054. return NL80211_IFTYPE_P2P_CLIENT;
  5055. case WPA_IF_AP_VLAN:
  5056. return NL80211_IFTYPE_AP_VLAN;
  5057. case WPA_IF_AP_BSS:
  5058. return NL80211_IFTYPE_AP;
  5059. case WPA_IF_P2P_GO:
  5060. return NL80211_IFTYPE_P2P_GO;
  5061. case WPA_IF_P2P_DEVICE:
  5062. return NL80211_IFTYPE_P2P_DEVICE;
  5063. case WPA_IF_MESH:
  5064. return NL80211_IFTYPE_MESH_POINT;
  5065. default:
  5066. return -1;
  5067. }
  5068. }
  5069. static int nl80211_addr_in_use(struct nl80211_global *global, const u8 *addr)
  5070. {
  5071. struct wpa_driver_nl80211_data *drv;
  5072. dl_list_for_each(drv, &global->interfaces,
  5073. struct wpa_driver_nl80211_data, list) {
  5074. if (os_memcmp(addr, drv->first_bss->addr, ETH_ALEN) == 0)
  5075. return 1;
  5076. }
  5077. return 0;
  5078. }
  5079. static int nl80211_vif_addr(struct wpa_driver_nl80211_data *drv, u8 *new_addr)
  5080. {
  5081. unsigned int idx;
  5082. if (!drv->global)
  5083. return -1;
  5084. os_memcpy(new_addr, drv->first_bss->addr, ETH_ALEN);
  5085. for (idx = 0; idx < 64; idx++) {
  5086. new_addr[0] = drv->first_bss->addr[0] | 0x02;
  5087. new_addr[0] ^= idx << 2;
  5088. if (!nl80211_addr_in_use(drv->global, new_addr))
  5089. break;
  5090. }
  5091. if (idx == 64)
  5092. return -1;
  5093. wpa_printf(MSG_DEBUG, "nl80211: Assigned new virtual interface address "
  5094. MACSTR, MAC2STR(new_addr));
  5095. return 0;
  5096. }
  5097. struct wdev_info {
  5098. u64 wdev_id;
  5099. int wdev_id_set;
  5100. u8 macaddr[ETH_ALEN];
  5101. };
  5102. static int nl80211_wdev_handler(struct nl_msg *msg, void *arg)
  5103. {
  5104. struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
  5105. struct nlattr *tb[NL80211_ATTR_MAX + 1];
  5106. struct wdev_info *wi = arg;
  5107. nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
  5108. genlmsg_attrlen(gnlh, 0), NULL);
  5109. if (tb[NL80211_ATTR_WDEV]) {
  5110. wi->wdev_id = nla_get_u64(tb[NL80211_ATTR_WDEV]);
  5111. wi->wdev_id_set = 1;
  5112. }
  5113. if (tb[NL80211_ATTR_MAC])
  5114. os_memcpy(wi->macaddr, nla_data(tb[NL80211_ATTR_MAC]),
  5115. ETH_ALEN);
  5116. return NL_SKIP;
  5117. }
  5118. static int wpa_driver_nl80211_if_add(void *priv, enum wpa_driver_if_type type,
  5119. const char *ifname, const u8 *addr,
  5120. void *bss_ctx, void **drv_priv,
  5121. char *force_ifname, u8 *if_addr,
  5122. const char *bridge, int use_existing,
  5123. int setup_ap)
  5124. {
  5125. enum nl80211_iftype nlmode;
  5126. struct i802_bss *bss = priv;
  5127. struct wpa_driver_nl80211_data *drv = bss->drv;
  5128. int ifidx;
  5129. int added = 1;
  5130. if (addr)
  5131. os_memcpy(if_addr, addr, ETH_ALEN);
  5132. nlmode = wpa_driver_nl80211_if_type(type);
  5133. if (nlmode == NL80211_IFTYPE_P2P_DEVICE) {
  5134. struct wdev_info p2pdev_info;
  5135. os_memset(&p2pdev_info, 0, sizeof(p2pdev_info));
  5136. ifidx = nl80211_create_iface(drv, ifname, nlmode, addr,
  5137. 0, nl80211_wdev_handler,
  5138. &p2pdev_info, use_existing);
  5139. if (!p2pdev_info.wdev_id_set || ifidx != 0) {
  5140. wpa_printf(MSG_ERROR, "nl80211: Failed to create a P2P Device interface %s",
  5141. ifname);
  5142. return -1;
  5143. }
  5144. drv->global->if_add_wdevid = p2pdev_info.wdev_id;
  5145. drv->global->if_add_wdevid_set = p2pdev_info.wdev_id_set;
  5146. if (!is_zero_ether_addr(p2pdev_info.macaddr))
  5147. os_memcpy(if_addr, p2pdev_info.macaddr, ETH_ALEN);
  5148. wpa_printf(MSG_DEBUG, "nl80211: New P2P Device interface %s (0x%llx) created",
  5149. ifname,
  5150. (long long unsigned int) p2pdev_info.wdev_id);
  5151. } else {
  5152. ifidx = nl80211_create_iface(drv, ifname, nlmode, addr,
  5153. 0, NULL, NULL, use_existing);
  5154. if (use_existing && ifidx == -ENFILE) {
  5155. added = 0;
  5156. ifidx = if_nametoindex(ifname);
  5157. } else if (ifidx < 0) {
  5158. return -1;
  5159. }
  5160. }
  5161. if (!addr) {
  5162. if (nlmode == NL80211_IFTYPE_P2P_DEVICE)
  5163. os_memcpy(if_addr, bss->addr, ETH_ALEN);
  5164. else if (linux_get_ifhwaddr(drv->global->ioctl_sock,
  5165. ifname, if_addr) < 0) {
  5166. if (added)
  5167. nl80211_remove_iface(drv, ifidx);
  5168. return -1;
  5169. }
  5170. }
  5171. if (!addr &&
  5172. (type == WPA_IF_P2P_CLIENT || type == WPA_IF_P2P_GROUP ||
  5173. type == WPA_IF_P2P_GO || type == WPA_IF_MESH ||
  5174. type == WPA_IF_STATION)) {
  5175. /* Enforce unique address */
  5176. u8 new_addr[ETH_ALEN];
  5177. if (linux_get_ifhwaddr(drv->global->ioctl_sock, ifname,
  5178. new_addr) < 0) {
  5179. if (added)
  5180. nl80211_remove_iface(drv, ifidx);
  5181. return -1;
  5182. }
  5183. if (nl80211_addr_in_use(drv->global, new_addr)) {
  5184. wpa_printf(MSG_DEBUG, "nl80211: Allocate new address "
  5185. "for interface %s type %d", ifname, type);
  5186. if (nl80211_vif_addr(drv, new_addr) < 0) {
  5187. if (added)
  5188. nl80211_remove_iface(drv, ifidx);
  5189. return -1;
  5190. }
  5191. if (linux_set_ifhwaddr(drv->global->ioctl_sock, ifname,
  5192. new_addr) < 0) {
  5193. if (added)
  5194. nl80211_remove_iface(drv, ifidx);
  5195. return -1;
  5196. }
  5197. }
  5198. os_memcpy(if_addr, new_addr, ETH_ALEN);
  5199. }
  5200. if (type == WPA_IF_AP_BSS && setup_ap) {
  5201. struct i802_bss *new_bss = os_zalloc(sizeof(*new_bss));
  5202. if (new_bss == NULL) {
  5203. if (added)
  5204. nl80211_remove_iface(drv, ifidx);
  5205. return -1;
  5206. }
  5207. if (bridge &&
  5208. i802_check_bridge(drv, new_bss, bridge, ifname) < 0) {
  5209. wpa_printf(MSG_ERROR, "nl80211: Failed to add the new "
  5210. "interface %s to a bridge %s",
  5211. ifname, bridge);
  5212. if (added)
  5213. nl80211_remove_iface(drv, ifidx);
  5214. os_free(new_bss);
  5215. return -1;
  5216. }
  5217. if (linux_set_iface_flags(drv->global->ioctl_sock, ifname, 1))
  5218. {
  5219. if (added)
  5220. nl80211_remove_iface(drv, ifidx);
  5221. os_free(new_bss);
  5222. return -1;
  5223. }
  5224. os_strlcpy(new_bss->ifname, ifname, IFNAMSIZ);
  5225. os_memcpy(new_bss->addr, if_addr, ETH_ALEN);
  5226. new_bss->ifindex = ifidx;
  5227. new_bss->drv = drv;
  5228. new_bss->next = drv->first_bss->next;
  5229. new_bss->freq = drv->first_bss->freq;
  5230. new_bss->ctx = bss_ctx;
  5231. new_bss->added_if = added;
  5232. drv->first_bss->next = new_bss;
  5233. if (drv_priv)
  5234. *drv_priv = new_bss;
  5235. nl80211_init_bss(new_bss);
  5236. /* Subscribe management frames for this WPA_IF_AP_BSS */
  5237. if (nl80211_setup_ap(new_bss))
  5238. return -1;
  5239. }
  5240. if (drv->global)
  5241. drv->global->if_add_ifindex = ifidx;
  5242. /*
  5243. * Some virtual interfaces need to process EAPOL packets and events on
  5244. * the parent interface. This is used mainly with hostapd.
  5245. */
  5246. if (ifidx > 0 &&
  5247. (drv->hostapd ||
  5248. nlmode == NL80211_IFTYPE_AP_VLAN ||
  5249. nlmode == NL80211_IFTYPE_WDS ||
  5250. nlmode == NL80211_IFTYPE_MONITOR))
  5251. add_ifidx(drv, ifidx, IFIDX_ANY);
  5252. return 0;
  5253. }
  5254. static int wpa_driver_nl80211_if_remove(struct i802_bss *bss,
  5255. enum wpa_driver_if_type type,
  5256. const char *ifname)
  5257. {
  5258. struct wpa_driver_nl80211_data *drv = bss->drv;
  5259. int ifindex = if_nametoindex(ifname);
  5260. wpa_printf(MSG_DEBUG, "nl80211: %s(type=%d ifname=%s) ifindex=%d added_if=%d",
  5261. __func__, type, ifname, ifindex, bss->added_if);
  5262. if (ifindex > 0 && (bss->added_if || bss->ifindex != ifindex))
  5263. nl80211_remove_iface(drv, ifindex);
  5264. else if (ifindex > 0 && !bss->added_if) {
  5265. struct wpa_driver_nl80211_data *drv2;
  5266. dl_list_for_each(drv2, &drv->global->interfaces,
  5267. struct wpa_driver_nl80211_data, list) {
  5268. del_ifidx(drv2, ifindex, IFIDX_ANY);
  5269. del_ifidx(drv2, IFIDX_ANY, ifindex);
  5270. }
  5271. }
  5272. if (type != WPA_IF_AP_BSS)
  5273. return 0;
  5274. if (bss->added_if_into_bridge) {
  5275. if (linux_br_del_if(drv->global->ioctl_sock, bss->brname,
  5276. bss->ifname) < 0)
  5277. wpa_printf(MSG_INFO, "nl80211: Failed to remove "
  5278. "interface %s from bridge %s: %s",
  5279. bss->ifname, bss->brname, strerror(errno));
  5280. }
  5281. if (bss->added_bridge) {
  5282. if (linux_br_del(drv->global->ioctl_sock, bss->brname) < 0)
  5283. wpa_printf(MSG_INFO, "nl80211: Failed to remove "
  5284. "bridge %s: %s",
  5285. bss->brname, strerror(errno));
  5286. }
  5287. if (bss != drv->first_bss) {
  5288. struct i802_bss *tbss;
  5289. wpa_printf(MSG_DEBUG, "nl80211: Not the first BSS - remove it");
  5290. for (tbss = drv->first_bss; tbss; tbss = tbss->next) {
  5291. if (tbss->next == bss) {
  5292. tbss->next = bss->next;
  5293. /* Unsubscribe management frames */
  5294. nl80211_teardown_ap(bss);
  5295. nl80211_destroy_bss(bss);
  5296. if (!bss->added_if)
  5297. i802_set_iface_flags(bss, 0);
  5298. os_free(bss);
  5299. bss = NULL;
  5300. break;
  5301. }
  5302. }
  5303. if (bss)
  5304. wpa_printf(MSG_INFO, "nl80211: %s - could not find "
  5305. "BSS %p in the list", __func__, bss);
  5306. } else {
  5307. wpa_printf(MSG_DEBUG, "nl80211: First BSS - reassign context");
  5308. nl80211_teardown_ap(bss);
  5309. if (!bss->added_if && !drv->first_bss->next)
  5310. wpa_driver_nl80211_del_beacon(drv);
  5311. nl80211_destroy_bss(bss);
  5312. if (!bss->added_if)
  5313. i802_set_iface_flags(bss, 0);
  5314. if (drv->first_bss->next) {
  5315. drv->first_bss = drv->first_bss->next;
  5316. drv->ctx = drv->first_bss->ctx;
  5317. os_free(bss);
  5318. } else {
  5319. wpa_printf(MSG_DEBUG, "nl80211: No second BSS to reassign context to");
  5320. }
  5321. }
  5322. return 0;
  5323. }
  5324. static int cookie_handler(struct nl_msg *msg, void *arg)
  5325. {
  5326. struct nlattr *tb[NL80211_ATTR_MAX + 1];
  5327. struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
  5328. u64 *cookie = arg;
  5329. nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
  5330. genlmsg_attrlen(gnlh, 0), NULL);
  5331. if (tb[NL80211_ATTR_COOKIE])
  5332. *cookie = nla_get_u64(tb[NL80211_ATTR_COOKIE]);
  5333. return NL_SKIP;
  5334. }
  5335. static int nl80211_send_frame_cmd(struct i802_bss *bss,
  5336. unsigned int freq, unsigned int wait,
  5337. const u8 *buf, size_t buf_len,
  5338. u64 *cookie_out, int no_cck, int no_ack,
  5339. int offchanok, const u16 *csa_offs,
  5340. size_t csa_offs_len)
  5341. {
  5342. struct wpa_driver_nl80211_data *drv = bss->drv;
  5343. struct nl_msg *msg;
  5344. u64 cookie;
  5345. int ret = -1;
  5346. wpa_printf(MSG_MSGDUMP, "nl80211: CMD_FRAME freq=%u wait=%u no_cck=%d "
  5347. "no_ack=%d offchanok=%d",
  5348. freq, wait, no_cck, no_ack, offchanok);
  5349. wpa_hexdump(MSG_MSGDUMP, "CMD_FRAME", buf, buf_len);
  5350. if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_FRAME)) ||
  5351. (freq && nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq)) ||
  5352. (wait && nla_put_u32(msg, NL80211_ATTR_DURATION, wait)) ||
  5353. (offchanok && ((drv->capa.flags & WPA_DRIVER_FLAGS_OFFCHANNEL_TX) ||
  5354. drv->test_use_roc_tx) &&
  5355. nla_put_flag(msg, NL80211_ATTR_OFFCHANNEL_TX_OK)) ||
  5356. (no_cck && nla_put_flag(msg, NL80211_ATTR_TX_NO_CCK_RATE)) ||
  5357. (no_ack && nla_put_flag(msg, NL80211_ATTR_DONT_WAIT_FOR_ACK)) ||
  5358. (csa_offs && nla_put(msg, NL80211_ATTR_CSA_C_OFFSETS_TX,
  5359. csa_offs_len * sizeof(u16), csa_offs)) ||
  5360. nla_put(msg, NL80211_ATTR_FRAME, buf_len, buf))
  5361. goto fail;
  5362. cookie = 0;
  5363. ret = send_and_recv_msgs(drv, msg, cookie_handler, &cookie);
  5364. msg = NULL;
  5365. if (ret) {
  5366. wpa_printf(MSG_DEBUG, "nl80211: Frame command failed: ret=%d "
  5367. "(%s) (freq=%u wait=%u)", ret, strerror(-ret),
  5368. freq, wait);
  5369. } else {
  5370. wpa_printf(MSG_MSGDUMP, "nl80211: Frame TX command accepted%s; "
  5371. "cookie 0x%llx", no_ack ? " (no ACK)" : "",
  5372. (long long unsigned int) cookie);
  5373. if (cookie_out)
  5374. *cookie_out = no_ack ? (u64) -1 : cookie;
  5375. if (drv->num_send_action_cookies == MAX_SEND_ACTION_COOKIES) {
  5376. wpa_printf(MSG_DEBUG,
  5377. "nl80211: Drop oldest pending send action cookie 0x%llx",
  5378. (long long unsigned int)
  5379. drv->send_action_cookies[0]);
  5380. os_memmove(&drv->send_action_cookies[0],
  5381. &drv->send_action_cookies[1],
  5382. (MAX_SEND_ACTION_COOKIES - 1) *
  5383. sizeof(u64));
  5384. drv->num_send_action_cookies--;
  5385. }
  5386. drv->send_action_cookies[drv->num_send_action_cookies] = cookie;
  5387. drv->num_send_action_cookies++;
  5388. }
  5389. fail:
  5390. nlmsg_free(msg);
  5391. return ret;
  5392. }
  5393. static int wpa_driver_nl80211_send_action(struct i802_bss *bss,
  5394. unsigned int freq,
  5395. unsigned int wait_time,
  5396. const u8 *dst, const u8 *src,
  5397. const u8 *bssid,
  5398. const u8 *data, size_t data_len,
  5399. int no_cck)
  5400. {
  5401. struct wpa_driver_nl80211_data *drv = bss->drv;
  5402. int ret = -1;
  5403. u8 *buf;
  5404. struct ieee80211_hdr *hdr;
  5405. wpa_printf(MSG_DEBUG, "nl80211: Send Action frame (ifindex=%d, "
  5406. "freq=%u MHz wait=%d ms no_cck=%d)",
  5407. drv->ifindex, freq, wait_time, no_cck);
  5408. buf = os_zalloc(24 + data_len);
  5409. if (buf == NULL)
  5410. return ret;
  5411. os_memcpy(buf + 24, data, data_len);
  5412. hdr = (struct ieee80211_hdr *) buf;
  5413. hdr->frame_control =
  5414. IEEE80211_FC(WLAN_FC_TYPE_MGMT, WLAN_FC_STYPE_ACTION);
  5415. os_memcpy(hdr->addr1, dst, ETH_ALEN);
  5416. os_memcpy(hdr->addr2, src, ETH_ALEN);
  5417. os_memcpy(hdr->addr3, bssid, ETH_ALEN);
  5418. if (is_ap_interface(drv->nlmode) &&
  5419. (!(drv->capa.flags & WPA_DRIVER_FLAGS_OFFCHANNEL_TX) ||
  5420. (int) freq == bss->freq || drv->device_ap_sme ||
  5421. !drv->use_monitor))
  5422. ret = wpa_driver_nl80211_send_mlme(bss, buf, 24 + data_len,
  5423. 0, freq, no_cck, 1,
  5424. wait_time, NULL, 0);
  5425. else
  5426. ret = nl80211_send_frame_cmd(bss, freq, wait_time, buf,
  5427. 24 + data_len,
  5428. &drv->send_action_cookie,
  5429. no_cck, 0, 1, NULL, 0);
  5430. os_free(buf);
  5431. return ret;
  5432. }
  5433. static void nl80211_frame_wait_cancel(struct i802_bss *bss, u64 cookie)
  5434. {
  5435. struct wpa_driver_nl80211_data *drv = bss->drv;
  5436. struct nl_msg *msg;
  5437. int ret;
  5438. wpa_printf(MSG_DEBUG, "nl80211: Cancel TX frame wait: cookie=0x%llx",
  5439. (long long unsigned int) cookie);
  5440. if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_FRAME_WAIT_CANCEL)) ||
  5441. nla_put_u64(msg, NL80211_ATTR_COOKIE, cookie)) {
  5442. nlmsg_free(msg);
  5443. return;
  5444. }
  5445. ret = send_and_recv_msgs(drv, msg, NULL, NULL);
  5446. if (ret)
  5447. wpa_printf(MSG_DEBUG, "nl80211: wait cancel failed: ret=%d "
  5448. "(%s)", ret, strerror(-ret));
  5449. }
  5450. static void wpa_driver_nl80211_send_action_cancel_wait(void *priv)
  5451. {
  5452. struct i802_bss *bss = priv;
  5453. struct wpa_driver_nl80211_data *drv = bss->drv;
  5454. unsigned int i;
  5455. u64 cookie;
  5456. /* Cancel the last pending TX cookie */
  5457. nl80211_frame_wait_cancel(bss, drv->send_action_cookie);
  5458. /*
  5459. * Cancel the other pending TX cookies, if any. This is needed since
  5460. * the driver may keep a list of all pending offchannel TX operations
  5461. * and free up the radio only once they have expired or cancelled.
  5462. */
  5463. for (i = drv->num_send_action_cookies; i > 0; i--) {
  5464. cookie = drv->send_action_cookies[i - 1];
  5465. if (cookie != drv->send_action_cookie)
  5466. nl80211_frame_wait_cancel(bss, cookie);
  5467. }
  5468. drv->num_send_action_cookies = 0;
  5469. }
  5470. static int wpa_driver_nl80211_remain_on_channel(void *priv, unsigned int freq,
  5471. unsigned int duration)
  5472. {
  5473. struct i802_bss *bss = priv;
  5474. struct wpa_driver_nl80211_data *drv = bss->drv;
  5475. struct nl_msg *msg;
  5476. int ret;
  5477. u64 cookie;
  5478. if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_REMAIN_ON_CHANNEL)) ||
  5479. nla_put_u32(msg, NL80211_ATTR_WIPHY_FREQ, freq) ||
  5480. nla_put_u32(msg, NL80211_ATTR_DURATION, duration)) {
  5481. nlmsg_free(msg);
  5482. return -1;
  5483. }
  5484. cookie = 0;
  5485. ret = send_and_recv_msgs(drv, msg, cookie_handler, &cookie);
  5486. if (ret == 0) {
  5487. wpa_printf(MSG_DEBUG, "nl80211: Remain-on-channel cookie "
  5488. "0x%llx for freq=%u MHz duration=%u",
  5489. (long long unsigned int) cookie, freq, duration);
  5490. drv->remain_on_chan_cookie = cookie;
  5491. drv->pending_remain_on_chan = 1;
  5492. return 0;
  5493. }
  5494. wpa_printf(MSG_DEBUG, "nl80211: Failed to request remain-on-channel "
  5495. "(freq=%d duration=%u): %d (%s)",
  5496. freq, duration, ret, strerror(-ret));
  5497. return -1;
  5498. }
  5499. static int wpa_driver_nl80211_cancel_remain_on_channel(void *priv)
  5500. {
  5501. struct i802_bss *bss = priv;
  5502. struct wpa_driver_nl80211_data *drv = bss->drv;
  5503. struct nl_msg *msg;
  5504. int ret;
  5505. if (!drv->pending_remain_on_chan) {
  5506. wpa_printf(MSG_DEBUG, "nl80211: No pending remain-on-channel "
  5507. "to cancel");
  5508. return -1;
  5509. }
  5510. wpa_printf(MSG_DEBUG, "nl80211: Cancel remain-on-channel with cookie "
  5511. "0x%llx",
  5512. (long long unsigned int) drv->remain_on_chan_cookie);
  5513. msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_CANCEL_REMAIN_ON_CHANNEL);
  5514. if (!msg ||
  5515. nla_put_u64(msg, NL80211_ATTR_COOKIE, drv->remain_on_chan_cookie)) {
  5516. nlmsg_free(msg);
  5517. return -1;
  5518. }
  5519. ret = send_and_recv_msgs(drv, msg, NULL, NULL);
  5520. if (ret == 0)
  5521. return 0;
  5522. wpa_printf(MSG_DEBUG, "nl80211: Failed to cancel remain-on-channel: "
  5523. "%d (%s)", ret, strerror(-ret));
  5524. return -1;
  5525. }
  5526. static int wpa_driver_nl80211_probe_req_report(struct i802_bss *bss, int report)
  5527. {
  5528. struct wpa_driver_nl80211_data *drv = bss->drv;
  5529. if (!report) {
  5530. if (bss->nl_preq && drv->device_ap_sme &&
  5531. is_ap_interface(drv->nlmode) && !bss->in_deinit &&
  5532. !bss->static_ap) {
  5533. /*
  5534. * Do not disable Probe Request reporting that was
  5535. * enabled in nl80211_setup_ap().
  5536. */
  5537. wpa_printf(MSG_DEBUG, "nl80211: Skip disabling of "
  5538. "Probe Request reporting nl_preq=%p while "
  5539. "in AP mode", bss->nl_preq);
  5540. } else if (bss->nl_preq) {
  5541. wpa_printf(MSG_DEBUG, "nl80211: Disable Probe Request "
  5542. "reporting nl_preq=%p", bss->nl_preq);
  5543. nl80211_destroy_eloop_handle(&bss->nl_preq);
  5544. }
  5545. return 0;
  5546. }
  5547. if (bss->nl_preq) {
  5548. wpa_printf(MSG_DEBUG, "nl80211: Probe Request reporting "
  5549. "already on! nl_preq=%p", bss->nl_preq);
  5550. return 0;
  5551. }
  5552. bss->nl_preq = nl_create_handle(drv->global->nl_cb, "preq");
  5553. if (bss->nl_preq == NULL)
  5554. return -1;
  5555. wpa_printf(MSG_DEBUG, "nl80211: Enable Probe Request "
  5556. "reporting nl_preq=%p", bss->nl_preq);
  5557. if (nl80211_register_frame(bss, bss->nl_preq,
  5558. (WLAN_FC_TYPE_MGMT << 2) |
  5559. (WLAN_FC_STYPE_PROBE_REQ << 4),
  5560. NULL, 0) < 0)
  5561. goto out_err;
  5562. nl80211_register_eloop_read(&bss->nl_preq,
  5563. wpa_driver_nl80211_event_receive,
  5564. bss->nl_cb);
  5565. return 0;
  5566. out_err:
  5567. nl_destroy_handles(&bss->nl_preq);
  5568. return -1;
  5569. }
  5570. static int nl80211_disable_11b_rates(struct wpa_driver_nl80211_data *drv,
  5571. int ifindex, int disabled)
  5572. {
  5573. struct nl_msg *msg;
  5574. struct nlattr *bands, *band;
  5575. int ret;
  5576. wpa_printf(MSG_DEBUG,
  5577. "nl80211: NL80211_CMD_SET_TX_BITRATE_MASK (ifindex=%d %s)",
  5578. ifindex, disabled ? "NL80211_TXRATE_LEGACY=OFDM-only" :
  5579. "no NL80211_TXRATE_LEGACY constraint");
  5580. msg = nl80211_ifindex_msg(drv, ifindex, 0,
  5581. NL80211_CMD_SET_TX_BITRATE_MASK);
  5582. if (!msg)
  5583. return -1;
  5584. bands = nla_nest_start(msg, NL80211_ATTR_TX_RATES);
  5585. if (!bands)
  5586. goto fail;
  5587. /*
  5588. * Disable 2 GHz rates 1, 2, 5.5, 11 Mbps by masking out everything
  5589. * else apart from 6, 9, 12, 18, 24, 36, 48, 54 Mbps from non-MCS
  5590. * rates. All 5 GHz rates are left enabled.
  5591. */
  5592. band = nla_nest_start(msg, NL80211_BAND_2GHZ);
  5593. if (!band ||
  5594. (disabled && nla_put(msg, NL80211_TXRATE_LEGACY, 8,
  5595. "\x0c\x12\x18\x24\x30\x48\x60\x6c")))
  5596. goto fail;
  5597. nla_nest_end(msg, band);
  5598. nla_nest_end(msg, bands);
  5599. ret = send_and_recv_msgs(drv, msg, NULL, NULL);
  5600. if (ret) {
  5601. wpa_printf(MSG_DEBUG, "nl80211: Set TX rates failed: ret=%d "
  5602. "(%s)", ret, strerror(-ret));
  5603. } else
  5604. drv->disabled_11b_rates = disabled;
  5605. return ret;
  5606. fail:
  5607. nlmsg_free(msg);
  5608. return -1;
  5609. }
  5610. static int wpa_driver_nl80211_deinit_ap(void *priv)
  5611. {
  5612. struct i802_bss *bss = priv;
  5613. struct wpa_driver_nl80211_data *drv = bss->drv;
  5614. if (!is_ap_interface(drv->nlmode))
  5615. return -1;
  5616. wpa_driver_nl80211_del_beacon(drv);
  5617. bss->beacon_set = 0;
  5618. /*
  5619. * If the P2P GO interface was dynamically added, then it is
  5620. * possible that the interface change to station is not possible.
  5621. */
  5622. if (drv->nlmode == NL80211_IFTYPE_P2P_GO && bss->if_dynamic)
  5623. return 0;
  5624. return wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_STATION);
  5625. }
  5626. static int wpa_driver_nl80211_stop_ap(void *priv)
  5627. {
  5628. struct i802_bss *bss = priv;
  5629. struct wpa_driver_nl80211_data *drv = bss->drv;
  5630. if (!is_ap_interface(drv->nlmode))
  5631. return -1;
  5632. wpa_driver_nl80211_del_beacon(drv);
  5633. bss->beacon_set = 0;
  5634. return 0;
  5635. }
  5636. static int wpa_driver_nl80211_deinit_p2p_cli(void *priv)
  5637. {
  5638. struct i802_bss *bss = priv;
  5639. struct wpa_driver_nl80211_data *drv = bss->drv;
  5640. if (drv->nlmode != NL80211_IFTYPE_P2P_CLIENT)
  5641. return -1;
  5642. /*
  5643. * If the P2P Client interface was dynamically added, then it is
  5644. * possible that the interface change to station is not possible.
  5645. */
  5646. if (bss->if_dynamic)
  5647. return 0;
  5648. return wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_STATION);
  5649. }
  5650. static void wpa_driver_nl80211_resume(void *priv)
  5651. {
  5652. struct i802_bss *bss = priv;
  5653. enum nl80211_iftype nlmode = nl80211_get_ifmode(bss);
  5654. if (i802_set_iface_flags(bss, 1))
  5655. wpa_printf(MSG_DEBUG, "nl80211: Failed to set interface up on resume event");
  5656. if (is_p2p_net_interface(nlmode))
  5657. nl80211_disable_11b_rates(bss->drv, bss->drv->ifindex, 1);
  5658. }
  5659. static int nl80211_signal_monitor(void *priv, int threshold, int hysteresis)
  5660. {
  5661. struct i802_bss *bss = priv;
  5662. struct wpa_driver_nl80211_data *drv = bss->drv;
  5663. struct nl_msg *msg;
  5664. struct nlattr *cqm;
  5665. wpa_printf(MSG_DEBUG, "nl80211: Signal monitor threshold=%d "
  5666. "hysteresis=%d", threshold, hysteresis);
  5667. if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_CQM)) ||
  5668. !(cqm = nla_nest_start(msg, NL80211_ATTR_CQM)) ||
  5669. nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_THOLD, threshold) ||
  5670. nla_put_u32(msg, NL80211_ATTR_CQM_RSSI_HYST, hysteresis)) {
  5671. nlmsg_free(msg);
  5672. return -1;
  5673. }
  5674. nla_nest_end(msg, cqm);
  5675. return send_and_recv_msgs(drv, msg, NULL, NULL);
  5676. }
  5677. static int get_channel_width(struct nl_msg *msg, void *arg)
  5678. {
  5679. struct nlattr *tb[NL80211_ATTR_MAX + 1];
  5680. struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
  5681. struct wpa_signal_info *sig_change = arg;
  5682. nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
  5683. genlmsg_attrlen(gnlh, 0), NULL);
  5684. sig_change->center_frq1 = -1;
  5685. sig_change->center_frq2 = -1;
  5686. sig_change->chanwidth = CHAN_WIDTH_UNKNOWN;
  5687. if (tb[NL80211_ATTR_CHANNEL_WIDTH]) {
  5688. sig_change->chanwidth = convert2width(
  5689. nla_get_u32(tb[NL80211_ATTR_CHANNEL_WIDTH]));
  5690. if (tb[NL80211_ATTR_CENTER_FREQ1])
  5691. sig_change->center_frq1 =
  5692. nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ1]);
  5693. if (tb[NL80211_ATTR_CENTER_FREQ2])
  5694. sig_change->center_frq2 =
  5695. nla_get_u32(tb[NL80211_ATTR_CENTER_FREQ2]);
  5696. }
  5697. return NL_SKIP;
  5698. }
  5699. static int nl80211_get_channel_width(struct wpa_driver_nl80211_data *drv,
  5700. struct wpa_signal_info *sig)
  5701. {
  5702. struct nl_msg *msg;
  5703. msg = nl80211_drv_msg(drv, 0, NL80211_CMD_GET_INTERFACE);
  5704. return send_and_recv_msgs(drv, msg, get_channel_width, sig);
  5705. }
  5706. static int nl80211_signal_poll(void *priv, struct wpa_signal_info *si)
  5707. {
  5708. struct i802_bss *bss = priv;
  5709. struct wpa_driver_nl80211_data *drv = bss->drv;
  5710. int res;
  5711. os_memset(si, 0, sizeof(*si));
  5712. res = nl80211_get_link_signal(drv, si);
  5713. if (res) {
  5714. if (drv->nlmode != NL80211_IFTYPE_ADHOC &&
  5715. drv->nlmode != NL80211_IFTYPE_MESH_POINT)
  5716. return res;
  5717. si->current_signal = 0;
  5718. }
  5719. res = nl80211_get_channel_width(drv, si);
  5720. if (res != 0)
  5721. return res;
  5722. return nl80211_get_link_noise(drv, si);
  5723. }
  5724. static int nl80211_send_frame(void *priv, const u8 *data, size_t data_len,
  5725. int encrypt)
  5726. {
  5727. struct i802_bss *bss = priv;
  5728. return wpa_driver_nl80211_send_frame(bss, data, data_len, encrypt, 0,
  5729. 0, 0, 0, 0, NULL, 0);
  5730. }
  5731. static int nl80211_set_param(void *priv, const char *param)
  5732. {
  5733. if (param == NULL)
  5734. return 0;
  5735. wpa_printf(MSG_DEBUG, "nl80211: driver param='%s'", param);
  5736. #ifdef CONFIG_P2P
  5737. if (os_strstr(param, "use_p2p_group_interface=1")) {
  5738. struct i802_bss *bss = priv;
  5739. struct wpa_driver_nl80211_data *drv = bss->drv;
  5740. wpa_printf(MSG_DEBUG, "nl80211: Use separate P2P group "
  5741. "interface");
  5742. drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_CONCURRENT;
  5743. drv->capa.flags |= WPA_DRIVER_FLAGS_P2P_MGMT_AND_NON_P2P;
  5744. }
  5745. #endif /* CONFIG_P2P */
  5746. if (os_strstr(param, "use_monitor=1")) {
  5747. struct i802_bss *bss = priv;
  5748. struct wpa_driver_nl80211_data *drv = bss->drv;
  5749. drv->use_monitor = 1;
  5750. }
  5751. if (os_strstr(param, "force_connect_cmd=1")) {
  5752. struct i802_bss *bss = priv;
  5753. struct wpa_driver_nl80211_data *drv = bss->drv;
  5754. drv->capa.flags &= ~WPA_DRIVER_FLAGS_SME;
  5755. drv->force_connect_cmd = 1;
  5756. }
  5757. if (os_strstr(param, "no_offchannel_tx=1")) {
  5758. struct i802_bss *bss = priv;
  5759. struct wpa_driver_nl80211_data *drv = bss->drv;
  5760. drv->capa.flags &= ~WPA_DRIVER_FLAGS_OFFCHANNEL_TX;
  5761. drv->test_use_roc_tx = 1;
  5762. }
  5763. return 0;
  5764. }
  5765. static void * nl80211_global_init(void)
  5766. {
  5767. struct nl80211_global *global;
  5768. struct netlink_config *cfg;
  5769. global = os_zalloc(sizeof(*global));
  5770. if (global == NULL)
  5771. return NULL;
  5772. global->ioctl_sock = -1;
  5773. dl_list_init(&global->interfaces);
  5774. global->if_add_ifindex = -1;
  5775. cfg = os_zalloc(sizeof(*cfg));
  5776. if (cfg == NULL)
  5777. goto err;
  5778. cfg->ctx = global;
  5779. cfg->newlink_cb = wpa_driver_nl80211_event_rtm_newlink;
  5780. cfg->dellink_cb = wpa_driver_nl80211_event_rtm_dellink;
  5781. global->netlink = netlink_init(cfg);
  5782. if (global->netlink == NULL) {
  5783. os_free(cfg);
  5784. goto err;
  5785. }
  5786. if (wpa_driver_nl80211_init_nl_global(global) < 0)
  5787. goto err;
  5788. global->ioctl_sock = socket(PF_INET, SOCK_DGRAM, 0);
  5789. if (global->ioctl_sock < 0) {
  5790. wpa_printf(MSG_ERROR, "nl80211: socket(PF_INET,SOCK_DGRAM) failed: %s",
  5791. strerror(errno));
  5792. goto err;
  5793. }
  5794. return global;
  5795. err:
  5796. nl80211_global_deinit(global);
  5797. return NULL;
  5798. }
  5799. static void nl80211_global_deinit(void *priv)
  5800. {
  5801. struct nl80211_global *global = priv;
  5802. if (global == NULL)
  5803. return;
  5804. if (!dl_list_empty(&global->interfaces)) {
  5805. wpa_printf(MSG_ERROR, "nl80211: %u interface(s) remain at "
  5806. "nl80211_global_deinit",
  5807. dl_list_len(&global->interfaces));
  5808. }
  5809. if (global->netlink)
  5810. netlink_deinit(global->netlink);
  5811. nl_destroy_handles(&global->nl);
  5812. if (global->nl_event)
  5813. nl80211_destroy_eloop_handle(&global->nl_event);
  5814. nl_cb_put(global->nl_cb);
  5815. if (global->ioctl_sock >= 0)
  5816. close(global->ioctl_sock);
  5817. os_free(global);
  5818. }
  5819. static const char * nl80211_get_radio_name(void *priv)
  5820. {
  5821. struct i802_bss *bss = priv;
  5822. struct wpa_driver_nl80211_data *drv = bss->drv;
  5823. return drv->phyname;
  5824. }
  5825. static int nl80211_pmkid(struct i802_bss *bss, int cmd, const u8 *bssid,
  5826. const u8 *pmkid)
  5827. {
  5828. struct nl_msg *msg;
  5829. if (!(msg = nl80211_bss_msg(bss, 0, cmd)) ||
  5830. (pmkid && nla_put(msg, NL80211_ATTR_PMKID, 16, pmkid)) ||
  5831. (bssid && nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, bssid))) {
  5832. nlmsg_free(msg);
  5833. return -ENOBUFS;
  5834. }
  5835. return send_and_recv_msgs(bss->drv, msg, NULL, NULL);
  5836. }
  5837. static int nl80211_add_pmkid(void *priv, const u8 *bssid, const u8 *pmkid)
  5838. {
  5839. struct i802_bss *bss = priv;
  5840. wpa_printf(MSG_DEBUG, "nl80211: Add PMKID for " MACSTR, MAC2STR(bssid));
  5841. return nl80211_pmkid(bss, NL80211_CMD_SET_PMKSA, bssid, pmkid);
  5842. }
  5843. static int nl80211_remove_pmkid(void *priv, const u8 *bssid, const u8 *pmkid)
  5844. {
  5845. struct i802_bss *bss = priv;
  5846. wpa_printf(MSG_DEBUG, "nl80211: Delete PMKID for " MACSTR,
  5847. MAC2STR(bssid));
  5848. return nl80211_pmkid(bss, NL80211_CMD_DEL_PMKSA, bssid, pmkid);
  5849. }
  5850. static int nl80211_flush_pmkid(void *priv)
  5851. {
  5852. struct i802_bss *bss = priv;
  5853. wpa_printf(MSG_DEBUG, "nl80211: Flush PMKIDs");
  5854. return nl80211_pmkid(bss, NL80211_CMD_FLUSH_PMKSA, NULL, NULL);
  5855. }
  5856. static void clean_survey_results(struct survey_results *survey_results)
  5857. {
  5858. struct freq_survey *survey, *tmp;
  5859. if (dl_list_empty(&survey_results->survey_list))
  5860. return;
  5861. dl_list_for_each_safe(survey, tmp, &survey_results->survey_list,
  5862. struct freq_survey, list) {
  5863. dl_list_del(&survey->list);
  5864. os_free(survey);
  5865. }
  5866. }
  5867. static void add_survey(struct nlattr **sinfo, u32 ifidx,
  5868. struct dl_list *survey_list)
  5869. {
  5870. struct freq_survey *survey;
  5871. survey = os_zalloc(sizeof(struct freq_survey));
  5872. if (!survey)
  5873. return;
  5874. survey->ifidx = ifidx;
  5875. survey->freq = nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]);
  5876. survey->filled = 0;
  5877. if (sinfo[NL80211_SURVEY_INFO_NOISE]) {
  5878. survey->nf = (int8_t)
  5879. nla_get_u8(sinfo[NL80211_SURVEY_INFO_NOISE]);
  5880. survey->filled |= SURVEY_HAS_NF;
  5881. }
  5882. if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME]) {
  5883. survey->channel_time =
  5884. nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME]);
  5885. survey->filled |= SURVEY_HAS_CHAN_TIME;
  5886. }
  5887. if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY]) {
  5888. survey->channel_time_busy =
  5889. nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_BUSY]);
  5890. survey->filled |= SURVEY_HAS_CHAN_TIME_BUSY;
  5891. }
  5892. if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_RX]) {
  5893. survey->channel_time_rx =
  5894. nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_RX]);
  5895. survey->filled |= SURVEY_HAS_CHAN_TIME_RX;
  5896. }
  5897. if (sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_TX]) {
  5898. survey->channel_time_tx =
  5899. nla_get_u64(sinfo[NL80211_SURVEY_INFO_CHANNEL_TIME_TX]);
  5900. survey->filled |= SURVEY_HAS_CHAN_TIME_TX;
  5901. }
  5902. wpa_printf(MSG_DEBUG, "nl80211: Freq survey dump event (freq=%d MHz noise=%d channel_time=%ld busy_time=%ld tx_time=%ld rx_time=%ld filled=%04x)",
  5903. survey->freq,
  5904. survey->nf,
  5905. (unsigned long int) survey->channel_time,
  5906. (unsigned long int) survey->channel_time_busy,
  5907. (unsigned long int) survey->channel_time_tx,
  5908. (unsigned long int) survey->channel_time_rx,
  5909. survey->filled);
  5910. dl_list_add_tail(survey_list, &survey->list);
  5911. }
  5912. static int check_survey_ok(struct nlattr **sinfo, u32 surveyed_freq,
  5913. unsigned int freq_filter)
  5914. {
  5915. if (!freq_filter)
  5916. return 1;
  5917. return freq_filter == surveyed_freq;
  5918. }
  5919. static int survey_handler(struct nl_msg *msg, void *arg)
  5920. {
  5921. struct nlattr *tb[NL80211_ATTR_MAX + 1];
  5922. struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
  5923. struct nlattr *sinfo[NL80211_SURVEY_INFO_MAX + 1];
  5924. struct survey_results *survey_results;
  5925. u32 surveyed_freq = 0;
  5926. u32 ifidx;
  5927. static struct nla_policy survey_policy[NL80211_SURVEY_INFO_MAX + 1] = {
  5928. [NL80211_SURVEY_INFO_FREQUENCY] = { .type = NLA_U32 },
  5929. [NL80211_SURVEY_INFO_NOISE] = { .type = NLA_U8 },
  5930. };
  5931. survey_results = (struct survey_results *) arg;
  5932. nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
  5933. genlmsg_attrlen(gnlh, 0), NULL);
  5934. if (!tb[NL80211_ATTR_IFINDEX])
  5935. return NL_SKIP;
  5936. ifidx = nla_get_u32(tb[NL80211_ATTR_IFINDEX]);
  5937. if (!tb[NL80211_ATTR_SURVEY_INFO])
  5938. return NL_SKIP;
  5939. if (nla_parse_nested(sinfo, NL80211_SURVEY_INFO_MAX,
  5940. tb[NL80211_ATTR_SURVEY_INFO],
  5941. survey_policy))
  5942. return NL_SKIP;
  5943. if (!sinfo[NL80211_SURVEY_INFO_FREQUENCY]) {
  5944. wpa_printf(MSG_ERROR, "nl80211: Invalid survey data");
  5945. return NL_SKIP;
  5946. }
  5947. surveyed_freq = nla_get_u32(sinfo[NL80211_SURVEY_INFO_FREQUENCY]);
  5948. if (!check_survey_ok(sinfo, surveyed_freq,
  5949. survey_results->freq_filter))
  5950. return NL_SKIP;
  5951. if (survey_results->freq_filter &&
  5952. survey_results->freq_filter != surveyed_freq) {
  5953. wpa_printf(MSG_EXCESSIVE, "nl80211: Ignoring survey data for freq %d MHz",
  5954. surveyed_freq);
  5955. return NL_SKIP;
  5956. }
  5957. add_survey(sinfo, ifidx, &survey_results->survey_list);
  5958. return NL_SKIP;
  5959. }
  5960. static int wpa_driver_nl80211_get_survey(void *priv, unsigned int freq)
  5961. {
  5962. struct i802_bss *bss = priv;
  5963. struct wpa_driver_nl80211_data *drv = bss->drv;
  5964. struct nl_msg *msg;
  5965. int err;
  5966. union wpa_event_data data;
  5967. struct survey_results *survey_results;
  5968. os_memset(&data, 0, sizeof(data));
  5969. survey_results = &data.survey_results;
  5970. dl_list_init(&survey_results->survey_list);
  5971. msg = nl80211_drv_msg(drv, NLM_F_DUMP, NL80211_CMD_GET_SURVEY);
  5972. if (!msg)
  5973. return -ENOBUFS;
  5974. if (freq)
  5975. data.survey_results.freq_filter = freq;
  5976. do {
  5977. wpa_printf(MSG_DEBUG, "nl80211: Fetch survey data");
  5978. err = send_and_recv_msgs(drv, msg, survey_handler,
  5979. survey_results);
  5980. } while (err > 0);
  5981. if (err)
  5982. wpa_printf(MSG_ERROR, "nl80211: Failed to process survey data");
  5983. else
  5984. wpa_supplicant_event(drv->ctx, EVENT_SURVEY, &data);
  5985. clean_survey_results(survey_results);
  5986. return err;
  5987. }
  5988. static void nl80211_set_rekey_info(void *priv, const u8 *kek, size_t kek_len,
  5989. const u8 *kck, size_t kck_len,
  5990. const u8 *replay_ctr)
  5991. {
  5992. struct i802_bss *bss = priv;
  5993. struct wpa_driver_nl80211_data *drv = bss->drv;
  5994. struct nlattr *replay_nested;
  5995. struct nl_msg *msg;
  5996. int ret;
  5997. if (!drv->set_rekey_offload)
  5998. return;
  5999. wpa_printf(MSG_DEBUG, "nl80211: Set rekey offload");
  6000. if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_REKEY_OFFLOAD)) ||
  6001. !(replay_nested = nla_nest_start(msg, NL80211_ATTR_REKEY_DATA)) ||
  6002. nla_put(msg, NL80211_REKEY_DATA_KEK, kek_len, kek) ||
  6003. nla_put(msg, NL80211_REKEY_DATA_KCK, kck_len, kck) ||
  6004. nla_put(msg, NL80211_REKEY_DATA_REPLAY_CTR, NL80211_REPLAY_CTR_LEN,
  6005. replay_ctr)) {
  6006. nl80211_nlmsg_clear(msg);
  6007. nlmsg_free(msg);
  6008. return;
  6009. }
  6010. nla_nest_end(msg, replay_nested);
  6011. ret = send_and_recv_msgs(drv, msg, NULL, (void *) -1);
  6012. if (ret == -EOPNOTSUPP) {
  6013. wpa_printf(MSG_DEBUG,
  6014. "nl80211: Driver does not support rekey offload");
  6015. drv->set_rekey_offload = 0;
  6016. }
  6017. }
  6018. static void nl80211_send_null_frame(struct i802_bss *bss, const u8 *own_addr,
  6019. const u8 *addr, int qos)
  6020. {
  6021. /* send data frame to poll STA and check whether
  6022. * this frame is ACKed */
  6023. struct {
  6024. struct ieee80211_hdr hdr;
  6025. u16 qos_ctl;
  6026. } STRUCT_PACKED nulldata;
  6027. size_t size;
  6028. /* Send data frame to poll STA and check whether this frame is ACKed */
  6029. os_memset(&nulldata, 0, sizeof(nulldata));
  6030. if (qos) {
  6031. nulldata.hdr.frame_control =
  6032. IEEE80211_FC(WLAN_FC_TYPE_DATA,
  6033. WLAN_FC_STYPE_QOS_NULL);
  6034. size = sizeof(nulldata);
  6035. } else {
  6036. nulldata.hdr.frame_control =
  6037. IEEE80211_FC(WLAN_FC_TYPE_DATA,
  6038. WLAN_FC_STYPE_NULLFUNC);
  6039. size = sizeof(struct ieee80211_hdr);
  6040. }
  6041. nulldata.hdr.frame_control |= host_to_le16(WLAN_FC_FROMDS);
  6042. os_memcpy(nulldata.hdr.IEEE80211_DA_FROMDS, addr, ETH_ALEN);
  6043. os_memcpy(nulldata.hdr.IEEE80211_BSSID_FROMDS, own_addr, ETH_ALEN);
  6044. os_memcpy(nulldata.hdr.IEEE80211_SA_FROMDS, own_addr, ETH_ALEN);
  6045. if (wpa_driver_nl80211_send_mlme(bss, (u8 *) &nulldata, size, 0, 0, 0,
  6046. 0, 0, NULL, 0) < 0)
  6047. wpa_printf(MSG_DEBUG, "nl80211_send_null_frame: Failed to "
  6048. "send poll frame");
  6049. }
  6050. static void nl80211_poll_client(void *priv, const u8 *own_addr, const u8 *addr,
  6051. int qos)
  6052. {
  6053. struct i802_bss *bss = priv;
  6054. struct wpa_driver_nl80211_data *drv = bss->drv;
  6055. struct nl_msg *msg;
  6056. int ret;
  6057. if (!drv->poll_command_supported) {
  6058. nl80211_send_null_frame(bss, own_addr, addr, qos);
  6059. return;
  6060. }
  6061. if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_PROBE_CLIENT)) ||
  6062. nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) {
  6063. nlmsg_free(msg);
  6064. return;
  6065. }
  6066. ret = send_and_recv_msgs(drv, msg, NULL, NULL);
  6067. if (ret < 0) {
  6068. wpa_printf(MSG_DEBUG, "nl80211: Client probe request for "
  6069. MACSTR " failed: ret=%d (%s)",
  6070. MAC2STR(addr), ret, strerror(-ret));
  6071. }
  6072. }
  6073. static int nl80211_set_power_save(struct i802_bss *bss, int enabled)
  6074. {
  6075. struct nl_msg *msg;
  6076. if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_SET_POWER_SAVE)) ||
  6077. nla_put_u32(msg, NL80211_ATTR_PS_STATE,
  6078. enabled ? NL80211_PS_ENABLED : NL80211_PS_DISABLED)) {
  6079. nlmsg_free(msg);
  6080. return -ENOBUFS;
  6081. }
  6082. return send_and_recv_msgs(bss->drv, msg, NULL, NULL);
  6083. }
  6084. static int nl80211_set_p2p_powersave(void *priv, int legacy_ps, int opp_ps,
  6085. int ctwindow)
  6086. {
  6087. struct i802_bss *bss = priv;
  6088. wpa_printf(MSG_DEBUG, "nl80211: set_p2p_powersave (legacy_ps=%d "
  6089. "opp_ps=%d ctwindow=%d)", legacy_ps, opp_ps, ctwindow);
  6090. if (opp_ps != -1 || ctwindow != -1) {
  6091. #ifdef ANDROID_P2P
  6092. wpa_driver_set_p2p_ps(priv, legacy_ps, opp_ps, ctwindow);
  6093. #else /* ANDROID_P2P */
  6094. return -1; /* Not yet supported */
  6095. #endif /* ANDROID_P2P */
  6096. }
  6097. if (legacy_ps == -1)
  6098. return 0;
  6099. if (legacy_ps != 0 && legacy_ps != 1)
  6100. return -1; /* Not yet supported */
  6101. return nl80211_set_power_save(bss, legacy_ps);
  6102. }
  6103. static int nl80211_start_radar_detection(void *priv,
  6104. struct hostapd_freq_params *freq)
  6105. {
  6106. struct i802_bss *bss = priv;
  6107. struct wpa_driver_nl80211_data *drv = bss->drv;
  6108. struct nl_msg *msg;
  6109. int ret;
  6110. wpa_printf(MSG_DEBUG, "nl80211: Start radar detection (CAC) %d MHz (ht_enabled=%d, vht_enabled=%d, bandwidth=%d MHz, cf1=%d MHz, cf2=%d MHz)",
  6111. freq->freq, freq->ht_enabled, freq->vht_enabled,
  6112. freq->bandwidth, freq->center_freq1, freq->center_freq2);
  6113. if (!(drv->capa.flags & WPA_DRIVER_FLAGS_RADAR)) {
  6114. wpa_printf(MSG_DEBUG, "nl80211: Driver does not support radar "
  6115. "detection");
  6116. return -1;
  6117. }
  6118. if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_RADAR_DETECT)) ||
  6119. nl80211_put_freq_params(msg, freq) < 0) {
  6120. nlmsg_free(msg);
  6121. return -1;
  6122. }
  6123. ret = send_and_recv_msgs(drv, msg, NULL, NULL);
  6124. if (ret == 0)
  6125. return 0;
  6126. wpa_printf(MSG_DEBUG, "nl80211: Failed to start radar detection: "
  6127. "%d (%s)", ret, strerror(-ret));
  6128. return -1;
  6129. }
  6130. #ifdef CONFIG_TDLS
  6131. static int nl80211_send_tdls_mgmt(void *priv, const u8 *dst, u8 action_code,
  6132. u8 dialog_token, u16 status_code,
  6133. u32 peer_capab, int initiator, const u8 *buf,
  6134. size_t len)
  6135. {
  6136. struct i802_bss *bss = priv;
  6137. struct wpa_driver_nl80211_data *drv = bss->drv;
  6138. struct nl_msg *msg;
  6139. if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT))
  6140. return -EOPNOTSUPP;
  6141. if (!dst)
  6142. return -EINVAL;
  6143. if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_TDLS_MGMT)) ||
  6144. nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, dst) ||
  6145. nla_put_u8(msg, NL80211_ATTR_TDLS_ACTION, action_code) ||
  6146. nla_put_u8(msg, NL80211_ATTR_TDLS_DIALOG_TOKEN, dialog_token) ||
  6147. nla_put_u16(msg, NL80211_ATTR_STATUS_CODE, status_code))
  6148. goto fail;
  6149. if (peer_capab) {
  6150. /*
  6151. * The internal enum tdls_peer_capability definition is
  6152. * currently identical with the nl80211 enum
  6153. * nl80211_tdls_peer_capability, so no conversion is needed
  6154. * here.
  6155. */
  6156. if (nla_put_u32(msg, NL80211_ATTR_TDLS_PEER_CAPABILITY,
  6157. peer_capab))
  6158. goto fail;
  6159. }
  6160. if ((initiator &&
  6161. nla_put_flag(msg, NL80211_ATTR_TDLS_INITIATOR)) ||
  6162. nla_put(msg, NL80211_ATTR_IE, len, buf))
  6163. goto fail;
  6164. return send_and_recv_msgs(drv, msg, NULL, NULL);
  6165. fail:
  6166. nlmsg_free(msg);
  6167. return -ENOBUFS;
  6168. }
  6169. static int nl80211_tdls_oper(void *priv, enum tdls_oper oper, const u8 *peer)
  6170. {
  6171. struct i802_bss *bss = priv;
  6172. struct wpa_driver_nl80211_data *drv = bss->drv;
  6173. struct nl_msg *msg;
  6174. enum nl80211_tdls_operation nl80211_oper;
  6175. if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT))
  6176. return -EOPNOTSUPP;
  6177. switch (oper) {
  6178. case TDLS_DISCOVERY_REQ:
  6179. nl80211_oper = NL80211_TDLS_DISCOVERY_REQ;
  6180. break;
  6181. case TDLS_SETUP:
  6182. nl80211_oper = NL80211_TDLS_SETUP;
  6183. break;
  6184. case TDLS_TEARDOWN:
  6185. nl80211_oper = NL80211_TDLS_TEARDOWN;
  6186. break;
  6187. case TDLS_ENABLE_LINK:
  6188. nl80211_oper = NL80211_TDLS_ENABLE_LINK;
  6189. break;
  6190. case TDLS_DISABLE_LINK:
  6191. nl80211_oper = NL80211_TDLS_DISABLE_LINK;
  6192. break;
  6193. case TDLS_ENABLE:
  6194. return 0;
  6195. case TDLS_DISABLE:
  6196. return 0;
  6197. default:
  6198. return -EINVAL;
  6199. }
  6200. if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_TDLS_OPER)) ||
  6201. nla_put_u8(msg, NL80211_ATTR_TDLS_OPERATION, nl80211_oper) ||
  6202. nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, peer)) {
  6203. nlmsg_free(msg);
  6204. return -ENOBUFS;
  6205. }
  6206. return send_and_recv_msgs(drv, msg, NULL, NULL);
  6207. }
  6208. static int
  6209. nl80211_tdls_enable_channel_switch(void *priv, const u8 *addr, u8 oper_class,
  6210. const struct hostapd_freq_params *params)
  6211. {
  6212. struct i802_bss *bss = priv;
  6213. struct wpa_driver_nl80211_data *drv = bss->drv;
  6214. struct nl_msg *msg;
  6215. int ret = -ENOBUFS;
  6216. if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT) ||
  6217. !(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_CHANNEL_SWITCH))
  6218. return -EOPNOTSUPP;
  6219. wpa_printf(MSG_DEBUG, "nl80211: Enable TDLS channel switch " MACSTR
  6220. " oper_class=%u freq=%u",
  6221. MAC2STR(addr), oper_class, params->freq);
  6222. msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_TDLS_CHANNEL_SWITCH);
  6223. if (!msg ||
  6224. nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
  6225. nla_put_u8(msg, NL80211_ATTR_OPER_CLASS, oper_class) ||
  6226. (ret = nl80211_put_freq_params(msg, params))) {
  6227. nlmsg_free(msg);
  6228. wpa_printf(MSG_DEBUG, "nl80211: Could not build TDLS chan switch");
  6229. return ret;
  6230. }
  6231. return send_and_recv_msgs(drv, msg, NULL, NULL);
  6232. }
  6233. static int
  6234. nl80211_tdls_disable_channel_switch(void *priv, const u8 *addr)
  6235. {
  6236. struct i802_bss *bss = priv;
  6237. struct wpa_driver_nl80211_data *drv = bss->drv;
  6238. struct nl_msg *msg;
  6239. if (!(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT) ||
  6240. !(drv->capa.flags & WPA_DRIVER_FLAGS_TDLS_CHANNEL_SWITCH))
  6241. return -EOPNOTSUPP;
  6242. wpa_printf(MSG_DEBUG, "nl80211: Disable TDLS channel switch " MACSTR,
  6243. MAC2STR(addr));
  6244. msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_TDLS_CANCEL_CHANNEL_SWITCH);
  6245. if (!msg ||
  6246. nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) {
  6247. nlmsg_free(msg);
  6248. wpa_printf(MSG_DEBUG,
  6249. "nl80211: Could not build TDLS cancel chan switch");
  6250. return -ENOBUFS;
  6251. }
  6252. return send_and_recv_msgs(drv, msg, NULL, NULL);
  6253. }
  6254. #endif /* CONFIG TDLS */
  6255. static int driver_nl80211_set_key(const char *ifname, void *priv,
  6256. enum wpa_alg alg, const u8 *addr,
  6257. int key_idx, int set_tx,
  6258. const u8 *seq, size_t seq_len,
  6259. const u8 *key, size_t key_len)
  6260. {
  6261. struct i802_bss *bss = priv;
  6262. return wpa_driver_nl80211_set_key(ifname, bss, alg, addr, key_idx,
  6263. set_tx, seq, seq_len, key, key_len);
  6264. }
  6265. static int driver_nl80211_scan2(void *priv,
  6266. struct wpa_driver_scan_params *params)
  6267. {
  6268. struct i802_bss *bss = priv;
  6269. #ifdef CONFIG_DRIVER_NL80211_QCA
  6270. struct wpa_driver_nl80211_data *drv = bss->drv;
  6271. /*
  6272. * Do a vendor specific scan if possible. If only_new_results is
  6273. * set, do a normal scan since a kernel (cfg80211) BSS cache flush
  6274. * cannot be achieved through a vendor scan. The below condition may
  6275. * need to be modified if new scan flags are added in the future whose
  6276. * functionality can only be achieved through a normal scan.
  6277. */
  6278. if (drv->scan_vendor_cmd_avail && !params->only_new_results)
  6279. return wpa_driver_nl80211_vendor_scan(bss, params);
  6280. #endif /* CONFIG_DRIVER_NL80211_QCA */
  6281. return wpa_driver_nl80211_scan(bss, params);
  6282. }
  6283. static int driver_nl80211_deauthenticate(void *priv, const u8 *addr,
  6284. int reason_code)
  6285. {
  6286. struct i802_bss *bss = priv;
  6287. return wpa_driver_nl80211_deauthenticate(bss, addr, reason_code);
  6288. }
  6289. static int driver_nl80211_authenticate(void *priv,
  6290. struct wpa_driver_auth_params *params)
  6291. {
  6292. struct i802_bss *bss = priv;
  6293. return wpa_driver_nl80211_authenticate(bss, params);
  6294. }
  6295. static void driver_nl80211_deinit(void *priv)
  6296. {
  6297. struct i802_bss *bss = priv;
  6298. wpa_driver_nl80211_deinit(bss);
  6299. }
  6300. static int driver_nl80211_if_remove(void *priv, enum wpa_driver_if_type type,
  6301. const char *ifname)
  6302. {
  6303. struct i802_bss *bss = priv;
  6304. return wpa_driver_nl80211_if_remove(bss, type, ifname);
  6305. }
  6306. static int driver_nl80211_send_mlme(void *priv, const u8 *data,
  6307. size_t data_len, int noack,
  6308. unsigned int freq,
  6309. const u16 *csa_offs, size_t csa_offs_len)
  6310. {
  6311. struct i802_bss *bss = priv;
  6312. return wpa_driver_nl80211_send_mlme(bss, data, data_len, noack,
  6313. freq, 0, 0, 0, csa_offs,
  6314. csa_offs_len);
  6315. }
  6316. static int driver_nl80211_sta_remove(void *priv, const u8 *addr)
  6317. {
  6318. struct i802_bss *bss = priv;
  6319. return wpa_driver_nl80211_sta_remove(bss, addr, -1, 0);
  6320. }
  6321. static int driver_nl80211_set_sta_vlan(void *priv, const u8 *addr,
  6322. const char *ifname, int vlan_id)
  6323. {
  6324. struct i802_bss *bss = priv;
  6325. return i802_set_sta_vlan(bss, addr, ifname, vlan_id);
  6326. }
  6327. static int driver_nl80211_read_sta_data(void *priv,
  6328. struct hostap_sta_driver_data *data,
  6329. const u8 *addr)
  6330. {
  6331. struct i802_bss *bss = priv;
  6332. return i802_read_sta_data(bss, data, addr);
  6333. }
  6334. static int driver_nl80211_send_action(void *priv, unsigned int freq,
  6335. unsigned int wait_time,
  6336. const u8 *dst, const u8 *src,
  6337. const u8 *bssid,
  6338. const u8 *data, size_t data_len,
  6339. int no_cck)
  6340. {
  6341. struct i802_bss *bss = priv;
  6342. return wpa_driver_nl80211_send_action(bss, freq, wait_time, dst, src,
  6343. bssid, data, data_len, no_cck);
  6344. }
  6345. static int driver_nl80211_probe_req_report(void *priv, int report)
  6346. {
  6347. struct i802_bss *bss = priv;
  6348. return wpa_driver_nl80211_probe_req_report(bss, report);
  6349. }
  6350. static int wpa_driver_nl80211_update_ft_ies(void *priv, const u8 *md,
  6351. const u8 *ies, size_t ies_len)
  6352. {
  6353. int ret;
  6354. struct nl_msg *msg;
  6355. struct i802_bss *bss = priv;
  6356. struct wpa_driver_nl80211_data *drv = bss->drv;
  6357. u16 mdid = WPA_GET_LE16(md);
  6358. wpa_printf(MSG_DEBUG, "nl80211: Updating FT IEs");
  6359. if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_UPDATE_FT_IES)) ||
  6360. nla_put(msg, NL80211_ATTR_IE, ies_len, ies) ||
  6361. nla_put_u16(msg, NL80211_ATTR_MDID, mdid)) {
  6362. nlmsg_free(msg);
  6363. return -ENOBUFS;
  6364. }
  6365. ret = send_and_recv_msgs(drv, msg, NULL, NULL);
  6366. if (ret) {
  6367. wpa_printf(MSG_DEBUG, "nl80211: update_ft_ies failed "
  6368. "err=%d (%s)", ret, strerror(-ret));
  6369. }
  6370. return ret;
  6371. }
  6372. const u8 * wpa_driver_nl80211_get_macaddr(void *priv)
  6373. {
  6374. struct i802_bss *bss = priv;
  6375. struct wpa_driver_nl80211_data *drv = bss->drv;
  6376. if (drv->nlmode != NL80211_IFTYPE_P2P_DEVICE)
  6377. return NULL;
  6378. return bss->addr;
  6379. }
  6380. static const char * scan_state_str(enum scan_states scan_state)
  6381. {
  6382. switch (scan_state) {
  6383. case NO_SCAN:
  6384. return "NO_SCAN";
  6385. case SCAN_REQUESTED:
  6386. return "SCAN_REQUESTED";
  6387. case SCAN_STARTED:
  6388. return "SCAN_STARTED";
  6389. case SCAN_COMPLETED:
  6390. return "SCAN_COMPLETED";
  6391. case SCAN_ABORTED:
  6392. return "SCAN_ABORTED";
  6393. case SCHED_SCAN_STARTED:
  6394. return "SCHED_SCAN_STARTED";
  6395. case SCHED_SCAN_STOPPED:
  6396. return "SCHED_SCAN_STOPPED";
  6397. case SCHED_SCAN_RESULTS:
  6398. return "SCHED_SCAN_RESULTS";
  6399. }
  6400. return "??";
  6401. }
  6402. static int wpa_driver_nl80211_status(void *priv, char *buf, size_t buflen)
  6403. {
  6404. struct i802_bss *bss = priv;
  6405. struct wpa_driver_nl80211_data *drv = bss->drv;
  6406. int res;
  6407. char *pos, *end;
  6408. pos = buf;
  6409. end = buf + buflen;
  6410. res = os_snprintf(pos, end - pos,
  6411. "ifindex=%d\n"
  6412. "ifname=%s\n"
  6413. "brname=%s\n"
  6414. "addr=" MACSTR "\n"
  6415. "freq=%d\n"
  6416. "%s%s%s%s%s",
  6417. bss->ifindex,
  6418. bss->ifname,
  6419. bss->brname,
  6420. MAC2STR(bss->addr),
  6421. bss->freq,
  6422. bss->beacon_set ? "beacon_set=1\n" : "",
  6423. bss->added_if_into_bridge ?
  6424. "added_if_into_bridge=1\n" : "",
  6425. bss->added_bridge ? "added_bridge=1\n" : "",
  6426. bss->in_deinit ? "in_deinit=1\n" : "",
  6427. bss->if_dynamic ? "if_dynamic=1\n" : "");
  6428. if (os_snprintf_error(end - pos, res))
  6429. return pos - buf;
  6430. pos += res;
  6431. if (bss->wdev_id_set) {
  6432. res = os_snprintf(pos, end - pos, "wdev_id=%llu\n",
  6433. (unsigned long long) bss->wdev_id);
  6434. if (os_snprintf_error(end - pos, res))
  6435. return pos - buf;
  6436. pos += res;
  6437. }
  6438. res = os_snprintf(pos, end - pos,
  6439. "phyname=%s\n"
  6440. "perm_addr=" MACSTR "\n"
  6441. "drv_ifindex=%d\n"
  6442. "operstate=%d\n"
  6443. "scan_state=%s\n"
  6444. "auth_bssid=" MACSTR "\n"
  6445. "auth_attempt_bssid=" MACSTR "\n"
  6446. "bssid=" MACSTR "\n"
  6447. "prev_bssid=" MACSTR "\n"
  6448. "associated=%d\n"
  6449. "assoc_freq=%u\n"
  6450. "monitor_sock=%d\n"
  6451. "monitor_ifidx=%d\n"
  6452. "monitor_refcount=%d\n"
  6453. "last_mgmt_freq=%u\n"
  6454. "eapol_tx_sock=%d\n"
  6455. "%s%s%s%s%s%s%s%s%s%s%s%s%s",
  6456. drv->phyname,
  6457. MAC2STR(drv->perm_addr),
  6458. drv->ifindex,
  6459. drv->operstate,
  6460. scan_state_str(drv->scan_state),
  6461. MAC2STR(drv->auth_bssid),
  6462. MAC2STR(drv->auth_attempt_bssid),
  6463. MAC2STR(drv->bssid),
  6464. MAC2STR(drv->prev_bssid),
  6465. drv->associated,
  6466. drv->assoc_freq,
  6467. drv->monitor_sock,
  6468. drv->monitor_ifidx,
  6469. drv->monitor_refcount,
  6470. drv->last_mgmt_freq,
  6471. drv->eapol_tx_sock,
  6472. drv->ignore_if_down_event ?
  6473. "ignore_if_down_event=1\n" : "",
  6474. drv->scan_complete_events ?
  6475. "scan_complete_events=1\n" : "",
  6476. drv->disabled_11b_rates ?
  6477. "disabled_11b_rates=1\n" : "",
  6478. drv->pending_remain_on_chan ?
  6479. "pending_remain_on_chan=1\n" : "",
  6480. drv->in_interface_list ? "in_interface_list=1\n" : "",
  6481. drv->device_ap_sme ? "device_ap_sme=1\n" : "",
  6482. drv->poll_command_supported ?
  6483. "poll_command_supported=1\n" : "",
  6484. drv->data_tx_status ? "data_tx_status=1\n" : "",
  6485. drv->scan_for_auth ? "scan_for_auth=1\n" : "",
  6486. drv->retry_auth ? "retry_auth=1\n" : "",
  6487. drv->use_monitor ? "use_monitor=1\n" : "",
  6488. drv->ignore_next_local_disconnect ?
  6489. "ignore_next_local_disconnect=1\n" : "",
  6490. drv->ignore_next_local_deauth ?
  6491. "ignore_next_local_deauth=1\n" : "");
  6492. if (os_snprintf_error(end - pos, res))
  6493. return pos - buf;
  6494. pos += res;
  6495. if (drv->has_capability) {
  6496. res = os_snprintf(pos, end - pos,
  6497. "capa.key_mgmt=0x%x\n"
  6498. "capa.enc=0x%x\n"
  6499. "capa.auth=0x%x\n"
  6500. "capa.flags=0x%llx\n"
  6501. "capa.rrm_flags=0x%x\n"
  6502. "capa.max_scan_ssids=%d\n"
  6503. "capa.max_sched_scan_ssids=%d\n"
  6504. "capa.sched_scan_supported=%d\n"
  6505. "capa.max_match_sets=%d\n"
  6506. "capa.max_remain_on_chan=%u\n"
  6507. "capa.max_stations=%u\n"
  6508. "capa.probe_resp_offloads=0x%x\n"
  6509. "capa.max_acl_mac_addrs=%u\n"
  6510. "capa.num_multichan_concurrent=%u\n"
  6511. "capa.mac_addr_rand_sched_scan_supported=%d\n"
  6512. "capa.mac_addr_rand_scan_supported=%d\n"
  6513. "capa.conc_capab=%u\n"
  6514. "capa.max_conc_chan_2_4=%u\n"
  6515. "capa.max_conc_chan_5_0=%u\n"
  6516. "capa.max_sched_scan_plans=%u\n"
  6517. "capa.max_sched_scan_plan_interval=%u\n"
  6518. "capa.max_sched_scan_plan_iterations=%u\n",
  6519. drv->capa.key_mgmt,
  6520. drv->capa.enc,
  6521. drv->capa.auth,
  6522. (unsigned long long) drv->capa.flags,
  6523. drv->capa.rrm_flags,
  6524. drv->capa.max_scan_ssids,
  6525. drv->capa.max_sched_scan_ssids,
  6526. drv->capa.sched_scan_supported,
  6527. drv->capa.max_match_sets,
  6528. drv->capa.max_remain_on_chan,
  6529. drv->capa.max_stations,
  6530. drv->capa.probe_resp_offloads,
  6531. drv->capa.max_acl_mac_addrs,
  6532. drv->capa.num_multichan_concurrent,
  6533. drv->capa.mac_addr_rand_sched_scan_supported,
  6534. drv->capa.mac_addr_rand_scan_supported,
  6535. drv->capa.conc_capab,
  6536. drv->capa.max_conc_chan_2_4,
  6537. drv->capa.max_conc_chan_5_0,
  6538. drv->capa.max_sched_scan_plans,
  6539. drv->capa.max_sched_scan_plan_interval,
  6540. drv->capa.max_sched_scan_plan_iterations);
  6541. if (os_snprintf_error(end - pos, res))
  6542. return pos - buf;
  6543. pos += res;
  6544. }
  6545. return pos - buf;
  6546. }
  6547. static int set_beacon_data(struct nl_msg *msg, struct beacon_data *settings)
  6548. {
  6549. if ((settings->head &&
  6550. nla_put(msg, NL80211_ATTR_BEACON_HEAD,
  6551. settings->head_len, settings->head)) ||
  6552. (settings->tail &&
  6553. nla_put(msg, NL80211_ATTR_BEACON_TAIL,
  6554. settings->tail_len, settings->tail)) ||
  6555. (settings->beacon_ies &&
  6556. nla_put(msg, NL80211_ATTR_IE,
  6557. settings->beacon_ies_len, settings->beacon_ies)) ||
  6558. (settings->proberesp_ies &&
  6559. nla_put(msg, NL80211_ATTR_IE_PROBE_RESP,
  6560. settings->proberesp_ies_len, settings->proberesp_ies)) ||
  6561. (settings->assocresp_ies &&
  6562. nla_put(msg, NL80211_ATTR_IE_ASSOC_RESP,
  6563. settings->assocresp_ies_len, settings->assocresp_ies)) ||
  6564. (settings->probe_resp &&
  6565. nla_put(msg, NL80211_ATTR_PROBE_RESP,
  6566. settings->probe_resp_len, settings->probe_resp)))
  6567. return -ENOBUFS;
  6568. return 0;
  6569. }
  6570. static int nl80211_switch_channel(void *priv, struct csa_settings *settings)
  6571. {
  6572. struct nl_msg *msg;
  6573. struct i802_bss *bss = priv;
  6574. struct wpa_driver_nl80211_data *drv = bss->drv;
  6575. struct nlattr *beacon_csa;
  6576. int ret = -ENOBUFS;
  6577. int csa_off_len = 0;
  6578. int i;
  6579. wpa_printf(MSG_DEBUG, "nl80211: Channel switch request (cs_count=%u block_tx=%u freq=%d width=%d cf1=%d cf2=%d)",
  6580. settings->cs_count, settings->block_tx,
  6581. settings->freq_params.freq, settings->freq_params.bandwidth,
  6582. settings->freq_params.center_freq1,
  6583. settings->freq_params.center_freq2);
  6584. if (!(drv->capa.flags & WPA_DRIVER_FLAGS_AP_CSA)) {
  6585. wpa_printf(MSG_DEBUG, "nl80211: Driver does not support channel switch command");
  6586. return -EOPNOTSUPP;
  6587. }
  6588. if ((drv->nlmode != NL80211_IFTYPE_AP) &&
  6589. (drv->nlmode != NL80211_IFTYPE_P2P_GO))
  6590. return -EOPNOTSUPP;
  6591. /*
  6592. * Remove empty counters, assuming Probe Response and Beacon frame
  6593. * counters match. This implementation assumes that there are only two
  6594. * counters.
  6595. */
  6596. if (settings->counter_offset_beacon[0] &&
  6597. !settings->counter_offset_beacon[1]) {
  6598. csa_off_len = 1;
  6599. } else if (settings->counter_offset_beacon[1] &&
  6600. !settings->counter_offset_beacon[0]) {
  6601. csa_off_len = 1;
  6602. settings->counter_offset_beacon[0] =
  6603. settings->counter_offset_beacon[1];
  6604. settings->counter_offset_presp[0] =
  6605. settings->counter_offset_presp[1];
  6606. } else if (settings->counter_offset_beacon[1] &&
  6607. settings->counter_offset_beacon[0]) {
  6608. csa_off_len = 2;
  6609. } else {
  6610. wpa_printf(MSG_ERROR, "nl80211: No CSA counters provided");
  6611. return -EINVAL;
  6612. }
  6613. /* Check CSA counters validity */
  6614. if (drv->capa.max_csa_counters &&
  6615. csa_off_len > drv->capa.max_csa_counters) {
  6616. wpa_printf(MSG_ERROR,
  6617. "nl80211: Too many CSA counters provided");
  6618. return -EINVAL;
  6619. }
  6620. if (!settings->beacon_csa.tail)
  6621. return -EINVAL;
  6622. for (i = 0; i < csa_off_len; i++) {
  6623. u16 csa_c_off_bcn = settings->counter_offset_beacon[i];
  6624. u16 csa_c_off_presp = settings->counter_offset_presp[i];
  6625. if ((settings->beacon_csa.tail_len <= csa_c_off_bcn) ||
  6626. (settings->beacon_csa.tail[csa_c_off_bcn] !=
  6627. settings->cs_count))
  6628. return -EINVAL;
  6629. if (settings->beacon_csa.probe_resp &&
  6630. ((settings->beacon_csa.probe_resp_len <=
  6631. csa_c_off_presp) ||
  6632. (settings->beacon_csa.probe_resp[csa_c_off_presp] !=
  6633. settings->cs_count)))
  6634. return -EINVAL;
  6635. }
  6636. if (!(msg = nl80211_bss_msg(bss, 0, NL80211_CMD_CHANNEL_SWITCH)) ||
  6637. nla_put_u32(msg, NL80211_ATTR_CH_SWITCH_COUNT,
  6638. settings->cs_count) ||
  6639. (ret = nl80211_put_freq_params(msg, &settings->freq_params)) ||
  6640. (settings->block_tx &&
  6641. nla_put_flag(msg, NL80211_ATTR_CH_SWITCH_BLOCK_TX)))
  6642. goto error;
  6643. /* beacon_after params */
  6644. ret = set_beacon_data(msg, &settings->beacon_after);
  6645. if (ret)
  6646. goto error;
  6647. /* beacon_csa params */
  6648. beacon_csa = nla_nest_start(msg, NL80211_ATTR_CSA_IES);
  6649. if (!beacon_csa)
  6650. goto fail;
  6651. ret = set_beacon_data(msg, &settings->beacon_csa);
  6652. if (ret)
  6653. goto error;
  6654. if (nla_put(msg, NL80211_ATTR_CSA_C_OFF_BEACON,
  6655. csa_off_len * sizeof(u16),
  6656. settings->counter_offset_beacon) ||
  6657. (settings->beacon_csa.probe_resp &&
  6658. nla_put(msg, NL80211_ATTR_CSA_C_OFF_PRESP,
  6659. csa_off_len * sizeof(u16),
  6660. settings->counter_offset_presp)))
  6661. goto fail;
  6662. nla_nest_end(msg, beacon_csa);
  6663. ret = send_and_recv_msgs(drv, msg, NULL, NULL);
  6664. if (ret) {
  6665. wpa_printf(MSG_DEBUG, "nl80211: switch_channel failed err=%d (%s)",
  6666. ret, strerror(-ret));
  6667. }
  6668. return ret;
  6669. fail:
  6670. ret = -ENOBUFS;
  6671. error:
  6672. nlmsg_free(msg);
  6673. wpa_printf(MSG_DEBUG, "nl80211: Could not build channel switch request");
  6674. return ret;
  6675. }
  6676. static int nl80211_add_ts(void *priv, u8 tsid, const u8 *addr,
  6677. u8 user_priority, u16 admitted_time)
  6678. {
  6679. struct i802_bss *bss = priv;
  6680. struct wpa_driver_nl80211_data *drv = bss->drv;
  6681. struct nl_msg *msg;
  6682. int ret;
  6683. wpa_printf(MSG_DEBUG,
  6684. "nl80211: add_ts request: tsid=%u admitted_time=%u up=%d",
  6685. tsid, admitted_time, user_priority);
  6686. if (!is_sta_interface(drv->nlmode))
  6687. return -ENOTSUP;
  6688. msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_ADD_TX_TS);
  6689. if (!msg ||
  6690. nla_put_u8(msg, NL80211_ATTR_TSID, tsid) ||
  6691. nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr) ||
  6692. nla_put_u8(msg, NL80211_ATTR_USER_PRIO, user_priority) ||
  6693. nla_put_u16(msg, NL80211_ATTR_ADMITTED_TIME, admitted_time)) {
  6694. nlmsg_free(msg);
  6695. return -ENOBUFS;
  6696. }
  6697. ret = send_and_recv_msgs(drv, msg, NULL, NULL);
  6698. if (ret)
  6699. wpa_printf(MSG_DEBUG, "nl80211: add_ts failed err=%d (%s)",
  6700. ret, strerror(-ret));
  6701. return ret;
  6702. }
  6703. static int nl80211_del_ts(void *priv, u8 tsid, const u8 *addr)
  6704. {
  6705. struct i802_bss *bss = priv;
  6706. struct wpa_driver_nl80211_data *drv = bss->drv;
  6707. struct nl_msg *msg;
  6708. int ret;
  6709. wpa_printf(MSG_DEBUG, "nl80211: del_ts request: tsid=%u", tsid);
  6710. if (!is_sta_interface(drv->nlmode))
  6711. return -ENOTSUP;
  6712. if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_DEL_TX_TS)) ||
  6713. nla_put_u8(msg, NL80211_ATTR_TSID, tsid) ||
  6714. nla_put(msg, NL80211_ATTR_MAC, ETH_ALEN, addr)) {
  6715. nlmsg_free(msg);
  6716. return -ENOBUFS;
  6717. }
  6718. ret = send_and_recv_msgs(drv, msg, NULL, NULL);
  6719. if (ret)
  6720. wpa_printf(MSG_DEBUG, "nl80211: del_ts failed err=%d (%s)",
  6721. ret, strerror(-ret));
  6722. return ret;
  6723. }
  6724. #ifdef CONFIG_TESTING_OPTIONS
  6725. static int cmd_reply_handler(struct nl_msg *msg, void *arg)
  6726. {
  6727. struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
  6728. struct wpabuf *buf = arg;
  6729. if (!buf)
  6730. return NL_SKIP;
  6731. if ((size_t) genlmsg_attrlen(gnlh, 0) > wpabuf_tailroom(buf)) {
  6732. wpa_printf(MSG_INFO, "nl80211: insufficient buffer space for reply");
  6733. return NL_SKIP;
  6734. }
  6735. wpabuf_put_data(buf, genlmsg_attrdata(gnlh, 0),
  6736. genlmsg_attrlen(gnlh, 0));
  6737. return NL_SKIP;
  6738. }
  6739. #endif /* CONFIG_TESTING_OPTIONS */
  6740. static int vendor_reply_handler(struct nl_msg *msg, void *arg)
  6741. {
  6742. struct nlattr *tb[NL80211_ATTR_MAX + 1];
  6743. struct nlattr *nl_vendor_reply, *nl;
  6744. struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
  6745. struct wpabuf *buf = arg;
  6746. int rem;
  6747. if (!buf)
  6748. return NL_SKIP;
  6749. nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
  6750. genlmsg_attrlen(gnlh, 0), NULL);
  6751. nl_vendor_reply = tb[NL80211_ATTR_VENDOR_DATA];
  6752. if (!nl_vendor_reply)
  6753. return NL_SKIP;
  6754. if ((size_t) nla_len(nl_vendor_reply) > wpabuf_tailroom(buf)) {
  6755. wpa_printf(MSG_INFO, "nl80211: Vendor command: insufficient buffer space for reply");
  6756. return NL_SKIP;
  6757. }
  6758. nla_for_each_nested(nl, nl_vendor_reply, rem) {
  6759. wpabuf_put_data(buf, nla_data(nl), nla_len(nl));
  6760. }
  6761. return NL_SKIP;
  6762. }
  6763. static int nl80211_vendor_cmd(void *priv, unsigned int vendor_id,
  6764. unsigned int subcmd, const u8 *data,
  6765. size_t data_len, struct wpabuf *buf)
  6766. {
  6767. struct i802_bss *bss = priv;
  6768. struct wpa_driver_nl80211_data *drv = bss->drv;
  6769. struct nl_msg *msg;
  6770. int ret;
  6771. #ifdef CONFIG_TESTING_OPTIONS
  6772. if (vendor_id == 0xffffffff) {
  6773. msg = nlmsg_alloc();
  6774. if (!msg)
  6775. return -ENOMEM;
  6776. nl80211_cmd(drv, msg, 0, subcmd);
  6777. if (nlmsg_append(msg, (void *) data, data_len, NLMSG_ALIGNTO) <
  6778. 0)
  6779. goto fail;
  6780. ret = send_and_recv_msgs(drv, msg, cmd_reply_handler, buf);
  6781. if (ret)
  6782. wpa_printf(MSG_DEBUG, "nl80211: command failed err=%d",
  6783. ret);
  6784. return ret;
  6785. }
  6786. #endif /* CONFIG_TESTING_OPTIONS */
  6787. if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_VENDOR)) ||
  6788. nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, vendor_id) ||
  6789. nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD, subcmd) ||
  6790. (data &&
  6791. nla_put(msg, NL80211_ATTR_VENDOR_DATA, data_len, data)))
  6792. goto fail;
  6793. ret = send_and_recv_msgs(drv, msg, vendor_reply_handler, buf);
  6794. if (ret)
  6795. wpa_printf(MSG_DEBUG, "nl80211: vendor command failed err=%d",
  6796. ret);
  6797. return ret;
  6798. fail:
  6799. nlmsg_free(msg);
  6800. return -ENOBUFS;
  6801. }
  6802. static int nl80211_set_qos_map(void *priv, const u8 *qos_map_set,
  6803. u8 qos_map_set_len)
  6804. {
  6805. struct i802_bss *bss = priv;
  6806. struct wpa_driver_nl80211_data *drv = bss->drv;
  6807. struct nl_msg *msg;
  6808. int ret;
  6809. wpa_hexdump(MSG_DEBUG, "nl80211: Setting QoS Map",
  6810. qos_map_set, qos_map_set_len);
  6811. if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_QOS_MAP)) ||
  6812. nla_put(msg, NL80211_ATTR_QOS_MAP, qos_map_set_len, qos_map_set)) {
  6813. nlmsg_free(msg);
  6814. return -ENOBUFS;
  6815. }
  6816. ret = send_and_recv_msgs(drv, msg, NULL, NULL);
  6817. if (ret)
  6818. wpa_printf(MSG_DEBUG, "nl80211: Setting QoS Map failed");
  6819. return ret;
  6820. }
  6821. static int nl80211_set_wowlan(void *priv,
  6822. const struct wowlan_triggers *triggers)
  6823. {
  6824. struct i802_bss *bss = priv;
  6825. struct wpa_driver_nl80211_data *drv = bss->drv;
  6826. struct nl_msg *msg;
  6827. struct nlattr *wowlan_triggers;
  6828. int ret;
  6829. wpa_printf(MSG_DEBUG, "nl80211: Setting wowlan");
  6830. if (!(msg = nl80211_cmd_msg(bss, 0, NL80211_CMD_SET_WOWLAN)) ||
  6831. !(wowlan_triggers = nla_nest_start(msg,
  6832. NL80211_ATTR_WOWLAN_TRIGGERS)) ||
  6833. (triggers->any &&
  6834. nla_put_flag(msg, NL80211_WOWLAN_TRIG_ANY)) ||
  6835. (triggers->disconnect &&
  6836. nla_put_flag(msg, NL80211_WOWLAN_TRIG_DISCONNECT)) ||
  6837. (triggers->magic_pkt &&
  6838. nla_put_flag(msg, NL80211_WOWLAN_TRIG_MAGIC_PKT)) ||
  6839. (triggers->gtk_rekey_failure &&
  6840. nla_put_flag(msg, NL80211_WOWLAN_TRIG_GTK_REKEY_FAILURE)) ||
  6841. (triggers->eap_identity_req &&
  6842. nla_put_flag(msg, NL80211_WOWLAN_TRIG_EAP_IDENT_REQUEST)) ||
  6843. (triggers->four_way_handshake &&
  6844. nla_put_flag(msg, NL80211_WOWLAN_TRIG_4WAY_HANDSHAKE)) ||
  6845. (triggers->rfkill_release &&
  6846. nla_put_flag(msg, NL80211_WOWLAN_TRIG_RFKILL_RELEASE))) {
  6847. nlmsg_free(msg);
  6848. return -ENOBUFS;
  6849. }
  6850. nla_nest_end(msg, wowlan_triggers);
  6851. ret = send_and_recv_msgs(drv, msg, NULL, NULL);
  6852. if (ret)
  6853. wpa_printf(MSG_DEBUG, "nl80211: Setting wowlan failed");
  6854. return ret;
  6855. }
  6856. #ifdef CONFIG_DRIVER_NL80211_QCA
  6857. static int nl80211_roaming(void *priv, int allowed, const u8 *bssid)
  6858. {
  6859. struct i802_bss *bss = priv;
  6860. struct wpa_driver_nl80211_data *drv = bss->drv;
  6861. struct nl_msg *msg;
  6862. struct nlattr *params;
  6863. wpa_printf(MSG_DEBUG, "nl80211: Roaming policy: allowed=%d", allowed);
  6864. if (!drv->roaming_vendor_cmd_avail) {
  6865. wpa_printf(MSG_DEBUG,
  6866. "nl80211: Ignore roaming policy change since driver does not provide command for setting it");
  6867. return -1;
  6868. }
  6869. if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
  6870. nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
  6871. nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
  6872. QCA_NL80211_VENDOR_SUBCMD_ROAMING) ||
  6873. !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
  6874. nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_ROAMING_POLICY,
  6875. allowed ? QCA_ROAMING_ALLOWED_WITHIN_ESS :
  6876. QCA_ROAMING_NOT_ALLOWED) ||
  6877. (bssid &&
  6878. nla_put(msg, QCA_WLAN_VENDOR_ATTR_MAC_ADDR, ETH_ALEN, bssid))) {
  6879. nlmsg_free(msg);
  6880. return -1;
  6881. }
  6882. nla_nest_end(msg, params);
  6883. return send_and_recv_msgs(drv, msg, NULL, NULL);
  6884. }
  6885. #endif /* CONFIG_DRIVER_NL80211_QCA */
  6886. static int nl80211_set_mac_addr(void *priv, const u8 *addr)
  6887. {
  6888. struct i802_bss *bss = priv;
  6889. struct wpa_driver_nl80211_data *drv = bss->drv;
  6890. int new_addr = addr != NULL;
  6891. if (!addr)
  6892. addr = drv->perm_addr;
  6893. if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 0) < 0)
  6894. return -1;
  6895. if (linux_set_ifhwaddr(drv->global->ioctl_sock, bss->ifname, addr) < 0)
  6896. {
  6897. wpa_printf(MSG_DEBUG,
  6898. "nl80211: failed to set_mac_addr for %s to " MACSTR,
  6899. bss->ifname, MAC2STR(addr));
  6900. if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname,
  6901. 1) < 0) {
  6902. wpa_printf(MSG_DEBUG,
  6903. "nl80211: Could not restore interface UP after failed set_mac_addr");
  6904. }
  6905. return -1;
  6906. }
  6907. wpa_printf(MSG_DEBUG, "nl80211: set_mac_addr for %s to " MACSTR,
  6908. bss->ifname, MAC2STR(addr));
  6909. drv->addr_changed = new_addr;
  6910. os_memcpy(bss->addr, addr, ETH_ALEN);
  6911. if (linux_set_iface_flags(drv->global->ioctl_sock, bss->ifname, 1) < 0)
  6912. {
  6913. wpa_printf(MSG_DEBUG,
  6914. "nl80211: Could not restore interface UP after set_mac_addr");
  6915. }
  6916. return 0;
  6917. }
  6918. #ifdef CONFIG_MESH
  6919. static int wpa_driver_nl80211_init_mesh(void *priv)
  6920. {
  6921. if (wpa_driver_nl80211_set_mode(priv, NL80211_IFTYPE_MESH_POINT)) {
  6922. wpa_printf(MSG_INFO,
  6923. "nl80211: Failed to set interface into mesh mode");
  6924. return -1;
  6925. }
  6926. return 0;
  6927. }
  6928. static int nl80211_put_mesh_id(struct nl_msg *msg, const u8 *mesh_id,
  6929. size_t mesh_id_len)
  6930. {
  6931. if (mesh_id) {
  6932. wpa_hexdump_ascii(MSG_DEBUG, " * Mesh ID (SSID)",
  6933. mesh_id, mesh_id_len);
  6934. return nla_put(msg, NL80211_ATTR_MESH_ID, mesh_id_len, mesh_id);
  6935. }
  6936. return 0;
  6937. }
  6938. static int nl80211_join_mesh(struct i802_bss *bss,
  6939. struct wpa_driver_mesh_join_params *params)
  6940. {
  6941. struct wpa_driver_nl80211_data *drv = bss->drv;
  6942. struct nl_msg *msg;
  6943. struct nlattr *container;
  6944. int ret = -1;
  6945. wpa_printf(MSG_DEBUG, "nl80211: mesh join (ifindex=%d)", drv->ifindex);
  6946. msg = nl80211_drv_msg(drv, 0, NL80211_CMD_JOIN_MESH);
  6947. if (!msg ||
  6948. nl80211_put_freq_params(msg, &params->freq) ||
  6949. nl80211_put_basic_rates(msg, params->basic_rates) ||
  6950. nl80211_put_mesh_id(msg, params->meshid, params->meshid_len) ||
  6951. nl80211_put_beacon_int(msg, params->beacon_int))
  6952. goto fail;
  6953. wpa_printf(MSG_DEBUG, " * flags=%08X", params->flags);
  6954. container = nla_nest_start(msg, NL80211_ATTR_MESH_SETUP);
  6955. if (!container)
  6956. goto fail;
  6957. if (params->ies) {
  6958. wpa_hexdump(MSG_DEBUG, " * IEs", params->ies, params->ie_len);
  6959. if (nla_put(msg, NL80211_MESH_SETUP_IE, params->ie_len,
  6960. params->ies))
  6961. goto fail;
  6962. }
  6963. /* WPA_DRIVER_MESH_FLAG_OPEN_AUTH is treated as default by nl80211 */
  6964. if (params->flags & WPA_DRIVER_MESH_FLAG_SAE_AUTH) {
  6965. if (nla_put_u8(msg, NL80211_MESH_SETUP_AUTH_PROTOCOL, 0x1) ||
  6966. nla_put_flag(msg, NL80211_MESH_SETUP_USERSPACE_AUTH))
  6967. goto fail;
  6968. }
  6969. if ((params->flags & WPA_DRIVER_MESH_FLAG_AMPE) &&
  6970. nla_put_flag(msg, NL80211_MESH_SETUP_USERSPACE_AMPE))
  6971. goto fail;
  6972. if ((params->flags & WPA_DRIVER_MESH_FLAG_USER_MPM) &&
  6973. nla_put_flag(msg, NL80211_MESH_SETUP_USERSPACE_MPM))
  6974. goto fail;
  6975. nla_nest_end(msg, container);
  6976. container = nla_nest_start(msg, NL80211_ATTR_MESH_CONFIG);
  6977. if (!container)
  6978. goto fail;
  6979. if (!(params->conf.flags & WPA_DRIVER_MESH_CONF_FLAG_AUTO_PLINKS) &&
  6980. nla_put_u32(msg, NL80211_MESHCONF_AUTO_OPEN_PLINKS, 0))
  6981. goto fail;
  6982. if ((params->conf.flags & WPA_DRIVER_MESH_FLAG_DRIVER_MPM) &&
  6983. nla_put_u16(msg, NL80211_MESHCONF_MAX_PEER_LINKS,
  6984. params->max_peer_links))
  6985. goto fail;
  6986. /*
  6987. * Set NL80211_MESHCONF_PLINK_TIMEOUT even if user mpm is used because
  6988. * the timer could disconnect stations even in that case.
  6989. */
  6990. if (nla_put_u32(msg, NL80211_MESHCONF_PLINK_TIMEOUT,
  6991. params->conf.peer_link_timeout)) {
  6992. wpa_printf(MSG_ERROR, "nl80211: Failed to set PLINK_TIMEOUT");
  6993. goto fail;
  6994. }
  6995. nla_nest_end(msg, container);
  6996. ret = send_and_recv_msgs(drv, msg, NULL, NULL);
  6997. msg = NULL;
  6998. if (ret) {
  6999. wpa_printf(MSG_DEBUG, "nl80211: mesh join failed: ret=%d (%s)",
  7000. ret, strerror(-ret));
  7001. goto fail;
  7002. }
  7003. ret = 0;
  7004. bss->freq = params->freq.freq;
  7005. wpa_printf(MSG_DEBUG, "nl80211: mesh join request send successfully");
  7006. fail:
  7007. nlmsg_free(msg);
  7008. return ret;
  7009. }
  7010. static int
  7011. wpa_driver_nl80211_join_mesh(void *priv,
  7012. struct wpa_driver_mesh_join_params *params)
  7013. {
  7014. struct i802_bss *bss = priv;
  7015. int ret, timeout;
  7016. timeout = params->conf.peer_link_timeout;
  7017. /* Disable kernel inactivity timer */
  7018. if (params->flags & WPA_DRIVER_MESH_FLAG_USER_MPM)
  7019. params->conf.peer_link_timeout = 0;
  7020. ret = nl80211_join_mesh(bss, params);
  7021. if (ret == -EINVAL && params->conf.peer_link_timeout == 0) {
  7022. wpa_printf(MSG_DEBUG,
  7023. "nl80211: Mesh join retry for peer_link_timeout");
  7024. /*
  7025. * Old kernel does not support setting
  7026. * NL80211_MESHCONF_PLINK_TIMEOUT to zero, so set 60 seconds
  7027. * into future from peer_link_timeout.
  7028. */
  7029. params->conf.peer_link_timeout = timeout + 60;
  7030. ret = nl80211_join_mesh(priv, params);
  7031. }
  7032. params->conf.peer_link_timeout = timeout;
  7033. return ret;
  7034. }
  7035. static int wpa_driver_nl80211_leave_mesh(void *priv)
  7036. {
  7037. struct i802_bss *bss = priv;
  7038. struct wpa_driver_nl80211_data *drv = bss->drv;
  7039. struct nl_msg *msg;
  7040. int ret;
  7041. wpa_printf(MSG_DEBUG, "nl80211: mesh leave (ifindex=%d)", drv->ifindex);
  7042. msg = nl80211_drv_msg(drv, 0, NL80211_CMD_LEAVE_MESH);
  7043. ret = send_and_recv_msgs(drv, msg, NULL, NULL);
  7044. if (ret) {
  7045. wpa_printf(MSG_DEBUG, "nl80211: mesh leave failed: ret=%d (%s)",
  7046. ret, strerror(-ret));
  7047. } else {
  7048. wpa_printf(MSG_DEBUG,
  7049. "nl80211: mesh leave request send successfully");
  7050. }
  7051. if (wpa_driver_nl80211_set_mode(drv->first_bss,
  7052. NL80211_IFTYPE_STATION)) {
  7053. wpa_printf(MSG_INFO,
  7054. "nl80211: Failed to set interface into station mode");
  7055. }
  7056. return ret;
  7057. }
  7058. #endif /* CONFIG_MESH */
  7059. static int wpa_driver_br_add_ip_neigh(void *priv, u8 version,
  7060. const u8 *ipaddr, int prefixlen,
  7061. const u8 *addr)
  7062. {
  7063. #ifdef CONFIG_LIBNL3_ROUTE
  7064. struct i802_bss *bss = priv;
  7065. struct wpa_driver_nl80211_data *drv = bss->drv;
  7066. struct rtnl_neigh *rn;
  7067. struct nl_addr *nl_ipaddr = NULL;
  7068. struct nl_addr *nl_lladdr = NULL;
  7069. int family, addrsize;
  7070. int res;
  7071. if (!ipaddr || prefixlen == 0 || !addr)
  7072. return -EINVAL;
  7073. if (bss->br_ifindex == 0) {
  7074. wpa_printf(MSG_DEBUG,
  7075. "nl80211: bridge must be set before adding an ip neigh to it");
  7076. return -1;
  7077. }
  7078. if (!drv->rtnl_sk) {
  7079. wpa_printf(MSG_DEBUG,
  7080. "nl80211: nl_sock for NETLINK_ROUTE is not initialized");
  7081. return -1;
  7082. }
  7083. if (version == 4) {
  7084. family = AF_INET;
  7085. addrsize = 4;
  7086. } else if (version == 6) {
  7087. family = AF_INET6;
  7088. addrsize = 16;
  7089. } else {
  7090. return -EINVAL;
  7091. }
  7092. rn = rtnl_neigh_alloc();
  7093. if (rn == NULL)
  7094. return -ENOMEM;
  7095. /* set the destination ip address for neigh */
  7096. nl_ipaddr = nl_addr_build(family, (void *) ipaddr, addrsize);
  7097. if (nl_ipaddr == NULL) {
  7098. wpa_printf(MSG_DEBUG, "nl80211: nl_ipaddr build failed");
  7099. res = -ENOMEM;
  7100. goto errout;
  7101. }
  7102. nl_addr_set_prefixlen(nl_ipaddr, prefixlen);
  7103. res = rtnl_neigh_set_dst(rn, nl_ipaddr);
  7104. if (res) {
  7105. wpa_printf(MSG_DEBUG,
  7106. "nl80211: neigh set destination addr failed");
  7107. goto errout;
  7108. }
  7109. /* set the corresponding lladdr for neigh */
  7110. nl_lladdr = nl_addr_build(AF_BRIDGE, (u8 *) addr, ETH_ALEN);
  7111. if (nl_lladdr == NULL) {
  7112. wpa_printf(MSG_DEBUG, "nl80211: neigh set lladdr failed");
  7113. res = -ENOMEM;
  7114. goto errout;
  7115. }
  7116. rtnl_neigh_set_lladdr(rn, nl_lladdr);
  7117. rtnl_neigh_set_ifindex(rn, bss->br_ifindex);
  7118. rtnl_neigh_set_state(rn, NUD_PERMANENT);
  7119. res = rtnl_neigh_add(drv->rtnl_sk, rn, NLM_F_CREATE);
  7120. if (res) {
  7121. wpa_printf(MSG_DEBUG,
  7122. "nl80211: Adding bridge ip neigh failed: %s",
  7123. strerror(errno));
  7124. }
  7125. errout:
  7126. if (nl_lladdr)
  7127. nl_addr_put(nl_lladdr);
  7128. if (nl_ipaddr)
  7129. nl_addr_put(nl_ipaddr);
  7130. if (rn)
  7131. rtnl_neigh_put(rn);
  7132. return res;
  7133. #else /* CONFIG_LIBNL3_ROUTE */
  7134. return -1;
  7135. #endif /* CONFIG_LIBNL3_ROUTE */
  7136. }
  7137. static int wpa_driver_br_delete_ip_neigh(void *priv, u8 version,
  7138. const u8 *ipaddr)
  7139. {
  7140. #ifdef CONFIG_LIBNL3_ROUTE
  7141. struct i802_bss *bss = priv;
  7142. struct wpa_driver_nl80211_data *drv = bss->drv;
  7143. struct rtnl_neigh *rn;
  7144. struct nl_addr *nl_ipaddr;
  7145. int family, addrsize;
  7146. int res;
  7147. if (!ipaddr)
  7148. return -EINVAL;
  7149. if (version == 4) {
  7150. family = AF_INET;
  7151. addrsize = 4;
  7152. } else if (version == 6) {
  7153. family = AF_INET6;
  7154. addrsize = 16;
  7155. } else {
  7156. return -EINVAL;
  7157. }
  7158. if (bss->br_ifindex == 0) {
  7159. wpa_printf(MSG_DEBUG,
  7160. "nl80211: bridge must be set to delete an ip neigh");
  7161. return -1;
  7162. }
  7163. if (!drv->rtnl_sk) {
  7164. wpa_printf(MSG_DEBUG,
  7165. "nl80211: nl_sock for NETLINK_ROUTE is not initialized");
  7166. return -1;
  7167. }
  7168. rn = rtnl_neigh_alloc();
  7169. if (rn == NULL)
  7170. return -ENOMEM;
  7171. /* set the destination ip address for neigh */
  7172. nl_ipaddr = nl_addr_build(family, (void *) ipaddr, addrsize);
  7173. if (nl_ipaddr == NULL) {
  7174. wpa_printf(MSG_DEBUG, "nl80211: nl_ipaddr build failed");
  7175. res = -ENOMEM;
  7176. goto errout;
  7177. }
  7178. res = rtnl_neigh_set_dst(rn, nl_ipaddr);
  7179. if (res) {
  7180. wpa_printf(MSG_DEBUG,
  7181. "nl80211: neigh set destination addr failed");
  7182. goto errout;
  7183. }
  7184. rtnl_neigh_set_ifindex(rn, bss->br_ifindex);
  7185. res = rtnl_neigh_delete(drv->rtnl_sk, rn, 0);
  7186. if (res) {
  7187. wpa_printf(MSG_DEBUG,
  7188. "nl80211: Deleting bridge ip neigh failed: %s",
  7189. strerror(errno));
  7190. }
  7191. errout:
  7192. if (nl_ipaddr)
  7193. nl_addr_put(nl_ipaddr);
  7194. if (rn)
  7195. rtnl_neigh_put(rn);
  7196. return res;
  7197. #else /* CONFIG_LIBNL3_ROUTE */
  7198. return -1;
  7199. #endif /* CONFIG_LIBNL3_ROUTE */
  7200. }
  7201. static int linux_write_system_file(const char *path, unsigned int val)
  7202. {
  7203. char buf[50];
  7204. int fd, len;
  7205. len = os_snprintf(buf, sizeof(buf), "%u\n", val);
  7206. if (os_snprintf_error(sizeof(buf), len))
  7207. return -1;
  7208. fd = open(path, O_WRONLY);
  7209. if (fd < 0)
  7210. return -1;
  7211. if (write(fd, buf, len) < 0) {
  7212. wpa_printf(MSG_DEBUG,
  7213. "nl80211: Failed to write Linux system file: %s with the value of %d",
  7214. path, val);
  7215. close(fd);
  7216. return -1;
  7217. }
  7218. close(fd);
  7219. return 0;
  7220. }
  7221. static const char * drv_br_port_attr_str(enum drv_br_port_attr attr)
  7222. {
  7223. switch (attr) {
  7224. case DRV_BR_PORT_ATTR_PROXYARP:
  7225. return "proxyarp_wifi";
  7226. case DRV_BR_PORT_ATTR_HAIRPIN_MODE:
  7227. return "hairpin_mode";
  7228. }
  7229. return NULL;
  7230. }
  7231. static int wpa_driver_br_port_set_attr(void *priv, enum drv_br_port_attr attr,
  7232. unsigned int val)
  7233. {
  7234. struct i802_bss *bss = priv;
  7235. char path[128];
  7236. const char *attr_txt;
  7237. attr_txt = drv_br_port_attr_str(attr);
  7238. if (attr_txt == NULL)
  7239. return -EINVAL;
  7240. os_snprintf(path, sizeof(path), "/sys/class/net/%s/brport/%s",
  7241. bss->ifname, attr_txt);
  7242. if (linux_write_system_file(path, val))
  7243. return -1;
  7244. return 0;
  7245. }
  7246. static const char * drv_br_net_param_str(enum drv_br_net_param param)
  7247. {
  7248. switch (param) {
  7249. case DRV_BR_NET_PARAM_GARP_ACCEPT:
  7250. return "arp_accept";
  7251. default:
  7252. return NULL;
  7253. }
  7254. }
  7255. static int wpa_driver_br_set_net_param(void *priv, enum drv_br_net_param param,
  7256. unsigned int val)
  7257. {
  7258. struct i802_bss *bss = priv;
  7259. char path[128];
  7260. const char *param_txt;
  7261. int ip_version = 4;
  7262. if (param == DRV_BR_MULTICAST_SNOOPING) {
  7263. os_snprintf(path, sizeof(path),
  7264. "/sys/devices/virtual/net/%s/bridge/multicast_snooping",
  7265. bss->brname);
  7266. goto set_val;
  7267. }
  7268. param_txt = drv_br_net_param_str(param);
  7269. if (param_txt == NULL)
  7270. return -EINVAL;
  7271. switch (param) {
  7272. case DRV_BR_NET_PARAM_GARP_ACCEPT:
  7273. ip_version = 4;
  7274. break;
  7275. default:
  7276. return -EINVAL;
  7277. }
  7278. os_snprintf(path, sizeof(path), "/proc/sys/net/ipv%d/conf/%s/%s",
  7279. ip_version, bss->brname, param_txt);
  7280. set_val:
  7281. if (linux_write_system_file(path, val))
  7282. return -1;
  7283. return 0;
  7284. }
  7285. #ifdef CONFIG_DRIVER_NL80211_QCA
  7286. static int hw_mode_to_qca_acs(enum hostapd_hw_mode hw_mode)
  7287. {
  7288. switch (hw_mode) {
  7289. case HOSTAPD_MODE_IEEE80211B:
  7290. return QCA_ACS_MODE_IEEE80211B;
  7291. case HOSTAPD_MODE_IEEE80211G:
  7292. return QCA_ACS_MODE_IEEE80211G;
  7293. case HOSTAPD_MODE_IEEE80211A:
  7294. return QCA_ACS_MODE_IEEE80211A;
  7295. case HOSTAPD_MODE_IEEE80211AD:
  7296. return QCA_ACS_MODE_IEEE80211AD;
  7297. case HOSTAPD_MODE_IEEE80211ANY:
  7298. return QCA_ACS_MODE_IEEE80211ANY;
  7299. default:
  7300. return -1;
  7301. }
  7302. }
  7303. static int add_acs_freq_list(struct nl_msg *msg, const int *freq_list)
  7304. {
  7305. int i, len, ret;
  7306. u32 *freqs;
  7307. if (!freq_list)
  7308. return 0;
  7309. len = int_array_len(freq_list);
  7310. freqs = os_malloc(sizeof(u32) * len);
  7311. if (!freqs)
  7312. return -1;
  7313. for (i = 0; i < len; i++)
  7314. freqs[i] = freq_list[i];
  7315. ret = nla_put(msg, QCA_WLAN_VENDOR_ATTR_ACS_FREQ_LIST,
  7316. sizeof(u32) * len, freqs);
  7317. os_free(freqs);
  7318. return ret;
  7319. }
  7320. static int wpa_driver_do_acs(void *priv, struct drv_acs_params *params)
  7321. {
  7322. struct i802_bss *bss = priv;
  7323. struct wpa_driver_nl80211_data *drv = bss->drv;
  7324. struct nl_msg *msg;
  7325. struct nlattr *data;
  7326. int ret;
  7327. int mode;
  7328. mode = hw_mode_to_qca_acs(params->hw_mode);
  7329. if (mode < 0)
  7330. return -1;
  7331. if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
  7332. nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
  7333. nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
  7334. QCA_NL80211_VENDOR_SUBCMD_DO_ACS) ||
  7335. !(data = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
  7336. nla_put_u8(msg, QCA_WLAN_VENDOR_ATTR_ACS_HW_MODE, mode) ||
  7337. (params->ht_enabled &&
  7338. nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_HT_ENABLED)) ||
  7339. (params->ht40_enabled &&
  7340. nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_HT40_ENABLED)) ||
  7341. (params->vht_enabled &&
  7342. nla_put_flag(msg, QCA_WLAN_VENDOR_ATTR_ACS_VHT_ENABLED)) ||
  7343. nla_put_u16(msg, QCA_WLAN_VENDOR_ATTR_ACS_CHWIDTH,
  7344. params->ch_width) ||
  7345. (params->ch_list_len &&
  7346. nla_put(msg, QCA_WLAN_VENDOR_ATTR_ACS_CH_LIST, params->ch_list_len,
  7347. params->ch_list)) ||
  7348. add_acs_freq_list(msg, params->freq_list)) {
  7349. nlmsg_free(msg);
  7350. return -ENOBUFS;
  7351. }
  7352. nla_nest_end(msg, data);
  7353. wpa_printf(MSG_DEBUG,
  7354. "nl80211: ACS Params: HW_MODE: %d HT: %d HT40: %d VHT: %d BW: %d CH_LIST_LEN: %u",
  7355. params->hw_mode, params->ht_enabled, params->ht40_enabled,
  7356. params->vht_enabled, params->ch_width, params->ch_list_len);
  7357. ret = send_and_recv_msgs(drv, msg, NULL, NULL);
  7358. if (ret) {
  7359. wpa_printf(MSG_DEBUG,
  7360. "nl80211: Failed to invoke driver ACS function: %s",
  7361. strerror(errno));
  7362. }
  7363. return ret;
  7364. }
  7365. static int nl80211_set_band(void *priv, enum set_band band)
  7366. {
  7367. struct i802_bss *bss = priv;
  7368. struct wpa_driver_nl80211_data *drv = bss->drv;
  7369. struct nl_msg *msg;
  7370. struct nlattr *data;
  7371. int ret;
  7372. enum qca_set_band qca_band;
  7373. if (!drv->setband_vendor_cmd_avail)
  7374. return -1;
  7375. switch (band) {
  7376. case WPA_SETBAND_AUTO:
  7377. qca_band = QCA_SETBAND_AUTO;
  7378. break;
  7379. case WPA_SETBAND_5G:
  7380. qca_band = QCA_SETBAND_5G;
  7381. break;
  7382. case WPA_SETBAND_2G:
  7383. qca_band = QCA_SETBAND_2G;
  7384. break;
  7385. default:
  7386. return -1;
  7387. }
  7388. if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
  7389. nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
  7390. nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
  7391. QCA_NL80211_VENDOR_SUBCMD_SETBAND) ||
  7392. !(data = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
  7393. nla_put_u32(msg, QCA_WLAN_VENDOR_ATTR_SETBAND_VALUE, qca_band)) {
  7394. nlmsg_free(msg);
  7395. return -ENOBUFS;
  7396. }
  7397. nla_nest_end(msg, data);
  7398. ret = send_and_recv_msgs(drv, msg, NULL, NULL);
  7399. if (ret) {
  7400. wpa_printf(MSG_DEBUG,
  7401. "nl80211: Driver setband function failed: %s",
  7402. strerror(errno));
  7403. }
  7404. return ret;
  7405. }
  7406. struct nl80211_pcl {
  7407. unsigned int num;
  7408. unsigned int *freq_list;
  7409. };
  7410. static int preferred_freq_info_handler(struct nl_msg *msg, void *arg)
  7411. {
  7412. struct nlattr *tb[NL80211_ATTR_MAX + 1];
  7413. struct genlmsghdr *gnlh = nlmsg_data(nlmsg_hdr(msg));
  7414. struct nl80211_pcl *param = arg;
  7415. struct nlattr *nl_vend, *attr;
  7416. enum qca_iface_type iface_type;
  7417. struct nlattr *tb_vendor[QCA_WLAN_VENDOR_ATTR_MAX + 1];
  7418. unsigned int num, max_num;
  7419. u32 *freqs;
  7420. nla_parse(tb, NL80211_ATTR_MAX, genlmsg_attrdata(gnlh, 0),
  7421. genlmsg_attrlen(gnlh, 0), NULL);
  7422. nl_vend = tb[NL80211_ATTR_VENDOR_DATA];
  7423. if (!nl_vend)
  7424. return NL_SKIP;
  7425. nla_parse(tb_vendor, QCA_WLAN_VENDOR_ATTR_MAX,
  7426. nla_data(nl_vend), nla_len(nl_vend), NULL);
  7427. attr = tb_vendor[
  7428. QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST_IFACE_TYPE];
  7429. if (!attr) {
  7430. wpa_printf(MSG_ERROR, "nl80211: iface_type couldn't be found");
  7431. param->num = 0;
  7432. return NL_SKIP;
  7433. }
  7434. iface_type = (enum qca_iface_type) nla_get_u32(attr);
  7435. wpa_printf(MSG_DEBUG, "nl80211: Driver returned iface_type=%d",
  7436. iface_type);
  7437. attr = tb_vendor[QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST];
  7438. if (!attr) {
  7439. wpa_printf(MSG_ERROR,
  7440. "nl80211: preferred_freq_list couldn't be found");
  7441. param->num = 0;
  7442. return NL_SKIP;
  7443. }
  7444. /*
  7445. * param->num has the maximum number of entries for which there
  7446. * is room in the freq_list provided by the caller.
  7447. */
  7448. freqs = nla_data(attr);
  7449. max_num = nla_len(attr) / sizeof(u32);
  7450. if (max_num > param->num)
  7451. max_num = param->num;
  7452. for (num = 0; num < max_num; num++)
  7453. param->freq_list[num] = freqs[num];
  7454. param->num = num;
  7455. return NL_SKIP;
  7456. }
  7457. static int nl80211_get_pref_freq_list(void *priv,
  7458. enum wpa_driver_if_type if_type,
  7459. unsigned int *num,
  7460. unsigned int *freq_list)
  7461. {
  7462. struct i802_bss *bss = priv;
  7463. struct wpa_driver_nl80211_data *drv = bss->drv;
  7464. struct nl_msg *msg;
  7465. int ret;
  7466. unsigned int i;
  7467. struct nlattr *params;
  7468. struct nl80211_pcl param;
  7469. enum qca_iface_type iface_type;
  7470. if (!drv->get_pref_freq_list)
  7471. return -1;
  7472. switch (if_type) {
  7473. case WPA_IF_STATION:
  7474. iface_type = QCA_IFACE_TYPE_STA;
  7475. break;
  7476. case WPA_IF_AP_BSS:
  7477. iface_type = QCA_IFACE_TYPE_AP;
  7478. break;
  7479. case WPA_IF_P2P_GO:
  7480. iface_type = QCA_IFACE_TYPE_P2P_GO;
  7481. break;
  7482. case WPA_IF_P2P_CLIENT:
  7483. iface_type = QCA_IFACE_TYPE_P2P_CLIENT;
  7484. break;
  7485. case WPA_IF_IBSS:
  7486. iface_type = QCA_IFACE_TYPE_IBSS;
  7487. break;
  7488. case WPA_IF_TDLS:
  7489. iface_type = QCA_IFACE_TYPE_TDLS;
  7490. break;
  7491. default:
  7492. return -1;
  7493. }
  7494. param.num = *num;
  7495. param.freq_list = freq_list;
  7496. if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
  7497. nla_put_u32(msg, NL80211_ATTR_IFINDEX, drv->ifindex) ||
  7498. nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
  7499. nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
  7500. QCA_NL80211_VENDOR_SUBCMD_GET_PREFERRED_FREQ_LIST) ||
  7501. !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
  7502. nla_put_u32(msg,
  7503. QCA_WLAN_VENDOR_ATTR_GET_PREFERRED_FREQ_LIST_IFACE_TYPE,
  7504. iface_type)) {
  7505. wpa_printf(MSG_ERROR,
  7506. "%s: err in adding vendor_cmd and vendor_data",
  7507. __func__);
  7508. nlmsg_free(msg);
  7509. return -1;
  7510. }
  7511. nla_nest_end(msg, params);
  7512. os_memset(freq_list, 0, *num * sizeof(freq_list[0]));
  7513. ret = send_and_recv_msgs(drv, msg, preferred_freq_info_handler, &param);
  7514. if (ret) {
  7515. wpa_printf(MSG_ERROR,
  7516. "%s: err in send_and_recv_msgs", __func__);
  7517. return ret;
  7518. }
  7519. *num = param.num;
  7520. for (i = 0; i < *num; i++) {
  7521. wpa_printf(MSG_DEBUG, "nl80211: preferred_channel_list[%d]=%d",
  7522. i, freq_list[i]);
  7523. }
  7524. return 0;
  7525. }
  7526. static int nl80211_set_prob_oper_freq(void *priv, unsigned int freq)
  7527. {
  7528. struct i802_bss *bss = priv;
  7529. struct wpa_driver_nl80211_data *drv = bss->drv;
  7530. struct nl_msg *msg;
  7531. int ret;
  7532. struct nlattr *params;
  7533. if (!drv->set_prob_oper_freq)
  7534. return -1;
  7535. wpa_printf(MSG_DEBUG,
  7536. "nl80211: Set P2P probable operating freq %u for ifindex %d",
  7537. freq, bss->ifindex);
  7538. if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_VENDOR)) ||
  7539. nla_put_u32(msg, NL80211_ATTR_VENDOR_ID, OUI_QCA) ||
  7540. nla_put_u32(msg, NL80211_ATTR_VENDOR_SUBCMD,
  7541. QCA_NL80211_VENDOR_SUBCMD_SET_PROBABLE_OPER_CHANNEL) ||
  7542. !(params = nla_nest_start(msg, NL80211_ATTR_VENDOR_DATA)) ||
  7543. nla_put_u32(msg,
  7544. QCA_WLAN_VENDOR_ATTR_PROBABLE_OPER_CHANNEL_IFACE_TYPE,
  7545. QCA_IFACE_TYPE_P2P_CLIENT) ||
  7546. nla_put_u32(msg,
  7547. QCA_WLAN_VENDOR_ATTR_PROBABLE_OPER_CHANNEL_FREQ,
  7548. freq)) {
  7549. wpa_printf(MSG_ERROR,
  7550. "%s: err in adding vendor_cmd and vendor_data",
  7551. __func__);
  7552. nlmsg_free(msg);
  7553. return -1;
  7554. }
  7555. nla_nest_end(msg, params);
  7556. ret = send_and_recv_msgs(drv, msg, NULL, NULL);
  7557. msg = NULL;
  7558. if (ret) {
  7559. wpa_printf(MSG_ERROR, "%s: err in send_and_recv_msgs",
  7560. __func__);
  7561. return ret;
  7562. }
  7563. nlmsg_free(msg);
  7564. return 0;
  7565. }
  7566. #endif /* CONFIG_DRIVER_NL80211_QCA */
  7567. const struct wpa_driver_ops wpa_driver_nl80211_ops = {
  7568. .name = "nl80211",
  7569. .desc = "Linux nl80211/cfg80211",
  7570. .get_bssid = wpa_driver_nl80211_get_bssid,
  7571. .get_ssid = wpa_driver_nl80211_get_ssid,
  7572. .set_key = driver_nl80211_set_key,
  7573. .scan2 = driver_nl80211_scan2,
  7574. .sched_scan = wpa_driver_nl80211_sched_scan,
  7575. .stop_sched_scan = wpa_driver_nl80211_stop_sched_scan,
  7576. .get_scan_results2 = wpa_driver_nl80211_get_scan_results,
  7577. .abort_scan = wpa_driver_nl80211_abort_scan,
  7578. .deauthenticate = driver_nl80211_deauthenticate,
  7579. .authenticate = driver_nl80211_authenticate,
  7580. .associate = wpa_driver_nl80211_associate,
  7581. .global_init = nl80211_global_init,
  7582. .global_deinit = nl80211_global_deinit,
  7583. .init2 = wpa_driver_nl80211_init,
  7584. .deinit = driver_nl80211_deinit,
  7585. .get_capa = wpa_driver_nl80211_get_capa,
  7586. .set_operstate = wpa_driver_nl80211_set_operstate,
  7587. .set_supp_port = wpa_driver_nl80211_set_supp_port,
  7588. .set_country = wpa_driver_nl80211_set_country,
  7589. .get_country = wpa_driver_nl80211_get_country,
  7590. .set_ap = wpa_driver_nl80211_set_ap,
  7591. .set_acl = wpa_driver_nl80211_set_acl,
  7592. .if_add = wpa_driver_nl80211_if_add,
  7593. .if_remove = driver_nl80211_if_remove,
  7594. .send_mlme = driver_nl80211_send_mlme,
  7595. .get_hw_feature_data = nl80211_get_hw_feature_data,
  7596. .sta_add = wpa_driver_nl80211_sta_add,
  7597. .sta_remove = driver_nl80211_sta_remove,
  7598. .hapd_send_eapol = wpa_driver_nl80211_hapd_send_eapol,
  7599. .sta_set_flags = wpa_driver_nl80211_sta_set_flags,
  7600. .hapd_init = i802_init,
  7601. .hapd_deinit = i802_deinit,
  7602. .set_wds_sta = i802_set_wds_sta,
  7603. .get_seqnum = i802_get_seqnum,
  7604. .flush = i802_flush,
  7605. .get_inact_sec = i802_get_inact_sec,
  7606. .sta_clear_stats = i802_sta_clear_stats,
  7607. .set_rts = i802_set_rts,
  7608. .set_frag = i802_set_frag,
  7609. .set_tx_queue_params = i802_set_tx_queue_params,
  7610. .set_sta_vlan = driver_nl80211_set_sta_vlan,
  7611. .sta_deauth = i802_sta_deauth,
  7612. .sta_disassoc = i802_sta_disassoc,
  7613. .read_sta_data = driver_nl80211_read_sta_data,
  7614. .set_freq = i802_set_freq,
  7615. .send_action = driver_nl80211_send_action,
  7616. .send_action_cancel_wait = wpa_driver_nl80211_send_action_cancel_wait,
  7617. .remain_on_channel = wpa_driver_nl80211_remain_on_channel,
  7618. .cancel_remain_on_channel =
  7619. wpa_driver_nl80211_cancel_remain_on_channel,
  7620. .probe_req_report = driver_nl80211_probe_req_report,
  7621. .deinit_ap = wpa_driver_nl80211_deinit_ap,
  7622. .deinit_p2p_cli = wpa_driver_nl80211_deinit_p2p_cli,
  7623. .resume = wpa_driver_nl80211_resume,
  7624. .signal_monitor = nl80211_signal_monitor,
  7625. .signal_poll = nl80211_signal_poll,
  7626. .send_frame = nl80211_send_frame,
  7627. .set_param = nl80211_set_param,
  7628. .get_radio_name = nl80211_get_radio_name,
  7629. .add_pmkid = nl80211_add_pmkid,
  7630. .remove_pmkid = nl80211_remove_pmkid,
  7631. .flush_pmkid = nl80211_flush_pmkid,
  7632. .set_rekey_info = nl80211_set_rekey_info,
  7633. .poll_client = nl80211_poll_client,
  7634. .set_p2p_powersave = nl80211_set_p2p_powersave,
  7635. .start_dfs_cac = nl80211_start_radar_detection,
  7636. .stop_ap = wpa_driver_nl80211_stop_ap,
  7637. #ifdef CONFIG_TDLS
  7638. .send_tdls_mgmt = nl80211_send_tdls_mgmt,
  7639. .tdls_oper = nl80211_tdls_oper,
  7640. .tdls_enable_channel_switch = nl80211_tdls_enable_channel_switch,
  7641. .tdls_disable_channel_switch = nl80211_tdls_disable_channel_switch,
  7642. #endif /* CONFIG_TDLS */
  7643. .update_ft_ies = wpa_driver_nl80211_update_ft_ies,
  7644. .get_mac_addr = wpa_driver_nl80211_get_macaddr,
  7645. .get_survey = wpa_driver_nl80211_get_survey,
  7646. .status = wpa_driver_nl80211_status,
  7647. .switch_channel = nl80211_switch_channel,
  7648. #ifdef ANDROID_P2P
  7649. .set_noa = wpa_driver_set_p2p_noa,
  7650. .get_noa = wpa_driver_get_p2p_noa,
  7651. .set_ap_wps_ie = wpa_driver_set_ap_wps_p2p_ie,
  7652. #endif /* ANDROID_P2P */
  7653. #ifdef ANDROID
  7654. #ifndef ANDROID_LIB_STUB
  7655. .driver_cmd = wpa_driver_nl80211_driver_cmd,
  7656. #endif /* !ANDROID_LIB_STUB */
  7657. #endif /* ANDROID */
  7658. .vendor_cmd = nl80211_vendor_cmd,
  7659. .set_qos_map = nl80211_set_qos_map,
  7660. .set_wowlan = nl80211_set_wowlan,
  7661. #ifdef CONFIG_DRIVER_NL80211_QCA
  7662. .roaming = nl80211_roaming,
  7663. #endif /* CONFIG_DRIVER_NL80211_QCA */
  7664. .set_mac_addr = nl80211_set_mac_addr,
  7665. #ifdef CONFIG_MESH
  7666. .init_mesh = wpa_driver_nl80211_init_mesh,
  7667. .join_mesh = wpa_driver_nl80211_join_mesh,
  7668. .leave_mesh = wpa_driver_nl80211_leave_mesh,
  7669. #endif /* CONFIG_MESH */
  7670. .br_add_ip_neigh = wpa_driver_br_add_ip_neigh,
  7671. .br_delete_ip_neigh = wpa_driver_br_delete_ip_neigh,
  7672. .br_port_set_attr = wpa_driver_br_port_set_attr,
  7673. .br_set_net_param = wpa_driver_br_set_net_param,
  7674. .add_tx_ts = nl80211_add_ts,
  7675. .del_tx_ts = nl80211_del_ts,
  7676. #ifdef CONFIG_DRIVER_NL80211_QCA
  7677. .do_acs = wpa_driver_do_acs,
  7678. .set_band = nl80211_set_band,
  7679. .get_pref_freq_list = nl80211_get_pref_freq_list,
  7680. .set_prob_oper_freq = nl80211_set_prob_oper_freq,
  7681. #endif /* CONFIG_DRIVER_NL80211_QCA */
  7682. };