ctrl_iface.c 257 KB

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