ctrl_iface.c 202 KB

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