ctrl_iface.c 271 KB

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