ctrl_iface.c 269 KB

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