ctrl_iface.c 257 KB

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