ctrl_iface.c 269 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039804080418042804380448045804680478048804980508051805280538054805580568057805880598060806180628063806480658066806780688069807080718072807380748075807680778078807980808081808280838084808580868087808880898090809180928093809480958096809780988099810081018102810381048105810681078108810981108111811281138114811581168117811881198120812181228123812481258126812781288129813081318132813381348135813681378138813981408141814281438144814581468147814881498150815181528153815481558156815781588159816081618162816381648165816681678168816981708171817281738174817581768177817881798180818181828183818481858186818781888189819081918192819381948195819681978198819982008201820282038204820582068207820882098210821182128213821482158216821782188219822082218222822382248225822682278228822982308231823282338234823582368237823882398240824182428243824482458246824782488249825082518252825382548255825682578258825982608261826282638264826582668267826882698270827182728273827482758276827782788279828082818282828382848285828682878288828982908291829282938294829582968297829882998300830183028303830483058306830783088309831083118312831383148315831683178318831983208321832283238324832583268327832883298330833183328333833483358336833783388339834083418342834383448345834683478348834983508351835283538354835583568357835883598360836183628363836483658366836783688369837083718372837383748375837683778378837983808381838283838384838583868387838883898390839183928393839483958396839783988399840084018402840384048405840684078408840984108411841284138414841584168417841884198420842184228423842484258426842784288429843084318432843384348435843684378438843984408441844284438444844584468447844884498450845184528453845484558456845784588459846084618462846384648465846684678468846984708471847284738474847584768477847884798480848184828483848484858486848784888489849084918492849384948495849684978498849985008501850285038504850585068507850885098510851185128513851485158516851785188519852085218522852385248525852685278528852985308531853285338534853585368537853885398540854185428543854485458546854785488549855085518552855385548555855685578558855985608561856285638564856585668567856885698570857185728573857485758576857785788579858085818582858385848585858685878588858985908591859285938594859585968597859885998600860186028603860486058606860786088609861086118612861386148615861686178618861986208621862286238624862586268627862886298630863186328633863486358636863786388639864086418642864386448645864686478648864986508651865286538654865586568657865886598660866186628663866486658666866786688669867086718672867386748675867686778678867986808681868286838684868586868687868886898690869186928693869486958696869786988699870087018702870387048705870687078708870987108711871287138714871587168717871887198720872187228723872487258726872787288729873087318732873387348735873687378738873987408741874287438744874587468747874887498750875187528753875487558756875787588759876087618762876387648765876687678768876987708771877287738774877587768777877887798780878187828783878487858786878787888789879087918792879387948795879687978798879988008801880288038804880588068807880888098810881188128813881488158816881788188819882088218822882388248825882688278828882988308831883288338834883588368837883888398840884188428843884488458846884788488849885088518852885388548855885688578858885988608861886288638864886588668867886888698870887188728873887488758876887788788879888088818882888388848885888688878888888988908891889288938894889588968897889888998900890189028903890489058906890789088909891089118912891389148915891689178918891989208921892289238924892589268927892889298930893189328933893489358936893789388939894089418942894389448945894689478948894989508951895289538954895589568957895889598960896189628963896489658966896789688969897089718972897389748975897689778978897989808981898289838984898589868987898889898990899189928993899489958996899789988999900090019002900390049005900690079008900990109011901290139014901590169017901890199020902190229023902490259026902790289029903090319032903390349035903690379038903990409041904290439044904590469047904890499050905190529053905490559056905790589059906090619062906390649065906690679068906990709071907290739074907590769077907890799080908190829083908490859086908790889089909090919092909390949095909690979098909991009101910291039104910591069107910891099110911191129113911491159116911791189119912091219122912391249125912691279128912991309131913291339134913591369137913891399140914191429143914491459146914791489149915091519152915391549155915691579158915991609161916291639164916591669167916891699170917191729173917491759176917791789179918091819182918391849185918691879188918991909191919291939194919591969197919891999200920192029203920492059206920792089209921092119212921392149215921692179218921992209221922292239224922592269227922892299230923192329233923492359236923792389239924092419242924392449245924692479248924992509251925292539254925592569257925892599260926192629263926492659266926792689269927092719272927392749275927692779278927992809281928292839284928592869287928892899290929192929293929492959296929792989299930093019302930393049305930693079308930993109311931293139314931593169317931893199320932193229323932493259326932793289329933093319332933393349335933693379338933993409341934293439344934593469347934893499350935193529353935493559356935793589359936093619362936393649365936693679368936993709371937293739374937593769377937893799380938193829383938493859386938793889389939093919392939393949395939693979398939994009401940294039404940594069407940894099410941194129413941494159416941794189419942094219422942394249425942694279428942994309431943294339434943594369437943894399440944194429443944494459446944794489449945094519452945394549455945694579458945994609461946294639464946594669467946894699470947194729473947494759476947794789479948094819482948394849485948694879488948994909491949294939494949594969497949894999500950195029503950495059506950795089509951095119512951395149515951695179518951995209521952295239524952595269527952895299530953195329533953495359536953795389539954095419542954395449545954695479548954995509551955295539554955595569557955895599560956195629563956495659566956795689569957095719572957395749575957695779578957995809581958295839584958595869587958895899590959195929593959495959596959795989599960096019602960396049605960696079608960996109611961296139614961596169617961896199620962196229623962496259626962796289629963096319632963396349635963696379638963996409641964296439644964596469647964896499650965196529653965496559656965796589659966096619662966396649665966696679668966996709671967296739674967596769677967896799680968196829683968496859686968796889689969096919692969396949695969696979698969997009701970297039704970597069707970897099710971197129713971497159716971797189719972097219722972397249725972697279728972997309731973297339734973597369737973897399740974197429743974497459746974797489749975097519752975397549755975697579758975997609761976297639764976597669767976897699770977197729773977497759776977797789779978097819782978397849785978697879788978997909791979297939794979597969797979897999800980198029803980498059806980798089809981098119812981398149815981698179818981998209821982298239824982598269827982898299830983198329833983498359836983798389839984098419842984398449845984698479848984998509851985298539854985598569857985898599860986198629863986498659866986798689869987098719872987398749875987698779878987998809881988298839884988598869887988898899890989198929893989498959896989798989899990099019902990399049905990699079908990999109911991299139914991599169917991899199920992199229923992499259926992799289929993099319932993399349935993699379938993999409941994299439944994599469947994899499950995199529953995499559956995799589959996099619962996399649965996699679968996999709971997299739974997599769977997899799980998199829983998499859986998799889989999099919992999399949995999699979998999910000100011000210003100041000510006100071000810009100101001110012100131001410015100161001710018100191002010021100221002310024100251002610027100281002910030100311003210033100341003510036100371003810039100401004110042100431004410045100461004710048100491005010051100521005310054100551005610057100581005910060100611006210063100641006510066100671006810069100701007110072100731007410075100761007710078100791008010081100821008310084100851008610087100881008910090100911009210093100941009510096100971009810099101001010110102101031010410105101061010710108101091011010111101121011310114101151011610117101181011910120101211012210123101241012510126101271012810129101301013110132101331013410135101361013710138101391014010141101421014310144101451014610147101481014910150101511015210153101541015510156101571015810159101601016110162101631016410165101661016710168101691017010171101721017310174101751017610177101781017910180101811018210183101841018510186101871018810189101901019110192101931019410195101961019710198101991020010201102021020310204102051020610207102081020910210102111021210213102141021510216102171021810219102201022110222102231022410225102261022710228102291023010231102321023310234102351023610237102381023910240102411024210243102441024510246102471024810249102501025110252102531025410255102561025710258102591026010261102621026310264102651026610267102681026910270102711027210273102741027510276102771027810279102801028110282102831028410285102861028710288102891029010291102921029310294102951029610297102981029910300103011030210303103041030510306103071030810309103101031110312103131031410315103161031710318103191032010321103221032310324103251032610327103281032910330103311033210333103341033510336103371033810339103401034110342103431034410345103461034710348103491035010351103521035310354103551035610357103581035910360103611036210363103641036510366103671036810369103701037110372103731037410375103761037710378103791038010381103821038310384103851038610387103881038910390103911039210393103941039510396103971039810399104001040110402104031040410405104061040710408104091041010411104121041310414104151041610417104181041910420104211042210423104241042510426104271042810429104301043110432104331043410435104361043710438104391044010441104421044310444104451044610447104481044910450104511045210453104541045510456104571045810459104601046110462104631046410465104661046710468104691047010471104721047310474104751047610477104781047910480104811048210483104841048510486104871048810489104901049110492104931049410495104961049710498104991050010501105021050310504105051050610507105081050910510105111051210513105141051510516105171051810519105201052110522105231052410525105261052710528105291053010531105321053310534105351053610537105381053910540105411054210543105441054510546105471054810549105501055110552105531055410555105561055710558105591056010561105621056310564105651056610567105681056910570105711057210573105741057510576105771057810579105801058110582105831058410585105861058710588105891059010591105921059310594105951059610597105981059910600106011060210603106041060510606106071060810609106101061110612106131061410615106161061710618106191062010621106221062310624106251062610627106281062910630106311063210633106341063510636106371063810639106401064110642106431064410645106461064710648106491065010651106521065310654106551065610657106581065910660106611066210663106641066510666106671066810669106701067110672106731067410675106761067710678106791068010681106821068310684106851068610687106881068910690106911069210693106941069510696106971069810699107001070110702107031070410705107061070710708107091071010711107121071310714107151071610717107181071910720107211072210723107241072510726107271072810729107301073110732107331073410735107361073710738107391074010741107421074310744107451074610747107481074910750107511075210753107541075510756107571075810759107601076110762107631076410765107661076710768107691077010771107721077310774107751077610777107781077910780107811078210783107841078510786107871078810789107901079110792107931079410795107961079710798107991080010801108021080310804108051080610807108081080910810108111081210813108141081510816108171081810819108201082110822108231082410825108261082710828108291083010831108321083310834108351083610837108381083910840108411084210843108441084510846108471084810849108501085110852108531085410855108561085710858108591086010861108621086310864108651086610867108681086910870108711087210873108741087510876108771087810879108801088110882108831088410885108861088710888108891089010891108921089310894108951089610897108981089910900109011090210903109041090510906109071090810909109101091110912109131091410915109161091710918109191092010921109221092310924109251092610927109281092910930109311093210933109341093510936109371093810939109401094110942109431094410945109461094710948109491095010951109521095310954109551095610957109581095910960109611096210963109641096510966109671096810969109701097110972109731097410975109761097710978109791098010981109821098310984109851098610987109881098910990109911099210993109941099510996109971099810999110001100111002110031100411005110061100711008110091101011011110121101311014110151101611017110181101911020110211102211023110241102511026110271102811029110301103111032110331103411035110361103711038110391104011041110421104311044110451104611047110481104911050110511105211053110541105511056110571105811059110601106111062110631106411065110661106711068110691107011071110721107311074110751107611077110781107911080110811108211083110841108511086110871108811089110901109111092110931109411095110961109711098110991110011101111021110311104111051110611107111081110911110111111111211113111141111511116111171111811119111201112111122111231112411125111261112711128111291113011131111321113311134111351113611137111381113911140111411114211143111441114511146111471114811149111501115111152111531115411155111561115711158111591116011161111621116311164111651116611167111681116911170111711117211173111741117511176111771117811179111801118111182111831118411185111861118711188111891119011191111921119311194111951119611197111981119911200112011120211203112041120511206112071120811209112101121111212112131121411215112161121711218112191122011221112221122311224112251122611227112281122911230112311123211233112341123511236112371123811239112401124111242112431124411245112461124711248112491125011251112521125311254112551125611257112581125911260112611126211263112641126511266112671126811269112701127111272112731127411275112761127711278112791128011281
  1. /*
  2. * WPA Supplicant / Control interface (shared code for all backends)
  3. * Copyright (c) 2004-2015, Jouni Malinen <j@w1.fi>
  4. *
  5. * This software may be distributed under the terms of the BSD license.
  6. * See README for more details.
  7. */
  8. #include "utils/includes.h"
  9. #ifdef CONFIG_TESTING_OPTIONS
  10. #include <net/ethernet.h>
  11. #include <netinet/ip.h>
  12. #endif /* CONFIG_TESTING_OPTIONS */
  13. #include "utils/common.h"
  14. #include "utils/eloop.h"
  15. #include "utils/uuid.h"
  16. #include "utils/module_tests.h"
  17. #include "common/version.h"
  18. #include "common/ieee802_11_defs.h"
  19. #include "common/ieee802_11_common.h"
  20. #include "common/wpa_ctrl.h"
  21. #include "common/dpp.h"
  22. #include "crypto/tls.h"
  23. #include "ap/hostapd.h"
  24. #include "eap_peer/eap.h"
  25. #include "eapol_supp/eapol_supp_sm.h"
  26. #include "rsn_supp/wpa.h"
  27. #include "rsn_supp/preauth.h"
  28. #include "rsn_supp/pmksa_cache.h"
  29. #include "l2_packet/l2_packet.h"
  30. #include "wps/wps.h"
  31. #include "fst/fst.h"
  32. #include "fst/fst_ctrl_iface.h"
  33. #include "config.h"
  34. #include "wpa_supplicant_i.h"
  35. #include "driver_i.h"
  36. #include "wps_supplicant.h"
  37. #include "ibss_rsn.h"
  38. #include "ap.h"
  39. #include "p2p_supplicant.h"
  40. #include "p2p/p2p.h"
  41. #include "hs20_supplicant.h"
  42. #include "wifi_display.h"
  43. #include "notify.h"
  44. #include "bss.h"
  45. #include "scan.h"
  46. #include "ctrl_iface.h"
  47. #include "interworking.h"
  48. #include "blacklist.h"
  49. #include "autoscan.h"
  50. #include "wnm_sta.h"
  51. #include "offchannel.h"
  52. #include "drivers/driver.h"
  53. #include "mesh.h"
  54. #include "dpp_supplicant.h"
  55. static int wpa_supplicant_global_iface_list(struct wpa_global *global,
  56. char *buf, int len);
  57. static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global,
  58. const char *input,
  59. char *buf, int len);
  60. static int * freq_range_to_channel_list(struct wpa_supplicant *wpa_s,
  61. char *val);
  62. #ifdef CONFIG_FILS
  63. static int wpa_is_fils_supported(struct wpa_supplicant *wpa_s)
  64. {
  65. return (((wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
  66. (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SUPPORT_FILS)) ||
  67. (!(wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
  68. (wpa_s->drv_flags & WPA_DRIVER_FLAGS_FILS_SK_OFFLOAD)));
  69. }
  70. #ifdef CONFIG_FILS_SK_PFS
  71. static int wpa_is_fils_sk_pfs_supported(struct wpa_supplicant *wpa_s)
  72. {
  73. return (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SME) &&
  74. (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SUPPORT_FILS);
  75. }
  76. #endif /* CONFIG_FILS_SK_PFS */
  77. #endif /* CONFIG_FILS */
  78. static int set_bssid_filter(struct wpa_supplicant *wpa_s, char *val)
  79. {
  80. char *pos;
  81. u8 addr[ETH_ALEN], *filter = NULL, *n;
  82. size_t count = 0;
  83. pos = val;
  84. while (pos) {
  85. if (*pos == '\0')
  86. break;
  87. if (hwaddr_aton(pos, addr)) {
  88. os_free(filter);
  89. return -1;
  90. }
  91. n = os_realloc_array(filter, count + 1, ETH_ALEN);
  92. if (n == NULL) {
  93. os_free(filter);
  94. return -1;
  95. }
  96. filter = n;
  97. os_memcpy(filter + count * ETH_ALEN, addr, ETH_ALEN);
  98. count++;
  99. pos = os_strchr(pos, ' ');
  100. if (pos)
  101. pos++;
  102. }
  103. wpa_hexdump(MSG_DEBUG, "bssid_filter", filter, count * ETH_ALEN);
  104. os_free(wpa_s->bssid_filter);
  105. wpa_s->bssid_filter = filter;
  106. wpa_s->bssid_filter_count = count;
  107. return 0;
  108. }
  109. static int set_disallow_aps(struct wpa_supplicant *wpa_s, char *val)
  110. {
  111. char *pos;
  112. u8 addr[ETH_ALEN], *bssid = NULL, *n;
  113. struct wpa_ssid_value *ssid = NULL, *ns;
  114. size_t count = 0, ssid_count = 0;
  115. struct wpa_ssid *c;
  116. /*
  117. * disallow_list ::= <ssid_spec> | <bssid_spec> | <disallow_list> | ""
  118. * SSID_SPEC ::= ssid <SSID_HEX>
  119. * BSSID_SPEC ::= bssid <BSSID_HEX>
  120. */
  121. pos = val;
  122. while (pos) {
  123. if (*pos == '\0')
  124. break;
  125. if (os_strncmp(pos, "bssid ", 6) == 0) {
  126. int res;
  127. pos += 6;
  128. res = hwaddr_aton2(pos, addr);
  129. if (res < 0) {
  130. os_free(ssid);
  131. os_free(bssid);
  132. wpa_printf(MSG_DEBUG, "Invalid disallow_aps "
  133. "BSSID value '%s'", pos);
  134. return -1;
  135. }
  136. pos += res;
  137. n = os_realloc_array(bssid, count + 1, ETH_ALEN);
  138. if (n == NULL) {
  139. os_free(ssid);
  140. os_free(bssid);
  141. return -1;
  142. }
  143. bssid = n;
  144. os_memcpy(bssid + count * ETH_ALEN, addr, ETH_ALEN);
  145. count++;
  146. } else if (os_strncmp(pos, "ssid ", 5) == 0) {
  147. char *end;
  148. pos += 5;
  149. end = pos;
  150. while (*end) {
  151. if (*end == '\0' || *end == ' ')
  152. break;
  153. end++;
  154. }
  155. ns = os_realloc_array(ssid, ssid_count + 1,
  156. sizeof(struct wpa_ssid_value));
  157. if (ns == NULL) {
  158. os_free(ssid);
  159. os_free(bssid);
  160. return -1;
  161. }
  162. ssid = ns;
  163. if ((end - pos) & 0x01 ||
  164. end - pos > 2 * SSID_MAX_LEN ||
  165. hexstr2bin(pos, ssid[ssid_count].ssid,
  166. (end - pos) / 2) < 0) {
  167. os_free(ssid);
  168. os_free(bssid);
  169. wpa_printf(MSG_DEBUG, "Invalid disallow_aps "
  170. "SSID value '%s'", pos);
  171. return -1;
  172. }
  173. ssid[ssid_count].ssid_len = (end - pos) / 2;
  174. wpa_hexdump_ascii(MSG_DEBUG, "disallow_aps SSID",
  175. ssid[ssid_count].ssid,
  176. ssid[ssid_count].ssid_len);
  177. ssid_count++;
  178. pos = end;
  179. } else {
  180. wpa_printf(MSG_DEBUG, "Unexpected disallow_aps value "
  181. "'%s'", pos);
  182. os_free(ssid);
  183. os_free(bssid);
  184. return -1;
  185. }
  186. pos = os_strchr(pos, ' ');
  187. if (pos)
  188. pos++;
  189. }
  190. wpa_hexdump(MSG_DEBUG, "disallow_aps_bssid", bssid, count * ETH_ALEN);
  191. os_free(wpa_s->disallow_aps_bssid);
  192. wpa_s->disallow_aps_bssid = bssid;
  193. wpa_s->disallow_aps_bssid_count = count;
  194. wpa_printf(MSG_DEBUG, "disallow_aps_ssid_count %d", (int) ssid_count);
  195. os_free(wpa_s->disallow_aps_ssid);
  196. wpa_s->disallow_aps_ssid = ssid;
  197. wpa_s->disallow_aps_ssid_count = ssid_count;
  198. if (!wpa_s->current_ssid || wpa_s->wpa_state < WPA_AUTHENTICATING)
  199. return 0;
  200. c = wpa_s->current_ssid;
  201. if (c->mode != WPAS_MODE_INFRA && c->mode != WPAS_MODE_IBSS)
  202. return 0;
  203. if (!disallowed_bssid(wpa_s, wpa_s->bssid) &&
  204. !disallowed_ssid(wpa_s, c->ssid, c->ssid_len))
  205. return 0;
  206. wpa_printf(MSG_DEBUG, "Disconnect and try to find another network "
  207. "because current AP was marked disallowed");
  208. #ifdef CONFIG_SME
  209. wpa_s->sme.prev_bssid_set = 0;
  210. #endif /* CONFIG_SME */
  211. wpa_s->reassociate = 1;
  212. wpa_s->own_disconnect_req = 1;
  213. wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
  214. wpa_supplicant_req_scan(wpa_s, 0, 0);
  215. return 0;
  216. }
  217. #ifndef CONFIG_NO_CONFIG_BLOBS
  218. static int wpas_ctrl_set_blob(struct wpa_supplicant *wpa_s, char *pos)
  219. {
  220. char *name = pos;
  221. struct wpa_config_blob *blob;
  222. size_t len;
  223. pos = os_strchr(pos, ' ');
  224. if (pos == NULL)
  225. return -1;
  226. *pos++ = '\0';
  227. len = os_strlen(pos);
  228. if (len & 1)
  229. return -1;
  230. wpa_printf(MSG_DEBUG, "CTRL: Set blob '%s'", name);
  231. blob = os_zalloc(sizeof(*blob));
  232. if (blob == NULL)
  233. return -1;
  234. blob->name = os_strdup(name);
  235. blob->data = os_malloc(len / 2);
  236. if (blob->name == NULL || blob->data == NULL) {
  237. wpa_config_free_blob(blob);
  238. return -1;
  239. }
  240. if (hexstr2bin(pos, blob->data, len / 2) < 0) {
  241. wpa_printf(MSG_DEBUG, "CTRL: Invalid blob hex data");
  242. wpa_config_free_blob(blob);
  243. return -1;
  244. }
  245. blob->len = len / 2;
  246. wpa_config_set_blob(wpa_s->conf, blob);
  247. return 0;
  248. }
  249. #endif /* CONFIG_NO_CONFIG_BLOBS */
  250. static int wpas_ctrl_pno(struct wpa_supplicant *wpa_s, char *cmd)
  251. {
  252. char *params;
  253. char *pos;
  254. int *freqs = NULL;
  255. int ret;
  256. if (atoi(cmd)) {
  257. params = os_strchr(cmd, ' ');
  258. os_free(wpa_s->manual_sched_scan_freqs);
  259. if (params) {
  260. params++;
  261. pos = os_strstr(params, "freq=");
  262. if (pos)
  263. freqs = freq_range_to_channel_list(wpa_s,
  264. pos + 5);
  265. }
  266. wpa_s->manual_sched_scan_freqs = freqs;
  267. ret = wpas_start_pno(wpa_s);
  268. } else {
  269. ret = wpas_stop_pno(wpa_s);
  270. }
  271. return ret;
  272. }
  273. static int wpas_ctrl_set_band(struct wpa_supplicant *wpa_s, char *band)
  274. {
  275. union wpa_event_data event;
  276. if (os_strcmp(band, "AUTO") == 0)
  277. wpa_s->setband = WPA_SETBAND_AUTO;
  278. else if (os_strcmp(band, "5G") == 0)
  279. wpa_s->setband = WPA_SETBAND_5G;
  280. else if (os_strcmp(band, "2G") == 0)
  281. wpa_s->setband = WPA_SETBAND_2G;
  282. else
  283. return -1;
  284. if (wpa_drv_setband(wpa_s, wpa_s->setband) == 0) {
  285. os_memset(&event, 0, sizeof(event));
  286. event.channel_list_changed.initiator = REGDOM_SET_BY_USER;
  287. event.channel_list_changed.type = REGDOM_TYPE_UNKNOWN;
  288. wpa_supplicant_event(wpa_s, EVENT_CHANNEL_LIST_CHANGED, &event);
  289. }
  290. return 0;
  291. }
  292. static int wpas_ctrl_iface_set_lci(struct wpa_supplicant *wpa_s,
  293. const char *cmd)
  294. {
  295. struct wpabuf *lci;
  296. if (*cmd == '\0' || os_strcmp(cmd, "\"\"") == 0) {
  297. wpabuf_free(wpa_s->lci);
  298. wpa_s->lci = NULL;
  299. return 0;
  300. }
  301. lci = wpabuf_parse_bin(cmd);
  302. if (!lci)
  303. return -1;
  304. if (os_get_reltime(&wpa_s->lci_time)) {
  305. wpabuf_free(lci);
  306. return -1;
  307. }
  308. wpabuf_free(wpa_s->lci);
  309. wpa_s->lci = lci;
  310. return 0;
  311. }
  312. static int
  313. wpas_ctrl_set_relative_rssi(struct wpa_supplicant *wpa_s, const char *cmd)
  314. {
  315. int relative_rssi;
  316. if (os_strcmp(cmd, "disable") == 0) {
  317. wpa_s->srp.relative_rssi_set = 0;
  318. return 0;
  319. }
  320. relative_rssi = atoi(cmd);
  321. if (relative_rssi < 0 || relative_rssi > 100)
  322. return -1;
  323. wpa_s->srp.relative_rssi = relative_rssi;
  324. wpa_s->srp.relative_rssi_set = 1;
  325. return 0;
  326. }
  327. static int wpas_ctrl_set_relative_band_adjust(struct wpa_supplicant *wpa_s,
  328. const char *cmd)
  329. {
  330. char *pos;
  331. int adjust_rssi;
  332. /* <band>:adjust_value */
  333. pos = os_strchr(cmd, ':');
  334. if (!pos)
  335. return -1;
  336. pos++;
  337. adjust_rssi = atoi(pos);
  338. if (adjust_rssi < -100 || adjust_rssi > 100)
  339. return -1;
  340. if (os_strncmp(cmd, "2G", 2) == 0)
  341. wpa_s->srp.relative_adjust_band = WPA_SETBAND_2G;
  342. else if (os_strncmp(cmd, "5G", 2) == 0)
  343. wpa_s->srp.relative_adjust_band = WPA_SETBAND_5G;
  344. else
  345. return -1;
  346. wpa_s->srp.relative_adjust_rssi = adjust_rssi;
  347. return 0;
  348. }
  349. static int wpas_ctrl_iface_set_ric_ies(struct wpa_supplicant *wpa_s,
  350. const char *cmd)
  351. {
  352. struct wpabuf *ric_ies;
  353. if (*cmd == '\0' || os_strcmp(cmd, "\"\"") == 0) {
  354. wpabuf_free(wpa_s->ric_ies);
  355. wpa_s->ric_ies = NULL;
  356. return 0;
  357. }
  358. ric_ies = wpabuf_parse_bin(cmd);
  359. if (!ric_ies)
  360. return -1;
  361. wpabuf_free(wpa_s->ric_ies);
  362. wpa_s->ric_ies = ric_ies;
  363. return 0;
  364. }
  365. static int wpa_supplicant_ctrl_iface_set(struct wpa_supplicant *wpa_s,
  366. char *cmd)
  367. {
  368. char *value;
  369. int ret = 0;
  370. value = os_strchr(cmd, ' ');
  371. if (value == NULL)
  372. return -1;
  373. *value++ = '\0';
  374. wpa_printf(MSG_DEBUG, "CTRL_IFACE SET '%s'='%s'", cmd, value);
  375. if (os_strcasecmp(cmd, "EAPOL::heldPeriod") == 0) {
  376. eapol_sm_configure(wpa_s->eapol,
  377. atoi(value), -1, -1, -1);
  378. } else if (os_strcasecmp(cmd, "EAPOL::authPeriod") == 0) {
  379. eapol_sm_configure(wpa_s->eapol,
  380. -1, atoi(value), -1, -1);
  381. } else if (os_strcasecmp(cmd, "EAPOL::startPeriod") == 0) {
  382. eapol_sm_configure(wpa_s->eapol,
  383. -1, -1, atoi(value), -1);
  384. } else if (os_strcasecmp(cmd, "EAPOL::maxStart") == 0) {
  385. eapol_sm_configure(wpa_s->eapol,
  386. -1, -1, -1, atoi(value));
  387. } else if (os_strcasecmp(cmd, "dot11RSNAConfigPMKLifetime") == 0) {
  388. if (wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_LIFETIME,
  389. atoi(value))) {
  390. ret = -1;
  391. } else {
  392. value[-1] = '=';
  393. wpa_config_process_global(wpa_s->conf, cmd, -1);
  394. }
  395. } else if (os_strcasecmp(cmd, "dot11RSNAConfigPMKReauthThreshold") ==
  396. 0) {
  397. if (wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_REAUTH_THRESHOLD,
  398. atoi(value))) {
  399. ret = -1;
  400. } else {
  401. value[-1] = '=';
  402. wpa_config_process_global(wpa_s->conf, cmd, -1);
  403. }
  404. } else if (os_strcasecmp(cmd, "dot11RSNAConfigSATimeout") == 0) {
  405. if (wpa_sm_set_param(wpa_s->wpa, RSNA_SA_TIMEOUT,
  406. atoi(value))) {
  407. ret = -1;
  408. } else {
  409. value[-1] = '=';
  410. wpa_config_process_global(wpa_s->conf, cmd, -1);
  411. }
  412. } else if (os_strcasecmp(cmd, "wps_fragment_size") == 0) {
  413. wpa_s->wps_fragment_size = atoi(value);
  414. #ifdef CONFIG_WPS_TESTING
  415. } else if (os_strcasecmp(cmd, "wps_version_number") == 0) {
  416. long int val;
  417. val = strtol(value, NULL, 0);
  418. if (val < 0 || val > 0xff) {
  419. ret = -1;
  420. wpa_printf(MSG_DEBUG, "WPS: Invalid "
  421. "wps_version_number %ld", val);
  422. } else {
  423. wps_version_number = val;
  424. wpa_printf(MSG_DEBUG, "WPS: Testing - force WPS "
  425. "version %u.%u",
  426. (wps_version_number & 0xf0) >> 4,
  427. wps_version_number & 0x0f);
  428. }
  429. } else if (os_strcasecmp(cmd, "wps_testing_dummy_cred") == 0) {
  430. wps_testing_dummy_cred = atoi(value);
  431. wpa_printf(MSG_DEBUG, "WPS: Testing - dummy_cred=%d",
  432. wps_testing_dummy_cred);
  433. } else if (os_strcasecmp(cmd, "wps_corrupt_pkhash") == 0) {
  434. wps_corrupt_pkhash = atoi(value);
  435. wpa_printf(MSG_DEBUG, "WPS: Testing - wps_corrupt_pkhash=%d",
  436. wps_corrupt_pkhash);
  437. } else if (os_strcasecmp(cmd, "wps_force_auth_types") == 0) {
  438. if (value[0] == '\0') {
  439. wps_force_auth_types_in_use = 0;
  440. } else {
  441. wps_force_auth_types = strtol(value, NULL, 0);
  442. wps_force_auth_types_in_use = 1;
  443. }
  444. } else if (os_strcasecmp(cmd, "wps_force_encr_types") == 0) {
  445. if (value[0] == '\0') {
  446. wps_force_encr_types_in_use = 0;
  447. } else {
  448. wps_force_encr_types = strtol(value, NULL, 0);
  449. wps_force_encr_types_in_use = 1;
  450. }
  451. #endif /* CONFIG_WPS_TESTING */
  452. } else if (os_strcasecmp(cmd, "ampdu") == 0) {
  453. if (wpa_drv_ampdu(wpa_s, atoi(value)) < 0)
  454. ret = -1;
  455. #ifdef CONFIG_TDLS
  456. #ifdef CONFIG_TDLS_TESTING
  457. } else if (os_strcasecmp(cmd, "tdls_testing") == 0) {
  458. tdls_testing = strtol(value, NULL, 0);
  459. wpa_printf(MSG_DEBUG, "TDLS: tdls_testing=0x%x", tdls_testing);
  460. #endif /* CONFIG_TDLS_TESTING */
  461. } else if (os_strcasecmp(cmd, "tdls_disabled") == 0) {
  462. int disabled = atoi(value);
  463. wpa_printf(MSG_DEBUG, "TDLS: tdls_disabled=%d", disabled);
  464. if (disabled) {
  465. if (wpa_drv_tdls_oper(wpa_s, TDLS_DISABLE, NULL) < 0)
  466. ret = -1;
  467. } else if (wpa_drv_tdls_oper(wpa_s, TDLS_ENABLE, NULL) < 0)
  468. ret = -1;
  469. wpa_tdls_enable(wpa_s->wpa, !disabled);
  470. #endif /* CONFIG_TDLS */
  471. } else if (os_strcasecmp(cmd, "pno") == 0) {
  472. ret = wpas_ctrl_pno(wpa_s, value);
  473. } else if (os_strcasecmp(cmd, "radio_disabled") == 0) {
  474. int disabled = atoi(value);
  475. if (wpa_drv_radio_disable(wpa_s, disabled) < 0)
  476. ret = -1;
  477. else if (disabled)
  478. wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
  479. } else if (os_strcasecmp(cmd, "uapsd") == 0) {
  480. if (os_strcmp(value, "disable") == 0)
  481. wpa_s->set_sta_uapsd = 0;
  482. else {
  483. int be, bk, vi, vo;
  484. char *pos;
  485. /* format: BE,BK,VI,VO;max SP Length */
  486. be = atoi(value);
  487. pos = os_strchr(value, ',');
  488. if (pos == NULL)
  489. return -1;
  490. pos++;
  491. bk = atoi(pos);
  492. pos = os_strchr(pos, ',');
  493. if (pos == NULL)
  494. return -1;
  495. pos++;
  496. vi = atoi(pos);
  497. pos = os_strchr(pos, ',');
  498. if (pos == NULL)
  499. return -1;
  500. pos++;
  501. vo = atoi(pos);
  502. /* ignore max SP Length for now */
  503. wpa_s->set_sta_uapsd = 1;
  504. wpa_s->sta_uapsd = 0;
  505. if (be)
  506. wpa_s->sta_uapsd |= BIT(0);
  507. if (bk)
  508. wpa_s->sta_uapsd |= BIT(1);
  509. if (vi)
  510. wpa_s->sta_uapsd |= BIT(2);
  511. if (vo)
  512. wpa_s->sta_uapsd |= BIT(3);
  513. }
  514. } else if (os_strcasecmp(cmd, "ps") == 0) {
  515. ret = wpa_drv_set_p2p_powersave(wpa_s, atoi(value), -1, -1);
  516. #ifdef CONFIG_WIFI_DISPLAY
  517. } else if (os_strcasecmp(cmd, "wifi_display") == 0) {
  518. int enabled = !!atoi(value);
  519. if (enabled && !wpa_s->global->p2p)
  520. ret = -1;
  521. else
  522. wifi_display_enable(wpa_s->global, enabled);
  523. #endif /* CONFIG_WIFI_DISPLAY */
  524. } else if (os_strcasecmp(cmd, "bssid_filter") == 0) {
  525. ret = set_bssid_filter(wpa_s, value);
  526. } else if (os_strcasecmp(cmd, "disallow_aps") == 0) {
  527. ret = set_disallow_aps(wpa_s, value);
  528. } else if (os_strcasecmp(cmd, "no_keep_alive") == 0) {
  529. wpa_s->no_keep_alive = !!atoi(value);
  530. #ifdef CONFIG_DPP
  531. } else if (os_strcasecmp(cmd, "dpp_configurator_params") == 0) {
  532. os_free(wpa_s->dpp_configurator_params);
  533. wpa_s->dpp_configurator_params = os_strdup(value);
  534. } else if (os_strcasecmp(cmd, "dpp_init_max_tries") == 0) {
  535. wpa_s->dpp_init_max_tries = atoi(value);
  536. } else if (os_strcasecmp(cmd, "dpp_init_retry_time") == 0) {
  537. wpa_s->dpp_init_retry_time = atoi(value);
  538. } else if (os_strcasecmp(cmd, "dpp_resp_wait_time") == 0) {
  539. wpa_s->dpp_resp_wait_time = atoi(value);
  540. } else if (os_strcasecmp(cmd, "dpp_resp_max_tries") == 0) {
  541. wpa_s->dpp_resp_max_tries = atoi(value);
  542. } else if (os_strcasecmp(cmd, "dpp_resp_retry_time") == 0) {
  543. wpa_s->dpp_resp_retry_time = atoi(value);
  544. } else if (os_strcasecmp(cmd, "dpp_pkex_own_mac_override") == 0) {
  545. if (hwaddr_aton(value, dpp_pkex_own_mac_override))
  546. ret = -1;
  547. } else if (os_strcasecmp(cmd, "dpp_pkex_peer_mac_override") == 0) {
  548. if (hwaddr_aton(value, dpp_pkex_peer_mac_override))
  549. ret = -1;
  550. } else if (os_strcasecmp(cmd, "dpp_pkex_ephemeral_key_override") == 0) {
  551. size_t hex_len = os_strlen(value);
  552. if (hex_len >
  553. 2 * sizeof(dpp_pkex_ephemeral_key_override))
  554. ret = -1;
  555. else if (hexstr2bin(value, dpp_pkex_ephemeral_key_override,
  556. hex_len / 2))
  557. ret = -1;
  558. else
  559. dpp_pkex_ephemeral_key_override_len = hex_len / 2;
  560. #endif /* CONFIG_DPP */
  561. #ifdef CONFIG_TESTING_OPTIONS
  562. } else if (os_strcasecmp(cmd, "ext_mgmt_frame_handling") == 0) {
  563. wpa_s->ext_mgmt_frame_handling = !!atoi(value);
  564. } else if (os_strcasecmp(cmd, "ext_eapol_frame_io") == 0) {
  565. wpa_s->ext_eapol_frame_io = !!atoi(value);
  566. #ifdef CONFIG_AP
  567. if (wpa_s->ap_iface) {
  568. wpa_s->ap_iface->bss[0]->ext_eapol_frame_io =
  569. wpa_s->ext_eapol_frame_io;
  570. }
  571. #endif /* CONFIG_AP */
  572. } else if (os_strcasecmp(cmd, "extra_roc_dur") == 0) {
  573. wpa_s->extra_roc_dur = atoi(value);
  574. } else if (os_strcasecmp(cmd, "test_failure") == 0) {
  575. wpa_s->test_failure = atoi(value);
  576. } else if (os_strcasecmp(cmd, "p2p_go_csa_on_inv") == 0) {
  577. wpa_s->p2p_go_csa_on_inv = !!atoi(value);
  578. } else if (os_strcasecmp(cmd, "ignore_auth_resp") == 0) {
  579. wpa_s->ignore_auth_resp = !!atoi(value);
  580. } else if (os_strcasecmp(cmd, "ignore_assoc_disallow") == 0) {
  581. wpa_s->ignore_assoc_disallow = !!atoi(value);
  582. wpa_drv_ignore_assoc_disallow(wpa_s,
  583. wpa_s->ignore_assoc_disallow);
  584. } else if (os_strcasecmp(cmd, "reject_btm_req_reason") == 0) {
  585. wpa_s->reject_btm_req_reason = atoi(value);
  586. } else if (os_strcasecmp(cmd, "get_pref_freq_list_override") == 0) {
  587. os_free(wpa_s->get_pref_freq_list_override);
  588. if (!value[0])
  589. wpa_s->get_pref_freq_list_override = NULL;
  590. else
  591. wpa_s->get_pref_freq_list_override = os_strdup(value);
  592. } else if (os_strcasecmp(cmd, "sae_commit_override") == 0) {
  593. wpabuf_free(wpa_s->sae_commit_override);
  594. if (value[0] == '\0')
  595. wpa_s->sae_commit_override = NULL;
  596. else
  597. wpa_s->sae_commit_override = wpabuf_parse_bin(value);
  598. #ifdef CONFIG_DPP
  599. } else if (os_strcasecmp(cmd, "dpp_config_obj_override") == 0) {
  600. os_free(wpa_s->dpp_config_obj_override);
  601. if (value[0] == '\0')
  602. wpa_s->dpp_config_obj_override = NULL;
  603. else
  604. wpa_s->dpp_config_obj_override = os_strdup(value);
  605. } else if (os_strcasecmp(cmd, "dpp_discovery_override") == 0) {
  606. os_free(wpa_s->dpp_discovery_override);
  607. if (value[0] == '\0')
  608. wpa_s->dpp_discovery_override = NULL;
  609. else
  610. wpa_s->dpp_discovery_override = os_strdup(value);
  611. } else if (os_strcasecmp(cmd, "dpp_groups_override") == 0) {
  612. os_free(wpa_s->dpp_groups_override);
  613. if (value[0] == '\0')
  614. wpa_s->dpp_groups_override = NULL;
  615. else
  616. wpa_s->dpp_groups_override = os_strdup(value);
  617. } else if (os_strcasecmp(cmd,
  618. "dpp_ignore_netaccesskey_mismatch") == 0) {
  619. wpa_s->dpp_ignore_netaccesskey_mismatch = atoi(value);
  620. } else if (os_strcasecmp(cmd, "dpp_test") == 0) {
  621. dpp_test = atoi(value);
  622. #endif /* CONFIG_DPP */
  623. #endif /* CONFIG_TESTING_OPTIONS */
  624. #ifndef CONFIG_NO_CONFIG_BLOBS
  625. } else if (os_strcmp(cmd, "blob") == 0) {
  626. ret = wpas_ctrl_set_blob(wpa_s, value);
  627. #endif /* CONFIG_NO_CONFIG_BLOBS */
  628. } else if (os_strcasecmp(cmd, "setband") == 0) {
  629. ret = wpas_ctrl_set_band(wpa_s, value);
  630. #ifdef CONFIG_MBO
  631. } else if (os_strcasecmp(cmd, "non_pref_chan") == 0) {
  632. ret = wpas_mbo_update_non_pref_chan(wpa_s, value);
  633. if (ret == 0) {
  634. value[-1] = '=';
  635. wpa_config_process_global(wpa_s->conf, cmd, -1);
  636. }
  637. } else if (os_strcasecmp(cmd, "mbo_cell_capa") == 0) {
  638. wpas_mbo_update_cell_capa(wpa_s, atoi(value));
  639. } else if (os_strcasecmp(cmd, "oce") == 0) {
  640. wpa_s->conf->oce = atoi(value);
  641. if (wpa_s->conf->oce) {
  642. if ((wpa_s->conf->oce & OCE_STA) &&
  643. (wpa_s->drv_flags & WPA_DRIVER_FLAGS_OCE_STA))
  644. wpa_s->enable_oce = OCE_STA;
  645. if ((wpa_s->conf->oce & OCE_STA_CFON) &&
  646. (wpa_s->drv_flags &
  647. WPA_DRIVER_FLAGS_OCE_STA_CFON)) {
  648. /* TODO: Need to add STA-CFON support */
  649. wpa_printf(MSG_ERROR,
  650. "OCE STA-CFON feature is not yet supported");
  651. return -1;
  652. }
  653. } else {
  654. wpa_s->enable_oce = 0;
  655. }
  656. wpa_supplicant_set_default_scan_ies(wpa_s);
  657. #endif /* CONFIG_MBO */
  658. } else if (os_strcasecmp(cmd, "lci") == 0) {
  659. ret = wpas_ctrl_iface_set_lci(wpa_s, value);
  660. } else if (os_strcasecmp(cmd, "tdls_trigger_control") == 0) {
  661. ret = wpa_drv_set_tdls_mode(wpa_s, atoi(value));
  662. } else if (os_strcasecmp(cmd, "relative_rssi") == 0) {
  663. ret = wpas_ctrl_set_relative_rssi(wpa_s, value);
  664. } else if (os_strcasecmp(cmd, "relative_band_adjust") == 0) {
  665. ret = wpas_ctrl_set_relative_band_adjust(wpa_s, value);
  666. } else if (os_strcasecmp(cmd, "ric_ies") == 0) {
  667. ret = wpas_ctrl_iface_set_ric_ies(wpa_s, value);
  668. } else if (os_strcasecmp(cmd, "roaming") == 0) {
  669. ret = wpa_drv_roaming(wpa_s, atoi(value), NULL);
  670. } else {
  671. value[-1] = '=';
  672. ret = wpa_config_process_global(wpa_s->conf, cmd, -1);
  673. if (ret == 0)
  674. wpa_supplicant_update_config(wpa_s);
  675. }
  676. return ret;
  677. }
  678. static int wpa_supplicant_ctrl_iface_get(struct wpa_supplicant *wpa_s,
  679. char *cmd, char *buf, size_t buflen)
  680. {
  681. int res = -1;
  682. wpa_printf(MSG_DEBUG, "CTRL_IFACE GET '%s'", cmd);
  683. if (os_strcmp(cmd, "version") == 0) {
  684. res = os_snprintf(buf, buflen, "%s", VERSION_STR);
  685. } else if (os_strcasecmp(cmd, "country") == 0) {
  686. if (wpa_s->conf->country[0] && wpa_s->conf->country[1])
  687. res = os_snprintf(buf, buflen, "%c%c",
  688. wpa_s->conf->country[0],
  689. wpa_s->conf->country[1]);
  690. #ifdef CONFIG_WIFI_DISPLAY
  691. } else if (os_strcasecmp(cmd, "wifi_display") == 0) {
  692. int enabled;
  693. if (wpa_s->global->p2p == NULL ||
  694. wpa_s->global->p2p_disabled)
  695. enabled = 0;
  696. else
  697. enabled = wpa_s->global->wifi_display;
  698. res = os_snprintf(buf, buflen, "%d", enabled);
  699. #endif /* CONFIG_WIFI_DISPLAY */
  700. #ifdef CONFIG_TESTING_GET_GTK
  701. } else if (os_strcmp(cmd, "gtk") == 0) {
  702. if (wpa_s->last_gtk_len == 0)
  703. return -1;
  704. res = wpa_snprintf_hex(buf, buflen, wpa_s->last_gtk,
  705. wpa_s->last_gtk_len);
  706. return res;
  707. #endif /* CONFIG_TESTING_GET_GTK */
  708. } else if (os_strcmp(cmd, "tls_library") == 0) {
  709. res = tls_get_library_version(buf, buflen);
  710. #ifdef CONFIG_TESTING_OPTIONS
  711. } else if (os_strcmp(cmd, "anonce") == 0) {
  712. return wpa_snprintf_hex(buf, buflen,
  713. wpa_sm_get_anonce(wpa_s->wpa),
  714. WPA_NONCE_LEN);
  715. #endif /* CONFIG_TESTING_OPTIONS */
  716. } else {
  717. res = wpa_config_get_value(cmd, wpa_s->conf, buf, buflen);
  718. }
  719. if (os_snprintf_error(buflen, res))
  720. return -1;
  721. return res;
  722. }
  723. #ifdef IEEE8021X_EAPOL
  724. static int wpa_supplicant_ctrl_iface_preauth(struct wpa_supplicant *wpa_s,
  725. char *addr)
  726. {
  727. u8 bssid[ETH_ALEN];
  728. struct wpa_ssid *ssid = wpa_s->current_ssid;
  729. if (hwaddr_aton(addr, bssid)) {
  730. wpa_printf(MSG_DEBUG, "CTRL_IFACE PREAUTH: invalid address "
  731. "'%s'", addr);
  732. return -1;
  733. }
  734. wpa_printf(MSG_DEBUG, "CTRL_IFACE PREAUTH " MACSTR, MAC2STR(bssid));
  735. rsn_preauth_deinit(wpa_s->wpa);
  736. if (rsn_preauth_init(wpa_s->wpa, bssid, ssid ? &ssid->eap : NULL))
  737. return -1;
  738. return 0;
  739. }
  740. #endif /* IEEE8021X_EAPOL */
  741. #ifdef CONFIG_TDLS
  742. static int wpa_supplicant_ctrl_iface_tdls_discover(
  743. struct wpa_supplicant *wpa_s, char *addr)
  744. {
  745. u8 peer[ETH_ALEN];
  746. int ret;
  747. if (hwaddr_aton(addr, peer)) {
  748. wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_DISCOVER: invalid "
  749. "address '%s'", addr);
  750. return -1;
  751. }
  752. wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_DISCOVER " MACSTR,
  753. MAC2STR(peer));
  754. if (wpa_tdls_is_external_setup(wpa_s->wpa))
  755. ret = wpa_tdls_send_discovery_request(wpa_s->wpa, peer);
  756. else
  757. ret = wpa_drv_tdls_oper(wpa_s, TDLS_DISCOVERY_REQ, peer);
  758. return ret;
  759. }
  760. static int wpa_supplicant_ctrl_iface_tdls_setup(
  761. struct wpa_supplicant *wpa_s, char *addr)
  762. {
  763. u8 peer[ETH_ALEN];
  764. int ret;
  765. if (hwaddr_aton(addr, peer)) {
  766. wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_SETUP: invalid "
  767. "address '%s'", addr);
  768. return -1;
  769. }
  770. wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_SETUP " MACSTR,
  771. MAC2STR(peer));
  772. if ((wpa_s->conf->tdls_external_control) &&
  773. wpa_tdls_is_external_setup(wpa_s->wpa))
  774. return wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, peer);
  775. wpa_tdls_remove(wpa_s->wpa, peer);
  776. if (wpa_tdls_is_external_setup(wpa_s->wpa))
  777. ret = wpa_tdls_start(wpa_s->wpa, peer);
  778. else
  779. ret = wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, peer);
  780. return ret;
  781. }
  782. static int wpa_supplicant_ctrl_iface_tdls_teardown(
  783. struct wpa_supplicant *wpa_s, char *addr)
  784. {
  785. u8 peer[ETH_ALEN];
  786. int ret;
  787. if (os_strcmp(addr, "*") == 0) {
  788. /* remove everyone */
  789. wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN *");
  790. wpa_tdls_teardown_peers(wpa_s->wpa);
  791. return 0;
  792. }
  793. if (hwaddr_aton(addr, peer)) {
  794. wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN: invalid "
  795. "address '%s'", addr);
  796. return -1;
  797. }
  798. wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN " MACSTR,
  799. MAC2STR(peer));
  800. if ((wpa_s->conf->tdls_external_control) &&
  801. wpa_tdls_is_external_setup(wpa_s->wpa))
  802. return wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN, peer);
  803. if (wpa_tdls_is_external_setup(wpa_s->wpa))
  804. ret = wpa_tdls_teardown_link(
  805. wpa_s->wpa, peer,
  806. WLAN_REASON_TDLS_TEARDOWN_UNSPECIFIED);
  807. else
  808. ret = wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN, peer);
  809. return ret;
  810. }
  811. static int ctrl_iface_get_capability_tdls(
  812. struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
  813. {
  814. int ret;
  815. ret = os_snprintf(buf, buflen, "%s\n",
  816. wpa_s->drv_flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT ?
  817. (wpa_s->drv_flags &
  818. WPA_DRIVER_FLAGS_TDLS_EXTERNAL_SETUP ?
  819. "EXTERNAL" : "INTERNAL") : "UNSUPPORTED");
  820. if (os_snprintf_error(buflen, ret))
  821. return -1;
  822. return ret;
  823. }
  824. static int wpa_supplicant_ctrl_iface_tdls_chan_switch(
  825. struct wpa_supplicant *wpa_s, char *cmd)
  826. {
  827. u8 peer[ETH_ALEN];
  828. struct hostapd_freq_params freq_params;
  829. u8 oper_class;
  830. char *pos, *end;
  831. if (!wpa_tdls_is_external_setup(wpa_s->wpa)) {
  832. wpa_printf(MSG_INFO,
  833. "tdls_chanswitch: Only supported with external setup");
  834. return -1;
  835. }
  836. os_memset(&freq_params, 0, sizeof(freq_params));
  837. pos = os_strchr(cmd, ' ');
  838. if (pos == NULL)
  839. return -1;
  840. *pos++ = '\0';
  841. oper_class = strtol(pos, &end, 10);
  842. if (pos == end) {
  843. wpa_printf(MSG_INFO,
  844. "tdls_chanswitch: Invalid op class provided");
  845. return -1;
  846. }
  847. pos = end;
  848. freq_params.freq = atoi(pos);
  849. if (freq_params.freq == 0) {
  850. wpa_printf(MSG_INFO, "tdls_chanswitch: Invalid freq provided");
  851. return -1;
  852. }
  853. #define SET_FREQ_SETTING(str) \
  854. do { \
  855. const char *pos2 = os_strstr(pos, " " #str "="); \
  856. if (pos2) { \
  857. pos2 += sizeof(" " #str "=") - 1; \
  858. freq_params.str = atoi(pos2); \
  859. } \
  860. } while (0)
  861. SET_FREQ_SETTING(center_freq1);
  862. SET_FREQ_SETTING(center_freq2);
  863. SET_FREQ_SETTING(bandwidth);
  864. SET_FREQ_SETTING(sec_channel_offset);
  865. #undef SET_FREQ_SETTING
  866. freq_params.ht_enabled = !!os_strstr(pos, " ht");
  867. freq_params.vht_enabled = !!os_strstr(pos, " vht");
  868. if (hwaddr_aton(cmd, peer)) {
  869. wpa_printf(MSG_DEBUG,
  870. "CTRL_IFACE TDLS_CHAN_SWITCH: Invalid address '%s'",
  871. cmd);
  872. return -1;
  873. }
  874. wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_CHAN_SWITCH " MACSTR
  875. " OP CLASS %d FREQ %d CENTER1 %d CENTER2 %d BW %d SEC_OFFSET %d%s%s",
  876. MAC2STR(peer), oper_class, freq_params.freq,
  877. freq_params.center_freq1, freq_params.center_freq2,
  878. freq_params.bandwidth, freq_params.sec_channel_offset,
  879. freq_params.ht_enabled ? " HT" : "",
  880. freq_params.vht_enabled ? " VHT" : "");
  881. return wpa_tdls_enable_chan_switch(wpa_s->wpa, peer, oper_class,
  882. &freq_params);
  883. }
  884. static int wpa_supplicant_ctrl_iface_tdls_cancel_chan_switch(
  885. struct wpa_supplicant *wpa_s, char *cmd)
  886. {
  887. u8 peer[ETH_ALEN];
  888. if (!wpa_tdls_is_external_setup(wpa_s->wpa)) {
  889. wpa_printf(MSG_INFO,
  890. "tdls_chanswitch: Only supported with external setup");
  891. return -1;
  892. }
  893. if (hwaddr_aton(cmd, peer)) {
  894. wpa_printf(MSG_DEBUG,
  895. "CTRL_IFACE TDLS_CANCEL_CHAN_SWITCH: Invalid address '%s'",
  896. cmd);
  897. return -1;
  898. }
  899. wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_CANCEL_CHAN_SWITCH " MACSTR,
  900. MAC2STR(peer));
  901. return wpa_tdls_disable_chan_switch(wpa_s->wpa, peer);
  902. }
  903. static int wpa_supplicant_ctrl_iface_tdls_link_status(
  904. struct wpa_supplicant *wpa_s, const char *addr,
  905. char *buf, size_t buflen)
  906. {
  907. u8 peer[ETH_ALEN];
  908. const char *tdls_status;
  909. int ret;
  910. if (hwaddr_aton(addr, peer)) {
  911. wpa_printf(MSG_DEBUG,
  912. "CTRL_IFACE TDLS_LINK_STATUS: Invalid address '%s'",
  913. addr);
  914. return -1;
  915. }
  916. wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_LINK_STATUS " MACSTR,
  917. MAC2STR(peer));
  918. tdls_status = wpa_tdls_get_link_status(wpa_s->wpa, peer);
  919. wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_LINK_STATUS: %s", tdls_status);
  920. ret = os_snprintf(buf, buflen, "TDLS link status: %s\n", tdls_status);
  921. if (os_snprintf_error(buflen, ret))
  922. return -1;
  923. return ret;
  924. }
  925. #endif /* CONFIG_TDLS */
  926. static int wmm_ac_ctrl_addts(struct wpa_supplicant *wpa_s, char *cmd)
  927. {
  928. char *token, *context = NULL;
  929. struct wmm_ac_ts_setup_params params = {
  930. .tsid = 0xff,
  931. .direction = 0xff,
  932. };
  933. while ((token = str_token(cmd, " ", &context))) {
  934. if (sscanf(token, "tsid=%i", &params.tsid) == 1 ||
  935. sscanf(token, "up=%i", &params.user_priority) == 1 ||
  936. sscanf(token, "nominal_msdu_size=%i",
  937. &params.nominal_msdu_size) == 1 ||
  938. sscanf(token, "mean_data_rate=%i",
  939. &params.mean_data_rate) == 1 ||
  940. sscanf(token, "min_phy_rate=%i",
  941. &params.minimum_phy_rate) == 1 ||
  942. sscanf(token, "sba=%i",
  943. &params.surplus_bandwidth_allowance) == 1)
  944. continue;
  945. if (os_strcasecmp(token, "downlink") == 0) {
  946. params.direction = WMM_TSPEC_DIRECTION_DOWNLINK;
  947. } else if (os_strcasecmp(token, "uplink") == 0) {
  948. params.direction = WMM_TSPEC_DIRECTION_UPLINK;
  949. } else if (os_strcasecmp(token, "bidi") == 0) {
  950. params.direction = WMM_TSPEC_DIRECTION_BI_DIRECTIONAL;
  951. } else if (os_strcasecmp(token, "fixed_nominal_msdu") == 0) {
  952. params.fixed_nominal_msdu = 1;
  953. } else {
  954. wpa_printf(MSG_DEBUG,
  955. "CTRL: Invalid WMM_AC_ADDTS parameter: '%s'",
  956. token);
  957. return -1;
  958. }
  959. }
  960. return wpas_wmm_ac_addts(wpa_s, &params);
  961. }
  962. static int wmm_ac_ctrl_delts(struct wpa_supplicant *wpa_s, char *cmd)
  963. {
  964. u8 tsid = atoi(cmd);
  965. return wpas_wmm_ac_delts(wpa_s, tsid);
  966. }
  967. #ifdef CONFIG_IEEE80211R
  968. static int wpa_supplicant_ctrl_iface_ft_ds(
  969. struct wpa_supplicant *wpa_s, char *addr)
  970. {
  971. u8 target_ap[ETH_ALEN];
  972. struct wpa_bss *bss;
  973. const u8 *mdie;
  974. if (hwaddr_aton(addr, target_ap)) {
  975. wpa_printf(MSG_DEBUG, "CTRL_IFACE FT_DS: invalid "
  976. "address '%s'", addr);
  977. return -1;
  978. }
  979. wpa_printf(MSG_DEBUG, "CTRL_IFACE FT_DS " MACSTR, MAC2STR(target_ap));
  980. bss = wpa_bss_get_bssid(wpa_s, target_ap);
  981. if (bss)
  982. mdie = wpa_bss_get_ie(bss, WLAN_EID_MOBILITY_DOMAIN);
  983. else
  984. mdie = NULL;
  985. return wpa_ft_start_over_ds(wpa_s->wpa, target_ap, mdie);
  986. }
  987. #endif /* CONFIG_IEEE80211R */
  988. #ifdef CONFIG_WPS
  989. static int wpa_supplicant_ctrl_iface_wps_pbc(struct wpa_supplicant *wpa_s,
  990. char *cmd)
  991. {
  992. u8 bssid[ETH_ALEN], *_bssid = bssid;
  993. #ifdef CONFIG_P2P
  994. u8 p2p_dev_addr[ETH_ALEN];
  995. #endif /* CONFIG_P2P */
  996. #ifdef CONFIG_AP
  997. u8 *_p2p_dev_addr = NULL;
  998. #endif /* CONFIG_AP */
  999. if (cmd == NULL || os_strcmp(cmd, "any") == 0) {
  1000. _bssid = NULL;
  1001. #ifdef CONFIG_P2P
  1002. } else if (os_strncmp(cmd, "p2p_dev_addr=", 13) == 0) {
  1003. if (hwaddr_aton(cmd + 13, p2p_dev_addr)) {
  1004. wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PBC: invalid "
  1005. "P2P Device Address '%s'",
  1006. cmd + 13);
  1007. return -1;
  1008. }
  1009. _p2p_dev_addr = p2p_dev_addr;
  1010. #endif /* CONFIG_P2P */
  1011. } else if (hwaddr_aton(cmd, bssid)) {
  1012. wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PBC: invalid BSSID '%s'",
  1013. cmd);
  1014. return -1;
  1015. }
  1016. #ifdef CONFIG_AP
  1017. if (wpa_s->ap_iface)
  1018. return wpa_supplicant_ap_wps_pbc(wpa_s, _bssid, _p2p_dev_addr);
  1019. #endif /* CONFIG_AP */
  1020. return wpas_wps_start_pbc(wpa_s, _bssid, 0);
  1021. }
  1022. static int wpa_supplicant_ctrl_iface_wps_pin(struct wpa_supplicant *wpa_s,
  1023. char *cmd, char *buf,
  1024. size_t buflen)
  1025. {
  1026. u8 bssid[ETH_ALEN], *_bssid = bssid;
  1027. char *pin;
  1028. int ret;
  1029. pin = os_strchr(cmd, ' ');
  1030. if (pin)
  1031. *pin++ = '\0';
  1032. if (os_strcmp(cmd, "any") == 0)
  1033. _bssid = NULL;
  1034. else if (os_strcmp(cmd, "get") == 0) {
  1035. if (wps_generate_pin((unsigned int *) &ret) < 0)
  1036. return -1;
  1037. goto done;
  1038. } else if (hwaddr_aton(cmd, bssid)) {
  1039. wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PIN: invalid BSSID '%s'",
  1040. cmd);
  1041. return -1;
  1042. }
  1043. #ifdef CONFIG_AP
  1044. if (wpa_s->ap_iface) {
  1045. int timeout = 0;
  1046. char *pos;
  1047. if (pin) {
  1048. pos = os_strchr(pin, ' ');
  1049. if (pos) {
  1050. *pos++ = '\0';
  1051. timeout = atoi(pos);
  1052. }
  1053. }
  1054. return wpa_supplicant_ap_wps_pin(wpa_s, _bssid, pin,
  1055. buf, buflen, timeout);
  1056. }
  1057. #endif /* CONFIG_AP */
  1058. if (pin) {
  1059. ret = wpas_wps_start_pin(wpa_s, _bssid, pin, 0,
  1060. DEV_PW_DEFAULT);
  1061. if (ret < 0)
  1062. return -1;
  1063. ret = os_snprintf(buf, buflen, "%s", pin);
  1064. if (os_snprintf_error(buflen, ret))
  1065. return -1;
  1066. return ret;
  1067. }
  1068. ret = wpas_wps_start_pin(wpa_s, _bssid, NULL, 0, DEV_PW_DEFAULT);
  1069. if (ret < 0)
  1070. return -1;
  1071. done:
  1072. /* Return the generated PIN */
  1073. ret = os_snprintf(buf, buflen, "%08d", ret);
  1074. if (os_snprintf_error(buflen, ret))
  1075. return -1;
  1076. return ret;
  1077. }
  1078. static int wpa_supplicant_ctrl_iface_wps_check_pin(
  1079. struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
  1080. {
  1081. char pin[9];
  1082. size_t len;
  1083. char *pos;
  1084. int ret;
  1085. wpa_hexdump_ascii_key(MSG_DEBUG, "WPS_CHECK_PIN",
  1086. (u8 *) cmd, os_strlen(cmd));
  1087. for (pos = cmd, len = 0; *pos != '\0'; pos++) {
  1088. if (*pos < '0' || *pos > '9')
  1089. continue;
  1090. pin[len++] = *pos;
  1091. if (len == 9) {
  1092. wpa_printf(MSG_DEBUG, "WPS: Too long PIN");
  1093. return -1;
  1094. }
  1095. }
  1096. if (len != 4 && len != 8) {
  1097. wpa_printf(MSG_DEBUG, "WPS: Invalid PIN length %d", (int) len);
  1098. return -1;
  1099. }
  1100. pin[len] = '\0';
  1101. if (len == 8) {
  1102. unsigned int pin_val;
  1103. pin_val = atoi(pin);
  1104. if (!wps_pin_valid(pin_val)) {
  1105. wpa_printf(MSG_DEBUG, "WPS: Invalid checksum digit");
  1106. ret = os_snprintf(buf, buflen, "FAIL-CHECKSUM\n");
  1107. if (os_snprintf_error(buflen, ret))
  1108. return -1;
  1109. return ret;
  1110. }
  1111. }
  1112. ret = os_snprintf(buf, buflen, "%s", pin);
  1113. if (os_snprintf_error(buflen, ret))
  1114. return -1;
  1115. return ret;
  1116. }
  1117. #ifdef CONFIG_WPS_NFC
  1118. static int wpa_supplicant_ctrl_iface_wps_nfc(struct wpa_supplicant *wpa_s,
  1119. char *cmd)
  1120. {
  1121. u8 bssid[ETH_ALEN], *_bssid = bssid;
  1122. if (cmd == NULL || cmd[0] == '\0')
  1123. _bssid = NULL;
  1124. else if (hwaddr_aton(cmd, bssid))
  1125. return -1;
  1126. return wpas_wps_start_nfc(wpa_s, NULL, _bssid, NULL, 0, 0, NULL, NULL,
  1127. 0, 0);
  1128. }
  1129. static int wpa_supplicant_ctrl_iface_wps_nfc_config_token(
  1130. struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
  1131. {
  1132. int ndef;
  1133. struct wpabuf *buf;
  1134. int res;
  1135. char *pos;
  1136. pos = os_strchr(cmd, ' ');
  1137. if (pos)
  1138. *pos++ = '\0';
  1139. if (os_strcmp(cmd, "WPS") == 0)
  1140. ndef = 0;
  1141. else if (os_strcmp(cmd, "NDEF") == 0)
  1142. ndef = 1;
  1143. else
  1144. return -1;
  1145. buf = wpas_wps_nfc_config_token(wpa_s, ndef, pos);
  1146. if (buf == NULL)
  1147. return -1;
  1148. res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
  1149. wpabuf_len(buf));
  1150. reply[res++] = '\n';
  1151. reply[res] = '\0';
  1152. wpabuf_free(buf);
  1153. return res;
  1154. }
  1155. static int wpa_supplicant_ctrl_iface_wps_nfc_token(
  1156. struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
  1157. {
  1158. int ndef;
  1159. struct wpabuf *buf;
  1160. int res;
  1161. if (os_strcmp(cmd, "WPS") == 0)
  1162. ndef = 0;
  1163. else if (os_strcmp(cmd, "NDEF") == 0)
  1164. ndef = 1;
  1165. else
  1166. return -1;
  1167. buf = wpas_wps_nfc_token(wpa_s, ndef);
  1168. if (buf == NULL)
  1169. return -1;
  1170. res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
  1171. wpabuf_len(buf));
  1172. reply[res++] = '\n';
  1173. reply[res] = '\0';
  1174. wpabuf_free(buf);
  1175. return res;
  1176. }
  1177. static int wpa_supplicant_ctrl_iface_wps_nfc_tag_read(
  1178. struct wpa_supplicant *wpa_s, char *pos)
  1179. {
  1180. size_t len;
  1181. struct wpabuf *buf;
  1182. int ret;
  1183. char *freq;
  1184. int forced_freq = 0;
  1185. freq = strstr(pos, " freq=");
  1186. if (freq) {
  1187. *freq = '\0';
  1188. freq += 6;
  1189. forced_freq = atoi(freq);
  1190. }
  1191. len = os_strlen(pos);
  1192. if (len & 0x01)
  1193. return -1;
  1194. len /= 2;
  1195. buf = wpabuf_alloc(len);
  1196. if (buf == NULL)
  1197. return -1;
  1198. if (hexstr2bin(pos, wpabuf_put(buf, len), len) < 0) {
  1199. wpabuf_free(buf);
  1200. return -1;
  1201. }
  1202. ret = wpas_wps_nfc_tag_read(wpa_s, buf, forced_freq);
  1203. wpabuf_free(buf);
  1204. return ret;
  1205. }
  1206. static int wpas_ctrl_nfc_get_handover_req_wps(struct wpa_supplicant *wpa_s,
  1207. char *reply, size_t max_len,
  1208. int ndef)
  1209. {
  1210. struct wpabuf *buf;
  1211. int res;
  1212. buf = wpas_wps_nfc_handover_req(wpa_s, ndef);
  1213. if (buf == NULL)
  1214. return -1;
  1215. res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
  1216. wpabuf_len(buf));
  1217. reply[res++] = '\n';
  1218. reply[res] = '\0';
  1219. wpabuf_free(buf);
  1220. return res;
  1221. }
  1222. #ifdef CONFIG_P2P
  1223. static int wpas_ctrl_nfc_get_handover_req_p2p(struct wpa_supplicant *wpa_s,
  1224. char *reply, size_t max_len,
  1225. int ndef)
  1226. {
  1227. struct wpabuf *buf;
  1228. int res;
  1229. buf = wpas_p2p_nfc_handover_req(wpa_s, ndef);
  1230. if (buf == NULL) {
  1231. wpa_printf(MSG_DEBUG, "P2P: Could not generate NFC handover request");
  1232. return -1;
  1233. }
  1234. res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
  1235. wpabuf_len(buf));
  1236. reply[res++] = '\n';
  1237. reply[res] = '\0';
  1238. wpabuf_free(buf);
  1239. return res;
  1240. }
  1241. #endif /* CONFIG_P2P */
  1242. static int wpas_ctrl_nfc_get_handover_req(struct wpa_supplicant *wpa_s,
  1243. char *cmd, char *reply,
  1244. size_t max_len)
  1245. {
  1246. char *pos;
  1247. int ndef;
  1248. pos = os_strchr(cmd, ' ');
  1249. if (pos == NULL)
  1250. return -1;
  1251. *pos++ = '\0';
  1252. if (os_strcmp(cmd, "WPS") == 0)
  1253. ndef = 0;
  1254. else if (os_strcmp(cmd, "NDEF") == 0)
  1255. ndef = 1;
  1256. else
  1257. return -1;
  1258. if (os_strcmp(pos, "WPS") == 0 || os_strcmp(pos, "WPS-CR") == 0) {
  1259. if (!ndef)
  1260. return -1;
  1261. return wpas_ctrl_nfc_get_handover_req_wps(
  1262. wpa_s, reply, max_len, ndef);
  1263. }
  1264. #ifdef CONFIG_P2P
  1265. if (os_strcmp(pos, "P2P-CR") == 0) {
  1266. return wpas_ctrl_nfc_get_handover_req_p2p(
  1267. wpa_s, reply, max_len, ndef);
  1268. }
  1269. #endif /* CONFIG_P2P */
  1270. return -1;
  1271. }
  1272. static int wpas_ctrl_nfc_get_handover_sel_wps(struct wpa_supplicant *wpa_s,
  1273. char *reply, size_t max_len,
  1274. int ndef, int cr, char *uuid)
  1275. {
  1276. struct wpabuf *buf;
  1277. int res;
  1278. buf = wpas_wps_nfc_handover_sel(wpa_s, ndef, cr, uuid);
  1279. if (buf == NULL)
  1280. return -1;
  1281. res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
  1282. wpabuf_len(buf));
  1283. reply[res++] = '\n';
  1284. reply[res] = '\0';
  1285. wpabuf_free(buf);
  1286. return res;
  1287. }
  1288. #ifdef CONFIG_P2P
  1289. static int wpas_ctrl_nfc_get_handover_sel_p2p(struct wpa_supplicant *wpa_s,
  1290. char *reply, size_t max_len,
  1291. int ndef, int tag)
  1292. {
  1293. struct wpabuf *buf;
  1294. int res;
  1295. buf = wpas_p2p_nfc_handover_sel(wpa_s, ndef, tag);
  1296. if (buf == NULL)
  1297. return -1;
  1298. res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
  1299. wpabuf_len(buf));
  1300. reply[res++] = '\n';
  1301. reply[res] = '\0';
  1302. wpabuf_free(buf);
  1303. return res;
  1304. }
  1305. #endif /* CONFIG_P2P */
  1306. static int wpas_ctrl_nfc_get_handover_sel(struct wpa_supplicant *wpa_s,
  1307. char *cmd, char *reply,
  1308. size_t max_len)
  1309. {
  1310. char *pos, *pos2;
  1311. int ndef;
  1312. pos = os_strchr(cmd, ' ');
  1313. if (pos == NULL)
  1314. return -1;
  1315. *pos++ = '\0';
  1316. if (os_strcmp(cmd, "WPS") == 0)
  1317. ndef = 0;
  1318. else if (os_strcmp(cmd, "NDEF") == 0)
  1319. ndef = 1;
  1320. else
  1321. return -1;
  1322. pos2 = os_strchr(pos, ' ');
  1323. if (pos2)
  1324. *pos2++ = '\0';
  1325. if (os_strcmp(pos, "WPS") == 0 || os_strcmp(pos, "WPS-CR") == 0) {
  1326. if (!ndef)
  1327. return -1;
  1328. return wpas_ctrl_nfc_get_handover_sel_wps(
  1329. wpa_s, reply, max_len, ndef,
  1330. os_strcmp(pos, "WPS-CR") == 0, pos2);
  1331. }
  1332. #ifdef CONFIG_P2P
  1333. if (os_strcmp(pos, "P2P-CR") == 0) {
  1334. return wpas_ctrl_nfc_get_handover_sel_p2p(
  1335. wpa_s, reply, max_len, ndef, 0);
  1336. }
  1337. if (os_strcmp(pos, "P2P-CR-TAG") == 0) {
  1338. return wpas_ctrl_nfc_get_handover_sel_p2p(
  1339. wpa_s, reply, max_len, ndef, 1);
  1340. }
  1341. #endif /* CONFIG_P2P */
  1342. return -1;
  1343. }
  1344. static int wpas_ctrl_nfc_report_handover(struct wpa_supplicant *wpa_s,
  1345. char *cmd)
  1346. {
  1347. size_t len;
  1348. struct wpabuf *req, *sel;
  1349. int ret;
  1350. char *pos, *role, *type, *pos2;
  1351. #ifdef CONFIG_P2P
  1352. char *freq;
  1353. int forced_freq = 0;
  1354. freq = strstr(cmd, " freq=");
  1355. if (freq) {
  1356. *freq = '\0';
  1357. freq += 6;
  1358. forced_freq = atoi(freq);
  1359. }
  1360. #endif /* CONFIG_P2P */
  1361. role = cmd;
  1362. pos = os_strchr(role, ' ');
  1363. if (pos == NULL) {
  1364. wpa_printf(MSG_DEBUG, "NFC: Missing type in handover report");
  1365. return -1;
  1366. }
  1367. *pos++ = '\0';
  1368. type = pos;
  1369. pos = os_strchr(type, ' ');
  1370. if (pos == NULL) {
  1371. wpa_printf(MSG_DEBUG, "NFC: Missing request message in handover report");
  1372. return -1;
  1373. }
  1374. *pos++ = '\0';
  1375. pos2 = os_strchr(pos, ' ');
  1376. if (pos2 == NULL) {
  1377. wpa_printf(MSG_DEBUG, "NFC: Missing select message in handover report");
  1378. return -1;
  1379. }
  1380. *pos2++ = '\0';
  1381. len = os_strlen(pos);
  1382. if (len & 0x01) {
  1383. wpa_printf(MSG_DEBUG, "NFC: Invalid request message length in handover report");
  1384. return -1;
  1385. }
  1386. len /= 2;
  1387. req = wpabuf_alloc(len);
  1388. if (req == NULL) {
  1389. wpa_printf(MSG_DEBUG, "NFC: Failed to allocate memory for request message");
  1390. return -1;
  1391. }
  1392. if (hexstr2bin(pos, wpabuf_put(req, len), len) < 0) {
  1393. wpa_printf(MSG_DEBUG, "NFC: Invalid request message hexdump in handover report");
  1394. wpabuf_free(req);
  1395. return -1;
  1396. }
  1397. len = os_strlen(pos2);
  1398. if (len & 0x01) {
  1399. wpa_printf(MSG_DEBUG, "NFC: Invalid select message length in handover report");
  1400. wpabuf_free(req);
  1401. return -1;
  1402. }
  1403. len /= 2;
  1404. sel = wpabuf_alloc(len);
  1405. if (sel == NULL) {
  1406. wpa_printf(MSG_DEBUG, "NFC: Failed to allocate memory for select message");
  1407. wpabuf_free(req);
  1408. return -1;
  1409. }
  1410. if (hexstr2bin(pos2, wpabuf_put(sel, len), len) < 0) {
  1411. wpa_printf(MSG_DEBUG, "NFC: Invalid select message hexdump in handover report");
  1412. wpabuf_free(req);
  1413. wpabuf_free(sel);
  1414. return -1;
  1415. }
  1416. wpa_printf(MSG_DEBUG, "NFC: Connection handover reported - role=%s type=%s req_len=%d sel_len=%d",
  1417. role, type, (int) wpabuf_len(req), (int) wpabuf_len(sel));
  1418. if (os_strcmp(role, "INIT") == 0 && os_strcmp(type, "WPS") == 0) {
  1419. ret = wpas_wps_nfc_report_handover(wpa_s, req, sel);
  1420. #ifdef CONFIG_AP
  1421. } else if (os_strcmp(role, "RESP") == 0 && os_strcmp(type, "WPS") == 0)
  1422. {
  1423. ret = wpas_ap_wps_nfc_report_handover(wpa_s, req, sel);
  1424. if (ret < 0)
  1425. ret = wpas_er_wps_nfc_report_handover(wpa_s, req, sel);
  1426. #endif /* CONFIG_AP */
  1427. #ifdef CONFIG_P2P
  1428. } else if (os_strcmp(role, "INIT") == 0 && os_strcmp(type, "P2P") == 0)
  1429. {
  1430. ret = wpas_p2p_nfc_report_handover(wpa_s, 1, req, sel, 0);
  1431. } else if (os_strcmp(role, "RESP") == 0 && os_strcmp(type, "P2P") == 0)
  1432. {
  1433. ret = wpas_p2p_nfc_report_handover(wpa_s, 0, req, sel,
  1434. forced_freq);
  1435. #endif /* CONFIG_P2P */
  1436. } else {
  1437. wpa_printf(MSG_DEBUG, "NFC: Unsupported connection handover "
  1438. "reported: role=%s type=%s", role, type);
  1439. ret = -1;
  1440. }
  1441. wpabuf_free(req);
  1442. wpabuf_free(sel);
  1443. if (ret)
  1444. wpa_printf(MSG_DEBUG, "NFC: Failed to process reported handover messages");
  1445. return ret;
  1446. }
  1447. #endif /* CONFIG_WPS_NFC */
  1448. static int wpa_supplicant_ctrl_iface_wps_reg(struct wpa_supplicant *wpa_s,
  1449. char *cmd)
  1450. {
  1451. u8 bssid[ETH_ALEN];
  1452. char *pin;
  1453. char *new_ssid;
  1454. char *new_auth;
  1455. char *new_encr;
  1456. char *new_key;
  1457. struct wps_new_ap_settings ap;
  1458. pin = os_strchr(cmd, ' ');
  1459. if (pin == NULL)
  1460. return -1;
  1461. *pin++ = '\0';
  1462. if (hwaddr_aton(cmd, bssid)) {
  1463. wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_REG: invalid BSSID '%s'",
  1464. cmd);
  1465. return -1;
  1466. }
  1467. new_ssid = os_strchr(pin, ' ');
  1468. if (new_ssid == NULL)
  1469. return wpas_wps_start_reg(wpa_s, bssid, pin, NULL);
  1470. *new_ssid++ = '\0';
  1471. new_auth = os_strchr(new_ssid, ' ');
  1472. if (new_auth == NULL)
  1473. return -1;
  1474. *new_auth++ = '\0';
  1475. new_encr = os_strchr(new_auth, ' ');
  1476. if (new_encr == NULL)
  1477. return -1;
  1478. *new_encr++ = '\0';
  1479. new_key = os_strchr(new_encr, ' ');
  1480. if (new_key == NULL)
  1481. return -1;
  1482. *new_key++ = '\0';
  1483. os_memset(&ap, 0, sizeof(ap));
  1484. ap.ssid_hex = new_ssid;
  1485. ap.auth = new_auth;
  1486. ap.encr = new_encr;
  1487. ap.key_hex = new_key;
  1488. return wpas_wps_start_reg(wpa_s, bssid, pin, &ap);
  1489. }
  1490. #ifdef CONFIG_AP
  1491. static int wpa_supplicant_ctrl_iface_wps_ap_pin(struct wpa_supplicant *wpa_s,
  1492. char *cmd, char *buf,
  1493. size_t buflen)
  1494. {
  1495. int timeout = 300;
  1496. char *pos;
  1497. const char *pin_txt;
  1498. if (!wpa_s->ap_iface)
  1499. return -1;
  1500. pos = os_strchr(cmd, ' ');
  1501. if (pos)
  1502. *pos++ = '\0';
  1503. if (os_strcmp(cmd, "disable") == 0) {
  1504. wpas_wps_ap_pin_disable(wpa_s);
  1505. return os_snprintf(buf, buflen, "OK\n");
  1506. }
  1507. if (os_strcmp(cmd, "random") == 0) {
  1508. if (pos)
  1509. timeout = atoi(pos);
  1510. pin_txt = wpas_wps_ap_pin_random(wpa_s, timeout);
  1511. if (pin_txt == NULL)
  1512. return -1;
  1513. return os_snprintf(buf, buflen, "%s", pin_txt);
  1514. }
  1515. if (os_strcmp(cmd, "get") == 0) {
  1516. pin_txt = wpas_wps_ap_pin_get(wpa_s);
  1517. if (pin_txt == NULL)
  1518. return -1;
  1519. return os_snprintf(buf, buflen, "%s", pin_txt);
  1520. }
  1521. if (os_strcmp(cmd, "set") == 0) {
  1522. char *pin;
  1523. if (pos == NULL)
  1524. return -1;
  1525. pin = pos;
  1526. pos = os_strchr(pos, ' ');
  1527. if (pos) {
  1528. *pos++ = '\0';
  1529. timeout = atoi(pos);
  1530. }
  1531. if (os_strlen(pin) > buflen)
  1532. return -1;
  1533. if (wpas_wps_ap_pin_set(wpa_s, pin, timeout) < 0)
  1534. return -1;
  1535. return os_snprintf(buf, buflen, "%s", pin);
  1536. }
  1537. return -1;
  1538. }
  1539. #endif /* CONFIG_AP */
  1540. #ifdef CONFIG_WPS_ER
  1541. static int wpa_supplicant_ctrl_iface_wps_er_pin(struct wpa_supplicant *wpa_s,
  1542. char *cmd)
  1543. {
  1544. char *uuid = cmd, *pin, *pos;
  1545. u8 addr_buf[ETH_ALEN], *addr = NULL;
  1546. pin = os_strchr(uuid, ' ');
  1547. if (pin == NULL)
  1548. return -1;
  1549. *pin++ = '\0';
  1550. pos = os_strchr(pin, ' ');
  1551. if (pos) {
  1552. *pos++ = '\0';
  1553. if (hwaddr_aton(pos, addr_buf) == 0)
  1554. addr = addr_buf;
  1555. }
  1556. return wpas_wps_er_add_pin(wpa_s, addr, uuid, pin);
  1557. }
  1558. static int wpa_supplicant_ctrl_iface_wps_er_learn(struct wpa_supplicant *wpa_s,
  1559. char *cmd)
  1560. {
  1561. char *uuid = cmd, *pin;
  1562. pin = os_strchr(uuid, ' ');
  1563. if (pin == NULL)
  1564. return -1;
  1565. *pin++ = '\0';
  1566. return wpas_wps_er_learn(wpa_s, uuid, pin);
  1567. }
  1568. static int wpa_supplicant_ctrl_iface_wps_er_set_config(
  1569. struct wpa_supplicant *wpa_s, char *cmd)
  1570. {
  1571. char *uuid = cmd, *id;
  1572. id = os_strchr(uuid, ' ');
  1573. if (id == NULL)
  1574. return -1;
  1575. *id++ = '\0';
  1576. return wpas_wps_er_set_config(wpa_s, uuid, atoi(id));
  1577. }
  1578. static int wpa_supplicant_ctrl_iface_wps_er_config(
  1579. struct wpa_supplicant *wpa_s, char *cmd)
  1580. {
  1581. char *pin;
  1582. char *new_ssid;
  1583. char *new_auth;
  1584. char *new_encr;
  1585. char *new_key;
  1586. struct wps_new_ap_settings ap;
  1587. pin = os_strchr(cmd, ' ');
  1588. if (pin == NULL)
  1589. return -1;
  1590. *pin++ = '\0';
  1591. new_ssid = os_strchr(pin, ' ');
  1592. if (new_ssid == NULL)
  1593. return -1;
  1594. *new_ssid++ = '\0';
  1595. new_auth = os_strchr(new_ssid, ' ');
  1596. if (new_auth == NULL)
  1597. return -1;
  1598. *new_auth++ = '\0';
  1599. new_encr = os_strchr(new_auth, ' ');
  1600. if (new_encr == NULL)
  1601. return -1;
  1602. *new_encr++ = '\0';
  1603. new_key = os_strchr(new_encr, ' ');
  1604. if (new_key == NULL)
  1605. return -1;
  1606. *new_key++ = '\0';
  1607. os_memset(&ap, 0, sizeof(ap));
  1608. ap.ssid_hex = new_ssid;
  1609. ap.auth = new_auth;
  1610. ap.encr = new_encr;
  1611. ap.key_hex = new_key;
  1612. return wpas_wps_er_config(wpa_s, cmd, pin, &ap);
  1613. }
  1614. #ifdef CONFIG_WPS_NFC
  1615. static int wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
  1616. struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
  1617. {
  1618. int ndef;
  1619. struct wpabuf *buf;
  1620. int res;
  1621. char *uuid;
  1622. uuid = os_strchr(cmd, ' ');
  1623. if (uuid == NULL)
  1624. return -1;
  1625. *uuid++ = '\0';
  1626. if (os_strcmp(cmd, "WPS") == 0)
  1627. ndef = 0;
  1628. else if (os_strcmp(cmd, "NDEF") == 0)
  1629. ndef = 1;
  1630. else
  1631. return -1;
  1632. buf = wpas_wps_er_nfc_config_token(wpa_s, ndef, uuid);
  1633. if (buf == NULL)
  1634. return -1;
  1635. res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
  1636. wpabuf_len(buf));
  1637. reply[res++] = '\n';
  1638. reply[res] = '\0';
  1639. wpabuf_free(buf);
  1640. return res;
  1641. }
  1642. #endif /* CONFIG_WPS_NFC */
  1643. #endif /* CONFIG_WPS_ER */
  1644. #endif /* CONFIG_WPS */
  1645. #ifdef CONFIG_IBSS_RSN
  1646. static int wpa_supplicant_ctrl_iface_ibss_rsn(
  1647. struct wpa_supplicant *wpa_s, char *addr)
  1648. {
  1649. u8 peer[ETH_ALEN];
  1650. if (hwaddr_aton(addr, peer)) {
  1651. wpa_printf(MSG_DEBUG, "CTRL_IFACE IBSS_RSN: invalid "
  1652. "address '%s'", addr);
  1653. return -1;
  1654. }
  1655. wpa_printf(MSG_DEBUG, "CTRL_IFACE IBSS_RSN " MACSTR,
  1656. MAC2STR(peer));
  1657. return ibss_rsn_start(wpa_s->ibss_rsn, peer);
  1658. }
  1659. #endif /* CONFIG_IBSS_RSN */
  1660. static int wpa_supplicant_ctrl_iface_ctrl_rsp(struct wpa_supplicant *wpa_s,
  1661. char *rsp)
  1662. {
  1663. #ifdef IEEE8021X_EAPOL
  1664. char *pos, *id_pos;
  1665. int id;
  1666. struct wpa_ssid *ssid;
  1667. pos = os_strchr(rsp, '-');
  1668. if (pos == NULL)
  1669. return -1;
  1670. *pos++ = '\0';
  1671. id_pos = pos;
  1672. pos = os_strchr(pos, ':');
  1673. if (pos == NULL)
  1674. return -1;
  1675. *pos++ = '\0';
  1676. id = atoi(id_pos);
  1677. wpa_printf(MSG_DEBUG, "CTRL_IFACE: field=%s id=%d", rsp, id);
  1678. wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
  1679. (u8 *) pos, os_strlen(pos));
  1680. ssid = wpa_config_get_network(wpa_s->conf, id);
  1681. if (ssid == NULL) {
  1682. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
  1683. "to update", id);
  1684. return -1;
  1685. }
  1686. return wpa_supplicant_ctrl_iface_ctrl_rsp_handle(wpa_s, ssid, rsp,
  1687. pos);
  1688. #else /* IEEE8021X_EAPOL */
  1689. wpa_printf(MSG_DEBUG, "CTRL_IFACE: 802.1X not included");
  1690. return -1;
  1691. #endif /* IEEE8021X_EAPOL */
  1692. }
  1693. static int wpa_supplicant_ctrl_iface_status(struct wpa_supplicant *wpa_s,
  1694. const char *params,
  1695. char *buf, size_t buflen)
  1696. {
  1697. char *pos, *end, tmp[30];
  1698. int res, verbose, wps, ret;
  1699. #ifdef CONFIG_HS20
  1700. const u8 *hs20;
  1701. #endif /* CONFIG_HS20 */
  1702. const u8 *sess_id;
  1703. size_t sess_id_len;
  1704. if (os_strcmp(params, "-DRIVER") == 0)
  1705. return wpa_drv_status(wpa_s, buf, buflen);
  1706. verbose = os_strcmp(params, "-VERBOSE") == 0;
  1707. wps = os_strcmp(params, "-WPS") == 0;
  1708. pos = buf;
  1709. end = buf + buflen;
  1710. if (wpa_s->wpa_state >= WPA_ASSOCIATED) {
  1711. struct wpa_ssid *ssid = wpa_s->current_ssid;
  1712. ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n",
  1713. MAC2STR(wpa_s->bssid));
  1714. if (os_snprintf_error(end - pos, ret))
  1715. return pos - buf;
  1716. pos += ret;
  1717. ret = os_snprintf(pos, end - pos, "freq=%u\n",
  1718. wpa_s->assoc_freq);
  1719. if (os_snprintf_error(end - pos, ret))
  1720. return pos - buf;
  1721. pos += ret;
  1722. if (ssid) {
  1723. u8 *_ssid = ssid->ssid;
  1724. size_t ssid_len = ssid->ssid_len;
  1725. u8 ssid_buf[SSID_MAX_LEN];
  1726. if (ssid_len == 0) {
  1727. int _res = wpa_drv_get_ssid(wpa_s, ssid_buf);
  1728. if (_res < 0)
  1729. ssid_len = 0;
  1730. else
  1731. ssid_len = _res;
  1732. _ssid = ssid_buf;
  1733. }
  1734. ret = os_snprintf(pos, end - pos, "ssid=%s\nid=%d\n",
  1735. wpa_ssid_txt(_ssid, ssid_len),
  1736. ssid->id);
  1737. if (os_snprintf_error(end - pos, ret))
  1738. return pos - buf;
  1739. pos += ret;
  1740. if (wps && ssid->passphrase &&
  1741. wpa_key_mgmt_wpa_psk(ssid->key_mgmt) &&
  1742. (ssid->mode == WPAS_MODE_AP ||
  1743. ssid->mode == WPAS_MODE_P2P_GO)) {
  1744. ret = os_snprintf(pos, end - pos,
  1745. "passphrase=%s\n",
  1746. ssid->passphrase);
  1747. if (os_snprintf_error(end - pos, ret))
  1748. return pos - buf;
  1749. pos += ret;
  1750. }
  1751. if (ssid->id_str) {
  1752. ret = os_snprintf(pos, end - pos,
  1753. "id_str=%s\n",
  1754. ssid->id_str);
  1755. if (os_snprintf_error(end - pos, ret))
  1756. return pos - buf;
  1757. pos += ret;
  1758. }
  1759. switch (ssid->mode) {
  1760. case WPAS_MODE_INFRA:
  1761. ret = os_snprintf(pos, end - pos,
  1762. "mode=station\n");
  1763. break;
  1764. case WPAS_MODE_IBSS:
  1765. ret = os_snprintf(pos, end - pos,
  1766. "mode=IBSS\n");
  1767. break;
  1768. case WPAS_MODE_AP:
  1769. ret = os_snprintf(pos, end - pos,
  1770. "mode=AP\n");
  1771. break;
  1772. case WPAS_MODE_P2P_GO:
  1773. ret = os_snprintf(pos, end - pos,
  1774. "mode=P2P GO\n");
  1775. break;
  1776. case WPAS_MODE_P2P_GROUP_FORMATION:
  1777. ret = os_snprintf(pos, end - pos,
  1778. "mode=P2P GO - group "
  1779. "formation\n");
  1780. break;
  1781. case WPAS_MODE_MESH:
  1782. ret = os_snprintf(pos, end - pos,
  1783. "mode=mesh\n");
  1784. break;
  1785. default:
  1786. ret = 0;
  1787. break;
  1788. }
  1789. if (os_snprintf_error(end - pos, ret))
  1790. return pos - buf;
  1791. pos += ret;
  1792. }
  1793. #ifdef CONFIG_AP
  1794. if (wpa_s->ap_iface) {
  1795. pos += ap_ctrl_iface_wpa_get_status(wpa_s, pos,
  1796. end - pos,
  1797. verbose);
  1798. } else
  1799. #endif /* CONFIG_AP */
  1800. pos += wpa_sm_get_status(wpa_s->wpa, pos, end - pos, verbose);
  1801. }
  1802. #ifdef CONFIG_SME
  1803. #ifdef CONFIG_SAE
  1804. if (wpa_s->wpa_state >= WPA_ASSOCIATED &&
  1805. #ifdef CONFIG_AP
  1806. !wpa_s->ap_iface &&
  1807. #endif /* CONFIG_AP */
  1808. wpa_s->sme.sae.state == SAE_ACCEPTED) {
  1809. ret = os_snprintf(pos, end - pos, "sae_group=%d\n",
  1810. wpa_s->sme.sae.group);
  1811. if (os_snprintf_error(end - pos, ret))
  1812. return pos - buf;
  1813. pos += ret;
  1814. }
  1815. #endif /* CONFIG_SAE */
  1816. #endif /* CONFIG_SME */
  1817. ret = os_snprintf(pos, end - pos, "wpa_state=%s\n",
  1818. wpa_supplicant_state_txt(wpa_s->wpa_state));
  1819. if (os_snprintf_error(end - pos, ret))
  1820. return pos - buf;
  1821. pos += ret;
  1822. if (wpa_s->l2 &&
  1823. l2_packet_get_ip_addr(wpa_s->l2, tmp, sizeof(tmp)) >= 0) {
  1824. ret = os_snprintf(pos, end - pos, "ip_address=%s\n", tmp);
  1825. if (os_snprintf_error(end - pos, ret))
  1826. return pos - buf;
  1827. pos += ret;
  1828. }
  1829. #ifdef CONFIG_P2P
  1830. if (wpa_s->global->p2p) {
  1831. ret = os_snprintf(pos, end - pos, "p2p_device_address=" MACSTR
  1832. "\n", MAC2STR(wpa_s->global->p2p_dev_addr));
  1833. if (os_snprintf_error(end - pos, ret))
  1834. return pos - buf;
  1835. pos += ret;
  1836. }
  1837. #endif /* CONFIG_P2P */
  1838. ret = os_snprintf(pos, end - pos, "address=" MACSTR "\n",
  1839. MAC2STR(wpa_s->own_addr));
  1840. if (os_snprintf_error(end - pos, ret))
  1841. return pos - buf;
  1842. pos += ret;
  1843. #ifdef CONFIG_HS20
  1844. if (wpa_s->current_bss &&
  1845. (hs20 = wpa_bss_get_vendor_ie(wpa_s->current_bss,
  1846. HS20_IE_VENDOR_TYPE)) &&
  1847. wpa_s->wpa_proto == WPA_PROTO_RSN &&
  1848. wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
  1849. int release = 1;
  1850. if (hs20[1] >= 5) {
  1851. u8 rel_num = (hs20[6] & 0xf0) >> 4;
  1852. release = rel_num + 1;
  1853. }
  1854. ret = os_snprintf(pos, end - pos, "hs20=%d\n", release);
  1855. if (os_snprintf_error(end - pos, ret))
  1856. return pos - buf;
  1857. pos += ret;
  1858. }
  1859. if (wpa_s->current_ssid) {
  1860. struct wpa_cred *cred;
  1861. char *type;
  1862. for (cred = wpa_s->conf->cred; cred; cred = cred->next) {
  1863. size_t i;
  1864. if (wpa_s->current_ssid->parent_cred != cred)
  1865. continue;
  1866. if (cred->provisioning_sp) {
  1867. ret = os_snprintf(pos, end - pos,
  1868. "provisioning_sp=%s\n",
  1869. cred->provisioning_sp);
  1870. if (os_snprintf_error(end - pos, ret))
  1871. return pos - buf;
  1872. pos += ret;
  1873. }
  1874. if (!cred->domain)
  1875. goto no_domain;
  1876. i = 0;
  1877. if (wpa_s->current_bss && wpa_s->current_bss->anqp) {
  1878. struct wpabuf *names =
  1879. wpa_s->current_bss->anqp->domain_name;
  1880. for (i = 0; names && i < cred->num_domain; i++)
  1881. {
  1882. if (domain_name_list_contains(
  1883. names, cred->domain[i], 1))
  1884. break;
  1885. }
  1886. if (i == cred->num_domain)
  1887. i = 0; /* show first entry by default */
  1888. }
  1889. ret = os_snprintf(pos, end - pos, "home_sp=%s\n",
  1890. cred->domain[i]);
  1891. if (os_snprintf_error(end - pos, ret))
  1892. return pos - buf;
  1893. pos += ret;
  1894. no_domain:
  1895. if (wpa_s->current_bss == NULL ||
  1896. wpa_s->current_bss->anqp == NULL)
  1897. res = -1;
  1898. else
  1899. res = interworking_home_sp_cred(
  1900. wpa_s, cred,
  1901. wpa_s->current_bss->anqp->domain_name);
  1902. if (res > 0)
  1903. type = "home";
  1904. else if (res == 0)
  1905. type = "roaming";
  1906. else
  1907. type = "unknown";
  1908. ret = os_snprintf(pos, end - pos, "sp_type=%s\n", type);
  1909. if (os_snprintf_error(end - pos, ret))
  1910. return pos - buf;
  1911. pos += ret;
  1912. break;
  1913. }
  1914. }
  1915. #endif /* CONFIG_HS20 */
  1916. if (wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
  1917. wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) {
  1918. res = eapol_sm_get_status(wpa_s->eapol, pos, end - pos,
  1919. verbose);
  1920. if (res >= 0)
  1921. pos += res;
  1922. }
  1923. #ifdef CONFIG_MACSEC
  1924. res = ieee802_1x_kay_get_status(wpa_s->kay, pos, end - pos);
  1925. if (res > 0)
  1926. pos += res;
  1927. #endif /* CONFIG_MACSEC */
  1928. sess_id = eapol_sm_get_session_id(wpa_s->eapol, &sess_id_len);
  1929. if (sess_id) {
  1930. char *start = pos;
  1931. ret = os_snprintf(pos, end - pos, "eap_session_id=");
  1932. if (os_snprintf_error(end - pos, ret))
  1933. return start - buf;
  1934. pos += ret;
  1935. ret = wpa_snprintf_hex(pos, end - pos, sess_id, sess_id_len);
  1936. if (ret <= 0)
  1937. return start - buf;
  1938. pos += ret;
  1939. ret = os_snprintf(pos, end - pos, "\n");
  1940. if (os_snprintf_error(end - pos, ret))
  1941. return start - buf;
  1942. pos += ret;
  1943. }
  1944. res = rsn_preauth_get_status(wpa_s->wpa, pos, end - pos, verbose);
  1945. if (res >= 0)
  1946. pos += res;
  1947. #ifdef CONFIG_WPS
  1948. {
  1949. char uuid_str[100];
  1950. uuid_bin2str(wpa_s->wps->uuid, uuid_str, sizeof(uuid_str));
  1951. ret = os_snprintf(pos, end - pos, "uuid=%s\n", uuid_str);
  1952. if (os_snprintf_error(end - pos, ret))
  1953. return pos - buf;
  1954. pos += ret;
  1955. }
  1956. #endif /* CONFIG_WPS */
  1957. #ifdef ANDROID
  1958. /*
  1959. * Allow using the STATUS command with default behavior, say for debug,
  1960. * i.e., don't generate a "fake" CONNECTION and SUPPLICANT_STATE_CHANGE
  1961. * events with STATUS-NO_EVENTS.
  1962. */
  1963. if (os_strcmp(params, "-NO_EVENTS")) {
  1964. wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_STATE_CHANGE
  1965. "id=%d state=%d BSSID=" MACSTR " SSID=%s",
  1966. wpa_s->current_ssid ? wpa_s->current_ssid->id : -1,
  1967. wpa_s->wpa_state,
  1968. MAC2STR(wpa_s->bssid),
  1969. wpa_s->current_ssid && wpa_s->current_ssid->ssid ?
  1970. wpa_ssid_txt(wpa_s->current_ssid->ssid,
  1971. wpa_s->current_ssid->ssid_len) : "");
  1972. if (wpa_s->wpa_state == WPA_COMPLETED) {
  1973. struct wpa_ssid *ssid = wpa_s->current_ssid;
  1974. wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_CONNECTED
  1975. "- connection to " MACSTR
  1976. " completed %s [id=%d id_str=%s]",
  1977. MAC2STR(wpa_s->bssid), "(auth)",
  1978. ssid ? ssid->id : -1,
  1979. ssid && ssid->id_str ? ssid->id_str : "");
  1980. }
  1981. }
  1982. #endif /* ANDROID */
  1983. return pos - buf;
  1984. }
  1985. static int wpa_supplicant_ctrl_iface_bssid(struct wpa_supplicant *wpa_s,
  1986. char *cmd)
  1987. {
  1988. char *pos;
  1989. int id;
  1990. struct wpa_ssid *ssid;
  1991. u8 bssid[ETH_ALEN];
  1992. /* cmd: "<network id> <BSSID>" */
  1993. pos = os_strchr(cmd, ' ');
  1994. if (pos == NULL)
  1995. return -1;
  1996. *pos++ = '\0';
  1997. id = atoi(cmd);
  1998. wpa_printf(MSG_DEBUG, "CTRL_IFACE: id=%d bssid='%s'", id, pos);
  1999. if (hwaddr_aton(pos, bssid)) {
  2000. wpa_printf(MSG_DEBUG ,"CTRL_IFACE: invalid BSSID '%s'", pos);
  2001. return -1;
  2002. }
  2003. ssid = wpa_config_get_network(wpa_s->conf, id);
  2004. if (ssid == NULL) {
  2005. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
  2006. "to update", id);
  2007. return -1;
  2008. }
  2009. os_memcpy(ssid->bssid, bssid, ETH_ALEN);
  2010. ssid->bssid_set = !is_zero_ether_addr(bssid);
  2011. return 0;
  2012. }
  2013. static int wpa_supplicant_ctrl_iface_blacklist(struct wpa_supplicant *wpa_s,
  2014. char *cmd, char *buf,
  2015. size_t buflen)
  2016. {
  2017. u8 bssid[ETH_ALEN];
  2018. struct wpa_blacklist *e;
  2019. char *pos, *end;
  2020. int ret;
  2021. /* cmd: "BLACKLIST [<BSSID>]" */
  2022. if (*cmd == '\0') {
  2023. pos = buf;
  2024. end = buf + buflen;
  2025. e = wpa_s->blacklist;
  2026. while (e) {
  2027. ret = os_snprintf(pos, end - pos, MACSTR "\n",
  2028. MAC2STR(e->bssid));
  2029. if (os_snprintf_error(end - pos, ret))
  2030. return pos - buf;
  2031. pos += ret;
  2032. e = e->next;
  2033. }
  2034. return pos - buf;
  2035. }
  2036. cmd++;
  2037. if (os_strncmp(cmd, "clear", 5) == 0) {
  2038. wpa_blacklist_clear(wpa_s);
  2039. os_memcpy(buf, "OK\n", 3);
  2040. return 3;
  2041. }
  2042. wpa_printf(MSG_DEBUG, "CTRL_IFACE: BLACKLIST bssid='%s'", cmd);
  2043. if (hwaddr_aton(cmd, bssid)) {
  2044. wpa_printf(MSG_DEBUG, "CTRL_IFACE: invalid BSSID '%s'", cmd);
  2045. return -1;
  2046. }
  2047. /*
  2048. * Add the BSSID twice, so its count will be 2, causing it to be
  2049. * skipped when processing scan results.
  2050. */
  2051. ret = wpa_blacklist_add(wpa_s, bssid);
  2052. if (ret < 0)
  2053. return -1;
  2054. ret = wpa_blacklist_add(wpa_s, bssid);
  2055. if (ret < 0)
  2056. return -1;
  2057. os_memcpy(buf, "OK\n", 3);
  2058. return 3;
  2059. }
  2060. static int wpa_supplicant_ctrl_iface_log_level(struct wpa_supplicant *wpa_s,
  2061. char *cmd, char *buf,
  2062. size_t buflen)
  2063. {
  2064. char *pos, *end, *stamp;
  2065. int ret;
  2066. /* cmd: "LOG_LEVEL [<level>]" */
  2067. if (*cmd == '\0') {
  2068. pos = buf;
  2069. end = buf + buflen;
  2070. ret = os_snprintf(pos, end - pos, "Current level: %s\n"
  2071. "Timestamp: %d\n",
  2072. debug_level_str(wpa_debug_level),
  2073. wpa_debug_timestamp);
  2074. if (os_snprintf_error(end - pos, ret))
  2075. ret = 0;
  2076. return ret;
  2077. }
  2078. while (*cmd == ' ')
  2079. cmd++;
  2080. stamp = os_strchr(cmd, ' ');
  2081. if (stamp) {
  2082. *stamp++ = '\0';
  2083. while (*stamp == ' ') {
  2084. stamp++;
  2085. }
  2086. }
  2087. if (os_strlen(cmd)) {
  2088. int level = str_to_debug_level(cmd);
  2089. if (level < 0)
  2090. return -1;
  2091. wpa_debug_level = level;
  2092. }
  2093. if (stamp && os_strlen(stamp))
  2094. wpa_debug_timestamp = atoi(stamp);
  2095. os_memcpy(buf, "OK\n", 3);
  2096. return 3;
  2097. }
  2098. static int wpa_supplicant_ctrl_iface_list_networks(
  2099. struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
  2100. {
  2101. char *pos, *end, *prev;
  2102. struct wpa_ssid *ssid;
  2103. int ret;
  2104. pos = buf;
  2105. end = buf + buflen;
  2106. ret = os_snprintf(pos, end - pos,
  2107. "network id / ssid / bssid / flags\n");
  2108. if (os_snprintf_error(end - pos, ret))
  2109. return pos - buf;
  2110. pos += ret;
  2111. ssid = wpa_s->conf->ssid;
  2112. /* skip over ssids until we find next one */
  2113. if (cmd != NULL && os_strncmp(cmd, "LAST_ID=", 8) == 0) {
  2114. int last_id = atoi(cmd + 8);
  2115. if (last_id != -1) {
  2116. while (ssid != NULL && ssid->id <= last_id) {
  2117. ssid = ssid->next;
  2118. }
  2119. }
  2120. }
  2121. while (ssid) {
  2122. prev = pos;
  2123. ret = os_snprintf(pos, end - pos, "%d\t%s",
  2124. ssid->id,
  2125. wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
  2126. if (os_snprintf_error(end - pos, ret))
  2127. return prev - buf;
  2128. pos += ret;
  2129. if (ssid->bssid_set) {
  2130. ret = os_snprintf(pos, end - pos, "\t" MACSTR,
  2131. MAC2STR(ssid->bssid));
  2132. } else {
  2133. ret = os_snprintf(pos, end - pos, "\tany");
  2134. }
  2135. if (os_snprintf_error(end - pos, ret))
  2136. return prev - buf;
  2137. pos += ret;
  2138. ret = os_snprintf(pos, end - pos, "\t%s%s%s%s",
  2139. ssid == wpa_s->current_ssid ?
  2140. "[CURRENT]" : "",
  2141. ssid->disabled ? "[DISABLED]" : "",
  2142. ssid->disabled_until.sec ?
  2143. "[TEMP-DISABLED]" : "",
  2144. ssid->disabled == 2 ? "[P2P-PERSISTENT]" :
  2145. "");
  2146. if (os_snprintf_error(end - pos, ret))
  2147. return prev - buf;
  2148. pos += ret;
  2149. ret = os_snprintf(pos, end - pos, "\n");
  2150. if (os_snprintf_error(end - pos, ret))
  2151. return prev - buf;
  2152. pos += ret;
  2153. ssid = ssid->next;
  2154. }
  2155. return pos - buf;
  2156. }
  2157. static char * wpa_supplicant_cipher_txt(char *pos, char *end, int cipher)
  2158. {
  2159. int ret;
  2160. ret = os_snprintf(pos, end - pos, "-");
  2161. if (os_snprintf_error(end - pos, ret))
  2162. return pos;
  2163. pos += ret;
  2164. ret = wpa_write_ciphers(pos, end, cipher, "+");
  2165. if (ret < 0)
  2166. return pos;
  2167. pos += ret;
  2168. return pos;
  2169. }
  2170. static char * wpa_supplicant_ie_txt(char *pos, char *end, const char *proto,
  2171. const u8 *ie, size_t ie_len)
  2172. {
  2173. struct wpa_ie_data data;
  2174. char *start;
  2175. int ret;
  2176. ret = os_snprintf(pos, end - pos, "[%s-", proto);
  2177. if (os_snprintf_error(end - pos, ret))
  2178. return pos;
  2179. pos += ret;
  2180. if (wpa_parse_wpa_ie(ie, ie_len, &data) < 0) {
  2181. ret = os_snprintf(pos, end - pos, "?]");
  2182. if (os_snprintf_error(end - pos, ret))
  2183. return pos;
  2184. pos += ret;
  2185. return pos;
  2186. }
  2187. start = pos;
  2188. if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X) {
  2189. ret = os_snprintf(pos, end - pos, "%sEAP",
  2190. pos == start ? "" : "+");
  2191. if (os_snprintf_error(end - pos, ret))
  2192. return pos;
  2193. pos += ret;
  2194. }
  2195. if (data.key_mgmt & WPA_KEY_MGMT_PSK) {
  2196. ret = os_snprintf(pos, end - pos, "%sPSK",
  2197. pos == start ? "" : "+");
  2198. if (os_snprintf_error(end - pos, ret))
  2199. return pos;
  2200. pos += ret;
  2201. }
  2202. if (data.key_mgmt & WPA_KEY_MGMT_WPA_NONE) {
  2203. ret = os_snprintf(pos, end - pos, "%sNone",
  2204. pos == start ? "" : "+");
  2205. if (os_snprintf_error(end - pos, ret))
  2206. return pos;
  2207. pos += ret;
  2208. }
  2209. if (data.key_mgmt & WPA_KEY_MGMT_SAE) {
  2210. ret = os_snprintf(pos, end - pos, "%sSAE",
  2211. pos == start ? "" : "+");
  2212. if (os_snprintf_error(end - pos, ret))
  2213. return pos;
  2214. pos += ret;
  2215. }
  2216. #ifdef CONFIG_IEEE80211R
  2217. if (data.key_mgmt & WPA_KEY_MGMT_FT_IEEE8021X) {
  2218. ret = os_snprintf(pos, end - pos, "%sFT/EAP",
  2219. pos == start ? "" : "+");
  2220. if (os_snprintf_error(end - pos, ret))
  2221. return pos;
  2222. pos += ret;
  2223. }
  2224. if (data.key_mgmt & WPA_KEY_MGMT_FT_PSK) {
  2225. ret = os_snprintf(pos, end - pos, "%sFT/PSK",
  2226. pos == start ? "" : "+");
  2227. if (os_snprintf_error(end - pos, ret))
  2228. return pos;
  2229. pos += ret;
  2230. }
  2231. if (data.key_mgmt & WPA_KEY_MGMT_FT_SAE) {
  2232. ret = os_snprintf(pos, end - pos, "%sFT/SAE",
  2233. pos == start ? "" : "+");
  2234. if (os_snprintf_error(end - pos, ret))
  2235. return pos;
  2236. pos += ret;
  2237. }
  2238. #endif /* CONFIG_IEEE80211R */
  2239. #ifdef CONFIG_IEEE80211W
  2240. if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SHA256) {
  2241. ret = os_snprintf(pos, end - pos, "%sEAP-SHA256",
  2242. pos == start ? "" : "+");
  2243. if (os_snprintf_error(end - pos, ret))
  2244. return pos;
  2245. pos += ret;
  2246. }
  2247. if (data.key_mgmt & WPA_KEY_MGMT_PSK_SHA256) {
  2248. ret = os_snprintf(pos, end - pos, "%sPSK-SHA256",
  2249. pos == start ? "" : "+");
  2250. if (os_snprintf_error(end - pos, ret))
  2251. return pos;
  2252. pos += ret;
  2253. }
  2254. #endif /* CONFIG_IEEE80211W */
  2255. #ifdef CONFIG_SUITEB
  2256. if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SUITE_B) {
  2257. ret = os_snprintf(pos, end - pos, "%sEAP-SUITE-B",
  2258. pos == start ? "" : "+");
  2259. if (os_snprintf_error(end - pos, ret))
  2260. return pos;
  2261. pos += ret;
  2262. }
  2263. #endif /* CONFIG_SUITEB */
  2264. #ifdef CONFIG_SUITEB192
  2265. if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SUITE_B_192) {
  2266. ret = os_snprintf(pos, end - pos, "%sEAP-SUITE-B-192",
  2267. pos == start ? "" : "+");
  2268. if (os_snprintf_error(end - pos, ret))
  2269. return pos;
  2270. pos += ret;
  2271. }
  2272. #endif /* CONFIG_SUITEB192 */
  2273. #ifdef CONFIG_FILS
  2274. if (data.key_mgmt & WPA_KEY_MGMT_FILS_SHA256) {
  2275. ret = os_snprintf(pos, end - pos, "%sFILS-SHA256",
  2276. pos == start ? "" : "+");
  2277. if (os_snprintf_error(end - pos, ret))
  2278. return pos;
  2279. pos += ret;
  2280. }
  2281. if (data.key_mgmt & WPA_KEY_MGMT_FILS_SHA384) {
  2282. ret = os_snprintf(pos, end - pos, "%sFILS-SHA384",
  2283. pos == start ? "" : "+");
  2284. if (os_snprintf_error(end - pos, ret))
  2285. return pos;
  2286. pos += ret;
  2287. }
  2288. #ifdef CONFIG_IEEE80211R
  2289. if (data.key_mgmt & WPA_KEY_MGMT_FT_FILS_SHA256) {
  2290. ret = os_snprintf(pos, end - pos, "%sFT-FILS-SHA256",
  2291. pos == start ? "" : "+");
  2292. if (os_snprintf_error(end - pos, ret))
  2293. return pos;
  2294. pos += ret;
  2295. }
  2296. if (data.key_mgmt & WPA_KEY_MGMT_FT_FILS_SHA384) {
  2297. ret = os_snprintf(pos, end - pos, "%sFT-FILS-SHA384",
  2298. pos == start ? "" : "+");
  2299. if (os_snprintf_error(end - pos, ret))
  2300. return pos;
  2301. pos += ret;
  2302. }
  2303. #endif /* CONFIG_IEEE80211R */
  2304. #endif /* CONFIG_FILS */
  2305. #ifdef CONFIG_OWE
  2306. if (data.key_mgmt & WPA_KEY_MGMT_OWE) {
  2307. ret = os_snprintf(pos, end - pos, "%sOWE",
  2308. pos == start ? "" : "+");
  2309. if (os_snprintf_error(end - pos, ret))
  2310. return pos;
  2311. pos += ret;
  2312. }
  2313. #endif /* CONFIG_OWE */
  2314. #ifdef CONFIG_DPP
  2315. if (data.key_mgmt & WPA_KEY_MGMT_DPP) {
  2316. ret = os_snprintf(pos, end - pos, "%sDPP",
  2317. pos == start ? "" : "+");
  2318. if (os_snprintf_error(end - pos, ret))
  2319. return pos;
  2320. pos += ret;
  2321. }
  2322. #endif /* CONFIG_DPP */
  2323. if (data.key_mgmt & WPA_KEY_MGMT_OSEN) {
  2324. ret = os_snprintf(pos, end - pos, "%sOSEN",
  2325. pos == start ? "" : "+");
  2326. if (os_snprintf_error(end - pos, ret))
  2327. return pos;
  2328. pos += ret;
  2329. }
  2330. pos = wpa_supplicant_cipher_txt(pos, end, data.pairwise_cipher);
  2331. if (data.capabilities & WPA_CAPABILITY_PREAUTH) {
  2332. ret = os_snprintf(pos, end - pos, "-preauth");
  2333. if (os_snprintf_error(end - pos, ret))
  2334. return pos;
  2335. pos += ret;
  2336. }
  2337. ret = os_snprintf(pos, end - pos, "]");
  2338. if (os_snprintf_error(end - pos, ret))
  2339. return pos;
  2340. pos += ret;
  2341. return pos;
  2342. }
  2343. #ifdef CONFIG_WPS
  2344. static char * wpa_supplicant_wps_ie_txt_buf(struct wpa_supplicant *wpa_s,
  2345. char *pos, char *end,
  2346. struct wpabuf *wps_ie)
  2347. {
  2348. int ret;
  2349. const char *txt;
  2350. if (wps_ie == NULL)
  2351. return pos;
  2352. if (wps_is_selected_pbc_registrar(wps_ie))
  2353. txt = "[WPS-PBC]";
  2354. else if (wps_is_addr_authorized(wps_ie, wpa_s->own_addr, 0))
  2355. txt = "[WPS-AUTH]";
  2356. else if (wps_is_selected_pin_registrar(wps_ie))
  2357. txt = "[WPS-PIN]";
  2358. else
  2359. txt = "[WPS]";
  2360. ret = os_snprintf(pos, end - pos, "%s", txt);
  2361. if (!os_snprintf_error(end - pos, ret))
  2362. pos += ret;
  2363. wpabuf_free(wps_ie);
  2364. return pos;
  2365. }
  2366. #endif /* CONFIG_WPS */
  2367. static char * wpa_supplicant_wps_ie_txt(struct wpa_supplicant *wpa_s,
  2368. char *pos, char *end,
  2369. const struct wpa_bss *bss)
  2370. {
  2371. #ifdef CONFIG_WPS
  2372. struct wpabuf *wps_ie;
  2373. wps_ie = wpa_bss_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE);
  2374. return wpa_supplicant_wps_ie_txt_buf(wpa_s, pos, end, wps_ie);
  2375. #else /* CONFIG_WPS */
  2376. return pos;
  2377. #endif /* CONFIG_WPS */
  2378. }
  2379. /* Format one result on one text line into a buffer. */
  2380. static int wpa_supplicant_ctrl_iface_scan_result(
  2381. struct wpa_supplicant *wpa_s,
  2382. const struct wpa_bss *bss, char *buf, size_t buflen)
  2383. {
  2384. char *pos, *end;
  2385. int ret;
  2386. const u8 *ie, *ie2, *osen_ie, *p2p, *mesh, *owe;
  2387. mesh = wpa_bss_get_ie(bss, WLAN_EID_MESH_ID);
  2388. p2p = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE);
  2389. if (!p2p)
  2390. p2p = wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE);
  2391. if (p2p && bss->ssid_len == P2P_WILDCARD_SSID_LEN &&
  2392. os_memcmp(bss->ssid, P2P_WILDCARD_SSID, P2P_WILDCARD_SSID_LEN) ==
  2393. 0)
  2394. return 0; /* Do not show P2P listen discovery results here */
  2395. pos = buf;
  2396. end = buf + buflen;
  2397. ret = os_snprintf(pos, end - pos, MACSTR "\t%d\t%d\t",
  2398. MAC2STR(bss->bssid), bss->freq, bss->level);
  2399. if (os_snprintf_error(end - pos, ret))
  2400. return -1;
  2401. pos += ret;
  2402. ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
  2403. if (ie)
  2404. pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie, 2 + ie[1]);
  2405. ie2 = wpa_bss_get_ie(bss, WLAN_EID_RSN);
  2406. if (ie2) {
  2407. pos = wpa_supplicant_ie_txt(pos, end, mesh ? "RSN" : "WPA2",
  2408. ie2, 2 + ie2[1]);
  2409. }
  2410. osen_ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE);
  2411. if (osen_ie)
  2412. pos = wpa_supplicant_ie_txt(pos, end, "OSEN",
  2413. osen_ie, 2 + osen_ie[1]);
  2414. owe = wpa_bss_get_vendor_ie(bss, OWE_IE_VENDOR_TYPE);
  2415. if (owe) {
  2416. ret = os_snprintf(pos, end - pos,
  2417. ie2 ? "[OWE-TRANS]" : "[OWE-TRANS-OPEN]");
  2418. if (os_snprintf_error(end - pos, ret))
  2419. return -1;
  2420. pos += ret;
  2421. }
  2422. pos = wpa_supplicant_wps_ie_txt(wpa_s, pos, end, bss);
  2423. if (!ie && !ie2 && !osen_ie && (bss->caps & IEEE80211_CAP_PRIVACY)) {
  2424. ret = os_snprintf(pos, end - pos, "[WEP]");
  2425. if (os_snprintf_error(end - pos, ret))
  2426. return -1;
  2427. pos += ret;
  2428. }
  2429. if (mesh) {
  2430. ret = os_snprintf(pos, end - pos, "[MESH]");
  2431. if (os_snprintf_error(end - pos, ret))
  2432. return -1;
  2433. pos += ret;
  2434. }
  2435. if (bss_is_dmg(bss)) {
  2436. const char *s;
  2437. ret = os_snprintf(pos, end - pos, "[DMG]");
  2438. if (os_snprintf_error(end - pos, ret))
  2439. return -1;
  2440. pos += ret;
  2441. switch (bss->caps & IEEE80211_CAP_DMG_MASK) {
  2442. case IEEE80211_CAP_DMG_IBSS:
  2443. s = "[IBSS]";
  2444. break;
  2445. case IEEE80211_CAP_DMG_AP:
  2446. s = "[ESS]";
  2447. break;
  2448. case IEEE80211_CAP_DMG_PBSS:
  2449. s = "[PBSS]";
  2450. break;
  2451. default:
  2452. s = "";
  2453. break;
  2454. }
  2455. ret = os_snprintf(pos, end - pos, "%s", s);
  2456. if (os_snprintf_error(end - pos, ret))
  2457. return -1;
  2458. pos += ret;
  2459. } else {
  2460. if (bss->caps & IEEE80211_CAP_IBSS) {
  2461. ret = os_snprintf(pos, end - pos, "[IBSS]");
  2462. if (os_snprintf_error(end - pos, ret))
  2463. return -1;
  2464. pos += ret;
  2465. }
  2466. if (bss->caps & IEEE80211_CAP_ESS) {
  2467. ret = os_snprintf(pos, end - pos, "[ESS]");
  2468. if (os_snprintf_error(end - pos, ret))
  2469. return -1;
  2470. pos += ret;
  2471. }
  2472. }
  2473. if (p2p) {
  2474. ret = os_snprintf(pos, end - pos, "[P2P]");
  2475. if (os_snprintf_error(end - pos, ret))
  2476. return -1;
  2477. pos += ret;
  2478. }
  2479. #ifdef CONFIG_HS20
  2480. if (wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE) && ie2) {
  2481. ret = os_snprintf(pos, end - pos, "[HS20]");
  2482. if (os_snprintf_error(end - pos, ret))
  2483. return -1;
  2484. pos += ret;
  2485. }
  2486. #endif /* CONFIG_HS20 */
  2487. #ifdef CONFIG_FILS
  2488. if (wpa_bss_get_ie(bss, WLAN_EID_FILS_INDICATION)) {
  2489. ret = os_snprintf(pos, end - pos, "[FILS]");
  2490. if (os_snprintf_error(end - pos, ret))
  2491. return -1;
  2492. pos += ret;
  2493. }
  2494. #endif /* CONFIG_FILS */
  2495. #ifdef CONFIG_FST
  2496. if (wpa_bss_get_ie(bss, WLAN_EID_MULTI_BAND)) {
  2497. ret = os_snprintf(pos, end - pos, "[FST]");
  2498. if (os_snprintf_error(end - pos, ret))
  2499. return -1;
  2500. pos += ret;
  2501. }
  2502. #endif /* CONFIG_FST */
  2503. ret = os_snprintf(pos, end - pos, "\t%s",
  2504. wpa_ssid_txt(bss->ssid, bss->ssid_len));
  2505. if (os_snprintf_error(end - pos, ret))
  2506. return -1;
  2507. pos += ret;
  2508. ret = os_snprintf(pos, end - pos, "\n");
  2509. if (os_snprintf_error(end - pos, ret))
  2510. return -1;
  2511. pos += ret;
  2512. return pos - buf;
  2513. }
  2514. static int wpa_supplicant_ctrl_iface_scan_results(
  2515. struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
  2516. {
  2517. char *pos, *end;
  2518. struct wpa_bss *bss;
  2519. int ret;
  2520. pos = buf;
  2521. end = buf + buflen;
  2522. ret = os_snprintf(pos, end - pos, "bssid / frequency / signal level / "
  2523. "flags / ssid\n");
  2524. if (os_snprintf_error(end - pos, ret))
  2525. return pos - buf;
  2526. pos += ret;
  2527. dl_list_for_each(bss, &wpa_s->bss_id, struct wpa_bss, list_id) {
  2528. ret = wpa_supplicant_ctrl_iface_scan_result(wpa_s, bss, pos,
  2529. end - pos);
  2530. if (ret < 0 || ret >= end - pos)
  2531. return pos - buf;
  2532. pos += ret;
  2533. }
  2534. return pos - buf;
  2535. }
  2536. #ifdef CONFIG_MESH
  2537. static int wpa_supplicant_ctrl_iface_mesh_interface_add(
  2538. struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
  2539. {
  2540. char *pos, ifname[IFNAMSIZ + 1];
  2541. ifname[0] = '\0';
  2542. pos = os_strstr(cmd, "ifname=");
  2543. if (pos) {
  2544. pos += 7;
  2545. os_strlcpy(ifname, pos, sizeof(ifname));
  2546. }
  2547. if (wpas_mesh_add_interface(wpa_s, ifname, sizeof(ifname)) < 0)
  2548. return -1;
  2549. os_strlcpy(reply, ifname, max_len);
  2550. return os_strlen(ifname);
  2551. }
  2552. static int wpa_supplicant_ctrl_iface_mesh_group_add(
  2553. struct wpa_supplicant *wpa_s, char *cmd)
  2554. {
  2555. int id;
  2556. struct wpa_ssid *ssid;
  2557. id = atoi(cmd);
  2558. wpa_printf(MSG_DEBUG, "CTRL_IFACE: MESH_GROUP_ADD id=%d", id);
  2559. ssid = wpa_config_get_network(wpa_s->conf, id);
  2560. if (ssid == NULL) {
  2561. wpa_printf(MSG_DEBUG,
  2562. "CTRL_IFACE: Could not find network id=%d", id);
  2563. return -1;
  2564. }
  2565. if (ssid->mode != WPAS_MODE_MESH) {
  2566. wpa_printf(MSG_DEBUG,
  2567. "CTRL_IFACE: Cannot use MESH_GROUP_ADD on a non mesh network");
  2568. return -1;
  2569. }
  2570. if (ssid->key_mgmt != WPA_KEY_MGMT_NONE &&
  2571. ssid->key_mgmt != WPA_KEY_MGMT_SAE) {
  2572. wpa_printf(MSG_ERROR,
  2573. "CTRL_IFACE: key_mgmt for mesh network should be open or SAE");
  2574. return -1;
  2575. }
  2576. /*
  2577. * TODO: If necessary write our own group_add function,
  2578. * for now we can reuse select_network
  2579. */
  2580. wpa_supplicant_select_network(wpa_s, ssid);
  2581. return 0;
  2582. }
  2583. static int wpa_supplicant_ctrl_iface_mesh_group_remove(
  2584. struct wpa_supplicant *wpa_s, char *cmd)
  2585. {
  2586. struct wpa_supplicant *orig;
  2587. struct wpa_global *global;
  2588. int found = 0;
  2589. wpa_printf(MSG_DEBUG, "CTRL_IFACE: MESH_GROUP_REMOVE ifname=%s", cmd);
  2590. global = wpa_s->global;
  2591. orig = wpa_s;
  2592. for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
  2593. if (os_strcmp(wpa_s->ifname, cmd) == 0) {
  2594. found = 1;
  2595. break;
  2596. }
  2597. }
  2598. if (!found) {
  2599. wpa_printf(MSG_ERROR,
  2600. "CTRL_IFACE: MESH_GROUP_REMOVE ifname=%s not found",
  2601. cmd);
  2602. return -1;
  2603. }
  2604. if (wpa_s->mesh_if_created && wpa_s == orig) {
  2605. wpa_printf(MSG_ERROR,
  2606. "CTRL_IFACE: MESH_GROUP_REMOVE can't remove itself");
  2607. return -1;
  2608. }
  2609. wpa_s->reassociate = 0;
  2610. wpa_s->disconnected = 1;
  2611. wpa_supplicant_cancel_sched_scan(wpa_s);
  2612. wpa_supplicant_cancel_scan(wpa_s);
  2613. /*
  2614. * TODO: If necessary write our own group_remove function,
  2615. * for now we can reuse deauthenticate
  2616. */
  2617. wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
  2618. if (wpa_s->mesh_if_created)
  2619. wpa_supplicant_remove_iface(global, wpa_s, 0);
  2620. return 0;
  2621. }
  2622. static int wpa_supplicant_ctrl_iface_mesh_peer_remove(
  2623. struct wpa_supplicant *wpa_s, char *cmd)
  2624. {
  2625. u8 addr[ETH_ALEN];
  2626. if (hwaddr_aton(cmd, addr) < 0)
  2627. return -1;
  2628. return wpas_mesh_peer_remove(wpa_s, addr);
  2629. }
  2630. static int wpa_supplicant_ctrl_iface_mesh_peer_add(
  2631. struct wpa_supplicant *wpa_s, char *cmd)
  2632. {
  2633. u8 addr[ETH_ALEN];
  2634. int duration;
  2635. char *pos;
  2636. pos = os_strstr(cmd, " duration=");
  2637. if (pos) {
  2638. *pos = '\0';
  2639. duration = atoi(pos + 10);
  2640. } else {
  2641. duration = -1;
  2642. }
  2643. if (hwaddr_aton(cmd, addr))
  2644. return -1;
  2645. return wpas_mesh_peer_add(wpa_s, addr, duration);
  2646. }
  2647. #endif /* CONFIG_MESH */
  2648. static int wpa_supplicant_ctrl_iface_select_network(
  2649. struct wpa_supplicant *wpa_s, char *cmd)
  2650. {
  2651. int id;
  2652. struct wpa_ssid *ssid;
  2653. char *pos;
  2654. /* cmd: "<network id>" or "any" */
  2655. if (os_strncmp(cmd, "any", 3) == 0) {
  2656. wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK any");
  2657. ssid = NULL;
  2658. } else {
  2659. id = atoi(cmd);
  2660. wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK id=%d", id);
  2661. ssid = wpa_config_get_network(wpa_s->conf, id);
  2662. if (ssid == NULL) {
  2663. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
  2664. "network id=%d", id);
  2665. return -1;
  2666. }
  2667. if (ssid->disabled == 2) {
  2668. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
  2669. "SELECT_NETWORK with persistent P2P group");
  2670. return -1;
  2671. }
  2672. }
  2673. pos = os_strstr(cmd, " freq=");
  2674. if (pos) {
  2675. int *freqs = freq_range_to_channel_list(wpa_s, pos + 6);
  2676. if (freqs) {
  2677. os_free(wpa_s->select_network_scan_freqs);
  2678. wpa_s->select_network_scan_freqs = freqs;
  2679. }
  2680. }
  2681. wpa_s->scan_min_time.sec = 0;
  2682. wpa_s->scan_min_time.usec = 0;
  2683. wpa_supplicant_select_network(wpa_s, ssid);
  2684. return 0;
  2685. }
  2686. static int wpa_supplicant_ctrl_iface_enable_network(
  2687. struct wpa_supplicant *wpa_s, char *cmd)
  2688. {
  2689. int id;
  2690. struct wpa_ssid *ssid;
  2691. /* cmd: "<network id>" or "all" */
  2692. if (os_strcmp(cmd, "all") == 0) {
  2693. wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK all");
  2694. ssid = NULL;
  2695. } else {
  2696. id = atoi(cmd);
  2697. wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK id=%d", id);
  2698. ssid = wpa_config_get_network(wpa_s->conf, id);
  2699. if (ssid == NULL) {
  2700. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
  2701. "network id=%d", id);
  2702. return -1;
  2703. }
  2704. if (ssid->disabled == 2) {
  2705. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
  2706. "ENABLE_NETWORK with persistent P2P group");
  2707. return -1;
  2708. }
  2709. if (os_strstr(cmd, " no-connect")) {
  2710. ssid->disabled = 0;
  2711. return 0;
  2712. }
  2713. }
  2714. wpa_s->scan_min_time.sec = 0;
  2715. wpa_s->scan_min_time.usec = 0;
  2716. wpa_supplicant_enable_network(wpa_s, ssid);
  2717. return 0;
  2718. }
  2719. static int wpa_supplicant_ctrl_iface_disable_network(
  2720. struct wpa_supplicant *wpa_s, char *cmd)
  2721. {
  2722. int id;
  2723. struct wpa_ssid *ssid;
  2724. /* cmd: "<network id>" or "all" */
  2725. if (os_strcmp(cmd, "all") == 0) {
  2726. wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK all");
  2727. ssid = NULL;
  2728. } else {
  2729. id = atoi(cmd);
  2730. wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK id=%d", id);
  2731. ssid = wpa_config_get_network(wpa_s->conf, id);
  2732. if (ssid == NULL) {
  2733. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
  2734. "network id=%d", id);
  2735. return -1;
  2736. }
  2737. if (ssid->disabled == 2) {
  2738. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
  2739. "DISABLE_NETWORK with persistent P2P "
  2740. "group");
  2741. return -1;
  2742. }
  2743. }
  2744. wpa_supplicant_disable_network(wpa_s, ssid);
  2745. return 0;
  2746. }
  2747. static int wpa_supplicant_ctrl_iface_add_network(
  2748. struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
  2749. {
  2750. struct wpa_ssid *ssid;
  2751. int ret;
  2752. wpa_printf(MSG_DEBUG, "CTRL_IFACE: ADD_NETWORK");
  2753. ssid = wpa_supplicant_add_network(wpa_s);
  2754. if (ssid == NULL)
  2755. return -1;
  2756. ret = os_snprintf(buf, buflen, "%d\n", ssid->id);
  2757. if (os_snprintf_error(buflen, ret))
  2758. return -1;
  2759. return ret;
  2760. }
  2761. static int wpa_supplicant_ctrl_iface_remove_network(
  2762. struct wpa_supplicant *wpa_s, char *cmd)
  2763. {
  2764. int id;
  2765. struct wpa_ssid *ssid;
  2766. int result;
  2767. /* cmd: "<network id>" or "all" */
  2768. if (os_strcmp(cmd, "all") == 0) {
  2769. wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK all");
  2770. if (wpa_s->sched_scanning)
  2771. wpa_supplicant_cancel_sched_scan(wpa_s);
  2772. eapol_sm_invalidate_cached_session(wpa_s->eapol);
  2773. if (wpa_s->current_ssid) {
  2774. #ifdef CONFIG_SME
  2775. wpa_s->sme.prev_bssid_set = 0;
  2776. #endif /* CONFIG_SME */
  2777. wpa_sm_set_config(wpa_s->wpa, NULL);
  2778. eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
  2779. if (wpa_s->wpa_state >= WPA_AUTHENTICATING)
  2780. wpa_s->own_disconnect_req = 1;
  2781. wpa_supplicant_deauthenticate(
  2782. wpa_s, WLAN_REASON_DEAUTH_LEAVING);
  2783. }
  2784. ssid = wpa_s->conf->ssid;
  2785. while (ssid) {
  2786. struct wpa_ssid *remove_ssid = ssid;
  2787. id = ssid->id;
  2788. ssid = ssid->next;
  2789. if (wpa_s->last_ssid == remove_ssid)
  2790. wpa_s->last_ssid = NULL;
  2791. wpas_notify_network_removed(wpa_s, remove_ssid);
  2792. wpa_config_remove_network(wpa_s->conf, id);
  2793. }
  2794. return 0;
  2795. }
  2796. id = atoi(cmd);
  2797. wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK id=%d", id);
  2798. result = wpa_supplicant_remove_network(wpa_s, id);
  2799. if (result == -1) {
  2800. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
  2801. "id=%d", id);
  2802. return -1;
  2803. }
  2804. if (result == -2) {
  2805. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Not able to remove the "
  2806. "network id=%d", id);
  2807. return -1;
  2808. }
  2809. return 0;
  2810. }
  2811. static int wpa_supplicant_ctrl_iface_update_network(
  2812. struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
  2813. char *name, char *value)
  2814. {
  2815. int ret;
  2816. ret = wpa_config_set(ssid, name, value, 0);
  2817. if (ret < 0) {
  2818. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set network "
  2819. "variable '%s'", name);
  2820. return -1;
  2821. }
  2822. if (ret == 1)
  2823. return 0; /* No change to the previously configured value */
  2824. if (os_strcmp(name, "bssid") != 0 &&
  2825. os_strcmp(name, "bssid_hint") != 0 &&
  2826. os_strcmp(name, "priority") != 0) {
  2827. wpa_sm_pmksa_cache_flush(wpa_s->wpa, ssid);
  2828. if (wpa_s->current_ssid == ssid ||
  2829. wpa_s->current_ssid == NULL) {
  2830. /*
  2831. * Invalidate the EAP session cache if anything in the
  2832. * current or previously used configuration changes.
  2833. */
  2834. eapol_sm_invalidate_cached_session(wpa_s->eapol);
  2835. }
  2836. }
  2837. if ((os_strcmp(name, "psk") == 0 &&
  2838. value[0] == '"' && ssid->ssid_len) ||
  2839. (os_strcmp(name, "ssid") == 0 && ssid->passphrase))
  2840. wpa_config_update_psk(ssid);
  2841. else if (os_strcmp(name, "priority") == 0)
  2842. wpa_config_update_prio_list(wpa_s->conf);
  2843. return 0;
  2844. }
  2845. static int wpa_supplicant_ctrl_iface_set_network(
  2846. struct wpa_supplicant *wpa_s, char *cmd)
  2847. {
  2848. int id, ret, prev_bssid_set, prev_disabled;
  2849. struct wpa_ssid *ssid;
  2850. char *name, *value;
  2851. u8 prev_bssid[ETH_ALEN];
  2852. /* cmd: "<network id> <variable name> <value>" */
  2853. name = os_strchr(cmd, ' ');
  2854. if (name == NULL)
  2855. return -1;
  2856. *name++ = '\0';
  2857. value = os_strchr(name, ' ');
  2858. if (value == NULL)
  2859. return -1;
  2860. *value++ = '\0';
  2861. id = atoi(cmd);
  2862. wpa_printf(MSG_DEBUG, "CTRL_IFACE: SET_NETWORK id=%d name='%s'",
  2863. id, name);
  2864. wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
  2865. (u8 *) value, os_strlen(value));
  2866. ssid = wpa_config_get_network(wpa_s->conf, id);
  2867. if (ssid == NULL) {
  2868. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
  2869. "id=%d", id);
  2870. return -1;
  2871. }
  2872. prev_bssid_set = ssid->bssid_set;
  2873. prev_disabled = ssid->disabled;
  2874. os_memcpy(prev_bssid, ssid->bssid, ETH_ALEN);
  2875. ret = wpa_supplicant_ctrl_iface_update_network(wpa_s, ssid, name,
  2876. value);
  2877. if (ret == 0 &&
  2878. (ssid->bssid_set != prev_bssid_set ||
  2879. os_memcmp(ssid->bssid, prev_bssid, ETH_ALEN) != 0))
  2880. wpas_notify_network_bssid_set_changed(wpa_s, ssid);
  2881. if (prev_disabled != ssid->disabled &&
  2882. (prev_disabled == 2 || ssid->disabled == 2))
  2883. wpas_notify_network_type_changed(wpa_s, ssid);
  2884. return ret;
  2885. }
  2886. static int wpa_supplicant_ctrl_iface_get_network(
  2887. struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
  2888. {
  2889. int id;
  2890. size_t res;
  2891. struct wpa_ssid *ssid;
  2892. char *name, *value;
  2893. /* cmd: "<network id> <variable name>" */
  2894. name = os_strchr(cmd, ' ');
  2895. if (name == NULL || buflen == 0)
  2896. return -1;
  2897. *name++ = '\0';
  2898. id = atoi(cmd);
  2899. wpa_printf(MSG_EXCESSIVE, "CTRL_IFACE: GET_NETWORK id=%d name='%s'",
  2900. id, name);
  2901. ssid = wpa_config_get_network(wpa_s->conf, id);
  2902. if (ssid == NULL) {
  2903. wpa_printf(MSG_EXCESSIVE, "CTRL_IFACE: Could not find network "
  2904. "id=%d", id);
  2905. return -1;
  2906. }
  2907. value = wpa_config_get_no_key(ssid, name);
  2908. if (value == NULL) {
  2909. wpa_printf(MSG_EXCESSIVE, "CTRL_IFACE: Failed to get network "
  2910. "variable '%s'", name);
  2911. return -1;
  2912. }
  2913. res = os_strlcpy(buf, value, buflen);
  2914. if (res >= buflen) {
  2915. os_free(value);
  2916. return -1;
  2917. }
  2918. os_free(value);
  2919. return res;
  2920. }
  2921. static int wpa_supplicant_ctrl_iface_dup_network(
  2922. struct wpa_supplicant *wpa_s, char *cmd,
  2923. struct wpa_supplicant *dst_wpa_s)
  2924. {
  2925. struct wpa_ssid *ssid_s, *ssid_d;
  2926. char *name, *id, *value;
  2927. int id_s, id_d, ret;
  2928. /* cmd: "<src network id> <dst network id> <variable name>" */
  2929. id = os_strchr(cmd, ' ');
  2930. if (id == NULL)
  2931. return -1;
  2932. *id++ = '\0';
  2933. name = os_strchr(id, ' ');
  2934. if (name == NULL)
  2935. return -1;
  2936. *name++ = '\0';
  2937. id_s = atoi(cmd);
  2938. id_d = atoi(id);
  2939. wpa_printf(MSG_DEBUG,
  2940. "CTRL_IFACE: DUP_NETWORK ifname=%s->%s id=%d->%d name='%s'",
  2941. wpa_s->ifname, dst_wpa_s->ifname, id_s, id_d, name);
  2942. ssid_s = wpa_config_get_network(wpa_s->conf, id_s);
  2943. if (ssid_s == NULL) {
  2944. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
  2945. "network id=%d", id_s);
  2946. return -1;
  2947. }
  2948. ssid_d = wpa_config_get_network(dst_wpa_s->conf, id_d);
  2949. if (ssid_d == NULL) {
  2950. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
  2951. "network id=%d", id_d);
  2952. return -1;
  2953. }
  2954. value = wpa_config_get(ssid_s, name);
  2955. if (value == NULL) {
  2956. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to get network "
  2957. "variable '%s'", name);
  2958. return -1;
  2959. }
  2960. ret = wpa_supplicant_ctrl_iface_update_network(dst_wpa_s, ssid_d, name,
  2961. value);
  2962. os_free(value);
  2963. return ret;
  2964. }
  2965. static int wpa_supplicant_ctrl_iface_list_creds(struct wpa_supplicant *wpa_s,
  2966. char *buf, size_t buflen)
  2967. {
  2968. char *pos, *end;
  2969. struct wpa_cred *cred;
  2970. int ret;
  2971. pos = buf;
  2972. end = buf + buflen;
  2973. ret = os_snprintf(pos, end - pos,
  2974. "cred id / realm / username / domain / imsi\n");
  2975. if (os_snprintf_error(end - pos, ret))
  2976. return pos - buf;
  2977. pos += ret;
  2978. cred = wpa_s->conf->cred;
  2979. while (cred) {
  2980. ret = os_snprintf(pos, end - pos, "%d\t%s\t%s\t%s\t%s\n",
  2981. cred->id, cred->realm ? cred->realm : "",
  2982. cred->username ? cred->username : "",
  2983. cred->domain ? cred->domain[0] : "",
  2984. cred->imsi ? cred->imsi : "");
  2985. if (os_snprintf_error(end - pos, ret))
  2986. return pos - buf;
  2987. pos += ret;
  2988. cred = cred->next;
  2989. }
  2990. return pos - buf;
  2991. }
  2992. static int wpa_supplicant_ctrl_iface_add_cred(struct wpa_supplicant *wpa_s,
  2993. char *buf, size_t buflen)
  2994. {
  2995. struct wpa_cred *cred;
  2996. int ret;
  2997. wpa_printf(MSG_DEBUG, "CTRL_IFACE: ADD_CRED");
  2998. cred = wpa_config_add_cred(wpa_s->conf);
  2999. if (cred == NULL)
  3000. return -1;
  3001. wpa_msg(wpa_s, MSG_INFO, CRED_ADDED "%d", cred->id);
  3002. ret = os_snprintf(buf, buflen, "%d\n", cred->id);
  3003. if (os_snprintf_error(buflen, ret))
  3004. return -1;
  3005. return ret;
  3006. }
  3007. static int wpas_ctrl_remove_cred(struct wpa_supplicant *wpa_s,
  3008. struct wpa_cred *cred)
  3009. {
  3010. struct wpa_ssid *ssid;
  3011. char str[20];
  3012. int id;
  3013. if (cred == NULL) {
  3014. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred");
  3015. return -1;
  3016. }
  3017. id = cred->id;
  3018. if (wpa_config_remove_cred(wpa_s->conf, id) < 0) {
  3019. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred");
  3020. return -1;
  3021. }
  3022. wpa_msg(wpa_s, MSG_INFO, CRED_REMOVED "%d", id);
  3023. /* Remove any network entry created based on the removed credential */
  3024. ssid = wpa_s->conf->ssid;
  3025. while (ssid) {
  3026. if (ssid->parent_cred == cred) {
  3027. int res;
  3028. wpa_printf(MSG_DEBUG, "Remove network id %d since it "
  3029. "used the removed credential", ssid->id);
  3030. res = os_snprintf(str, sizeof(str), "%d", ssid->id);
  3031. if (os_snprintf_error(sizeof(str), res))
  3032. str[sizeof(str) - 1] = '\0';
  3033. ssid = ssid->next;
  3034. wpa_supplicant_ctrl_iface_remove_network(wpa_s, str);
  3035. } else
  3036. ssid = ssid->next;
  3037. }
  3038. return 0;
  3039. }
  3040. static int wpa_supplicant_ctrl_iface_remove_cred(struct wpa_supplicant *wpa_s,
  3041. char *cmd)
  3042. {
  3043. int id;
  3044. struct wpa_cred *cred, *prev;
  3045. /* cmd: "<cred id>", "all", "sp_fqdn=<FQDN>", or
  3046. * "provisioning_sp=<FQDN> */
  3047. if (os_strcmp(cmd, "all") == 0) {
  3048. wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED all");
  3049. cred = wpa_s->conf->cred;
  3050. while (cred) {
  3051. prev = cred;
  3052. cred = cred->next;
  3053. wpas_ctrl_remove_cred(wpa_s, prev);
  3054. }
  3055. return 0;
  3056. }
  3057. if (os_strncmp(cmd, "sp_fqdn=", 8) == 0) {
  3058. wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED SP FQDN '%s'",
  3059. cmd + 8);
  3060. cred = wpa_s->conf->cred;
  3061. while (cred) {
  3062. prev = cred;
  3063. cred = cred->next;
  3064. if (prev->domain) {
  3065. size_t i;
  3066. for (i = 0; i < prev->num_domain; i++) {
  3067. if (os_strcmp(prev->domain[i], cmd + 8)
  3068. != 0)
  3069. continue;
  3070. wpas_ctrl_remove_cred(wpa_s, prev);
  3071. break;
  3072. }
  3073. }
  3074. }
  3075. return 0;
  3076. }
  3077. if (os_strncmp(cmd, "provisioning_sp=", 16) == 0) {
  3078. wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED provisioning SP FQDN '%s'",
  3079. cmd + 16);
  3080. cred = wpa_s->conf->cred;
  3081. while (cred) {
  3082. prev = cred;
  3083. cred = cred->next;
  3084. if (prev->provisioning_sp &&
  3085. os_strcmp(prev->provisioning_sp, cmd + 16) == 0)
  3086. wpas_ctrl_remove_cred(wpa_s, prev);
  3087. }
  3088. return 0;
  3089. }
  3090. id = atoi(cmd);
  3091. wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED id=%d", id);
  3092. cred = wpa_config_get_cred(wpa_s->conf, id);
  3093. return wpas_ctrl_remove_cred(wpa_s, cred);
  3094. }
  3095. static int wpa_supplicant_ctrl_iface_set_cred(struct wpa_supplicant *wpa_s,
  3096. char *cmd)
  3097. {
  3098. int id;
  3099. struct wpa_cred *cred;
  3100. char *name, *value;
  3101. /* cmd: "<cred id> <variable name> <value>" */
  3102. name = os_strchr(cmd, ' ');
  3103. if (name == NULL)
  3104. return -1;
  3105. *name++ = '\0';
  3106. value = os_strchr(name, ' ');
  3107. if (value == NULL)
  3108. return -1;
  3109. *value++ = '\0';
  3110. id = atoi(cmd);
  3111. wpa_printf(MSG_DEBUG, "CTRL_IFACE: SET_CRED id=%d name='%s'",
  3112. id, name);
  3113. wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
  3114. (u8 *) value, os_strlen(value));
  3115. cred = wpa_config_get_cred(wpa_s->conf, id);
  3116. if (cred == NULL) {
  3117. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred id=%d",
  3118. id);
  3119. return -1;
  3120. }
  3121. if (wpa_config_set_cred(cred, name, value, 0) < 0) {
  3122. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set cred "
  3123. "variable '%s'", name);
  3124. return -1;
  3125. }
  3126. wpa_msg(wpa_s, MSG_INFO, CRED_MODIFIED "%d %s", cred->id, name);
  3127. return 0;
  3128. }
  3129. static int wpa_supplicant_ctrl_iface_get_cred(struct wpa_supplicant *wpa_s,
  3130. char *cmd, char *buf,
  3131. size_t buflen)
  3132. {
  3133. int id;
  3134. size_t res;
  3135. struct wpa_cred *cred;
  3136. char *name, *value;
  3137. /* cmd: "<cred id> <variable name>" */
  3138. name = os_strchr(cmd, ' ');
  3139. if (name == NULL)
  3140. return -1;
  3141. *name++ = '\0';
  3142. id = atoi(cmd);
  3143. wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_CRED id=%d name='%s'",
  3144. id, name);
  3145. cred = wpa_config_get_cred(wpa_s->conf, id);
  3146. if (cred == NULL) {
  3147. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred id=%d",
  3148. id);
  3149. return -1;
  3150. }
  3151. value = wpa_config_get_cred_no_key(cred, name);
  3152. if (value == NULL) {
  3153. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to get cred variable '%s'",
  3154. name);
  3155. return -1;
  3156. }
  3157. res = os_strlcpy(buf, value, buflen);
  3158. if (res >= buflen) {
  3159. os_free(value);
  3160. return -1;
  3161. }
  3162. os_free(value);
  3163. return res;
  3164. }
  3165. #ifndef CONFIG_NO_CONFIG_WRITE
  3166. static int wpa_supplicant_ctrl_iface_save_config(struct wpa_supplicant *wpa_s)
  3167. {
  3168. int ret;
  3169. if (!wpa_s->conf->update_config) {
  3170. wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Not allowed "
  3171. "to update configuration (update_config=0)");
  3172. return -1;
  3173. }
  3174. ret = wpa_config_write(wpa_s->confname, wpa_s->conf);
  3175. if (ret) {
  3176. wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Failed to "
  3177. "update configuration");
  3178. } else {
  3179. wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Configuration"
  3180. " updated");
  3181. }
  3182. return ret;
  3183. }
  3184. #endif /* CONFIG_NO_CONFIG_WRITE */
  3185. struct cipher_info {
  3186. unsigned int capa;
  3187. const char *name;
  3188. int group_only;
  3189. };
  3190. static const struct cipher_info ciphers[] = {
  3191. { WPA_DRIVER_CAPA_ENC_CCMP_256, "CCMP-256", 0 },
  3192. { WPA_DRIVER_CAPA_ENC_GCMP_256, "GCMP-256", 0 },
  3193. { WPA_DRIVER_CAPA_ENC_CCMP, "CCMP", 0 },
  3194. { WPA_DRIVER_CAPA_ENC_GCMP, "GCMP", 0 },
  3195. { WPA_DRIVER_CAPA_ENC_TKIP, "TKIP", 0 },
  3196. { WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE, "NONE", 0 },
  3197. { WPA_DRIVER_CAPA_ENC_WEP104, "WEP104", 1 },
  3198. { WPA_DRIVER_CAPA_ENC_WEP40, "WEP40", 1 }
  3199. };
  3200. static const struct cipher_info ciphers_group_mgmt[] = {
  3201. { WPA_DRIVER_CAPA_ENC_BIP, "AES-128-CMAC", 1 },
  3202. { WPA_DRIVER_CAPA_ENC_BIP_GMAC_128, "BIP-GMAC-128", 1 },
  3203. { WPA_DRIVER_CAPA_ENC_BIP_GMAC_256, "BIP-GMAC-256", 1 },
  3204. { WPA_DRIVER_CAPA_ENC_BIP_CMAC_256, "BIP-CMAC-256", 1 },
  3205. };
  3206. static int ctrl_iface_get_capability_pairwise(int res, char *strict,
  3207. struct wpa_driver_capa *capa,
  3208. char *buf, size_t buflen)
  3209. {
  3210. int ret;
  3211. char *pos, *end;
  3212. size_t len;
  3213. unsigned int i;
  3214. pos = buf;
  3215. end = pos + buflen;
  3216. if (res < 0) {
  3217. if (strict)
  3218. return 0;
  3219. len = os_strlcpy(buf, "CCMP TKIP NONE", buflen);
  3220. if (len >= buflen)
  3221. return -1;
  3222. return len;
  3223. }
  3224. for (i = 0; i < ARRAY_SIZE(ciphers); i++) {
  3225. if (!ciphers[i].group_only && capa->enc & ciphers[i].capa) {
  3226. ret = os_snprintf(pos, end - pos, "%s%s",
  3227. pos == buf ? "" : " ",
  3228. ciphers[i].name);
  3229. if (os_snprintf_error(end - pos, ret))
  3230. return pos - buf;
  3231. pos += ret;
  3232. }
  3233. }
  3234. return pos - buf;
  3235. }
  3236. static int ctrl_iface_get_capability_group(int res, char *strict,
  3237. struct wpa_driver_capa *capa,
  3238. char *buf, size_t buflen)
  3239. {
  3240. int ret;
  3241. char *pos, *end;
  3242. size_t len;
  3243. unsigned int i;
  3244. pos = buf;
  3245. end = pos + buflen;
  3246. if (res < 0) {
  3247. if (strict)
  3248. return 0;
  3249. len = os_strlcpy(buf, "CCMP TKIP WEP104 WEP40", buflen);
  3250. if (len >= buflen)
  3251. return -1;
  3252. return len;
  3253. }
  3254. for (i = 0; i < ARRAY_SIZE(ciphers); i++) {
  3255. if (capa->enc & ciphers[i].capa) {
  3256. ret = os_snprintf(pos, end - pos, "%s%s",
  3257. pos == buf ? "" : " ",
  3258. ciphers[i].name);
  3259. if (os_snprintf_error(end - pos, ret))
  3260. return pos - buf;
  3261. pos += ret;
  3262. }
  3263. }
  3264. return pos - buf;
  3265. }
  3266. static int ctrl_iface_get_capability_group_mgmt(int res, char *strict,
  3267. struct wpa_driver_capa *capa,
  3268. char *buf, size_t buflen)
  3269. {
  3270. int ret;
  3271. char *pos, *end;
  3272. unsigned int i;
  3273. pos = buf;
  3274. end = pos + buflen;
  3275. if (res < 0)
  3276. return 0;
  3277. for (i = 0; i < ARRAY_SIZE(ciphers_group_mgmt); i++) {
  3278. if (capa->enc & ciphers_group_mgmt[i].capa) {
  3279. ret = os_snprintf(pos, end - pos, "%s%s",
  3280. pos == buf ? "" : " ",
  3281. ciphers_group_mgmt[i].name);
  3282. if (os_snprintf_error(end - pos, ret))
  3283. return pos - buf;
  3284. pos += ret;
  3285. }
  3286. }
  3287. return pos - buf;
  3288. }
  3289. static int ctrl_iface_get_capability_key_mgmt(int res, char *strict,
  3290. struct wpa_driver_capa *capa,
  3291. char *buf, size_t buflen)
  3292. {
  3293. int ret;
  3294. char *pos, *end;
  3295. size_t len;
  3296. pos = buf;
  3297. end = pos + buflen;
  3298. if (res < 0) {
  3299. if (strict)
  3300. return 0;
  3301. len = os_strlcpy(buf, "WPA-PSK WPA-EAP IEEE8021X WPA-NONE "
  3302. "NONE", buflen);
  3303. if (len >= buflen)
  3304. return -1;
  3305. return len;
  3306. }
  3307. ret = os_snprintf(pos, end - pos, "NONE IEEE8021X");
  3308. if (os_snprintf_error(end - pos, ret))
  3309. return pos - buf;
  3310. pos += ret;
  3311. if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
  3312. WPA_DRIVER_CAPA_KEY_MGMT_WPA2)) {
  3313. ret = os_snprintf(pos, end - pos, " WPA-EAP");
  3314. if (os_snprintf_error(end - pos, ret))
  3315. return pos - buf;
  3316. pos += ret;
  3317. }
  3318. if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK |
  3319. WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
  3320. ret = os_snprintf(pos, end - pos, " WPA-PSK");
  3321. if (os_snprintf_error(end - pos, ret))
  3322. return pos - buf;
  3323. pos += ret;
  3324. }
  3325. if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE) {
  3326. ret = os_snprintf(pos, end - pos, " WPA-NONE");
  3327. if (os_snprintf_error(end - pos, ret))
  3328. return pos - buf;
  3329. pos += ret;
  3330. }
  3331. #ifdef CONFIG_SUITEB
  3332. if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B) {
  3333. ret = os_snprintf(pos, end - pos, " WPA-EAP-SUITE-B");
  3334. if (os_snprintf_error(end - pos, ret))
  3335. return pos - buf;
  3336. pos += ret;
  3337. }
  3338. #endif /* CONFIG_SUITEB */
  3339. #ifdef CONFIG_SUITEB192
  3340. if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_SUITE_B_192) {
  3341. ret = os_snprintf(pos, end - pos, " WPA-EAP-SUITE-B-192");
  3342. if (os_snprintf_error(end - pos, ret))
  3343. return pos - buf;
  3344. pos += ret;
  3345. }
  3346. #endif /* CONFIG_SUITEB192 */
  3347. #ifdef CONFIG_OWE
  3348. if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_OWE) {
  3349. ret = os_snprintf(pos, end - pos, " OWE");
  3350. if (os_snprintf_error(end - pos, ret))
  3351. return pos - buf;
  3352. pos += ret;
  3353. }
  3354. #endif /* CONFIG_OWE */
  3355. #ifdef CONFIG_DPP
  3356. if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_DPP) {
  3357. ret = os_snprintf(pos, end - pos, " DPP");
  3358. if (os_snprintf_error(end - pos, ret))
  3359. return pos - buf;
  3360. pos += ret;
  3361. }
  3362. #endif /* CONFIG_DPP */
  3363. #ifdef CONFIG_FILS
  3364. if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FILS_SHA256) {
  3365. ret = os_snprintf(pos, end - pos, " FILS-SHA256");
  3366. if (os_snprintf_error(end - pos, ret))
  3367. return pos - buf;
  3368. pos += ret;
  3369. }
  3370. if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FILS_SHA384) {
  3371. ret = os_snprintf(pos, end - pos, " FILS-SHA384");
  3372. if (os_snprintf_error(end - pos, ret))
  3373. return pos - buf;
  3374. pos += ret;
  3375. }
  3376. #ifdef CONFIG_IEEE80211R
  3377. if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT_FILS_SHA256) {
  3378. ret = os_snprintf(pos, end - pos, " FT-FILS-SHA256");
  3379. if (os_snprintf_error(end - pos, ret))
  3380. return pos - buf;
  3381. pos += ret;
  3382. }
  3383. if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_FT_FILS_SHA384) {
  3384. ret = os_snprintf(pos, end - pos, " FT-FILS-SHA384");
  3385. if (os_snprintf_error(end - pos, ret))
  3386. return pos - buf;
  3387. pos += ret;
  3388. }
  3389. #endif /* CONFIG_IEEE80211R */
  3390. #endif /* CONFIG_FILS */
  3391. return pos - buf;
  3392. }
  3393. static int ctrl_iface_get_capability_proto(int res, char *strict,
  3394. struct wpa_driver_capa *capa,
  3395. char *buf, size_t buflen)
  3396. {
  3397. int ret;
  3398. char *pos, *end;
  3399. size_t len;
  3400. pos = buf;
  3401. end = pos + buflen;
  3402. if (res < 0) {
  3403. if (strict)
  3404. return 0;
  3405. len = os_strlcpy(buf, "RSN WPA", buflen);
  3406. if (len >= buflen)
  3407. return -1;
  3408. return len;
  3409. }
  3410. if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA2 |
  3411. WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
  3412. ret = os_snprintf(pos, end - pos, "%sRSN",
  3413. pos == buf ? "" : " ");
  3414. if (os_snprintf_error(end - pos, ret))
  3415. return pos - buf;
  3416. pos += ret;
  3417. }
  3418. if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
  3419. WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK)) {
  3420. ret = os_snprintf(pos, end - pos, "%sWPA",
  3421. pos == buf ? "" : " ");
  3422. if (os_snprintf_error(end - pos, ret))
  3423. return pos - buf;
  3424. pos += ret;
  3425. }
  3426. return pos - buf;
  3427. }
  3428. static int ctrl_iface_get_capability_auth_alg(struct wpa_supplicant *wpa_s,
  3429. int res, char *strict,
  3430. struct wpa_driver_capa *capa,
  3431. char *buf, size_t buflen)
  3432. {
  3433. int ret;
  3434. char *pos, *end;
  3435. size_t len;
  3436. pos = buf;
  3437. end = pos + buflen;
  3438. if (res < 0) {
  3439. if (strict)
  3440. return 0;
  3441. len = os_strlcpy(buf, "OPEN SHARED LEAP", buflen);
  3442. if (len >= buflen)
  3443. return -1;
  3444. return len;
  3445. }
  3446. if (capa->auth & (WPA_DRIVER_AUTH_OPEN)) {
  3447. ret = os_snprintf(pos, end - pos, "%sOPEN",
  3448. pos == buf ? "" : " ");
  3449. if (os_snprintf_error(end - pos, ret))
  3450. return pos - buf;
  3451. pos += ret;
  3452. }
  3453. if (capa->auth & (WPA_DRIVER_AUTH_SHARED)) {
  3454. ret = os_snprintf(pos, end - pos, "%sSHARED",
  3455. pos == buf ? "" : " ");
  3456. if (os_snprintf_error(end - pos, ret))
  3457. return pos - buf;
  3458. pos += ret;
  3459. }
  3460. if (capa->auth & (WPA_DRIVER_AUTH_LEAP)) {
  3461. ret = os_snprintf(pos, end - pos, "%sLEAP",
  3462. pos == buf ? "" : " ");
  3463. if (os_snprintf_error(end - pos, ret))
  3464. return pos - buf;
  3465. pos += ret;
  3466. }
  3467. #ifdef CONFIG_SAE
  3468. if (wpa_s->drv_flags & WPA_DRIVER_FLAGS_SAE) {
  3469. ret = os_snprintf(pos, end - pos, "%sSAE",
  3470. pos == buf ? "" : " ");
  3471. if (os_snprintf_error(end - pos, ret))
  3472. return pos - buf;
  3473. pos += ret;
  3474. }
  3475. #endif /* CONFIG_SAE */
  3476. #ifdef CONFIG_FILS
  3477. if (wpa_is_fils_supported(wpa_s)) {
  3478. ret = os_snprintf(pos, end - pos, "%sFILS_SK_WITHOUT_PFS",
  3479. pos == buf ? "" : " ");
  3480. if (os_snprintf_error(end - pos, ret))
  3481. return pos - buf;
  3482. pos += ret;
  3483. }
  3484. #ifdef CONFIG_FILS_SK_PFS
  3485. if (wpa_is_fils_sk_pfs_supported(wpa_s)) {
  3486. ret = os_snprintf(pos, end - pos, "%sFILS_SK_WITH_PFS",
  3487. pos == buf ? "" : " ");
  3488. if (os_snprintf_error(end - pos, ret))
  3489. return pos - buf;
  3490. pos += ret;
  3491. }
  3492. #endif /* CONFIG_FILS_SK_PFS */
  3493. #endif /* CONFIG_FILS */
  3494. return pos - buf;
  3495. }
  3496. static int ctrl_iface_get_capability_modes(int res, char *strict,
  3497. struct wpa_driver_capa *capa,
  3498. char *buf, size_t buflen)
  3499. {
  3500. int ret;
  3501. char *pos, *end;
  3502. size_t len;
  3503. pos = buf;
  3504. end = pos + buflen;
  3505. if (res < 0) {
  3506. if (strict)
  3507. return 0;
  3508. len = os_strlcpy(buf, "IBSS AP", buflen);
  3509. if (len >= buflen)
  3510. return -1;
  3511. return len;
  3512. }
  3513. if (capa->flags & WPA_DRIVER_FLAGS_IBSS) {
  3514. ret = os_snprintf(pos, end - pos, "%sIBSS",
  3515. pos == buf ? "" : " ");
  3516. if (os_snprintf_error(end - pos, ret))
  3517. return pos - buf;
  3518. pos += ret;
  3519. }
  3520. if (capa->flags & WPA_DRIVER_FLAGS_AP) {
  3521. ret = os_snprintf(pos, end - pos, "%sAP",
  3522. pos == buf ? "" : " ");
  3523. if (os_snprintf_error(end - pos, ret))
  3524. return pos - buf;
  3525. pos += ret;
  3526. }
  3527. #ifdef CONFIG_MESH
  3528. if (capa->flags & WPA_DRIVER_FLAGS_MESH) {
  3529. ret = os_snprintf(pos, end - pos, "%sMESH",
  3530. pos == buf ? "" : " ");
  3531. if (os_snprintf_error(end - pos, ret))
  3532. return pos - buf;
  3533. pos += ret;
  3534. }
  3535. #endif /* CONFIG_MESH */
  3536. return pos - buf;
  3537. }
  3538. static int ctrl_iface_get_capability_channels(struct wpa_supplicant *wpa_s,
  3539. char *buf, size_t buflen)
  3540. {
  3541. struct hostapd_channel_data *chnl;
  3542. int ret, i, j;
  3543. char *pos, *end, *hmode;
  3544. pos = buf;
  3545. end = pos + buflen;
  3546. for (j = 0; j < wpa_s->hw.num_modes; j++) {
  3547. switch (wpa_s->hw.modes[j].mode) {
  3548. case HOSTAPD_MODE_IEEE80211B:
  3549. hmode = "B";
  3550. break;
  3551. case HOSTAPD_MODE_IEEE80211G:
  3552. hmode = "G";
  3553. break;
  3554. case HOSTAPD_MODE_IEEE80211A:
  3555. hmode = "A";
  3556. break;
  3557. case HOSTAPD_MODE_IEEE80211AD:
  3558. hmode = "AD";
  3559. break;
  3560. default:
  3561. continue;
  3562. }
  3563. ret = os_snprintf(pos, end - pos, "Mode[%s] Channels:", hmode);
  3564. if (os_snprintf_error(end - pos, ret))
  3565. return pos - buf;
  3566. pos += ret;
  3567. chnl = wpa_s->hw.modes[j].channels;
  3568. for (i = 0; i < wpa_s->hw.modes[j].num_channels; i++) {
  3569. if (chnl[i].flag & HOSTAPD_CHAN_DISABLED)
  3570. continue;
  3571. ret = os_snprintf(pos, end - pos, " %d", chnl[i].chan);
  3572. if (os_snprintf_error(end - pos, ret))
  3573. return pos - buf;
  3574. pos += ret;
  3575. }
  3576. ret = os_snprintf(pos, end - pos, "\n");
  3577. if (os_snprintf_error(end - pos, ret))
  3578. return pos - buf;
  3579. pos += ret;
  3580. }
  3581. return pos - buf;
  3582. }
  3583. static int ctrl_iface_get_capability_freq(struct wpa_supplicant *wpa_s,
  3584. char *buf, size_t buflen)
  3585. {
  3586. struct hostapd_channel_data *chnl;
  3587. int ret, i, j;
  3588. char *pos, *end, *hmode;
  3589. pos = buf;
  3590. end = pos + buflen;
  3591. for (j = 0; j < wpa_s->hw.num_modes; j++) {
  3592. switch (wpa_s->hw.modes[j].mode) {
  3593. case HOSTAPD_MODE_IEEE80211B:
  3594. hmode = "B";
  3595. break;
  3596. case HOSTAPD_MODE_IEEE80211G:
  3597. hmode = "G";
  3598. break;
  3599. case HOSTAPD_MODE_IEEE80211A:
  3600. hmode = "A";
  3601. break;
  3602. case HOSTAPD_MODE_IEEE80211AD:
  3603. hmode = "AD";
  3604. break;
  3605. default:
  3606. continue;
  3607. }
  3608. ret = os_snprintf(pos, end - pos, "Mode[%s] Channels:\n",
  3609. hmode);
  3610. if (os_snprintf_error(end - pos, ret))
  3611. return pos - buf;
  3612. pos += ret;
  3613. chnl = wpa_s->hw.modes[j].channels;
  3614. for (i = 0; i < wpa_s->hw.modes[j].num_channels; i++) {
  3615. if (chnl[i].flag & HOSTAPD_CHAN_DISABLED)
  3616. continue;
  3617. ret = os_snprintf(pos, end - pos, " %d = %d MHz%s%s\n",
  3618. chnl[i].chan, chnl[i].freq,
  3619. chnl[i].flag & HOSTAPD_CHAN_NO_IR ?
  3620. " (NO_IR)" : "",
  3621. chnl[i].flag & HOSTAPD_CHAN_RADAR ?
  3622. " (DFS)" : "");
  3623. if (os_snprintf_error(end - pos, ret))
  3624. return pos - buf;
  3625. pos += ret;
  3626. }
  3627. ret = os_snprintf(pos, end - pos, "\n");
  3628. if (os_snprintf_error(end - pos, ret))
  3629. return pos - buf;
  3630. pos += ret;
  3631. }
  3632. return pos - buf;
  3633. }
  3634. static int wpa_supplicant_ctrl_iface_get_capability(
  3635. struct wpa_supplicant *wpa_s, const char *_field, char *buf,
  3636. size_t buflen)
  3637. {
  3638. struct wpa_driver_capa capa;
  3639. int res;
  3640. char *strict;
  3641. char field[30];
  3642. size_t len;
  3643. /* Determine whether or not strict checking was requested */
  3644. len = os_strlcpy(field, _field, sizeof(field));
  3645. if (len >= sizeof(field))
  3646. return -1;
  3647. strict = os_strchr(field, ' ');
  3648. if (strict != NULL) {
  3649. *strict++ = '\0';
  3650. if (os_strcmp(strict, "strict") != 0)
  3651. return -1;
  3652. }
  3653. wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_CAPABILITY '%s' %s",
  3654. field, strict ? strict : "");
  3655. if (os_strcmp(field, "eap") == 0) {
  3656. return eap_get_names(buf, buflen);
  3657. }
  3658. res = wpa_drv_get_capa(wpa_s, &capa);
  3659. if (os_strcmp(field, "pairwise") == 0)
  3660. return ctrl_iface_get_capability_pairwise(res, strict, &capa,
  3661. buf, buflen);
  3662. if (os_strcmp(field, "group") == 0)
  3663. return ctrl_iface_get_capability_group(res, strict, &capa,
  3664. buf, buflen);
  3665. if (os_strcmp(field, "group_mgmt") == 0)
  3666. return ctrl_iface_get_capability_group_mgmt(res, strict, &capa,
  3667. buf, buflen);
  3668. if (os_strcmp(field, "key_mgmt") == 0)
  3669. return ctrl_iface_get_capability_key_mgmt(res, strict, &capa,
  3670. buf, buflen);
  3671. if (os_strcmp(field, "proto") == 0)
  3672. return ctrl_iface_get_capability_proto(res, strict, &capa,
  3673. buf, buflen);
  3674. if (os_strcmp(field, "auth_alg") == 0)
  3675. return ctrl_iface_get_capability_auth_alg(wpa_s, res, strict,
  3676. &capa, buf, buflen);
  3677. if (os_strcmp(field, "modes") == 0)
  3678. return ctrl_iface_get_capability_modes(res, strict, &capa,
  3679. buf, buflen);
  3680. if (os_strcmp(field, "channels") == 0)
  3681. return ctrl_iface_get_capability_channels(wpa_s, buf, buflen);
  3682. if (os_strcmp(field, "freq") == 0)
  3683. return ctrl_iface_get_capability_freq(wpa_s, buf, buflen);
  3684. #ifdef CONFIG_TDLS
  3685. if (os_strcmp(field, "tdls") == 0)
  3686. return ctrl_iface_get_capability_tdls(wpa_s, buf, buflen);
  3687. #endif /* CONFIG_TDLS */
  3688. #ifdef CONFIG_ERP
  3689. if (os_strcmp(field, "erp") == 0) {
  3690. res = os_snprintf(buf, buflen, "ERP");
  3691. if (os_snprintf_error(buflen, res))
  3692. return -1;
  3693. return res;
  3694. }
  3695. #endif /* CONFIG_EPR */
  3696. #ifdef CONFIG_FIPS
  3697. if (os_strcmp(field, "fips") == 0) {
  3698. res = os_snprintf(buf, buflen, "FIPS");
  3699. if (os_snprintf_error(buflen, res))
  3700. return -1;
  3701. return res;
  3702. }
  3703. #endif /* CONFIG_FIPS */
  3704. #ifdef CONFIG_ACS
  3705. if (os_strcmp(field, "acs") == 0) {
  3706. res = os_snprintf(buf, buflen, "ACS");
  3707. if (os_snprintf_error(buflen, res))
  3708. return -1;
  3709. return res;
  3710. }
  3711. #endif /* CONFIG_ACS */
  3712. #ifdef CONFIG_FILS
  3713. if (os_strcmp(field, "fils") == 0) {
  3714. #ifdef CONFIG_FILS_SK_PFS
  3715. if (wpa_is_fils_supported(wpa_s) &&
  3716. wpa_is_fils_sk_pfs_supported(wpa_s)) {
  3717. res = os_snprintf(buf, buflen, "FILS FILS-SK-PFS");
  3718. if (os_snprintf_error(buflen, res))
  3719. return -1;
  3720. return res;
  3721. }
  3722. #endif /* CONFIG_FILS_SK_PFS */
  3723. if (wpa_is_fils_supported(wpa_s)) {
  3724. res = os_snprintf(buf, buflen, "FILS");
  3725. if (os_snprintf_error(buflen, res))
  3726. return -1;
  3727. return res;
  3728. }
  3729. }
  3730. #endif /* CONFIG_FILS */
  3731. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown GET_CAPABILITY field '%s'",
  3732. field);
  3733. return -1;
  3734. }
  3735. #ifdef CONFIG_INTERWORKING
  3736. static char * anqp_add_hex(char *pos, char *end, const char *title,
  3737. struct wpabuf *data)
  3738. {
  3739. char *start = pos;
  3740. size_t i;
  3741. int ret;
  3742. const u8 *d;
  3743. if (data == NULL)
  3744. return start;
  3745. ret = os_snprintf(pos, end - pos, "%s=", title);
  3746. if (os_snprintf_error(end - pos, ret))
  3747. return start;
  3748. pos += ret;
  3749. d = wpabuf_head_u8(data);
  3750. for (i = 0; i < wpabuf_len(data); i++) {
  3751. ret = os_snprintf(pos, end - pos, "%02x", *d++);
  3752. if (os_snprintf_error(end - pos, ret))
  3753. return start;
  3754. pos += ret;
  3755. }
  3756. ret = os_snprintf(pos, end - pos, "\n");
  3757. if (os_snprintf_error(end - pos, ret))
  3758. return start;
  3759. pos += ret;
  3760. return pos;
  3761. }
  3762. #endif /* CONFIG_INTERWORKING */
  3763. #ifdef CONFIG_FILS
  3764. static int print_fils_indication(struct wpa_bss *bss, char *pos, char *end)
  3765. {
  3766. char *start = pos;
  3767. const u8 *ie, *ie_end;
  3768. u16 info, realms;
  3769. int ret;
  3770. ie = wpa_bss_get_ie(bss, WLAN_EID_FILS_INDICATION);
  3771. if (!ie)
  3772. return 0;
  3773. ie_end = ie + 2 + ie[1];
  3774. ie += 2;
  3775. if (ie_end - ie < 2)
  3776. return -1;
  3777. info = WPA_GET_LE16(ie);
  3778. ie += 2;
  3779. ret = os_snprintf(pos, end - pos, "fils_info=%04x\n", info);
  3780. if (os_snprintf_error(end - pos, ret))
  3781. return 0;
  3782. pos += ret;
  3783. if (info & BIT(7)) {
  3784. /* Cache Identifier Included */
  3785. if (ie_end - ie < 2)
  3786. return -1;
  3787. ret = os_snprintf(pos, end - pos, "fils_cache_id=%02x%02x\n",
  3788. ie[0], ie[1]);
  3789. if (os_snprintf_error(end - pos, ret))
  3790. return 0;
  3791. pos += ret;
  3792. ie += 2;
  3793. }
  3794. if (info & BIT(8)) {
  3795. /* HESSID Included */
  3796. if (ie_end - ie < ETH_ALEN)
  3797. return -1;
  3798. ret = os_snprintf(pos, end - pos, "fils_hessid=" MACSTR "\n",
  3799. MAC2STR(ie));
  3800. if (os_snprintf_error(end - pos, ret))
  3801. return 0;
  3802. pos += ret;
  3803. ie += ETH_ALEN;
  3804. }
  3805. realms = (info & (BIT(3) | BIT(4) | BIT(5))) >> 3;
  3806. if (realms) {
  3807. if (ie_end - ie < realms * 2)
  3808. return -1;
  3809. ret = os_snprintf(pos, end - pos, "fils_realms=");
  3810. if (os_snprintf_error(end - pos, ret))
  3811. return 0;
  3812. pos += ret;
  3813. ret = wpa_snprintf_hex(pos, end - pos, ie, realms * 2);
  3814. if (ret <= 0)
  3815. return 0;
  3816. pos += ret;
  3817. ie += realms * 2;
  3818. ret = os_snprintf(pos, end - pos, "\n");
  3819. if (os_snprintf_error(end - pos, ret))
  3820. return 0;
  3821. pos += ret;
  3822. }
  3823. return pos - start;
  3824. }
  3825. #endif /* CONFIG_FILS */
  3826. static int print_bss_info(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
  3827. unsigned long mask, char *buf, size_t buflen)
  3828. {
  3829. size_t i;
  3830. int ret;
  3831. char *pos, *end;
  3832. const u8 *ie, *ie2, *osen_ie, *mesh, *owe;
  3833. pos = buf;
  3834. end = buf + buflen;
  3835. if (mask & WPA_BSS_MASK_ID) {
  3836. ret = os_snprintf(pos, end - pos, "id=%u\n", bss->id);
  3837. if (os_snprintf_error(end - pos, ret))
  3838. return 0;
  3839. pos += ret;
  3840. }
  3841. if (mask & WPA_BSS_MASK_BSSID) {
  3842. ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n",
  3843. MAC2STR(bss->bssid));
  3844. if (os_snprintf_error(end - pos, ret))
  3845. return 0;
  3846. pos += ret;
  3847. }
  3848. if (mask & WPA_BSS_MASK_FREQ) {
  3849. ret = os_snprintf(pos, end - pos, "freq=%d\n", bss->freq);
  3850. if (os_snprintf_error(end - pos, ret))
  3851. return 0;
  3852. pos += ret;
  3853. }
  3854. if (mask & WPA_BSS_MASK_BEACON_INT) {
  3855. ret = os_snprintf(pos, end - pos, "beacon_int=%d\n",
  3856. bss->beacon_int);
  3857. if (os_snprintf_error(end - pos, ret))
  3858. return 0;
  3859. pos += ret;
  3860. }
  3861. if (mask & WPA_BSS_MASK_CAPABILITIES) {
  3862. ret = os_snprintf(pos, end - pos, "capabilities=0x%04x\n",
  3863. bss->caps);
  3864. if (os_snprintf_error(end - pos, ret))
  3865. return 0;
  3866. pos += ret;
  3867. }
  3868. if (mask & WPA_BSS_MASK_QUAL) {
  3869. ret = os_snprintf(pos, end - pos, "qual=%d\n", bss->qual);
  3870. if (os_snprintf_error(end - pos, ret))
  3871. return 0;
  3872. pos += ret;
  3873. }
  3874. if (mask & WPA_BSS_MASK_NOISE) {
  3875. ret = os_snprintf(pos, end - pos, "noise=%d\n", bss->noise);
  3876. if (os_snprintf_error(end - pos, ret))
  3877. return 0;
  3878. pos += ret;
  3879. }
  3880. if (mask & WPA_BSS_MASK_LEVEL) {
  3881. ret = os_snprintf(pos, end - pos, "level=%d\n", bss->level);
  3882. if (os_snprintf_error(end - pos, ret))
  3883. return 0;
  3884. pos += ret;
  3885. }
  3886. if (mask & WPA_BSS_MASK_TSF) {
  3887. ret = os_snprintf(pos, end - pos, "tsf=%016llu\n",
  3888. (unsigned long long) bss->tsf);
  3889. if (os_snprintf_error(end - pos, ret))
  3890. return 0;
  3891. pos += ret;
  3892. }
  3893. if (mask & WPA_BSS_MASK_AGE) {
  3894. struct os_reltime now;
  3895. os_get_reltime(&now);
  3896. ret = os_snprintf(pos, end - pos, "age=%d\n",
  3897. (int) (now.sec - bss->last_update.sec));
  3898. if (os_snprintf_error(end - pos, ret))
  3899. return 0;
  3900. pos += ret;
  3901. }
  3902. if (mask & WPA_BSS_MASK_IE) {
  3903. ret = os_snprintf(pos, end - pos, "ie=");
  3904. if (os_snprintf_error(end - pos, ret))
  3905. return 0;
  3906. pos += ret;
  3907. ie = (const u8 *) (bss + 1);
  3908. for (i = 0; i < bss->ie_len; i++) {
  3909. ret = os_snprintf(pos, end - pos, "%02x", *ie++);
  3910. if (os_snprintf_error(end - pos, ret))
  3911. return 0;
  3912. pos += ret;
  3913. }
  3914. ret = os_snprintf(pos, end - pos, "\n");
  3915. if (os_snprintf_error(end - pos, ret))
  3916. return 0;
  3917. pos += ret;
  3918. }
  3919. if (mask & WPA_BSS_MASK_FLAGS) {
  3920. ret = os_snprintf(pos, end - pos, "flags=");
  3921. if (os_snprintf_error(end - pos, ret))
  3922. return 0;
  3923. pos += ret;
  3924. mesh = wpa_bss_get_ie(bss, WLAN_EID_MESH_ID);
  3925. ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
  3926. if (ie)
  3927. pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie,
  3928. 2 + ie[1]);
  3929. ie2 = wpa_bss_get_ie(bss, WLAN_EID_RSN);
  3930. if (ie2)
  3931. pos = wpa_supplicant_ie_txt(pos, end,
  3932. mesh ? "RSN" : "WPA2", ie2,
  3933. 2 + ie2[1]);
  3934. osen_ie = wpa_bss_get_vendor_ie(bss, OSEN_IE_VENDOR_TYPE);
  3935. if (osen_ie)
  3936. pos = wpa_supplicant_ie_txt(pos, end, "OSEN",
  3937. osen_ie, 2 + osen_ie[1]);
  3938. owe = wpa_bss_get_vendor_ie(bss, OWE_IE_VENDOR_TYPE);
  3939. if (owe) {
  3940. ret = os_snprintf(
  3941. pos, end - pos,
  3942. ie2 ? "[OWE-TRANS]" : "[OWE-TRANS-OPEN]");
  3943. if (os_snprintf_error(end - pos, ret))
  3944. return 0;
  3945. pos += ret;
  3946. }
  3947. pos = wpa_supplicant_wps_ie_txt(wpa_s, pos, end, bss);
  3948. if (!ie && !ie2 && !osen_ie &&
  3949. (bss->caps & IEEE80211_CAP_PRIVACY)) {
  3950. ret = os_snprintf(pos, end - pos, "[WEP]");
  3951. if (os_snprintf_error(end - pos, ret))
  3952. return 0;
  3953. pos += ret;
  3954. }
  3955. if (mesh) {
  3956. ret = os_snprintf(pos, end - pos, "[MESH]");
  3957. if (os_snprintf_error(end - pos, ret))
  3958. return 0;
  3959. pos += ret;
  3960. }
  3961. if (bss_is_dmg(bss)) {
  3962. const char *s;
  3963. ret = os_snprintf(pos, end - pos, "[DMG]");
  3964. if (os_snprintf_error(end - pos, ret))
  3965. return 0;
  3966. pos += ret;
  3967. switch (bss->caps & IEEE80211_CAP_DMG_MASK) {
  3968. case IEEE80211_CAP_DMG_IBSS:
  3969. s = "[IBSS]";
  3970. break;
  3971. case IEEE80211_CAP_DMG_AP:
  3972. s = "[ESS]";
  3973. break;
  3974. case IEEE80211_CAP_DMG_PBSS:
  3975. s = "[PBSS]";
  3976. break;
  3977. default:
  3978. s = "";
  3979. break;
  3980. }
  3981. ret = os_snprintf(pos, end - pos, "%s", s);
  3982. if (os_snprintf_error(end - pos, ret))
  3983. return 0;
  3984. pos += ret;
  3985. } else {
  3986. if (bss->caps & IEEE80211_CAP_IBSS) {
  3987. ret = os_snprintf(pos, end - pos, "[IBSS]");
  3988. if (os_snprintf_error(end - pos, ret))
  3989. return 0;
  3990. pos += ret;
  3991. }
  3992. if (bss->caps & IEEE80211_CAP_ESS) {
  3993. ret = os_snprintf(pos, end - pos, "[ESS]");
  3994. if (os_snprintf_error(end - pos, ret))
  3995. return 0;
  3996. pos += ret;
  3997. }
  3998. }
  3999. if (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) ||
  4000. wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) {
  4001. ret = os_snprintf(pos, end - pos, "[P2P]");
  4002. if (os_snprintf_error(end - pos, ret))
  4003. return 0;
  4004. pos += ret;
  4005. }
  4006. #ifdef CONFIG_HS20
  4007. if (wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE)) {
  4008. ret = os_snprintf(pos, end - pos, "[HS20]");
  4009. if (os_snprintf_error(end - pos, ret))
  4010. return 0;
  4011. pos += ret;
  4012. }
  4013. #endif /* CONFIG_HS20 */
  4014. #ifdef CONFIG_FILS
  4015. if (wpa_bss_get_ie(bss, WLAN_EID_FILS_INDICATION)) {
  4016. ret = os_snprintf(pos, end - pos, "[FILS]");
  4017. if (os_snprintf_error(end - pos, ret))
  4018. return 0;
  4019. pos += ret;
  4020. }
  4021. #endif /* CONFIG_FILS */
  4022. ret = os_snprintf(pos, end - pos, "\n");
  4023. if (os_snprintf_error(end - pos, ret))
  4024. return 0;
  4025. pos += ret;
  4026. }
  4027. if (mask & WPA_BSS_MASK_SSID) {
  4028. ret = os_snprintf(pos, end - pos, "ssid=%s\n",
  4029. wpa_ssid_txt(bss->ssid, bss->ssid_len));
  4030. if (os_snprintf_error(end - pos, ret))
  4031. return 0;
  4032. pos += ret;
  4033. }
  4034. #ifdef CONFIG_WPS
  4035. if (mask & WPA_BSS_MASK_WPS_SCAN) {
  4036. ie = (const u8 *) (bss + 1);
  4037. ret = wpas_wps_scan_result_text(ie, bss->ie_len, pos, end);
  4038. if (ret >= end - pos)
  4039. return 0;
  4040. if (ret > 0)
  4041. pos += ret;
  4042. }
  4043. #endif /* CONFIG_WPS */
  4044. #ifdef CONFIG_P2P
  4045. if (mask & WPA_BSS_MASK_P2P_SCAN) {
  4046. ie = (const u8 *) (bss + 1);
  4047. ret = wpas_p2p_scan_result_text(ie, bss->ie_len, pos, end);
  4048. if (ret >= end - pos)
  4049. return 0;
  4050. if (ret > 0)
  4051. pos += ret;
  4052. }
  4053. #endif /* CONFIG_P2P */
  4054. #ifdef CONFIG_WIFI_DISPLAY
  4055. if (mask & WPA_BSS_MASK_WIFI_DISPLAY) {
  4056. struct wpabuf *wfd;
  4057. ie = (const u8 *) (bss + 1);
  4058. wfd = ieee802_11_vendor_ie_concat(ie, bss->ie_len,
  4059. WFD_IE_VENDOR_TYPE);
  4060. if (wfd) {
  4061. ret = os_snprintf(pos, end - pos, "wfd_subelems=");
  4062. if (os_snprintf_error(end - pos, ret)) {
  4063. wpabuf_free(wfd);
  4064. return 0;
  4065. }
  4066. pos += ret;
  4067. pos += wpa_snprintf_hex(pos, end - pos,
  4068. wpabuf_head(wfd),
  4069. wpabuf_len(wfd));
  4070. wpabuf_free(wfd);
  4071. ret = os_snprintf(pos, end - pos, "\n");
  4072. if (os_snprintf_error(end - pos, ret))
  4073. return 0;
  4074. pos += ret;
  4075. }
  4076. }
  4077. #endif /* CONFIG_WIFI_DISPLAY */
  4078. #ifdef CONFIG_INTERWORKING
  4079. if ((mask & WPA_BSS_MASK_INTERNETW) && bss->anqp) {
  4080. struct wpa_bss_anqp *anqp = bss->anqp;
  4081. struct wpa_bss_anqp_elem *elem;
  4082. pos = anqp_add_hex(pos, end, "anqp_capability_list",
  4083. anqp->capability_list);
  4084. pos = anqp_add_hex(pos, end, "anqp_venue_name",
  4085. anqp->venue_name);
  4086. pos = anqp_add_hex(pos, end, "anqp_network_auth_type",
  4087. anqp->network_auth_type);
  4088. pos = anqp_add_hex(pos, end, "anqp_roaming_consortium",
  4089. anqp->roaming_consortium);
  4090. pos = anqp_add_hex(pos, end, "anqp_ip_addr_type_availability",
  4091. anqp->ip_addr_type_availability);
  4092. pos = anqp_add_hex(pos, end, "anqp_nai_realm",
  4093. anqp->nai_realm);
  4094. pos = anqp_add_hex(pos, end, "anqp_3gpp", anqp->anqp_3gpp);
  4095. pos = anqp_add_hex(pos, end, "anqp_domain_name",
  4096. anqp->domain_name);
  4097. pos = anqp_add_hex(pos, end, "anqp_fils_realm_info",
  4098. anqp->fils_realm_info);
  4099. #ifdef CONFIG_HS20
  4100. pos = anqp_add_hex(pos, end, "hs20_capability_list",
  4101. anqp->hs20_capability_list);
  4102. pos = anqp_add_hex(pos, end, "hs20_operator_friendly_name",
  4103. anqp->hs20_operator_friendly_name);
  4104. pos = anqp_add_hex(pos, end, "hs20_wan_metrics",
  4105. anqp->hs20_wan_metrics);
  4106. pos = anqp_add_hex(pos, end, "hs20_connection_capability",
  4107. anqp->hs20_connection_capability);
  4108. pos = anqp_add_hex(pos, end, "hs20_operating_class",
  4109. anqp->hs20_operating_class);
  4110. pos = anqp_add_hex(pos, end, "hs20_osu_providers_list",
  4111. anqp->hs20_osu_providers_list);
  4112. #endif /* CONFIG_HS20 */
  4113. dl_list_for_each(elem, &anqp->anqp_elems,
  4114. struct wpa_bss_anqp_elem, list) {
  4115. char title[20];
  4116. os_snprintf(title, sizeof(title), "anqp[%u]",
  4117. elem->infoid);
  4118. pos = anqp_add_hex(pos, end, title, elem->payload);
  4119. }
  4120. }
  4121. #endif /* CONFIG_INTERWORKING */
  4122. #ifdef CONFIG_MESH
  4123. if (mask & WPA_BSS_MASK_MESH_SCAN) {
  4124. ie = (const u8 *) (bss + 1);
  4125. ret = wpas_mesh_scan_result_text(ie, bss->ie_len, pos, end);
  4126. if (ret >= end - pos)
  4127. return 0;
  4128. if (ret > 0)
  4129. pos += ret;
  4130. }
  4131. #endif /* CONFIG_MESH */
  4132. if (mask & WPA_BSS_MASK_SNR) {
  4133. ret = os_snprintf(pos, end - pos, "snr=%d\n", bss->snr);
  4134. if (os_snprintf_error(end - pos, ret))
  4135. return 0;
  4136. pos += ret;
  4137. }
  4138. if (mask & WPA_BSS_MASK_EST_THROUGHPUT) {
  4139. ret = os_snprintf(pos, end - pos, "est_throughput=%d\n",
  4140. bss->est_throughput);
  4141. if (os_snprintf_error(end - pos, ret))
  4142. return 0;
  4143. pos += ret;
  4144. }
  4145. #ifdef CONFIG_FST
  4146. if (mask & WPA_BSS_MASK_FST) {
  4147. ret = fst_ctrl_iface_mb_info(bss->bssid, pos, end - pos);
  4148. if (ret < 0 || ret >= end - pos)
  4149. return 0;
  4150. pos += ret;
  4151. }
  4152. #endif /* CONFIG_FST */
  4153. if (mask & WPA_BSS_MASK_UPDATE_IDX) {
  4154. ret = os_snprintf(pos, end - pos, "update_idx=%u\n",
  4155. bss->last_update_idx);
  4156. if (os_snprintf_error(end - pos, ret))
  4157. return 0;
  4158. pos += ret;
  4159. }
  4160. if ((mask & WPA_BSS_MASK_BEACON_IE) && bss->beacon_ie_len) {
  4161. ret = os_snprintf(pos, end - pos, "beacon_ie=");
  4162. if (os_snprintf_error(end - pos, ret))
  4163. return 0;
  4164. pos += ret;
  4165. ie = (const u8 *) (bss + 1);
  4166. ie += bss->ie_len;
  4167. for (i = 0; i < bss->beacon_ie_len; i++) {
  4168. ret = os_snprintf(pos, end - pos, "%02x", *ie++);
  4169. if (os_snprintf_error(end - pos, ret))
  4170. return 0;
  4171. pos += ret;
  4172. }
  4173. ret = os_snprintf(pos, end - pos, "\n");
  4174. if (os_snprintf_error(end - pos, ret))
  4175. return 0;
  4176. pos += ret;
  4177. }
  4178. #ifdef CONFIG_FILS
  4179. if (mask & WPA_BSS_MASK_FILS_INDICATION) {
  4180. ret = print_fils_indication(bss, pos, end);
  4181. if (ret < 0)
  4182. return 0;
  4183. pos += ret;
  4184. }
  4185. #endif /* CONFIG_FILS */
  4186. if (mask & WPA_BSS_MASK_DELIM) {
  4187. ret = os_snprintf(pos, end - pos, "====\n");
  4188. if (os_snprintf_error(end - pos, ret))
  4189. return 0;
  4190. pos += ret;
  4191. }
  4192. return pos - buf;
  4193. }
  4194. static int wpa_supplicant_ctrl_iface_bss(struct wpa_supplicant *wpa_s,
  4195. const char *cmd, char *buf,
  4196. size_t buflen)
  4197. {
  4198. u8 bssid[ETH_ALEN];
  4199. size_t i;
  4200. struct wpa_bss *bss;
  4201. struct wpa_bss *bsslast = NULL;
  4202. struct dl_list *next;
  4203. int ret = 0;
  4204. int len;
  4205. char *ctmp, *end = buf + buflen;
  4206. unsigned long mask = WPA_BSS_MASK_ALL;
  4207. if (os_strncmp(cmd, "RANGE=", 6) == 0) {
  4208. if (os_strncmp(cmd + 6, "ALL", 3) == 0) {
  4209. bss = dl_list_first(&wpa_s->bss_id, struct wpa_bss,
  4210. list_id);
  4211. bsslast = dl_list_last(&wpa_s->bss_id, struct wpa_bss,
  4212. list_id);
  4213. } else { /* N1-N2 */
  4214. unsigned int id1, id2;
  4215. if ((ctmp = os_strchr(cmd + 6, '-')) == NULL) {
  4216. wpa_printf(MSG_INFO, "Wrong BSS range "
  4217. "format");
  4218. return 0;
  4219. }
  4220. if (*(cmd + 6) == '-')
  4221. id1 = 0;
  4222. else
  4223. id1 = atoi(cmd + 6);
  4224. ctmp++;
  4225. if (*ctmp >= '0' && *ctmp <= '9')
  4226. id2 = atoi(ctmp);
  4227. else
  4228. id2 = (unsigned int) -1;
  4229. bss = wpa_bss_get_id_range(wpa_s, id1, id2);
  4230. if (id2 == (unsigned int) -1)
  4231. bsslast = dl_list_last(&wpa_s->bss_id,
  4232. struct wpa_bss,
  4233. list_id);
  4234. else {
  4235. bsslast = wpa_bss_get_id(wpa_s, id2);
  4236. if (bsslast == NULL && bss && id2 > id1) {
  4237. struct wpa_bss *tmp = bss;
  4238. for (;;) {
  4239. next = tmp->list_id.next;
  4240. if (next == &wpa_s->bss_id)
  4241. break;
  4242. tmp = dl_list_entry(
  4243. next, struct wpa_bss,
  4244. list_id);
  4245. if (tmp->id > id2)
  4246. break;
  4247. bsslast = tmp;
  4248. }
  4249. }
  4250. }
  4251. }
  4252. } else if (os_strncmp(cmd, "FIRST", 5) == 0)
  4253. bss = dl_list_first(&wpa_s->bss_id, struct wpa_bss, list_id);
  4254. else if (os_strncmp(cmd, "LAST", 4) == 0)
  4255. bss = dl_list_last(&wpa_s->bss_id, struct wpa_bss, list_id);
  4256. else if (os_strncmp(cmd, "ID-", 3) == 0) {
  4257. i = atoi(cmd + 3);
  4258. bss = wpa_bss_get_id(wpa_s, i);
  4259. } else if (os_strncmp(cmd, "NEXT-", 5) == 0) {
  4260. i = atoi(cmd + 5);
  4261. bss = wpa_bss_get_id(wpa_s, i);
  4262. if (bss) {
  4263. next = bss->list_id.next;
  4264. if (next == &wpa_s->bss_id)
  4265. bss = NULL;
  4266. else
  4267. bss = dl_list_entry(next, struct wpa_bss,
  4268. list_id);
  4269. }
  4270. } else if (os_strncmp(cmd, "CURRENT", 7) == 0) {
  4271. bss = wpa_s->current_bss;
  4272. #ifdef CONFIG_P2P
  4273. } else if (os_strncmp(cmd, "p2p_dev_addr=", 13) == 0) {
  4274. if (hwaddr_aton(cmd + 13, bssid) == 0)
  4275. bss = wpa_bss_get_p2p_dev_addr(wpa_s, bssid);
  4276. else
  4277. bss = NULL;
  4278. #endif /* CONFIG_P2P */
  4279. } else if (hwaddr_aton(cmd, bssid) == 0)
  4280. bss = wpa_bss_get_bssid(wpa_s, bssid);
  4281. else {
  4282. struct wpa_bss *tmp;
  4283. i = atoi(cmd);
  4284. bss = NULL;
  4285. dl_list_for_each(tmp, &wpa_s->bss_id, struct wpa_bss, list_id)
  4286. {
  4287. if (i-- == 0) {
  4288. bss = tmp;
  4289. break;
  4290. }
  4291. }
  4292. }
  4293. if ((ctmp = os_strstr(cmd, "MASK=")) != NULL) {
  4294. mask = strtoul(ctmp + 5, NULL, 0x10);
  4295. if (mask == 0)
  4296. mask = WPA_BSS_MASK_ALL;
  4297. }
  4298. if (bss == NULL)
  4299. return 0;
  4300. if (bsslast == NULL)
  4301. bsslast = bss;
  4302. do {
  4303. len = print_bss_info(wpa_s, bss, mask, buf, buflen);
  4304. ret += len;
  4305. buf += len;
  4306. buflen -= len;
  4307. if (bss == bsslast) {
  4308. if ((mask & WPA_BSS_MASK_DELIM) && len &&
  4309. (bss == dl_list_last(&wpa_s->bss_id,
  4310. struct wpa_bss, list_id))) {
  4311. int res;
  4312. res = os_snprintf(buf - 5, end - buf + 5,
  4313. "####\n");
  4314. if (os_snprintf_error(end - buf + 5, res)) {
  4315. wpa_printf(MSG_DEBUG,
  4316. "Could not add end delim");
  4317. }
  4318. }
  4319. break;
  4320. }
  4321. next = bss->list_id.next;
  4322. if (next == &wpa_s->bss_id)
  4323. break;
  4324. bss = dl_list_entry(next, struct wpa_bss, list_id);
  4325. } while (bss && len);
  4326. return ret;
  4327. }
  4328. static int wpa_supplicant_ctrl_iface_ap_scan(
  4329. struct wpa_supplicant *wpa_s, char *cmd)
  4330. {
  4331. int ap_scan = atoi(cmd);
  4332. return wpa_supplicant_set_ap_scan(wpa_s, ap_scan);
  4333. }
  4334. static int wpa_supplicant_ctrl_iface_scan_interval(
  4335. struct wpa_supplicant *wpa_s, char *cmd)
  4336. {
  4337. int scan_int = atoi(cmd);
  4338. return wpa_supplicant_set_scan_interval(wpa_s, scan_int);
  4339. }
  4340. static int wpa_supplicant_ctrl_iface_bss_expire_age(
  4341. struct wpa_supplicant *wpa_s, char *cmd)
  4342. {
  4343. int expire_age = atoi(cmd);
  4344. return wpa_supplicant_set_bss_expiration_age(wpa_s, expire_age);
  4345. }
  4346. static int wpa_supplicant_ctrl_iface_bss_expire_count(
  4347. struct wpa_supplicant *wpa_s, char *cmd)
  4348. {
  4349. int expire_count = atoi(cmd);
  4350. return wpa_supplicant_set_bss_expiration_count(wpa_s, expire_count);
  4351. }
  4352. static void wpa_supplicant_ctrl_iface_bss_flush(
  4353. struct wpa_supplicant *wpa_s, char *cmd)
  4354. {
  4355. int flush_age = atoi(cmd);
  4356. if (flush_age == 0)
  4357. wpa_bss_flush(wpa_s);
  4358. else
  4359. wpa_bss_flush_by_age(wpa_s, flush_age);
  4360. }
  4361. #ifdef CONFIG_TESTING_OPTIONS
  4362. static void wpa_supplicant_ctrl_iface_drop_sa(struct wpa_supplicant *wpa_s)
  4363. {
  4364. wpa_printf(MSG_DEBUG, "Dropping SA without deauthentication");
  4365. /* MLME-DELETEKEYS.request */
  4366. wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 0, 0, NULL, 0, NULL, 0);
  4367. wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 1, 0, NULL, 0, NULL, 0);
  4368. wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 2, 0, NULL, 0, NULL, 0);
  4369. wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 3, 0, NULL, 0, NULL, 0);
  4370. #ifdef CONFIG_IEEE80211W
  4371. wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 4, 0, NULL, 0, NULL, 0);
  4372. wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 5, 0, NULL, 0, NULL, 0);
  4373. #endif /* CONFIG_IEEE80211W */
  4374. wpa_drv_set_key(wpa_s, WPA_ALG_NONE, wpa_s->bssid, 0, 0, NULL, 0, NULL,
  4375. 0);
  4376. /* MLME-SETPROTECTION.request(None) */
  4377. wpa_drv_mlme_setprotection(wpa_s, wpa_s->bssid,
  4378. MLME_SETPROTECTION_PROTECT_TYPE_NONE,
  4379. MLME_SETPROTECTION_KEY_TYPE_PAIRWISE);
  4380. wpa_sm_drop_sa(wpa_s->wpa);
  4381. }
  4382. #endif /* CONFIG_TESTING_OPTIONS */
  4383. static int wpa_supplicant_ctrl_iface_roam(struct wpa_supplicant *wpa_s,
  4384. char *addr)
  4385. {
  4386. #ifdef CONFIG_NO_SCAN_PROCESSING
  4387. return -1;
  4388. #else /* CONFIG_NO_SCAN_PROCESSING */
  4389. u8 bssid[ETH_ALEN];
  4390. struct wpa_bss *bss;
  4391. struct wpa_ssid *ssid = wpa_s->current_ssid;
  4392. if (hwaddr_aton(addr, bssid)) {
  4393. wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: invalid "
  4394. "address '%s'", addr);
  4395. return -1;
  4396. }
  4397. wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM " MACSTR, MAC2STR(bssid));
  4398. if (!ssid) {
  4399. wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: No network "
  4400. "configuration known for the target AP");
  4401. return -1;
  4402. }
  4403. bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len);
  4404. if (!bss) {
  4405. wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: Target AP not found "
  4406. "from BSS table");
  4407. return -1;
  4408. }
  4409. /*
  4410. * TODO: Find best network configuration block from configuration to
  4411. * allow roaming to other networks
  4412. */
  4413. wpa_s->reassociate = 1;
  4414. wpa_supplicant_connect(wpa_s, bss, ssid);
  4415. return 0;
  4416. #endif /* CONFIG_NO_SCAN_PROCESSING */
  4417. }
  4418. #ifdef CONFIG_P2P
  4419. static int p2p_ctrl_find(struct wpa_supplicant *wpa_s, char *cmd)
  4420. {
  4421. unsigned int timeout = atoi(cmd);
  4422. enum p2p_discovery_type type = P2P_FIND_START_WITH_FULL;
  4423. u8 dev_id[ETH_ALEN], *_dev_id = NULL;
  4424. u8 dev_type[WPS_DEV_TYPE_LEN], *_dev_type = NULL;
  4425. char *pos;
  4426. unsigned int search_delay;
  4427. const char *_seek[P2P_MAX_QUERY_HASH + 1], **seek = NULL;
  4428. u8 seek_count = 0;
  4429. int freq = 0;
  4430. if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
  4431. wpa_dbg(wpa_s, MSG_INFO,
  4432. "Reject P2P_FIND since interface is disabled");
  4433. return -1;
  4434. }
  4435. if (os_strstr(cmd, "type=social"))
  4436. type = P2P_FIND_ONLY_SOCIAL;
  4437. else if (os_strstr(cmd, "type=progressive"))
  4438. type = P2P_FIND_PROGRESSIVE;
  4439. pos = os_strstr(cmd, "dev_id=");
  4440. if (pos) {
  4441. pos += 7;
  4442. if (hwaddr_aton(pos, dev_id))
  4443. return -1;
  4444. _dev_id = dev_id;
  4445. }
  4446. pos = os_strstr(cmd, "dev_type=");
  4447. if (pos) {
  4448. pos += 9;
  4449. if (wps_dev_type_str2bin(pos, dev_type) < 0)
  4450. return -1;
  4451. _dev_type = dev_type;
  4452. }
  4453. pos = os_strstr(cmd, "delay=");
  4454. if (pos) {
  4455. pos += 6;
  4456. search_delay = atoi(pos);
  4457. } else
  4458. search_delay = wpas_p2p_search_delay(wpa_s);
  4459. pos = os_strstr(cmd, "freq=");
  4460. if (pos) {
  4461. pos += 5;
  4462. freq = atoi(pos);
  4463. if (freq <= 0)
  4464. return -1;
  4465. }
  4466. /* Must be searched for last, because it adds nul termination */
  4467. pos = os_strstr(cmd, " seek=");
  4468. if (pos)
  4469. pos += 6;
  4470. while (pos && seek_count < P2P_MAX_QUERY_HASH + 1) {
  4471. char *term;
  4472. _seek[seek_count++] = pos;
  4473. seek = _seek;
  4474. term = os_strchr(pos, ' ');
  4475. if (!term)
  4476. break;
  4477. *term = '\0';
  4478. pos = os_strstr(term + 1, "seek=");
  4479. if (pos)
  4480. pos += 5;
  4481. }
  4482. if (seek_count > P2P_MAX_QUERY_HASH) {
  4483. seek[0] = NULL;
  4484. seek_count = 1;
  4485. }
  4486. return wpas_p2p_find(wpa_s, timeout, type, _dev_type != NULL, _dev_type,
  4487. _dev_id, search_delay, seek_count, seek, freq);
  4488. }
  4489. static int p2ps_ctrl_parse_cpt_priority(const char *pos, u8 *cpt)
  4490. {
  4491. const char *last = NULL;
  4492. const char *token;
  4493. long int token_len;
  4494. unsigned int i;
  4495. /* Expected predefined CPT names delimited by ':' */
  4496. for (i = 0; (token = cstr_token(pos, ": \t", &last)); i++) {
  4497. if (i >= P2PS_FEATURE_CAPAB_CPT_MAX) {
  4498. wpa_printf(MSG_ERROR,
  4499. "P2PS: CPT name list is too long, expected up to %d names",
  4500. P2PS_FEATURE_CAPAB_CPT_MAX);
  4501. cpt[0] = 0;
  4502. return -1;
  4503. }
  4504. token_len = last - token;
  4505. if (token_len == 3 &&
  4506. os_memcmp(token, "UDP", token_len) == 0) {
  4507. cpt[i] = P2PS_FEATURE_CAPAB_UDP_TRANSPORT;
  4508. } else if (token_len == 3 &&
  4509. os_memcmp(token, "MAC", token_len) == 0) {
  4510. cpt[i] = P2PS_FEATURE_CAPAB_MAC_TRANSPORT;
  4511. } else {
  4512. wpa_printf(MSG_ERROR,
  4513. "P2PS: Unsupported CPT name '%s'", token);
  4514. cpt[0] = 0;
  4515. return -1;
  4516. }
  4517. if (isblank((unsigned char) *last)) {
  4518. i++;
  4519. break;
  4520. }
  4521. }
  4522. cpt[i] = 0;
  4523. return 0;
  4524. }
  4525. static struct p2ps_provision * p2p_parse_asp_provision_cmd(const char *cmd)
  4526. {
  4527. struct p2ps_provision *p2ps_prov;
  4528. char *pos;
  4529. size_t info_len = 0;
  4530. char *info = NULL;
  4531. u8 role = P2PS_SETUP_NONE;
  4532. long long unsigned val;
  4533. int i;
  4534. pos = os_strstr(cmd, "info=");
  4535. if (pos) {
  4536. pos += 5;
  4537. info_len = os_strlen(pos);
  4538. if (info_len) {
  4539. info = os_malloc(info_len + 1);
  4540. if (info) {
  4541. info_len = utf8_unescape(pos, info_len,
  4542. info, info_len + 1);
  4543. } else
  4544. info_len = 0;
  4545. }
  4546. }
  4547. p2ps_prov = os_zalloc(sizeof(struct p2ps_provision) + info_len + 1);
  4548. if (p2ps_prov == NULL) {
  4549. os_free(info);
  4550. return NULL;
  4551. }
  4552. if (info) {
  4553. os_memcpy(p2ps_prov->info, info, info_len);
  4554. p2ps_prov->info[info_len] = '\0';
  4555. os_free(info);
  4556. }
  4557. pos = os_strstr(cmd, "status=");
  4558. if (pos)
  4559. p2ps_prov->status = atoi(pos + 7);
  4560. else
  4561. p2ps_prov->status = -1;
  4562. pos = os_strstr(cmd, "adv_id=");
  4563. if (!pos || sscanf(pos + 7, "%llx", &val) != 1 || val > 0xffffffffULL)
  4564. goto invalid_args;
  4565. p2ps_prov->adv_id = val;
  4566. pos = os_strstr(cmd, "method=");
  4567. if (pos)
  4568. p2ps_prov->method = strtol(pos + 7, NULL, 16);
  4569. else
  4570. p2ps_prov->method = 0;
  4571. pos = os_strstr(cmd, "session=");
  4572. if (!pos || sscanf(pos + 8, "%llx", &val) != 1 || val > 0xffffffffULL)
  4573. goto invalid_args;
  4574. p2ps_prov->session_id = val;
  4575. pos = os_strstr(cmd, "adv_mac=");
  4576. if (!pos || hwaddr_aton(pos + 8, p2ps_prov->adv_mac))
  4577. goto invalid_args;
  4578. pos = os_strstr(cmd, "session_mac=");
  4579. if (!pos || hwaddr_aton(pos + 12, p2ps_prov->session_mac))
  4580. goto invalid_args;
  4581. pos = os_strstr(cmd, "cpt=");
  4582. if (pos) {
  4583. if (p2ps_ctrl_parse_cpt_priority(pos + 4,
  4584. p2ps_prov->cpt_priority))
  4585. goto invalid_args;
  4586. } else {
  4587. p2ps_prov->cpt_priority[0] = P2PS_FEATURE_CAPAB_UDP_TRANSPORT;
  4588. }
  4589. for (i = 0; p2ps_prov->cpt_priority[i]; i++)
  4590. p2ps_prov->cpt_mask |= p2ps_prov->cpt_priority[i];
  4591. /* force conncap with tstCap (no sanity checks) */
  4592. pos = os_strstr(cmd, "tstCap=");
  4593. if (pos) {
  4594. role = strtol(pos + 7, NULL, 16);
  4595. } else {
  4596. pos = os_strstr(cmd, "role=");
  4597. if (pos) {
  4598. role = strtol(pos + 5, NULL, 16);
  4599. if (role != P2PS_SETUP_CLIENT &&
  4600. role != P2PS_SETUP_GROUP_OWNER)
  4601. role = P2PS_SETUP_NONE;
  4602. }
  4603. }
  4604. p2ps_prov->role = role;
  4605. return p2ps_prov;
  4606. invalid_args:
  4607. os_free(p2ps_prov);
  4608. return NULL;
  4609. }
  4610. static int p2p_ctrl_asp_provision_resp(struct wpa_supplicant *wpa_s, char *cmd)
  4611. {
  4612. u8 addr[ETH_ALEN];
  4613. struct p2ps_provision *p2ps_prov;
  4614. char *pos;
  4615. /* <addr> id=<adv_id> [role=<conncap>] [info=<infodata>] */
  4616. wpa_printf(MSG_DEBUG, "%s: %s", __func__, cmd);
  4617. if (hwaddr_aton(cmd, addr))
  4618. return -1;
  4619. pos = cmd + 17;
  4620. if (*pos != ' ')
  4621. return -1;
  4622. p2ps_prov = p2p_parse_asp_provision_cmd(pos);
  4623. if (!p2ps_prov)
  4624. return -1;
  4625. if (p2ps_prov->status < 0) {
  4626. os_free(p2ps_prov);
  4627. return -1;
  4628. }
  4629. return wpas_p2p_prov_disc(wpa_s, addr, NULL, WPAS_P2P_PD_FOR_ASP,
  4630. p2ps_prov);
  4631. }
  4632. static int p2p_ctrl_asp_provision(struct wpa_supplicant *wpa_s, char *cmd)
  4633. {
  4634. u8 addr[ETH_ALEN];
  4635. struct p2ps_provision *p2ps_prov;
  4636. char *pos;
  4637. /* <addr> id=<adv_id> adv_mac=<adv_mac> conncap=<conncap>
  4638. * session=<ses_id> mac=<ses_mac> [info=<infodata>]
  4639. */
  4640. wpa_printf(MSG_DEBUG, "%s: %s", __func__, cmd);
  4641. if (hwaddr_aton(cmd, addr))
  4642. return -1;
  4643. pos = cmd + 17;
  4644. if (*pos != ' ')
  4645. return -1;
  4646. p2ps_prov = p2p_parse_asp_provision_cmd(pos);
  4647. if (!p2ps_prov)
  4648. return -1;
  4649. p2ps_prov->pd_seeker = 1;
  4650. return wpas_p2p_prov_disc(wpa_s, addr, NULL, WPAS_P2P_PD_FOR_ASP,
  4651. p2ps_prov);
  4652. }
  4653. static int parse_freq(int chwidth, int freq2)
  4654. {
  4655. if (freq2 < 0)
  4656. return -1;
  4657. if (freq2)
  4658. return VHT_CHANWIDTH_80P80MHZ;
  4659. switch (chwidth) {
  4660. case 0:
  4661. case 20:
  4662. case 40:
  4663. return VHT_CHANWIDTH_USE_HT;
  4664. case 80:
  4665. return VHT_CHANWIDTH_80MHZ;
  4666. case 160:
  4667. return VHT_CHANWIDTH_160MHZ;
  4668. default:
  4669. wpa_printf(MSG_DEBUG, "Unknown max oper bandwidth: %d",
  4670. chwidth);
  4671. return -1;
  4672. }
  4673. }
  4674. static int p2p_ctrl_connect(struct wpa_supplicant *wpa_s, char *cmd,
  4675. char *buf, size_t buflen)
  4676. {
  4677. u8 addr[ETH_ALEN];
  4678. char *pos, *pos2;
  4679. char *pin = NULL;
  4680. enum p2p_wps_method wps_method;
  4681. int new_pin;
  4682. int ret;
  4683. int persistent_group, persistent_id = -1;
  4684. int join;
  4685. int auth;
  4686. int automatic;
  4687. int go_intent = -1;
  4688. int freq = 0;
  4689. int pd;
  4690. int ht40, vht, max_oper_chwidth, chwidth = 0, freq2 = 0;
  4691. u8 _group_ssid[SSID_MAX_LEN], *group_ssid = NULL;
  4692. size_t group_ssid_len = 0;
  4693. if (!wpa_s->global->p2p_init_wpa_s)
  4694. return -1;
  4695. if (wpa_s->global->p2p_init_wpa_s != wpa_s) {
  4696. wpa_dbg(wpa_s, MSG_DEBUG, "Direct P2P_CONNECT command to %s",
  4697. wpa_s->global->p2p_init_wpa_s->ifname);
  4698. wpa_s = wpa_s->global->p2p_init_wpa_s;
  4699. }
  4700. /* <addr> <"pbc" | "pin" | PIN> [label|display|keypad|p2ps]
  4701. * [persistent|persistent=<network id>]
  4702. * [join] [auth] [go_intent=<0..15>] [freq=<in MHz>] [provdisc]
  4703. * [ht40] [vht] [auto] [ssid=<hexdump>] */
  4704. if (hwaddr_aton(cmd, addr))
  4705. return -1;
  4706. pos = cmd + 17;
  4707. if (*pos != ' ')
  4708. return -1;
  4709. pos++;
  4710. persistent_group = os_strstr(pos, " persistent") != NULL;
  4711. pos2 = os_strstr(pos, " persistent=");
  4712. if (pos2) {
  4713. struct wpa_ssid *ssid;
  4714. persistent_id = atoi(pos2 + 12);
  4715. ssid = wpa_config_get_network(wpa_s->conf, persistent_id);
  4716. if (ssid == NULL || ssid->disabled != 2 ||
  4717. ssid->mode != WPAS_MODE_P2P_GO) {
  4718. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
  4719. "SSID id=%d for persistent P2P group (GO)",
  4720. persistent_id);
  4721. return -1;
  4722. }
  4723. }
  4724. join = os_strstr(pos, " join") != NULL;
  4725. auth = os_strstr(pos, " auth") != NULL;
  4726. automatic = os_strstr(pos, " auto") != NULL;
  4727. pd = os_strstr(pos, " provdisc") != NULL;
  4728. vht = (os_strstr(cmd, " vht") != NULL) || wpa_s->conf->p2p_go_vht;
  4729. ht40 = (os_strstr(cmd, " ht40") != NULL) || wpa_s->conf->p2p_go_ht40 ||
  4730. vht;
  4731. pos2 = os_strstr(pos, " go_intent=");
  4732. if (pos2) {
  4733. pos2 += 11;
  4734. go_intent = atoi(pos2);
  4735. if (go_intent < 0 || go_intent > 15)
  4736. return -1;
  4737. }
  4738. pos2 = os_strstr(pos, " freq=");
  4739. if (pos2) {
  4740. pos2 += 6;
  4741. freq = atoi(pos2);
  4742. if (freq <= 0)
  4743. return -1;
  4744. }
  4745. pos2 = os_strstr(pos, " freq2=");
  4746. if (pos2)
  4747. freq2 = atoi(pos2 + 7);
  4748. pos2 = os_strstr(pos, " max_oper_chwidth=");
  4749. if (pos2)
  4750. chwidth = atoi(pos2 + 18);
  4751. max_oper_chwidth = parse_freq(chwidth, freq2);
  4752. if (max_oper_chwidth < 0)
  4753. return -1;
  4754. pos2 = os_strstr(pos, " ssid=");
  4755. if (pos2) {
  4756. char *end;
  4757. pos2 += 6;
  4758. end = os_strchr(pos2, ' ');
  4759. if (!end)
  4760. group_ssid_len = os_strlen(pos2) / 2;
  4761. else
  4762. group_ssid_len = (end - pos2) / 2;
  4763. if (group_ssid_len == 0 || group_ssid_len > SSID_MAX_LEN ||
  4764. hexstr2bin(pos2, _group_ssid, group_ssid_len) < 0)
  4765. return -1;
  4766. group_ssid = _group_ssid;
  4767. }
  4768. if (os_strncmp(pos, "pin", 3) == 0) {
  4769. /* Request random PIN (to be displayed) and enable the PIN */
  4770. wps_method = WPS_PIN_DISPLAY;
  4771. } else if (os_strncmp(pos, "pbc", 3) == 0) {
  4772. wps_method = WPS_PBC;
  4773. } else if (os_strstr(pos, "p2ps") != NULL) {
  4774. wps_method = WPS_P2PS;
  4775. } else {
  4776. pin = pos;
  4777. pos = os_strchr(pin, ' ');
  4778. wps_method = WPS_PIN_KEYPAD;
  4779. if (pos) {
  4780. *pos++ = '\0';
  4781. if (os_strncmp(pos, "display", 7) == 0)
  4782. wps_method = WPS_PIN_DISPLAY;
  4783. }
  4784. if (!wps_pin_str_valid(pin)) {
  4785. os_memcpy(buf, "FAIL-INVALID-PIN\n", 17);
  4786. return 17;
  4787. }
  4788. }
  4789. new_pin = wpas_p2p_connect(wpa_s, addr, pin, wps_method,
  4790. persistent_group, automatic, join,
  4791. auth, go_intent, freq, freq2, persistent_id,
  4792. pd, ht40, vht, max_oper_chwidth,
  4793. group_ssid, group_ssid_len);
  4794. if (new_pin == -2) {
  4795. os_memcpy(buf, "FAIL-CHANNEL-UNAVAILABLE\n", 25);
  4796. return 25;
  4797. }
  4798. if (new_pin == -3) {
  4799. os_memcpy(buf, "FAIL-CHANNEL-UNSUPPORTED\n", 25);
  4800. return 25;
  4801. }
  4802. if (new_pin < 0)
  4803. return -1;
  4804. if (wps_method == WPS_PIN_DISPLAY && pin == NULL) {
  4805. ret = os_snprintf(buf, buflen, "%08d", new_pin);
  4806. if (os_snprintf_error(buflen, ret))
  4807. return -1;
  4808. return ret;
  4809. }
  4810. os_memcpy(buf, "OK\n", 3);
  4811. return 3;
  4812. }
  4813. static int p2p_ctrl_listen(struct wpa_supplicant *wpa_s, char *cmd)
  4814. {
  4815. unsigned int timeout = atoi(cmd);
  4816. if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
  4817. wpa_dbg(wpa_s, MSG_INFO,
  4818. "Reject P2P_LISTEN since interface is disabled");
  4819. return -1;
  4820. }
  4821. return wpas_p2p_listen(wpa_s, timeout);
  4822. }
  4823. static int p2p_ctrl_prov_disc(struct wpa_supplicant *wpa_s, char *cmd)
  4824. {
  4825. u8 addr[ETH_ALEN];
  4826. char *pos;
  4827. enum wpas_p2p_prov_disc_use use = WPAS_P2P_PD_FOR_GO_NEG;
  4828. /* <addr> <config method> [join|auto] */
  4829. if (hwaddr_aton(cmd, addr))
  4830. return -1;
  4831. pos = cmd + 17;
  4832. if (*pos != ' ')
  4833. return -1;
  4834. pos++;
  4835. if (os_strstr(pos, " join") != NULL)
  4836. use = WPAS_P2P_PD_FOR_JOIN;
  4837. else if (os_strstr(pos, " auto") != NULL)
  4838. use = WPAS_P2P_PD_AUTO;
  4839. return wpas_p2p_prov_disc(wpa_s, addr, pos, use, NULL);
  4840. }
  4841. static int p2p_get_passphrase(struct wpa_supplicant *wpa_s, char *buf,
  4842. size_t buflen)
  4843. {
  4844. struct wpa_ssid *ssid = wpa_s->current_ssid;
  4845. if (ssid == NULL || ssid->mode != WPAS_MODE_P2P_GO ||
  4846. ssid->passphrase == NULL)
  4847. return -1;
  4848. os_strlcpy(buf, ssid->passphrase, buflen);
  4849. return os_strlen(buf);
  4850. }
  4851. static int p2p_ctrl_serv_disc_req(struct wpa_supplicant *wpa_s, char *cmd,
  4852. char *buf, size_t buflen)
  4853. {
  4854. u64 ref;
  4855. int res;
  4856. u8 dst_buf[ETH_ALEN], *dst;
  4857. struct wpabuf *tlvs;
  4858. char *pos;
  4859. size_t len;
  4860. if (hwaddr_aton(cmd, dst_buf))
  4861. return -1;
  4862. dst = dst_buf;
  4863. if (dst[0] == 0 && dst[1] == 0 && dst[2] == 0 &&
  4864. dst[3] == 0 && dst[4] == 0 && dst[5] == 0)
  4865. dst = NULL;
  4866. pos = cmd + 17;
  4867. if (*pos != ' ')
  4868. return -1;
  4869. pos++;
  4870. if (os_strncmp(pos, "upnp ", 5) == 0) {
  4871. u8 version;
  4872. pos += 5;
  4873. if (hexstr2bin(pos, &version, 1) < 0)
  4874. return -1;
  4875. pos += 2;
  4876. if (*pos != ' ')
  4877. return -1;
  4878. pos++;
  4879. ref = wpas_p2p_sd_request_upnp(wpa_s, dst, version, pos);
  4880. #ifdef CONFIG_WIFI_DISPLAY
  4881. } else if (os_strncmp(pos, "wifi-display ", 13) == 0) {
  4882. ref = wpas_p2p_sd_request_wifi_display(wpa_s, dst, pos + 13);
  4883. #endif /* CONFIG_WIFI_DISPLAY */
  4884. } else if (os_strncmp(pos, "asp ", 4) == 0) {
  4885. char *svc_str;
  4886. char *svc_info = NULL;
  4887. u32 id;
  4888. pos += 4;
  4889. if (sscanf(pos, "%x", &id) != 1 || id > 0xff)
  4890. return -1;
  4891. pos = os_strchr(pos, ' ');
  4892. if (pos == NULL || pos[1] == '\0' || pos[1] == ' ')
  4893. return -1;
  4894. svc_str = pos + 1;
  4895. pos = os_strchr(svc_str, ' ');
  4896. if (pos)
  4897. *pos++ = '\0';
  4898. /* All remaining data is the svc_info string */
  4899. if (pos && pos[0] && pos[0] != ' ') {
  4900. len = os_strlen(pos);
  4901. /* Unescape in place */
  4902. len = utf8_unescape(pos, len, pos, len);
  4903. if (len > 0xff)
  4904. return -1;
  4905. svc_info = pos;
  4906. }
  4907. ref = wpas_p2p_sd_request_asp(wpa_s, dst, (u8) id,
  4908. svc_str, svc_info);
  4909. } else {
  4910. len = os_strlen(pos);
  4911. if (len & 1)
  4912. return -1;
  4913. len /= 2;
  4914. tlvs = wpabuf_alloc(len);
  4915. if (tlvs == NULL)
  4916. return -1;
  4917. if (hexstr2bin(pos, wpabuf_put(tlvs, len), len) < 0) {
  4918. wpabuf_free(tlvs);
  4919. return -1;
  4920. }
  4921. ref = wpas_p2p_sd_request(wpa_s, dst, tlvs);
  4922. wpabuf_free(tlvs);
  4923. }
  4924. if (ref == 0)
  4925. return -1;
  4926. res = os_snprintf(buf, buflen, "%llx", (long long unsigned) ref);
  4927. if (os_snprintf_error(buflen, res))
  4928. return -1;
  4929. return res;
  4930. }
  4931. static int p2p_ctrl_serv_disc_cancel_req(struct wpa_supplicant *wpa_s,
  4932. char *cmd)
  4933. {
  4934. long long unsigned val;
  4935. u64 req;
  4936. if (sscanf(cmd, "%llx", &val) != 1)
  4937. return -1;
  4938. req = val;
  4939. return wpas_p2p_sd_cancel_request(wpa_s, req);
  4940. }
  4941. static int p2p_ctrl_serv_disc_resp(struct wpa_supplicant *wpa_s, char *cmd)
  4942. {
  4943. int freq;
  4944. u8 dst[ETH_ALEN];
  4945. u8 dialog_token;
  4946. struct wpabuf *resp_tlvs;
  4947. char *pos, *pos2;
  4948. size_t len;
  4949. pos = os_strchr(cmd, ' ');
  4950. if (pos == NULL)
  4951. return -1;
  4952. *pos++ = '\0';
  4953. freq = atoi(cmd);
  4954. if (freq == 0)
  4955. return -1;
  4956. if (hwaddr_aton(pos, dst))
  4957. return -1;
  4958. pos += 17;
  4959. if (*pos != ' ')
  4960. return -1;
  4961. pos++;
  4962. pos2 = os_strchr(pos, ' ');
  4963. if (pos2 == NULL)
  4964. return -1;
  4965. *pos2++ = '\0';
  4966. dialog_token = atoi(pos);
  4967. len = os_strlen(pos2);
  4968. if (len & 1)
  4969. return -1;
  4970. len /= 2;
  4971. resp_tlvs = wpabuf_alloc(len);
  4972. if (resp_tlvs == NULL)
  4973. return -1;
  4974. if (hexstr2bin(pos2, wpabuf_put(resp_tlvs, len), len) < 0) {
  4975. wpabuf_free(resp_tlvs);
  4976. return -1;
  4977. }
  4978. wpas_p2p_sd_response(wpa_s, freq, dst, dialog_token, resp_tlvs);
  4979. wpabuf_free(resp_tlvs);
  4980. return 0;
  4981. }
  4982. static int p2p_ctrl_serv_disc_external(struct wpa_supplicant *wpa_s,
  4983. char *cmd)
  4984. {
  4985. if (os_strcmp(cmd, "0") && os_strcmp(cmd, "1"))
  4986. return -1;
  4987. wpa_s->p2p_sd_over_ctrl_iface = atoi(cmd);
  4988. return 0;
  4989. }
  4990. static int p2p_ctrl_service_add_bonjour(struct wpa_supplicant *wpa_s,
  4991. char *cmd)
  4992. {
  4993. char *pos;
  4994. size_t len;
  4995. struct wpabuf *query, *resp;
  4996. pos = os_strchr(cmd, ' ');
  4997. if (pos == NULL)
  4998. return -1;
  4999. *pos++ = '\0';
  5000. len = os_strlen(cmd);
  5001. if (len & 1)
  5002. return -1;
  5003. len /= 2;
  5004. query = wpabuf_alloc(len);
  5005. if (query == NULL)
  5006. return -1;
  5007. if (hexstr2bin(cmd, wpabuf_put(query, len), len) < 0) {
  5008. wpabuf_free(query);
  5009. return -1;
  5010. }
  5011. len = os_strlen(pos);
  5012. if (len & 1) {
  5013. wpabuf_free(query);
  5014. return -1;
  5015. }
  5016. len /= 2;
  5017. resp = wpabuf_alloc(len);
  5018. if (resp == NULL) {
  5019. wpabuf_free(query);
  5020. return -1;
  5021. }
  5022. if (hexstr2bin(pos, wpabuf_put(resp, len), len) < 0) {
  5023. wpabuf_free(query);
  5024. wpabuf_free(resp);
  5025. return -1;
  5026. }
  5027. if (wpas_p2p_service_add_bonjour(wpa_s, query, resp) < 0) {
  5028. wpabuf_free(query);
  5029. wpabuf_free(resp);
  5030. return -1;
  5031. }
  5032. return 0;
  5033. }
  5034. static int p2p_ctrl_service_add_upnp(struct wpa_supplicant *wpa_s, char *cmd)
  5035. {
  5036. char *pos;
  5037. u8 version;
  5038. pos = os_strchr(cmd, ' ');
  5039. if (pos == NULL)
  5040. return -1;
  5041. *pos++ = '\0';
  5042. if (hexstr2bin(cmd, &version, 1) < 0)
  5043. return -1;
  5044. return wpas_p2p_service_add_upnp(wpa_s, version, pos);
  5045. }
  5046. static int p2p_ctrl_service_add_asp(struct wpa_supplicant *wpa_s,
  5047. u8 replace, char *cmd)
  5048. {
  5049. char *pos;
  5050. char *adv_str;
  5051. u32 auto_accept, adv_id, svc_state, config_methods;
  5052. char *svc_info = NULL;
  5053. char *cpt_prio_str;
  5054. u8 cpt_prio[P2PS_FEATURE_CAPAB_CPT_MAX + 1];
  5055. pos = os_strchr(cmd, ' ');
  5056. if (pos == NULL)
  5057. return -1;
  5058. *pos++ = '\0';
  5059. /* Auto-Accept value is mandatory, and must be one of the
  5060. * single values (0, 1, 2, 4) */
  5061. auto_accept = atoi(cmd);
  5062. switch (auto_accept) {
  5063. case P2PS_SETUP_NONE: /* No auto-accept */
  5064. case P2PS_SETUP_NEW:
  5065. case P2PS_SETUP_CLIENT:
  5066. case P2PS_SETUP_GROUP_OWNER:
  5067. break;
  5068. default:
  5069. return -1;
  5070. }
  5071. /* Advertisement ID is mandatory */
  5072. cmd = pos;
  5073. pos = os_strchr(cmd, ' ');
  5074. if (pos == NULL)
  5075. return -1;
  5076. *pos++ = '\0';
  5077. /* Handle Adv_ID == 0 (wildcard "org.wi-fi.wfds") internally. */
  5078. if (sscanf(cmd, "%x", &adv_id) != 1 || adv_id == 0)
  5079. return -1;
  5080. /* Only allow replacements if exist, and adds if not */
  5081. if (wpas_p2p_service_p2ps_id_exists(wpa_s, adv_id)) {
  5082. if (!replace)
  5083. return -1;
  5084. } else {
  5085. if (replace)
  5086. return -1;
  5087. }
  5088. /* svc_state between 0 - 0xff is mandatory */
  5089. if (sscanf(pos, "%x", &svc_state) != 1 || svc_state > 0xff)
  5090. return -1;
  5091. pos = os_strchr(pos, ' ');
  5092. if (pos == NULL)
  5093. return -1;
  5094. /* config_methods is mandatory */
  5095. pos++;
  5096. if (sscanf(pos, "%x", &config_methods) != 1)
  5097. return -1;
  5098. if (!(config_methods &
  5099. (WPS_CONFIG_DISPLAY | WPS_CONFIG_KEYPAD | WPS_CONFIG_P2PS)))
  5100. return -1;
  5101. pos = os_strchr(pos, ' ');
  5102. if (pos == NULL)
  5103. return -1;
  5104. pos++;
  5105. adv_str = pos;
  5106. /* Advertisement string is mandatory */
  5107. if (!pos[0] || pos[0] == ' ')
  5108. return -1;
  5109. /* Terminate svc string */
  5110. pos = os_strchr(pos, ' ');
  5111. if (pos != NULL)
  5112. *pos++ = '\0';
  5113. cpt_prio_str = (pos && pos[0]) ? os_strstr(pos, "cpt=") : NULL;
  5114. if (cpt_prio_str) {
  5115. pos = os_strchr(pos, ' ');
  5116. if (pos != NULL)
  5117. *pos++ = '\0';
  5118. if (p2ps_ctrl_parse_cpt_priority(cpt_prio_str + 4, cpt_prio))
  5119. return -1;
  5120. } else {
  5121. cpt_prio[0] = P2PS_FEATURE_CAPAB_UDP_TRANSPORT;
  5122. cpt_prio[1] = 0;
  5123. }
  5124. /* Service and Response Information are optional */
  5125. if (pos && pos[0]) {
  5126. size_t len;
  5127. /* Note the bare ' included, which cannot exist legally
  5128. * in unescaped string. */
  5129. svc_info = os_strstr(pos, "svc_info='");
  5130. if (svc_info) {
  5131. svc_info += 9;
  5132. len = os_strlen(svc_info);
  5133. utf8_unescape(svc_info, len, svc_info, len);
  5134. }
  5135. }
  5136. return wpas_p2p_service_add_asp(wpa_s, auto_accept, adv_id, adv_str,
  5137. (u8) svc_state, (u16) config_methods,
  5138. svc_info, cpt_prio);
  5139. }
  5140. static int p2p_ctrl_service_add(struct wpa_supplicant *wpa_s, char *cmd)
  5141. {
  5142. char *pos;
  5143. pos = os_strchr(cmd, ' ');
  5144. if (pos == NULL)
  5145. return -1;
  5146. *pos++ = '\0';
  5147. if (os_strcmp(cmd, "bonjour") == 0)
  5148. return p2p_ctrl_service_add_bonjour(wpa_s, pos);
  5149. if (os_strcmp(cmd, "upnp") == 0)
  5150. return p2p_ctrl_service_add_upnp(wpa_s, pos);
  5151. if (os_strcmp(cmd, "asp") == 0)
  5152. return p2p_ctrl_service_add_asp(wpa_s, 0, pos);
  5153. wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd);
  5154. return -1;
  5155. }
  5156. static int p2p_ctrl_service_del_bonjour(struct wpa_supplicant *wpa_s,
  5157. char *cmd)
  5158. {
  5159. size_t len;
  5160. struct wpabuf *query;
  5161. int ret;
  5162. len = os_strlen(cmd);
  5163. if (len & 1)
  5164. return -1;
  5165. len /= 2;
  5166. query = wpabuf_alloc(len);
  5167. if (query == NULL)
  5168. return -1;
  5169. if (hexstr2bin(cmd, wpabuf_put(query, len), len) < 0) {
  5170. wpabuf_free(query);
  5171. return -1;
  5172. }
  5173. ret = wpas_p2p_service_del_bonjour(wpa_s, query);
  5174. wpabuf_free(query);
  5175. return ret;
  5176. }
  5177. static int p2p_ctrl_service_del_upnp(struct wpa_supplicant *wpa_s, char *cmd)
  5178. {
  5179. char *pos;
  5180. u8 version;
  5181. pos = os_strchr(cmd, ' ');
  5182. if (pos == NULL)
  5183. return -1;
  5184. *pos++ = '\0';
  5185. if (hexstr2bin(cmd, &version, 1) < 0)
  5186. return -1;
  5187. return wpas_p2p_service_del_upnp(wpa_s, version, pos);
  5188. }
  5189. static int p2p_ctrl_service_del_asp(struct wpa_supplicant *wpa_s, char *cmd)
  5190. {
  5191. u32 adv_id;
  5192. if (os_strcmp(cmd, "all") == 0) {
  5193. wpas_p2p_service_flush_asp(wpa_s);
  5194. return 0;
  5195. }
  5196. if (sscanf(cmd, "%x", &adv_id) != 1)
  5197. return -1;
  5198. return wpas_p2p_service_del_asp(wpa_s, adv_id);
  5199. }
  5200. static int p2p_ctrl_service_del(struct wpa_supplicant *wpa_s, char *cmd)
  5201. {
  5202. char *pos;
  5203. pos = os_strchr(cmd, ' ');
  5204. if (pos == NULL)
  5205. return -1;
  5206. *pos++ = '\0';
  5207. if (os_strcmp(cmd, "bonjour") == 0)
  5208. return p2p_ctrl_service_del_bonjour(wpa_s, pos);
  5209. if (os_strcmp(cmd, "upnp") == 0)
  5210. return p2p_ctrl_service_del_upnp(wpa_s, pos);
  5211. if (os_strcmp(cmd, "asp") == 0)
  5212. return p2p_ctrl_service_del_asp(wpa_s, pos);
  5213. wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd);
  5214. return -1;
  5215. }
  5216. static int p2p_ctrl_service_replace(struct wpa_supplicant *wpa_s, char *cmd)
  5217. {
  5218. char *pos;
  5219. pos = os_strchr(cmd, ' ');
  5220. if (pos == NULL)
  5221. return -1;
  5222. *pos++ = '\0';
  5223. if (os_strcmp(cmd, "asp") == 0)
  5224. return p2p_ctrl_service_add_asp(wpa_s, 1, pos);
  5225. wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd);
  5226. return -1;
  5227. }
  5228. static int p2p_ctrl_reject(struct wpa_supplicant *wpa_s, char *cmd)
  5229. {
  5230. u8 addr[ETH_ALEN];
  5231. /* <addr> */
  5232. if (hwaddr_aton(cmd, addr))
  5233. return -1;
  5234. return wpas_p2p_reject(wpa_s, addr);
  5235. }
  5236. static int p2p_ctrl_invite_persistent(struct wpa_supplicant *wpa_s, char *cmd)
  5237. {
  5238. char *pos;
  5239. int id;
  5240. struct wpa_ssid *ssid;
  5241. u8 *_peer = NULL, peer[ETH_ALEN];
  5242. int freq = 0, pref_freq = 0;
  5243. int ht40, vht, max_oper_chwidth, chwidth = 0, freq2 = 0;
  5244. id = atoi(cmd);
  5245. pos = os_strstr(cmd, " peer=");
  5246. if (pos) {
  5247. pos += 6;
  5248. if (hwaddr_aton(pos, peer))
  5249. return -1;
  5250. _peer = peer;
  5251. }
  5252. ssid = wpa_config_get_network(wpa_s->conf, id);
  5253. if (ssid == NULL || ssid->disabled != 2) {
  5254. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
  5255. "for persistent P2P group",
  5256. id);
  5257. return -1;
  5258. }
  5259. pos = os_strstr(cmd, " freq=");
  5260. if (pos) {
  5261. pos += 6;
  5262. freq = atoi(pos);
  5263. if (freq <= 0)
  5264. return -1;
  5265. }
  5266. pos = os_strstr(cmd, " pref=");
  5267. if (pos) {
  5268. pos += 6;
  5269. pref_freq = atoi(pos);
  5270. if (pref_freq <= 0)
  5271. return -1;
  5272. }
  5273. vht = (os_strstr(cmd, " vht") != NULL) || wpa_s->conf->p2p_go_vht;
  5274. ht40 = (os_strstr(cmd, " ht40") != NULL) || wpa_s->conf->p2p_go_ht40 ||
  5275. vht;
  5276. pos = os_strstr(cmd, "freq2=");
  5277. if (pos)
  5278. freq2 = atoi(pos + 6);
  5279. pos = os_strstr(cmd, " max_oper_chwidth=");
  5280. if (pos)
  5281. chwidth = atoi(pos + 18);
  5282. max_oper_chwidth = parse_freq(chwidth, freq2);
  5283. if (max_oper_chwidth < 0)
  5284. return -1;
  5285. return wpas_p2p_invite(wpa_s, _peer, ssid, NULL, freq, freq2, ht40, vht,
  5286. max_oper_chwidth, pref_freq);
  5287. }
  5288. static int p2p_ctrl_invite_group(struct wpa_supplicant *wpa_s, char *cmd)
  5289. {
  5290. char *pos;
  5291. u8 peer[ETH_ALEN], go_dev_addr[ETH_ALEN], *go_dev = NULL;
  5292. pos = os_strstr(cmd, " peer=");
  5293. if (!pos)
  5294. return -1;
  5295. *pos = '\0';
  5296. pos += 6;
  5297. if (hwaddr_aton(pos, peer)) {
  5298. wpa_printf(MSG_DEBUG, "P2P: Invalid MAC address '%s'", pos);
  5299. return -1;
  5300. }
  5301. pos = os_strstr(pos, " go_dev_addr=");
  5302. if (pos) {
  5303. pos += 13;
  5304. if (hwaddr_aton(pos, go_dev_addr)) {
  5305. wpa_printf(MSG_DEBUG, "P2P: Invalid MAC address '%s'",
  5306. pos);
  5307. return -1;
  5308. }
  5309. go_dev = go_dev_addr;
  5310. }
  5311. return wpas_p2p_invite_group(wpa_s, cmd, peer, go_dev);
  5312. }
  5313. static int p2p_ctrl_invite(struct wpa_supplicant *wpa_s, char *cmd)
  5314. {
  5315. if (os_strncmp(cmd, "persistent=", 11) == 0)
  5316. return p2p_ctrl_invite_persistent(wpa_s, cmd + 11);
  5317. if (os_strncmp(cmd, "group=", 6) == 0)
  5318. return p2p_ctrl_invite_group(wpa_s, cmd + 6);
  5319. return -1;
  5320. }
  5321. static int p2p_ctrl_group_add_persistent(struct wpa_supplicant *wpa_s,
  5322. int id, int freq, int vht_center_freq2,
  5323. int ht40, int vht, int vht_chwidth)
  5324. {
  5325. struct wpa_ssid *ssid;
  5326. ssid = wpa_config_get_network(wpa_s->conf, id);
  5327. if (ssid == NULL || ssid->disabled != 2) {
  5328. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
  5329. "for persistent P2P group",
  5330. id);
  5331. return -1;
  5332. }
  5333. return wpas_p2p_group_add_persistent(wpa_s, ssid, 0, freq,
  5334. vht_center_freq2, 0, ht40, vht,
  5335. vht_chwidth, NULL, 0, 0);
  5336. }
  5337. static int p2p_ctrl_group_add(struct wpa_supplicant *wpa_s, char *cmd)
  5338. {
  5339. int freq = 0, persistent = 0, group_id = -1;
  5340. int vht = wpa_s->conf->p2p_go_vht;
  5341. int ht40 = wpa_s->conf->p2p_go_ht40 || vht;
  5342. int max_oper_chwidth, chwidth = 0, freq2 = 0;
  5343. char *token, *context = NULL;
  5344. #ifdef CONFIG_ACS
  5345. int acs = 0;
  5346. #endif /* CONFIG_ACS */
  5347. while ((token = str_token(cmd, " ", &context))) {
  5348. if (sscanf(token, "freq2=%d", &freq2) == 1 ||
  5349. sscanf(token, "persistent=%d", &group_id) == 1 ||
  5350. sscanf(token, "max_oper_chwidth=%d", &chwidth) == 1) {
  5351. continue;
  5352. #ifdef CONFIG_ACS
  5353. } else if (os_strcmp(token, "freq=acs") == 0) {
  5354. acs = 1;
  5355. #endif /* CONFIG_ACS */
  5356. } else if (sscanf(token, "freq=%d", &freq) == 1) {
  5357. continue;
  5358. } else if (os_strcmp(token, "ht40") == 0) {
  5359. ht40 = 1;
  5360. } else if (os_strcmp(token, "vht") == 0) {
  5361. vht = 1;
  5362. ht40 = 1;
  5363. } else if (os_strcmp(token, "persistent") == 0) {
  5364. persistent = 1;
  5365. } else {
  5366. wpa_printf(MSG_DEBUG,
  5367. "CTRL: Invalid P2P_GROUP_ADD parameter: '%s'",
  5368. token);
  5369. return -1;
  5370. }
  5371. }
  5372. #ifdef CONFIG_ACS
  5373. if ((wpa_s->drv_flags & WPA_DRIVER_FLAGS_ACS_OFFLOAD) &&
  5374. (acs || freq == 2 || freq == 5)) {
  5375. if (freq == 2 && wpa_s->best_24_freq <= 0) {
  5376. wpa_s->p2p_go_acs_band = HOSTAPD_MODE_IEEE80211G;
  5377. wpa_s->p2p_go_do_acs = 1;
  5378. freq = 0;
  5379. } else if (freq == 5 && wpa_s->best_5_freq <= 0) {
  5380. wpa_s->p2p_go_acs_band = HOSTAPD_MODE_IEEE80211A;
  5381. wpa_s->p2p_go_do_acs = 1;
  5382. freq = 0;
  5383. } else {
  5384. wpa_s->p2p_go_acs_band = HOSTAPD_MODE_IEEE80211ANY;
  5385. wpa_s->p2p_go_do_acs = 1;
  5386. }
  5387. }
  5388. #endif /* CONFIG_ACS */
  5389. max_oper_chwidth = parse_freq(chwidth, freq2);
  5390. if (max_oper_chwidth < 0)
  5391. return -1;
  5392. if (group_id >= 0)
  5393. return p2p_ctrl_group_add_persistent(wpa_s, group_id,
  5394. freq, freq2, ht40, vht,
  5395. max_oper_chwidth);
  5396. return wpas_p2p_group_add(wpa_s, persistent, freq, freq2, ht40, vht,
  5397. max_oper_chwidth);
  5398. }
  5399. static int p2p_ctrl_group_member(struct wpa_supplicant *wpa_s, const char *cmd,
  5400. char *buf, size_t buflen)
  5401. {
  5402. u8 dev_addr[ETH_ALEN];
  5403. struct wpa_ssid *ssid;
  5404. int res;
  5405. const u8 *iaddr;
  5406. ssid = wpa_s->current_ssid;
  5407. if (!wpa_s->global->p2p || !ssid || ssid->mode != WPAS_MODE_P2P_GO ||
  5408. hwaddr_aton(cmd, dev_addr))
  5409. return -1;
  5410. iaddr = p2p_group_get_client_interface_addr(wpa_s->p2p_group, dev_addr);
  5411. if (!iaddr)
  5412. return -1;
  5413. res = os_snprintf(buf, buflen, MACSTR, MAC2STR(iaddr));
  5414. if (os_snprintf_error(buflen, res))
  5415. return -1;
  5416. return res;
  5417. }
  5418. static int wpas_find_p2p_dev_addr_bss(struct wpa_global *global,
  5419. const u8 *p2p_dev_addr)
  5420. {
  5421. struct wpa_supplicant *wpa_s;
  5422. for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
  5423. if (wpa_bss_get_p2p_dev_addr(wpa_s, p2p_dev_addr))
  5424. return 1;
  5425. }
  5426. return 0;
  5427. }
  5428. static int p2p_ctrl_peer(struct wpa_supplicant *wpa_s, char *cmd,
  5429. char *buf, size_t buflen)
  5430. {
  5431. u8 addr[ETH_ALEN], *addr_ptr, group_capab;
  5432. int next, res;
  5433. const struct p2p_peer_info *info;
  5434. char *pos, *end;
  5435. char devtype[WPS_DEV_TYPE_BUFSIZE];
  5436. struct wpa_ssid *ssid;
  5437. size_t i;
  5438. if (!wpa_s->global->p2p)
  5439. return -1;
  5440. if (os_strcmp(cmd, "FIRST") == 0) {
  5441. addr_ptr = NULL;
  5442. next = 0;
  5443. } else if (os_strncmp(cmd, "NEXT-", 5) == 0) {
  5444. if (hwaddr_aton(cmd + 5, addr) < 0)
  5445. return -1;
  5446. addr_ptr = addr;
  5447. next = 1;
  5448. } else {
  5449. if (hwaddr_aton(cmd, addr) < 0)
  5450. return -1;
  5451. addr_ptr = addr;
  5452. next = 0;
  5453. }
  5454. info = p2p_get_peer_info(wpa_s->global->p2p, addr_ptr, next);
  5455. if (info == NULL)
  5456. return -1;
  5457. group_capab = info->group_capab;
  5458. if (group_capab &&
  5459. !wpas_find_p2p_dev_addr_bss(wpa_s->global, info->p2p_device_addr)) {
  5460. wpa_printf(MSG_DEBUG,
  5461. "P2P: Could not find any BSS with p2p_dev_addr "
  5462. MACSTR ", hence override group_capab from 0x%x to 0",
  5463. MAC2STR(info->p2p_device_addr), group_capab);
  5464. group_capab = 0;
  5465. }
  5466. pos = buf;
  5467. end = buf + buflen;
  5468. res = os_snprintf(pos, end - pos, MACSTR "\n"
  5469. "pri_dev_type=%s\n"
  5470. "device_name=%s\n"
  5471. "manufacturer=%s\n"
  5472. "model_name=%s\n"
  5473. "model_number=%s\n"
  5474. "serial_number=%s\n"
  5475. "config_methods=0x%x\n"
  5476. "dev_capab=0x%x\n"
  5477. "group_capab=0x%x\n"
  5478. "level=%d\n",
  5479. MAC2STR(info->p2p_device_addr),
  5480. wps_dev_type_bin2str(info->pri_dev_type,
  5481. devtype, sizeof(devtype)),
  5482. info->device_name,
  5483. info->manufacturer,
  5484. info->model_name,
  5485. info->model_number,
  5486. info->serial_number,
  5487. info->config_methods,
  5488. info->dev_capab,
  5489. group_capab,
  5490. info->level);
  5491. if (os_snprintf_error(end - pos, res))
  5492. return pos - buf;
  5493. pos += res;
  5494. for (i = 0; i < info->wps_sec_dev_type_list_len / WPS_DEV_TYPE_LEN; i++)
  5495. {
  5496. const u8 *t;
  5497. t = &info->wps_sec_dev_type_list[i * WPS_DEV_TYPE_LEN];
  5498. res = os_snprintf(pos, end - pos, "sec_dev_type=%s\n",
  5499. wps_dev_type_bin2str(t, devtype,
  5500. sizeof(devtype)));
  5501. if (os_snprintf_error(end - pos, res))
  5502. return pos - buf;
  5503. pos += res;
  5504. }
  5505. ssid = wpas_p2p_get_persistent(wpa_s, info->p2p_device_addr, NULL, 0);
  5506. if (ssid) {
  5507. res = os_snprintf(pos, end - pos, "persistent=%d\n", ssid->id);
  5508. if (os_snprintf_error(end - pos, res))
  5509. return pos - buf;
  5510. pos += res;
  5511. }
  5512. res = p2p_get_peer_info_txt(info, pos, end - pos);
  5513. if (res < 0)
  5514. return pos - buf;
  5515. pos += res;
  5516. if (info->vendor_elems) {
  5517. res = os_snprintf(pos, end - pos, "vendor_elems=");
  5518. if (os_snprintf_error(end - pos, res))
  5519. return pos - buf;
  5520. pos += res;
  5521. pos += wpa_snprintf_hex(pos, end - pos,
  5522. wpabuf_head(info->vendor_elems),
  5523. wpabuf_len(info->vendor_elems));
  5524. res = os_snprintf(pos, end - pos, "\n");
  5525. if (os_snprintf_error(end - pos, res))
  5526. return pos - buf;
  5527. pos += res;
  5528. }
  5529. return pos - buf;
  5530. }
  5531. static int p2p_ctrl_disallow_freq(struct wpa_supplicant *wpa_s,
  5532. const char *param)
  5533. {
  5534. unsigned int i;
  5535. if (wpa_s->global->p2p == NULL)
  5536. return -1;
  5537. if (freq_range_list_parse(&wpa_s->global->p2p_disallow_freq, param) < 0)
  5538. return -1;
  5539. for (i = 0; i < wpa_s->global->p2p_disallow_freq.num; i++) {
  5540. struct wpa_freq_range *freq;
  5541. freq = &wpa_s->global->p2p_disallow_freq.range[i];
  5542. wpa_printf(MSG_DEBUG, "P2P: Disallowed frequency range %u-%u",
  5543. freq->min, freq->max);
  5544. }
  5545. wpas_p2p_update_channel_list(wpa_s, WPAS_P2P_CHANNEL_UPDATE_DISALLOW);
  5546. return 0;
  5547. }
  5548. static int p2p_ctrl_set(struct wpa_supplicant *wpa_s, char *cmd)
  5549. {
  5550. char *param;
  5551. if (wpa_s->global->p2p == NULL)
  5552. return -1;
  5553. param = os_strchr(cmd, ' ');
  5554. if (param == NULL)
  5555. return -1;
  5556. *param++ = '\0';
  5557. if (os_strcmp(cmd, "discoverability") == 0) {
  5558. p2p_set_client_discoverability(wpa_s->global->p2p,
  5559. atoi(param));
  5560. return 0;
  5561. }
  5562. if (os_strcmp(cmd, "managed") == 0) {
  5563. p2p_set_managed_oper(wpa_s->global->p2p, atoi(param));
  5564. return 0;
  5565. }
  5566. if (os_strcmp(cmd, "listen_channel") == 0) {
  5567. char *pos;
  5568. u8 channel, op_class;
  5569. channel = atoi(param);
  5570. pos = os_strchr(param, ' ');
  5571. op_class = pos ? atoi(pos) : 81;
  5572. return p2p_set_listen_channel(wpa_s->global->p2p, op_class,
  5573. channel, 1);
  5574. }
  5575. if (os_strcmp(cmd, "ssid_postfix") == 0) {
  5576. return p2p_set_ssid_postfix(wpa_s->global->p2p, (u8 *) param,
  5577. os_strlen(param));
  5578. }
  5579. if (os_strcmp(cmd, "noa") == 0) {
  5580. char *pos;
  5581. int count, start, duration;
  5582. /* GO NoA parameters: count,start_offset(ms),duration(ms) */
  5583. count = atoi(param);
  5584. pos = os_strchr(param, ',');
  5585. if (pos == NULL)
  5586. return -1;
  5587. pos++;
  5588. start = atoi(pos);
  5589. pos = os_strchr(pos, ',');
  5590. if (pos == NULL)
  5591. return -1;
  5592. pos++;
  5593. duration = atoi(pos);
  5594. if (count < 0 || count > 255 || start < 0 || duration < 0)
  5595. return -1;
  5596. if (count == 0 && duration > 0)
  5597. return -1;
  5598. wpa_printf(MSG_DEBUG, "CTRL_IFACE: P2P_SET GO NoA: count=%d "
  5599. "start=%d duration=%d", count, start, duration);
  5600. return wpas_p2p_set_noa(wpa_s, count, start, duration);
  5601. }
  5602. if (os_strcmp(cmd, "ps") == 0)
  5603. return wpa_drv_set_p2p_powersave(wpa_s, atoi(param), -1, -1);
  5604. if (os_strcmp(cmd, "oppps") == 0)
  5605. return wpa_drv_set_p2p_powersave(wpa_s, -1, atoi(param), -1);
  5606. if (os_strcmp(cmd, "ctwindow") == 0)
  5607. return wpa_drv_set_p2p_powersave(wpa_s, -1, -1, atoi(param));
  5608. if (os_strcmp(cmd, "disabled") == 0) {
  5609. wpa_s->global->p2p_disabled = atoi(param);
  5610. wpa_printf(MSG_DEBUG, "P2P functionality %s",
  5611. wpa_s->global->p2p_disabled ?
  5612. "disabled" : "enabled");
  5613. if (wpa_s->global->p2p_disabled) {
  5614. wpas_p2p_stop_find(wpa_s);
  5615. os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN);
  5616. p2p_flush(wpa_s->global->p2p);
  5617. }
  5618. return 0;
  5619. }
  5620. if (os_strcmp(cmd, "conc_pref") == 0) {
  5621. if (os_strcmp(param, "sta") == 0)
  5622. wpa_s->global->conc_pref = WPA_CONC_PREF_STA;
  5623. else if (os_strcmp(param, "p2p") == 0)
  5624. wpa_s->global->conc_pref = WPA_CONC_PREF_P2P;
  5625. else {
  5626. wpa_printf(MSG_INFO, "Invalid conc_pref value");
  5627. return -1;
  5628. }
  5629. wpa_printf(MSG_DEBUG, "Single channel concurrency preference: "
  5630. "%s", param);
  5631. return 0;
  5632. }
  5633. if (os_strcmp(cmd, "force_long_sd") == 0) {
  5634. wpa_s->force_long_sd = atoi(param);
  5635. return 0;
  5636. }
  5637. if (os_strcmp(cmd, "peer_filter") == 0) {
  5638. u8 addr[ETH_ALEN];
  5639. if (hwaddr_aton(param, addr))
  5640. return -1;
  5641. p2p_set_peer_filter(wpa_s->global->p2p, addr);
  5642. return 0;
  5643. }
  5644. if (os_strcmp(cmd, "cross_connect") == 0)
  5645. return wpas_p2p_set_cross_connect(wpa_s, atoi(param));
  5646. if (os_strcmp(cmd, "go_apsd") == 0) {
  5647. if (os_strcmp(param, "disable") == 0)
  5648. wpa_s->set_ap_uapsd = 0;
  5649. else {
  5650. wpa_s->set_ap_uapsd = 1;
  5651. wpa_s->ap_uapsd = atoi(param);
  5652. }
  5653. return 0;
  5654. }
  5655. if (os_strcmp(cmd, "client_apsd") == 0) {
  5656. if (os_strcmp(param, "disable") == 0)
  5657. wpa_s->set_sta_uapsd = 0;
  5658. else {
  5659. int be, bk, vi, vo;
  5660. char *pos;
  5661. /* format: BE,BK,VI,VO;max SP Length */
  5662. be = atoi(param);
  5663. pos = os_strchr(param, ',');
  5664. if (pos == NULL)
  5665. return -1;
  5666. pos++;
  5667. bk = atoi(pos);
  5668. pos = os_strchr(pos, ',');
  5669. if (pos == NULL)
  5670. return -1;
  5671. pos++;
  5672. vi = atoi(pos);
  5673. pos = os_strchr(pos, ',');
  5674. if (pos == NULL)
  5675. return -1;
  5676. pos++;
  5677. vo = atoi(pos);
  5678. /* ignore max SP Length for now */
  5679. wpa_s->set_sta_uapsd = 1;
  5680. wpa_s->sta_uapsd = 0;
  5681. if (be)
  5682. wpa_s->sta_uapsd |= BIT(0);
  5683. if (bk)
  5684. wpa_s->sta_uapsd |= BIT(1);
  5685. if (vi)
  5686. wpa_s->sta_uapsd |= BIT(2);
  5687. if (vo)
  5688. wpa_s->sta_uapsd |= BIT(3);
  5689. }
  5690. return 0;
  5691. }
  5692. if (os_strcmp(cmd, "disallow_freq") == 0)
  5693. return p2p_ctrl_disallow_freq(wpa_s, param);
  5694. if (os_strcmp(cmd, "disc_int") == 0) {
  5695. int min_disc_int, max_disc_int, max_disc_tu;
  5696. char *pos;
  5697. pos = param;
  5698. min_disc_int = atoi(pos);
  5699. pos = os_strchr(pos, ' ');
  5700. if (pos == NULL)
  5701. return -1;
  5702. *pos++ = '\0';
  5703. max_disc_int = atoi(pos);
  5704. pos = os_strchr(pos, ' ');
  5705. if (pos == NULL)
  5706. return -1;
  5707. *pos++ = '\0';
  5708. max_disc_tu = atoi(pos);
  5709. return p2p_set_disc_int(wpa_s->global->p2p, min_disc_int,
  5710. max_disc_int, max_disc_tu);
  5711. }
  5712. if (os_strcmp(cmd, "per_sta_psk") == 0) {
  5713. wpa_s->global->p2p_per_sta_psk = !!atoi(param);
  5714. return 0;
  5715. }
  5716. #ifdef CONFIG_WPS_NFC
  5717. if (os_strcmp(cmd, "nfc_tag") == 0)
  5718. return wpas_p2p_nfc_tag_enabled(wpa_s, !!atoi(param));
  5719. #endif /* CONFIG_WPS_NFC */
  5720. if (os_strcmp(cmd, "disable_ip_addr_req") == 0) {
  5721. wpa_s->p2p_disable_ip_addr_req = !!atoi(param);
  5722. return 0;
  5723. }
  5724. if (os_strcmp(cmd, "override_pref_op_chan") == 0) {
  5725. int op_class, chan;
  5726. op_class = atoi(param);
  5727. param = os_strchr(param, ':');
  5728. if (!param)
  5729. return -1;
  5730. param++;
  5731. chan = atoi(param);
  5732. p2p_set_override_pref_op_chan(wpa_s->global->p2p, op_class,
  5733. chan);
  5734. return 0;
  5735. }
  5736. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown P2P_SET field value '%s'",
  5737. cmd);
  5738. return -1;
  5739. }
  5740. static void p2p_ctrl_flush(struct wpa_supplicant *wpa_s)
  5741. {
  5742. os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN);
  5743. wpa_s->force_long_sd = 0;
  5744. #ifdef CONFIG_TESTING_OPTIONS
  5745. os_free(wpa_s->get_pref_freq_list_override);
  5746. wpa_s->get_pref_freq_list_override = NULL;
  5747. #endif /* CONFIG_TESTING_OPTIONS */
  5748. wpas_p2p_stop_find(wpa_s);
  5749. wpa_s->parent->p2ps_method_config_any = 0;
  5750. if (wpa_s->global->p2p)
  5751. p2p_flush(wpa_s->global->p2p);
  5752. }
  5753. static int p2p_ctrl_presence_req(struct wpa_supplicant *wpa_s, char *cmd)
  5754. {
  5755. char *pos, *pos2;
  5756. unsigned int dur1 = 0, int1 = 0, dur2 = 0, int2 = 0;
  5757. if (cmd[0]) {
  5758. pos = os_strchr(cmd, ' ');
  5759. if (pos == NULL)
  5760. return -1;
  5761. *pos++ = '\0';
  5762. dur1 = atoi(cmd);
  5763. pos2 = os_strchr(pos, ' ');
  5764. if (pos2)
  5765. *pos2++ = '\0';
  5766. int1 = atoi(pos);
  5767. } else
  5768. pos2 = NULL;
  5769. if (pos2) {
  5770. pos = os_strchr(pos2, ' ');
  5771. if (pos == NULL)
  5772. return -1;
  5773. *pos++ = '\0';
  5774. dur2 = atoi(pos2);
  5775. int2 = atoi(pos);
  5776. }
  5777. return wpas_p2p_presence_req(wpa_s, dur1, int1, dur2, int2);
  5778. }
  5779. static int p2p_ctrl_ext_listen(struct wpa_supplicant *wpa_s, char *cmd)
  5780. {
  5781. char *pos;
  5782. unsigned int period = 0, interval = 0;
  5783. if (cmd[0]) {
  5784. pos = os_strchr(cmd, ' ');
  5785. if (pos == NULL)
  5786. return -1;
  5787. *pos++ = '\0';
  5788. period = atoi(cmd);
  5789. interval = atoi(pos);
  5790. }
  5791. return wpas_p2p_ext_listen(wpa_s, period, interval);
  5792. }
  5793. static int p2p_ctrl_remove_client(struct wpa_supplicant *wpa_s, const char *cmd)
  5794. {
  5795. const char *pos;
  5796. u8 peer[ETH_ALEN];
  5797. int iface_addr = 0;
  5798. pos = cmd;
  5799. if (os_strncmp(pos, "iface=", 6) == 0) {
  5800. iface_addr = 1;
  5801. pos += 6;
  5802. }
  5803. if (hwaddr_aton(pos, peer))
  5804. return -1;
  5805. wpas_p2p_remove_client(wpa_s, peer, iface_addr);
  5806. return 0;
  5807. }
  5808. static int p2p_ctrl_iface_p2p_lo_start(struct wpa_supplicant *wpa_s, char *cmd)
  5809. {
  5810. int freq = 0, period = 0, interval = 0, count = 0;
  5811. if (sscanf(cmd, "%d %d %d %d", &freq, &period, &interval, &count) != 4)
  5812. {
  5813. wpa_printf(MSG_DEBUG,
  5814. "CTRL: Invalid P2P LO Start parameter: '%s'", cmd);
  5815. return -1;
  5816. }
  5817. return wpas_p2p_lo_start(wpa_s, freq, period, interval, count);
  5818. }
  5819. #endif /* CONFIG_P2P */
  5820. static int * freq_range_to_channel_list(struct wpa_supplicant *wpa_s, char *val)
  5821. {
  5822. struct wpa_freq_range_list ranges;
  5823. int *freqs = NULL;
  5824. struct hostapd_hw_modes *mode;
  5825. u16 i;
  5826. if (wpa_s->hw.modes == NULL)
  5827. return NULL;
  5828. os_memset(&ranges, 0, sizeof(ranges));
  5829. if (freq_range_list_parse(&ranges, val) < 0)
  5830. return NULL;
  5831. for (i = 0; i < wpa_s->hw.num_modes; i++) {
  5832. int j;
  5833. mode = &wpa_s->hw.modes[i];
  5834. for (j = 0; j < mode->num_channels; j++) {
  5835. unsigned int freq;
  5836. if (mode->channels[j].flag & HOSTAPD_CHAN_DISABLED)
  5837. continue;
  5838. freq = mode->channels[j].freq;
  5839. if (!freq_range_list_includes(&ranges, freq))
  5840. continue;
  5841. int_array_add_unique(&freqs, freq);
  5842. }
  5843. }
  5844. os_free(ranges.range);
  5845. return freqs;
  5846. }
  5847. #ifdef CONFIG_INTERWORKING
  5848. static int ctrl_interworking_select(struct wpa_supplicant *wpa_s, char *param)
  5849. {
  5850. int auto_sel = 0;
  5851. int *freqs = NULL;
  5852. if (param) {
  5853. char *pos;
  5854. auto_sel = os_strstr(param, "auto") != NULL;
  5855. pos = os_strstr(param, "freq=");
  5856. if (pos) {
  5857. freqs = freq_range_to_channel_list(wpa_s, pos + 5);
  5858. if (freqs == NULL)
  5859. return -1;
  5860. }
  5861. }
  5862. return interworking_select(wpa_s, auto_sel, freqs);
  5863. }
  5864. static int ctrl_interworking_connect(struct wpa_supplicant *wpa_s, char *dst,
  5865. int only_add)
  5866. {
  5867. u8 bssid[ETH_ALEN];
  5868. struct wpa_bss *bss;
  5869. if (hwaddr_aton(dst, bssid)) {
  5870. wpa_printf(MSG_DEBUG, "Invalid BSSID '%s'", dst);
  5871. return -1;
  5872. }
  5873. bss = wpa_bss_get_bssid(wpa_s, bssid);
  5874. if (bss == NULL) {
  5875. wpa_printf(MSG_DEBUG, "Could not find BSS " MACSTR,
  5876. MAC2STR(bssid));
  5877. return -1;
  5878. }
  5879. if (bss->ssid_len == 0) {
  5880. int found = 0;
  5881. wpa_printf(MSG_DEBUG, "Selected BSS entry for " MACSTR
  5882. " does not have SSID information", MAC2STR(bssid));
  5883. dl_list_for_each_reverse(bss, &wpa_s->bss, struct wpa_bss,
  5884. list) {
  5885. if (os_memcmp(bss->bssid, bssid, ETH_ALEN) == 0 &&
  5886. bss->ssid_len > 0) {
  5887. found = 1;
  5888. break;
  5889. }
  5890. }
  5891. if (!found)
  5892. return -1;
  5893. wpa_printf(MSG_DEBUG,
  5894. "Found another matching BSS entry with SSID");
  5895. }
  5896. return interworking_connect(wpa_s, bss, only_add);
  5897. }
  5898. static int get_anqp(struct wpa_supplicant *wpa_s, char *dst)
  5899. {
  5900. u8 dst_addr[ETH_ALEN];
  5901. int used;
  5902. char *pos;
  5903. #define MAX_ANQP_INFO_ID 100
  5904. u16 id[MAX_ANQP_INFO_ID];
  5905. size_t num_id = 0;
  5906. u32 subtypes = 0;
  5907. u32 mbo_subtypes = 0;
  5908. used = hwaddr_aton2(dst, dst_addr);
  5909. if (used < 0)
  5910. return -1;
  5911. pos = dst + used;
  5912. if (*pos == ' ')
  5913. pos++;
  5914. while (num_id < MAX_ANQP_INFO_ID) {
  5915. if (os_strncmp(pos, "hs20:", 5) == 0) {
  5916. #ifdef CONFIG_HS20
  5917. int num = atoi(pos + 5);
  5918. if (num <= 0 || num > 31)
  5919. return -1;
  5920. subtypes |= BIT(num);
  5921. #else /* CONFIG_HS20 */
  5922. return -1;
  5923. #endif /* CONFIG_HS20 */
  5924. } else if (os_strncmp(pos, "mbo:", 4) == 0) {
  5925. #ifdef CONFIG_MBO
  5926. int num = atoi(pos + 4);
  5927. if (num <= 0 || num > MAX_MBO_ANQP_SUBTYPE)
  5928. return -1;
  5929. mbo_subtypes |= BIT(num);
  5930. #else /* CONFIG_MBO */
  5931. return -1;
  5932. #endif /* CONFIG_MBO */
  5933. } else {
  5934. id[num_id] = atoi(pos);
  5935. if (id[num_id])
  5936. num_id++;
  5937. }
  5938. pos = os_strchr(pos + 1, ',');
  5939. if (pos == NULL)
  5940. break;
  5941. pos++;
  5942. }
  5943. if (num_id == 0 && !subtypes && !mbo_subtypes)
  5944. return -1;
  5945. return anqp_send_req(wpa_s, dst_addr, id, num_id, subtypes,
  5946. mbo_subtypes);
  5947. }
  5948. static int gas_request(struct wpa_supplicant *wpa_s, char *cmd)
  5949. {
  5950. u8 dst_addr[ETH_ALEN];
  5951. struct wpabuf *advproto, *query = NULL;
  5952. int used, ret = -1;
  5953. char *pos, *end;
  5954. size_t len;
  5955. used = hwaddr_aton2(cmd, dst_addr);
  5956. if (used < 0)
  5957. return -1;
  5958. pos = cmd + used;
  5959. while (*pos == ' ')
  5960. pos++;
  5961. /* Advertisement Protocol ID */
  5962. end = os_strchr(pos, ' ');
  5963. if (end)
  5964. len = end - pos;
  5965. else
  5966. len = os_strlen(pos);
  5967. if (len & 0x01)
  5968. return -1;
  5969. len /= 2;
  5970. if (len == 0)
  5971. return -1;
  5972. advproto = wpabuf_alloc(len);
  5973. if (advproto == NULL)
  5974. return -1;
  5975. if (hexstr2bin(pos, wpabuf_put(advproto, len), len) < 0)
  5976. goto fail;
  5977. if (end) {
  5978. /* Optional Query Request */
  5979. pos = end + 1;
  5980. while (*pos == ' ')
  5981. pos++;
  5982. len = os_strlen(pos);
  5983. if (len) {
  5984. if (len & 0x01)
  5985. goto fail;
  5986. len /= 2;
  5987. if (len == 0)
  5988. goto fail;
  5989. query = wpabuf_alloc(len);
  5990. if (query == NULL)
  5991. goto fail;
  5992. if (hexstr2bin(pos, wpabuf_put(query, len), len) < 0)
  5993. goto fail;
  5994. }
  5995. }
  5996. ret = gas_send_request(wpa_s, dst_addr, advproto, query);
  5997. fail:
  5998. wpabuf_free(advproto);
  5999. wpabuf_free(query);
  6000. return ret;
  6001. }
  6002. static int gas_response_get(struct wpa_supplicant *wpa_s, char *cmd, char *buf,
  6003. size_t buflen)
  6004. {
  6005. u8 addr[ETH_ALEN];
  6006. int dialog_token;
  6007. int used;
  6008. char *pos;
  6009. size_t resp_len, start, requested_len;
  6010. struct wpabuf *resp;
  6011. int ret;
  6012. used = hwaddr_aton2(cmd, addr);
  6013. if (used < 0)
  6014. return -1;
  6015. pos = cmd + used;
  6016. while (*pos == ' ')
  6017. pos++;
  6018. dialog_token = atoi(pos);
  6019. if (wpa_s->last_gas_resp &&
  6020. os_memcmp(addr, wpa_s->last_gas_addr, ETH_ALEN) == 0 &&
  6021. dialog_token == wpa_s->last_gas_dialog_token)
  6022. resp = wpa_s->last_gas_resp;
  6023. else if (wpa_s->prev_gas_resp &&
  6024. os_memcmp(addr, wpa_s->prev_gas_addr, ETH_ALEN) == 0 &&
  6025. dialog_token == wpa_s->prev_gas_dialog_token)
  6026. resp = wpa_s->prev_gas_resp;
  6027. else
  6028. return -1;
  6029. resp_len = wpabuf_len(resp);
  6030. start = 0;
  6031. requested_len = resp_len;
  6032. pos = os_strchr(pos, ' ');
  6033. if (pos) {
  6034. start = atoi(pos);
  6035. if (start > resp_len)
  6036. return os_snprintf(buf, buflen, "FAIL-Invalid range");
  6037. pos = os_strchr(pos, ',');
  6038. if (pos == NULL)
  6039. return -1;
  6040. pos++;
  6041. requested_len = atoi(pos);
  6042. if (start + requested_len > resp_len)
  6043. return os_snprintf(buf, buflen, "FAIL-Invalid range");
  6044. }
  6045. if (requested_len * 2 + 1 > buflen)
  6046. return os_snprintf(buf, buflen, "FAIL-Too long response");
  6047. ret = wpa_snprintf_hex(buf, buflen, wpabuf_head_u8(resp) + start,
  6048. requested_len);
  6049. if (start + requested_len == resp_len) {
  6050. /*
  6051. * Free memory by dropping the response after it has been
  6052. * fetched.
  6053. */
  6054. if (resp == wpa_s->prev_gas_resp) {
  6055. wpabuf_free(wpa_s->prev_gas_resp);
  6056. wpa_s->prev_gas_resp = NULL;
  6057. } else {
  6058. wpabuf_free(wpa_s->last_gas_resp);
  6059. wpa_s->last_gas_resp = NULL;
  6060. }
  6061. }
  6062. return ret;
  6063. }
  6064. #endif /* CONFIG_INTERWORKING */
  6065. #ifdef CONFIG_HS20
  6066. static int get_hs20_anqp(struct wpa_supplicant *wpa_s, char *dst)
  6067. {
  6068. u8 dst_addr[ETH_ALEN];
  6069. int used;
  6070. char *pos;
  6071. u32 subtypes = 0;
  6072. used = hwaddr_aton2(dst, dst_addr);
  6073. if (used < 0)
  6074. return -1;
  6075. pos = dst + used;
  6076. if (*pos == ' ')
  6077. pos++;
  6078. for (;;) {
  6079. int num = atoi(pos);
  6080. if (num <= 0 || num > 31)
  6081. return -1;
  6082. subtypes |= BIT(num);
  6083. pos = os_strchr(pos + 1, ',');
  6084. if (pos == NULL)
  6085. break;
  6086. pos++;
  6087. }
  6088. if (subtypes == 0)
  6089. return -1;
  6090. return hs20_anqp_send_req(wpa_s, dst_addr, subtypes, NULL, 0, 0);
  6091. }
  6092. static int hs20_nai_home_realm_list(struct wpa_supplicant *wpa_s,
  6093. const u8 *addr, const char *realm)
  6094. {
  6095. u8 *buf;
  6096. size_t rlen, len;
  6097. int ret;
  6098. rlen = os_strlen(realm);
  6099. len = 3 + rlen;
  6100. buf = os_malloc(len);
  6101. if (buf == NULL)
  6102. return -1;
  6103. buf[0] = 1; /* NAI Home Realm Count */
  6104. buf[1] = 0; /* Formatted in accordance with RFC 4282 */
  6105. buf[2] = rlen;
  6106. os_memcpy(buf + 3, realm, rlen);
  6107. ret = hs20_anqp_send_req(wpa_s, addr,
  6108. BIT(HS20_STYPE_NAI_HOME_REALM_QUERY),
  6109. buf, len, 0);
  6110. os_free(buf);
  6111. return ret;
  6112. }
  6113. static int hs20_get_nai_home_realm_list(struct wpa_supplicant *wpa_s,
  6114. char *dst)
  6115. {
  6116. struct wpa_cred *cred = wpa_s->conf->cred;
  6117. u8 dst_addr[ETH_ALEN];
  6118. int used;
  6119. u8 *buf;
  6120. size_t len;
  6121. int ret;
  6122. used = hwaddr_aton2(dst, dst_addr);
  6123. if (used < 0)
  6124. return -1;
  6125. while (dst[used] == ' ')
  6126. used++;
  6127. if (os_strncmp(dst + used, "realm=", 6) == 0)
  6128. return hs20_nai_home_realm_list(wpa_s, dst_addr,
  6129. dst + used + 6);
  6130. len = os_strlen(dst + used);
  6131. if (len == 0 && cred && cred->realm)
  6132. return hs20_nai_home_realm_list(wpa_s, dst_addr, cred->realm);
  6133. if (len & 1)
  6134. return -1;
  6135. len /= 2;
  6136. buf = os_malloc(len);
  6137. if (buf == NULL)
  6138. return -1;
  6139. if (hexstr2bin(dst + used, buf, len) < 0) {
  6140. os_free(buf);
  6141. return -1;
  6142. }
  6143. ret = hs20_anqp_send_req(wpa_s, dst_addr,
  6144. BIT(HS20_STYPE_NAI_HOME_REALM_QUERY),
  6145. buf, len, 0);
  6146. os_free(buf);
  6147. return ret;
  6148. }
  6149. static int get_hs20_icon(struct wpa_supplicant *wpa_s, char *cmd, char *reply,
  6150. int buflen)
  6151. {
  6152. u8 dst_addr[ETH_ALEN];
  6153. int used;
  6154. char *ctx = NULL, *icon, *poffset, *psize;
  6155. used = hwaddr_aton2(cmd, dst_addr);
  6156. if (used < 0)
  6157. return -1;
  6158. cmd += used;
  6159. icon = str_token(cmd, " ", &ctx);
  6160. poffset = str_token(cmd, " ", &ctx);
  6161. psize = str_token(cmd, " ", &ctx);
  6162. if (!icon || !poffset || !psize)
  6163. return -1;
  6164. wpa_s->fetch_osu_icon_in_progress = 0;
  6165. return hs20_get_icon(wpa_s, dst_addr, icon, atoi(poffset), atoi(psize),
  6166. reply, buflen);
  6167. }
  6168. static int del_hs20_icon(struct wpa_supplicant *wpa_s, char *cmd)
  6169. {
  6170. u8 dst_addr[ETH_ALEN];
  6171. int used;
  6172. char *icon;
  6173. if (!cmd[0])
  6174. return hs20_del_icon(wpa_s, NULL, NULL);
  6175. used = hwaddr_aton2(cmd, dst_addr);
  6176. if (used < 0)
  6177. return -1;
  6178. while (cmd[used] == ' ')
  6179. used++;
  6180. icon = cmd[used] ? &cmd[used] : NULL;
  6181. return hs20_del_icon(wpa_s, dst_addr, icon);
  6182. }
  6183. static int hs20_icon_request(struct wpa_supplicant *wpa_s, char *cmd, int inmem)
  6184. {
  6185. u8 dst_addr[ETH_ALEN];
  6186. int used;
  6187. char *icon;
  6188. used = hwaddr_aton2(cmd, dst_addr);
  6189. if (used < 0)
  6190. return -1;
  6191. while (cmd[used] == ' ')
  6192. used++;
  6193. icon = &cmd[used];
  6194. wpa_s->fetch_osu_icon_in_progress = 0;
  6195. return hs20_anqp_send_req(wpa_s, dst_addr, BIT(HS20_STYPE_ICON_REQUEST),
  6196. (u8 *) icon, os_strlen(icon), inmem);
  6197. }
  6198. #endif /* CONFIG_HS20 */
  6199. #ifdef CONFIG_AUTOSCAN
  6200. static int wpa_supplicant_ctrl_iface_autoscan(struct wpa_supplicant *wpa_s,
  6201. char *cmd)
  6202. {
  6203. enum wpa_states state = wpa_s->wpa_state;
  6204. char *new_params = NULL;
  6205. if (os_strlen(cmd) > 0) {
  6206. new_params = os_strdup(cmd);
  6207. if (new_params == NULL)
  6208. return -1;
  6209. }
  6210. os_free(wpa_s->conf->autoscan);
  6211. wpa_s->conf->autoscan = new_params;
  6212. if (wpa_s->conf->autoscan == NULL)
  6213. autoscan_deinit(wpa_s);
  6214. else if (state == WPA_DISCONNECTED || state == WPA_INACTIVE)
  6215. autoscan_init(wpa_s, 1);
  6216. else if (state == WPA_SCANNING)
  6217. wpa_supplicant_reinit_autoscan(wpa_s);
  6218. else
  6219. wpa_printf(MSG_DEBUG, "No autoscan update in state %s",
  6220. wpa_supplicant_state_txt(state));
  6221. return 0;
  6222. }
  6223. #endif /* CONFIG_AUTOSCAN */
  6224. #ifdef CONFIG_WNM
  6225. static int wpas_ctrl_iface_wnm_sleep(struct wpa_supplicant *wpa_s, char *cmd)
  6226. {
  6227. int enter;
  6228. int intval = 0;
  6229. char *pos;
  6230. int ret;
  6231. struct wpabuf *tfs_req = NULL;
  6232. if (os_strncmp(cmd, "enter", 5) == 0)
  6233. enter = 1;
  6234. else if (os_strncmp(cmd, "exit", 4) == 0)
  6235. enter = 0;
  6236. else
  6237. return -1;
  6238. pos = os_strstr(cmd, " interval=");
  6239. if (pos)
  6240. intval = atoi(pos + 10);
  6241. pos = os_strstr(cmd, " tfs_req=");
  6242. if (pos) {
  6243. char *end;
  6244. size_t len;
  6245. pos += 9;
  6246. end = os_strchr(pos, ' ');
  6247. if (end)
  6248. len = end - pos;
  6249. else
  6250. len = os_strlen(pos);
  6251. if (len & 1)
  6252. return -1;
  6253. len /= 2;
  6254. tfs_req = wpabuf_alloc(len);
  6255. if (tfs_req == NULL)
  6256. return -1;
  6257. if (hexstr2bin(pos, wpabuf_put(tfs_req, len), len) < 0) {
  6258. wpabuf_free(tfs_req);
  6259. return -1;
  6260. }
  6261. }
  6262. ret = ieee802_11_send_wnmsleep_req(wpa_s, enter ? WNM_SLEEP_MODE_ENTER :
  6263. WNM_SLEEP_MODE_EXIT, intval,
  6264. tfs_req);
  6265. wpabuf_free(tfs_req);
  6266. return ret;
  6267. }
  6268. static int wpas_ctrl_iface_wnm_bss_query(struct wpa_supplicant *wpa_s, char *cmd)
  6269. {
  6270. int query_reason, list = 0;
  6271. char *btm_candidates = NULL;
  6272. query_reason = atoi(cmd);
  6273. cmd = os_strchr(cmd, ' ');
  6274. if (cmd) {
  6275. if (os_strncmp(cmd, " list", 5) == 0)
  6276. list = 1;
  6277. else
  6278. btm_candidates = cmd;
  6279. }
  6280. wpa_printf(MSG_DEBUG,
  6281. "CTRL_IFACE: WNM_BSS_QUERY query_reason=%d%s",
  6282. query_reason, list ? " candidate list" : "");
  6283. return wnm_send_bss_transition_mgmt_query(wpa_s, query_reason,
  6284. btm_candidates,
  6285. list);
  6286. }
  6287. #endif /* CONFIG_WNM */
  6288. static int wpa_supplicant_signal_poll(struct wpa_supplicant *wpa_s, char *buf,
  6289. size_t buflen)
  6290. {
  6291. struct wpa_signal_info si;
  6292. int ret;
  6293. char *pos, *end;
  6294. ret = wpa_drv_signal_poll(wpa_s, &si);
  6295. if (ret)
  6296. return -1;
  6297. pos = buf;
  6298. end = buf + buflen;
  6299. ret = os_snprintf(pos, end - pos, "RSSI=%d\nLINKSPEED=%d\n"
  6300. "NOISE=%d\nFREQUENCY=%u\n",
  6301. si.current_signal, si.current_txrate / 1000,
  6302. si.current_noise, si.frequency);
  6303. if (os_snprintf_error(end - pos, ret))
  6304. return -1;
  6305. pos += ret;
  6306. if (si.chanwidth != CHAN_WIDTH_UNKNOWN) {
  6307. ret = os_snprintf(pos, end - pos, "WIDTH=%s\n",
  6308. channel_width_to_string(si.chanwidth));
  6309. if (os_snprintf_error(end - pos, ret))
  6310. return -1;
  6311. pos += ret;
  6312. }
  6313. if (si.center_frq1 > 0 && si.center_frq2 > 0) {
  6314. ret = os_snprintf(pos, end - pos,
  6315. "CENTER_FRQ1=%d\nCENTER_FRQ2=%d\n",
  6316. si.center_frq1, si.center_frq2);
  6317. if (os_snprintf_error(end - pos, ret))
  6318. return -1;
  6319. pos += ret;
  6320. }
  6321. if (si.avg_signal) {
  6322. ret = os_snprintf(pos, end - pos,
  6323. "AVG_RSSI=%d\n", si.avg_signal);
  6324. if (os_snprintf_error(end - pos, ret))
  6325. return -1;
  6326. pos += ret;
  6327. }
  6328. if (si.avg_beacon_signal) {
  6329. ret = os_snprintf(pos, end - pos,
  6330. "AVG_BEACON_RSSI=%d\n", si.avg_beacon_signal);
  6331. if (os_snprintf_error(end - pos, ret))
  6332. return -1;
  6333. pos += ret;
  6334. }
  6335. return pos - buf;
  6336. }
  6337. static int wpas_ctrl_iface_signal_monitor(struct wpa_supplicant *wpa_s,
  6338. const char *cmd)
  6339. {
  6340. const char *pos;
  6341. int threshold = 0;
  6342. int hysteresis = 0;
  6343. if (wpa_s->bgscan && wpa_s->bgscan_priv) {
  6344. wpa_printf(MSG_DEBUG,
  6345. "Reject SIGNAL_MONITOR command - bgscan is active");
  6346. return -1;
  6347. }
  6348. pos = os_strstr(cmd, "THRESHOLD=");
  6349. if (pos)
  6350. threshold = atoi(pos + 10);
  6351. pos = os_strstr(cmd, "HYSTERESIS=");
  6352. if (pos)
  6353. hysteresis = atoi(pos + 11);
  6354. return wpa_drv_signal_monitor(wpa_s, threshold, hysteresis);
  6355. }
  6356. #ifdef CONFIG_TESTING_OPTIONS
  6357. int wpas_ctrl_iface_get_pref_freq_list_override(struct wpa_supplicant *wpa_s,
  6358. enum wpa_driver_if_type if_type,
  6359. unsigned int *num,
  6360. unsigned int *freq_list)
  6361. {
  6362. char *pos = wpa_s->get_pref_freq_list_override;
  6363. char *end;
  6364. unsigned int count = 0;
  6365. /* Override string format:
  6366. * <if_type1>:<freq1>,<freq2>,... <if_type2>:... */
  6367. while (pos) {
  6368. if (atoi(pos) == (int) if_type)
  6369. break;
  6370. pos = os_strchr(pos, ' ');
  6371. if (pos)
  6372. pos++;
  6373. }
  6374. if (!pos)
  6375. return -1;
  6376. pos = os_strchr(pos, ':');
  6377. if (!pos)
  6378. return -1;
  6379. pos++;
  6380. end = os_strchr(pos, ' ');
  6381. while (pos && (!end || pos < end) && count < *num) {
  6382. freq_list[count++] = atoi(pos);
  6383. pos = os_strchr(pos, ',');
  6384. if (pos)
  6385. pos++;
  6386. }
  6387. *num = count;
  6388. return 0;
  6389. }
  6390. #endif /* CONFIG_TESTING_OPTIONS */
  6391. static int wpas_ctrl_iface_get_pref_freq_list(
  6392. struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
  6393. {
  6394. unsigned int freq_list[100], num = 100, i;
  6395. int ret;
  6396. enum wpa_driver_if_type iface_type;
  6397. char *pos, *end;
  6398. pos = buf;
  6399. end = buf + buflen;
  6400. /* buf: "<interface_type>" */
  6401. if (os_strcmp(cmd, "STATION") == 0)
  6402. iface_type = WPA_IF_STATION;
  6403. else if (os_strcmp(cmd, "AP") == 0)
  6404. iface_type = WPA_IF_AP_BSS;
  6405. else if (os_strcmp(cmd, "P2P_GO") == 0)
  6406. iface_type = WPA_IF_P2P_GO;
  6407. else if (os_strcmp(cmd, "P2P_CLIENT") == 0)
  6408. iface_type = WPA_IF_P2P_CLIENT;
  6409. else if (os_strcmp(cmd, "IBSS") == 0)
  6410. iface_type = WPA_IF_IBSS;
  6411. else if (os_strcmp(cmd, "TDLS") == 0)
  6412. iface_type = WPA_IF_TDLS;
  6413. else
  6414. return -1;
  6415. wpa_printf(MSG_DEBUG,
  6416. "CTRL_IFACE: GET_PREF_FREQ_LIST iface_type=%d (%s)",
  6417. iface_type, buf);
  6418. ret = wpa_drv_get_pref_freq_list(wpa_s, iface_type, &num, freq_list);
  6419. if (ret)
  6420. return -1;
  6421. for (i = 0; i < num; i++) {
  6422. ret = os_snprintf(pos, end - pos, "%s%u",
  6423. i > 0 ? "," : "", freq_list[i]);
  6424. if (os_snprintf_error(end - pos, ret))
  6425. return -1;
  6426. pos += ret;
  6427. }
  6428. return pos - buf;
  6429. }
  6430. static int wpas_ctrl_iface_driver_flags(struct wpa_supplicant *wpa_s,
  6431. char *buf, size_t buflen)
  6432. {
  6433. int ret, i;
  6434. char *pos, *end;
  6435. ret = os_snprintf(buf, buflen, "%016llX:\n",
  6436. (long long unsigned) wpa_s->drv_flags);
  6437. if (os_snprintf_error(buflen, ret))
  6438. return -1;
  6439. pos = buf + ret;
  6440. end = buf + buflen;
  6441. for (i = 0; i < 64; i++) {
  6442. if (wpa_s->drv_flags & (1LLU << i)) {
  6443. ret = os_snprintf(pos, end - pos, "%s\n",
  6444. driver_flag_to_string(1LLU << i));
  6445. if (os_snprintf_error(end - pos, ret))
  6446. return -1;
  6447. pos += ret;
  6448. }
  6449. }
  6450. return pos - buf;
  6451. }
  6452. static int wpa_supplicant_pktcnt_poll(struct wpa_supplicant *wpa_s, char *buf,
  6453. size_t buflen)
  6454. {
  6455. struct hostap_sta_driver_data sta;
  6456. int ret;
  6457. ret = wpa_drv_pktcnt_poll(wpa_s, &sta);
  6458. if (ret)
  6459. return -1;
  6460. ret = os_snprintf(buf, buflen, "TXGOOD=%lu\nTXBAD=%lu\nRXGOOD=%lu\n",
  6461. sta.tx_packets, sta.tx_retry_failed, sta.rx_packets);
  6462. if (os_snprintf_error(buflen, ret))
  6463. return -1;
  6464. return ret;
  6465. }
  6466. #ifdef ANDROID
  6467. static int wpa_supplicant_driver_cmd(struct wpa_supplicant *wpa_s, char *cmd,
  6468. char *buf, size_t buflen)
  6469. {
  6470. int ret;
  6471. ret = wpa_drv_driver_cmd(wpa_s, cmd, buf, buflen);
  6472. if (ret == 0) {
  6473. if (os_strncasecmp(cmd, "COUNTRY", 7) == 0) {
  6474. struct p2p_data *p2p = wpa_s->global->p2p;
  6475. if (p2p) {
  6476. char country[3];
  6477. country[0] = cmd[8];
  6478. country[1] = cmd[9];
  6479. country[2] = 0x04;
  6480. p2p_set_country(p2p, country);
  6481. }
  6482. }
  6483. ret = os_snprintf(buf, buflen, "%s\n", "OK");
  6484. if (os_snprintf_error(buflen, ret))
  6485. ret = -1;
  6486. }
  6487. return ret;
  6488. }
  6489. #endif /* ANDROID */
  6490. static int wpa_supplicant_vendor_cmd(struct wpa_supplicant *wpa_s, char *cmd,
  6491. char *buf, size_t buflen)
  6492. {
  6493. int ret;
  6494. char *pos;
  6495. u8 *data = NULL;
  6496. unsigned int vendor_id, subcmd;
  6497. struct wpabuf *reply;
  6498. size_t data_len = 0;
  6499. /* cmd: <vendor id> <subcommand id> [<hex formatted data>] */
  6500. vendor_id = strtoul(cmd, &pos, 16);
  6501. if (!isblank((unsigned char) *pos))
  6502. return -EINVAL;
  6503. subcmd = strtoul(pos, &pos, 10);
  6504. if (*pos != '\0') {
  6505. if (!isblank((unsigned char) *pos++))
  6506. return -EINVAL;
  6507. data_len = os_strlen(pos);
  6508. }
  6509. if (data_len) {
  6510. data_len /= 2;
  6511. data = os_malloc(data_len);
  6512. if (!data)
  6513. return -1;
  6514. if (hexstr2bin(pos, data, data_len)) {
  6515. wpa_printf(MSG_DEBUG,
  6516. "Vendor command: wrong parameter format");
  6517. os_free(data);
  6518. return -EINVAL;
  6519. }
  6520. }
  6521. reply = wpabuf_alloc((buflen - 1) / 2);
  6522. if (!reply) {
  6523. os_free(data);
  6524. return -1;
  6525. }
  6526. ret = wpa_drv_vendor_cmd(wpa_s, vendor_id, subcmd, data, data_len,
  6527. reply);
  6528. if (ret == 0)
  6529. ret = wpa_snprintf_hex(buf, buflen, wpabuf_head_u8(reply),
  6530. wpabuf_len(reply));
  6531. wpabuf_free(reply);
  6532. os_free(data);
  6533. return ret;
  6534. }
  6535. static void wpa_supplicant_ctrl_iface_flush(struct wpa_supplicant *wpa_s)
  6536. {
  6537. #ifdef CONFIG_P2P
  6538. struct wpa_supplicant *p2p_wpa_s = wpa_s->global->p2p_init_wpa_s ?
  6539. wpa_s->global->p2p_init_wpa_s : wpa_s;
  6540. #endif /* CONFIG_P2P */
  6541. wpa_dbg(wpa_s, MSG_DEBUG, "Flush all wpa_supplicant state");
  6542. if (wpas_abort_ongoing_scan(wpa_s) == 0)
  6543. wpa_s->ignore_post_flush_scan_res = 1;
  6544. if (wpa_s->wpa_state >= WPA_AUTHENTICATING) {
  6545. /*
  6546. * Avoid possible auto connect re-connection on getting
  6547. * disconnected due to state flush.
  6548. */
  6549. wpa_supplicant_set_state(wpa_s, WPA_DISCONNECTED);
  6550. }
  6551. #ifdef CONFIG_P2P
  6552. wpas_p2p_group_remove(p2p_wpa_s, "*");
  6553. wpas_p2p_cancel(p2p_wpa_s);
  6554. p2p_ctrl_flush(p2p_wpa_s);
  6555. wpas_p2p_service_flush(p2p_wpa_s);
  6556. p2p_wpa_s->global->p2p_disabled = 0;
  6557. p2p_wpa_s->global->p2p_per_sta_psk = 0;
  6558. p2p_wpa_s->conf->num_sec_device_types = 0;
  6559. p2p_wpa_s->p2p_disable_ip_addr_req = 0;
  6560. os_free(p2p_wpa_s->global->p2p_go_avoid_freq.range);
  6561. p2p_wpa_s->global->p2p_go_avoid_freq.range = NULL;
  6562. p2p_wpa_s->global->p2p_go_avoid_freq.num = 0;
  6563. p2p_wpa_s->global->pending_p2ps_group = 0;
  6564. p2p_wpa_s->global->pending_p2ps_group_freq = 0;
  6565. #endif /* CONFIG_P2P */
  6566. #ifdef CONFIG_WPS_TESTING
  6567. wps_version_number = 0x20;
  6568. wps_testing_dummy_cred = 0;
  6569. wps_corrupt_pkhash = 0;
  6570. wps_force_auth_types_in_use = 0;
  6571. wps_force_encr_types_in_use = 0;
  6572. #endif /* CONFIG_WPS_TESTING */
  6573. #ifdef CONFIG_WPS
  6574. wpa_s->wps_fragment_size = 0;
  6575. wpas_wps_cancel(wpa_s);
  6576. wps_registrar_flush(wpa_s->wps->registrar);
  6577. #endif /* CONFIG_WPS */
  6578. wpa_s->after_wps = 0;
  6579. wpa_s->known_wps_freq = 0;
  6580. #ifdef CONFIG_DPP
  6581. wpas_dpp_deinit(wpa_s);
  6582. wpa_s->dpp_init_max_tries = 0;
  6583. wpa_s->dpp_init_retry_time = 0;
  6584. wpa_s->dpp_resp_wait_time = 0;
  6585. wpa_s->dpp_resp_max_tries = 0;
  6586. wpa_s->dpp_resp_retry_time = 0;
  6587. os_memset(dpp_pkex_own_mac_override, 0, ETH_ALEN);
  6588. os_memset(dpp_pkex_peer_mac_override, 0, ETH_ALEN);
  6589. dpp_pkex_ephemeral_key_override_len = 0;
  6590. #endif /* CONFIG_DPP */
  6591. #ifdef CONFIG_TDLS
  6592. #ifdef CONFIG_TDLS_TESTING
  6593. tdls_testing = 0;
  6594. #endif /* CONFIG_TDLS_TESTING */
  6595. wpa_drv_tdls_oper(wpa_s, TDLS_ENABLE, NULL);
  6596. wpa_tdls_enable(wpa_s->wpa, 1);
  6597. #endif /* CONFIG_TDLS */
  6598. eloop_cancel_timeout(wpa_supplicant_stop_countermeasures, wpa_s, NULL);
  6599. wpa_supplicant_stop_countermeasures(wpa_s, NULL);
  6600. wpa_s->no_keep_alive = 0;
  6601. wpa_s->own_disconnect_req = 0;
  6602. os_free(wpa_s->disallow_aps_bssid);
  6603. wpa_s->disallow_aps_bssid = NULL;
  6604. wpa_s->disallow_aps_bssid_count = 0;
  6605. os_free(wpa_s->disallow_aps_ssid);
  6606. wpa_s->disallow_aps_ssid = NULL;
  6607. wpa_s->disallow_aps_ssid_count = 0;
  6608. wpa_s->set_sta_uapsd = 0;
  6609. wpa_s->sta_uapsd = 0;
  6610. wpa_drv_radio_disable(wpa_s, 0);
  6611. wpa_blacklist_clear(wpa_s);
  6612. wpa_s->extra_blacklist_count = 0;
  6613. wpa_supplicant_ctrl_iface_remove_network(wpa_s, "all");
  6614. wpa_supplicant_ctrl_iface_remove_cred(wpa_s, "all");
  6615. wpa_config_flush_blobs(wpa_s->conf);
  6616. wpa_s->conf->auto_interworking = 0;
  6617. wpa_s->conf->okc = 0;
  6618. wpa_sm_pmksa_cache_flush(wpa_s->wpa, NULL);
  6619. rsn_preauth_deinit(wpa_s->wpa);
  6620. wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_LIFETIME, 43200);
  6621. wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_REAUTH_THRESHOLD, 70);
  6622. wpa_sm_set_param(wpa_s->wpa, RSNA_SA_TIMEOUT, 60);
  6623. eapol_sm_notify_logoff(wpa_s->eapol, FALSE);
  6624. radio_remove_works(wpa_s, NULL, 1);
  6625. wpa_s->ext_work_in_progress = 0;
  6626. wpa_s->next_ssid = NULL;
  6627. #ifdef CONFIG_INTERWORKING
  6628. #ifdef CONFIG_HS20
  6629. hs20_cancel_fetch_osu(wpa_s);
  6630. hs20_del_icon(wpa_s, NULL, NULL);
  6631. #endif /* CONFIG_HS20 */
  6632. #endif /* CONFIG_INTERWORKING */
  6633. wpa_s->ext_mgmt_frame_handling = 0;
  6634. wpa_s->ext_eapol_frame_io = 0;
  6635. #ifdef CONFIG_TESTING_OPTIONS
  6636. wpa_s->extra_roc_dur = 0;
  6637. wpa_s->test_failure = WPAS_TEST_FAILURE_NONE;
  6638. wpa_s->p2p_go_csa_on_inv = 0;
  6639. wpa_s->ignore_auth_resp = 0;
  6640. wpa_s->ignore_assoc_disallow = 0;
  6641. wpa_s->testing_resend_assoc = 0;
  6642. wpa_s->reject_btm_req_reason = 0;
  6643. wpa_sm_set_test_assoc_ie(wpa_s->wpa, NULL);
  6644. os_free(wpa_s->get_pref_freq_list_override);
  6645. wpa_s->get_pref_freq_list_override = NULL;
  6646. wpabuf_free(wpa_s->sae_commit_override);
  6647. wpa_s->sae_commit_override = NULL;
  6648. #ifdef CONFIG_DPP
  6649. os_free(wpa_s->dpp_config_obj_override);
  6650. wpa_s->dpp_config_obj_override = NULL;
  6651. os_free(wpa_s->dpp_discovery_override);
  6652. wpa_s->dpp_discovery_override = NULL;
  6653. os_free(wpa_s->dpp_groups_override);
  6654. wpa_s->dpp_groups_override = NULL;
  6655. dpp_test = DPP_TEST_DISABLED;
  6656. #endif /* CONFIG_DPP */
  6657. #endif /* CONFIG_TESTING_OPTIONS */
  6658. wpa_s->disconnected = 0;
  6659. os_free(wpa_s->next_scan_freqs);
  6660. wpa_s->next_scan_freqs = NULL;
  6661. os_free(wpa_s->select_network_scan_freqs);
  6662. wpa_s->select_network_scan_freqs = NULL;
  6663. wpa_bss_flush(wpa_s);
  6664. if (!dl_list_empty(&wpa_s->bss)) {
  6665. wpa_printf(MSG_DEBUG,
  6666. "BSS table not empty after flush: %u entries, current_bss=%p bssid="
  6667. MACSTR " pending_bssid=" MACSTR,
  6668. dl_list_len(&wpa_s->bss), wpa_s->current_bss,
  6669. MAC2STR(wpa_s->bssid),
  6670. MAC2STR(wpa_s->pending_bssid));
  6671. }
  6672. eloop_cancel_timeout(wpas_network_reenabled, wpa_s, NULL);
  6673. wpa_s->wnmsleep_used = 0;
  6674. #ifdef CONFIG_SME
  6675. wpa_s->sme.last_unprot_disconnect.sec = 0;
  6676. #endif /* CONFIG_SME */
  6677. wpabuf_free(wpa_s->ric_ies);
  6678. wpa_s->ric_ies = NULL;
  6679. }
  6680. static int wpas_ctrl_radio_work_show(struct wpa_supplicant *wpa_s,
  6681. char *buf, size_t buflen)
  6682. {
  6683. struct wpa_radio_work *work;
  6684. char *pos, *end;
  6685. struct os_reltime now, diff;
  6686. pos = buf;
  6687. end = buf + buflen;
  6688. os_get_reltime(&now);
  6689. dl_list_for_each(work, &wpa_s->radio->work, struct wpa_radio_work, list)
  6690. {
  6691. int ret;
  6692. os_reltime_sub(&now, &work->time, &diff);
  6693. ret = os_snprintf(pos, end - pos, "%s@%s:%u:%u:%ld.%06ld\n",
  6694. work->type, work->wpa_s->ifname, work->freq,
  6695. work->started, diff.sec, diff.usec);
  6696. if (os_snprintf_error(end - pos, ret))
  6697. break;
  6698. pos += ret;
  6699. }
  6700. return pos - buf;
  6701. }
  6702. static void wpas_ctrl_radio_work_timeout(void *eloop_ctx, void *timeout_ctx)
  6703. {
  6704. struct wpa_radio_work *work = eloop_ctx;
  6705. struct wpa_external_work *ework = work->ctx;
  6706. wpa_dbg(work->wpa_s, MSG_DEBUG,
  6707. "Timing out external radio work %u (%s)",
  6708. ework->id, work->type);
  6709. wpa_msg(work->wpa_s, MSG_INFO, EXT_RADIO_WORK_TIMEOUT "%u", ework->id);
  6710. work->wpa_s->ext_work_in_progress = 0;
  6711. radio_work_done(work);
  6712. os_free(ework);
  6713. }
  6714. static void wpas_ctrl_radio_work_cb(struct wpa_radio_work *work, int deinit)
  6715. {
  6716. struct wpa_external_work *ework = work->ctx;
  6717. if (deinit) {
  6718. if (work->started)
  6719. eloop_cancel_timeout(wpas_ctrl_radio_work_timeout,
  6720. work, NULL);
  6721. /*
  6722. * work->type points to a buffer in ework, so need to replace
  6723. * that here with a fixed string to avoid use of freed memory
  6724. * in debug prints.
  6725. */
  6726. work->type = "freed-ext-work";
  6727. work->ctx = NULL;
  6728. os_free(ework);
  6729. return;
  6730. }
  6731. wpa_dbg(work->wpa_s, MSG_DEBUG, "Starting external radio work %u (%s)",
  6732. ework->id, ework->type);
  6733. wpa_msg(work->wpa_s, MSG_INFO, EXT_RADIO_WORK_START "%u", ework->id);
  6734. work->wpa_s->ext_work_in_progress = 1;
  6735. if (!ework->timeout)
  6736. ework->timeout = 10;
  6737. eloop_register_timeout(ework->timeout, 0, wpas_ctrl_radio_work_timeout,
  6738. work, NULL);
  6739. }
  6740. static int wpas_ctrl_radio_work_add(struct wpa_supplicant *wpa_s, char *cmd,
  6741. char *buf, size_t buflen)
  6742. {
  6743. struct wpa_external_work *ework;
  6744. char *pos, *pos2;
  6745. size_t type_len;
  6746. int ret;
  6747. unsigned int freq = 0;
  6748. /* format: <name> [freq=<MHz>] [timeout=<seconds>] */
  6749. ework = os_zalloc(sizeof(*ework));
  6750. if (ework == NULL)
  6751. return -1;
  6752. pos = os_strchr(cmd, ' ');
  6753. if (pos) {
  6754. type_len = pos - cmd;
  6755. pos++;
  6756. pos2 = os_strstr(pos, "freq=");
  6757. if (pos2)
  6758. freq = atoi(pos2 + 5);
  6759. pos2 = os_strstr(pos, "timeout=");
  6760. if (pos2)
  6761. ework->timeout = atoi(pos2 + 8);
  6762. } else {
  6763. type_len = os_strlen(cmd);
  6764. }
  6765. if (4 + type_len >= sizeof(ework->type))
  6766. type_len = sizeof(ework->type) - 4 - 1;
  6767. os_strlcpy(ework->type, "ext:", sizeof(ework->type));
  6768. os_memcpy(ework->type + 4, cmd, type_len);
  6769. ework->type[4 + type_len] = '\0';
  6770. wpa_s->ext_work_id++;
  6771. if (wpa_s->ext_work_id == 0)
  6772. wpa_s->ext_work_id++;
  6773. ework->id = wpa_s->ext_work_id;
  6774. if (radio_add_work(wpa_s, freq, ework->type, 0, wpas_ctrl_radio_work_cb,
  6775. ework) < 0) {
  6776. os_free(ework);
  6777. return -1;
  6778. }
  6779. ret = os_snprintf(buf, buflen, "%u", ework->id);
  6780. if (os_snprintf_error(buflen, ret))
  6781. return -1;
  6782. return ret;
  6783. }
  6784. static int wpas_ctrl_radio_work_done(struct wpa_supplicant *wpa_s, char *cmd)
  6785. {
  6786. struct wpa_radio_work *work;
  6787. unsigned int id = atoi(cmd);
  6788. dl_list_for_each(work, &wpa_s->radio->work, struct wpa_radio_work, list)
  6789. {
  6790. struct wpa_external_work *ework;
  6791. if (os_strncmp(work->type, "ext:", 4) != 0)
  6792. continue;
  6793. ework = work->ctx;
  6794. if (id && ework->id != id)
  6795. continue;
  6796. wpa_dbg(wpa_s, MSG_DEBUG,
  6797. "Completed external radio work %u (%s)",
  6798. ework->id, ework->type);
  6799. eloop_cancel_timeout(wpas_ctrl_radio_work_timeout, work, NULL);
  6800. wpa_s->ext_work_in_progress = 0;
  6801. radio_work_done(work);
  6802. os_free(ework);
  6803. return 3; /* "OK\n" */
  6804. }
  6805. return -1;
  6806. }
  6807. static int wpas_ctrl_radio_work(struct wpa_supplicant *wpa_s, char *cmd,
  6808. char *buf, size_t buflen)
  6809. {
  6810. if (os_strcmp(cmd, "show") == 0)
  6811. return wpas_ctrl_radio_work_show(wpa_s, buf, buflen);
  6812. if (os_strncmp(cmd, "add ", 4) == 0)
  6813. return wpas_ctrl_radio_work_add(wpa_s, cmd + 4, buf, buflen);
  6814. if (os_strncmp(cmd, "done ", 5) == 0)
  6815. return wpas_ctrl_radio_work_done(wpa_s, cmd + 4);
  6816. return -1;
  6817. }
  6818. void wpas_ctrl_radio_work_flush(struct wpa_supplicant *wpa_s)
  6819. {
  6820. struct wpa_radio_work *work, *tmp;
  6821. if (!wpa_s || !wpa_s->radio)
  6822. return;
  6823. dl_list_for_each_safe(work, tmp, &wpa_s->radio->work,
  6824. struct wpa_radio_work, list) {
  6825. struct wpa_external_work *ework;
  6826. if (os_strncmp(work->type, "ext:", 4) != 0)
  6827. continue;
  6828. ework = work->ctx;
  6829. wpa_dbg(wpa_s, MSG_DEBUG,
  6830. "Flushing%s external radio work %u (%s)",
  6831. work->started ? " started" : "", ework->id,
  6832. ework->type);
  6833. if (work->started)
  6834. eloop_cancel_timeout(wpas_ctrl_radio_work_timeout,
  6835. work, NULL);
  6836. radio_work_done(work);
  6837. os_free(ework);
  6838. }
  6839. }
  6840. static void wpas_ctrl_eapol_response(void *eloop_ctx, void *timeout_ctx)
  6841. {
  6842. struct wpa_supplicant *wpa_s = eloop_ctx;
  6843. eapol_sm_notify_ctrl_response(wpa_s->eapol);
  6844. }
  6845. static int scan_id_list_parse(struct wpa_supplicant *wpa_s, const char *value,
  6846. unsigned int *scan_id_count, int scan_id[])
  6847. {
  6848. const char *pos = value;
  6849. while (pos) {
  6850. if (*pos == ' ' || *pos == '\0')
  6851. break;
  6852. if (*scan_id_count == MAX_SCAN_ID)
  6853. return -1;
  6854. scan_id[(*scan_id_count)++] = atoi(pos);
  6855. pos = os_strchr(pos, ',');
  6856. if (pos)
  6857. pos++;
  6858. }
  6859. return 0;
  6860. }
  6861. static void wpas_ctrl_scan(struct wpa_supplicant *wpa_s, char *params,
  6862. char *reply, int reply_size, int *reply_len)
  6863. {
  6864. char *pos;
  6865. unsigned int manual_scan_passive = 0;
  6866. unsigned int manual_scan_use_id = 0;
  6867. unsigned int manual_scan_only_new = 0;
  6868. unsigned int scan_only = 0;
  6869. unsigned int scan_id_count = 0;
  6870. int scan_id[MAX_SCAN_ID];
  6871. void (*scan_res_handler)(struct wpa_supplicant *wpa_s,
  6872. struct wpa_scan_results *scan_res);
  6873. int *manual_scan_freqs = NULL;
  6874. struct wpa_ssid_value *ssid = NULL, *ns;
  6875. unsigned int ssid_count = 0;
  6876. if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
  6877. *reply_len = -1;
  6878. return;
  6879. }
  6880. if (radio_work_pending(wpa_s, "scan")) {
  6881. wpa_printf(MSG_DEBUG,
  6882. "Pending scan scheduled - reject new request");
  6883. *reply_len = os_snprintf(reply, reply_size, "FAIL-BUSY\n");
  6884. return;
  6885. }
  6886. #ifdef CONFIG_INTERWORKING
  6887. if (wpa_s->fetch_anqp_in_progress || wpa_s->network_select) {
  6888. wpa_printf(MSG_DEBUG,
  6889. "Interworking select in progress - reject new scan");
  6890. *reply_len = os_snprintf(reply, reply_size, "FAIL-BUSY\n");
  6891. return;
  6892. }
  6893. #endif /* CONFIG_INTERWORKING */
  6894. if (params) {
  6895. if (os_strncasecmp(params, "TYPE=ONLY", 9) == 0)
  6896. scan_only = 1;
  6897. pos = os_strstr(params, "freq=");
  6898. if (pos) {
  6899. manual_scan_freqs = freq_range_to_channel_list(wpa_s,
  6900. pos + 5);
  6901. if (manual_scan_freqs == NULL) {
  6902. *reply_len = -1;
  6903. goto done;
  6904. }
  6905. }
  6906. pos = os_strstr(params, "passive=");
  6907. if (pos)
  6908. manual_scan_passive = !!atoi(pos + 8);
  6909. pos = os_strstr(params, "use_id=");
  6910. if (pos)
  6911. manual_scan_use_id = atoi(pos + 7);
  6912. pos = os_strstr(params, "only_new=1");
  6913. if (pos)
  6914. manual_scan_only_new = 1;
  6915. pos = os_strstr(params, "scan_id=");
  6916. if (pos && scan_id_list_parse(wpa_s, pos + 8, &scan_id_count,
  6917. scan_id) < 0) {
  6918. *reply_len = -1;
  6919. goto done;
  6920. }
  6921. pos = os_strstr(params, "bssid=");
  6922. if (pos) {
  6923. u8 bssid[ETH_ALEN];
  6924. pos += 6;
  6925. if (hwaddr_aton(pos, bssid)) {
  6926. wpa_printf(MSG_ERROR, "Invalid BSSID %s", pos);
  6927. *reply_len = -1;
  6928. goto done;
  6929. }
  6930. os_memcpy(wpa_s->next_scan_bssid, bssid, ETH_ALEN);
  6931. }
  6932. pos = params;
  6933. while (pos && *pos != '\0') {
  6934. if (os_strncmp(pos, "ssid ", 5) == 0) {
  6935. char *end;
  6936. pos += 5;
  6937. end = pos;
  6938. while (*end) {
  6939. if (*end == '\0' || *end == ' ')
  6940. break;
  6941. end++;
  6942. }
  6943. ns = os_realloc_array(
  6944. ssid, ssid_count + 1,
  6945. sizeof(struct wpa_ssid_value));
  6946. if (ns == NULL) {
  6947. *reply_len = -1;
  6948. goto done;
  6949. }
  6950. ssid = ns;
  6951. if ((end - pos) & 0x01 ||
  6952. end - pos > 2 * SSID_MAX_LEN ||
  6953. hexstr2bin(pos, ssid[ssid_count].ssid,
  6954. (end - pos) / 2) < 0) {
  6955. wpa_printf(MSG_DEBUG,
  6956. "Invalid SSID value '%s'",
  6957. pos);
  6958. *reply_len = -1;
  6959. goto done;
  6960. }
  6961. ssid[ssid_count].ssid_len = (end - pos) / 2;
  6962. wpa_hexdump_ascii(MSG_DEBUG, "scan SSID",
  6963. ssid[ssid_count].ssid,
  6964. ssid[ssid_count].ssid_len);
  6965. ssid_count++;
  6966. pos = end;
  6967. }
  6968. pos = os_strchr(pos, ' ');
  6969. if (pos)
  6970. pos++;
  6971. }
  6972. }
  6973. wpa_s->num_ssids_from_scan_req = ssid_count;
  6974. os_free(wpa_s->ssids_from_scan_req);
  6975. if (ssid_count) {
  6976. wpa_s->ssids_from_scan_req = ssid;
  6977. ssid = NULL;
  6978. } else {
  6979. wpa_s->ssids_from_scan_req = NULL;
  6980. }
  6981. if (scan_only)
  6982. scan_res_handler = scan_only_handler;
  6983. else if (wpa_s->scan_res_handler == scan_only_handler)
  6984. scan_res_handler = NULL;
  6985. else
  6986. scan_res_handler = wpa_s->scan_res_handler;
  6987. if (!wpa_s->sched_scanning && !wpa_s->scanning &&
  6988. ((wpa_s->wpa_state <= WPA_SCANNING) ||
  6989. (wpa_s->wpa_state == WPA_COMPLETED))) {
  6990. wpa_s->manual_scan_passive = manual_scan_passive;
  6991. wpa_s->manual_scan_use_id = manual_scan_use_id;
  6992. wpa_s->manual_scan_only_new = manual_scan_only_new;
  6993. wpa_s->scan_id_count = scan_id_count;
  6994. os_memcpy(wpa_s->scan_id, scan_id, scan_id_count * sizeof(int));
  6995. wpa_s->scan_res_handler = scan_res_handler;
  6996. os_free(wpa_s->manual_scan_freqs);
  6997. wpa_s->manual_scan_freqs = manual_scan_freqs;
  6998. manual_scan_freqs = NULL;
  6999. wpa_s->normal_scans = 0;
  7000. wpa_s->scan_req = MANUAL_SCAN_REQ;
  7001. wpa_s->after_wps = 0;
  7002. wpa_s->known_wps_freq = 0;
  7003. wpa_supplicant_req_scan(wpa_s, 0, 0);
  7004. if (wpa_s->manual_scan_use_id) {
  7005. wpa_s->manual_scan_id++;
  7006. wpa_dbg(wpa_s, MSG_DEBUG, "Assigned scan id %u",
  7007. wpa_s->manual_scan_id);
  7008. *reply_len = os_snprintf(reply, reply_size, "%u\n",
  7009. wpa_s->manual_scan_id);
  7010. }
  7011. } else if (wpa_s->sched_scanning) {
  7012. wpa_s->manual_scan_passive = manual_scan_passive;
  7013. wpa_s->manual_scan_use_id = manual_scan_use_id;
  7014. wpa_s->manual_scan_only_new = manual_scan_only_new;
  7015. wpa_s->scan_id_count = scan_id_count;
  7016. os_memcpy(wpa_s->scan_id, scan_id, scan_id_count * sizeof(int));
  7017. wpa_s->scan_res_handler = scan_res_handler;
  7018. os_free(wpa_s->manual_scan_freqs);
  7019. wpa_s->manual_scan_freqs = manual_scan_freqs;
  7020. manual_scan_freqs = NULL;
  7021. wpa_printf(MSG_DEBUG, "Stop ongoing sched_scan to allow requested full scan to proceed");
  7022. wpa_supplicant_cancel_sched_scan(wpa_s);
  7023. wpa_s->scan_req = MANUAL_SCAN_REQ;
  7024. wpa_supplicant_req_scan(wpa_s, 0, 0);
  7025. if (wpa_s->manual_scan_use_id) {
  7026. wpa_s->manual_scan_id++;
  7027. *reply_len = os_snprintf(reply, reply_size, "%u\n",
  7028. wpa_s->manual_scan_id);
  7029. wpa_dbg(wpa_s, MSG_DEBUG, "Assigned scan id %u",
  7030. wpa_s->manual_scan_id);
  7031. }
  7032. } else {
  7033. wpa_printf(MSG_DEBUG, "Ongoing scan action - reject new request");
  7034. *reply_len = os_snprintf(reply, reply_size, "FAIL-BUSY\n");
  7035. }
  7036. done:
  7037. os_free(manual_scan_freqs);
  7038. os_free(ssid);
  7039. }
  7040. #ifdef CONFIG_TESTING_OPTIONS
  7041. static void wpas_ctrl_iface_mgmt_tx_cb(struct wpa_supplicant *wpa_s,
  7042. unsigned int freq, const u8 *dst,
  7043. const u8 *src, const u8 *bssid,
  7044. const u8 *data, size_t data_len,
  7045. enum offchannel_send_action_result
  7046. result)
  7047. {
  7048. wpa_msg(wpa_s, MSG_INFO, "MGMT-TX-STATUS freq=%u dst=" MACSTR
  7049. " src=" MACSTR " bssid=" MACSTR " result=%s",
  7050. freq, MAC2STR(dst), MAC2STR(src), MAC2STR(bssid),
  7051. result == OFFCHANNEL_SEND_ACTION_SUCCESS ?
  7052. "SUCCESS" : (result == OFFCHANNEL_SEND_ACTION_NO_ACK ?
  7053. "NO_ACK" : "FAILED"));
  7054. }
  7055. static int wpas_ctrl_iface_mgmt_tx(struct wpa_supplicant *wpa_s, char *cmd)
  7056. {
  7057. char *pos, *param;
  7058. size_t len;
  7059. u8 *buf, da[ETH_ALEN], bssid[ETH_ALEN];
  7060. int res, used;
  7061. int freq = 0, no_cck = 0, wait_time = 0;
  7062. /* <DA> <BSSID> [freq=<MHz>] [wait_time=<ms>] [no_cck=1]
  7063. * <action=Action frame payload> */
  7064. wpa_printf(MSG_DEBUG, "External MGMT TX: %s", cmd);
  7065. pos = cmd;
  7066. used = hwaddr_aton2(pos, da);
  7067. if (used < 0)
  7068. return -1;
  7069. pos += used;
  7070. while (*pos == ' ')
  7071. pos++;
  7072. used = hwaddr_aton2(pos, bssid);
  7073. if (used < 0)
  7074. return -1;
  7075. pos += used;
  7076. param = os_strstr(pos, " freq=");
  7077. if (param) {
  7078. param += 6;
  7079. freq = atoi(param);
  7080. }
  7081. param = os_strstr(pos, " no_cck=");
  7082. if (param) {
  7083. param += 8;
  7084. no_cck = atoi(param);
  7085. }
  7086. param = os_strstr(pos, " wait_time=");
  7087. if (param) {
  7088. param += 11;
  7089. wait_time = atoi(param);
  7090. }
  7091. param = os_strstr(pos, " action=");
  7092. if (param == NULL)
  7093. return -1;
  7094. param += 8;
  7095. len = os_strlen(param);
  7096. if (len & 1)
  7097. return -1;
  7098. len /= 2;
  7099. buf = os_malloc(len);
  7100. if (buf == NULL)
  7101. return -1;
  7102. if (hexstr2bin(param, buf, len) < 0) {
  7103. os_free(buf);
  7104. return -1;
  7105. }
  7106. res = offchannel_send_action(wpa_s, freq, da, wpa_s->own_addr, bssid,
  7107. buf, len, wait_time,
  7108. wpas_ctrl_iface_mgmt_tx_cb, no_cck);
  7109. os_free(buf);
  7110. return res;
  7111. }
  7112. static void wpas_ctrl_iface_mgmt_tx_done(struct wpa_supplicant *wpa_s)
  7113. {
  7114. wpa_printf(MSG_DEBUG, "External MGMT TX - done waiting");
  7115. offchannel_send_action_done(wpa_s);
  7116. }
  7117. static int wpas_ctrl_iface_mgmt_rx_process(struct wpa_supplicant *wpa_s,
  7118. char *cmd)
  7119. {
  7120. char *pos, *param;
  7121. size_t len;
  7122. u8 *buf;
  7123. int freq = 0, datarate = 0, ssi_signal = 0;
  7124. union wpa_event_data event;
  7125. if (!wpa_s->ext_mgmt_frame_handling)
  7126. return -1;
  7127. /* freq=<MHz> datarate=<val> ssi_signal=<val> frame=<frame hexdump> */
  7128. wpa_printf(MSG_DEBUG, "External MGMT RX process: %s", cmd);
  7129. pos = cmd;
  7130. param = os_strstr(pos, "freq=");
  7131. if (param) {
  7132. param += 5;
  7133. freq = atoi(param);
  7134. }
  7135. param = os_strstr(pos, " datarate=");
  7136. if (param) {
  7137. param += 10;
  7138. datarate = atoi(param);
  7139. }
  7140. param = os_strstr(pos, " ssi_signal=");
  7141. if (param) {
  7142. param += 12;
  7143. ssi_signal = atoi(param);
  7144. }
  7145. param = os_strstr(pos, " frame=");
  7146. if (param == NULL)
  7147. return -1;
  7148. param += 7;
  7149. len = os_strlen(param);
  7150. if (len & 1)
  7151. return -1;
  7152. len /= 2;
  7153. buf = os_malloc(len);
  7154. if (buf == NULL)
  7155. return -1;
  7156. if (hexstr2bin(param, buf, len) < 0) {
  7157. os_free(buf);
  7158. return -1;
  7159. }
  7160. os_memset(&event, 0, sizeof(event));
  7161. event.rx_mgmt.freq = freq;
  7162. event.rx_mgmt.frame = buf;
  7163. event.rx_mgmt.frame_len = len;
  7164. event.rx_mgmt.ssi_signal = ssi_signal;
  7165. event.rx_mgmt.datarate = datarate;
  7166. wpa_s->ext_mgmt_frame_handling = 0;
  7167. wpa_supplicant_event(wpa_s, EVENT_RX_MGMT, &event);
  7168. wpa_s->ext_mgmt_frame_handling = 1;
  7169. os_free(buf);
  7170. return 0;
  7171. }
  7172. static int wpas_ctrl_iface_driver_scan_res(struct wpa_supplicant *wpa_s,
  7173. char *param)
  7174. {
  7175. struct wpa_scan_res *res;
  7176. struct os_reltime now;
  7177. char *pos, *end;
  7178. int ret = -1;
  7179. if (!param)
  7180. return -1;
  7181. if (os_strcmp(param, "START") == 0) {
  7182. wpa_bss_update_start(wpa_s);
  7183. return 0;
  7184. }
  7185. if (os_strcmp(param, "END") == 0) {
  7186. wpa_bss_update_end(wpa_s, NULL, 1);
  7187. return 0;
  7188. }
  7189. if (os_strncmp(param, "BSS ", 4) != 0)
  7190. return -1;
  7191. param += 3;
  7192. res = os_zalloc(sizeof(*res) + os_strlen(param) / 2);
  7193. if (!res)
  7194. return -1;
  7195. pos = os_strstr(param, " flags=");
  7196. if (pos)
  7197. res->flags = strtol(pos + 7, NULL, 16);
  7198. pos = os_strstr(param, " bssid=");
  7199. if (pos && hwaddr_aton(pos + 7, res->bssid))
  7200. goto fail;
  7201. pos = os_strstr(param, " freq=");
  7202. if (pos)
  7203. res->freq = atoi(pos + 6);
  7204. pos = os_strstr(param, " beacon_int=");
  7205. if (pos)
  7206. res->beacon_int = atoi(pos + 12);
  7207. pos = os_strstr(param, " caps=");
  7208. if (pos)
  7209. res->caps = strtol(pos + 6, NULL, 16);
  7210. pos = os_strstr(param, " qual=");
  7211. if (pos)
  7212. res->qual = atoi(pos + 6);
  7213. pos = os_strstr(param, " noise=");
  7214. if (pos)
  7215. res->noise = atoi(pos + 7);
  7216. pos = os_strstr(param, " level=");
  7217. if (pos)
  7218. res->level = atoi(pos + 7);
  7219. pos = os_strstr(param, " tsf=");
  7220. if (pos)
  7221. res->tsf = strtoll(pos + 5, NULL, 16);
  7222. pos = os_strstr(param, " age=");
  7223. if (pos)
  7224. res->age = atoi(pos + 5);
  7225. pos = os_strstr(param, " est_throughput=");
  7226. if (pos)
  7227. res->est_throughput = atoi(pos + 16);
  7228. pos = os_strstr(param, " snr=");
  7229. if (pos)
  7230. res->snr = atoi(pos + 5);
  7231. pos = os_strstr(param, " parent_tsf=");
  7232. if (pos)
  7233. res->parent_tsf = strtoll(pos + 7, NULL, 16);
  7234. pos = os_strstr(param, " tsf_bssid=");
  7235. if (pos && hwaddr_aton(pos + 11, res->tsf_bssid))
  7236. goto fail;
  7237. pos = os_strstr(param, " ie=");
  7238. if (pos) {
  7239. pos += 4;
  7240. end = os_strchr(pos, ' ');
  7241. if (!end)
  7242. end = pos + os_strlen(pos);
  7243. res->ie_len = (end - pos) / 2;
  7244. if (hexstr2bin(pos, (u8 *) (res + 1), res->ie_len))
  7245. goto fail;
  7246. }
  7247. pos = os_strstr(param, " beacon_ie=");
  7248. if (pos) {
  7249. pos += 11;
  7250. end = os_strchr(pos, ' ');
  7251. if (!end)
  7252. end = pos + os_strlen(pos);
  7253. res->beacon_ie_len = (end - pos) / 2;
  7254. if (hexstr2bin(pos, ((u8 *) (res + 1)) + res->ie_len,
  7255. res->beacon_ie_len))
  7256. goto fail;
  7257. }
  7258. os_get_reltime(&now);
  7259. wpa_bss_update_scan_res(wpa_s, res, &now);
  7260. ret = 0;
  7261. fail:
  7262. os_free(res);
  7263. return ret;
  7264. }
  7265. static int wpas_ctrl_iface_driver_event(struct wpa_supplicant *wpa_s, char *cmd)
  7266. {
  7267. char *pos, *param;
  7268. union wpa_event_data event;
  7269. enum wpa_event_type ev;
  7270. /* <event name> [parameters..] */
  7271. wpa_dbg(wpa_s, MSG_DEBUG, "Testing - external driver event: %s", cmd);
  7272. pos = cmd;
  7273. param = os_strchr(pos, ' ');
  7274. if (param)
  7275. *param++ = '\0';
  7276. os_memset(&event, 0, sizeof(event));
  7277. if (os_strcmp(cmd, "INTERFACE_ENABLED") == 0) {
  7278. ev = EVENT_INTERFACE_ENABLED;
  7279. } else if (os_strcmp(cmd, "INTERFACE_DISABLED") == 0) {
  7280. ev = EVENT_INTERFACE_DISABLED;
  7281. } else if (os_strcmp(cmd, "AVOID_FREQUENCIES") == 0) {
  7282. ev = EVENT_AVOID_FREQUENCIES;
  7283. if (param == NULL)
  7284. param = "";
  7285. if (freq_range_list_parse(&event.freq_range, param) < 0)
  7286. return -1;
  7287. wpa_supplicant_event(wpa_s, ev, &event);
  7288. os_free(event.freq_range.range);
  7289. return 0;
  7290. } else if (os_strcmp(cmd, "SCAN_RES") == 0) {
  7291. return wpas_ctrl_iface_driver_scan_res(wpa_s, param);
  7292. } else {
  7293. wpa_dbg(wpa_s, MSG_DEBUG, "Testing - unknown driver event: %s",
  7294. cmd);
  7295. return -1;
  7296. }
  7297. wpa_supplicant_event(wpa_s, ev, &event);
  7298. return 0;
  7299. }
  7300. static int wpas_ctrl_iface_eapol_rx(struct wpa_supplicant *wpa_s, char *cmd)
  7301. {
  7302. char *pos;
  7303. u8 src[ETH_ALEN], *buf;
  7304. int used;
  7305. size_t len;
  7306. wpa_printf(MSG_DEBUG, "External EAPOL RX: %s", cmd);
  7307. pos = cmd;
  7308. used = hwaddr_aton2(pos, src);
  7309. if (used < 0)
  7310. return -1;
  7311. pos += used;
  7312. while (*pos == ' ')
  7313. pos++;
  7314. len = os_strlen(pos);
  7315. if (len & 1)
  7316. return -1;
  7317. len /= 2;
  7318. buf = os_malloc(len);
  7319. if (buf == NULL)
  7320. return -1;
  7321. if (hexstr2bin(pos, buf, len) < 0) {
  7322. os_free(buf);
  7323. return -1;
  7324. }
  7325. wpa_supplicant_rx_eapol(wpa_s, src, buf, len);
  7326. os_free(buf);
  7327. return 0;
  7328. }
  7329. static u16 ipv4_hdr_checksum(const void *buf, size_t len)
  7330. {
  7331. size_t i;
  7332. u32 sum = 0;
  7333. const u16 *pos = buf;
  7334. for (i = 0; i < len / 2; i++)
  7335. sum += *pos++;
  7336. while (sum >> 16)
  7337. sum = (sum & 0xffff) + (sum >> 16);
  7338. return sum ^ 0xffff;
  7339. }
  7340. #define HWSIM_PACKETLEN 1500
  7341. #define HWSIM_IP_LEN (HWSIM_PACKETLEN - sizeof(struct ether_header))
  7342. static void wpas_data_test_rx(void *ctx, const u8 *src_addr, const u8 *buf,
  7343. size_t len)
  7344. {
  7345. struct wpa_supplicant *wpa_s = ctx;
  7346. const struct ether_header *eth;
  7347. struct iphdr ip;
  7348. const u8 *pos;
  7349. unsigned int i;
  7350. if (len != HWSIM_PACKETLEN)
  7351. return;
  7352. eth = (const struct ether_header *) buf;
  7353. os_memcpy(&ip, eth + 1, sizeof(ip));
  7354. pos = &buf[sizeof(*eth) + sizeof(ip)];
  7355. if (ip.ihl != 5 || ip.version != 4 ||
  7356. ntohs(ip.tot_len) != HWSIM_IP_LEN)
  7357. return;
  7358. for (i = 0; i < HWSIM_IP_LEN - sizeof(ip); i++) {
  7359. if (*pos != (u8) i)
  7360. return;
  7361. pos++;
  7362. }
  7363. wpa_msg(wpa_s, MSG_INFO, "DATA-TEST-RX " MACSTR " " MACSTR,
  7364. MAC2STR(eth->ether_dhost), MAC2STR(eth->ether_shost));
  7365. }
  7366. static int wpas_ctrl_iface_data_test_config(struct wpa_supplicant *wpa_s,
  7367. char *cmd)
  7368. {
  7369. int enabled = atoi(cmd);
  7370. char *pos;
  7371. const char *ifname;
  7372. if (!enabled) {
  7373. if (wpa_s->l2_test) {
  7374. l2_packet_deinit(wpa_s->l2_test);
  7375. wpa_s->l2_test = NULL;
  7376. wpa_dbg(wpa_s, MSG_DEBUG, "test data: Disabled");
  7377. }
  7378. return 0;
  7379. }
  7380. if (wpa_s->l2_test)
  7381. return 0;
  7382. pos = os_strstr(cmd, " ifname=");
  7383. if (pos)
  7384. ifname = pos + 8;
  7385. else
  7386. ifname = wpa_s->ifname;
  7387. wpa_s->l2_test = l2_packet_init(ifname, wpa_s->own_addr,
  7388. ETHERTYPE_IP, wpas_data_test_rx,
  7389. wpa_s, 1);
  7390. if (wpa_s->l2_test == NULL)
  7391. return -1;
  7392. wpa_dbg(wpa_s, MSG_DEBUG, "test data: Enabled");
  7393. return 0;
  7394. }
  7395. static int wpas_ctrl_iface_data_test_tx(struct wpa_supplicant *wpa_s, char *cmd)
  7396. {
  7397. u8 dst[ETH_ALEN], src[ETH_ALEN];
  7398. char *pos;
  7399. int used;
  7400. long int val;
  7401. u8 tos;
  7402. u8 buf[2 + HWSIM_PACKETLEN];
  7403. struct ether_header *eth;
  7404. struct iphdr *ip;
  7405. u8 *dpos;
  7406. unsigned int i;
  7407. if (wpa_s->l2_test == NULL)
  7408. return -1;
  7409. /* format: <dst> <src> <tos> */
  7410. pos = cmd;
  7411. used = hwaddr_aton2(pos, dst);
  7412. if (used < 0)
  7413. return -1;
  7414. pos += used;
  7415. while (*pos == ' ')
  7416. pos++;
  7417. used = hwaddr_aton2(pos, src);
  7418. if (used < 0)
  7419. return -1;
  7420. pos += used;
  7421. val = strtol(pos, NULL, 0);
  7422. if (val < 0 || val > 0xff)
  7423. return -1;
  7424. tos = val;
  7425. eth = (struct ether_header *) &buf[2];
  7426. os_memcpy(eth->ether_dhost, dst, ETH_ALEN);
  7427. os_memcpy(eth->ether_shost, src, ETH_ALEN);
  7428. eth->ether_type = htons(ETHERTYPE_IP);
  7429. ip = (struct iphdr *) (eth + 1);
  7430. os_memset(ip, 0, sizeof(*ip));
  7431. ip->ihl = 5;
  7432. ip->version = 4;
  7433. ip->ttl = 64;
  7434. ip->tos = tos;
  7435. ip->tot_len = htons(HWSIM_IP_LEN);
  7436. ip->protocol = 1;
  7437. ip->saddr = htonl(192U << 24 | 168 << 16 | 1 << 8 | 1);
  7438. ip->daddr = htonl(192U << 24 | 168 << 16 | 1 << 8 | 2);
  7439. ip->check = ipv4_hdr_checksum(ip, sizeof(*ip));
  7440. dpos = (u8 *) (ip + 1);
  7441. for (i = 0; i < HWSIM_IP_LEN - sizeof(*ip); i++)
  7442. *dpos++ = i;
  7443. if (l2_packet_send(wpa_s->l2_test, dst, ETHERTYPE_IP, &buf[2],
  7444. HWSIM_PACKETLEN) < 0)
  7445. return -1;
  7446. wpa_dbg(wpa_s, MSG_DEBUG, "test data: TX dst=" MACSTR " src=" MACSTR
  7447. " tos=0x%x", MAC2STR(dst), MAC2STR(src), tos);
  7448. return 0;
  7449. }
  7450. static int wpas_ctrl_iface_data_test_frame(struct wpa_supplicant *wpa_s,
  7451. char *cmd)
  7452. {
  7453. u8 *buf;
  7454. struct ether_header *eth;
  7455. struct l2_packet_data *l2 = NULL;
  7456. size_t len;
  7457. u16 ethertype;
  7458. int res = -1;
  7459. len = os_strlen(cmd);
  7460. if (len & 1 || len < ETH_HLEN * 2)
  7461. return -1;
  7462. len /= 2;
  7463. buf = os_malloc(len);
  7464. if (buf == NULL)
  7465. return -1;
  7466. if (hexstr2bin(cmd, buf, len) < 0)
  7467. goto done;
  7468. eth = (struct ether_header *) buf;
  7469. ethertype = ntohs(eth->ether_type);
  7470. l2 = l2_packet_init(wpa_s->ifname, wpa_s->own_addr, ethertype,
  7471. wpas_data_test_rx, wpa_s, 1);
  7472. if (l2 == NULL)
  7473. goto done;
  7474. res = l2_packet_send(l2, eth->ether_dhost, ethertype, buf, len);
  7475. wpa_dbg(wpa_s, MSG_DEBUG, "test data: TX frame res=%d", res);
  7476. done:
  7477. if (l2)
  7478. l2_packet_deinit(l2);
  7479. os_free(buf);
  7480. return res < 0 ? -1 : 0;
  7481. }
  7482. static int wpas_ctrl_test_alloc_fail(struct wpa_supplicant *wpa_s, char *cmd)
  7483. {
  7484. #ifdef WPA_TRACE_BFD
  7485. char *pos;
  7486. wpa_trace_fail_after = atoi(cmd);
  7487. pos = os_strchr(cmd, ':');
  7488. if (pos) {
  7489. pos++;
  7490. os_strlcpy(wpa_trace_fail_func, pos,
  7491. sizeof(wpa_trace_fail_func));
  7492. } else {
  7493. wpa_trace_fail_after = 0;
  7494. }
  7495. return 0;
  7496. #else /* WPA_TRACE_BFD */
  7497. return -1;
  7498. #endif /* WPA_TRACE_BFD */
  7499. }
  7500. static int wpas_ctrl_get_alloc_fail(struct wpa_supplicant *wpa_s,
  7501. char *buf, size_t buflen)
  7502. {
  7503. #ifdef WPA_TRACE_BFD
  7504. return os_snprintf(buf, buflen, "%u:%s", wpa_trace_fail_after,
  7505. wpa_trace_fail_func);
  7506. #else /* WPA_TRACE_BFD */
  7507. return -1;
  7508. #endif /* WPA_TRACE_BFD */
  7509. }
  7510. static int wpas_ctrl_test_fail(struct wpa_supplicant *wpa_s, char *cmd)
  7511. {
  7512. #ifdef WPA_TRACE_BFD
  7513. char *pos;
  7514. wpa_trace_test_fail_after = atoi(cmd);
  7515. pos = os_strchr(cmd, ':');
  7516. if (pos) {
  7517. pos++;
  7518. os_strlcpy(wpa_trace_test_fail_func, pos,
  7519. sizeof(wpa_trace_test_fail_func));
  7520. } else {
  7521. wpa_trace_test_fail_after = 0;
  7522. }
  7523. return 0;
  7524. #else /* WPA_TRACE_BFD */
  7525. return -1;
  7526. #endif /* WPA_TRACE_BFD */
  7527. }
  7528. static int wpas_ctrl_get_fail(struct wpa_supplicant *wpa_s,
  7529. char *buf, size_t buflen)
  7530. {
  7531. #ifdef WPA_TRACE_BFD
  7532. return os_snprintf(buf, buflen, "%u:%s", wpa_trace_test_fail_after,
  7533. wpa_trace_test_fail_func);
  7534. #else /* WPA_TRACE_BFD */
  7535. return -1;
  7536. #endif /* WPA_TRACE_BFD */
  7537. }
  7538. static void wpas_ctrl_event_test_cb(void *eloop_ctx, void *timeout_ctx)
  7539. {
  7540. struct wpa_supplicant *wpa_s = eloop_ctx;
  7541. int i, count = (intptr_t) timeout_ctx;
  7542. wpa_printf(MSG_DEBUG, "TEST: Send %d control interface event messages",
  7543. count);
  7544. for (i = 0; i < count; i++) {
  7545. wpa_msg_ctrl(wpa_s, MSG_INFO, "TEST-EVENT-MESSAGE %d/%d",
  7546. i + 1, count);
  7547. }
  7548. }
  7549. static int wpas_ctrl_event_test(struct wpa_supplicant *wpa_s, const char *cmd)
  7550. {
  7551. int count;
  7552. count = atoi(cmd);
  7553. if (count <= 0)
  7554. return -1;
  7555. return eloop_register_timeout(0, 0, wpas_ctrl_event_test_cb, wpa_s,
  7556. (void *) (intptr_t) count);
  7557. }
  7558. static int wpas_ctrl_test_assoc_ie(struct wpa_supplicant *wpa_s,
  7559. const char *cmd)
  7560. {
  7561. struct wpabuf *buf;
  7562. size_t len;
  7563. len = os_strlen(cmd);
  7564. if (len & 1)
  7565. return -1;
  7566. len /= 2;
  7567. if (len == 0) {
  7568. buf = NULL;
  7569. } else {
  7570. buf = wpabuf_alloc(len);
  7571. if (buf == NULL)
  7572. return -1;
  7573. if (hexstr2bin(cmd, wpabuf_put(buf, len), len) < 0) {
  7574. wpabuf_free(buf);
  7575. return -1;
  7576. }
  7577. }
  7578. wpa_sm_set_test_assoc_ie(wpa_s->wpa, buf);
  7579. return 0;
  7580. }
  7581. static int wpas_ctrl_reset_pn(struct wpa_supplicant *wpa_s)
  7582. {
  7583. u8 zero[WPA_TK_MAX_LEN];
  7584. if (wpa_s->last_tk_alg == WPA_ALG_NONE)
  7585. return -1;
  7586. wpa_printf(MSG_INFO, "TESTING: Reset PN");
  7587. os_memset(zero, 0, sizeof(zero));
  7588. /* First, use a zero key to avoid any possible duplicate key avoidance
  7589. * in the driver. */
  7590. if (wpa_drv_set_key(wpa_s, wpa_s->last_tk_alg, wpa_s->last_tk_addr,
  7591. wpa_s->last_tk_key_idx, 1, zero, 6,
  7592. zero, wpa_s->last_tk_len) < 0)
  7593. return -1;
  7594. /* Set the previously configured key to reset its TSC/RSC */
  7595. return wpa_drv_set_key(wpa_s, wpa_s->last_tk_alg, wpa_s->last_tk_addr,
  7596. wpa_s->last_tk_key_idx, 1, zero, 6,
  7597. wpa_s->last_tk, wpa_s->last_tk_len);
  7598. }
  7599. static int wpas_ctrl_key_request(struct wpa_supplicant *wpa_s, const char *cmd)
  7600. {
  7601. const char *pos = cmd;
  7602. int error, pairwise;
  7603. error = atoi(pos);
  7604. pos = os_strchr(pos, ' ');
  7605. if (!pos)
  7606. return -1;
  7607. pairwise = atoi(pos);
  7608. wpa_sm_key_request(wpa_s->wpa, error, pairwise);
  7609. return 0;
  7610. }
  7611. static int wpas_ctrl_resend_assoc(struct wpa_supplicant *wpa_s)
  7612. {
  7613. #ifdef CONFIG_SME
  7614. struct wpa_driver_associate_params params;
  7615. int ret;
  7616. os_memset(&params, 0, sizeof(params));
  7617. params.bssid = wpa_s->bssid;
  7618. params.ssid = wpa_s->sme.ssid;
  7619. params.ssid_len = wpa_s->sme.ssid_len;
  7620. params.freq.freq = wpa_s->sme.freq;
  7621. if (wpa_s->last_assoc_req_wpa_ie) {
  7622. params.wpa_ie = wpabuf_head(wpa_s->last_assoc_req_wpa_ie);
  7623. params.wpa_ie_len = wpabuf_len(wpa_s->last_assoc_req_wpa_ie);
  7624. }
  7625. params.pairwise_suite = wpa_s->pairwise_cipher;
  7626. params.group_suite = wpa_s->group_cipher;
  7627. params.mgmt_group_suite = wpa_s->mgmt_group_cipher;
  7628. params.key_mgmt_suite = wpa_s->key_mgmt;
  7629. params.wpa_proto = wpa_s->wpa_proto;
  7630. params.mgmt_frame_protection = wpa_s->sme.mfp;
  7631. params.rrm_used = wpa_s->rrm.rrm_used;
  7632. if (wpa_s->sme.prev_bssid_set)
  7633. params.prev_bssid = wpa_s->sme.prev_bssid;
  7634. wpa_printf(MSG_INFO, "TESTING: Resend association request");
  7635. ret = wpa_drv_associate(wpa_s, &params);
  7636. wpa_s->testing_resend_assoc = 1;
  7637. return ret;
  7638. #else /* CONFIG_SME */
  7639. return -1;
  7640. #endif /* CONFIG_SME */
  7641. }
  7642. #endif /* CONFIG_TESTING_OPTIONS */
  7643. static int wpas_ctrl_vendor_elem_add(struct wpa_supplicant *wpa_s, char *cmd)
  7644. {
  7645. char *pos = cmd;
  7646. int frame;
  7647. size_t len;
  7648. struct wpabuf *buf;
  7649. struct ieee802_11_elems elems;
  7650. frame = atoi(pos);
  7651. if (frame < 0 || frame >= NUM_VENDOR_ELEM_FRAMES)
  7652. return -1;
  7653. wpa_s = wpas_vendor_elem(wpa_s, frame);
  7654. pos = os_strchr(pos, ' ');
  7655. if (pos == NULL)
  7656. return -1;
  7657. pos++;
  7658. len = os_strlen(pos);
  7659. if (len == 0)
  7660. return 0;
  7661. if (len & 1)
  7662. return -1;
  7663. len /= 2;
  7664. buf = wpabuf_alloc(len);
  7665. if (buf == NULL)
  7666. return -1;
  7667. if (hexstr2bin(pos, wpabuf_put(buf, len), len) < 0) {
  7668. wpabuf_free(buf);
  7669. return -1;
  7670. }
  7671. if (ieee802_11_parse_elems(wpabuf_head_u8(buf), len, &elems, 0) ==
  7672. ParseFailed) {
  7673. wpabuf_free(buf);
  7674. return -1;
  7675. }
  7676. if (wpa_s->vendor_elem[frame] == NULL) {
  7677. wpa_s->vendor_elem[frame] = buf;
  7678. wpas_vendor_elem_update(wpa_s);
  7679. return 0;
  7680. }
  7681. if (wpabuf_resize(&wpa_s->vendor_elem[frame], len) < 0) {
  7682. wpabuf_free(buf);
  7683. return -1;
  7684. }
  7685. wpabuf_put_buf(wpa_s->vendor_elem[frame], buf);
  7686. wpabuf_free(buf);
  7687. wpas_vendor_elem_update(wpa_s);
  7688. return 0;
  7689. }
  7690. static int wpas_ctrl_vendor_elem_get(struct wpa_supplicant *wpa_s, char *cmd,
  7691. char *buf, size_t buflen)
  7692. {
  7693. int frame = atoi(cmd);
  7694. if (frame < 0 || frame >= NUM_VENDOR_ELEM_FRAMES)
  7695. return -1;
  7696. wpa_s = wpas_vendor_elem(wpa_s, frame);
  7697. if (wpa_s->vendor_elem[frame] == NULL)
  7698. return 0;
  7699. return wpa_snprintf_hex(buf, buflen,
  7700. wpabuf_head_u8(wpa_s->vendor_elem[frame]),
  7701. wpabuf_len(wpa_s->vendor_elem[frame]));
  7702. }
  7703. static int wpas_ctrl_vendor_elem_remove(struct wpa_supplicant *wpa_s, char *cmd)
  7704. {
  7705. char *pos = cmd;
  7706. int frame;
  7707. size_t len;
  7708. u8 *buf;
  7709. struct ieee802_11_elems elems;
  7710. int res;
  7711. frame = atoi(pos);
  7712. if (frame < 0 || frame >= NUM_VENDOR_ELEM_FRAMES)
  7713. return -1;
  7714. wpa_s = wpas_vendor_elem(wpa_s, frame);
  7715. pos = os_strchr(pos, ' ');
  7716. if (pos == NULL)
  7717. return -1;
  7718. pos++;
  7719. if (*pos == '*') {
  7720. wpabuf_free(wpa_s->vendor_elem[frame]);
  7721. wpa_s->vendor_elem[frame] = NULL;
  7722. wpas_vendor_elem_update(wpa_s);
  7723. return 0;
  7724. }
  7725. if (wpa_s->vendor_elem[frame] == NULL)
  7726. return -1;
  7727. len = os_strlen(pos);
  7728. if (len == 0)
  7729. return 0;
  7730. if (len & 1)
  7731. return -1;
  7732. len /= 2;
  7733. buf = os_malloc(len);
  7734. if (buf == NULL)
  7735. return -1;
  7736. if (hexstr2bin(pos, buf, len) < 0) {
  7737. os_free(buf);
  7738. return -1;
  7739. }
  7740. if (ieee802_11_parse_elems(buf, len, &elems, 0) == ParseFailed) {
  7741. os_free(buf);
  7742. return -1;
  7743. }
  7744. res = wpas_vendor_elem_remove(wpa_s, frame, buf, len);
  7745. os_free(buf);
  7746. return res;
  7747. }
  7748. static void wpas_ctrl_neighbor_rep_cb(void *ctx, struct wpabuf *neighbor_rep)
  7749. {
  7750. struct wpa_supplicant *wpa_s = ctx;
  7751. size_t len;
  7752. const u8 *data;
  7753. /*
  7754. * Neighbor Report element (IEEE P802.11-REVmc/D5.0)
  7755. * BSSID[6]
  7756. * BSSID Information[4]
  7757. * Operating Class[1]
  7758. * Channel Number[1]
  7759. * PHY Type[1]
  7760. * Optional Subelements[variable]
  7761. */
  7762. #define NR_IE_MIN_LEN (ETH_ALEN + 4 + 1 + 1 + 1)
  7763. if (!neighbor_rep || wpabuf_len(neighbor_rep) == 0) {
  7764. wpa_msg_ctrl(wpa_s, MSG_INFO, RRM_EVENT_NEIGHBOR_REP_FAILED);
  7765. goto out;
  7766. }
  7767. data = wpabuf_head_u8(neighbor_rep);
  7768. len = wpabuf_len(neighbor_rep);
  7769. while (len >= 2 + NR_IE_MIN_LEN) {
  7770. const u8 *nr;
  7771. char lci[256 * 2 + 1];
  7772. char civic[256 * 2 + 1];
  7773. u8 nr_len = data[1];
  7774. const u8 *pos = data, *end;
  7775. if (pos[0] != WLAN_EID_NEIGHBOR_REPORT ||
  7776. nr_len < NR_IE_MIN_LEN) {
  7777. wpa_printf(MSG_DEBUG,
  7778. "CTRL: Invalid Neighbor Report element: id=%u len=%u",
  7779. data[0], nr_len);
  7780. goto out;
  7781. }
  7782. if (2U + nr_len > len) {
  7783. wpa_printf(MSG_DEBUG,
  7784. "CTRL: Invalid Neighbor Report element: id=%u len=%zu nr_len=%u",
  7785. data[0], len, nr_len);
  7786. goto out;
  7787. }
  7788. pos += 2;
  7789. end = pos + nr_len;
  7790. nr = pos;
  7791. pos += NR_IE_MIN_LEN;
  7792. lci[0] = '\0';
  7793. civic[0] = '\0';
  7794. while (end - pos > 2) {
  7795. u8 s_id, s_len;
  7796. s_id = *pos++;
  7797. s_len = *pos++;
  7798. if (s_len > end - pos)
  7799. goto out;
  7800. if (s_id == WLAN_EID_MEASURE_REPORT && s_len > 3) {
  7801. /* Measurement Token[1] */
  7802. /* Measurement Report Mode[1] */
  7803. /* Measurement Type[1] */
  7804. /* Measurement Report[variable] */
  7805. switch (pos[2]) {
  7806. case MEASURE_TYPE_LCI:
  7807. if (lci[0])
  7808. break;
  7809. wpa_snprintf_hex(lci, sizeof(lci),
  7810. pos, s_len);
  7811. break;
  7812. case MEASURE_TYPE_LOCATION_CIVIC:
  7813. if (civic[0])
  7814. break;
  7815. wpa_snprintf_hex(civic, sizeof(civic),
  7816. pos, s_len);
  7817. break;
  7818. }
  7819. }
  7820. pos += s_len;
  7821. }
  7822. wpa_msg(wpa_s, MSG_INFO, RRM_EVENT_NEIGHBOR_REP_RXED
  7823. "bssid=" MACSTR
  7824. " info=0x%x op_class=%u chan=%u phy_type=%u%s%s%s%s",
  7825. MAC2STR(nr), WPA_GET_LE32(nr + ETH_ALEN),
  7826. nr[ETH_ALEN + 4], nr[ETH_ALEN + 5],
  7827. nr[ETH_ALEN + 6],
  7828. lci[0] ? " lci=" : "", lci,
  7829. civic[0] ? " civic=" : "", civic);
  7830. data = end;
  7831. len -= 2 + nr_len;
  7832. }
  7833. out:
  7834. wpabuf_free(neighbor_rep);
  7835. }
  7836. static int wpas_ctrl_iface_send_neighbor_rep(struct wpa_supplicant *wpa_s,
  7837. char *cmd)
  7838. {
  7839. struct wpa_ssid_value ssid, *ssid_p = NULL;
  7840. int ret, lci = 0, civic = 0;
  7841. char *ssid_s;
  7842. ssid_s = os_strstr(cmd, "ssid=");
  7843. if (ssid_s) {
  7844. if (ssid_parse(ssid_s + 5, &ssid)) {
  7845. wpa_printf(MSG_ERROR,
  7846. "CTRL: Send Neighbor Report: bad SSID");
  7847. return -1;
  7848. }
  7849. ssid_p = &ssid;
  7850. /*
  7851. * Move cmd after the SSID text that may include "lci" or
  7852. * "civic".
  7853. */
  7854. cmd = os_strchr(ssid_s + 6, ssid_s[5] == '"' ? '"' : ' ');
  7855. if (cmd)
  7856. cmd++;
  7857. }
  7858. if (cmd && os_strstr(cmd, "lci"))
  7859. lci = 1;
  7860. if (cmd && os_strstr(cmd, "civic"))
  7861. civic = 1;
  7862. ret = wpas_rrm_send_neighbor_rep_request(wpa_s, ssid_p, lci, civic,
  7863. wpas_ctrl_neighbor_rep_cb,
  7864. wpa_s);
  7865. return ret;
  7866. }
  7867. static int wpas_ctrl_iface_erp_flush(struct wpa_supplicant *wpa_s)
  7868. {
  7869. eapol_sm_erp_flush(wpa_s->eapol);
  7870. return 0;
  7871. }
  7872. static int wpas_ctrl_iface_mac_rand_scan(struct wpa_supplicant *wpa_s,
  7873. char *cmd)
  7874. {
  7875. char *token, *context = NULL;
  7876. unsigned int enable = ~0, type = 0;
  7877. u8 _addr[ETH_ALEN], _mask[ETH_ALEN];
  7878. u8 *addr = NULL, *mask = NULL;
  7879. while ((token = str_token(cmd, " ", &context))) {
  7880. if (os_strcasecmp(token, "scan") == 0) {
  7881. type |= MAC_ADDR_RAND_SCAN;
  7882. } else if (os_strcasecmp(token, "sched") == 0) {
  7883. type |= MAC_ADDR_RAND_SCHED_SCAN;
  7884. } else if (os_strcasecmp(token, "pno") == 0) {
  7885. type |= MAC_ADDR_RAND_PNO;
  7886. } else if (os_strcasecmp(token, "all") == 0) {
  7887. type = wpa_s->mac_addr_rand_supported;
  7888. } else if (os_strncasecmp(token, "enable=", 7) == 0) {
  7889. enable = atoi(token + 7);
  7890. } else if (os_strncasecmp(token, "addr=", 5) == 0) {
  7891. addr = _addr;
  7892. if (hwaddr_aton(token + 5, addr)) {
  7893. wpa_printf(MSG_INFO,
  7894. "CTRL: Invalid MAC address: %s",
  7895. token);
  7896. return -1;
  7897. }
  7898. } else if (os_strncasecmp(token, "mask=", 5) == 0) {
  7899. mask = _mask;
  7900. if (hwaddr_aton(token + 5, mask)) {
  7901. wpa_printf(MSG_INFO,
  7902. "CTRL: Invalid MAC address mask: %s",
  7903. token);
  7904. return -1;
  7905. }
  7906. } else {
  7907. wpa_printf(MSG_INFO,
  7908. "CTRL: Invalid MAC_RAND_SCAN parameter: %s",
  7909. token);
  7910. return -1;
  7911. }
  7912. }
  7913. if (!type) {
  7914. wpa_printf(MSG_INFO, "CTRL: MAC_RAND_SCAN no type specified");
  7915. return -1;
  7916. }
  7917. if ((wpa_s->mac_addr_rand_supported & type) != type) {
  7918. wpa_printf(MSG_INFO,
  7919. "CTRL: MAC_RAND_SCAN types=%u != supported=%u",
  7920. type, wpa_s->mac_addr_rand_supported);
  7921. return -1;
  7922. }
  7923. if (enable > 1) {
  7924. wpa_printf(MSG_INFO,
  7925. "CTRL: MAC_RAND_SCAN enable=<0/1> not specified");
  7926. return -1;
  7927. }
  7928. if (!enable) {
  7929. wpas_mac_addr_rand_scan_clear(wpa_s, type);
  7930. if (wpa_s->pno) {
  7931. if (type & MAC_ADDR_RAND_PNO) {
  7932. wpas_stop_pno(wpa_s);
  7933. wpas_start_pno(wpa_s);
  7934. }
  7935. } else if (wpa_s->sched_scanning &&
  7936. (type & MAC_ADDR_RAND_SCHED_SCAN)) {
  7937. wpas_scan_restart_sched_scan(wpa_s);
  7938. }
  7939. return 0;
  7940. }
  7941. if ((addr && !mask) || (!addr && mask)) {
  7942. wpa_printf(MSG_INFO,
  7943. "CTRL: MAC_RAND_SCAN invalid addr/mask combination");
  7944. return -1;
  7945. }
  7946. if (addr && mask && (!(mask[0] & 0x01) || (addr[0] & 0x01))) {
  7947. wpa_printf(MSG_INFO,
  7948. "CTRL: MAC_RAND_SCAN cannot allow multicast address");
  7949. return -1;
  7950. }
  7951. if (type & MAC_ADDR_RAND_SCAN) {
  7952. wpas_mac_addr_rand_scan_set(wpa_s, MAC_ADDR_RAND_SCAN,
  7953. addr, mask);
  7954. }
  7955. if (type & MAC_ADDR_RAND_SCHED_SCAN) {
  7956. wpas_mac_addr_rand_scan_set(wpa_s, MAC_ADDR_RAND_SCHED_SCAN,
  7957. addr, mask);
  7958. if (wpa_s->sched_scanning && !wpa_s->pno)
  7959. wpas_scan_restart_sched_scan(wpa_s);
  7960. }
  7961. if (type & MAC_ADDR_RAND_PNO) {
  7962. wpas_mac_addr_rand_scan_set(wpa_s, MAC_ADDR_RAND_PNO,
  7963. addr, mask);
  7964. if (wpa_s->pno) {
  7965. wpas_stop_pno(wpa_s);
  7966. wpas_start_pno(wpa_s);
  7967. }
  7968. }
  7969. return 0;
  7970. }
  7971. static int wpas_ctrl_iface_pmksa(struct wpa_supplicant *wpa_s,
  7972. char *buf, size_t buflen)
  7973. {
  7974. size_t reply_len;
  7975. reply_len = wpa_sm_pmksa_cache_list(wpa_s->wpa, buf, buflen);
  7976. #ifdef CONFIG_AP
  7977. reply_len += wpas_ap_pmksa_cache_list(wpa_s, &buf[reply_len],
  7978. buflen - reply_len);
  7979. #endif /* CONFIG_AP */
  7980. return reply_len;
  7981. }
  7982. static void wpas_ctrl_iface_pmksa_flush(struct wpa_supplicant *wpa_s)
  7983. {
  7984. wpa_sm_pmksa_cache_flush(wpa_s->wpa, NULL);
  7985. #ifdef CONFIG_AP
  7986. wpas_ap_pmksa_cache_flush(wpa_s);
  7987. #endif /* CONFIG_AP */
  7988. }
  7989. #ifdef CONFIG_PMKSA_CACHE_EXTERNAL
  7990. static int wpas_ctrl_iface_pmksa_get(struct wpa_supplicant *wpa_s,
  7991. const char *cmd, char *buf, size_t buflen)
  7992. {
  7993. struct rsn_pmksa_cache_entry *entry;
  7994. struct wpa_ssid *ssid;
  7995. char *pos, *pos2, *end;
  7996. int ret;
  7997. struct os_reltime now;
  7998. ssid = wpa_config_get_network(wpa_s->conf, atoi(cmd));
  7999. if (!ssid)
  8000. return -1;
  8001. pos = buf;
  8002. end = buf + buflen;
  8003. os_get_reltime(&now);
  8004. /*
  8005. * Entry format:
  8006. * <BSSID> <PMKID> <PMK> <reauth_time in seconds>
  8007. * <expiration in seconds> <akmp> <opportunistic>
  8008. * [FILS Cache Identifier]
  8009. */
  8010. for (entry = wpa_sm_pmksa_cache_head(wpa_s->wpa); entry;
  8011. entry = entry->next) {
  8012. if (entry->network_ctx != ssid)
  8013. continue;
  8014. pos2 = pos;
  8015. ret = os_snprintf(pos2, end - pos2, MACSTR " ",
  8016. MAC2STR(entry->aa));
  8017. if (os_snprintf_error(end - pos2, ret))
  8018. break;
  8019. pos2 += ret;
  8020. pos2 += wpa_snprintf_hex(pos2, end - pos2, entry->pmkid,
  8021. PMKID_LEN);
  8022. ret = os_snprintf(pos2, end - pos2, " ");
  8023. if (os_snprintf_error(end - pos2, ret))
  8024. break;
  8025. pos2 += ret;
  8026. pos2 += wpa_snprintf_hex(pos2, end - pos2, entry->pmk,
  8027. entry->pmk_len);
  8028. ret = os_snprintf(pos2, end - pos2, " %d %d %d %d",
  8029. (int) (entry->reauth_time - now.sec),
  8030. (int) (entry->expiration - now.sec),
  8031. entry->akmp,
  8032. entry->opportunistic);
  8033. if (os_snprintf_error(end - pos2, ret))
  8034. break;
  8035. pos2 += ret;
  8036. if (entry->fils_cache_id_set) {
  8037. ret = os_snprintf(pos2, end - pos2, " %02x%02x",
  8038. entry->fils_cache_id[0],
  8039. entry->fils_cache_id[1]);
  8040. if (os_snprintf_error(end - pos2, ret))
  8041. break;
  8042. pos2 += ret;
  8043. }
  8044. ret = os_snprintf(pos2, end - pos2, "\n");
  8045. if (os_snprintf_error(end - pos2, ret))
  8046. break;
  8047. pos2 += ret;
  8048. pos = pos2;
  8049. }
  8050. return pos - buf;
  8051. }
  8052. static int wpas_ctrl_iface_pmksa_add(struct wpa_supplicant *wpa_s,
  8053. char *cmd)
  8054. {
  8055. struct rsn_pmksa_cache_entry *entry;
  8056. struct wpa_ssid *ssid;
  8057. char *pos, *pos2;
  8058. int ret = -1;
  8059. struct os_reltime now;
  8060. int reauth_time = 0, expiration = 0, i;
  8061. /*
  8062. * Entry format:
  8063. * <network_id> <BSSID> <PMKID> <PMK> <reauth_time in seconds>
  8064. * <expiration in seconds> <akmp> <opportunistic>
  8065. * [FILS Cache Identifier]
  8066. */
  8067. ssid = wpa_config_get_network(wpa_s->conf, atoi(cmd));
  8068. if (!ssid)
  8069. return -1;
  8070. pos = os_strchr(cmd, ' ');
  8071. if (!pos)
  8072. return -1;
  8073. pos++;
  8074. entry = os_zalloc(sizeof(*entry));
  8075. if (!entry)
  8076. return -1;
  8077. if (hwaddr_aton(pos, entry->aa))
  8078. goto fail;
  8079. pos = os_strchr(pos, ' ');
  8080. if (!pos)
  8081. goto fail;
  8082. pos++;
  8083. if (hexstr2bin(pos, entry->pmkid, PMKID_LEN) < 0)
  8084. goto fail;
  8085. pos = os_strchr(pos, ' ');
  8086. if (!pos)
  8087. goto fail;
  8088. pos++;
  8089. pos2 = os_strchr(pos, ' ');
  8090. if (!pos2)
  8091. goto fail;
  8092. entry->pmk_len = (pos2 - pos) / 2;
  8093. if (entry->pmk_len < PMK_LEN || entry->pmk_len > PMK_LEN_MAX ||
  8094. hexstr2bin(pos, entry->pmk, entry->pmk_len) < 0)
  8095. goto fail;
  8096. pos = os_strchr(pos, ' ');
  8097. if (!pos)
  8098. goto fail;
  8099. pos++;
  8100. if (sscanf(pos, "%d %d %d %d", &reauth_time, &expiration,
  8101. &entry->akmp, &entry->opportunistic) != 4)
  8102. goto fail;
  8103. for (i = 0; i < 4; i++) {
  8104. pos = os_strchr(pos, ' ');
  8105. if (!pos) {
  8106. if (i < 3)
  8107. goto fail;
  8108. break;
  8109. }
  8110. pos++;
  8111. }
  8112. if (pos) {
  8113. if (hexstr2bin(pos, entry->fils_cache_id,
  8114. FILS_CACHE_ID_LEN) < 0)
  8115. goto fail;
  8116. entry->fils_cache_id_set = 1;
  8117. }
  8118. os_get_reltime(&now);
  8119. entry->expiration = now.sec + expiration;
  8120. entry->reauth_time = now.sec + reauth_time;
  8121. entry->network_ctx = ssid;
  8122. wpa_sm_pmksa_cache_add_entry(wpa_s->wpa, entry);
  8123. entry = NULL;
  8124. ret = 0;
  8125. fail:
  8126. os_free(entry);
  8127. return ret;
  8128. }
  8129. #ifdef CONFIG_MESH
  8130. static int wpas_ctrl_iface_mesh_pmksa_get(struct wpa_supplicant *wpa_s,
  8131. const char *cmd, char *buf,
  8132. size_t buflen)
  8133. {
  8134. u8 spa[ETH_ALEN];
  8135. if (!wpa_s->ifmsh)
  8136. return -1;
  8137. if (os_strcasecmp(cmd, "any") == 0)
  8138. return wpas_ap_pmksa_cache_list_mesh(wpa_s, NULL, buf, buflen);
  8139. if (hwaddr_aton(cmd, spa))
  8140. return -1;
  8141. return wpas_ap_pmksa_cache_list_mesh(wpa_s, spa, buf, buflen);
  8142. }
  8143. static int wpas_ctrl_iface_mesh_pmksa_add(struct wpa_supplicant *wpa_s,
  8144. char *cmd)
  8145. {
  8146. /*
  8147. * We do not check mesh interface existance because PMKSA should be
  8148. * stored before wpa_s->ifmsh creation to suppress commit message
  8149. * creation.
  8150. */
  8151. return wpas_ap_pmksa_cache_add_external(wpa_s, cmd);
  8152. }
  8153. #endif /* CONFIG_MESH */
  8154. #endif /* CONFIG_PMKSA_CACHE_EXTERNAL */
  8155. #ifdef CONFIG_FILS
  8156. static int wpas_ctrl_iface_fils_hlp_req_add(struct wpa_supplicant *wpa_s,
  8157. const char *cmd)
  8158. {
  8159. struct fils_hlp_req *req;
  8160. const char *pos;
  8161. /* format: <dst> <packet starting from ethertype> */
  8162. req = os_zalloc(sizeof(*req));
  8163. if (!req)
  8164. return -1;
  8165. if (hwaddr_aton(cmd, req->dst))
  8166. goto fail;
  8167. pos = os_strchr(cmd, ' ');
  8168. if (!pos)
  8169. goto fail;
  8170. pos++;
  8171. req->pkt = wpabuf_parse_bin(pos);
  8172. if (!req->pkt)
  8173. goto fail;
  8174. dl_list_add_tail(&wpa_s->fils_hlp_req, &req->list);
  8175. return 0;
  8176. fail:
  8177. wpabuf_free(req->pkt);
  8178. os_free(req);
  8179. return -1;
  8180. }
  8181. #endif /* CONFIG_FILS */
  8182. static int wpas_ctrl_cmd_debug_level(const char *cmd)
  8183. {
  8184. if (os_strcmp(cmd, "PING") == 0 ||
  8185. os_strncmp(cmd, "BSS ", 4) == 0 ||
  8186. os_strncmp(cmd, "GET_NETWORK ", 12) == 0 ||
  8187. os_strncmp(cmd, "STATUS", 6) == 0 ||
  8188. os_strncmp(cmd, "STA ", 4) == 0 ||
  8189. os_strncmp(cmd, "STA-", 4) == 0)
  8190. return MSG_EXCESSIVE;
  8191. return MSG_DEBUG;
  8192. }
  8193. char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s,
  8194. char *buf, size_t *resp_len)
  8195. {
  8196. char *reply;
  8197. const int reply_size = 4096;
  8198. int reply_len;
  8199. if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0 ||
  8200. os_strncmp(buf, "SET_NETWORK ", 12) == 0 ||
  8201. os_strncmp(buf, "PMKSA_ADD ", 10) == 0 ||
  8202. os_strncmp(buf, "MESH_PMKSA_ADD ", 15) == 0) {
  8203. if (wpa_debug_show_keys)
  8204. wpa_dbg(wpa_s, MSG_DEBUG,
  8205. "Control interface command '%s'", buf);
  8206. else
  8207. wpa_dbg(wpa_s, MSG_DEBUG,
  8208. "Control interface command '%s [REMOVED]'",
  8209. os_strncmp(buf, WPA_CTRL_RSP,
  8210. os_strlen(WPA_CTRL_RSP)) == 0 ?
  8211. WPA_CTRL_RSP :
  8212. (os_strncmp(buf, "SET_NETWORK ", 12) == 0 ?
  8213. "SET_NETWORK" : "key-add"));
  8214. } else if (os_strncmp(buf, "WPS_NFC_TAG_READ", 16) == 0 ||
  8215. os_strncmp(buf, "NFC_REPORT_HANDOVER", 19) == 0) {
  8216. wpa_hexdump_ascii_key(MSG_DEBUG, "RX ctrl_iface",
  8217. (const u8 *) buf, os_strlen(buf));
  8218. } else {
  8219. int level = wpas_ctrl_cmd_debug_level(buf);
  8220. wpa_dbg(wpa_s, level, "Control interface command '%s'", buf);
  8221. }
  8222. reply = os_malloc(reply_size);
  8223. if (reply == NULL) {
  8224. *resp_len = 1;
  8225. return NULL;
  8226. }
  8227. os_memcpy(reply, "OK\n", 3);
  8228. reply_len = 3;
  8229. if (os_strcmp(buf, "PING") == 0) {
  8230. os_memcpy(reply, "PONG\n", 5);
  8231. reply_len = 5;
  8232. } else if (os_strcmp(buf, "IFNAME") == 0) {
  8233. reply_len = os_strlen(wpa_s->ifname);
  8234. os_memcpy(reply, wpa_s->ifname, reply_len);
  8235. } else if (os_strncmp(buf, "RELOG", 5) == 0) {
  8236. if (wpa_debug_reopen_file() < 0)
  8237. reply_len = -1;
  8238. } else if (os_strncmp(buf, "NOTE ", 5) == 0) {
  8239. wpa_printf(MSG_INFO, "NOTE: %s", buf + 5);
  8240. } else if (os_strcmp(buf, "MIB") == 0) {
  8241. reply_len = wpa_sm_get_mib(wpa_s->wpa, reply, reply_size);
  8242. if (reply_len >= 0) {
  8243. reply_len += eapol_sm_get_mib(wpa_s->eapol,
  8244. reply + reply_len,
  8245. reply_size - reply_len);
  8246. }
  8247. } else if (os_strncmp(buf, "STATUS", 6) == 0) {
  8248. reply_len = wpa_supplicant_ctrl_iface_status(
  8249. wpa_s, buf + 6, reply, reply_size);
  8250. } else if (os_strcmp(buf, "PMKSA") == 0) {
  8251. reply_len = wpas_ctrl_iface_pmksa(wpa_s, reply, reply_size);
  8252. } else if (os_strcmp(buf, "PMKSA_FLUSH") == 0) {
  8253. wpas_ctrl_iface_pmksa_flush(wpa_s);
  8254. #ifdef CONFIG_PMKSA_CACHE_EXTERNAL
  8255. } else if (os_strncmp(buf, "PMKSA_GET ", 10) == 0) {
  8256. reply_len = wpas_ctrl_iface_pmksa_get(wpa_s, buf + 10,
  8257. reply, reply_size);
  8258. } else if (os_strncmp(buf, "PMKSA_ADD ", 10) == 0) {
  8259. if (wpas_ctrl_iface_pmksa_add(wpa_s, buf + 10) < 0)
  8260. reply_len = -1;
  8261. #ifdef CONFIG_MESH
  8262. } else if (os_strncmp(buf, "MESH_PMKSA_GET ", 15) == 0) {
  8263. reply_len = wpas_ctrl_iface_mesh_pmksa_get(wpa_s, buf + 15,
  8264. reply, reply_size);
  8265. } else if (os_strncmp(buf, "MESH_PMKSA_ADD ", 15) == 0) {
  8266. if (wpas_ctrl_iface_mesh_pmksa_add(wpa_s, buf + 15) < 0)
  8267. reply_len = -1;
  8268. #endif /* CONFIG_MESH */
  8269. #endif /* CONFIG_PMKSA_CACHE_EXTERNAL */
  8270. } else if (os_strncmp(buf, "SET ", 4) == 0) {
  8271. if (wpa_supplicant_ctrl_iface_set(wpa_s, buf + 4))
  8272. reply_len = -1;
  8273. } else if (os_strncmp(buf, "DUMP", 4) == 0) {
  8274. reply_len = wpa_config_dump_values(wpa_s->conf,
  8275. reply, reply_size);
  8276. } else if (os_strncmp(buf, "GET ", 4) == 0) {
  8277. reply_len = wpa_supplicant_ctrl_iface_get(wpa_s, buf + 4,
  8278. reply, reply_size);
  8279. } else if (os_strcmp(buf, "LOGON") == 0) {
  8280. eapol_sm_notify_logoff(wpa_s->eapol, FALSE);
  8281. } else if (os_strcmp(buf, "LOGOFF") == 0) {
  8282. eapol_sm_notify_logoff(wpa_s->eapol, TRUE);
  8283. } else if (os_strcmp(buf, "REASSOCIATE") == 0) {
  8284. if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
  8285. reply_len = -1;
  8286. else
  8287. wpas_request_connection(wpa_s);
  8288. } else if (os_strcmp(buf, "REATTACH") == 0) {
  8289. if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED ||
  8290. !wpa_s->current_ssid)
  8291. reply_len = -1;
  8292. else {
  8293. wpa_s->reattach = 1;
  8294. wpas_request_connection(wpa_s);
  8295. }
  8296. } else if (os_strcmp(buf, "RECONNECT") == 0) {
  8297. if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
  8298. reply_len = -1;
  8299. else if (wpa_s->disconnected)
  8300. wpas_request_connection(wpa_s);
  8301. #ifdef IEEE8021X_EAPOL
  8302. } else if (os_strncmp(buf, "PREAUTH ", 8) == 0) {
  8303. if (wpa_supplicant_ctrl_iface_preauth(wpa_s, buf + 8))
  8304. reply_len = -1;
  8305. #endif /* IEEE8021X_EAPOL */
  8306. #ifdef CONFIG_IEEE80211R
  8307. } else if (os_strncmp(buf, "FT_DS ", 6) == 0) {
  8308. if (wpa_supplicant_ctrl_iface_ft_ds(wpa_s, buf + 6))
  8309. reply_len = -1;
  8310. #endif /* CONFIG_IEEE80211R */
  8311. #ifdef CONFIG_WPS
  8312. } else if (os_strcmp(buf, "WPS_PBC") == 0) {
  8313. int res = wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, NULL);
  8314. if (res == -2) {
  8315. os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
  8316. reply_len = 17;
  8317. } else if (res)
  8318. reply_len = -1;
  8319. } else if (os_strncmp(buf, "WPS_PBC ", 8) == 0) {
  8320. int res = wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, buf + 8);
  8321. if (res == -2) {
  8322. os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
  8323. reply_len = 17;
  8324. } else if (res)
  8325. reply_len = -1;
  8326. } else if (os_strncmp(buf, "WPS_PIN ", 8) == 0) {
  8327. reply_len = wpa_supplicant_ctrl_iface_wps_pin(wpa_s, buf + 8,
  8328. reply,
  8329. reply_size);
  8330. } else if (os_strncmp(buf, "WPS_CHECK_PIN ", 14) == 0) {
  8331. reply_len = wpa_supplicant_ctrl_iface_wps_check_pin(
  8332. wpa_s, buf + 14, reply, reply_size);
  8333. } else if (os_strcmp(buf, "WPS_CANCEL") == 0) {
  8334. if (wpas_wps_cancel(wpa_s))
  8335. reply_len = -1;
  8336. #ifdef CONFIG_WPS_NFC
  8337. } else if (os_strcmp(buf, "WPS_NFC") == 0) {
  8338. if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s, NULL))
  8339. reply_len = -1;
  8340. } else if (os_strncmp(buf, "WPS_NFC ", 8) == 0) {
  8341. if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s, buf + 8))
  8342. reply_len = -1;
  8343. } else if (os_strncmp(buf, "WPS_NFC_CONFIG_TOKEN ", 21) == 0) {
  8344. reply_len = wpa_supplicant_ctrl_iface_wps_nfc_config_token(
  8345. wpa_s, buf + 21, reply, reply_size);
  8346. } else if (os_strncmp(buf, "WPS_NFC_TOKEN ", 14) == 0) {
  8347. reply_len = wpa_supplicant_ctrl_iface_wps_nfc_token(
  8348. wpa_s, buf + 14, reply, reply_size);
  8349. } else if (os_strncmp(buf, "WPS_NFC_TAG_READ ", 17) == 0) {
  8350. if (wpa_supplicant_ctrl_iface_wps_nfc_tag_read(wpa_s,
  8351. buf + 17))
  8352. reply_len = -1;
  8353. } else if (os_strncmp(buf, "NFC_GET_HANDOVER_REQ ", 21) == 0) {
  8354. reply_len = wpas_ctrl_nfc_get_handover_req(
  8355. wpa_s, buf + 21, reply, reply_size);
  8356. } else if (os_strncmp(buf, "NFC_GET_HANDOVER_SEL ", 21) == 0) {
  8357. reply_len = wpas_ctrl_nfc_get_handover_sel(
  8358. wpa_s, buf + 21, reply, reply_size);
  8359. } else if (os_strncmp(buf, "NFC_REPORT_HANDOVER ", 20) == 0) {
  8360. if (wpas_ctrl_nfc_report_handover(wpa_s, buf + 20))
  8361. reply_len = -1;
  8362. #endif /* CONFIG_WPS_NFC */
  8363. } else if (os_strncmp(buf, "WPS_REG ", 8) == 0) {
  8364. if (wpa_supplicant_ctrl_iface_wps_reg(wpa_s, buf + 8))
  8365. reply_len = -1;
  8366. #ifdef CONFIG_AP
  8367. } else if (os_strncmp(buf, "WPS_AP_PIN ", 11) == 0) {
  8368. reply_len = wpa_supplicant_ctrl_iface_wps_ap_pin(
  8369. wpa_s, buf + 11, reply, reply_size);
  8370. #endif /* CONFIG_AP */
  8371. #ifdef CONFIG_WPS_ER
  8372. } else if (os_strcmp(buf, "WPS_ER_START") == 0) {
  8373. if (wpas_wps_er_start(wpa_s, NULL))
  8374. reply_len = -1;
  8375. } else if (os_strncmp(buf, "WPS_ER_START ", 13) == 0) {
  8376. if (wpas_wps_er_start(wpa_s, buf + 13))
  8377. reply_len = -1;
  8378. } else if (os_strcmp(buf, "WPS_ER_STOP") == 0) {
  8379. wpas_wps_er_stop(wpa_s);
  8380. } else if (os_strncmp(buf, "WPS_ER_PIN ", 11) == 0) {
  8381. if (wpa_supplicant_ctrl_iface_wps_er_pin(wpa_s, buf + 11))
  8382. reply_len = -1;
  8383. } else if (os_strncmp(buf, "WPS_ER_PBC ", 11) == 0) {
  8384. int ret = wpas_wps_er_pbc(wpa_s, buf + 11);
  8385. if (ret == -2) {
  8386. os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
  8387. reply_len = 17;
  8388. } else if (ret == -3) {
  8389. os_memcpy(reply, "FAIL-UNKNOWN-UUID\n", 18);
  8390. reply_len = 18;
  8391. } else if (ret == -4) {
  8392. os_memcpy(reply, "FAIL-NO-AP-SETTINGS\n", 20);
  8393. reply_len = 20;
  8394. } else if (ret)
  8395. reply_len = -1;
  8396. } else if (os_strncmp(buf, "WPS_ER_LEARN ", 13) == 0) {
  8397. if (wpa_supplicant_ctrl_iface_wps_er_learn(wpa_s, buf + 13))
  8398. reply_len = -1;
  8399. } else if (os_strncmp(buf, "WPS_ER_SET_CONFIG ", 18) == 0) {
  8400. if (wpa_supplicant_ctrl_iface_wps_er_set_config(wpa_s,
  8401. buf + 18))
  8402. reply_len = -1;
  8403. } else if (os_strncmp(buf, "WPS_ER_CONFIG ", 14) == 0) {
  8404. if (wpa_supplicant_ctrl_iface_wps_er_config(wpa_s, buf + 14))
  8405. reply_len = -1;
  8406. #ifdef CONFIG_WPS_NFC
  8407. } else if (os_strncmp(buf, "WPS_ER_NFC_CONFIG_TOKEN ", 24) == 0) {
  8408. reply_len = wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
  8409. wpa_s, buf + 24, reply, reply_size);
  8410. #endif /* CONFIG_WPS_NFC */
  8411. #endif /* CONFIG_WPS_ER */
  8412. #endif /* CONFIG_WPS */
  8413. #ifdef CONFIG_IBSS_RSN
  8414. } else if (os_strncmp(buf, "IBSS_RSN ", 9) == 0) {
  8415. if (wpa_supplicant_ctrl_iface_ibss_rsn(wpa_s, buf + 9))
  8416. reply_len = -1;
  8417. #endif /* CONFIG_IBSS_RSN */
  8418. #ifdef CONFIG_MESH
  8419. } else if (os_strncmp(buf, "MESH_INTERFACE_ADD ", 19) == 0) {
  8420. reply_len = wpa_supplicant_ctrl_iface_mesh_interface_add(
  8421. wpa_s, buf + 19, reply, reply_size);
  8422. } else if (os_strcmp(buf, "MESH_INTERFACE_ADD") == 0) {
  8423. reply_len = wpa_supplicant_ctrl_iface_mesh_interface_add(
  8424. wpa_s, "", reply, reply_size);
  8425. } else if (os_strncmp(buf, "MESH_GROUP_ADD ", 15) == 0) {
  8426. if (wpa_supplicant_ctrl_iface_mesh_group_add(wpa_s, buf + 15))
  8427. reply_len = -1;
  8428. } else if (os_strncmp(buf, "MESH_GROUP_REMOVE ", 18) == 0) {
  8429. if (wpa_supplicant_ctrl_iface_mesh_group_remove(wpa_s,
  8430. buf + 18))
  8431. reply_len = -1;
  8432. } else if (os_strncmp(buf, "MESH_PEER_REMOVE ", 17) == 0) {
  8433. if (wpa_supplicant_ctrl_iface_mesh_peer_remove(wpa_s, buf + 17))
  8434. reply_len = -1;
  8435. } else if (os_strncmp(buf, "MESH_PEER_ADD ", 14) == 0) {
  8436. if (wpa_supplicant_ctrl_iface_mesh_peer_add(wpa_s, buf + 14))
  8437. reply_len = -1;
  8438. #endif /* CONFIG_MESH */
  8439. #ifdef CONFIG_P2P
  8440. } else if (os_strncmp(buf, "P2P_FIND ", 9) == 0) {
  8441. if (p2p_ctrl_find(wpa_s, buf + 8))
  8442. reply_len = -1;
  8443. } else if (os_strcmp(buf, "P2P_FIND") == 0) {
  8444. if (p2p_ctrl_find(wpa_s, ""))
  8445. reply_len = -1;
  8446. } else if (os_strcmp(buf, "P2P_STOP_FIND") == 0) {
  8447. wpas_p2p_stop_find(wpa_s);
  8448. } else if (os_strncmp(buf, "P2P_ASP_PROVISION ", 18) == 0) {
  8449. if (p2p_ctrl_asp_provision(wpa_s, buf + 18))
  8450. reply_len = -1;
  8451. } else if (os_strncmp(buf, "P2P_ASP_PROVISION_RESP ", 23) == 0) {
  8452. if (p2p_ctrl_asp_provision_resp(wpa_s, buf + 23))
  8453. reply_len = -1;
  8454. } else if (os_strncmp(buf, "P2P_CONNECT ", 12) == 0) {
  8455. reply_len = p2p_ctrl_connect(wpa_s, buf + 12, reply,
  8456. reply_size);
  8457. } else if (os_strncmp(buf, "P2P_LISTEN ", 11) == 0) {
  8458. if (p2p_ctrl_listen(wpa_s, buf + 11))
  8459. reply_len = -1;
  8460. } else if (os_strcmp(buf, "P2P_LISTEN") == 0) {
  8461. if (p2p_ctrl_listen(wpa_s, ""))
  8462. reply_len = -1;
  8463. } else if (os_strncmp(buf, "P2P_GROUP_REMOVE ", 17) == 0) {
  8464. if (wpas_p2p_group_remove(wpa_s, buf + 17))
  8465. reply_len = -1;
  8466. } else if (os_strcmp(buf, "P2P_GROUP_ADD") == 0) {
  8467. if (p2p_ctrl_group_add(wpa_s, ""))
  8468. reply_len = -1;
  8469. } else if (os_strncmp(buf, "P2P_GROUP_ADD ", 14) == 0) {
  8470. if (p2p_ctrl_group_add(wpa_s, buf + 14))
  8471. reply_len = -1;
  8472. } else if (os_strncmp(buf, "P2P_GROUP_MEMBER ", 17) == 0) {
  8473. reply_len = p2p_ctrl_group_member(wpa_s, buf + 17, reply,
  8474. reply_size);
  8475. } else if (os_strncmp(buf, "P2P_PROV_DISC ", 14) == 0) {
  8476. if (p2p_ctrl_prov_disc(wpa_s, buf + 14))
  8477. reply_len = -1;
  8478. } else if (os_strcmp(buf, "P2P_GET_PASSPHRASE") == 0) {
  8479. reply_len = p2p_get_passphrase(wpa_s, reply, reply_size);
  8480. } else if (os_strncmp(buf, "P2P_SERV_DISC_REQ ", 18) == 0) {
  8481. reply_len = p2p_ctrl_serv_disc_req(wpa_s, buf + 18, reply,
  8482. reply_size);
  8483. } else if (os_strncmp(buf, "P2P_SERV_DISC_CANCEL_REQ ", 25) == 0) {
  8484. if (p2p_ctrl_serv_disc_cancel_req(wpa_s, buf + 25) < 0)
  8485. reply_len = -1;
  8486. } else if (os_strncmp(buf, "P2P_SERV_DISC_RESP ", 19) == 0) {
  8487. if (p2p_ctrl_serv_disc_resp(wpa_s, buf + 19) < 0)
  8488. reply_len = -1;
  8489. } else if (os_strcmp(buf, "P2P_SERVICE_UPDATE") == 0) {
  8490. wpas_p2p_sd_service_update(wpa_s);
  8491. } else if (os_strncmp(buf, "P2P_SERV_DISC_EXTERNAL ", 23) == 0) {
  8492. if (p2p_ctrl_serv_disc_external(wpa_s, buf + 23) < 0)
  8493. reply_len = -1;
  8494. } else if (os_strcmp(buf, "P2P_SERVICE_FLUSH") == 0) {
  8495. wpas_p2p_service_flush(wpa_s);
  8496. } else if (os_strncmp(buf, "P2P_SERVICE_ADD ", 16) == 0) {
  8497. if (p2p_ctrl_service_add(wpa_s, buf + 16) < 0)
  8498. reply_len = -1;
  8499. } else if (os_strncmp(buf, "P2P_SERVICE_DEL ", 16) == 0) {
  8500. if (p2p_ctrl_service_del(wpa_s, buf + 16) < 0)
  8501. reply_len = -1;
  8502. } else if (os_strncmp(buf, "P2P_SERVICE_REP ", 16) == 0) {
  8503. if (p2p_ctrl_service_replace(wpa_s, buf + 16) < 0)
  8504. reply_len = -1;
  8505. } else if (os_strncmp(buf, "P2P_REJECT ", 11) == 0) {
  8506. if (p2p_ctrl_reject(wpa_s, buf + 11) < 0)
  8507. reply_len = -1;
  8508. } else if (os_strncmp(buf, "P2P_INVITE ", 11) == 0) {
  8509. if (p2p_ctrl_invite(wpa_s, buf + 11) < 0)
  8510. reply_len = -1;
  8511. } else if (os_strncmp(buf, "P2P_PEER ", 9) == 0) {
  8512. reply_len = p2p_ctrl_peer(wpa_s, buf + 9, reply,
  8513. reply_size);
  8514. } else if (os_strncmp(buf, "P2P_SET ", 8) == 0) {
  8515. if (p2p_ctrl_set(wpa_s, buf + 8) < 0)
  8516. reply_len = -1;
  8517. } else if (os_strcmp(buf, "P2P_FLUSH") == 0) {
  8518. p2p_ctrl_flush(wpa_s);
  8519. } else if (os_strncmp(buf, "P2P_UNAUTHORIZE ", 16) == 0) {
  8520. if (wpas_p2p_unauthorize(wpa_s, buf + 16) < 0)
  8521. reply_len = -1;
  8522. } else if (os_strcmp(buf, "P2P_CANCEL") == 0) {
  8523. if (wpas_p2p_cancel(wpa_s))
  8524. reply_len = -1;
  8525. } else if (os_strncmp(buf, "P2P_PRESENCE_REQ ", 17) == 0) {
  8526. if (p2p_ctrl_presence_req(wpa_s, buf + 17) < 0)
  8527. reply_len = -1;
  8528. } else if (os_strcmp(buf, "P2P_PRESENCE_REQ") == 0) {
  8529. if (p2p_ctrl_presence_req(wpa_s, "") < 0)
  8530. reply_len = -1;
  8531. } else if (os_strncmp(buf, "P2P_EXT_LISTEN ", 15) == 0) {
  8532. if (p2p_ctrl_ext_listen(wpa_s, buf + 15) < 0)
  8533. reply_len = -1;
  8534. } else if (os_strcmp(buf, "P2P_EXT_LISTEN") == 0) {
  8535. if (p2p_ctrl_ext_listen(wpa_s, "") < 0)
  8536. reply_len = -1;
  8537. } else if (os_strncmp(buf, "P2P_REMOVE_CLIENT ", 18) == 0) {
  8538. if (p2p_ctrl_remove_client(wpa_s, buf + 18) < 0)
  8539. reply_len = -1;
  8540. } else if (os_strncmp(buf, "P2P_LO_START ", 13) == 0) {
  8541. if (p2p_ctrl_iface_p2p_lo_start(wpa_s, buf + 13))
  8542. reply_len = -1;
  8543. } else if (os_strcmp(buf, "P2P_LO_STOP") == 0) {
  8544. if (wpas_p2p_lo_stop(wpa_s))
  8545. reply_len = -1;
  8546. #endif /* CONFIG_P2P */
  8547. #ifdef CONFIG_WIFI_DISPLAY
  8548. } else if (os_strncmp(buf, "WFD_SUBELEM_SET ", 16) == 0) {
  8549. if (wifi_display_subelem_set(wpa_s->global, buf + 16) < 0)
  8550. reply_len = -1;
  8551. } else if (os_strncmp(buf, "WFD_SUBELEM_GET ", 16) == 0) {
  8552. reply_len = wifi_display_subelem_get(wpa_s->global, buf + 16,
  8553. reply, reply_size);
  8554. #endif /* CONFIG_WIFI_DISPLAY */
  8555. #ifdef CONFIG_INTERWORKING
  8556. } else if (os_strcmp(buf, "FETCH_ANQP") == 0) {
  8557. if (interworking_fetch_anqp(wpa_s) < 0)
  8558. reply_len = -1;
  8559. } else if (os_strcmp(buf, "STOP_FETCH_ANQP") == 0) {
  8560. interworking_stop_fetch_anqp(wpa_s);
  8561. } else if (os_strcmp(buf, "INTERWORKING_SELECT") == 0) {
  8562. if (ctrl_interworking_select(wpa_s, NULL) < 0)
  8563. reply_len = -1;
  8564. } else if (os_strncmp(buf, "INTERWORKING_SELECT ", 20) == 0) {
  8565. if (ctrl_interworking_select(wpa_s, buf + 20) < 0)
  8566. reply_len = -1;
  8567. } else if (os_strncmp(buf, "INTERWORKING_CONNECT ", 21) == 0) {
  8568. if (ctrl_interworking_connect(wpa_s, buf + 21, 0) < 0)
  8569. reply_len = -1;
  8570. } else if (os_strncmp(buf, "INTERWORKING_ADD_NETWORK ", 25) == 0) {
  8571. int id;
  8572. id = ctrl_interworking_connect(wpa_s, buf + 25, 1);
  8573. if (id < 0)
  8574. reply_len = -1;
  8575. else {
  8576. reply_len = os_snprintf(reply, reply_size, "%d\n", id);
  8577. if (os_snprintf_error(reply_size, reply_len))
  8578. reply_len = -1;
  8579. }
  8580. } else if (os_strncmp(buf, "ANQP_GET ", 9) == 0) {
  8581. if (get_anqp(wpa_s, buf + 9) < 0)
  8582. reply_len = -1;
  8583. } else if (os_strncmp(buf, "GAS_REQUEST ", 12) == 0) {
  8584. if (gas_request(wpa_s, buf + 12) < 0)
  8585. reply_len = -1;
  8586. } else if (os_strncmp(buf, "GAS_RESPONSE_GET ", 17) == 0) {
  8587. reply_len = gas_response_get(wpa_s, buf + 17, reply,
  8588. reply_size);
  8589. #endif /* CONFIG_INTERWORKING */
  8590. #ifdef CONFIG_HS20
  8591. } else if (os_strncmp(buf, "HS20_ANQP_GET ", 14) == 0) {
  8592. if (get_hs20_anqp(wpa_s, buf + 14) < 0)
  8593. reply_len = -1;
  8594. } else if (os_strncmp(buf, "HS20_GET_NAI_HOME_REALM_LIST ", 29) == 0) {
  8595. if (hs20_get_nai_home_realm_list(wpa_s, buf + 29) < 0)
  8596. reply_len = -1;
  8597. } else if (os_strncmp(buf, "HS20_ICON_REQUEST ", 18) == 0) {
  8598. if (hs20_icon_request(wpa_s, buf + 18, 0) < 0)
  8599. reply_len = -1;
  8600. } else if (os_strncmp(buf, "REQ_HS20_ICON ", 14) == 0) {
  8601. if (hs20_icon_request(wpa_s, buf + 14, 1) < 0)
  8602. reply_len = -1;
  8603. } else if (os_strncmp(buf, "GET_HS20_ICON ", 14) == 0) {
  8604. reply_len = get_hs20_icon(wpa_s, buf + 14, reply, reply_size);
  8605. } else if (os_strncmp(buf, "DEL_HS20_ICON ", 14) == 0) {
  8606. if (del_hs20_icon(wpa_s, buf + 14) < 0)
  8607. reply_len = -1;
  8608. } else if (os_strcmp(buf, "FETCH_OSU") == 0) {
  8609. if (hs20_fetch_osu(wpa_s, 0) < 0)
  8610. reply_len = -1;
  8611. } else if (os_strcmp(buf, "FETCH_OSU no-scan") == 0) {
  8612. if (hs20_fetch_osu(wpa_s, 1) < 0)
  8613. reply_len = -1;
  8614. } else if (os_strcmp(buf, "CANCEL_FETCH_OSU") == 0) {
  8615. hs20_cancel_fetch_osu(wpa_s);
  8616. #endif /* CONFIG_HS20 */
  8617. } else if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0)
  8618. {
  8619. if (wpa_supplicant_ctrl_iface_ctrl_rsp(
  8620. wpa_s, buf + os_strlen(WPA_CTRL_RSP)))
  8621. reply_len = -1;
  8622. else {
  8623. /*
  8624. * Notify response from timeout to allow the control
  8625. * interface response to be sent first.
  8626. */
  8627. eloop_register_timeout(0, 0, wpas_ctrl_eapol_response,
  8628. wpa_s, NULL);
  8629. }
  8630. } else if (os_strcmp(buf, "RECONFIGURE") == 0) {
  8631. if (wpa_supplicant_reload_configuration(wpa_s))
  8632. reply_len = -1;
  8633. } else if (os_strcmp(buf, "TERMINATE") == 0) {
  8634. wpa_supplicant_terminate_proc(wpa_s->global);
  8635. } else if (os_strncmp(buf, "BSSID ", 6) == 0) {
  8636. if (wpa_supplicant_ctrl_iface_bssid(wpa_s, buf + 6))
  8637. reply_len = -1;
  8638. } else if (os_strncmp(buf, "BLACKLIST", 9) == 0) {
  8639. reply_len = wpa_supplicant_ctrl_iface_blacklist(
  8640. wpa_s, buf + 9, reply, reply_size);
  8641. } else if (os_strncmp(buf, "LOG_LEVEL", 9) == 0) {
  8642. reply_len = wpa_supplicant_ctrl_iface_log_level(
  8643. wpa_s, buf + 9, reply, reply_size);
  8644. } else if (os_strncmp(buf, "LIST_NETWORKS ", 14) == 0) {
  8645. reply_len = wpa_supplicant_ctrl_iface_list_networks(
  8646. wpa_s, buf + 14, reply, reply_size);
  8647. } else if (os_strcmp(buf, "LIST_NETWORKS") == 0) {
  8648. reply_len = wpa_supplicant_ctrl_iface_list_networks(
  8649. wpa_s, NULL, reply, reply_size);
  8650. } else if (os_strcmp(buf, "DISCONNECT") == 0) {
  8651. wpas_request_disconnection(wpa_s);
  8652. } else if (os_strcmp(buf, "SCAN") == 0) {
  8653. wpas_ctrl_scan(wpa_s, NULL, reply, reply_size, &reply_len);
  8654. } else if (os_strncmp(buf, "SCAN ", 5) == 0) {
  8655. wpas_ctrl_scan(wpa_s, buf + 5, reply, reply_size, &reply_len);
  8656. } else if (os_strcmp(buf, "SCAN_RESULTS") == 0) {
  8657. reply_len = wpa_supplicant_ctrl_iface_scan_results(
  8658. wpa_s, reply, reply_size);
  8659. } else if (os_strcmp(buf, "ABORT_SCAN") == 0) {
  8660. if (wpas_abort_ongoing_scan(wpa_s) < 0)
  8661. reply_len = -1;
  8662. } else if (os_strncmp(buf, "SELECT_NETWORK ", 15) == 0) {
  8663. if (wpa_supplicant_ctrl_iface_select_network(wpa_s, buf + 15))
  8664. reply_len = -1;
  8665. } else if (os_strncmp(buf, "ENABLE_NETWORK ", 15) == 0) {
  8666. if (wpa_supplicant_ctrl_iface_enable_network(wpa_s, buf + 15))
  8667. reply_len = -1;
  8668. } else if (os_strncmp(buf, "DISABLE_NETWORK ", 16) == 0) {
  8669. if (wpa_supplicant_ctrl_iface_disable_network(wpa_s, buf + 16))
  8670. reply_len = -1;
  8671. } else if (os_strcmp(buf, "ADD_NETWORK") == 0) {
  8672. reply_len = wpa_supplicant_ctrl_iface_add_network(
  8673. wpa_s, reply, reply_size);
  8674. } else if (os_strncmp(buf, "REMOVE_NETWORK ", 15) == 0) {
  8675. if (wpa_supplicant_ctrl_iface_remove_network(wpa_s, buf + 15))
  8676. reply_len = -1;
  8677. } else if (os_strncmp(buf, "SET_NETWORK ", 12) == 0) {
  8678. if (wpa_supplicant_ctrl_iface_set_network(wpa_s, buf + 12))
  8679. reply_len = -1;
  8680. } else if (os_strncmp(buf, "GET_NETWORK ", 12) == 0) {
  8681. reply_len = wpa_supplicant_ctrl_iface_get_network(
  8682. wpa_s, buf + 12, reply, reply_size);
  8683. } else if (os_strncmp(buf, "DUP_NETWORK ", 12) == 0) {
  8684. if (wpa_supplicant_ctrl_iface_dup_network(wpa_s, buf + 12,
  8685. wpa_s))
  8686. reply_len = -1;
  8687. } else if (os_strcmp(buf, "LIST_CREDS") == 0) {
  8688. reply_len = wpa_supplicant_ctrl_iface_list_creds(
  8689. wpa_s, reply, reply_size);
  8690. } else if (os_strcmp(buf, "ADD_CRED") == 0) {
  8691. reply_len = wpa_supplicant_ctrl_iface_add_cred(
  8692. wpa_s, reply, reply_size);
  8693. } else if (os_strncmp(buf, "REMOVE_CRED ", 12) == 0) {
  8694. if (wpa_supplicant_ctrl_iface_remove_cred(wpa_s, buf + 12))
  8695. reply_len = -1;
  8696. } else if (os_strncmp(buf, "SET_CRED ", 9) == 0) {
  8697. if (wpa_supplicant_ctrl_iface_set_cred(wpa_s, buf + 9))
  8698. reply_len = -1;
  8699. } else if (os_strncmp(buf, "GET_CRED ", 9) == 0) {
  8700. reply_len = wpa_supplicant_ctrl_iface_get_cred(wpa_s, buf + 9,
  8701. reply,
  8702. reply_size);
  8703. #ifndef CONFIG_NO_CONFIG_WRITE
  8704. } else if (os_strcmp(buf, "SAVE_CONFIG") == 0) {
  8705. if (wpa_supplicant_ctrl_iface_save_config(wpa_s))
  8706. reply_len = -1;
  8707. #endif /* CONFIG_NO_CONFIG_WRITE */
  8708. } else if (os_strncmp(buf, "GET_CAPABILITY ", 15) == 0) {
  8709. reply_len = wpa_supplicant_ctrl_iface_get_capability(
  8710. wpa_s, buf + 15, reply, reply_size);
  8711. } else if (os_strncmp(buf, "AP_SCAN ", 8) == 0) {
  8712. if (wpa_supplicant_ctrl_iface_ap_scan(wpa_s, buf + 8))
  8713. reply_len = -1;
  8714. } else if (os_strncmp(buf, "SCAN_INTERVAL ", 14) == 0) {
  8715. if (wpa_supplicant_ctrl_iface_scan_interval(wpa_s, buf + 14))
  8716. reply_len = -1;
  8717. } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) {
  8718. reply_len = wpa_supplicant_global_iface_list(
  8719. wpa_s->global, reply, reply_size);
  8720. } else if (os_strncmp(buf, "INTERFACES", 10) == 0) {
  8721. reply_len = wpa_supplicant_global_iface_interfaces(
  8722. wpa_s->global, buf + 10, reply, reply_size);
  8723. } else if (os_strncmp(buf, "BSS ", 4) == 0) {
  8724. reply_len = wpa_supplicant_ctrl_iface_bss(
  8725. wpa_s, buf + 4, reply, reply_size);
  8726. #ifdef CONFIG_AP
  8727. } else if (os_strcmp(buf, "STA-FIRST") == 0) {
  8728. reply_len = ap_ctrl_iface_sta_first(wpa_s, reply, reply_size);
  8729. } else if (os_strncmp(buf, "STA ", 4) == 0) {
  8730. reply_len = ap_ctrl_iface_sta(wpa_s, buf + 4, reply,
  8731. reply_size);
  8732. } else if (os_strncmp(buf, "STA-NEXT ", 9) == 0) {
  8733. reply_len = ap_ctrl_iface_sta_next(wpa_s, buf + 9, reply,
  8734. reply_size);
  8735. } else if (os_strncmp(buf, "DEAUTHENTICATE ", 15) == 0) {
  8736. if (ap_ctrl_iface_sta_deauthenticate(wpa_s, buf + 15))
  8737. reply_len = -1;
  8738. } else if (os_strncmp(buf, "DISASSOCIATE ", 13) == 0) {
  8739. if (ap_ctrl_iface_sta_disassociate(wpa_s, buf + 13))
  8740. reply_len = -1;
  8741. } else if (os_strncmp(buf, "CHAN_SWITCH ", 12) == 0) {
  8742. if (ap_ctrl_iface_chanswitch(wpa_s, buf + 12))
  8743. reply_len = -1;
  8744. } else if (os_strcmp(buf, "STOP_AP") == 0) {
  8745. if (wpas_ap_stop_ap(wpa_s))
  8746. reply_len = -1;
  8747. #endif /* CONFIG_AP */
  8748. } else if (os_strcmp(buf, "SUSPEND") == 0) {
  8749. wpas_notify_suspend(wpa_s->global);
  8750. } else if (os_strcmp(buf, "RESUME") == 0) {
  8751. wpas_notify_resume(wpa_s->global);
  8752. #ifdef CONFIG_TESTING_OPTIONS
  8753. } else if (os_strcmp(buf, "DROP_SA") == 0) {
  8754. wpa_supplicant_ctrl_iface_drop_sa(wpa_s);
  8755. #endif /* CONFIG_TESTING_OPTIONS */
  8756. } else if (os_strncmp(buf, "ROAM ", 5) == 0) {
  8757. if (wpa_supplicant_ctrl_iface_roam(wpa_s, buf + 5))
  8758. reply_len = -1;
  8759. } else if (os_strncmp(buf, "STA_AUTOCONNECT ", 16) == 0) {
  8760. wpa_s->auto_reconnect_disabled = atoi(buf + 16) == 0;
  8761. } else if (os_strncmp(buf, "BSS_EXPIRE_AGE ", 15) == 0) {
  8762. if (wpa_supplicant_ctrl_iface_bss_expire_age(wpa_s, buf + 15))
  8763. reply_len = -1;
  8764. } else if (os_strncmp(buf, "BSS_EXPIRE_COUNT ", 17) == 0) {
  8765. if (wpa_supplicant_ctrl_iface_bss_expire_count(wpa_s,
  8766. buf + 17))
  8767. reply_len = -1;
  8768. } else if (os_strncmp(buf, "BSS_FLUSH ", 10) == 0) {
  8769. wpa_supplicant_ctrl_iface_bss_flush(wpa_s, buf + 10);
  8770. #ifdef CONFIG_TDLS
  8771. } else if (os_strncmp(buf, "TDLS_DISCOVER ", 14) == 0) {
  8772. if (wpa_supplicant_ctrl_iface_tdls_discover(wpa_s, buf + 14))
  8773. reply_len = -1;
  8774. } else if (os_strncmp(buf, "TDLS_SETUP ", 11) == 0) {
  8775. if (wpa_supplicant_ctrl_iface_tdls_setup(wpa_s, buf + 11))
  8776. reply_len = -1;
  8777. } else if (os_strncmp(buf, "TDLS_TEARDOWN ", 14) == 0) {
  8778. if (wpa_supplicant_ctrl_iface_tdls_teardown(wpa_s, buf + 14))
  8779. reply_len = -1;
  8780. } else if (os_strncmp(buf, "TDLS_CHAN_SWITCH ", 17) == 0) {
  8781. if (wpa_supplicant_ctrl_iface_tdls_chan_switch(wpa_s,
  8782. buf + 17))
  8783. reply_len = -1;
  8784. } else if (os_strncmp(buf, "TDLS_CANCEL_CHAN_SWITCH ", 24) == 0) {
  8785. if (wpa_supplicant_ctrl_iface_tdls_cancel_chan_switch(wpa_s,
  8786. buf + 24))
  8787. reply_len = -1;
  8788. } else if (os_strncmp(buf, "TDLS_LINK_STATUS ", 17) == 0) {
  8789. reply_len = wpa_supplicant_ctrl_iface_tdls_link_status(
  8790. wpa_s, buf + 17, reply, reply_size);
  8791. #endif /* CONFIG_TDLS */
  8792. } else if (os_strcmp(buf, "WMM_AC_STATUS") == 0) {
  8793. reply_len = wpas_wmm_ac_status(wpa_s, reply, reply_size);
  8794. } else if (os_strncmp(buf, "WMM_AC_ADDTS ", 13) == 0) {
  8795. if (wmm_ac_ctrl_addts(wpa_s, buf + 13))
  8796. reply_len = -1;
  8797. } else if (os_strncmp(buf, "WMM_AC_DELTS ", 13) == 0) {
  8798. if (wmm_ac_ctrl_delts(wpa_s, buf + 13))
  8799. reply_len = -1;
  8800. } else if (os_strncmp(buf, "SIGNAL_POLL", 11) == 0) {
  8801. reply_len = wpa_supplicant_signal_poll(wpa_s, reply,
  8802. reply_size);
  8803. } else if (os_strncmp(buf, "SIGNAL_MONITOR", 14) == 0) {
  8804. if (wpas_ctrl_iface_signal_monitor(wpa_s, buf + 14))
  8805. reply_len = -1;
  8806. } else if (os_strncmp(buf, "PKTCNT_POLL", 11) == 0) {
  8807. reply_len = wpa_supplicant_pktcnt_poll(wpa_s, reply,
  8808. reply_size);
  8809. #ifdef CONFIG_AUTOSCAN
  8810. } else if (os_strncmp(buf, "AUTOSCAN ", 9) == 0) {
  8811. if (wpa_supplicant_ctrl_iface_autoscan(wpa_s, buf + 9))
  8812. reply_len = -1;
  8813. #endif /* CONFIG_AUTOSCAN */
  8814. } else if (os_strcmp(buf, "DRIVER_FLAGS") == 0) {
  8815. reply_len = wpas_ctrl_iface_driver_flags(wpa_s, reply,
  8816. reply_size);
  8817. #ifdef ANDROID
  8818. } else if (os_strncmp(buf, "DRIVER ", 7) == 0) {
  8819. reply_len = wpa_supplicant_driver_cmd(wpa_s, buf + 7, reply,
  8820. reply_size);
  8821. #endif /* ANDROID */
  8822. } else if (os_strncmp(buf, "VENDOR ", 7) == 0) {
  8823. reply_len = wpa_supplicant_vendor_cmd(wpa_s, buf + 7, reply,
  8824. reply_size);
  8825. } else if (os_strcmp(buf, "REAUTHENTICATE") == 0) {
  8826. pmksa_cache_clear_current(wpa_s->wpa);
  8827. eapol_sm_request_reauth(wpa_s->eapol);
  8828. #ifdef CONFIG_WNM
  8829. } else if (os_strncmp(buf, "WNM_SLEEP ", 10) == 0) {
  8830. if (wpas_ctrl_iface_wnm_sleep(wpa_s, buf + 10))
  8831. reply_len = -1;
  8832. } else if (os_strncmp(buf, "WNM_BSS_QUERY ", 14) == 0) {
  8833. if (wpas_ctrl_iface_wnm_bss_query(wpa_s, buf + 14))
  8834. reply_len = -1;
  8835. #endif /* CONFIG_WNM */
  8836. } else if (os_strcmp(buf, "FLUSH") == 0) {
  8837. wpa_supplicant_ctrl_iface_flush(wpa_s);
  8838. } else if (os_strncmp(buf, "RADIO_WORK ", 11) == 0) {
  8839. reply_len = wpas_ctrl_radio_work(wpa_s, buf + 11, reply,
  8840. reply_size);
  8841. #ifdef CONFIG_TESTING_OPTIONS
  8842. } else if (os_strncmp(buf, "MGMT_TX ", 8) == 0) {
  8843. if (wpas_ctrl_iface_mgmt_tx(wpa_s, buf + 8) < 0)
  8844. reply_len = -1;
  8845. } else if (os_strcmp(buf, "MGMT_TX_DONE") == 0) {
  8846. wpas_ctrl_iface_mgmt_tx_done(wpa_s);
  8847. } else if (os_strncmp(buf, "MGMT_RX_PROCESS ", 16) == 0) {
  8848. if (wpas_ctrl_iface_mgmt_rx_process(wpa_s, buf + 16) < 0)
  8849. reply_len = -1;
  8850. } else if (os_strncmp(buf, "DRIVER_EVENT ", 13) == 0) {
  8851. if (wpas_ctrl_iface_driver_event(wpa_s, buf + 13) < 0)
  8852. reply_len = -1;
  8853. } else if (os_strncmp(buf, "EAPOL_RX ", 9) == 0) {
  8854. if (wpas_ctrl_iface_eapol_rx(wpa_s, buf + 9) < 0)
  8855. reply_len = -1;
  8856. } else if (os_strncmp(buf, "DATA_TEST_CONFIG ", 17) == 0) {
  8857. if (wpas_ctrl_iface_data_test_config(wpa_s, buf + 17) < 0)
  8858. reply_len = -1;
  8859. } else if (os_strncmp(buf, "DATA_TEST_TX ", 13) == 0) {
  8860. if (wpas_ctrl_iface_data_test_tx(wpa_s, buf + 13) < 0)
  8861. reply_len = -1;
  8862. } else if (os_strncmp(buf, "DATA_TEST_FRAME ", 16) == 0) {
  8863. if (wpas_ctrl_iface_data_test_frame(wpa_s, buf + 16) < 0)
  8864. reply_len = -1;
  8865. } else if (os_strncmp(buf, "TEST_ALLOC_FAIL ", 16) == 0) {
  8866. if (wpas_ctrl_test_alloc_fail(wpa_s, buf + 16) < 0)
  8867. reply_len = -1;
  8868. } else if (os_strcmp(buf, "GET_ALLOC_FAIL") == 0) {
  8869. reply_len = wpas_ctrl_get_alloc_fail(wpa_s, reply, reply_size);
  8870. } else if (os_strncmp(buf, "TEST_FAIL ", 10) == 0) {
  8871. if (wpas_ctrl_test_fail(wpa_s, buf + 10) < 0)
  8872. reply_len = -1;
  8873. } else if (os_strcmp(buf, "GET_FAIL") == 0) {
  8874. reply_len = wpas_ctrl_get_fail(wpa_s, reply, reply_size);
  8875. } else if (os_strncmp(buf, "EVENT_TEST ", 11) == 0) {
  8876. if (wpas_ctrl_event_test(wpa_s, buf + 11) < 0)
  8877. reply_len = -1;
  8878. } else if (os_strncmp(buf, "TEST_ASSOC_IE ", 14) == 0) {
  8879. if (wpas_ctrl_test_assoc_ie(wpa_s, buf + 14) < 0)
  8880. reply_len = -1;
  8881. } else if (os_strcmp(buf, "RESET_PN") == 0) {
  8882. if (wpas_ctrl_reset_pn(wpa_s) < 0)
  8883. reply_len = -1;
  8884. } else if (os_strncmp(buf, "KEY_REQUEST ", 12) == 0) {
  8885. if (wpas_ctrl_key_request(wpa_s, buf + 12) < 0)
  8886. reply_len = -1;
  8887. } else if (os_strcmp(buf, "RESEND_ASSOC") == 0) {
  8888. if (wpas_ctrl_resend_assoc(wpa_s) < 0)
  8889. reply_len = -1;
  8890. #endif /* CONFIG_TESTING_OPTIONS */
  8891. } else if (os_strncmp(buf, "VENDOR_ELEM_ADD ", 16) == 0) {
  8892. if (wpas_ctrl_vendor_elem_add(wpa_s, buf + 16) < 0)
  8893. reply_len = -1;
  8894. } else if (os_strncmp(buf, "VENDOR_ELEM_GET ", 16) == 0) {
  8895. reply_len = wpas_ctrl_vendor_elem_get(wpa_s, buf + 16, reply,
  8896. reply_size);
  8897. } else if (os_strncmp(buf, "VENDOR_ELEM_REMOVE ", 19) == 0) {
  8898. if (wpas_ctrl_vendor_elem_remove(wpa_s, buf + 19) < 0)
  8899. reply_len = -1;
  8900. } else if (os_strncmp(buf, "NEIGHBOR_REP_REQUEST", 20) == 0) {
  8901. if (wpas_ctrl_iface_send_neighbor_rep(wpa_s, buf + 20))
  8902. reply_len = -1;
  8903. } else if (os_strcmp(buf, "ERP_FLUSH") == 0) {
  8904. wpas_ctrl_iface_erp_flush(wpa_s);
  8905. } else if (os_strncmp(buf, "MAC_RAND_SCAN ", 14) == 0) {
  8906. if (wpas_ctrl_iface_mac_rand_scan(wpa_s, buf + 14))
  8907. reply_len = -1;
  8908. } else if (os_strncmp(buf, "GET_PREF_FREQ_LIST ", 19) == 0) {
  8909. reply_len = wpas_ctrl_iface_get_pref_freq_list(
  8910. wpa_s, buf + 19, reply, reply_size);
  8911. #ifdef CONFIG_FILS
  8912. } else if (os_strncmp(buf, "FILS_HLP_REQ_ADD ", 17) == 0) {
  8913. if (wpas_ctrl_iface_fils_hlp_req_add(wpa_s, buf + 17))
  8914. reply_len = -1;
  8915. } else if (os_strcmp(buf, "FILS_HLP_REQ_FLUSH") == 0) {
  8916. wpas_flush_fils_hlp_req(wpa_s);
  8917. #endif /* CONFIG_FILS */
  8918. #ifdef CONFIG_DPP
  8919. } else if (os_strncmp(buf, "DPP_QR_CODE ", 12) == 0) {
  8920. int res;
  8921. res = wpas_dpp_qr_code(wpa_s, buf + 12);
  8922. if (res < 0) {
  8923. reply_len = -1;
  8924. } else {
  8925. reply_len = os_snprintf(reply, reply_size, "%d", res);
  8926. if (os_snprintf_error(reply_size, reply_len))
  8927. reply_len = -1;
  8928. }
  8929. } else if (os_strncmp(buf, "DPP_BOOTSTRAP_GEN ", 18) == 0) {
  8930. int res;
  8931. res = wpas_dpp_bootstrap_gen(wpa_s, buf + 18);
  8932. if (res < 0) {
  8933. reply_len = -1;
  8934. } else {
  8935. reply_len = os_snprintf(reply, reply_size, "%d", res);
  8936. if (os_snprintf_error(reply_size, reply_len))
  8937. reply_len = -1;
  8938. }
  8939. } else if (os_strncmp(buf, "DPP_BOOTSTRAP_REMOVE ", 21) == 0) {
  8940. if (wpas_dpp_bootstrap_remove(wpa_s, buf + 21) < 0)
  8941. reply_len = -1;
  8942. } else if (os_strncmp(buf, "DPP_BOOTSTRAP_GET_URI ", 22) == 0) {
  8943. const char *uri;
  8944. uri = wpas_dpp_bootstrap_get_uri(wpa_s, atoi(buf + 22));
  8945. if (!uri) {
  8946. reply_len = -1;
  8947. } else {
  8948. reply_len = os_snprintf(reply, reply_size, "%s", uri);
  8949. if (os_snprintf_error(reply_size, reply_len))
  8950. reply_len = -1;
  8951. }
  8952. } else if (os_strncmp(buf, "DPP_BOOTSTRAP_INFO ", 19) == 0) {
  8953. reply_len = wpas_dpp_bootstrap_info(wpa_s, atoi(buf + 19),
  8954. reply, reply_size);
  8955. } else if (os_strncmp(buf, "DPP_AUTH_INIT ", 14) == 0) {
  8956. if (wpas_dpp_auth_init(wpa_s, buf + 13) < 0)
  8957. reply_len = -1;
  8958. } else if (os_strncmp(buf, "DPP_LISTEN ", 11) == 0) {
  8959. if (wpas_dpp_listen(wpa_s, buf + 11) < 0)
  8960. reply_len = -1;
  8961. } else if (os_strcmp(buf, "DPP_STOP_LISTEN") == 0) {
  8962. wpas_dpp_stop(wpa_s);
  8963. wpas_dpp_listen_stop(wpa_s);
  8964. } else if (os_strncmp(buf, "DPP_CONFIGURATOR_ADD", 20) == 0) {
  8965. int res;
  8966. res = wpas_dpp_configurator_add(wpa_s, buf + 20);
  8967. if (res < 0) {
  8968. reply_len = -1;
  8969. } else {
  8970. reply_len = os_snprintf(reply, reply_size, "%d", res);
  8971. if (os_snprintf_error(reply_size, reply_len))
  8972. reply_len = -1;
  8973. }
  8974. } else if (os_strncmp(buf, "DPP_CONFIGURATOR_REMOVE ", 24) == 0) {
  8975. if (wpas_dpp_configurator_remove(wpa_s, buf + 24) < 0)
  8976. reply_len = -1;
  8977. } else if (os_strncmp(buf, "DPP_CONFIGURATOR_SIGN ", 22) == 0) {
  8978. if (wpas_dpp_configurator_sign(wpa_s, buf + 22) < 0)
  8979. reply_len = -1;
  8980. } else if (os_strncmp(buf, "DPP_PKEX_ADD ", 13) == 0) {
  8981. int res;
  8982. res = wpas_dpp_pkex_add(wpa_s, buf + 12);
  8983. if (res < 0) {
  8984. reply_len = -1;
  8985. } else {
  8986. reply_len = os_snprintf(reply, reply_size, "%d", res);
  8987. if (os_snprintf_error(reply_size, reply_len))
  8988. reply_len = -1;
  8989. }
  8990. } else if (os_strncmp(buf, "DPP_PKEX_REMOVE ", 16) == 0) {
  8991. if (wpas_dpp_pkex_remove(wpa_s, buf + 16) < 0)
  8992. reply_len = -1;
  8993. #endif /* CONFIG_DPP */
  8994. } else {
  8995. os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
  8996. reply_len = 16;
  8997. }
  8998. if (reply_len < 0) {
  8999. os_memcpy(reply, "FAIL\n", 5);
  9000. reply_len = 5;
  9001. }
  9002. *resp_len = reply_len;
  9003. return reply;
  9004. }
  9005. static int wpa_supplicant_global_iface_add(struct wpa_global *global,
  9006. char *cmd)
  9007. {
  9008. struct wpa_interface iface;
  9009. char *pos, *extra;
  9010. struct wpa_supplicant *wpa_s;
  9011. unsigned int create_iface = 0;
  9012. u8 mac_addr[ETH_ALEN];
  9013. enum wpa_driver_if_type type = WPA_IF_STATION;
  9014. /*
  9015. * <ifname>TAB<confname>TAB<driver>TAB<ctrl_interface>TAB<driver_param>
  9016. * TAB<bridge_ifname>[TAB<create>[TAB<interface_type>]]
  9017. */
  9018. wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_ADD '%s'", cmd);
  9019. os_memset(&iface, 0, sizeof(iface));
  9020. do {
  9021. iface.ifname = pos = cmd;
  9022. pos = os_strchr(pos, '\t');
  9023. if (pos)
  9024. *pos++ = '\0';
  9025. if (iface.ifname[0] == '\0')
  9026. return -1;
  9027. if (pos == NULL)
  9028. break;
  9029. iface.confname = pos;
  9030. pos = os_strchr(pos, '\t');
  9031. if (pos)
  9032. *pos++ = '\0';
  9033. if (iface.confname[0] == '\0')
  9034. iface.confname = NULL;
  9035. if (pos == NULL)
  9036. break;
  9037. iface.driver = pos;
  9038. pos = os_strchr(pos, '\t');
  9039. if (pos)
  9040. *pos++ = '\0';
  9041. if (iface.driver[0] == '\0')
  9042. iface.driver = NULL;
  9043. if (pos == NULL)
  9044. break;
  9045. iface.ctrl_interface = pos;
  9046. pos = os_strchr(pos, '\t');
  9047. if (pos)
  9048. *pos++ = '\0';
  9049. if (iface.ctrl_interface[0] == '\0')
  9050. iface.ctrl_interface = NULL;
  9051. if (pos == NULL)
  9052. break;
  9053. iface.driver_param = pos;
  9054. pos = os_strchr(pos, '\t');
  9055. if (pos)
  9056. *pos++ = '\0';
  9057. if (iface.driver_param[0] == '\0')
  9058. iface.driver_param = NULL;
  9059. if (pos == NULL)
  9060. break;
  9061. iface.bridge_ifname = pos;
  9062. pos = os_strchr(pos, '\t');
  9063. if (pos)
  9064. *pos++ = '\0';
  9065. if (iface.bridge_ifname[0] == '\0')
  9066. iface.bridge_ifname = NULL;
  9067. if (pos == NULL)
  9068. break;
  9069. extra = pos;
  9070. pos = os_strchr(pos, '\t');
  9071. if (pos)
  9072. *pos++ = '\0';
  9073. if (!extra[0])
  9074. break;
  9075. if (os_strcmp(extra, "create") == 0) {
  9076. create_iface = 1;
  9077. if (!pos)
  9078. break;
  9079. if (os_strcmp(pos, "sta") == 0) {
  9080. type = WPA_IF_STATION;
  9081. } else if (os_strcmp(pos, "ap") == 0) {
  9082. type = WPA_IF_AP_BSS;
  9083. } else {
  9084. wpa_printf(MSG_DEBUG,
  9085. "INTERFACE_ADD unsupported interface type: '%s'",
  9086. pos);
  9087. return -1;
  9088. }
  9089. } else {
  9090. wpa_printf(MSG_DEBUG,
  9091. "INTERFACE_ADD unsupported extra parameter: '%s'",
  9092. extra);
  9093. return -1;
  9094. }
  9095. } while (0);
  9096. if (create_iface) {
  9097. wpa_printf(MSG_DEBUG, "CTRL_IFACE creating interface '%s'",
  9098. iface.ifname);
  9099. if (!global->ifaces)
  9100. return -1;
  9101. if (wpa_drv_if_add(global->ifaces, type, iface.ifname,
  9102. NULL, NULL, NULL, mac_addr, NULL) < 0) {
  9103. wpa_printf(MSG_ERROR,
  9104. "CTRL_IFACE interface creation failed");
  9105. return -1;
  9106. }
  9107. wpa_printf(MSG_DEBUG,
  9108. "CTRL_IFACE interface '%s' created with MAC addr: "
  9109. MACSTR, iface.ifname, MAC2STR(mac_addr));
  9110. }
  9111. if (wpa_supplicant_get_iface(global, iface.ifname))
  9112. goto fail;
  9113. wpa_s = wpa_supplicant_add_iface(global, &iface, NULL);
  9114. if (!wpa_s)
  9115. goto fail;
  9116. wpa_s->added_vif = create_iface;
  9117. return 0;
  9118. fail:
  9119. if (create_iface)
  9120. wpa_drv_if_remove(global->ifaces, WPA_IF_STATION, iface.ifname);
  9121. return -1;
  9122. }
  9123. static int wpa_supplicant_global_iface_remove(struct wpa_global *global,
  9124. char *cmd)
  9125. {
  9126. struct wpa_supplicant *wpa_s;
  9127. int ret;
  9128. unsigned int delete_iface;
  9129. wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_REMOVE '%s'", cmd);
  9130. wpa_s = wpa_supplicant_get_iface(global, cmd);
  9131. if (wpa_s == NULL)
  9132. return -1;
  9133. delete_iface = wpa_s->added_vif;
  9134. ret = wpa_supplicant_remove_iface(global, wpa_s, 0);
  9135. if (!ret && delete_iface) {
  9136. wpa_printf(MSG_DEBUG, "CTRL_IFACE deleting the interface '%s'",
  9137. cmd);
  9138. ret = wpa_drv_if_remove(global->ifaces, WPA_IF_STATION, cmd);
  9139. }
  9140. return ret;
  9141. }
  9142. static void wpa_free_iface_info(struct wpa_interface_info *iface)
  9143. {
  9144. struct wpa_interface_info *prev;
  9145. while (iface) {
  9146. prev = iface;
  9147. iface = iface->next;
  9148. os_free(prev->ifname);
  9149. os_free(prev->desc);
  9150. os_free(prev);
  9151. }
  9152. }
  9153. static int wpa_supplicant_global_iface_list(struct wpa_global *global,
  9154. char *buf, int len)
  9155. {
  9156. int i, res;
  9157. struct wpa_interface_info *iface = NULL, *last = NULL, *tmp;
  9158. char *pos, *end;
  9159. for (i = 0; wpa_drivers[i]; i++) {
  9160. const struct wpa_driver_ops *drv = wpa_drivers[i];
  9161. if (drv->get_interfaces == NULL)
  9162. continue;
  9163. tmp = drv->get_interfaces(global->drv_priv[i]);
  9164. if (tmp == NULL)
  9165. continue;
  9166. if (last == NULL)
  9167. iface = last = tmp;
  9168. else
  9169. last->next = tmp;
  9170. while (last->next)
  9171. last = last->next;
  9172. }
  9173. pos = buf;
  9174. end = buf + len;
  9175. for (tmp = iface; tmp; tmp = tmp->next) {
  9176. res = os_snprintf(pos, end - pos, "%s\t%s\t%s\n",
  9177. tmp->drv_name, tmp->ifname,
  9178. tmp->desc ? tmp->desc : "");
  9179. if (os_snprintf_error(end - pos, res)) {
  9180. *pos = '\0';
  9181. break;
  9182. }
  9183. pos += res;
  9184. }
  9185. wpa_free_iface_info(iface);
  9186. return pos - buf;
  9187. }
  9188. static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global,
  9189. const char *input,
  9190. char *buf, int len)
  9191. {
  9192. int res;
  9193. char *pos, *end;
  9194. struct wpa_supplicant *wpa_s;
  9195. int show_ctrl = 0;
  9196. if (input)
  9197. show_ctrl = !!os_strstr(input, "ctrl");
  9198. wpa_s = global->ifaces;
  9199. pos = buf;
  9200. end = buf + len;
  9201. while (wpa_s) {
  9202. if (show_ctrl)
  9203. res = os_snprintf(pos, end - pos, "%s ctrl_iface=%s\n",
  9204. wpa_s->ifname,
  9205. wpa_s->conf->ctrl_interface ?
  9206. wpa_s->conf->ctrl_interface : "N/A");
  9207. else
  9208. res = os_snprintf(pos, end - pos, "%s\n",
  9209. wpa_s->ifname);
  9210. if (os_snprintf_error(end - pos, res)) {
  9211. *pos = '\0';
  9212. break;
  9213. }
  9214. pos += res;
  9215. wpa_s = wpa_s->next;
  9216. }
  9217. return pos - buf;
  9218. }
  9219. static char * wpas_global_ctrl_iface_ifname(struct wpa_global *global,
  9220. const char *ifname,
  9221. char *cmd, size_t *resp_len)
  9222. {
  9223. struct wpa_supplicant *wpa_s;
  9224. for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
  9225. if (os_strcmp(ifname, wpa_s->ifname) == 0)
  9226. break;
  9227. }
  9228. if (wpa_s == NULL) {
  9229. char *resp = os_strdup("FAIL-NO-IFNAME-MATCH\n");
  9230. if (resp)
  9231. *resp_len = os_strlen(resp);
  9232. else
  9233. *resp_len = 1;
  9234. return resp;
  9235. }
  9236. return wpa_supplicant_ctrl_iface_process(wpa_s, cmd, resp_len);
  9237. }
  9238. static char * wpas_global_ctrl_iface_redir_p2p(struct wpa_global *global,
  9239. char *buf, size_t *resp_len)
  9240. {
  9241. #ifdef CONFIG_P2P
  9242. static const char * cmd[] = {
  9243. "LIST_NETWORKS",
  9244. "P2P_FIND",
  9245. "P2P_STOP_FIND",
  9246. "P2P_LISTEN",
  9247. "P2P_GROUP_ADD",
  9248. "P2P_GET_PASSPHRASE",
  9249. "P2P_SERVICE_UPDATE",
  9250. "P2P_SERVICE_FLUSH",
  9251. "P2P_FLUSH",
  9252. "P2P_CANCEL",
  9253. "P2P_PRESENCE_REQ",
  9254. "P2P_EXT_LISTEN",
  9255. #ifdef CONFIG_AP
  9256. "STA-FIRST",
  9257. #endif /* CONFIG_AP */
  9258. NULL
  9259. };
  9260. static const char * prefix[] = {
  9261. #ifdef ANDROID
  9262. "DRIVER ",
  9263. #endif /* ANDROID */
  9264. "GET_CAPABILITY ",
  9265. "GET_NETWORK ",
  9266. "REMOVE_NETWORK ",
  9267. "P2P_FIND ",
  9268. "P2P_CONNECT ",
  9269. "P2P_LISTEN ",
  9270. "P2P_GROUP_REMOVE ",
  9271. "P2P_GROUP_ADD ",
  9272. "P2P_GROUP_MEMBER ",
  9273. "P2P_PROV_DISC ",
  9274. "P2P_SERV_DISC_REQ ",
  9275. "P2P_SERV_DISC_CANCEL_REQ ",
  9276. "P2P_SERV_DISC_RESP ",
  9277. "P2P_SERV_DISC_EXTERNAL ",
  9278. "P2P_SERVICE_ADD ",
  9279. "P2P_SERVICE_DEL ",
  9280. "P2P_SERVICE_REP ",
  9281. "P2P_REJECT ",
  9282. "P2P_INVITE ",
  9283. "P2P_PEER ",
  9284. "P2P_SET ",
  9285. "P2P_UNAUTHORIZE ",
  9286. "P2P_PRESENCE_REQ ",
  9287. "P2P_EXT_LISTEN ",
  9288. "P2P_REMOVE_CLIENT ",
  9289. "WPS_NFC_TOKEN ",
  9290. "WPS_NFC_TAG_READ ",
  9291. "NFC_GET_HANDOVER_SEL ",
  9292. "NFC_GET_HANDOVER_REQ ",
  9293. "NFC_REPORT_HANDOVER ",
  9294. "P2P_ASP_PROVISION ",
  9295. "P2P_ASP_PROVISION_RESP ",
  9296. #ifdef CONFIG_AP
  9297. "STA ",
  9298. "STA-NEXT ",
  9299. #endif /* CONFIG_AP */
  9300. NULL
  9301. };
  9302. int found = 0;
  9303. int i;
  9304. if (global->p2p_init_wpa_s == NULL)
  9305. return NULL;
  9306. for (i = 0; !found && cmd[i]; i++) {
  9307. if (os_strcmp(buf, cmd[i]) == 0)
  9308. found = 1;
  9309. }
  9310. for (i = 0; !found && prefix[i]; i++) {
  9311. if (os_strncmp(buf, prefix[i], os_strlen(prefix[i])) == 0)
  9312. found = 1;
  9313. }
  9314. if (found)
  9315. return wpa_supplicant_ctrl_iface_process(global->p2p_init_wpa_s,
  9316. buf, resp_len);
  9317. #endif /* CONFIG_P2P */
  9318. return NULL;
  9319. }
  9320. static char * wpas_global_ctrl_iface_redir_wfd(struct wpa_global *global,
  9321. char *buf, size_t *resp_len)
  9322. {
  9323. #ifdef CONFIG_WIFI_DISPLAY
  9324. if (global->p2p_init_wpa_s == NULL)
  9325. return NULL;
  9326. if (os_strncmp(buf, "WFD_SUBELEM_SET ", 16) == 0 ||
  9327. os_strncmp(buf, "WFD_SUBELEM_GET ", 16) == 0)
  9328. return wpa_supplicant_ctrl_iface_process(global->p2p_init_wpa_s,
  9329. buf, resp_len);
  9330. #endif /* CONFIG_WIFI_DISPLAY */
  9331. return NULL;
  9332. }
  9333. static char * wpas_global_ctrl_iface_redir(struct wpa_global *global,
  9334. char *buf, size_t *resp_len)
  9335. {
  9336. char *ret;
  9337. ret = wpas_global_ctrl_iface_redir_p2p(global, buf, resp_len);
  9338. if (ret)
  9339. return ret;
  9340. ret = wpas_global_ctrl_iface_redir_wfd(global, buf, resp_len);
  9341. if (ret)
  9342. return ret;
  9343. return NULL;
  9344. }
  9345. static int wpas_global_ctrl_iface_set(struct wpa_global *global, char *cmd)
  9346. {
  9347. char *value;
  9348. value = os_strchr(cmd, ' ');
  9349. if (value == NULL)
  9350. return -1;
  9351. *value++ = '\0';
  9352. wpa_printf(MSG_DEBUG, "GLOBAL_CTRL_IFACE SET '%s'='%s'", cmd, value);
  9353. #ifdef CONFIG_WIFI_DISPLAY
  9354. if (os_strcasecmp(cmd, "wifi_display") == 0) {
  9355. wifi_display_enable(global, !!atoi(value));
  9356. return 0;
  9357. }
  9358. #endif /* CONFIG_WIFI_DISPLAY */
  9359. /* Restore cmd to its original value to allow redirection */
  9360. value[-1] = ' ';
  9361. return -1;
  9362. }
  9363. static int wpas_global_ctrl_iface_dup_network(struct wpa_global *global,
  9364. char *cmd)
  9365. {
  9366. struct wpa_supplicant *wpa_s[2]; /* src, dst */
  9367. char *p;
  9368. unsigned int i;
  9369. /* cmd: "<src ifname> <dst ifname> <src network id> <dst network id>
  9370. * <variable name> */
  9371. for (i = 0; i < ARRAY_SIZE(wpa_s) ; i++) {
  9372. p = os_strchr(cmd, ' ');
  9373. if (p == NULL)
  9374. return -1;
  9375. *p = '\0';
  9376. wpa_s[i] = global->ifaces;
  9377. for (; wpa_s[i]; wpa_s[i] = wpa_s[i]->next) {
  9378. if (os_strcmp(cmd, wpa_s[i]->ifname) == 0)
  9379. break;
  9380. }
  9381. if (!wpa_s[i]) {
  9382. wpa_printf(MSG_DEBUG,
  9383. "CTRL_IFACE: Could not find iface=%s", cmd);
  9384. return -1;
  9385. }
  9386. cmd = p + 1;
  9387. }
  9388. return wpa_supplicant_ctrl_iface_dup_network(wpa_s[0], cmd, wpa_s[1]);
  9389. }
  9390. #ifndef CONFIG_NO_CONFIG_WRITE
  9391. static int wpas_global_ctrl_iface_save_config(struct wpa_global *global)
  9392. {
  9393. int ret = 0, saved = 0;
  9394. struct wpa_supplicant *wpa_s;
  9395. for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
  9396. if (!wpa_s->conf->update_config) {
  9397. wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Not allowed to update configuration (update_config=0)");
  9398. continue;
  9399. }
  9400. if (wpa_config_write(wpa_s->confname, wpa_s->conf)) {
  9401. wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Failed to update configuration");
  9402. ret = 1;
  9403. } else {
  9404. wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Configuration updated");
  9405. saved++;
  9406. }
  9407. }
  9408. if (!saved && !ret) {
  9409. wpa_dbg(wpa_s, MSG_DEBUG,
  9410. "CTRL_IFACE: SAVE_CONFIG - No configuration files could be updated");
  9411. ret = 1;
  9412. }
  9413. return ret;
  9414. }
  9415. #endif /* CONFIG_NO_CONFIG_WRITE */
  9416. static int wpas_global_ctrl_iface_status(struct wpa_global *global,
  9417. char *buf, size_t buflen)
  9418. {
  9419. char *pos, *end;
  9420. int ret;
  9421. struct wpa_supplicant *wpa_s;
  9422. pos = buf;
  9423. end = buf + buflen;
  9424. #ifdef CONFIG_P2P
  9425. if (global->p2p && !global->p2p_disabled) {
  9426. ret = os_snprintf(pos, end - pos, "p2p_device_address=" MACSTR
  9427. "\n"
  9428. "p2p_state=%s\n",
  9429. MAC2STR(global->p2p_dev_addr),
  9430. p2p_get_state_txt(global->p2p));
  9431. if (os_snprintf_error(end - pos, ret))
  9432. return pos - buf;
  9433. pos += ret;
  9434. } else if (global->p2p) {
  9435. ret = os_snprintf(pos, end - pos, "p2p_state=DISABLED\n");
  9436. if (os_snprintf_error(end - pos, ret))
  9437. return pos - buf;
  9438. pos += ret;
  9439. }
  9440. #endif /* CONFIG_P2P */
  9441. #ifdef CONFIG_WIFI_DISPLAY
  9442. ret = os_snprintf(pos, end - pos, "wifi_display=%d\n",
  9443. !!global->wifi_display);
  9444. if (os_snprintf_error(end - pos, ret))
  9445. return pos - buf;
  9446. pos += ret;
  9447. #endif /* CONFIG_WIFI_DISPLAY */
  9448. for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
  9449. ret = os_snprintf(pos, end - pos, "ifname=%s\n"
  9450. "address=" MACSTR "\n",
  9451. wpa_s->ifname, MAC2STR(wpa_s->own_addr));
  9452. if (os_snprintf_error(end - pos, ret))
  9453. return pos - buf;
  9454. pos += ret;
  9455. }
  9456. return pos - buf;
  9457. }
  9458. #ifdef CONFIG_FST
  9459. static int wpas_global_ctrl_iface_fst_attach(struct wpa_global *global,
  9460. char *cmd, char *buf,
  9461. size_t reply_size)
  9462. {
  9463. char ifname[IFNAMSIZ + 1];
  9464. struct fst_iface_cfg cfg;
  9465. struct wpa_supplicant *wpa_s;
  9466. struct fst_wpa_obj iface_obj;
  9467. if (!fst_parse_attach_command(cmd, ifname, sizeof(ifname), &cfg)) {
  9468. wpa_s = wpa_supplicant_get_iface(global, ifname);
  9469. if (wpa_s) {
  9470. if (wpa_s->fst) {
  9471. wpa_printf(MSG_INFO, "FST: Already attached");
  9472. return -1;
  9473. }
  9474. fst_wpa_supplicant_fill_iface_obj(wpa_s, &iface_obj);
  9475. wpa_s->fst = fst_attach(ifname, wpa_s->own_addr,
  9476. &iface_obj, &cfg);
  9477. if (wpa_s->fst)
  9478. return os_snprintf(buf, reply_size, "OK\n");
  9479. }
  9480. }
  9481. return -1;
  9482. }
  9483. static int wpas_global_ctrl_iface_fst_detach(struct wpa_global *global,
  9484. char *cmd, char *buf,
  9485. size_t reply_size)
  9486. {
  9487. char ifname[IFNAMSIZ + 1];
  9488. struct wpa_supplicant *wpa_s;
  9489. if (!fst_parse_detach_command(cmd, ifname, sizeof(ifname))) {
  9490. wpa_s = wpa_supplicant_get_iface(global, ifname);
  9491. if (wpa_s) {
  9492. if (!fst_iface_detach(ifname)) {
  9493. wpa_s->fst = NULL;
  9494. return os_snprintf(buf, reply_size, "OK\n");
  9495. }
  9496. }
  9497. }
  9498. return -1;
  9499. }
  9500. #endif /* CONFIG_FST */
  9501. char * wpa_supplicant_global_ctrl_iface_process(struct wpa_global *global,
  9502. char *buf, size_t *resp_len)
  9503. {
  9504. char *reply;
  9505. const int reply_size = 2048;
  9506. int reply_len;
  9507. int level = MSG_DEBUG;
  9508. if (os_strncmp(buf, "IFNAME=", 7) == 0) {
  9509. char *pos = os_strchr(buf + 7, ' ');
  9510. if (pos) {
  9511. *pos++ = '\0';
  9512. return wpas_global_ctrl_iface_ifname(global,
  9513. buf + 7, pos,
  9514. resp_len);
  9515. }
  9516. }
  9517. reply = wpas_global_ctrl_iface_redir(global, buf, resp_len);
  9518. if (reply)
  9519. return reply;
  9520. if (os_strcmp(buf, "PING") == 0)
  9521. level = MSG_EXCESSIVE;
  9522. wpa_hexdump_ascii(level, "RX global ctrl_iface",
  9523. (const u8 *) buf, os_strlen(buf));
  9524. reply = os_malloc(reply_size);
  9525. if (reply == NULL) {
  9526. *resp_len = 1;
  9527. return NULL;
  9528. }
  9529. os_memcpy(reply, "OK\n", 3);
  9530. reply_len = 3;
  9531. if (os_strcmp(buf, "PING") == 0) {
  9532. os_memcpy(reply, "PONG\n", 5);
  9533. reply_len = 5;
  9534. } else if (os_strncmp(buf, "INTERFACE_ADD ", 14) == 0) {
  9535. if (wpa_supplicant_global_iface_add(global, buf + 14))
  9536. reply_len = -1;
  9537. } else if (os_strncmp(buf, "INTERFACE_REMOVE ", 17) == 0) {
  9538. if (wpa_supplicant_global_iface_remove(global, buf + 17))
  9539. reply_len = -1;
  9540. } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) {
  9541. reply_len = wpa_supplicant_global_iface_list(
  9542. global, reply, reply_size);
  9543. } else if (os_strncmp(buf, "INTERFACES", 10) == 0) {
  9544. reply_len = wpa_supplicant_global_iface_interfaces(
  9545. global, buf + 10, reply, reply_size);
  9546. #ifdef CONFIG_FST
  9547. } else if (os_strncmp(buf, "FST-ATTACH ", 11) == 0) {
  9548. reply_len = wpas_global_ctrl_iface_fst_attach(global, buf + 11,
  9549. reply,
  9550. reply_size);
  9551. } else if (os_strncmp(buf, "FST-DETACH ", 11) == 0) {
  9552. reply_len = wpas_global_ctrl_iface_fst_detach(global, buf + 11,
  9553. reply,
  9554. reply_size);
  9555. } else if (os_strncmp(buf, "FST-MANAGER ", 12) == 0) {
  9556. reply_len = fst_ctrl_iface_receive(buf + 12, reply, reply_size);
  9557. #endif /* CONFIG_FST */
  9558. } else if (os_strcmp(buf, "TERMINATE") == 0) {
  9559. wpa_supplicant_terminate_proc(global);
  9560. } else if (os_strcmp(buf, "SUSPEND") == 0) {
  9561. wpas_notify_suspend(global);
  9562. } else if (os_strcmp(buf, "RESUME") == 0) {
  9563. wpas_notify_resume(global);
  9564. } else if (os_strncmp(buf, "SET ", 4) == 0) {
  9565. if (wpas_global_ctrl_iface_set(global, buf + 4)) {
  9566. #ifdef CONFIG_P2P
  9567. if (global->p2p_init_wpa_s) {
  9568. os_free(reply);
  9569. /* Check if P2P redirection would work for this
  9570. * command. */
  9571. return wpa_supplicant_ctrl_iface_process(
  9572. global->p2p_init_wpa_s,
  9573. buf, resp_len);
  9574. }
  9575. #endif /* CONFIG_P2P */
  9576. reply_len = -1;
  9577. }
  9578. } else if (os_strncmp(buf, "DUP_NETWORK ", 12) == 0) {
  9579. if (wpas_global_ctrl_iface_dup_network(global, buf + 12))
  9580. reply_len = -1;
  9581. #ifndef CONFIG_NO_CONFIG_WRITE
  9582. } else if (os_strcmp(buf, "SAVE_CONFIG") == 0) {
  9583. if (wpas_global_ctrl_iface_save_config(global))
  9584. reply_len = -1;
  9585. #endif /* CONFIG_NO_CONFIG_WRITE */
  9586. } else if (os_strcmp(buf, "STATUS") == 0) {
  9587. reply_len = wpas_global_ctrl_iface_status(global, reply,
  9588. reply_size);
  9589. #ifdef CONFIG_MODULE_TESTS
  9590. } else if (os_strcmp(buf, "MODULE_TESTS") == 0) {
  9591. if (wpas_module_tests() < 0)
  9592. reply_len = -1;
  9593. #endif /* CONFIG_MODULE_TESTS */
  9594. } else if (os_strncmp(buf, "RELOG", 5) == 0) {
  9595. if (wpa_debug_reopen_file() < 0)
  9596. reply_len = -1;
  9597. } else {
  9598. os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
  9599. reply_len = 16;
  9600. }
  9601. if (reply_len < 0) {
  9602. os_memcpy(reply, "FAIL\n", 5);
  9603. reply_len = 5;
  9604. }
  9605. *resp_len = reply_len;
  9606. return reply;
  9607. }