ctrl_iface.c 256 KB

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