ctrl_iface.c 216 KB

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