ctrl_iface.c 270 KB

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