ctrl_iface.c 256 KB

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