ctrl_iface.c 257 KB

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