ctrl_iface.c 270 KB

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