ctrl_iface.c 257 KB

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