ctrl_iface.c 270 KB

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