ctrl_iface.c 189 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760476147624763476447654766476747684769477047714772477347744775477647774778477947804781478247834784478547864787478847894790479147924793479447954796479747984799480048014802480348044805480648074808480948104811481248134814481548164817481848194820482148224823482448254826482748284829483048314832483348344835483648374838483948404841484248434844484548464847484848494850485148524853485448554856485748584859486048614862486348644865486648674868486948704871487248734874487548764877487848794880488148824883488448854886488748884889489048914892489348944895489648974898489949004901490249034904490549064907490849094910491149124913491449154916491749184919492049214922492349244925492649274928492949304931493249334934493549364937493849394940494149424943494449454946494749484949495049514952495349544955495649574958495949604961496249634964496549664967496849694970497149724973497449754976497749784979498049814982498349844985498649874988498949904991499249934994499549964997499849995000500150025003500450055006500750085009501050115012501350145015501650175018501950205021502250235024502550265027502850295030503150325033503450355036503750385039504050415042504350445045504650475048504950505051505250535054505550565057505850595060506150625063506450655066506750685069507050715072507350745075507650775078507950805081508250835084508550865087508850895090509150925093509450955096509750985099510051015102510351045105510651075108510951105111511251135114511551165117511851195120512151225123512451255126512751285129513051315132513351345135513651375138513951405141514251435144514551465147514851495150515151525153515451555156515751585159516051615162516351645165516651675168516951705171517251735174517551765177517851795180518151825183518451855186518751885189519051915192519351945195519651975198519952005201520252035204520552065207520852095210521152125213521452155216521752185219522052215222522352245225522652275228522952305231523252335234523552365237523852395240524152425243524452455246524752485249525052515252525352545255525652575258525952605261526252635264526552665267526852695270527152725273527452755276527752785279528052815282528352845285528652875288528952905291529252935294529552965297529852995300530153025303530453055306530753085309531053115312531353145315531653175318531953205321532253235324532553265327532853295330533153325333533453355336533753385339534053415342534353445345534653475348534953505351535253535354535553565357535853595360536153625363536453655366536753685369537053715372537353745375537653775378537953805381538253835384538553865387538853895390539153925393539453955396539753985399540054015402540354045405540654075408540954105411541254135414541554165417541854195420542154225423542454255426542754285429543054315432543354345435543654375438543954405441544254435444544554465447544854495450545154525453545454555456545754585459546054615462546354645465546654675468546954705471547254735474547554765477547854795480548154825483548454855486548754885489549054915492549354945495549654975498549955005501550255035504550555065507550855095510551155125513551455155516551755185519552055215522552355245525552655275528552955305531553255335534553555365537553855395540554155425543554455455546554755485549555055515552555355545555555655575558555955605561556255635564556555665567556855695570557155725573557455755576557755785579558055815582558355845585558655875588558955905591559255935594559555965597559855995600560156025603560456055606560756085609561056115612561356145615561656175618561956205621562256235624562556265627562856295630563156325633563456355636563756385639564056415642564356445645564656475648564956505651565256535654565556565657565856595660566156625663566456655666566756685669567056715672567356745675567656775678567956805681568256835684568556865687568856895690569156925693569456955696569756985699570057015702570357045705570657075708570957105711571257135714571557165717571857195720572157225723572457255726572757285729573057315732573357345735573657375738573957405741574257435744574557465747574857495750575157525753575457555756575757585759576057615762576357645765576657675768576957705771577257735774577557765777577857795780578157825783578457855786578757885789579057915792579357945795579657975798579958005801580258035804580558065807580858095810581158125813581458155816581758185819582058215822582358245825582658275828582958305831583258335834583558365837583858395840584158425843584458455846584758485849585058515852585358545855585658575858585958605861586258635864586558665867586858695870587158725873587458755876587758785879588058815882588358845885588658875888588958905891589258935894589558965897589858995900590159025903590459055906590759085909591059115912591359145915591659175918591959205921592259235924592559265927592859295930593159325933593459355936593759385939594059415942594359445945594659475948594959505951595259535954595559565957595859595960596159625963596459655966596759685969597059715972597359745975597659775978597959805981598259835984598559865987598859895990599159925993599459955996599759985999600060016002600360046005600660076008600960106011601260136014601560166017601860196020602160226023602460256026602760286029603060316032603360346035603660376038603960406041604260436044604560466047604860496050605160526053605460556056605760586059606060616062606360646065606660676068606960706071607260736074607560766077607860796080608160826083608460856086608760886089609060916092609360946095609660976098609961006101610261036104610561066107610861096110611161126113611461156116611761186119612061216122612361246125612661276128612961306131613261336134613561366137613861396140614161426143614461456146614761486149615061516152615361546155615661576158615961606161616261636164616561666167616861696170617161726173617461756176617761786179618061816182618361846185618661876188618961906191619261936194619561966197619861996200620162026203620462056206620762086209621062116212621362146215621662176218621962206221622262236224622562266227622862296230623162326233623462356236623762386239624062416242624362446245624662476248624962506251625262536254625562566257625862596260626162626263626462656266626762686269627062716272627362746275627662776278627962806281628262836284628562866287628862896290629162926293629462956296629762986299630063016302630363046305630663076308630963106311631263136314631563166317631863196320632163226323632463256326632763286329633063316332633363346335633663376338633963406341634263436344634563466347634863496350635163526353635463556356635763586359636063616362636363646365636663676368636963706371637263736374637563766377637863796380638163826383638463856386638763886389639063916392639363946395639663976398639964006401640264036404640564066407640864096410641164126413641464156416641764186419642064216422642364246425642664276428642964306431643264336434643564366437643864396440644164426443644464456446644764486449645064516452645364546455645664576458645964606461646264636464646564666467646864696470647164726473647464756476647764786479648064816482648364846485648664876488648964906491649264936494649564966497649864996500650165026503650465056506650765086509651065116512651365146515651665176518651965206521652265236524652565266527652865296530653165326533653465356536653765386539654065416542654365446545654665476548654965506551655265536554655565566557655865596560656165626563656465656566656765686569657065716572657365746575657665776578657965806581658265836584658565866587658865896590659165926593659465956596659765986599660066016602660366046605660666076608660966106611661266136614661566166617661866196620662166226623662466256626662766286629663066316632663366346635663666376638663966406641664266436644664566466647664866496650665166526653665466556656665766586659666066616662666366646665666666676668666966706671667266736674667566766677667866796680668166826683668466856686668766886689669066916692669366946695669666976698669967006701670267036704670567066707670867096710671167126713671467156716671767186719672067216722672367246725672667276728672967306731673267336734673567366737673867396740674167426743674467456746674767486749675067516752675367546755675667576758675967606761676267636764676567666767676867696770677167726773677467756776677767786779678067816782678367846785678667876788678967906791679267936794679567966797679867996800680168026803680468056806680768086809681068116812681368146815681668176818681968206821682268236824682568266827682868296830683168326833683468356836683768386839684068416842684368446845684668476848684968506851685268536854685568566857685868596860686168626863686468656866686768686869687068716872687368746875687668776878687968806881688268836884688568866887688868896890689168926893689468956896689768986899690069016902690369046905690669076908690969106911691269136914691569166917691869196920692169226923692469256926692769286929693069316932693369346935693669376938693969406941694269436944694569466947694869496950695169526953695469556956695769586959696069616962696369646965696669676968696969706971697269736974697569766977697869796980698169826983698469856986698769886989699069916992699369946995699669976998699970007001700270037004700570067007700870097010701170127013701470157016701770187019702070217022702370247025702670277028702970307031703270337034703570367037703870397040704170427043704470457046704770487049705070517052705370547055705670577058705970607061706270637064706570667067706870697070707170727073707470757076707770787079708070817082708370847085708670877088708970907091709270937094709570967097709870997100710171027103710471057106710771087109711071117112711371147115711671177118711971207121712271237124712571267127712871297130713171327133713471357136713771387139714071417142714371447145714671477148714971507151715271537154715571567157715871597160716171627163716471657166716771687169717071717172717371747175717671777178717971807181718271837184718571867187718871897190719171927193719471957196719771987199720072017202720372047205720672077208720972107211721272137214721572167217721872197220722172227223722472257226722772287229723072317232723372347235723672377238723972407241724272437244724572467247724872497250725172527253725472557256725772587259726072617262726372647265726672677268726972707271727272737274727572767277727872797280728172827283728472857286728772887289729072917292729372947295729672977298729973007301730273037304730573067307730873097310731173127313731473157316731773187319732073217322732373247325732673277328732973307331733273337334733573367337733873397340734173427343734473457346734773487349735073517352735373547355735673577358735973607361736273637364736573667367736873697370737173727373737473757376737773787379738073817382738373847385738673877388738973907391739273937394739573967397739873997400740174027403740474057406740774087409741074117412741374147415741674177418741974207421742274237424742574267427742874297430743174327433743474357436743774387439744074417442744374447445744674477448744974507451745274537454745574567457745874597460746174627463746474657466746774687469747074717472747374747475747674777478747974807481748274837484748574867487748874897490749174927493749474957496749774987499750075017502750375047505750675077508750975107511751275137514751575167517751875197520752175227523752475257526752775287529753075317532753375347535753675377538753975407541754275437544754575467547754875497550755175527553755475557556755775587559756075617562756375647565756675677568756975707571757275737574757575767577757875797580758175827583758475857586758775887589759075917592759375947595759675977598759976007601760276037604760576067607760876097610761176127613761476157616761776187619762076217622762376247625762676277628762976307631763276337634763576367637763876397640764176427643764476457646764776487649765076517652765376547655765676577658765976607661766276637664766576667667766876697670767176727673767476757676767776787679768076817682768376847685768676877688768976907691769276937694769576967697769876997700770177027703770477057706770777087709771077117712771377147715771677177718771977207721772277237724772577267727772877297730773177327733773477357736773777387739774077417742774377447745774677477748774977507751775277537754775577567757775877597760776177627763776477657766776777687769777077717772777377747775777677777778777977807781778277837784778577867787778877897790779177927793779477957796779777987799780078017802780378047805780678077808780978107811781278137814781578167817781878197820782178227823782478257826782778287829783078317832783378347835783678377838783978407841784278437844784578467847784878497850785178527853785478557856785778587859786078617862786378647865786678677868786978707871787278737874787578767877787878797880788178827883788478857886788778887889789078917892789378947895789678977898789979007901790279037904790579067907790879097910791179127913791479157916791779187919792079217922792379247925792679277928792979307931793279337934793579367937793879397940794179427943794479457946794779487949795079517952795379547955795679577958795979607961796279637964796579667967796879697970797179727973797479757976797779787979798079817982798379847985798679877988798979907991799279937994799579967997799879998000800180028003800480058006800780088009801080118012801380148015801680178018801980208021802280238024802580268027802880298030803180328033803480358036803780388039
  1. /*
  2. * WPA Supplicant / Control interface (shared code for all backends)
  3. * Copyright (c) 2004-2014, 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 "common/version.h"
  17. #include "common/ieee802_11_defs.h"
  18. #include "common/ieee802_11_common.h"
  19. #include "common/wpa_ctrl.h"
  20. #include "ap/hostapd.h"
  21. #include "eap_peer/eap.h"
  22. #include "eapol_supp/eapol_supp_sm.h"
  23. #include "rsn_supp/wpa.h"
  24. #include "rsn_supp/preauth.h"
  25. #include "rsn_supp/pmksa_cache.h"
  26. #include "l2_packet/l2_packet.h"
  27. #include "wps/wps.h"
  28. #include "config.h"
  29. #include "wpa_supplicant_i.h"
  30. #include "driver_i.h"
  31. #include "wps_supplicant.h"
  32. #include "ibss_rsn.h"
  33. #include "ap.h"
  34. #include "p2p_supplicant.h"
  35. #include "p2p/p2p.h"
  36. #include "hs20_supplicant.h"
  37. #include "wifi_display.h"
  38. #include "notify.h"
  39. #include "bss.h"
  40. #include "scan.h"
  41. #include "ctrl_iface.h"
  42. #include "interworking.h"
  43. #include "blacklist.h"
  44. #include "autoscan.h"
  45. #include "wnm_sta.h"
  46. #include "offchannel.h"
  47. #include "drivers/driver.h"
  48. #include "mesh.h"
  49. static int wpa_supplicant_global_iface_list(struct wpa_global *global,
  50. char *buf, int len);
  51. static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global,
  52. char *buf, int len);
  53. static int * freq_range_to_channel_list(struct wpa_supplicant *wpa_s,
  54. char *val);
  55. static int set_bssid_filter(struct wpa_supplicant *wpa_s, char *val)
  56. {
  57. char *pos;
  58. u8 addr[ETH_ALEN], *filter = NULL, *n;
  59. size_t count = 0;
  60. pos = val;
  61. while (pos) {
  62. if (*pos == '\0')
  63. break;
  64. if (hwaddr_aton(pos, addr)) {
  65. os_free(filter);
  66. return -1;
  67. }
  68. n = os_realloc_array(filter, count + 1, ETH_ALEN);
  69. if (n == NULL) {
  70. os_free(filter);
  71. return -1;
  72. }
  73. filter = n;
  74. os_memcpy(filter + count * ETH_ALEN, addr, ETH_ALEN);
  75. count++;
  76. pos = os_strchr(pos, ' ');
  77. if (pos)
  78. pos++;
  79. }
  80. wpa_hexdump(MSG_DEBUG, "bssid_filter", filter, count * ETH_ALEN);
  81. os_free(wpa_s->bssid_filter);
  82. wpa_s->bssid_filter = filter;
  83. wpa_s->bssid_filter_count = count;
  84. return 0;
  85. }
  86. static int set_disallow_aps(struct wpa_supplicant *wpa_s, char *val)
  87. {
  88. char *pos;
  89. u8 addr[ETH_ALEN], *bssid = NULL, *n;
  90. struct wpa_ssid_value *ssid = NULL, *ns;
  91. size_t count = 0, ssid_count = 0;
  92. struct wpa_ssid *c;
  93. /*
  94. * disallow_list ::= <ssid_spec> | <bssid_spec> | <disallow_list> | ""
  95. * SSID_SPEC ::= ssid <SSID_HEX>
  96. * BSSID_SPEC ::= bssid <BSSID_HEX>
  97. */
  98. pos = val;
  99. while (pos) {
  100. if (*pos == '\0')
  101. break;
  102. if (os_strncmp(pos, "bssid ", 6) == 0) {
  103. int res;
  104. pos += 6;
  105. res = hwaddr_aton2(pos, addr);
  106. if (res < 0) {
  107. os_free(ssid);
  108. os_free(bssid);
  109. wpa_printf(MSG_DEBUG, "Invalid disallow_aps "
  110. "BSSID value '%s'", pos);
  111. return -1;
  112. }
  113. pos += res;
  114. n = os_realloc_array(bssid, count + 1, ETH_ALEN);
  115. if (n == NULL) {
  116. os_free(ssid);
  117. os_free(bssid);
  118. return -1;
  119. }
  120. bssid = n;
  121. os_memcpy(bssid + count * ETH_ALEN, addr, ETH_ALEN);
  122. count++;
  123. } else if (os_strncmp(pos, "ssid ", 5) == 0) {
  124. char *end;
  125. pos += 5;
  126. end = pos;
  127. while (*end) {
  128. if (*end == '\0' || *end == ' ')
  129. break;
  130. end++;
  131. }
  132. ns = os_realloc_array(ssid, ssid_count + 1,
  133. sizeof(struct wpa_ssid_value));
  134. if (ns == NULL) {
  135. os_free(ssid);
  136. os_free(bssid);
  137. return -1;
  138. }
  139. ssid = ns;
  140. if ((end - pos) & 0x01 || end - pos > 2 * 32 ||
  141. hexstr2bin(pos, ssid[ssid_count].ssid,
  142. (end - pos) / 2) < 0) {
  143. os_free(ssid);
  144. os_free(bssid);
  145. wpa_printf(MSG_DEBUG, "Invalid disallow_aps "
  146. "SSID value '%s'", pos);
  147. return -1;
  148. }
  149. ssid[ssid_count].ssid_len = (end - pos) / 2;
  150. wpa_hexdump_ascii(MSG_DEBUG, "disallow_aps SSID",
  151. ssid[ssid_count].ssid,
  152. ssid[ssid_count].ssid_len);
  153. ssid_count++;
  154. pos = end;
  155. } else {
  156. wpa_printf(MSG_DEBUG, "Unexpected disallow_aps value "
  157. "'%s'", pos);
  158. os_free(ssid);
  159. os_free(bssid);
  160. return -1;
  161. }
  162. pos = os_strchr(pos, ' ');
  163. if (pos)
  164. pos++;
  165. }
  166. wpa_hexdump(MSG_DEBUG, "disallow_aps_bssid", bssid, count * ETH_ALEN);
  167. os_free(wpa_s->disallow_aps_bssid);
  168. wpa_s->disallow_aps_bssid = bssid;
  169. wpa_s->disallow_aps_bssid_count = count;
  170. wpa_printf(MSG_DEBUG, "disallow_aps_ssid_count %d", (int) ssid_count);
  171. os_free(wpa_s->disallow_aps_ssid);
  172. wpa_s->disallow_aps_ssid = ssid;
  173. wpa_s->disallow_aps_ssid_count = ssid_count;
  174. if (!wpa_s->current_ssid || wpa_s->wpa_state < WPA_AUTHENTICATING)
  175. return 0;
  176. c = wpa_s->current_ssid;
  177. if (c->mode != WPAS_MODE_INFRA && c->mode != WPAS_MODE_IBSS)
  178. return 0;
  179. if (!disallowed_bssid(wpa_s, wpa_s->bssid) &&
  180. !disallowed_ssid(wpa_s, c->ssid, c->ssid_len))
  181. return 0;
  182. wpa_printf(MSG_DEBUG, "Disconnect and try to find another network "
  183. "because current AP was marked disallowed");
  184. #ifdef CONFIG_SME
  185. wpa_s->sme.prev_bssid_set = 0;
  186. #endif /* CONFIG_SME */
  187. wpa_s->reassociate = 1;
  188. wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
  189. wpa_supplicant_req_scan(wpa_s, 0, 0);
  190. return 0;
  191. }
  192. #ifndef CONFIG_NO_CONFIG_BLOBS
  193. static int wpas_ctrl_set_blob(struct wpa_supplicant *wpa_s, char *pos)
  194. {
  195. char *name = pos;
  196. struct wpa_config_blob *blob;
  197. size_t len;
  198. pos = os_strchr(pos, ' ');
  199. if (pos == NULL)
  200. return -1;
  201. *pos++ = '\0';
  202. len = os_strlen(pos);
  203. if (len & 1)
  204. return -1;
  205. wpa_printf(MSG_DEBUG, "CTRL: Set blob '%s'", name);
  206. blob = os_zalloc(sizeof(*blob));
  207. if (blob == NULL)
  208. return -1;
  209. blob->name = os_strdup(name);
  210. blob->data = os_malloc(len / 2);
  211. if (blob->name == NULL || blob->data == NULL) {
  212. wpa_config_free_blob(blob);
  213. return -1;
  214. }
  215. if (hexstr2bin(pos, blob->data, len / 2) < 0) {
  216. wpa_printf(MSG_DEBUG, "CTRL: Invalid blob hex data");
  217. wpa_config_free_blob(blob);
  218. return -1;
  219. }
  220. blob->len = len / 2;
  221. wpa_config_set_blob(wpa_s->conf, blob);
  222. return 0;
  223. }
  224. #endif /* CONFIG_NO_CONFIG_BLOBS */
  225. static int wpas_ctrl_pno(struct wpa_supplicant *wpa_s, char *cmd)
  226. {
  227. char *params;
  228. char *pos;
  229. int *freqs = NULL;
  230. int ret;
  231. if (atoi(cmd)) {
  232. params = os_strchr(cmd, ' ');
  233. os_free(wpa_s->manual_sched_scan_freqs);
  234. if (params) {
  235. params++;
  236. pos = os_strstr(params, "freq=");
  237. if (pos)
  238. freqs = freq_range_to_channel_list(wpa_s,
  239. pos + 5);
  240. }
  241. wpa_s->manual_sched_scan_freqs = freqs;
  242. ret = wpas_start_pno(wpa_s);
  243. } else {
  244. ret = wpas_stop_pno(wpa_s);
  245. }
  246. return ret;
  247. }
  248. static int wpa_supplicant_ctrl_iface_set(struct wpa_supplicant *wpa_s,
  249. char *cmd)
  250. {
  251. char *value;
  252. int ret = 0;
  253. value = os_strchr(cmd, ' ');
  254. if (value == NULL)
  255. return -1;
  256. *value++ = '\0';
  257. wpa_printf(MSG_DEBUG, "CTRL_IFACE SET '%s'='%s'", cmd, value);
  258. if (os_strcasecmp(cmd, "EAPOL::heldPeriod") == 0) {
  259. eapol_sm_configure(wpa_s->eapol,
  260. atoi(value), -1, -1, -1);
  261. } else if (os_strcasecmp(cmd, "EAPOL::authPeriod") == 0) {
  262. eapol_sm_configure(wpa_s->eapol,
  263. -1, atoi(value), -1, -1);
  264. } else if (os_strcasecmp(cmd, "EAPOL::startPeriod") == 0) {
  265. eapol_sm_configure(wpa_s->eapol,
  266. -1, -1, atoi(value), -1);
  267. } else if (os_strcasecmp(cmd, "EAPOL::maxStart") == 0) {
  268. eapol_sm_configure(wpa_s->eapol,
  269. -1, -1, -1, atoi(value));
  270. } else if (os_strcasecmp(cmd, "dot11RSNAConfigPMKLifetime") == 0) {
  271. if (wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_LIFETIME,
  272. atoi(value)))
  273. ret = -1;
  274. } else if (os_strcasecmp(cmd, "dot11RSNAConfigPMKReauthThreshold") ==
  275. 0) {
  276. if (wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_REAUTH_THRESHOLD,
  277. atoi(value)))
  278. ret = -1;
  279. } else if (os_strcasecmp(cmd, "dot11RSNAConfigSATimeout") == 0) {
  280. if (wpa_sm_set_param(wpa_s->wpa, RSNA_SA_TIMEOUT, atoi(value)))
  281. ret = -1;
  282. } else if (os_strcasecmp(cmd, "wps_fragment_size") == 0) {
  283. wpa_s->wps_fragment_size = atoi(value);
  284. #ifdef CONFIG_WPS_TESTING
  285. } else if (os_strcasecmp(cmd, "wps_version_number") == 0) {
  286. long int val;
  287. val = strtol(value, NULL, 0);
  288. if (val < 0 || val > 0xff) {
  289. ret = -1;
  290. wpa_printf(MSG_DEBUG, "WPS: Invalid "
  291. "wps_version_number %ld", val);
  292. } else {
  293. wps_version_number = val;
  294. wpa_printf(MSG_DEBUG, "WPS: Testing - force WPS "
  295. "version %u.%u",
  296. (wps_version_number & 0xf0) >> 4,
  297. wps_version_number & 0x0f);
  298. }
  299. } else if (os_strcasecmp(cmd, "wps_testing_dummy_cred") == 0) {
  300. wps_testing_dummy_cred = atoi(value);
  301. wpa_printf(MSG_DEBUG, "WPS: Testing - dummy_cred=%d",
  302. wps_testing_dummy_cred);
  303. } else if (os_strcasecmp(cmd, "wps_corrupt_pkhash") == 0) {
  304. wps_corrupt_pkhash = atoi(value);
  305. wpa_printf(MSG_DEBUG, "WPS: Testing - wps_corrupt_pkhash=%d",
  306. wps_corrupt_pkhash);
  307. #endif /* CONFIG_WPS_TESTING */
  308. } else if (os_strcasecmp(cmd, "ampdu") == 0) {
  309. if (wpa_drv_ampdu(wpa_s, atoi(value)) < 0)
  310. ret = -1;
  311. #ifdef CONFIG_TDLS
  312. #ifdef CONFIG_TDLS_TESTING
  313. } else if (os_strcasecmp(cmd, "tdls_testing") == 0) {
  314. extern unsigned int tdls_testing;
  315. tdls_testing = strtol(value, NULL, 0);
  316. wpa_printf(MSG_DEBUG, "TDLS: tdls_testing=0x%x", tdls_testing);
  317. #endif /* CONFIG_TDLS_TESTING */
  318. } else if (os_strcasecmp(cmd, "tdls_disabled") == 0) {
  319. int disabled = atoi(value);
  320. wpa_printf(MSG_DEBUG, "TDLS: tdls_disabled=%d", disabled);
  321. if (disabled) {
  322. if (wpa_drv_tdls_oper(wpa_s, TDLS_DISABLE, NULL) < 0)
  323. ret = -1;
  324. } else if (wpa_drv_tdls_oper(wpa_s, TDLS_ENABLE, NULL) < 0)
  325. ret = -1;
  326. wpa_tdls_enable(wpa_s->wpa, !disabled);
  327. #endif /* CONFIG_TDLS */
  328. } else if (os_strcasecmp(cmd, "pno") == 0) {
  329. ret = wpas_ctrl_pno(wpa_s, value);
  330. } else if (os_strcasecmp(cmd, "radio_disabled") == 0) {
  331. int disabled = atoi(value);
  332. if (wpa_drv_radio_disable(wpa_s, disabled) < 0)
  333. ret = -1;
  334. else if (disabled)
  335. wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
  336. } else if (os_strcasecmp(cmd, "uapsd") == 0) {
  337. if (os_strcmp(value, "disable") == 0)
  338. wpa_s->set_sta_uapsd = 0;
  339. else {
  340. int be, bk, vi, vo;
  341. char *pos;
  342. /* format: BE,BK,VI,VO;max SP Length */
  343. be = atoi(value);
  344. pos = os_strchr(value, ',');
  345. if (pos == NULL)
  346. return -1;
  347. pos++;
  348. bk = atoi(pos);
  349. pos = os_strchr(pos, ',');
  350. if (pos == NULL)
  351. return -1;
  352. pos++;
  353. vi = atoi(pos);
  354. pos = os_strchr(pos, ',');
  355. if (pos == NULL)
  356. return -1;
  357. pos++;
  358. vo = atoi(pos);
  359. /* ignore max SP Length for now */
  360. wpa_s->set_sta_uapsd = 1;
  361. wpa_s->sta_uapsd = 0;
  362. if (be)
  363. wpa_s->sta_uapsd |= BIT(0);
  364. if (bk)
  365. wpa_s->sta_uapsd |= BIT(1);
  366. if (vi)
  367. wpa_s->sta_uapsd |= BIT(2);
  368. if (vo)
  369. wpa_s->sta_uapsd |= BIT(3);
  370. }
  371. } else if (os_strcasecmp(cmd, "ps") == 0) {
  372. ret = wpa_drv_set_p2p_powersave(wpa_s, atoi(value), -1, -1);
  373. #ifdef CONFIG_WIFI_DISPLAY
  374. } else if (os_strcasecmp(cmd, "wifi_display") == 0) {
  375. int enabled = !!atoi(value);
  376. if (enabled && !wpa_s->global->p2p)
  377. ret = -1;
  378. else
  379. wifi_display_enable(wpa_s->global, enabled);
  380. #endif /* CONFIG_WIFI_DISPLAY */
  381. } else if (os_strcasecmp(cmd, "bssid_filter") == 0) {
  382. ret = set_bssid_filter(wpa_s, value);
  383. } else if (os_strcasecmp(cmd, "disallow_aps") == 0) {
  384. ret = set_disallow_aps(wpa_s, value);
  385. } else if (os_strcasecmp(cmd, "no_keep_alive") == 0) {
  386. wpa_s->no_keep_alive = !!atoi(value);
  387. #ifdef CONFIG_TESTING_OPTIONS
  388. } else if (os_strcasecmp(cmd, "ext_mgmt_frame_handling") == 0) {
  389. wpa_s->ext_mgmt_frame_handling = !!atoi(value);
  390. } else if (os_strcasecmp(cmd, "ext_eapol_frame_io") == 0) {
  391. wpa_s->ext_eapol_frame_io = !!atoi(value);
  392. #ifdef CONFIG_AP
  393. if (wpa_s->ap_iface) {
  394. wpa_s->ap_iface->bss[0]->ext_eapol_frame_io =
  395. wpa_s->ext_eapol_frame_io;
  396. }
  397. #endif /* CONFIG_AP */
  398. } else if (os_strcasecmp(cmd, "extra_roc_dur") == 0) {
  399. wpa_s->extra_roc_dur = atoi(value);
  400. #endif /* CONFIG_TESTING_OPTIONS */
  401. #ifndef CONFIG_NO_CONFIG_BLOBS
  402. } else if (os_strcmp(cmd, "blob") == 0) {
  403. ret = wpas_ctrl_set_blob(wpa_s, value);
  404. #endif /* CONFIG_NO_CONFIG_BLOBS */
  405. } else {
  406. value[-1] = '=';
  407. ret = wpa_config_process_global(wpa_s->conf, cmd, -1);
  408. if (ret == 0)
  409. wpa_supplicant_update_config(wpa_s);
  410. }
  411. return ret;
  412. }
  413. static int wpa_supplicant_ctrl_iface_get(struct wpa_supplicant *wpa_s,
  414. char *cmd, char *buf, size_t buflen)
  415. {
  416. int res = -1;
  417. wpa_printf(MSG_DEBUG, "CTRL_IFACE GET '%s'", cmd);
  418. if (os_strcmp(cmd, "version") == 0) {
  419. res = os_snprintf(buf, buflen, "%s", VERSION_STR);
  420. } else if (os_strcasecmp(cmd, "country") == 0) {
  421. if (wpa_s->conf->country[0] && wpa_s->conf->country[1])
  422. res = os_snprintf(buf, buflen, "%c%c",
  423. wpa_s->conf->country[0],
  424. wpa_s->conf->country[1]);
  425. #ifdef CONFIG_WIFI_DISPLAY
  426. } else if (os_strcasecmp(cmd, "wifi_display") == 0) {
  427. int enabled;
  428. if (wpa_s->global->p2p == NULL ||
  429. wpa_s->global->p2p_disabled)
  430. enabled = 0;
  431. else
  432. enabled = wpa_s->global->wifi_display;
  433. res = os_snprintf(buf, buflen, "%d", enabled);
  434. if (res < 0 || (unsigned int) res >= buflen)
  435. return -1;
  436. return res;
  437. #endif /* CONFIG_WIFI_DISPLAY */
  438. #ifdef CONFIG_TESTING_GET_GTK
  439. } else if (os_strcmp(cmd, "gtk") == 0) {
  440. if (wpa_s->last_gtk_len == 0)
  441. return -1;
  442. res = wpa_snprintf_hex(buf, buflen, wpa_s->last_gtk,
  443. wpa_s->last_gtk_len);
  444. return res;
  445. #endif /* CONFIG_TESTING_GET_GTK */
  446. }
  447. if (res < 0 || (unsigned int) res >= buflen)
  448. return -1;
  449. return res;
  450. }
  451. #ifdef IEEE8021X_EAPOL
  452. static int wpa_supplicant_ctrl_iface_preauth(struct wpa_supplicant *wpa_s,
  453. char *addr)
  454. {
  455. u8 bssid[ETH_ALEN];
  456. struct wpa_ssid *ssid = wpa_s->current_ssid;
  457. if (hwaddr_aton(addr, bssid)) {
  458. wpa_printf(MSG_DEBUG, "CTRL_IFACE PREAUTH: invalid address "
  459. "'%s'", addr);
  460. return -1;
  461. }
  462. wpa_printf(MSG_DEBUG, "CTRL_IFACE PREAUTH " MACSTR, MAC2STR(bssid));
  463. rsn_preauth_deinit(wpa_s->wpa);
  464. if (rsn_preauth_init(wpa_s->wpa, bssid, ssid ? &ssid->eap : NULL))
  465. return -1;
  466. return 0;
  467. }
  468. #endif /* IEEE8021X_EAPOL */
  469. #ifdef CONFIG_PEERKEY
  470. /* MLME-STKSTART.request(peer) */
  471. static int wpa_supplicant_ctrl_iface_stkstart(
  472. struct wpa_supplicant *wpa_s, char *addr)
  473. {
  474. u8 peer[ETH_ALEN];
  475. if (hwaddr_aton(addr, peer)) {
  476. wpa_printf(MSG_DEBUG, "CTRL_IFACE STKSTART: invalid "
  477. "address '%s'", addr);
  478. return -1;
  479. }
  480. wpa_printf(MSG_DEBUG, "CTRL_IFACE STKSTART " MACSTR,
  481. MAC2STR(peer));
  482. return wpa_sm_stkstart(wpa_s->wpa, peer);
  483. }
  484. #endif /* CONFIG_PEERKEY */
  485. #ifdef CONFIG_TDLS
  486. static int wpa_supplicant_ctrl_iface_tdls_discover(
  487. struct wpa_supplicant *wpa_s, char *addr)
  488. {
  489. u8 peer[ETH_ALEN];
  490. int ret;
  491. if (hwaddr_aton(addr, peer)) {
  492. wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_DISCOVER: invalid "
  493. "address '%s'", addr);
  494. return -1;
  495. }
  496. wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_DISCOVER " MACSTR,
  497. MAC2STR(peer));
  498. if (wpa_tdls_is_external_setup(wpa_s->wpa))
  499. ret = wpa_tdls_send_discovery_request(wpa_s->wpa, peer);
  500. else
  501. ret = wpa_drv_tdls_oper(wpa_s, TDLS_DISCOVERY_REQ, peer);
  502. return ret;
  503. }
  504. static int wpa_supplicant_ctrl_iface_tdls_setup(
  505. struct wpa_supplicant *wpa_s, char *addr)
  506. {
  507. u8 peer[ETH_ALEN];
  508. int ret;
  509. if (hwaddr_aton(addr, peer)) {
  510. wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_SETUP: invalid "
  511. "address '%s'", addr);
  512. return -1;
  513. }
  514. wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_SETUP " MACSTR,
  515. MAC2STR(peer));
  516. if ((wpa_s->conf->tdls_external_control) &&
  517. wpa_tdls_is_external_setup(wpa_s->wpa))
  518. return wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, peer);
  519. wpa_tdls_remove(wpa_s->wpa, peer);
  520. if (wpa_tdls_is_external_setup(wpa_s->wpa))
  521. ret = wpa_tdls_start(wpa_s->wpa, peer);
  522. else
  523. ret = wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, peer);
  524. return ret;
  525. }
  526. static int wpa_supplicant_ctrl_iface_tdls_teardown(
  527. struct wpa_supplicant *wpa_s, char *addr)
  528. {
  529. u8 peer[ETH_ALEN];
  530. int ret;
  531. if (os_strcmp(addr, "*") == 0) {
  532. /* remove everyone */
  533. wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN *");
  534. wpa_tdls_teardown_peers(wpa_s->wpa);
  535. return 0;
  536. }
  537. if (hwaddr_aton(addr, peer)) {
  538. wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN: invalid "
  539. "address '%s'", addr);
  540. return -1;
  541. }
  542. wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN " MACSTR,
  543. MAC2STR(peer));
  544. if ((wpa_s->conf->tdls_external_control) &&
  545. wpa_tdls_is_external_setup(wpa_s->wpa))
  546. return wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN, peer);
  547. if (wpa_tdls_is_external_setup(wpa_s->wpa))
  548. ret = wpa_tdls_teardown_link(
  549. wpa_s->wpa, peer,
  550. WLAN_REASON_TDLS_TEARDOWN_UNSPECIFIED);
  551. else
  552. ret = wpa_drv_tdls_oper(wpa_s, TDLS_TEARDOWN, peer);
  553. return ret;
  554. }
  555. static int ctrl_iface_get_capability_tdls(
  556. struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
  557. {
  558. int ret;
  559. ret = os_snprintf(buf, buflen, "%s\n",
  560. wpa_s->drv_flags & WPA_DRIVER_FLAGS_TDLS_SUPPORT ?
  561. (wpa_s->drv_flags &
  562. WPA_DRIVER_FLAGS_TDLS_EXTERNAL_SETUP ?
  563. "EXTERNAL" : "INTERNAL") : "UNSUPPORTED");
  564. if (ret < 0 || (size_t) ret > buflen)
  565. return -1;
  566. return ret;
  567. }
  568. #endif /* CONFIG_TDLS */
  569. static int wmm_ac_ctrl_addts(struct wpa_supplicant *wpa_s, char *cmd)
  570. {
  571. char *token, *context = NULL;
  572. struct wmm_ac_ts_setup_params params = {
  573. .tsid = 0xff,
  574. .direction = 0xff,
  575. };
  576. while ((token = str_token(cmd, " ", &context))) {
  577. if (sscanf(token, "tsid=%i", &params.tsid) == 1 ||
  578. sscanf(token, "up=%i", &params.user_priority) == 1 ||
  579. sscanf(token, "nominal_msdu_size=%i",
  580. &params.nominal_msdu_size) == 1 ||
  581. sscanf(token, "mean_data_rate=%i",
  582. &params.mean_data_rate) == 1 ||
  583. sscanf(token, "min_phy_rate=%i",
  584. &params.minimum_phy_rate) == 1 ||
  585. sscanf(token, "sba=%i",
  586. &params.surplus_bandwidth_allowance) == 1)
  587. continue;
  588. if (os_strcasecmp(token, "downlink") == 0) {
  589. params.direction = WMM_TSPEC_DIRECTION_DOWNLINK;
  590. } else if (os_strcasecmp(token, "uplink") == 0) {
  591. params.direction = WMM_TSPEC_DIRECTION_UPLINK;
  592. } else if (os_strcasecmp(token, "bidi") == 0) {
  593. params.direction = WMM_TSPEC_DIRECTION_BI_DIRECTIONAL;
  594. } else if (os_strcasecmp(token, "fixed_nominal_msdu") == 0) {
  595. params.fixed_nominal_msdu = 1;
  596. } else {
  597. wpa_printf(MSG_DEBUG,
  598. "CTRL: Invalid WMM_AC_ADDTS parameter: '%s'",
  599. token);
  600. return -1;
  601. }
  602. }
  603. return wpas_wmm_ac_addts(wpa_s, &params);
  604. }
  605. static int wmm_ac_ctrl_delts(struct wpa_supplicant *wpa_s, char *cmd)
  606. {
  607. u8 tsid = atoi(cmd);
  608. return wpas_wmm_ac_delts(wpa_s, tsid);
  609. }
  610. #ifdef CONFIG_IEEE80211R
  611. static int wpa_supplicant_ctrl_iface_ft_ds(
  612. struct wpa_supplicant *wpa_s, char *addr)
  613. {
  614. u8 target_ap[ETH_ALEN];
  615. struct wpa_bss *bss;
  616. const u8 *mdie;
  617. if (hwaddr_aton(addr, target_ap)) {
  618. wpa_printf(MSG_DEBUG, "CTRL_IFACE FT_DS: invalid "
  619. "address '%s'", addr);
  620. return -1;
  621. }
  622. wpa_printf(MSG_DEBUG, "CTRL_IFACE FT_DS " MACSTR, MAC2STR(target_ap));
  623. bss = wpa_bss_get_bssid(wpa_s, target_ap);
  624. if (bss)
  625. mdie = wpa_bss_get_ie(bss, WLAN_EID_MOBILITY_DOMAIN);
  626. else
  627. mdie = NULL;
  628. return wpa_ft_start_over_ds(wpa_s->wpa, target_ap, mdie);
  629. }
  630. #endif /* CONFIG_IEEE80211R */
  631. #ifdef CONFIG_WPS
  632. static int wpa_supplicant_ctrl_iface_wps_pbc(struct wpa_supplicant *wpa_s,
  633. char *cmd)
  634. {
  635. u8 bssid[ETH_ALEN], *_bssid = bssid;
  636. #ifdef CONFIG_P2P
  637. u8 p2p_dev_addr[ETH_ALEN];
  638. #endif /* CONFIG_P2P */
  639. #ifdef CONFIG_AP
  640. u8 *_p2p_dev_addr = NULL;
  641. #endif /* CONFIG_AP */
  642. if (cmd == NULL || os_strcmp(cmd, "any") == 0) {
  643. _bssid = NULL;
  644. #ifdef CONFIG_P2P
  645. } else if (os_strncmp(cmd, "p2p_dev_addr=", 13) == 0) {
  646. if (hwaddr_aton(cmd + 13, p2p_dev_addr)) {
  647. wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PBC: invalid "
  648. "P2P Device Address '%s'",
  649. cmd + 13);
  650. return -1;
  651. }
  652. _p2p_dev_addr = p2p_dev_addr;
  653. #endif /* CONFIG_P2P */
  654. } else if (hwaddr_aton(cmd, bssid)) {
  655. wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PBC: invalid BSSID '%s'",
  656. cmd);
  657. return -1;
  658. }
  659. #ifdef CONFIG_AP
  660. if (wpa_s->ap_iface)
  661. return wpa_supplicant_ap_wps_pbc(wpa_s, _bssid, _p2p_dev_addr);
  662. #endif /* CONFIG_AP */
  663. return wpas_wps_start_pbc(wpa_s, _bssid, 0);
  664. }
  665. static int wpa_supplicant_ctrl_iface_wps_pin(struct wpa_supplicant *wpa_s,
  666. char *cmd, char *buf,
  667. size_t buflen)
  668. {
  669. u8 bssid[ETH_ALEN], *_bssid = bssid;
  670. char *pin;
  671. int ret;
  672. pin = os_strchr(cmd, ' ');
  673. if (pin)
  674. *pin++ = '\0';
  675. if (os_strcmp(cmd, "any") == 0)
  676. _bssid = NULL;
  677. else if (os_strcmp(cmd, "get") == 0) {
  678. ret = wps_generate_pin();
  679. goto done;
  680. } else if (hwaddr_aton(cmd, bssid)) {
  681. wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PIN: invalid BSSID '%s'",
  682. cmd);
  683. return -1;
  684. }
  685. #ifdef CONFIG_AP
  686. if (wpa_s->ap_iface) {
  687. int timeout = 0;
  688. char *pos;
  689. if (pin) {
  690. pos = os_strchr(pin, ' ');
  691. if (pos) {
  692. *pos++ = '\0';
  693. timeout = atoi(pos);
  694. }
  695. }
  696. return wpa_supplicant_ap_wps_pin(wpa_s, _bssid, pin,
  697. buf, buflen, timeout);
  698. }
  699. #endif /* CONFIG_AP */
  700. if (pin) {
  701. ret = wpas_wps_start_pin(wpa_s, _bssid, pin, 0,
  702. DEV_PW_DEFAULT);
  703. if (ret < 0)
  704. return -1;
  705. ret = os_snprintf(buf, buflen, "%s", pin);
  706. if (ret < 0 || (size_t) ret >= buflen)
  707. return -1;
  708. return ret;
  709. }
  710. ret = wpas_wps_start_pin(wpa_s, _bssid, NULL, 0, DEV_PW_DEFAULT);
  711. if (ret < 0)
  712. return -1;
  713. done:
  714. /* Return the generated PIN */
  715. ret = os_snprintf(buf, buflen, "%08d", ret);
  716. if (ret < 0 || (size_t) ret >= buflen)
  717. return -1;
  718. return ret;
  719. }
  720. static int wpa_supplicant_ctrl_iface_wps_check_pin(
  721. struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
  722. {
  723. char pin[9];
  724. size_t len;
  725. char *pos;
  726. int ret;
  727. wpa_hexdump_ascii_key(MSG_DEBUG, "WPS_CHECK_PIN",
  728. (u8 *) cmd, os_strlen(cmd));
  729. for (pos = cmd, len = 0; *pos != '\0'; pos++) {
  730. if (*pos < '0' || *pos > '9')
  731. continue;
  732. pin[len++] = *pos;
  733. if (len == 9) {
  734. wpa_printf(MSG_DEBUG, "WPS: Too long PIN");
  735. return -1;
  736. }
  737. }
  738. if (len != 4 && len != 8) {
  739. wpa_printf(MSG_DEBUG, "WPS: Invalid PIN length %d", (int) len);
  740. return -1;
  741. }
  742. pin[len] = '\0';
  743. if (len == 8) {
  744. unsigned int pin_val;
  745. pin_val = atoi(pin);
  746. if (!wps_pin_valid(pin_val)) {
  747. wpa_printf(MSG_DEBUG, "WPS: Invalid checksum digit");
  748. ret = os_snprintf(buf, buflen, "FAIL-CHECKSUM\n");
  749. if (ret < 0 || (size_t) ret >= buflen)
  750. return -1;
  751. return ret;
  752. }
  753. }
  754. ret = os_snprintf(buf, buflen, "%s", pin);
  755. if (ret < 0 || (size_t) ret >= buflen)
  756. return -1;
  757. return ret;
  758. }
  759. #ifdef CONFIG_WPS_NFC
  760. static int wpa_supplicant_ctrl_iface_wps_nfc(struct wpa_supplicant *wpa_s,
  761. char *cmd)
  762. {
  763. u8 bssid[ETH_ALEN], *_bssid = bssid;
  764. if (cmd == NULL || cmd[0] == '\0')
  765. _bssid = NULL;
  766. else if (hwaddr_aton(cmd, bssid))
  767. return -1;
  768. return wpas_wps_start_nfc(wpa_s, NULL, _bssid, NULL, 0, 0, NULL, NULL,
  769. 0, 0);
  770. }
  771. static int wpa_supplicant_ctrl_iface_wps_nfc_config_token(
  772. struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
  773. {
  774. int ndef;
  775. struct wpabuf *buf;
  776. int res;
  777. char *pos;
  778. pos = os_strchr(cmd, ' ');
  779. if (pos)
  780. *pos++ = '\0';
  781. if (os_strcmp(cmd, "WPS") == 0)
  782. ndef = 0;
  783. else if (os_strcmp(cmd, "NDEF") == 0)
  784. ndef = 1;
  785. else
  786. return -1;
  787. buf = wpas_wps_nfc_config_token(wpa_s, ndef, pos);
  788. if (buf == NULL)
  789. return -1;
  790. res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
  791. wpabuf_len(buf));
  792. reply[res++] = '\n';
  793. reply[res] = '\0';
  794. wpabuf_free(buf);
  795. return res;
  796. }
  797. static int wpa_supplicant_ctrl_iface_wps_nfc_token(
  798. struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
  799. {
  800. int ndef;
  801. struct wpabuf *buf;
  802. int res;
  803. if (os_strcmp(cmd, "WPS") == 0)
  804. ndef = 0;
  805. else if (os_strcmp(cmd, "NDEF") == 0)
  806. ndef = 1;
  807. else
  808. return -1;
  809. buf = wpas_wps_nfc_token(wpa_s, ndef);
  810. if (buf == NULL)
  811. return -1;
  812. res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
  813. wpabuf_len(buf));
  814. reply[res++] = '\n';
  815. reply[res] = '\0';
  816. wpabuf_free(buf);
  817. return res;
  818. }
  819. static int wpa_supplicant_ctrl_iface_wps_nfc_tag_read(
  820. struct wpa_supplicant *wpa_s, char *pos)
  821. {
  822. size_t len;
  823. struct wpabuf *buf;
  824. int ret;
  825. char *freq;
  826. int forced_freq = 0;
  827. freq = strstr(pos, " freq=");
  828. if (freq) {
  829. *freq = '\0';
  830. freq += 6;
  831. forced_freq = atoi(freq);
  832. }
  833. len = os_strlen(pos);
  834. if (len & 0x01)
  835. return -1;
  836. len /= 2;
  837. buf = wpabuf_alloc(len);
  838. if (buf == NULL)
  839. return -1;
  840. if (hexstr2bin(pos, wpabuf_put(buf, len), len) < 0) {
  841. wpabuf_free(buf);
  842. return -1;
  843. }
  844. ret = wpas_wps_nfc_tag_read(wpa_s, buf, forced_freq);
  845. wpabuf_free(buf);
  846. return ret;
  847. }
  848. static int wpas_ctrl_nfc_get_handover_req_wps(struct wpa_supplicant *wpa_s,
  849. char *reply, size_t max_len,
  850. int ndef)
  851. {
  852. struct wpabuf *buf;
  853. int res;
  854. buf = wpas_wps_nfc_handover_req(wpa_s, ndef);
  855. if (buf == NULL)
  856. return -1;
  857. res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
  858. wpabuf_len(buf));
  859. reply[res++] = '\n';
  860. reply[res] = '\0';
  861. wpabuf_free(buf);
  862. return res;
  863. }
  864. #ifdef CONFIG_P2P
  865. static int wpas_ctrl_nfc_get_handover_req_p2p(struct wpa_supplicant *wpa_s,
  866. char *reply, size_t max_len,
  867. int ndef)
  868. {
  869. struct wpabuf *buf;
  870. int res;
  871. buf = wpas_p2p_nfc_handover_req(wpa_s, ndef);
  872. if (buf == NULL) {
  873. wpa_printf(MSG_DEBUG, "P2P: Could not generate NFC handover request");
  874. return -1;
  875. }
  876. res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
  877. wpabuf_len(buf));
  878. reply[res++] = '\n';
  879. reply[res] = '\0';
  880. wpabuf_free(buf);
  881. return res;
  882. }
  883. #endif /* CONFIG_P2P */
  884. static int wpas_ctrl_nfc_get_handover_req(struct wpa_supplicant *wpa_s,
  885. char *cmd, char *reply,
  886. size_t max_len)
  887. {
  888. char *pos;
  889. int ndef;
  890. pos = os_strchr(cmd, ' ');
  891. if (pos == NULL)
  892. return -1;
  893. *pos++ = '\0';
  894. if (os_strcmp(cmd, "WPS") == 0)
  895. ndef = 0;
  896. else if (os_strcmp(cmd, "NDEF") == 0)
  897. ndef = 1;
  898. else
  899. return -1;
  900. if (os_strcmp(pos, "WPS") == 0 || os_strcmp(pos, "WPS-CR") == 0) {
  901. if (!ndef)
  902. return -1;
  903. return wpas_ctrl_nfc_get_handover_req_wps(
  904. wpa_s, reply, max_len, ndef);
  905. }
  906. #ifdef CONFIG_P2P
  907. if (os_strcmp(pos, "P2P-CR") == 0) {
  908. return wpas_ctrl_nfc_get_handover_req_p2p(
  909. wpa_s, reply, max_len, ndef);
  910. }
  911. #endif /* CONFIG_P2P */
  912. return -1;
  913. }
  914. static int wpas_ctrl_nfc_get_handover_sel_wps(struct wpa_supplicant *wpa_s,
  915. char *reply, size_t max_len,
  916. int ndef, int cr, char *uuid)
  917. {
  918. struct wpabuf *buf;
  919. int res;
  920. buf = wpas_wps_nfc_handover_sel(wpa_s, ndef, cr, uuid);
  921. if (buf == NULL)
  922. return -1;
  923. res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
  924. wpabuf_len(buf));
  925. reply[res++] = '\n';
  926. reply[res] = '\0';
  927. wpabuf_free(buf);
  928. return res;
  929. }
  930. #ifdef CONFIG_P2P
  931. static int wpas_ctrl_nfc_get_handover_sel_p2p(struct wpa_supplicant *wpa_s,
  932. char *reply, size_t max_len,
  933. int ndef, int tag)
  934. {
  935. struct wpabuf *buf;
  936. int res;
  937. buf = wpas_p2p_nfc_handover_sel(wpa_s, ndef, tag);
  938. if (buf == NULL)
  939. return -1;
  940. res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
  941. wpabuf_len(buf));
  942. reply[res++] = '\n';
  943. reply[res] = '\0';
  944. wpabuf_free(buf);
  945. return res;
  946. }
  947. #endif /* CONFIG_P2P */
  948. static int wpas_ctrl_nfc_get_handover_sel(struct wpa_supplicant *wpa_s,
  949. char *cmd, char *reply,
  950. size_t max_len)
  951. {
  952. char *pos, *pos2;
  953. int ndef;
  954. pos = os_strchr(cmd, ' ');
  955. if (pos == NULL)
  956. return -1;
  957. *pos++ = '\0';
  958. if (os_strcmp(cmd, "WPS") == 0)
  959. ndef = 0;
  960. else if (os_strcmp(cmd, "NDEF") == 0)
  961. ndef = 1;
  962. else
  963. return -1;
  964. pos2 = os_strchr(pos, ' ');
  965. if (pos2)
  966. *pos2++ = '\0';
  967. if (os_strcmp(pos, "WPS") == 0 || os_strcmp(pos, "WPS-CR") == 0) {
  968. if (!ndef)
  969. return -1;
  970. return wpas_ctrl_nfc_get_handover_sel_wps(
  971. wpa_s, reply, max_len, ndef,
  972. os_strcmp(pos, "WPS-CR") == 0, pos2);
  973. }
  974. #ifdef CONFIG_P2P
  975. if (os_strcmp(pos, "P2P-CR") == 0) {
  976. return wpas_ctrl_nfc_get_handover_sel_p2p(
  977. wpa_s, reply, max_len, ndef, 0);
  978. }
  979. if (os_strcmp(pos, "P2P-CR-TAG") == 0) {
  980. return wpas_ctrl_nfc_get_handover_sel_p2p(
  981. wpa_s, reply, max_len, ndef, 1);
  982. }
  983. #endif /* CONFIG_P2P */
  984. return -1;
  985. }
  986. static int wpas_ctrl_nfc_report_handover(struct wpa_supplicant *wpa_s,
  987. char *cmd)
  988. {
  989. size_t len;
  990. struct wpabuf *req, *sel;
  991. int ret;
  992. char *pos, *role, *type, *pos2;
  993. #ifdef CONFIG_P2P
  994. char *freq;
  995. int forced_freq = 0;
  996. freq = strstr(cmd, " freq=");
  997. if (freq) {
  998. *freq = '\0';
  999. freq += 6;
  1000. forced_freq = atoi(freq);
  1001. }
  1002. #endif /* CONFIG_P2P */
  1003. role = cmd;
  1004. pos = os_strchr(role, ' ');
  1005. if (pos == NULL) {
  1006. wpa_printf(MSG_DEBUG, "NFC: Missing type in handover report");
  1007. return -1;
  1008. }
  1009. *pos++ = '\0';
  1010. type = pos;
  1011. pos = os_strchr(type, ' ');
  1012. if (pos == NULL) {
  1013. wpa_printf(MSG_DEBUG, "NFC: Missing request message in handover report");
  1014. return -1;
  1015. }
  1016. *pos++ = '\0';
  1017. pos2 = os_strchr(pos, ' ');
  1018. if (pos2 == NULL) {
  1019. wpa_printf(MSG_DEBUG, "NFC: Missing select message in handover report");
  1020. return -1;
  1021. }
  1022. *pos2++ = '\0';
  1023. len = os_strlen(pos);
  1024. if (len & 0x01) {
  1025. wpa_printf(MSG_DEBUG, "NFC: Invalid request message length in handover report");
  1026. return -1;
  1027. }
  1028. len /= 2;
  1029. req = wpabuf_alloc(len);
  1030. if (req == NULL) {
  1031. wpa_printf(MSG_DEBUG, "NFC: Failed to allocate memory for request message");
  1032. return -1;
  1033. }
  1034. if (hexstr2bin(pos, wpabuf_put(req, len), len) < 0) {
  1035. wpa_printf(MSG_DEBUG, "NFC: Invalid request message hexdump in handover report");
  1036. wpabuf_free(req);
  1037. return -1;
  1038. }
  1039. len = os_strlen(pos2);
  1040. if (len & 0x01) {
  1041. wpa_printf(MSG_DEBUG, "NFC: Invalid select message length in handover report");
  1042. wpabuf_free(req);
  1043. return -1;
  1044. }
  1045. len /= 2;
  1046. sel = wpabuf_alloc(len);
  1047. if (sel == NULL) {
  1048. wpa_printf(MSG_DEBUG, "NFC: Failed to allocate memory for select message");
  1049. wpabuf_free(req);
  1050. return -1;
  1051. }
  1052. if (hexstr2bin(pos2, wpabuf_put(sel, len), len) < 0) {
  1053. wpa_printf(MSG_DEBUG, "NFC: Invalid select message hexdump in handover report");
  1054. wpabuf_free(req);
  1055. wpabuf_free(sel);
  1056. return -1;
  1057. }
  1058. wpa_printf(MSG_DEBUG, "NFC: Connection handover reported - role=%s type=%s req_len=%d sel_len=%d",
  1059. role, type, (int) wpabuf_len(req), (int) wpabuf_len(sel));
  1060. if (os_strcmp(role, "INIT") == 0 && os_strcmp(type, "WPS") == 0) {
  1061. ret = wpas_wps_nfc_report_handover(wpa_s, req, sel);
  1062. #ifdef CONFIG_AP
  1063. } else if (os_strcmp(role, "RESP") == 0 && os_strcmp(type, "WPS") == 0)
  1064. {
  1065. ret = wpas_ap_wps_nfc_report_handover(wpa_s, req, sel);
  1066. if (ret < 0)
  1067. ret = wpas_er_wps_nfc_report_handover(wpa_s, req, sel);
  1068. #endif /* CONFIG_AP */
  1069. #ifdef CONFIG_P2P
  1070. } else if (os_strcmp(role, "INIT") == 0 && os_strcmp(type, "P2P") == 0)
  1071. {
  1072. ret = wpas_p2p_nfc_report_handover(wpa_s, 1, req, sel, 0);
  1073. } else if (os_strcmp(role, "RESP") == 0 && os_strcmp(type, "P2P") == 0)
  1074. {
  1075. ret = wpas_p2p_nfc_report_handover(wpa_s, 0, req, sel,
  1076. forced_freq);
  1077. #endif /* CONFIG_P2P */
  1078. } else {
  1079. wpa_printf(MSG_DEBUG, "NFC: Unsupported connection handover "
  1080. "reported: role=%s type=%s", role, type);
  1081. ret = -1;
  1082. }
  1083. wpabuf_free(req);
  1084. wpabuf_free(sel);
  1085. if (ret)
  1086. wpa_printf(MSG_DEBUG, "NFC: Failed to process reported handover messages");
  1087. return ret;
  1088. }
  1089. #endif /* CONFIG_WPS_NFC */
  1090. static int wpa_supplicant_ctrl_iface_wps_reg(struct wpa_supplicant *wpa_s,
  1091. char *cmd)
  1092. {
  1093. u8 bssid[ETH_ALEN];
  1094. char *pin;
  1095. char *new_ssid;
  1096. char *new_auth;
  1097. char *new_encr;
  1098. char *new_key;
  1099. struct wps_new_ap_settings ap;
  1100. pin = os_strchr(cmd, ' ');
  1101. if (pin == NULL)
  1102. return -1;
  1103. *pin++ = '\0';
  1104. if (hwaddr_aton(cmd, bssid)) {
  1105. wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_REG: invalid BSSID '%s'",
  1106. cmd);
  1107. return -1;
  1108. }
  1109. new_ssid = os_strchr(pin, ' ');
  1110. if (new_ssid == NULL)
  1111. return wpas_wps_start_reg(wpa_s, bssid, pin, NULL);
  1112. *new_ssid++ = '\0';
  1113. new_auth = os_strchr(new_ssid, ' ');
  1114. if (new_auth == NULL)
  1115. return -1;
  1116. *new_auth++ = '\0';
  1117. new_encr = os_strchr(new_auth, ' ');
  1118. if (new_encr == NULL)
  1119. return -1;
  1120. *new_encr++ = '\0';
  1121. new_key = os_strchr(new_encr, ' ');
  1122. if (new_key == NULL)
  1123. return -1;
  1124. *new_key++ = '\0';
  1125. os_memset(&ap, 0, sizeof(ap));
  1126. ap.ssid_hex = new_ssid;
  1127. ap.auth = new_auth;
  1128. ap.encr = new_encr;
  1129. ap.key_hex = new_key;
  1130. return wpas_wps_start_reg(wpa_s, bssid, pin, &ap);
  1131. }
  1132. #ifdef CONFIG_AP
  1133. static int wpa_supplicant_ctrl_iface_wps_ap_pin(struct wpa_supplicant *wpa_s,
  1134. char *cmd, char *buf,
  1135. size_t buflen)
  1136. {
  1137. int timeout = 300;
  1138. char *pos;
  1139. const char *pin_txt;
  1140. if (!wpa_s->ap_iface)
  1141. return -1;
  1142. pos = os_strchr(cmd, ' ');
  1143. if (pos)
  1144. *pos++ = '\0';
  1145. if (os_strcmp(cmd, "disable") == 0) {
  1146. wpas_wps_ap_pin_disable(wpa_s);
  1147. return os_snprintf(buf, buflen, "OK\n");
  1148. }
  1149. if (os_strcmp(cmd, "random") == 0) {
  1150. if (pos)
  1151. timeout = atoi(pos);
  1152. pin_txt = wpas_wps_ap_pin_random(wpa_s, timeout);
  1153. if (pin_txt == NULL)
  1154. return -1;
  1155. return os_snprintf(buf, buflen, "%s", pin_txt);
  1156. }
  1157. if (os_strcmp(cmd, "get") == 0) {
  1158. pin_txt = wpas_wps_ap_pin_get(wpa_s);
  1159. if (pin_txt == NULL)
  1160. return -1;
  1161. return os_snprintf(buf, buflen, "%s", pin_txt);
  1162. }
  1163. if (os_strcmp(cmd, "set") == 0) {
  1164. char *pin;
  1165. if (pos == NULL)
  1166. return -1;
  1167. pin = pos;
  1168. pos = os_strchr(pos, ' ');
  1169. if (pos) {
  1170. *pos++ = '\0';
  1171. timeout = atoi(pos);
  1172. }
  1173. if (os_strlen(pin) > buflen)
  1174. return -1;
  1175. if (wpas_wps_ap_pin_set(wpa_s, pin, timeout) < 0)
  1176. return -1;
  1177. return os_snprintf(buf, buflen, "%s", pin);
  1178. }
  1179. return -1;
  1180. }
  1181. #endif /* CONFIG_AP */
  1182. #ifdef CONFIG_WPS_ER
  1183. static int wpa_supplicant_ctrl_iface_wps_er_pin(struct wpa_supplicant *wpa_s,
  1184. char *cmd)
  1185. {
  1186. char *uuid = cmd, *pin, *pos;
  1187. u8 addr_buf[ETH_ALEN], *addr = NULL;
  1188. pin = os_strchr(uuid, ' ');
  1189. if (pin == NULL)
  1190. return -1;
  1191. *pin++ = '\0';
  1192. pos = os_strchr(pin, ' ');
  1193. if (pos) {
  1194. *pos++ = '\0';
  1195. if (hwaddr_aton(pos, addr_buf) == 0)
  1196. addr = addr_buf;
  1197. }
  1198. return wpas_wps_er_add_pin(wpa_s, addr, uuid, pin);
  1199. }
  1200. static int wpa_supplicant_ctrl_iface_wps_er_learn(struct wpa_supplicant *wpa_s,
  1201. char *cmd)
  1202. {
  1203. char *uuid = cmd, *pin;
  1204. pin = os_strchr(uuid, ' ');
  1205. if (pin == NULL)
  1206. return -1;
  1207. *pin++ = '\0';
  1208. return wpas_wps_er_learn(wpa_s, uuid, pin);
  1209. }
  1210. static int wpa_supplicant_ctrl_iface_wps_er_set_config(
  1211. struct wpa_supplicant *wpa_s, char *cmd)
  1212. {
  1213. char *uuid = cmd, *id;
  1214. id = os_strchr(uuid, ' ');
  1215. if (id == NULL)
  1216. return -1;
  1217. *id++ = '\0';
  1218. return wpas_wps_er_set_config(wpa_s, uuid, atoi(id));
  1219. }
  1220. static int wpa_supplicant_ctrl_iface_wps_er_config(
  1221. struct wpa_supplicant *wpa_s, char *cmd)
  1222. {
  1223. char *pin;
  1224. char *new_ssid;
  1225. char *new_auth;
  1226. char *new_encr;
  1227. char *new_key;
  1228. struct wps_new_ap_settings ap;
  1229. pin = os_strchr(cmd, ' ');
  1230. if (pin == NULL)
  1231. return -1;
  1232. *pin++ = '\0';
  1233. new_ssid = os_strchr(pin, ' ');
  1234. if (new_ssid == NULL)
  1235. return -1;
  1236. *new_ssid++ = '\0';
  1237. new_auth = os_strchr(new_ssid, ' ');
  1238. if (new_auth == NULL)
  1239. return -1;
  1240. *new_auth++ = '\0';
  1241. new_encr = os_strchr(new_auth, ' ');
  1242. if (new_encr == NULL)
  1243. return -1;
  1244. *new_encr++ = '\0';
  1245. new_key = os_strchr(new_encr, ' ');
  1246. if (new_key == NULL)
  1247. return -1;
  1248. *new_key++ = '\0';
  1249. os_memset(&ap, 0, sizeof(ap));
  1250. ap.ssid_hex = new_ssid;
  1251. ap.auth = new_auth;
  1252. ap.encr = new_encr;
  1253. ap.key_hex = new_key;
  1254. return wpas_wps_er_config(wpa_s, cmd, pin, &ap);
  1255. }
  1256. #ifdef CONFIG_WPS_NFC
  1257. static int wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
  1258. struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
  1259. {
  1260. int ndef;
  1261. struct wpabuf *buf;
  1262. int res;
  1263. char *uuid;
  1264. uuid = os_strchr(cmd, ' ');
  1265. if (uuid == NULL)
  1266. return -1;
  1267. *uuid++ = '\0';
  1268. if (os_strcmp(cmd, "WPS") == 0)
  1269. ndef = 0;
  1270. else if (os_strcmp(cmd, "NDEF") == 0)
  1271. ndef = 1;
  1272. else
  1273. return -1;
  1274. buf = wpas_wps_er_nfc_config_token(wpa_s, ndef, uuid);
  1275. if (buf == NULL)
  1276. return -1;
  1277. res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
  1278. wpabuf_len(buf));
  1279. reply[res++] = '\n';
  1280. reply[res] = '\0';
  1281. wpabuf_free(buf);
  1282. return res;
  1283. }
  1284. #endif /* CONFIG_WPS_NFC */
  1285. #endif /* CONFIG_WPS_ER */
  1286. #endif /* CONFIG_WPS */
  1287. #ifdef CONFIG_IBSS_RSN
  1288. static int wpa_supplicant_ctrl_iface_ibss_rsn(
  1289. struct wpa_supplicant *wpa_s, char *addr)
  1290. {
  1291. u8 peer[ETH_ALEN];
  1292. if (hwaddr_aton(addr, peer)) {
  1293. wpa_printf(MSG_DEBUG, "CTRL_IFACE IBSS_RSN: invalid "
  1294. "address '%s'", addr);
  1295. return -1;
  1296. }
  1297. wpa_printf(MSG_DEBUG, "CTRL_IFACE IBSS_RSN " MACSTR,
  1298. MAC2STR(peer));
  1299. return ibss_rsn_start(wpa_s->ibss_rsn, peer);
  1300. }
  1301. #endif /* CONFIG_IBSS_RSN */
  1302. static int wpa_supplicant_ctrl_iface_ctrl_rsp(struct wpa_supplicant *wpa_s,
  1303. char *rsp)
  1304. {
  1305. #ifdef IEEE8021X_EAPOL
  1306. char *pos, *id_pos;
  1307. int id;
  1308. struct wpa_ssid *ssid;
  1309. pos = os_strchr(rsp, '-');
  1310. if (pos == NULL)
  1311. return -1;
  1312. *pos++ = '\0';
  1313. id_pos = pos;
  1314. pos = os_strchr(pos, ':');
  1315. if (pos == NULL)
  1316. return -1;
  1317. *pos++ = '\0';
  1318. id = atoi(id_pos);
  1319. wpa_printf(MSG_DEBUG, "CTRL_IFACE: field=%s id=%d", rsp, id);
  1320. wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
  1321. (u8 *) pos, os_strlen(pos));
  1322. ssid = wpa_config_get_network(wpa_s->conf, id);
  1323. if (ssid == NULL) {
  1324. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
  1325. "to update", id);
  1326. return -1;
  1327. }
  1328. return wpa_supplicant_ctrl_iface_ctrl_rsp_handle(wpa_s, ssid, rsp,
  1329. pos);
  1330. #else /* IEEE8021X_EAPOL */
  1331. wpa_printf(MSG_DEBUG, "CTRL_IFACE: 802.1X not included");
  1332. return -1;
  1333. #endif /* IEEE8021X_EAPOL */
  1334. }
  1335. static int wpa_supplicant_ctrl_iface_status(struct wpa_supplicant *wpa_s,
  1336. const char *params,
  1337. char *buf, size_t buflen)
  1338. {
  1339. char *pos, *end, tmp[30];
  1340. int res, verbose, wps, ret;
  1341. #ifdef CONFIG_HS20
  1342. const u8 *hs20;
  1343. #endif /* CONFIG_HS20 */
  1344. if (os_strcmp(params, "-DRIVER") == 0)
  1345. return wpa_drv_status(wpa_s, buf, buflen);
  1346. verbose = os_strcmp(params, "-VERBOSE") == 0;
  1347. wps = os_strcmp(params, "-WPS") == 0;
  1348. pos = buf;
  1349. end = buf + buflen;
  1350. if (wpa_s->wpa_state >= WPA_ASSOCIATED) {
  1351. struct wpa_ssid *ssid = wpa_s->current_ssid;
  1352. ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n",
  1353. MAC2STR(wpa_s->bssid));
  1354. if (ret < 0 || ret >= end - pos)
  1355. return pos - buf;
  1356. pos += ret;
  1357. ret = os_snprintf(pos, end - pos, "freq=%u\n",
  1358. wpa_s->assoc_freq);
  1359. if (ret < 0 || ret >= end - pos)
  1360. return pos - buf;
  1361. pos += ret;
  1362. if (ssid) {
  1363. u8 *_ssid = ssid->ssid;
  1364. size_t ssid_len = ssid->ssid_len;
  1365. u8 ssid_buf[MAX_SSID_LEN];
  1366. if (ssid_len == 0) {
  1367. int _res = wpa_drv_get_ssid(wpa_s, ssid_buf);
  1368. if (_res < 0)
  1369. ssid_len = 0;
  1370. else
  1371. ssid_len = _res;
  1372. _ssid = ssid_buf;
  1373. }
  1374. ret = os_snprintf(pos, end - pos, "ssid=%s\nid=%d\n",
  1375. wpa_ssid_txt(_ssid, ssid_len),
  1376. ssid->id);
  1377. if (ret < 0 || ret >= end - pos)
  1378. return pos - buf;
  1379. pos += ret;
  1380. if (wps && ssid->passphrase &&
  1381. wpa_key_mgmt_wpa_psk(ssid->key_mgmt) &&
  1382. (ssid->mode == WPAS_MODE_AP ||
  1383. ssid->mode == WPAS_MODE_P2P_GO)) {
  1384. ret = os_snprintf(pos, end - pos,
  1385. "passphrase=%s\n",
  1386. ssid->passphrase);
  1387. if (ret < 0 || ret >= end - pos)
  1388. return pos - buf;
  1389. pos += ret;
  1390. }
  1391. if (ssid->id_str) {
  1392. ret = os_snprintf(pos, end - pos,
  1393. "id_str=%s\n",
  1394. ssid->id_str);
  1395. if (ret < 0 || ret >= end - pos)
  1396. return pos - buf;
  1397. pos += ret;
  1398. }
  1399. switch (ssid->mode) {
  1400. case WPAS_MODE_INFRA:
  1401. ret = os_snprintf(pos, end - pos,
  1402. "mode=station\n");
  1403. break;
  1404. case WPAS_MODE_IBSS:
  1405. ret = os_snprintf(pos, end - pos,
  1406. "mode=IBSS\n");
  1407. break;
  1408. case WPAS_MODE_AP:
  1409. ret = os_snprintf(pos, end - pos,
  1410. "mode=AP\n");
  1411. break;
  1412. case WPAS_MODE_P2P_GO:
  1413. ret = os_snprintf(pos, end - pos,
  1414. "mode=P2P GO\n");
  1415. break;
  1416. case WPAS_MODE_P2P_GROUP_FORMATION:
  1417. ret = os_snprintf(pos, end - pos,
  1418. "mode=P2P GO - group "
  1419. "formation\n");
  1420. break;
  1421. default:
  1422. ret = 0;
  1423. break;
  1424. }
  1425. if (ret < 0 || ret >= end - pos)
  1426. return pos - buf;
  1427. pos += ret;
  1428. }
  1429. #ifdef CONFIG_AP
  1430. if (wpa_s->ap_iface) {
  1431. pos += ap_ctrl_iface_wpa_get_status(wpa_s, pos,
  1432. end - pos,
  1433. verbose);
  1434. } else
  1435. #endif /* CONFIG_AP */
  1436. pos += wpa_sm_get_status(wpa_s->wpa, pos, end - pos, verbose);
  1437. }
  1438. #ifdef CONFIG_SAE
  1439. if (wpa_s->wpa_state >= WPA_ASSOCIATED &&
  1440. #ifdef CONFIG_AP
  1441. !wpa_s->ap_iface &&
  1442. #endif /* CONFIG_AP */
  1443. wpa_s->sme.sae.state == SAE_ACCEPTED) {
  1444. ret = os_snprintf(pos, end - pos, "sae_group=%d\n",
  1445. wpa_s->sme.sae.group);
  1446. if (ret < 0 || ret >= end - pos)
  1447. return pos - buf;
  1448. pos += ret;
  1449. }
  1450. #endif /* CONFIG_SAE */
  1451. ret = os_snprintf(pos, end - pos, "wpa_state=%s\n",
  1452. wpa_supplicant_state_txt(wpa_s->wpa_state));
  1453. if (ret < 0 || ret >= end - pos)
  1454. return pos - buf;
  1455. pos += ret;
  1456. if (wpa_s->l2 &&
  1457. l2_packet_get_ip_addr(wpa_s->l2, tmp, sizeof(tmp)) >= 0) {
  1458. ret = os_snprintf(pos, end - pos, "ip_address=%s\n", tmp);
  1459. if (ret < 0 || ret >= end - pos)
  1460. return pos - buf;
  1461. pos += ret;
  1462. }
  1463. #ifdef CONFIG_P2P
  1464. if (wpa_s->global->p2p) {
  1465. ret = os_snprintf(pos, end - pos, "p2p_device_address=" MACSTR
  1466. "\n", MAC2STR(wpa_s->global->p2p_dev_addr));
  1467. if (ret < 0 || ret >= end - pos)
  1468. return pos - buf;
  1469. pos += ret;
  1470. }
  1471. #endif /* CONFIG_P2P */
  1472. ret = os_snprintf(pos, end - pos, "address=" MACSTR "\n",
  1473. MAC2STR(wpa_s->own_addr));
  1474. if (ret < 0 || ret >= end - pos)
  1475. return pos - buf;
  1476. pos += ret;
  1477. #ifdef CONFIG_HS20
  1478. if (wpa_s->current_bss &&
  1479. (hs20 = wpa_bss_get_vendor_ie(wpa_s->current_bss,
  1480. HS20_IE_VENDOR_TYPE)) &&
  1481. wpa_s->wpa_proto == WPA_PROTO_RSN &&
  1482. wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt)) {
  1483. int release = 1;
  1484. if (hs20[1] >= 5) {
  1485. u8 rel_num = (hs20[6] & 0xf0) >> 4;
  1486. release = rel_num + 1;
  1487. }
  1488. ret = os_snprintf(pos, end - pos, "hs20=%d\n", release);
  1489. if (ret < 0 || ret >= end - pos)
  1490. return pos - buf;
  1491. pos += ret;
  1492. }
  1493. if (wpa_s->current_ssid) {
  1494. struct wpa_cred *cred;
  1495. char *type;
  1496. for (cred = wpa_s->conf->cred; cred; cred = cred->next) {
  1497. size_t i;
  1498. if (wpa_s->current_ssid->parent_cred != cred)
  1499. continue;
  1500. if (cred->provisioning_sp) {
  1501. ret = os_snprintf(pos, end - pos,
  1502. "provisioning_sp=%s\n",
  1503. cred->provisioning_sp);
  1504. if (ret < 0 || ret >= end - pos)
  1505. return pos - buf;
  1506. pos += ret;
  1507. }
  1508. if (!cred->domain)
  1509. goto no_domain;
  1510. i = 0;
  1511. if (wpa_s->current_bss && wpa_s->current_bss->anqp) {
  1512. struct wpabuf *names =
  1513. wpa_s->current_bss->anqp->domain_name;
  1514. for (i = 0; names && i < cred->num_domain; i++)
  1515. {
  1516. if (domain_name_list_contains(
  1517. names, cred->domain[i], 1))
  1518. break;
  1519. }
  1520. if (i == cred->num_domain)
  1521. i = 0; /* show first entry by default */
  1522. }
  1523. ret = os_snprintf(pos, end - pos, "home_sp=%s\n",
  1524. cred->domain[i]);
  1525. if (ret < 0 || ret >= end - pos)
  1526. return pos - buf;
  1527. pos += ret;
  1528. no_domain:
  1529. if (wpa_s->current_bss == NULL ||
  1530. wpa_s->current_bss->anqp == NULL)
  1531. res = -1;
  1532. else
  1533. res = interworking_home_sp_cred(
  1534. wpa_s, cred,
  1535. wpa_s->current_bss->anqp->domain_name);
  1536. if (res > 0)
  1537. type = "home";
  1538. else if (res == 0)
  1539. type = "roaming";
  1540. else
  1541. type = "unknown";
  1542. ret = os_snprintf(pos, end - pos, "sp_type=%s\n", type);
  1543. if (ret < 0 || ret >= end - pos)
  1544. return pos - buf;
  1545. pos += ret;
  1546. break;
  1547. }
  1548. }
  1549. #endif /* CONFIG_HS20 */
  1550. if (wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
  1551. wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) {
  1552. res = eapol_sm_get_status(wpa_s->eapol, pos, end - pos,
  1553. verbose);
  1554. if (res >= 0)
  1555. pos += res;
  1556. }
  1557. res = rsn_preauth_get_status(wpa_s->wpa, pos, end - pos, verbose);
  1558. if (res >= 0)
  1559. pos += res;
  1560. #ifdef CONFIG_WPS
  1561. {
  1562. char uuid_str[100];
  1563. uuid_bin2str(wpa_s->wps->uuid, uuid_str, sizeof(uuid_str));
  1564. ret = os_snprintf(pos, end - pos, "uuid=%s\n", uuid_str);
  1565. if (ret < 0 || ret >= end - pos)
  1566. return pos - buf;
  1567. pos += ret;
  1568. }
  1569. #endif /* CONFIG_WPS */
  1570. #ifdef ANDROID
  1571. /*
  1572. * Allow using the STATUS command with default behavior, say for debug,
  1573. * i.e., don't generate a "fake" CONNECTION and SUPPLICANT_STATE_CHANGE
  1574. * events with STATUS-NO_EVENTS.
  1575. */
  1576. if (os_strcmp(params, "-NO_EVENTS")) {
  1577. wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_STATE_CHANGE
  1578. "id=%d state=%d BSSID=" MACSTR " SSID=%s",
  1579. wpa_s->current_ssid ? wpa_s->current_ssid->id : -1,
  1580. wpa_s->wpa_state,
  1581. MAC2STR(wpa_s->bssid),
  1582. wpa_s->current_ssid && wpa_s->current_ssid->ssid ?
  1583. wpa_ssid_txt(wpa_s->current_ssid->ssid,
  1584. wpa_s->current_ssid->ssid_len) : "");
  1585. if (wpa_s->wpa_state == WPA_COMPLETED) {
  1586. struct wpa_ssid *ssid = wpa_s->current_ssid;
  1587. wpa_msg_ctrl(wpa_s, MSG_INFO, WPA_EVENT_CONNECTED
  1588. "- connection to " MACSTR
  1589. " completed %s [id=%d id_str=%s]",
  1590. MAC2STR(wpa_s->bssid), "(auth)",
  1591. ssid ? ssid->id : -1,
  1592. ssid && ssid->id_str ? ssid->id_str : "");
  1593. }
  1594. }
  1595. #endif /* ANDROID */
  1596. return pos - buf;
  1597. }
  1598. static int wpa_supplicant_ctrl_iface_bssid(struct wpa_supplicant *wpa_s,
  1599. char *cmd)
  1600. {
  1601. char *pos;
  1602. int id;
  1603. struct wpa_ssid *ssid;
  1604. u8 bssid[ETH_ALEN];
  1605. /* cmd: "<network id> <BSSID>" */
  1606. pos = os_strchr(cmd, ' ');
  1607. if (pos == NULL)
  1608. return -1;
  1609. *pos++ = '\0';
  1610. id = atoi(cmd);
  1611. wpa_printf(MSG_DEBUG, "CTRL_IFACE: id=%d bssid='%s'", id, pos);
  1612. if (hwaddr_aton(pos, bssid)) {
  1613. wpa_printf(MSG_DEBUG ,"CTRL_IFACE: invalid BSSID '%s'", pos);
  1614. return -1;
  1615. }
  1616. ssid = wpa_config_get_network(wpa_s->conf, id);
  1617. if (ssid == NULL) {
  1618. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
  1619. "to update", id);
  1620. return -1;
  1621. }
  1622. os_memcpy(ssid->bssid, bssid, ETH_ALEN);
  1623. ssid->bssid_set = !is_zero_ether_addr(bssid);
  1624. return 0;
  1625. }
  1626. static int wpa_supplicant_ctrl_iface_blacklist(struct wpa_supplicant *wpa_s,
  1627. char *cmd, char *buf,
  1628. size_t buflen)
  1629. {
  1630. u8 bssid[ETH_ALEN];
  1631. struct wpa_blacklist *e;
  1632. char *pos, *end;
  1633. int ret;
  1634. /* cmd: "BLACKLIST [<BSSID>]" */
  1635. if (*cmd == '\0') {
  1636. pos = buf;
  1637. end = buf + buflen;
  1638. e = wpa_s->blacklist;
  1639. while (e) {
  1640. ret = os_snprintf(pos, end - pos, MACSTR "\n",
  1641. MAC2STR(e->bssid));
  1642. if (ret < 0 || ret >= end - pos)
  1643. return pos - buf;
  1644. pos += ret;
  1645. e = e->next;
  1646. }
  1647. return pos - buf;
  1648. }
  1649. cmd++;
  1650. if (os_strncmp(cmd, "clear", 5) == 0) {
  1651. wpa_blacklist_clear(wpa_s);
  1652. os_memcpy(buf, "OK\n", 3);
  1653. return 3;
  1654. }
  1655. wpa_printf(MSG_DEBUG, "CTRL_IFACE: BLACKLIST bssid='%s'", cmd);
  1656. if (hwaddr_aton(cmd, bssid)) {
  1657. wpa_printf(MSG_DEBUG, "CTRL_IFACE: invalid BSSID '%s'", cmd);
  1658. return -1;
  1659. }
  1660. /*
  1661. * Add the BSSID twice, so its count will be 2, causing it to be
  1662. * skipped when processing scan results.
  1663. */
  1664. ret = wpa_blacklist_add(wpa_s, bssid);
  1665. if (ret < 0)
  1666. return -1;
  1667. ret = wpa_blacklist_add(wpa_s, bssid);
  1668. if (ret < 0)
  1669. return -1;
  1670. os_memcpy(buf, "OK\n", 3);
  1671. return 3;
  1672. }
  1673. static const char * debug_level_str(int level)
  1674. {
  1675. switch (level) {
  1676. case MSG_EXCESSIVE:
  1677. return "EXCESSIVE";
  1678. case MSG_MSGDUMP:
  1679. return "MSGDUMP";
  1680. case MSG_DEBUG:
  1681. return "DEBUG";
  1682. case MSG_INFO:
  1683. return "INFO";
  1684. case MSG_WARNING:
  1685. return "WARNING";
  1686. case MSG_ERROR:
  1687. return "ERROR";
  1688. default:
  1689. return "?";
  1690. }
  1691. }
  1692. static int str_to_debug_level(const char *s)
  1693. {
  1694. if (os_strcasecmp(s, "EXCESSIVE") == 0)
  1695. return MSG_EXCESSIVE;
  1696. if (os_strcasecmp(s, "MSGDUMP") == 0)
  1697. return MSG_MSGDUMP;
  1698. if (os_strcasecmp(s, "DEBUG") == 0)
  1699. return MSG_DEBUG;
  1700. if (os_strcasecmp(s, "INFO") == 0)
  1701. return MSG_INFO;
  1702. if (os_strcasecmp(s, "WARNING") == 0)
  1703. return MSG_WARNING;
  1704. if (os_strcasecmp(s, "ERROR") == 0)
  1705. return MSG_ERROR;
  1706. return -1;
  1707. }
  1708. static int wpa_supplicant_ctrl_iface_log_level(struct wpa_supplicant *wpa_s,
  1709. char *cmd, char *buf,
  1710. size_t buflen)
  1711. {
  1712. char *pos, *end, *stamp;
  1713. int ret;
  1714. if (cmd == NULL) {
  1715. return -1;
  1716. }
  1717. /* cmd: "LOG_LEVEL [<level>]" */
  1718. if (*cmd == '\0') {
  1719. pos = buf;
  1720. end = buf + buflen;
  1721. ret = os_snprintf(pos, end - pos, "Current level: %s\n"
  1722. "Timestamp: %d\n",
  1723. debug_level_str(wpa_debug_level),
  1724. wpa_debug_timestamp);
  1725. if (ret < 0 || ret >= end - pos)
  1726. ret = 0;
  1727. return ret;
  1728. }
  1729. while (*cmd == ' ')
  1730. cmd++;
  1731. stamp = os_strchr(cmd, ' ');
  1732. if (stamp) {
  1733. *stamp++ = '\0';
  1734. while (*stamp == ' ') {
  1735. stamp++;
  1736. }
  1737. }
  1738. if (cmd && os_strlen(cmd)) {
  1739. int level = str_to_debug_level(cmd);
  1740. if (level < 0)
  1741. return -1;
  1742. wpa_debug_level = level;
  1743. }
  1744. if (stamp && os_strlen(stamp))
  1745. wpa_debug_timestamp = atoi(stamp);
  1746. os_memcpy(buf, "OK\n", 3);
  1747. return 3;
  1748. }
  1749. static int wpa_supplicant_ctrl_iface_list_networks(
  1750. struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
  1751. {
  1752. char *pos, *end;
  1753. struct wpa_ssid *ssid;
  1754. int ret;
  1755. pos = buf;
  1756. end = buf + buflen;
  1757. ret = os_snprintf(pos, end - pos,
  1758. "network id / ssid / bssid / flags\n");
  1759. if (ret < 0 || ret >= end - pos)
  1760. return pos - buf;
  1761. pos += ret;
  1762. ssid = wpa_s->conf->ssid;
  1763. while (ssid) {
  1764. ret = os_snprintf(pos, end - pos, "%d\t%s",
  1765. ssid->id,
  1766. wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
  1767. if (ret < 0 || ret >= end - pos)
  1768. return pos - buf;
  1769. pos += ret;
  1770. if (ssid->bssid_set) {
  1771. ret = os_snprintf(pos, end - pos, "\t" MACSTR,
  1772. MAC2STR(ssid->bssid));
  1773. } else {
  1774. ret = os_snprintf(pos, end - pos, "\tany");
  1775. }
  1776. if (ret < 0 || ret >= end - pos)
  1777. return pos - buf;
  1778. pos += ret;
  1779. ret = os_snprintf(pos, end - pos, "\t%s%s%s%s",
  1780. ssid == wpa_s->current_ssid ?
  1781. "[CURRENT]" : "",
  1782. ssid->disabled ? "[DISABLED]" : "",
  1783. ssid->disabled_until.sec ?
  1784. "[TEMP-DISABLED]" : "",
  1785. ssid->disabled == 2 ? "[P2P-PERSISTENT]" :
  1786. "");
  1787. if (ret < 0 || ret >= end - pos)
  1788. return pos - buf;
  1789. pos += ret;
  1790. ret = os_snprintf(pos, end - pos, "\n");
  1791. if (ret < 0 || ret >= end - pos)
  1792. return pos - buf;
  1793. pos += ret;
  1794. ssid = ssid->next;
  1795. }
  1796. return pos - buf;
  1797. }
  1798. static char * wpa_supplicant_cipher_txt(char *pos, char *end, int cipher)
  1799. {
  1800. int ret;
  1801. ret = os_snprintf(pos, end - pos, "-");
  1802. if (ret < 0 || ret >= end - pos)
  1803. return pos;
  1804. pos += ret;
  1805. ret = wpa_write_ciphers(pos, end, cipher, "+");
  1806. if (ret < 0)
  1807. return pos;
  1808. pos += ret;
  1809. return pos;
  1810. }
  1811. static char * wpa_supplicant_ie_txt(char *pos, char *end, const char *proto,
  1812. const u8 *ie, size_t ie_len)
  1813. {
  1814. struct wpa_ie_data data;
  1815. char *start;
  1816. int ret;
  1817. ret = os_snprintf(pos, end - pos, "[%s-", proto);
  1818. if (ret < 0 || ret >= end - pos)
  1819. return pos;
  1820. pos += ret;
  1821. if (wpa_parse_wpa_ie(ie, ie_len, &data) < 0) {
  1822. ret = os_snprintf(pos, end - pos, "?]");
  1823. if (ret < 0 || ret >= end - pos)
  1824. return pos;
  1825. pos += ret;
  1826. return pos;
  1827. }
  1828. start = pos;
  1829. if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X) {
  1830. ret = os_snprintf(pos, end - pos, "%sEAP",
  1831. pos == start ? "" : "+");
  1832. if (ret < 0 || ret >= end - pos)
  1833. return pos;
  1834. pos += ret;
  1835. }
  1836. if (data.key_mgmt & WPA_KEY_MGMT_PSK) {
  1837. ret = os_snprintf(pos, end - pos, "%sPSK",
  1838. pos == start ? "" : "+");
  1839. if (ret < 0 || ret >= end - pos)
  1840. return pos;
  1841. pos += ret;
  1842. }
  1843. if (data.key_mgmt & WPA_KEY_MGMT_WPA_NONE) {
  1844. ret = os_snprintf(pos, end - pos, "%sNone",
  1845. pos == start ? "" : "+");
  1846. if (ret < 0 || ret >= end - pos)
  1847. return pos;
  1848. pos += ret;
  1849. }
  1850. if (data.key_mgmt & WPA_KEY_MGMT_SAE) {
  1851. ret = os_snprintf(pos, end - pos, "%sSAE",
  1852. pos == start ? "" : "+");
  1853. if (ret < 0 || ret >= end - pos)
  1854. return pos;
  1855. pos += ret;
  1856. }
  1857. #ifdef CONFIG_IEEE80211R
  1858. if (data.key_mgmt & WPA_KEY_MGMT_FT_IEEE8021X) {
  1859. ret = os_snprintf(pos, end - pos, "%sFT/EAP",
  1860. pos == start ? "" : "+");
  1861. if (ret < 0 || ret >= end - pos)
  1862. return pos;
  1863. pos += ret;
  1864. }
  1865. if (data.key_mgmt & WPA_KEY_MGMT_FT_PSK) {
  1866. ret = os_snprintf(pos, end - pos, "%sFT/PSK",
  1867. pos == start ? "" : "+");
  1868. if (ret < 0 || ret >= end - pos)
  1869. return pos;
  1870. pos += ret;
  1871. }
  1872. if (data.key_mgmt & WPA_KEY_MGMT_FT_SAE) {
  1873. ret = os_snprintf(pos, end - pos, "%sFT/SAE",
  1874. pos == start ? "" : "+");
  1875. if (ret < 0 || ret >= end - pos)
  1876. return pos;
  1877. pos += ret;
  1878. }
  1879. #endif /* CONFIG_IEEE80211R */
  1880. #ifdef CONFIG_IEEE80211W
  1881. if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SHA256) {
  1882. ret = os_snprintf(pos, end - pos, "%sEAP-SHA256",
  1883. pos == start ? "" : "+");
  1884. if (ret < 0 || ret >= end - pos)
  1885. return pos;
  1886. pos += ret;
  1887. }
  1888. if (data.key_mgmt & WPA_KEY_MGMT_PSK_SHA256) {
  1889. ret = os_snprintf(pos, end - pos, "%sPSK-SHA256",
  1890. pos == start ? "" : "+");
  1891. if (ret < 0 || ret >= end - pos)
  1892. return pos;
  1893. pos += ret;
  1894. }
  1895. #endif /* CONFIG_IEEE80211W */
  1896. if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SUITE_B) {
  1897. ret = os_snprintf(pos, end - pos, "%sEAP-SUITE-B",
  1898. pos == start ? "" : "+");
  1899. if (ret < 0 || ret >= end - pos)
  1900. return pos;
  1901. pos += ret;
  1902. }
  1903. pos = wpa_supplicant_cipher_txt(pos, end, data.pairwise_cipher);
  1904. if (data.capabilities & WPA_CAPABILITY_PREAUTH) {
  1905. ret = os_snprintf(pos, end - pos, "-preauth");
  1906. if (ret < 0 || ret >= end - pos)
  1907. return pos;
  1908. pos += ret;
  1909. }
  1910. ret = os_snprintf(pos, end - pos, "]");
  1911. if (ret < 0 || ret >= end - pos)
  1912. return pos;
  1913. pos += ret;
  1914. return pos;
  1915. }
  1916. #ifdef CONFIG_WPS
  1917. static char * wpa_supplicant_wps_ie_txt_buf(struct wpa_supplicant *wpa_s,
  1918. char *pos, char *end,
  1919. struct wpabuf *wps_ie)
  1920. {
  1921. int ret;
  1922. const char *txt;
  1923. if (wps_ie == NULL)
  1924. return pos;
  1925. if (wps_is_selected_pbc_registrar(wps_ie))
  1926. txt = "[WPS-PBC]";
  1927. else if (wps_is_addr_authorized(wps_ie, wpa_s->own_addr, 0))
  1928. txt = "[WPS-AUTH]";
  1929. else if (wps_is_selected_pin_registrar(wps_ie))
  1930. txt = "[WPS-PIN]";
  1931. else
  1932. txt = "[WPS]";
  1933. ret = os_snprintf(pos, end - pos, "%s", txt);
  1934. if (ret >= 0 && ret < end - pos)
  1935. pos += ret;
  1936. wpabuf_free(wps_ie);
  1937. return pos;
  1938. }
  1939. #endif /* CONFIG_WPS */
  1940. static char * wpa_supplicant_wps_ie_txt(struct wpa_supplicant *wpa_s,
  1941. char *pos, char *end,
  1942. const struct wpa_bss *bss)
  1943. {
  1944. #ifdef CONFIG_WPS
  1945. struct wpabuf *wps_ie;
  1946. wps_ie = wpa_bss_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE);
  1947. return wpa_supplicant_wps_ie_txt_buf(wpa_s, pos, end, wps_ie);
  1948. #else /* CONFIG_WPS */
  1949. return pos;
  1950. #endif /* CONFIG_WPS */
  1951. }
  1952. /* Format one result on one text line into a buffer. */
  1953. static int wpa_supplicant_ctrl_iface_scan_result(
  1954. struct wpa_supplicant *wpa_s,
  1955. const struct wpa_bss *bss, char *buf, size_t buflen)
  1956. {
  1957. char *pos, *end;
  1958. int ret;
  1959. const u8 *ie, *ie2, *p2p, *mesh;
  1960. mesh = wpa_bss_get_ie(bss, WLAN_EID_MESH_ID);
  1961. p2p = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE);
  1962. if (!p2p)
  1963. p2p = wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE);
  1964. if (p2p && bss->ssid_len == P2P_WILDCARD_SSID_LEN &&
  1965. os_memcmp(bss->ssid, P2P_WILDCARD_SSID, P2P_WILDCARD_SSID_LEN) ==
  1966. 0)
  1967. return 0; /* Do not show P2P listen discovery results here */
  1968. pos = buf;
  1969. end = buf + buflen;
  1970. ret = os_snprintf(pos, end - pos, MACSTR "\t%d\t%d\t",
  1971. MAC2STR(bss->bssid), bss->freq, bss->level);
  1972. if (ret < 0 || ret >= end - pos)
  1973. return -1;
  1974. pos += ret;
  1975. ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
  1976. if (ie)
  1977. pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie, 2 + ie[1]);
  1978. ie2 = wpa_bss_get_ie(bss, WLAN_EID_RSN);
  1979. if (ie2) {
  1980. pos = wpa_supplicant_ie_txt(pos, end, mesh ? "RSN" : "WPA2",
  1981. ie2, 2 + ie2[1]);
  1982. }
  1983. pos = wpa_supplicant_wps_ie_txt(wpa_s, pos, end, bss);
  1984. if (!ie && !ie2 && bss->caps & IEEE80211_CAP_PRIVACY) {
  1985. ret = os_snprintf(pos, end - pos, "[WEP]");
  1986. if (ret < 0 || ret >= end - pos)
  1987. return -1;
  1988. pos += ret;
  1989. }
  1990. if (mesh) {
  1991. ret = os_snprintf(pos, end - pos, "[MESH]");
  1992. if (ret < 0 || ret >= end - pos)
  1993. return -1;
  1994. pos += ret;
  1995. }
  1996. if (bss_is_dmg(bss)) {
  1997. const char *s;
  1998. ret = os_snprintf(pos, end - pos, "[DMG]");
  1999. if (ret < 0 || ret >= end - pos)
  2000. return -1;
  2001. pos += ret;
  2002. switch (bss->caps & IEEE80211_CAP_DMG_MASK) {
  2003. case IEEE80211_CAP_DMG_IBSS:
  2004. s = "[IBSS]";
  2005. break;
  2006. case IEEE80211_CAP_DMG_AP:
  2007. s = "[ESS]";
  2008. break;
  2009. case IEEE80211_CAP_DMG_PBSS:
  2010. s = "[PBSS]";
  2011. break;
  2012. default:
  2013. s = "";
  2014. break;
  2015. }
  2016. ret = os_snprintf(pos, end - pos, "%s", s);
  2017. if (ret < 0 || ret >= end - pos)
  2018. return -1;
  2019. pos += ret;
  2020. } else {
  2021. if (bss->caps & IEEE80211_CAP_IBSS) {
  2022. ret = os_snprintf(pos, end - pos, "[IBSS]");
  2023. if (ret < 0 || ret >= end - pos)
  2024. return -1;
  2025. pos += ret;
  2026. }
  2027. if (bss->caps & IEEE80211_CAP_ESS) {
  2028. ret = os_snprintf(pos, end - pos, "[ESS]");
  2029. if (ret < 0 || ret >= end - pos)
  2030. return -1;
  2031. pos += ret;
  2032. }
  2033. }
  2034. if (p2p) {
  2035. ret = os_snprintf(pos, end - pos, "[P2P]");
  2036. if (ret < 0 || ret >= end - pos)
  2037. return -1;
  2038. pos += ret;
  2039. }
  2040. #ifdef CONFIG_HS20
  2041. if (wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE) && ie2) {
  2042. ret = os_snprintf(pos, end - pos, "[HS20]");
  2043. if (ret < 0 || ret >= end - pos)
  2044. return -1;
  2045. pos += ret;
  2046. }
  2047. #endif /* CONFIG_HS20 */
  2048. ret = os_snprintf(pos, end - pos, "\t%s",
  2049. wpa_ssid_txt(bss->ssid, bss->ssid_len));
  2050. if (ret < 0 || ret >= end - pos)
  2051. return -1;
  2052. pos += ret;
  2053. ret = os_snprintf(pos, end - pos, "\n");
  2054. if (ret < 0 || ret >= end - pos)
  2055. return -1;
  2056. pos += ret;
  2057. return pos - buf;
  2058. }
  2059. static int wpa_supplicant_ctrl_iface_scan_results(
  2060. struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
  2061. {
  2062. char *pos, *end;
  2063. struct wpa_bss *bss;
  2064. int ret;
  2065. pos = buf;
  2066. end = buf + buflen;
  2067. ret = os_snprintf(pos, end - pos, "bssid / frequency / signal level / "
  2068. "flags / ssid\n");
  2069. if (ret < 0 || ret >= end - pos)
  2070. return pos - buf;
  2071. pos += ret;
  2072. dl_list_for_each(bss, &wpa_s->bss_id, struct wpa_bss, list_id) {
  2073. ret = wpa_supplicant_ctrl_iface_scan_result(wpa_s, bss, pos,
  2074. end - pos);
  2075. if (ret < 0 || ret >= end - pos)
  2076. return pos - buf;
  2077. pos += ret;
  2078. }
  2079. return pos - buf;
  2080. }
  2081. #ifdef CONFIG_MESH
  2082. static int wpa_supplicant_ctrl_iface_mesh_group_add(
  2083. struct wpa_supplicant *wpa_s, char *cmd)
  2084. {
  2085. int id;
  2086. struct wpa_ssid *ssid;
  2087. id = atoi(cmd);
  2088. wpa_printf(MSG_DEBUG, "CTRL_IFACE: MESH_GROUP_ADD id=%d", id);
  2089. ssid = wpa_config_get_network(wpa_s->conf, id);
  2090. if (ssid == NULL) {
  2091. wpa_printf(MSG_DEBUG,
  2092. "CTRL_IFACE: Could not find network id=%d", id);
  2093. return -1;
  2094. }
  2095. if (ssid->mode != WPAS_MODE_MESH) {
  2096. wpa_printf(MSG_DEBUG,
  2097. "CTRL_IFACE: Cannot use MESH_GROUP_ADD on a non mesh network");
  2098. return -1;
  2099. }
  2100. if (ssid->key_mgmt != WPA_KEY_MGMT_NONE &&
  2101. ssid->key_mgmt != WPA_KEY_MGMT_SAE) {
  2102. wpa_printf(MSG_ERROR,
  2103. "CTRL_IFACE: key_mgmt for mesh network should be open or SAE");
  2104. return -1;
  2105. }
  2106. /*
  2107. * TODO: If necessary write our own group_add function,
  2108. * for now we can reuse select_network
  2109. */
  2110. wpa_supplicant_select_network(wpa_s, ssid);
  2111. return 0;
  2112. }
  2113. static int wpa_supplicant_ctrl_iface_mesh_group_remove(
  2114. struct wpa_supplicant *wpa_s, char *cmd)
  2115. {
  2116. if (!cmd) {
  2117. wpa_printf(MSG_ERROR,
  2118. "CTRL_IFACE: MESH_GROUP_REMOVE ifname cannot be empty");
  2119. return -1;
  2120. }
  2121. /*
  2122. * TODO: Support a multiple mesh and other iface type combinations
  2123. */
  2124. if (os_strcmp(cmd, wpa_s->ifname) != 0) {
  2125. wpa_printf(MSG_DEBUG,
  2126. "CTRL_IFACE: MESH_GROUP_REMOVE unknown interface name: %s",
  2127. cmd);
  2128. return -1;
  2129. }
  2130. wpa_printf(MSG_DEBUG, "CTRL_IFACE: MESH_GROUP_REMOVE ifname=%s", cmd);
  2131. wpa_s->reassociate = 0;
  2132. wpa_s->disconnected = 1;
  2133. wpa_supplicant_cancel_sched_scan(wpa_s);
  2134. wpa_supplicant_cancel_scan(wpa_s);
  2135. /*
  2136. * TODO: If necessary write our own group_remove function,
  2137. * for now we can reuse deauthenticate
  2138. */
  2139. wpa_supplicant_deauthenticate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
  2140. return 0;
  2141. }
  2142. #endif /* CONFIG_MESH */
  2143. static int wpa_supplicant_ctrl_iface_select_network(
  2144. struct wpa_supplicant *wpa_s, char *cmd)
  2145. {
  2146. int id;
  2147. struct wpa_ssid *ssid;
  2148. char *pos;
  2149. /* cmd: "<network id>" or "any" */
  2150. if (os_strncmp(cmd, "any", 3) == 0) {
  2151. wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK any");
  2152. ssid = NULL;
  2153. } else {
  2154. id = atoi(cmd);
  2155. wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK id=%d", id);
  2156. ssid = wpa_config_get_network(wpa_s->conf, id);
  2157. if (ssid == NULL) {
  2158. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
  2159. "network id=%d", id);
  2160. return -1;
  2161. }
  2162. if (ssid->disabled == 2) {
  2163. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
  2164. "SELECT_NETWORK with persistent P2P group");
  2165. return -1;
  2166. }
  2167. }
  2168. pos = os_strstr(cmd, " freq=");
  2169. if (pos) {
  2170. int *freqs = freq_range_to_channel_list(wpa_s, pos + 6);
  2171. if (freqs) {
  2172. wpa_s->scan_req = MANUAL_SCAN_REQ;
  2173. os_free(wpa_s->manual_scan_freqs);
  2174. wpa_s->manual_scan_freqs = freqs;
  2175. }
  2176. }
  2177. wpa_supplicant_select_network(wpa_s, ssid);
  2178. return 0;
  2179. }
  2180. static int wpa_supplicant_ctrl_iface_enable_network(
  2181. struct wpa_supplicant *wpa_s, char *cmd)
  2182. {
  2183. int id;
  2184. struct wpa_ssid *ssid;
  2185. /* cmd: "<network id>" or "all" */
  2186. if (os_strcmp(cmd, "all") == 0) {
  2187. wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK all");
  2188. ssid = NULL;
  2189. } else {
  2190. id = atoi(cmd);
  2191. wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK id=%d", id);
  2192. ssid = wpa_config_get_network(wpa_s->conf, id);
  2193. if (ssid == NULL) {
  2194. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
  2195. "network id=%d", id);
  2196. return -1;
  2197. }
  2198. if (ssid->disabled == 2) {
  2199. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
  2200. "ENABLE_NETWORK with persistent P2P group");
  2201. return -1;
  2202. }
  2203. if (os_strstr(cmd, " no-connect")) {
  2204. ssid->disabled = 0;
  2205. return 0;
  2206. }
  2207. }
  2208. wpa_supplicant_enable_network(wpa_s, ssid);
  2209. return 0;
  2210. }
  2211. static int wpa_supplicant_ctrl_iface_disable_network(
  2212. struct wpa_supplicant *wpa_s, char *cmd)
  2213. {
  2214. int id;
  2215. struct wpa_ssid *ssid;
  2216. /* cmd: "<network id>" or "all" */
  2217. if (os_strcmp(cmd, "all") == 0) {
  2218. wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK all");
  2219. ssid = NULL;
  2220. } else {
  2221. id = atoi(cmd);
  2222. wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK id=%d", id);
  2223. ssid = wpa_config_get_network(wpa_s->conf, id);
  2224. if (ssid == NULL) {
  2225. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
  2226. "network id=%d", id);
  2227. return -1;
  2228. }
  2229. if (ssid->disabled == 2) {
  2230. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
  2231. "DISABLE_NETWORK with persistent P2P "
  2232. "group");
  2233. return -1;
  2234. }
  2235. }
  2236. wpa_supplicant_disable_network(wpa_s, ssid);
  2237. return 0;
  2238. }
  2239. static int wpa_supplicant_ctrl_iface_add_network(
  2240. struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
  2241. {
  2242. struct wpa_ssid *ssid;
  2243. int ret;
  2244. wpa_printf(MSG_DEBUG, "CTRL_IFACE: ADD_NETWORK");
  2245. ssid = wpa_config_add_network(wpa_s->conf);
  2246. if (ssid == NULL)
  2247. return -1;
  2248. wpas_notify_network_added(wpa_s, ssid);
  2249. ssid->disabled = 1;
  2250. wpa_config_set_network_defaults(ssid);
  2251. ret = os_snprintf(buf, buflen, "%d\n", ssid->id);
  2252. if (ret < 0 || (size_t) ret >= buflen)
  2253. return -1;
  2254. return ret;
  2255. }
  2256. static int wpa_supplicant_ctrl_iface_remove_network(
  2257. struct wpa_supplicant *wpa_s, char *cmd)
  2258. {
  2259. int id;
  2260. struct wpa_ssid *ssid;
  2261. int was_disabled;
  2262. /* cmd: "<network id>" or "all" */
  2263. if (os_strcmp(cmd, "all") == 0) {
  2264. wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK all");
  2265. if (wpa_s->sched_scanning)
  2266. wpa_supplicant_cancel_sched_scan(wpa_s);
  2267. eapol_sm_invalidate_cached_session(wpa_s->eapol);
  2268. if (wpa_s->current_ssid) {
  2269. #ifdef CONFIG_SME
  2270. wpa_s->sme.prev_bssid_set = 0;
  2271. #endif /* CONFIG_SME */
  2272. wpa_sm_set_config(wpa_s->wpa, NULL);
  2273. eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
  2274. wpa_supplicant_deauthenticate(
  2275. wpa_s, WLAN_REASON_DEAUTH_LEAVING);
  2276. }
  2277. ssid = wpa_s->conf->ssid;
  2278. while (ssid) {
  2279. struct wpa_ssid *remove_ssid = ssid;
  2280. id = ssid->id;
  2281. ssid = ssid->next;
  2282. if (wpa_s->last_ssid == remove_ssid)
  2283. wpa_s->last_ssid = NULL;
  2284. wpas_notify_network_removed(wpa_s, remove_ssid);
  2285. wpa_config_remove_network(wpa_s->conf, id);
  2286. }
  2287. return 0;
  2288. }
  2289. id = atoi(cmd);
  2290. wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK id=%d", id);
  2291. ssid = wpa_config_get_network(wpa_s->conf, id);
  2292. if (ssid)
  2293. wpas_notify_network_removed(wpa_s, ssid);
  2294. if (ssid == NULL) {
  2295. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
  2296. "id=%d", id);
  2297. return -1;
  2298. }
  2299. if (wpa_s->last_ssid == ssid)
  2300. wpa_s->last_ssid = NULL;
  2301. if (ssid == wpa_s->current_ssid || wpa_s->current_ssid == NULL) {
  2302. #ifdef CONFIG_SME
  2303. wpa_s->sme.prev_bssid_set = 0;
  2304. #endif /* CONFIG_SME */
  2305. /*
  2306. * Invalidate the EAP session cache if the current or
  2307. * previously used network is removed.
  2308. */
  2309. eapol_sm_invalidate_cached_session(wpa_s->eapol);
  2310. }
  2311. if (ssid == wpa_s->current_ssid) {
  2312. wpa_sm_set_config(wpa_s->wpa, NULL);
  2313. eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
  2314. wpa_supplicant_deauthenticate(wpa_s,
  2315. WLAN_REASON_DEAUTH_LEAVING);
  2316. }
  2317. was_disabled = ssid->disabled;
  2318. if (wpa_config_remove_network(wpa_s->conf, id) < 0) {
  2319. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Not able to remove the "
  2320. "network id=%d", id);
  2321. return -1;
  2322. }
  2323. if (!was_disabled && wpa_s->sched_scanning) {
  2324. wpa_printf(MSG_DEBUG, "Stop ongoing sched_scan to remove "
  2325. "network from filters");
  2326. wpa_supplicant_cancel_sched_scan(wpa_s);
  2327. wpa_supplicant_req_scan(wpa_s, 0, 0);
  2328. }
  2329. return 0;
  2330. }
  2331. static int wpa_supplicant_ctrl_iface_update_network(
  2332. struct wpa_supplicant *wpa_s, struct wpa_ssid *ssid,
  2333. char *name, char *value)
  2334. {
  2335. if (wpa_config_set(ssid, name, value, 0) < 0) {
  2336. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set network "
  2337. "variable '%s'", name);
  2338. return -1;
  2339. }
  2340. if (os_strcmp(name, "bssid") != 0 &&
  2341. os_strcmp(name, "priority") != 0)
  2342. wpa_sm_pmksa_cache_flush(wpa_s->wpa, ssid);
  2343. if (wpa_s->current_ssid == ssid || wpa_s->current_ssid == NULL) {
  2344. /*
  2345. * Invalidate the EAP session cache if anything in the current
  2346. * or previously used configuration changes.
  2347. */
  2348. eapol_sm_invalidate_cached_session(wpa_s->eapol);
  2349. }
  2350. if ((os_strcmp(name, "psk") == 0 &&
  2351. value[0] == '"' && ssid->ssid_len) ||
  2352. (os_strcmp(name, "ssid") == 0 && ssid->passphrase))
  2353. wpa_config_update_psk(ssid);
  2354. else if (os_strcmp(name, "priority") == 0)
  2355. wpa_config_update_prio_list(wpa_s->conf);
  2356. else if (os_strcmp(name, "no_auto_peer") == 0)
  2357. ssid->no_auto_peer = atoi(value);
  2358. return 0;
  2359. }
  2360. static int wpa_supplicant_ctrl_iface_set_network(
  2361. struct wpa_supplicant *wpa_s, char *cmd)
  2362. {
  2363. int id, ret, prev_bssid_set;
  2364. struct wpa_ssid *ssid;
  2365. char *name, *value;
  2366. u8 prev_bssid[ETH_ALEN];
  2367. /* cmd: "<network id> <variable name> <value>" */
  2368. name = os_strchr(cmd, ' ');
  2369. if (name == NULL)
  2370. return -1;
  2371. *name++ = '\0';
  2372. value = os_strchr(name, ' ');
  2373. if (value == NULL)
  2374. return -1;
  2375. *value++ = '\0';
  2376. id = atoi(cmd);
  2377. wpa_printf(MSG_DEBUG, "CTRL_IFACE: SET_NETWORK id=%d name='%s'",
  2378. id, name);
  2379. wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
  2380. (u8 *) value, os_strlen(value));
  2381. ssid = wpa_config_get_network(wpa_s->conf, id);
  2382. if (ssid == NULL) {
  2383. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
  2384. "id=%d", id);
  2385. return -1;
  2386. }
  2387. prev_bssid_set = ssid->bssid_set;
  2388. os_memcpy(prev_bssid, ssid->bssid, ETH_ALEN);
  2389. ret = wpa_supplicant_ctrl_iface_update_network(wpa_s, ssid, name,
  2390. value);
  2391. if (ret == 0 &&
  2392. (ssid->bssid_set != prev_bssid_set ||
  2393. os_memcmp(ssid->bssid, prev_bssid, ETH_ALEN) != 0))
  2394. wpas_notify_network_bssid_set_changed(wpa_s, ssid);
  2395. return ret;
  2396. }
  2397. static int wpa_supplicant_ctrl_iface_get_network(
  2398. struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
  2399. {
  2400. int id;
  2401. size_t res;
  2402. struct wpa_ssid *ssid;
  2403. char *name, *value;
  2404. /* cmd: "<network id> <variable name>" */
  2405. name = os_strchr(cmd, ' ');
  2406. if (name == NULL || buflen == 0)
  2407. return -1;
  2408. *name++ = '\0';
  2409. id = atoi(cmd);
  2410. wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_NETWORK id=%d name='%s'",
  2411. id, name);
  2412. ssid = wpa_config_get_network(wpa_s->conf, id);
  2413. if (ssid == NULL) {
  2414. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
  2415. "id=%d", id);
  2416. return -1;
  2417. }
  2418. value = wpa_config_get_no_key(ssid, name);
  2419. if (value == NULL) {
  2420. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to get network "
  2421. "variable '%s'", name);
  2422. return -1;
  2423. }
  2424. res = os_strlcpy(buf, value, buflen);
  2425. if (res >= buflen) {
  2426. os_free(value);
  2427. return -1;
  2428. }
  2429. os_free(value);
  2430. return res;
  2431. }
  2432. static int wpa_supplicant_ctrl_iface_dup_network(
  2433. struct wpa_supplicant *wpa_s, char *cmd)
  2434. {
  2435. struct wpa_ssid *ssid_s, *ssid_d;
  2436. char *name, *id, *value;
  2437. int id_s, id_d, ret;
  2438. /* cmd: "<src network id> <dst network id> <variable name>" */
  2439. id = os_strchr(cmd, ' ');
  2440. if (id == NULL)
  2441. return -1;
  2442. *id++ = '\0';
  2443. name = os_strchr(id, ' ');
  2444. if (name == NULL)
  2445. return -1;
  2446. *name++ = '\0';
  2447. id_s = atoi(cmd);
  2448. id_d = atoi(id);
  2449. wpa_printf(MSG_DEBUG, "CTRL_IFACE: DUP_NETWORK id=%d -> %d name='%s'",
  2450. id_s, id_d, name);
  2451. ssid_s = wpa_config_get_network(wpa_s->conf, id_s);
  2452. if (ssid_s == NULL) {
  2453. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
  2454. "network id=%d", id_s);
  2455. return -1;
  2456. }
  2457. ssid_d = wpa_config_get_network(wpa_s->conf, id_d);
  2458. if (ssid_d == NULL) {
  2459. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
  2460. "network id=%d", id_s);
  2461. return -1;
  2462. }
  2463. value = wpa_config_get(ssid_s, name);
  2464. if (value == NULL) {
  2465. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to get network "
  2466. "variable '%s'", name);
  2467. return -1;
  2468. }
  2469. ret = wpa_supplicant_ctrl_iface_update_network(wpa_s, ssid_d, name,
  2470. value);
  2471. os_free(value);
  2472. return ret;
  2473. }
  2474. static int wpa_supplicant_ctrl_iface_list_creds(struct wpa_supplicant *wpa_s,
  2475. char *buf, size_t buflen)
  2476. {
  2477. char *pos, *end;
  2478. struct wpa_cred *cred;
  2479. int ret;
  2480. pos = buf;
  2481. end = buf + buflen;
  2482. ret = os_snprintf(pos, end - pos,
  2483. "cred id / realm / username / domain / imsi\n");
  2484. if (ret < 0 || ret >= end - pos)
  2485. return pos - buf;
  2486. pos += ret;
  2487. cred = wpa_s->conf->cred;
  2488. while (cred) {
  2489. ret = os_snprintf(pos, end - pos, "%d\t%s\t%s\t%s\t%s\n",
  2490. cred->id, cred->realm ? cred->realm : "",
  2491. cred->username ? cred->username : "",
  2492. cred->domain ? cred->domain[0] : "",
  2493. cred->imsi ? cred->imsi : "");
  2494. if (ret < 0 || ret >= end - pos)
  2495. return pos - buf;
  2496. pos += ret;
  2497. cred = cred->next;
  2498. }
  2499. return pos - buf;
  2500. }
  2501. static int wpa_supplicant_ctrl_iface_add_cred(struct wpa_supplicant *wpa_s,
  2502. char *buf, size_t buflen)
  2503. {
  2504. struct wpa_cred *cred;
  2505. int ret;
  2506. wpa_printf(MSG_DEBUG, "CTRL_IFACE: ADD_CRED");
  2507. cred = wpa_config_add_cred(wpa_s->conf);
  2508. if (cred == NULL)
  2509. return -1;
  2510. wpa_msg(wpa_s, MSG_INFO, CRED_ADDED "%d", cred->id);
  2511. ret = os_snprintf(buf, buflen, "%d\n", cred->id);
  2512. if (ret < 0 || (size_t) ret >= buflen)
  2513. return -1;
  2514. return ret;
  2515. }
  2516. static int wpas_ctrl_remove_cred(struct wpa_supplicant *wpa_s,
  2517. struct wpa_cred *cred)
  2518. {
  2519. struct wpa_ssid *ssid;
  2520. char str[20];
  2521. int id;
  2522. if (cred == NULL) {
  2523. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred");
  2524. return -1;
  2525. }
  2526. id = cred->id;
  2527. if (wpa_config_remove_cred(wpa_s->conf, id) < 0) {
  2528. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred");
  2529. return -1;
  2530. }
  2531. wpa_msg(wpa_s, MSG_INFO, CRED_REMOVED "%d", id);
  2532. /* Remove any network entry created based on the removed credential */
  2533. ssid = wpa_s->conf->ssid;
  2534. while (ssid) {
  2535. if (ssid->parent_cred == cred) {
  2536. wpa_printf(MSG_DEBUG, "Remove network id %d since it "
  2537. "used the removed credential", ssid->id);
  2538. os_snprintf(str, sizeof(str), "%d", ssid->id);
  2539. ssid = ssid->next;
  2540. wpa_supplicant_ctrl_iface_remove_network(wpa_s, str);
  2541. } else
  2542. ssid = ssid->next;
  2543. }
  2544. return 0;
  2545. }
  2546. static int wpa_supplicant_ctrl_iface_remove_cred(struct wpa_supplicant *wpa_s,
  2547. char *cmd)
  2548. {
  2549. int id;
  2550. struct wpa_cred *cred, *prev;
  2551. /* cmd: "<cred id>", "all", "sp_fqdn=<FQDN>", or
  2552. * "provisioning_sp=<FQDN> */
  2553. if (os_strcmp(cmd, "all") == 0) {
  2554. wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED all");
  2555. cred = wpa_s->conf->cred;
  2556. while (cred) {
  2557. prev = cred;
  2558. cred = cred->next;
  2559. wpas_ctrl_remove_cred(wpa_s, prev);
  2560. }
  2561. return 0;
  2562. }
  2563. if (os_strncmp(cmd, "sp_fqdn=", 8) == 0) {
  2564. wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED SP FQDN '%s'",
  2565. cmd + 8);
  2566. cred = wpa_s->conf->cred;
  2567. while (cred) {
  2568. prev = cred;
  2569. cred = cred->next;
  2570. if (prev->domain) {
  2571. size_t i;
  2572. for (i = 0; i < prev->num_domain; i++) {
  2573. if (os_strcmp(prev->domain[i], cmd + 8)
  2574. != 0)
  2575. continue;
  2576. wpas_ctrl_remove_cred(wpa_s, prev);
  2577. break;
  2578. }
  2579. }
  2580. }
  2581. return 0;
  2582. }
  2583. if (os_strncmp(cmd, "provisioning_sp=", 16) == 0) {
  2584. wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED provisioning SP FQDN '%s'",
  2585. cmd + 16);
  2586. cred = wpa_s->conf->cred;
  2587. while (cred) {
  2588. prev = cred;
  2589. cred = cred->next;
  2590. if (prev->provisioning_sp &&
  2591. os_strcmp(prev->provisioning_sp, cmd + 16) == 0)
  2592. wpas_ctrl_remove_cred(wpa_s, prev);
  2593. }
  2594. return 0;
  2595. }
  2596. id = atoi(cmd);
  2597. wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED id=%d", id);
  2598. cred = wpa_config_get_cred(wpa_s->conf, id);
  2599. return wpas_ctrl_remove_cred(wpa_s, cred);
  2600. }
  2601. static int wpa_supplicant_ctrl_iface_set_cred(struct wpa_supplicant *wpa_s,
  2602. char *cmd)
  2603. {
  2604. int id;
  2605. struct wpa_cred *cred;
  2606. char *name, *value;
  2607. /* cmd: "<cred id> <variable name> <value>" */
  2608. name = os_strchr(cmd, ' ');
  2609. if (name == NULL)
  2610. return -1;
  2611. *name++ = '\0';
  2612. value = os_strchr(name, ' ');
  2613. if (value == NULL)
  2614. return -1;
  2615. *value++ = '\0';
  2616. id = atoi(cmd);
  2617. wpa_printf(MSG_DEBUG, "CTRL_IFACE: SET_CRED id=%d name='%s'",
  2618. id, name);
  2619. wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
  2620. (u8 *) value, os_strlen(value));
  2621. cred = wpa_config_get_cred(wpa_s->conf, id);
  2622. if (cred == NULL) {
  2623. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred id=%d",
  2624. id);
  2625. return -1;
  2626. }
  2627. if (wpa_config_set_cred(cred, name, value, 0) < 0) {
  2628. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set cred "
  2629. "variable '%s'", name);
  2630. return -1;
  2631. }
  2632. wpa_msg(wpa_s, MSG_INFO, CRED_MODIFIED "%d %s", cred->id, name);
  2633. return 0;
  2634. }
  2635. static int wpa_supplicant_ctrl_iface_get_cred(struct wpa_supplicant *wpa_s,
  2636. char *cmd, char *buf,
  2637. size_t buflen)
  2638. {
  2639. int id;
  2640. size_t res;
  2641. struct wpa_cred *cred;
  2642. char *name, *value;
  2643. /* cmd: "<cred id> <variable name>" */
  2644. name = os_strchr(cmd, ' ');
  2645. if (name == NULL)
  2646. return -1;
  2647. *name++ = '\0';
  2648. id = atoi(cmd);
  2649. wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_CRED id=%d name='%s'",
  2650. id, name);
  2651. cred = wpa_config_get_cred(wpa_s->conf, id);
  2652. if (cred == NULL) {
  2653. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred id=%d",
  2654. id);
  2655. return -1;
  2656. }
  2657. value = wpa_config_get_cred_no_key(cred, name);
  2658. if (value == NULL) {
  2659. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to get cred variable '%s'",
  2660. name);
  2661. return -1;
  2662. }
  2663. res = os_strlcpy(buf, value, buflen);
  2664. if (res >= buflen) {
  2665. os_free(value);
  2666. return -1;
  2667. }
  2668. os_free(value);
  2669. return res;
  2670. }
  2671. #ifndef CONFIG_NO_CONFIG_WRITE
  2672. static int wpa_supplicant_ctrl_iface_save_config(struct wpa_supplicant *wpa_s)
  2673. {
  2674. int ret;
  2675. if (!wpa_s->conf->update_config) {
  2676. wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Not allowed "
  2677. "to update configuration (update_config=0)");
  2678. return -1;
  2679. }
  2680. ret = wpa_config_write(wpa_s->confname, wpa_s->conf);
  2681. if (ret) {
  2682. wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Failed to "
  2683. "update configuration");
  2684. } else {
  2685. wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Configuration"
  2686. " updated");
  2687. }
  2688. return ret;
  2689. }
  2690. #endif /* CONFIG_NO_CONFIG_WRITE */
  2691. struct cipher_info {
  2692. unsigned int capa;
  2693. const char *name;
  2694. int group_only;
  2695. };
  2696. static const struct cipher_info ciphers[] = {
  2697. { WPA_DRIVER_CAPA_ENC_CCMP_256, "CCMP-256", 0 },
  2698. { WPA_DRIVER_CAPA_ENC_GCMP_256, "GCMP-256", 0 },
  2699. { WPA_DRIVER_CAPA_ENC_CCMP, "CCMP", 0 },
  2700. { WPA_DRIVER_CAPA_ENC_GCMP, "GCMP", 0 },
  2701. { WPA_DRIVER_CAPA_ENC_TKIP, "TKIP", 0 },
  2702. { WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE, "NONE", 0 },
  2703. { WPA_DRIVER_CAPA_ENC_WEP104, "WEP104", 1 },
  2704. { WPA_DRIVER_CAPA_ENC_WEP40, "WEP40", 1 }
  2705. };
  2706. static int ctrl_iface_get_capability_pairwise(int res, char *strict,
  2707. struct wpa_driver_capa *capa,
  2708. char *buf, size_t buflen)
  2709. {
  2710. int ret;
  2711. char *pos, *end;
  2712. size_t len;
  2713. unsigned int i;
  2714. pos = buf;
  2715. end = pos + buflen;
  2716. if (res < 0) {
  2717. if (strict)
  2718. return 0;
  2719. len = os_strlcpy(buf, "CCMP TKIP NONE", buflen);
  2720. if (len >= buflen)
  2721. return -1;
  2722. return len;
  2723. }
  2724. for (i = 0; i < ARRAY_SIZE(ciphers); i++) {
  2725. if (!ciphers[i].group_only && capa->enc & ciphers[i].capa) {
  2726. ret = os_snprintf(pos, end - pos, "%s%s",
  2727. pos == buf ? "" : " ",
  2728. ciphers[i].name);
  2729. if (ret < 0 || ret >= end - pos)
  2730. return pos - buf;
  2731. pos += ret;
  2732. }
  2733. }
  2734. return pos - buf;
  2735. }
  2736. static int ctrl_iface_get_capability_group(int res, char *strict,
  2737. struct wpa_driver_capa *capa,
  2738. char *buf, size_t buflen)
  2739. {
  2740. int ret;
  2741. char *pos, *end;
  2742. size_t len;
  2743. unsigned int i;
  2744. pos = buf;
  2745. end = pos + buflen;
  2746. if (res < 0) {
  2747. if (strict)
  2748. return 0;
  2749. len = os_strlcpy(buf, "CCMP TKIP WEP104 WEP40", buflen);
  2750. if (len >= buflen)
  2751. return -1;
  2752. return len;
  2753. }
  2754. for (i = 0; i < ARRAY_SIZE(ciphers); i++) {
  2755. if (capa->enc & ciphers[i].capa) {
  2756. ret = os_snprintf(pos, end - pos, "%s%s",
  2757. pos == buf ? "" : " ",
  2758. ciphers[i].name);
  2759. if (ret < 0 || ret >= end - pos)
  2760. return pos - buf;
  2761. pos += ret;
  2762. }
  2763. }
  2764. return pos - buf;
  2765. }
  2766. static int ctrl_iface_get_capability_key_mgmt(int res, char *strict,
  2767. struct wpa_driver_capa *capa,
  2768. char *buf, size_t buflen)
  2769. {
  2770. int ret;
  2771. char *pos, *end;
  2772. size_t len;
  2773. pos = buf;
  2774. end = pos + buflen;
  2775. if (res < 0) {
  2776. if (strict)
  2777. return 0;
  2778. len = os_strlcpy(buf, "WPA-PSK WPA-EAP IEEE8021X WPA-NONE "
  2779. "NONE", buflen);
  2780. if (len >= buflen)
  2781. return -1;
  2782. return len;
  2783. }
  2784. ret = os_snprintf(pos, end - pos, "NONE IEEE8021X");
  2785. if (ret < 0 || ret >= end - pos)
  2786. return pos - buf;
  2787. pos += ret;
  2788. if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
  2789. WPA_DRIVER_CAPA_KEY_MGMT_WPA2)) {
  2790. ret = os_snprintf(pos, end - pos, " WPA-EAP");
  2791. if (ret < 0 || ret >= end - pos)
  2792. return pos - buf;
  2793. pos += ret;
  2794. }
  2795. if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK |
  2796. WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
  2797. ret = os_snprintf(pos, end - pos, " WPA-PSK");
  2798. if (ret < 0 || ret >= end - pos)
  2799. return pos - buf;
  2800. pos += ret;
  2801. }
  2802. if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE) {
  2803. ret = os_snprintf(pos, end - pos, " WPA-NONE");
  2804. if (ret < 0 || ret >= end - pos)
  2805. return pos - buf;
  2806. pos += ret;
  2807. }
  2808. return pos - buf;
  2809. }
  2810. static int ctrl_iface_get_capability_proto(int res, char *strict,
  2811. struct wpa_driver_capa *capa,
  2812. char *buf, size_t buflen)
  2813. {
  2814. int ret;
  2815. char *pos, *end;
  2816. size_t len;
  2817. pos = buf;
  2818. end = pos + buflen;
  2819. if (res < 0) {
  2820. if (strict)
  2821. return 0;
  2822. len = os_strlcpy(buf, "RSN WPA", buflen);
  2823. if (len >= buflen)
  2824. return -1;
  2825. return len;
  2826. }
  2827. if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA2 |
  2828. WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
  2829. ret = os_snprintf(pos, end - pos, "%sRSN",
  2830. pos == buf ? "" : " ");
  2831. if (ret < 0 || ret >= end - pos)
  2832. return pos - buf;
  2833. pos += ret;
  2834. }
  2835. if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
  2836. WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK)) {
  2837. ret = os_snprintf(pos, end - pos, "%sWPA",
  2838. pos == buf ? "" : " ");
  2839. if (ret < 0 || ret >= end - pos)
  2840. return pos - buf;
  2841. pos += ret;
  2842. }
  2843. return pos - buf;
  2844. }
  2845. static int ctrl_iface_get_capability_auth_alg(int res, char *strict,
  2846. struct wpa_driver_capa *capa,
  2847. char *buf, size_t buflen)
  2848. {
  2849. int ret;
  2850. char *pos, *end;
  2851. size_t len;
  2852. pos = buf;
  2853. end = pos + buflen;
  2854. if (res < 0) {
  2855. if (strict)
  2856. return 0;
  2857. len = os_strlcpy(buf, "OPEN SHARED LEAP", buflen);
  2858. if (len >= buflen)
  2859. return -1;
  2860. return len;
  2861. }
  2862. if (capa->auth & (WPA_DRIVER_AUTH_OPEN)) {
  2863. ret = os_snprintf(pos, end - pos, "%sOPEN",
  2864. pos == buf ? "" : " ");
  2865. if (ret < 0 || ret >= end - pos)
  2866. return pos - buf;
  2867. pos += ret;
  2868. }
  2869. if (capa->auth & (WPA_DRIVER_AUTH_SHARED)) {
  2870. ret = os_snprintf(pos, end - pos, "%sSHARED",
  2871. pos == buf ? "" : " ");
  2872. if (ret < 0 || ret >= end - pos)
  2873. return pos - buf;
  2874. pos += ret;
  2875. }
  2876. if (capa->auth & (WPA_DRIVER_AUTH_LEAP)) {
  2877. ret = os_snprintf(pos, end - pos, "%sLEAP",
  2878. pos == buf ? "" : " ");
  2879. if (ret < 0 || ret >= end - pos)
  2880. return pos - buf;
  2881. pos += ret;
  2882. }
  2883. return pos - buf;
  2884. }
  2885. static int ctrl_iface_get_capability_modes(int res, char *strict,
  2886. struct wpa_driver_capa *capa,
  2887. char *buf, size_t buflen)
  2888. {
  2889. int ret;
  2890. char *pos, *end;
  2891. size_t len;
  2892. pos = buf;
  2893. end = pos + buflen;
  2894. if (res < 0) {
  2895. if (strict)
  2896. return 0;
  2897. len = os_strlcpy(buf, "IBSS AP", buflen);
  2898. if (len >= buflen)
  2899. return -1;
  2900. return len;
  2901. }
  2902. if (capa->flags & WPA_DRIVER_FLAGS_IBSS) {
  2903. ret = os_snprintf(pos, end - pos, "%sIBSS",
  2904. pos == buf ? "" : " ");
  2905. if (ret < 0 || ret >= end - pos)
  2906. return pos - buf;
  2907. pos += ret;
  2908. }
  2909. if (capa->flags & WPA_DRIVER_FLAGS_AP) {
  2910. ret = os_snprintf(pos, end - pos, "%sAP",
  2911. pos == buf ? "" : " ");
  2912. if (ret < 0 || ret >= end - pos)
  2913. return pos - buf;
  2914. pos += ret;
  2915. }
  2916. return pos - buf;
  2917. }
  2918. static int ctrl_iface_get_capability_channels(struct wpa_supplicant *wpa_s,
  2919. char *buf, size_t buflen)
  2920. {
  2921. struct hostapd_channel_data *chnl;
  2922. int ret, i, j;
  2923. char *pos, *end, *hmode;
  2924. pos = buf;
  2925. end = pos + buflen;
  2926. for (j = 0; j < wpa_s->hw.num_modes; j++) {
  2927. switch (wpa_s->hw.modes[j].mode) {
  2928. case HOSTAPD_MODE_IEEE80211B:
  2929. hmode = "B";
  2930. break;
  2931. case HOSTAPD_MODE_IEEE80211G:
  2932. hmode = "G";
  2933. break;
  2934. case HOSTAPD_MODE_IEEE80211A:
  2935. hmode = "A";
  2936. break;
  2937. case HOSTAPD_MODE_IEEE80211AD:
  2938. hmode = "AD";
  2939. break;
  2940. default:
  2941. continue;
  2942. }
  2943. ret = os_snprintf(pos, end - pos, "Mode[%s] Channels:", hmode);
  2944. if (ret < 0 || ret >= end - pos)
  2945. return pos - buf;
  2946. pos += ret;
  2947. chnl = wpa_s->hw.modes[j].channels;
  2948. for (i = 0; i < wpa_s->hw.modes[j].num_channels; i++) {
  2949. if (chnl[i].flag & HOSTAPD_CHAN_DISABLED)
  2950. continue;
  2951. ret = os_snprintf(pos, end - pos, " %d", chnl[i].chan);
  2952. if (ret < 0 || ret >= end - pos)
  2953. return pos - buf;
  2954. pos += ret;
  2955. }
  2956. ret = os_snprintf(pos, end - pos, "\n");
  2957. if (ret < 0 || ret >= end - pos)
  2958. return pos - buf;
  2959. pos += ret;
  2960. }
  2961. return pos - buf;
  2962. }
  2963. static int ctrl_iface_get_capability_freq(struct wpa_supplicant *wpa_s,
  2964. char *buf, size_t buflen)
  2965. {
  2966. struct hostapd_channel_data *chnl;
  2967. int ret, i, j;
  2968. char *pos, *end, *hmode;
  2969. pos = buf;
  2970. end = pos + buflen;
  2971. for (j = 0; j < wpa_s->hw.num_modes; j++) {
  2972. switch (wpa_s->hw.modes[j].mode) {
  2973. case HOSTAPD_MODE_IEEE80211B:
  2974. hmode = "B";
  2975. break;
  2976. case HOSTAPD_MODE_IEEE80211G:
  2977. hmode = "G";
  2978. break;
  2979. case HOSTAPD_MODE_IEEE80211A:
  2980. hmode = "A";
  2981. break;
  2982. case HOSTAPD_MODE_IEEE80211AD:
  2983. hmode = "AD";
  2984. break;
  2985. default:
  2986. continue;
  2987. }
  2988. ret = os_snprintf(pos, end - pos, "Mode[%s] Channels:\n",
  2989. hmode);
  2990. if (ret < 0 || ret >= end - pos)
  2991. return pos - buf;
  2992. pos += ret;
  2993. chnl = wpa_s->hw.modes[j].channels;
  2994. for (i = 0; i < wpa_s->hw.modes[j].num_channels; i++) {
  2995. if (chnl[i].flag & HOSTAPD_CHAN_DISABLED)
  2996. continue;
  2997. ret = os_snprintf(pos, end - pos, " %d = %d MHz%s%s\n",
  2998. chnl[i].chan, chnl[i].freq,
  2999. chnl[i].flag & HOSTAPD_CHAN_NO_IR ?
  3000. " (NO_IR)" : "",
  3001. chnl[i].flag & HOSTAPD_CHAN_RADAR ?
  3002. " (DFS)" : "");
  3003. if (ret < 0 || ret >= end - pos)
  3004. return pos - buf;
  3005. pos += ret;
  3006. }
  3007. ret = os_snprintf(pos, end - pos, "\n");
  3008. if (ret < 0 || ret >= end - pos)
  3009. return pos - buf;
  3010. pos += ret;
  3011. }
  3012. return pos - buf;
  3013. }
  3014. static int wpa_supplicant_ctrl_iface_get_capability(
  3015. struct wpa_supplicant *wpa_s, const char *_field, char *buf,
  3016. size_t buflen)
  3017. {
  3018. struct wpa_driver_capa capa;
  3019. int res;
  3020. char *strict;
  3021. char field[30];
  3022. size_t len;
  3023. /* Determine whether or not strict checking was requested */
  3024. len = os_strlcpy(field, _field, sizeof(field));
  3025. if (len >= sizeof(field))
  3026. return -1;
  3027. strict = os_strchr(field, ' ');
  3028. if (strict != NULL) {
  3029. *strict++ = '\0';
  3030. if (os_strcmp(strict, "strict") != 0)
  3031. return -1;
  3032. }
  3033. wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_CAPABILITY '%s' %s",
  3034. field, strict ? strict : "");
  3035. if (os_strcmp(field, "eap") == 0) {
  3036. return eap_get_names(buf, buflen);
  3037. }
  3038. res = wpa_drv_get_capa(wpa_s, &capa);
  3039. if (os_strcmp(field, "pairwise") == 0)
  3040. return ctrl_iface_get_capability_pairwise(res, strict, &capa,
  3041. buf, buflen);
  3042. if (os_strcmp(field, "group") == 0)
  3043. return ctrl_iface_get_capability_group(res, strict, &capa,
  3044. buf, buflen);
  3045. if (os_strcmp(field, "key_mgmt") == 0)
  3046. return ctrl_iface_get_capability_key_mgmt(res, strict, &capa,
  3047. buf, buflen);
  3048. if (os_strcmp(field, "proto") == 0)
  3049. return ctrl_iface_get_capability_proto(res, strict, &capa,
  3050. buf, buflen);
  3051. if (os_strcmp(field, "auth_alg") == 0)
  3052. return ctrl_iface_get_capability_auth_alg(res, strict, &capa,
  3053. buf, buflen);
  3054. if (os_strcmp(field, "modes") == 0)
  3055. return ctrl_iface_get_capability_modes(res, strict, &capa,
  3056. buf, buflen);
  3057. if (os_strcmp(field, "channels") == 0)
  3058. return ctrl_iface_get_capability_channels(wpa_s, buf, buflen);
  3059. if (os_strcmp(field, "freq") == 0)
  3060. return ctrl_iface_get_capability_freq(wpa_s, buf, buflen);
  3061. #ifdef CONFIG_TDLS
  3062. if (os_strcmp(field, "tdls") == 0)
  3063. return ctrl_iface_get_capability_tdls(wpa_s, buf, buflen);
  3064. #endif /* CONFIG_TDLS */
  3065. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown GET_CAPABILITY field '%s'",
  3066. field);
  3067. return -1;
  3068. }
  3069. #ifdef CONFIG_INTERWORKING
  3070. static char * anqp_add_hex(char *pos, char *end, const char *title,
  3071. struct wpabuf *data)
  3072. {
  3073. char *start = pos;
  3074. size_t i;
  3075. int ret;
  3076. const u8 *d;
  3077. if (data == NULL)
  3078. return start;
  3079. ret = os_snprintf(pos, end - pos, "%s=", title);
  3080. if (ret < 0 || ret >= end - pos)
  3081. return start;
  3082. pos += ret;
  3083. d = wpabuf_head_u8(data);
  3084. for (i = 0; i < wpabuf_len(data); i++) {
  3085. ret = os_snprintf(pos, end - pos, "%02x", *d++);
  3086. if (ret < 0 || ret >= end - pos)
  3087. return start;
  3088. pos += ret;
  3089. }
  3090. ret = os_snprintf(pos, end - pos, "\n");
  3091. if (ret < 0 || ret >= end - pos)
  3092. return start;
  3093. pos += ret;
  3094. return pos;
  3095. }
  3096. #endif /* CONFIG_INTERWORKING */
  3097. static int print_bss_info(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
  3098. unsigned long mask, char *buf, size_t buflen)
  3099. {
  3100. size_t i;
  3101. int ret;
  3102. char *pos, *end;
  3103. const u8 *ie, *ie2;
  3104. pos = buf;
  3105. end = buf + buflen;
  3106. if (mask & WPA_BSS_MASK_ID) {
  3107. ret = os_snprintf(pos, end - pos, "id=%u\n", bss->id);
  3108. if (ret < 0 || ret >= end - pos)
  3109. return 0;
  3110. pos += ret;
  3111. }
  3112. if (mask & WPA_BSS_MASK_BSSID) {
  3113. ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n",
  3114. MAC2STR(bss->bssid));
  3115. if (ret < 0 || ret >= end - pos)
  3116. return 0;
  3117. pos += ret;
  3118. }
  3119. if (mask & WPA_BSS_MASK_FREQ) {
  3120. ret = os_snprintf(pos, end - pos, "freq=%d\n", bss->freq);
  3121. if (ret < 0 || ret >= end - pos)
  3122. return 0;
  3123. pos += ret;
  3124. }
  3125. if (mask & WPA_BSS_MASK_BEACON_INT) {
  3126. ret = os_snprintf(pos, end - pos, "beacon_int=%d\n",
  3127. bss->beacon_int);
  3128. if (ret < 0 || ret >= end - pos)
  3129. return 0;
  3130. pos += ret;
  3131. }
  3132. if (mask & WPA_BSS_MASK_CAPABILITIES) {
  3133. ret = os_snprintf(pos, end - pos, "capabilities=0x%04x\n",
  3134. bss->caps);
  3135. if (ret < 0 || ret >= end - pos)
  3136. return 0;
  3137. pos += ret;
  3138. }
  3139. if (mask & WPA_BSS_MASK_QUAL) {
  3140. ret = os_snprintf(pos, end - pos, "qual=%d\n", bss->qual);
  3141. if (ret < 0 || ret >= end - pos)
  3142. return 0;
  3143. pos += ret;
  3144. }
  3145. if (mask & WPA_BSS_MASK_NOISE) {
  3146. ret = os_snprintf(pos, end - pos, "noise=%d\n", bss->noise);
  3147. if (ret < 0 || ret >= end - pos)
  3148. return 0;
  3149. pos += ret;
  3150. }
  3151. if (mask & WPA_BSS_MASK_LEVEL) {
  3152. ret = os_snprintf(pos, end - pos, "level=%d\n", bss->level);
  3153. if (ret < 0 || ret >= end - pos)
  3154. return 0;
  3155. pos += ret;
  3156. }
  3157. if (mask & WPA_BSS_MASK_TSF) {
  3158. ret = os_snprintf(pos, end - pos, "tsf=%016llu\n",
  3159. (unsigned long long) bss->tsf);
  3160. if (ret < 0 || ret >= end - pos)
  3161. return 0;
  3162. pos += ret;
  3163. }
  3164. if (mask & WPA_BSS_MASK_AGE) {
  3165. struct os_reltime now;
  3166. os_get_reltime(&now);
  3167. ret = os_snprintf(pos, end - pos, "age=%d\n",
  3168. (int) (now.sec - bss->last_update.sec));
  3169. if (ret < 0 || ret >= end - pos)
  3170. return 0;
  3171. pos += ret;
  3172. }
  3173. if (mask & WPA_BSS_MASK_IE) {
  3174. ret = os_snprintf(pos, end - pos, "ie=");
  3175. if (ret < 0 || ret >= end - pos)
  3176. return 0;
  3177. pos += ret;
  3178. ie = (const u8 *) (bss + 1);
  3179. for (i = 0; i < bss->ie_len; i++) {
  3180. ret = os_snprintf(pos, end - pos, "%02x", *ie++);
  3181. if (ret < 0 || ret >= end - pos)
  3182. return 0;
  3183. pos += ret;
  3184. }
  3185. ret = os_snprintf(pos, end - pos, "\n");
  3186. if (ret < 0 || ret >= end - pos)
  3187. return 0;
  3188. pos += ret;
  3189. }
  3190. if (mask & WPA_BSS_MASK_FLAGS) {
  3191. ret = os_snprintf(pos, end - pos, "flags=");
  3192. if (ret < 0 || ret >= end - pos)
  3193. return 0;
  3194. pos += ret;
  3195. ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
  3196. if (ie)
  3197. pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie,
  3198. 2 + ie[1]);
  3199. ie2 = wpa_bss_get_ie(bss, WLAN_EID_RSN);
  3200. if (ie2)
  3201. pos = wpa_supplicant_ie_txt(pos, end, "WPA2", ie2,
  3202. 2 + ie2[1]);
  3203. pos = wpa_supplicant_wps_ie_txt(wpa_s, pos, end, bss);
  3204. if (!ie && !ie2 && bss->caps & IEEE80211_CAP_PRIVACY) {
  3205. ret = os_snprintf(pos, end - pos, "[WEP]");
  3206. if (ret < 0 || ret >= end - pos)
  3207. return 0;
  3208. pos += ret;
  3209. }
  3210. if (bss_is_dmg(bss)) {
  3211. const char *s;
  3212. ret = os_snprintf(pos, end - pos, "[DMG]");
  3213. if (ret < 0 || ret >= end - pos)
  3214. return 0;
  3215. pos += ret;
  3216. switch (bss->caps & IEEE80211_CAP_DMG_MASK) {
  3217. case IEEE80211_CAP_DMG_IBSS:
  3218. s = "[IBSS]";
  3219. break;
  3220. case IEEE80211_CAP_DMG_AP:
  3221. s = "[ESS]";
  3222. break;
  3223. case IEEE80211_CAP_DMG_PBSS:
  3224. s = "[PBSS]";
  3225. break;
  3226. default:
  3227. s = "";
  3228. break;
  3229. }
  3230. ret = os_snprintf(pos, end - pos, "%s", s);
  3231. if (ret < 0 || ret >= end - pos)
  3232. return 0;
  3233. pos += ret;
  3234. } else {
  3235. if (bss->caps & IEEE80211_CAP_IBSS) {
  3236. ret = os_snprintf(pos, end - pos, "[IBSS]");
  3237. if (ret < 0 || ret >= end - pos)
  3238. return 0;
  3239. pos += ret;
  3240. }
  3241. if (bss->caps & IEEE80211_CAP_ESS) {
  3242. ret = os_snprintf(pos, end - pos, "[ESS]");
  3243. if (ret < 0 || ret >= end - pos)
  3244. return 0;
  3245. pos += ret;
  3246. }
  3247. }
  3248. if (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE) ||
  3249. wpa_bss_get_vendor_ie_beacon(bss, P2P_IE_VENDOR_TYPE)) {
  3250. ret = os_snprintf(pos, end - pos, "[P2P]");
  3251. if (ret < 0 || ret >= end - pos)
  3252. return 0;
  3253. pos += ret;
  3254. }
  3255. #ifdef CONFIG_HS20
  3256. if (wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE)) {
  3257. ret = os_snprintf(pos, end - pos, "[HS20]");
  3258. if (ret < 0 || ret >= end - pos)
  3259. return 0;
  3260. pos += ret;
  3261. }
  3262. #endif /* CONFIG_HS20 */
  3263. ret = os_snprintf(pos, end - pos, "\n");
  3264. if (ret < 0 || ret >= end - pos)
  3265. return 0;
  3266. pos += ret;
  3267. }
  3268. if (mask & WPA_BSS_MASK_SSID) {
  3269. ret = os_snprintf(pos, end - pos, "ssid=%s\n",
  3270. wpa_ssid_txt(bss->ssid, bss->ssid_len));
  3271. if (ret < 0 || ret >= end - pos)
  3272. return 0;
  3273. pos += ret;
  3274. }
  3275. #ifdef CONFIG_WPS
  3276. if (mask & WPA_BSS_MASK_WPS_SCAN) {
  3277. ie = (const u8 *) (bss + 1);
  3278. ret = wpas_wps_scan_result_text(ie, bss->ie_len, pos, end);
  3279. if (ret < 0 || ret >= end - pos)
  3280. return 0;
  3281. pos += ret;
  3282. }
  3283. #endif /* CONFIG_WPS */
  3284. #ifdef CONFIG_P2P
  3285. if (mask & WPA_BSS_MASK_P2P_SCAN) {
  3286. ie = (const u8 *) (bss + 1);
  3287. ret = wpas_p2p_scan_result_text(ie, bss->ie_len, pos, end);
  3288. if (ret < 0 || ret >= end - pos)
  3289. return 0;
  3290. pos += ret;
  3291. }
  3292. #endif /* CONFIG_P2P */
  3293. #ifdef CONFIG_WIFI_DISPLAY
  3294. if (mask & WPA_BSS_MASK_WIFI_DISPLAY) {
  3295. struct wpabuf *wfd;
  3296. ie = (const u8 *) (bss + 1);
  3297. wfd = ieee802_11_vendor_ie_concat(ie, bss->ie_len,
  3298. WFD_IE_VENDOR_TYPE);
  3299. if (wfd) {
  3300. ret = os_snprintf(pos, end - pos, "wfd_subelems=");
  3301. if (ret < 0 || ret >= end - pos) {
  3302. wpabuf_free(wfd);
  3303. return 0;
  3304. }
  3305. pos += ret;
  3306. pos += wpa_snprintf_hex(pos, end - pos,
  3307. wpabuf_head(wfd),
  3308. wpabuf_len(wfd));
  3309. wpabuf_free(wfd);
  3310. ret = os_snprintf(pos, end - pos, "\n");
  3311. if (ret < 0 || ret >= end - pos)
  3312. return 0;
  3313. pos += ret;
  3314. }
  3315. }
  3316. #endif /* CONFIG_WIFI_DISPLAY */
  3317. #ifdef CONFIG_INTERWORKING
  3318. if ((mask & WPA_BSS_MASK_INTERNETW) && bss->anqp) {
  3319. struct wpa_bss_anqp *anqp = bss->anqp;
  3320. pos = anqp_add_hex(pos, end, "anqp_venue_name",
  3321. anqp->venue_name);
  3322. pos = anqp_add_hex(pos, end, "anqp_network_auth_type",
  3323. anqp->network_auth_type);
  3324. pos = anqp_add_hex(pos, end, "anqp_roaming_consortium",
  3325. anqp->roaming_consortium);
  3326. pos = anqp_add_hex(pos, end, "anqp_ip_addr_type_availability",
  3327. anqp->ip_addr_type_availability);
  3328. pos = anqp_add_hex(pos, end, "anqp_nai_realm",
  3329. anqp->nai_realm);
  3330. pos = anqp_add_hex(pos, end, "anqp_3gpp", anqp->anqp_3gpp);
  3331. pos = anqp_add_hex(pos, end, "anqp_domain_name",
  3332. anqp->domain_name);
  3333. #ifdef CONFIG_HS20
  3334. pos = anqp_add_hex(pos, end, "hs20_operator_friendly_name",
  3335. anqp->hs20_operator_friendly_name);
  3336. pos = anqp_add_hex(pos, end, "hs20_wan_metrics",
  3337. anqp->hs20_wan_metrics);
  3338. pos = anqp_add_hex(pos, end, "hs20_connection_capability",
  3339. anqp->hs20_connection_capability);
  3340. pos = anqp_add_hex(pos, end, "hs20_operating_class",
  3341. anqp->hs20_operating_class);
  3342. pos = anqp_add_hex(pos, end, "hs20_osu_providers_list",
  3343. anqp->hs20_osu_providers_list);
  3344. #endif /* CONFIG_HS20 */
  3345. }
  3346. #endif /* CONFIG_INTERWORKING */
  3347. #ifdef CONFIG_MESH
  3348. if (mask & WPA_BSS_MASK_MESH_SCAN) {
  3349. ie = (const u8 *) (bss + 1);
  3350. ret = wpas_mesh_scan_result_text(ie, bss->ie_len, pos, end);
  3351. if (ret < 0 || ret >= end - pos)
  3352. return 0;
  3353. pos += ret;
  3354. }
  3355. #endif /* CONFIG_MESH */
  3356. if (mask & WPA_BSS_MASK_DELIM) {
  3357. ret = os_snprintf(pos, end - pos, "====\n");
  3358. if (ret < 0 || ret >= end - pos)
  3359. return 0;
  3360. pos += ret;
  3361. }
  3362. return pos - buf;
  3363. }
  3364. static int wpa_supplicant_ctrl_iface_bss(struct wpa_supplicant *wpa_s,
  3365. const char *cmd, char *buf,
  3366. size_t buflen)
  3367. {
  3368. u8 bssid[ETH_ALEN];
  3369. size_t i;
  3370. struct wpa_bss *bss;
  3371. struct wpa_bss *bsslast = NULL;
  3372. struct dl_list *next;
  3373. int ret = 0;
  3374. int len;
  3375. char *ctmp;
  3376. unsigned long mask = WPA_BSS_MASK_ALL;
  3377. if (os_strncmp(cmd, "RANGE=", 6) == 0) {
  3378. if (os_strncmp(cmd + 6, "ALL", 3) == 0) {
  3379. bss = dl_list_first(&wpa_s->bss_id, struct wpa_bss,
  3380. list_id);
  3381. bsslast = dl_list_last(&wpa_s->bss_id, struct wpa_bss,
  3382. list_id);
  3383. } else { /* N1-N2 */
  3384. unsigned int id1, id2;
  3385. if ((ctmp = os_strchr(cmd + 6, '-')) == NULL) {
  3386. wpa_printf(MSG_INFO, "Wrong BSS range "
  3387. "format");
  3388. return 0;
  3389. }
  3390. if (*(cmd + 6) == '-')
  3391. id1 = 0;
  3392. else
  3393. id1 = atoi(cmd + 6);
  3394. ctmp++;
  3395. if (*ctmp >= '0' && *ctmp <= '9')
  3396. id2 = atoi(ctmp);
  3397. else
  3398. id2 = (unsigned int) -1;
  3399. bss = wpa_bss_get_id_range(wpa_s, id1, id2);
  3400. if (id2 == (unsigned int) -1)
  3401. bsslast = dl_list_last(&wpa_s->bss_id,
  3402. struct wpa_bss,
  3403. list_id);
  3404. else {
  3405. bsslast = wpa_bss_get_id(wpa_s, id2);
  3406. if (bsslast == NULL && bss && id2 > id1) {
  3407. struct wpa_bss *tmp = bss;
  3408. for (;;) {
  3409. next = tmp->list_id.next;
  3410. if (next == &wpa_s->bss_id)
  3411. break;
  3412. tmp = dl_list_entry(
  3413. next, struct wpa_bss,
  3414. list_id);
  3415. if (tmp->id > id2)
  3416. break;
  3417. bsslast = tmp;
  3418. }
  3419. }
  3420. }
  3421. }
  3422. } else if (os_strncmp(cmd, "FIRST", 5) == 0)
  3423. bss = dl_list_first(&wpa_s->bss_id, struct wpa_bss, list_id);
  3424. else if (os_strncmp(cmd, "LAST", 4) == 0)
  3425. bss = dl_list_last(&wpa_s->bss_id, struct wpa_bss, list_id);
  3426. else if (os_strncmp(cmd, "ID-", 3) == 0) {
  3427. i = atoi(cmd + 3);
  3428. bss = wpa_bss_get_id(wpa_s, i);
  3429. } else if (os_strncmp(cmd, "NEXT-", 5) == 0) {
  3430. i = atoi(cmd + 5);
  3431. bss = wpa_bss_get_id(wpa_s, i);
  3432. if (bss) {
  3433. next = bss->list_id.next;
  3434. if (next == &wpa_s->bss_id)
  3435. bss = NULL;
  3436. else
  3437. bss = dl_list_entry(next, struct wpa_bss,
  3438. list_id);
  3439. }
  3440. #ifdef CONFIG_P2P
  3441. } else if (os_strncmp(cmd, "p2p_dev_addr=", 13) == 0) {
  3442. if (hwaddr_aton(cmd + 13, bssid) == 0)
  3443. bss = wpa_bss_get_p2p_dev_addr(wpa_s, bssid);
  3444. else
  3445. bss = NULL;
  3446. #endif /* CONFIG_P2P */
  3447. } else if (hwaddr_aton(cmd, bssid) == 0)
  3448. bss = wpa_bss_get_bssid(wpa_s, bssid);
  3449. else {
  3450. struct wpa_bss *tmp;
  3451. i = atoi(cmd);
  3452. bss = NULL;
  3453. dl_list_for_each(tmp, &wpa_s->bss_id, struct wpa_bss, list_id)
  3454. {
  3455. if (i-- == 0) {
  3456. bss = tmp;
  3457. break;
  3458. }
  3459. }
  3460. }
  3461. if ((ctmp = os_strstr(cmd, "MASK=")) != NULL) {
  3462. mask = strtoul(ctmp + 5, NULL, 0x10);
  3463. if (mask == 0)
  3464. mask = WPA_BSS_MASK_ALL;
  3465. }
  3466. if (bss == NULL)
  3467. return 0;
  3468. if (bsslast == NULL)
  3469. bsslast = bss;
  3470. do {
  3471. len = print_bss_info(wpa_s, bss, mask, buf, buflen);
  3472. ret += len;
  3473. buf += len;
  3474. buflen -= len;
  3475. if (bss == bsslast) {
  3476. if ((mask & WPA_BSS_MASK_DELIM) && len &&
  3477. (bss == dl_list_last(&wpa_s->bss_id,
  3478. struct wpa_bss, list_id)))
  3479. os_snprintf(buf - 5, 5, "####\n");
  3480. break;
  3481. }
  3482. next = bss->list_id.next;
  3483. if (next == &wpa_s->bss_id)
  3484. break;
  3485. bss = dl_list_entry(next, struct wpa_bss, list_id);
  3486. } while (bss && len);
  3487. return ret;
  3488. }
  3489. static int wpa_supplicant_ctrl_iface_ap_scan(
  3490. struct wpa_supplicant *wpa_s, char *cmd)
  3491. {
  3492. int ap_scan = atoi(cmd);
  3493. return wpa_supplicant_set_ap_scan(wpa_s, ap_scan);
  3494. }
  3495. static int wpa_supplicant_ctrl_iface_scan_interval(
  3496. struct wpa_supplicant *wpa_s, char *cmd)
  3497. {
  3498. int scan_int = atoi(cmd);
  3499. return wpa_supplicant_set_scan_interval(wpa_s, scan_int);
  3500. }
  3501. static int wpa_supplicant_ctrl_iface_bss_expire_age(
  3502. struct wpa_supplicant *wpa_s, char *cmd)
  3503. {
  3504. int expire_age = atoi(cmd);
  3505. return wpa_supplicant_set_bss_expiration_age(wpa_s, expire_age);
  3506. }
  3507. static int wpa_supplicant_ctrl_iface_bss_expire_count(
  3508. struct wpa_supplicant *wpa_s, char *cmd)
  3509. {
  3510. int expire_count = atoi(cmd);
  3511. return wpa_supplicant_set_bss_expiration_count(wpa_s, expire_count);
  3512. }
  3513. static int wpa_supplicant_ctrl_iface_bss_flush(
  3514. struct wpa_supplicant *wpa_s, char *cmd)
  3515. {
  3516. int flush_age = atoi(cmd);
  3517. if (flush_age == 0)
  3518. wpa_bss_flush(wpa_s);
  3519. else
  3520. wpa_bss_flush_by_age(wpa_s, flush_age);
  3521. return 0;
  3522. }
  3523. #ifdef CONFIG_TESTING_OPTIONS
  3524. static void wpa_supplicant_ctrl_iface_drop_sa(struct wpa_supplicant *wpa_s)
  3525. {
  3526. wpa_printf(MSG_DEBUG, "Dropping SA without deauthentication");
  3527. /* MLME-DELETEKEYS.request */
  3528. wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 0, 0, NULL, 0, NULL, 0);
  3529. wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 1, 0, NULL, 0, NULL, 0);
  3530. wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 2, 0, NULL, 0, NULL, 0);
  3531. wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 3, 0, NULL, 0, NULL, 0);
  3532. #ifdef CONFIG_IEEE80211W
  3533. wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 4, 0, NULL, 0, NULL, 0);
  3534. wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 5, 0, NULL, 0, NULL, 0);
  3535. #endif /* CONFIG_IEEE80211W */
  3536. wpa_drv_set_key(wpa_s, WPA_ALG_NONE, wpa_s->bssid, 0, 0, NULL, 0, NULL,
  3537. 0);
  3538. /* MLME-SETPROTECTION.request(None) */
  3539. wpa_drv_mlme_setprotection(wpa_s, wpa_s->bssid,
  3540. MLME_SETPROTECTION_PROTECT_TYPE_NONE,
  3541. MLME_SETPROTECTION_KEY_TYPE_PAIRWISE);
  3542. wpa_sm_drop_sa(wpa_s->wpa);
  3543. }
  3544. #endif /* CONFIG_TESTING_OPTIONS */
  3545. static int wpa_supplicant_ctrl_iface_roam(struct wpa_supplicant *wpa_s,
  3546. char *addr)
  3547. {
  3548. #ifdef CONFIG_NO_SCAN_PROCESSING
  3549. return -1;
  3550. #else /* CONFIG_NO_SCAN_PROCESSING */
  3551. u8 bssid[ETH_ALEN];
  3552. struct wpa_bss *bss;
  3553. struct wpa_ssid *ssid = wpa_s->current_ssid;
  3554. if (hwaddr_aton(addr, bssid)) {
  3555. wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: invalid "
  3556. "address '%s'", addr);
  3557. return -1;
  3558. }
  3559. wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM " MACSTR, MAC2STR(bssid));
  3560. if (!ssid) {
  3561. wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: No network "
  3562. "configuration known for the target AP");
  3563. return -1;
  3564. }
  3565. bss = wpa_bss_get(wpa_s, bssid, ssid->ssid, ssid->ssid_len);
  3566. if (!bss) {
  3567. wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: Target AP not found "
  3568. "from BSS table");
  3569. return -1;
  3570. }
  3571. /*
  3572. * TODO: Find best network configuration block from configuration to
  3573. * allow roaming to other networks
  3574. */
  3575. wpa_s->reassociate = 1;
  3576. wpa_supplicant_connect(wpa_s, bss, ssid);
  3577. return 0;
  3578. #endif /* CONFIG_NO_SCAN_PROCESSING */
  3579. }
  3580. #ifdef CONFIG_P2P
  3581. static int p2p_ctrl_find(struct wpa_supplicant *wpa_s, char *cmd)
  3582. {
  3583. unsigned int timeout = atoi(cmd);
  3584. enum p2p_discovery_type type = P2P_FIND_START_WITH_FULL;
  3585. u8 dev_id[ETH_ALEN], *_dev_id = NULL;
  3586. u8 dev_type[WPS_DEV_TYPE_LEN], *_dev_type = NULL;
  3587. char *pos;
  3588. unsigned int search_delay;
  3589. if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
  3590. wpa_dbg(wpa_s, MSG_INFO,
  3591. "Reject P2P_FIND since interface is disabled");
  3592. return -1;
  3593. }
  3594. if (os_strstr(cmd, "type=social"))
  3595. type = P2P_FIND_ONLY_SOCIAL;
  3596. else if (os_strstr(cmd, "type=progressive"))
  3597. type = P2P_FIND_PROGRESSIVE;
  3598. pos = os_strstr(cmd, "dev_id=");
  3599. if (pos) {
  3600. pos += 7;
  3601. if (hwaddr_aton(pos, dev_id))
  3602. return -1;
  3603. _dev_id = dev_id;
  3604. }
  3605. pos = os_strstr(cmd, "dev_type=");
  3606. if (pos) {
  3607. pos += 9;
  3608. if (wps_dev_type_str2bin(pos, dev_type) < 0)
  3609. return -1;
  3610. _dev_type = dev_type;
  3611. }
  3612. pos = os_strstr(cmd, "delay=");
  3613. if (pos) {
  3614. pos += 6;
  3615. search_delay = atoi(pos);
  3616. } else
  3617. search_delay = wpas_p2p_search_delay(wpa_s);
  3618. return wpas_p2p_find(wpa_s, timeout, type, _dev_type != NULL, _dev_type,
  3619. _dev_id, search_delay);
  3620. }
  3621. static int p2p_ctrl_connect(struct wpa_supplicant *wpa_s, char *cmd,
  3622. char *buf, size_t buflen)
  3623. {
  3624. u8 addr[ETH_ALEN];
  3625. char *pos, *pos2;
  3626. char *pin = NULL;
  3627. enum p2p_wps_method wps_method;
  3628. int new_pin;
  3629. int ret;
  3630. int persistent_group, persistent_id = -1;
  3631. int join;
  3632. int auth;
  3633. int automatic;
  3634. int go_intent = -1;
  3635. int freq = 0;
  3636. int pd;
  3637. int ht40, vht;
  3638. /* <addr> <"pbc" | "pin" | PIN> [label|display|keypad]
  3639. * [persistent|persistent=<network id>]
  3640. * [join] [auth] [go_intent=<0..15>] [freq=<in MHz>] [provdisc]
  3641. * [ht40] [vht] */
  3642. if (hwaddr_aton(cmd, addr))
  3643. return -1;
  3644. pos = cmd + 17;
  3645. if (*pos != ' ')
  3646. return -1;
  3647. pos++;
  3648. persistent_group = os_strstr(pos, " persistent") != NULL;
  3649. pos2 = os_strstr(pos, " persistent=");
  3650. if (pos2) {
  3651. struct wpa_ssid *ssid;
  3652. persistent_id = atoi(pos2 + 12);
  3653. ssid = wpa_config_get_network(wpa_s->conf, persistent_id);
  3654. if (ssid == NULL || ssid->disabled != 2 ||
  3655. ssid->mode != WPAS_MODE_P2P_GO) {
  3656. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
  3657. "SSID id=%d for persistent P2P group (GO)",
  3658. persistent_id);
  3659. return -1;
  3660. }
  3661. }
  3662. join = os_strstr(pos, " join") != NULL;
  3663. auth = os_strstr(pos, " auth") != NULL;
  3664. automatic = os_strstr(pos, " auto") != NULL;
  3665. pd = os_strstr(pos, " provdisc") != NULL;
  3666. vht = (os_strstr(cmd, " vht") != NULL) || wpa_s->conf->p2p_go_vht;
  3667. ht40 = (os_strstr(cmd, " ht40") != NULL) || wpa_s->conf->p2p_go_ht40 ||
  3668. vht;
  3669. pos2 = os_strstr(pos, " go_intent=");
  3670. if (pos2) {
  3671. pos2 += 11;
  3672. go_intent = atoi(pos2);
  3673. if (go_intent < 0 || go_intent > 15)
  3674. return -1;
  3675. }
  3676. pos2 = os_strstr(pos, " freq=");
  3677. if (pos2) {
  3678. pos2 += 6;
  3679. freq = atoi(pos2);
  3680. if (freq <= 0)
  3681. return -1;
  3682. }
  3683. if (os_strncmp(pos, "pin", 3) == 0) {
  3684. /* Request random PIN (to be displayed) and enable the PIN */
  3685. wps_method = WPS_PIN_DISPLAY;
  3686. } else if (os_strncmp(pos, "pbc", 3) == 0) {
  3687. wps_method = WPS_PBC;
  3688. } else {
  3689. pin = pos;
  3690. pos = os_strchr(pin, ' ');
  3691. wps_method = WPS_PIN_KEYPAD;
  3692. if (pos) {
  3693. *pos++ = '\0';
  3694. if (os_strncmp(pos, "display", 7) == 0)
  3695. wps_method = WPS_PIN_DISPLAY;
  3696. }
  3697. if (!wps_pin_str_valid(pin)) {
  3698. os_memcpy(buf, "FAIL-INVALID-PIN\n", 17);
  3699. return 17;
  3700. }
  3701. }
  3702. new_pin = wpas_p2p_connect(wpa_s, addr, pin, wps_method,
  3703. persistent_group, automatic, join,
  3704. auth, go_intent, freq, persistent_id, pd,
  3705. ht40, vht);
  3706. if (new_pin == -2) {
  3707. os_memcpy(buf, "FAIL-CHANNEL-UNAVAILABLE\n", 25);
  3708. return 25;
  3709. }
  3710. if (new_pin == -3) {
  3711. os_memcpy(buf, "FAIL-CHANNEL-UNSUPPORTED\n", 25);
  3712. return 25;
  3713. }
  3714. if (new_pin < 0)
  3715. return -1;
  3716. if (wps_method == WPS_PIN_DISPLAY && pin == NULL) {
  3717. ret = os_snprintf(buf, buflen, "%08d", new_pin);
  3718. if (ret < 0 || (size_t) ret >= buflen)
  3719. return -1;
  3720. return ret;
  3721. }
  3722. os_memcpy(buf, "OK\n", 3);
  3723. return 3;
  3724. }
  3725. static int p2p_ctrl_listen(struct wpa_supplicant *wpa_s, char *cmd)
  3726. {
  3727. unsigned int timeout = atoi(cmd);
  3728. if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
  3729. wpa_dbg(wpa_s, MSG_INFO,
  3730. "Reject P2P_LISTEN since interface is disabled");
  3731. return -1;
  3732. }
  3733. return wpas_p2p_listen(wpa_s, timeout);
  3734. }
  3735. static int p2p_ctrl_prov_disc(struct wpa_supplicant *wpa_s, char *cmd)
  3736. {
  3737. u8 addr[ETH_ALEN];
  3738. char *pos;
  3739. enum wpas_p2p_prov_disc_use use = WPAS_P2P_PD_FOR_GO_NEG;
  3740. /* <addr> <config method> [join|auto] */
  3741. if (hwaddr_aton(cmd, addr))
  3742. return -1;
  3743. pos = cmd + 17;
  3744. if (*pos != ' ')
  3745. return -1;
  3746. pos++;
  3747. if (os_strstr(pos, " join") != NULL)
  3748. use = WPAS_P2P_PD_FOR_JOIN;
  3749. else if (os_strstr(pos, " auto") != NULL)
  3750. use = WPAS_P2P_PD_AUTO;
  3751. return wpas_p2p_prov_disc(wpa_s, addr, pos, use);
  3752. }
  3753. static int p2p_get_passphrase(struct wpa_supplicant *wpa_s, char *buf,
  3754. size_t buflen)
  3755. {
  3756. struct wpa_ssid *ssid = wpa_s->current_ssid;
  3757. if (ssid == NULL || ssid->mode != WPAS_MODE_P2P_GO ||
  3758. ssid->passphrase == NULL)
  3759. return -1;
  3760. os_strlcpy(buf, ssid->passphrase, buflen);
  3761. return os_strlen(buf);
  3762. }
  3763. static int p2p_ctrl_serv_disc_req(struct wpa_supplicant *wpa_s, char *cmd,
  3764. char *buf, size_t buflen)
  3765. {
  3766. u64 ref;
  3767. int res;
  3768. u8 dst_buf[ETH_ALEN], *dst;
  3769. struct wpabuf *tlvs;
  3770. char *pos;
  3771. size_t len;
  3772. if (hwaddr_aton(cmd, dst_buf))
  3773. return -1;
  3774. dst = dst_buf;
  3775. if (dst[0] == 0 && dst[1] == 0 && dst[2] == 0 &&
  3776. dst[3] == 0 && dst[4] == 0 && dst[5] == 0)
  3777. dst = NULL;
  3778. pos = cmd + 17;
  3779. if (*pos != ' ')
  3780. return -1;
  3781. pos++;
  3782. if (os_strncmp(pos, "upnp ", 5) == 0) {
  3783. u8 version;
  3784. pos += 5;
  3785. if (hexstr2bin(pos, &version, 1) < 0)
  3786. return -1;
  3787. pos += 2;
  3788. if (*pos != ' ')
  3789. return -1;
  3790. pos++;
  3791. ref = wpas_p2p_sd_request_upnp(wpa_s, dst, version, pos);
  3792. #ifdef CONFIG_WIFI_DISPLAY
  3793. } else if (os_strncmp(pos, "wifi-display ", 13) == 0) {
  3794. ref = wpas_p2p_sd_request_wifi_display(wpa_s, dst, pos + 13);
  3795. #endif /* CONFIG_WIFI_DISPLAY */
  3796. } else {
  3797. len = os_strlen(pos);
  3798. if (len & 1)
  3799. return -1;
  3800. len /= 2;
  3801. tlvs = wpabuf_alloc(len);
  3802. if (tlvs == NULL)
  3803. return -1;
  3804. if (hexstr2bin(pos, wpabuf_put(tlvs, len), len) < 0) {
  3805. wpabuf_free(tlvs);
  3806. return -1;
  3807. }
  3808. ref = wpas_p2p_sd_request(wpa_s, dst, tlvs);
  3809. wpabuf_free(tlvs);
  3810. }
  3811. if (ref == 0)
  3812. return -1;
  3813. res = os_snprintf(buf, buflen, "%llx", (long long unsigned) ref);
  3814. if (res < 0 || (unsigned) res >= buflen)
  3815. return -1;
  3816. return res;
  3817. }
  3818. static int p2p_ctrl_serv_disc_cancel_req(struct wpa_supplicant *wpa_s,
  3819. char *cmd)
  3820. {
  3821. long long unsigned val;
  3822. u64 req;
  3823. if (sscanf(cmd, "%llx", &val) != 1)
  3824. return -1;
  3825. req = val;
  3826. return wpas_p2p_sd_cancel_request(wpa_s, req);
  3827. }
  3828. static int p2p_ctrl_serv_disc_resp(struct wpa_supplicant *wpa_s, char *cmd)
  3829. {
  3830. int freq;
  3831. u8 dst[ETH_ALEN];
  3832. u8 dialog_token;
  3833. struct wpabuf *resp_tlvs;
  3834. char *pos, *pos2;
  3835. size_t len;
  3836. pos = os_strchr(cmd, ' ');
  3837. if (pos == NULL)
  3838. return -1;
  3839. *pos++ = '\0';
  3840. freq = atoi(cmd);
  3841. if (freq == 0)
  3842. return -1;
  3843. if (hwaddr_aton(pos, dst))
  3844. return -1;
  3845. pos += 17;
  3846. if (*pos != ' ')
  3847. return -1;
  3848. pos++;
  3849. pos2 = os_strchr(pos, ' ');
  3850. if (pos2 == NULL)
  3851. return -1;
  3852. *pos2++ = '\0';
  3853. dialog_token = atoi(pos);
  3854. len = os_strlen(pos2);
  3855. if (len & 1)
  3856. return -1;
  3857. len /= 2;
  3858. resp_tlvs = wpabuf_alloc(len);
  3859. if (resp_tlvs == NULL)
  3860. return -1;
  3861. if (hexstr2bin(pos2, wpabuf_put(resp_tlvs, len), len) < 0) {
  3862. wpabuf_free(resp_tlvs);
  3863. return -1;
  3864. }
  3865. wpas_p2p_sd_response(wpa_s, freq, dst, dialog_token, resp_tlvs);
  3866. wpabuf_free(resp_tlvs);
  3867. return 0;
  3868. }
  3869. static int p2p_ctrl_serv_disc_external(struct wpa_supplicant *wpa_s,
  3870. char *cmd)
  3871. {
  3872. if (os_strcmp(cmd, "0") && os_strcmp(cmd, "1"))
  3873. return -1;
  3874. wpa_s->p2p_sd_over_ctrl_iface = atoi(cmd);
  3875. return 0;
  3876. }
  3877. static int p2p_ctrl_service_add_bonjour(struct wpa_supplicant *wpa_s,
  3878. char *cmd)
  3879. {
  3880. char *pos;
  3881. size_t len;
  3882. struct wpabuf *query, *resp;
  3883. pos = os_strchr(cmd, ' ');
  3884. if (pos == NULL)
  3885. return -1;
  3886. *pos++ = '\0';
  3887. len = os_strlen(cmd);
  3888. if (len & 1)
  3889. return -1;
  3890. len /= 2;
  3891. query = wpabuf_alloc(len);
  3892. if (query == NULL)
  3893. return -1;
  3894. if (hexstr2bin(cmd, wpabuf_put(query, len), len) < 0) {
  3895. wpabuf_free(query);
  3896. return -1;
  3897. }
  3898. len = os_strlen(pos);
  3899. if (len & 1) {
  3900. wpabuf_free(query);
  3901. return -1;
  3902. }
  3903. len /= 2;
  3904. resp = wpabuf_alloc(len);
  3905. if (resp == NULL) {
  3906. wpabuf_free(query);
  3907. return -1;
  3908. }
  3909. if (hexstr2bin(pos, wpabuf_put(resp, len), len) < 0) {
  3910. wpabuf_free(query);
  3911. wpabuf_free(resp);
  3912. return -1;
  3913. }
  3914. if (wpas_p2p_service_add_bonjour(wpa_s, query, resp) < 0) {
  3915. wpabuf_free(query);
  3916. wpabuf_free(resp);
  3917. return -1;
  3918. }
  3919. return 0;
  3920. }
  3921. static int p2p_ctrl_service_add_upnp(struct wpa_supplicant *wpa_s, char *cmd)
  3922. {
  3923. char *pos;
  3924. u8 version;
  3925. pos = os_strchr(cmd, ' ');
  3926. if (pos == NULL)
  3927. return -1;
  3928. *pos++ = '\0';
  3929. if (hexstr2bin(cmd, &version, 1) < 0)
  3930. return -1;
  3931. return wpas_p2p_service_add_upnp(wpa_s, version, pos);
  3932. }
  3933. static int p2p_ctrl_service_add(struct wpa_supplicant *wpa_s, char *cmd)
  3934. {
  3935. char *pos;
  3936. pos = os_strchr(cmd, ' ');
  3937. if (pos == NULL)
  3938. return -1;
  3939. *pos++ = '\0';
  3940. if (os_strcmp(cmd, "bonjour") == 0)
  3941. return p2p_ctrl_service_add_bonjour(wpa_s, pos);
  3942. if (os_strcmp(cmd, "upnp") == 0)
  3943. return p2p_ctrl_service_add_upnp(wpa_s, pos);
  3944. wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd);
  3945. return -1;
  3946. }
  3947. static int p2p_ctrl_service_del_bonjour(struct wpa_supplicant *wpa_s,
  3948. char *cmd)
  3949. {
  3950. size_t len;
  3951. struct wpabuf *query;
  3952. int ret;
  3953. len = os_strlen(cmd);
  3954. if (len & 1)
  3955. return -1;
  3956. len /= 2;
  3957. query = wpabuf_alloc(len);
  3958. if (query == NULL)
  3959. return -1;
  3960. if (hexstr2bin(cmd, wpabuf_put(query, len), len) < 0) {
  3961. wpabuf_free(query);
  3962. return -1;
  3963. }
  3964. ret = wpas_p2p_service_del_bonjour(wpa_s, query);
  3965. wpabuf_free(query);
  3966. return ret;
  3967. }
  3968. static int p2p_ctrl_service_del_upnp(struct wpa_supplicant *wpa_s, char *cmd)
  3969. {
  3970. char *pos;
  3971. u8 version;
  3972. pos = os_strchr(cmd, ' ');
  3973. if (pos == NULL)
  3974. return -1;
  3975. *pos++ = '\0';
  3976. if (hexstr2bin(cmd, &version, 1) < 0)
  3977. return -1;
  3978. return wpas_p2p_service_del_upnp(wpa_s, version, pos);
  3979. }
  3980. static int p2p_ctrl_service_del(struct wpa_supplicant *wpa_s, char *cmd)
  3981. {
  3982. char *pos;
  3983. pos = os_strchr(cmd, ' ');
  3984. if (pos == NULL)
  3985. return -1;
  3986. *pos++ = '\0';
  3987. if (os_strcmp(cmd, "bonjour") == 0)
  3988. return p2p_ctrl_service_del_bonjour(wpa_s, pos);
  3989. if (os_strcmp(cmd, "upnp") == 0)
  3990. return p2p_ctrl_service_del_upnp(wpa_s, pos);
  3991. wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd);
  3992. return -1;
  3993. }
  3994. static int p2p_ctrl_reject(struct wpa_supplicant *wpa_s, char *cmd)
  3995. {
  3996. u8 addr[ETH_ALEN];
  3997. /* <addr> */
  3998. if (hwaddr_aton(cmd, addr))
  3999. return -1;
  4000. return wpas_p2p_reject(wpa_s, addr);
  4001. }
  4002. static int p2p_ctrl_invite_persistent(struct wpa_supplicant *wpa_s, char *cmd)
  4003. {
  4004. char *pos;
  4005. int id;
  4006. struct wpa_ssid *ssid;
  4007. u8 *_peer = NULL, peer[ETH_ALEN];
  4008. int freq = 0, pref_freq = 0;
  4009. int ht40, vht;
  4010. id = atoi(cmd);
  4011. pos = os_strstr(cmd, " peer=");
  4012. if (pos) {
  4013. pos += 6;
  4014. if (hwaddr_aton(pos, peer))
  4015. return -1;
  4016. _peer = peer;
  4017. }
  4018. ssid = wpa_config_get_network(wpa_s->conf, id);
  4019. if (ssid == NULL || ssid->disabled != 2) {
  4020. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
  4021. "for persistent P2P group",
  4022. id);
  4023. return -1;
  4024. }
  4025. pos = os_strstr(cmd, " freq=");
  4026. if (pos) {
  4027. pos += 6;
  4028. freq = atoi(pos);
  4029. if (freq <= 0)
  4030. return -1;
  4031. }
  4032. pos = os_strstr(cmd, " pref=");
  4033. if (pos) {
  4034. pos += 6;
  4035. pref_freq = atoi(pos);
  4036. if (pref_freq <= 0)
  4037. return -1;
  4038. }
  4039. vht = (os_strstr(cmd, " vht") != NULL) || wpa_s->conf->p2p_go_vht;
  4040. ht40 = (os_strstr(cmd, " ht40") != NULL) || wpa_s->conf->p2p_go_ht40 ||
  4041. vht;
  4042. return wpas_p2p_invite(wpa_s, _peer, ssid, NULL, freq, ht40, vht,
  4043. pref_freq);
  4044. }
  4045. static int p2p_ctrl_invite_group(struct wpa_supplicant *wpa_s, char *cmd)
  4046. {
  4047. char *pos;
  4048. u8 peer[ETH_ALEN], go_dev_addr[ETH_ALEN], *go_dev = NULL;
  4049. pos = os_strstr(cmd, " peer=");
  4050. if (!pos)
  4051. return -1;
  4052. *pos = '\0';
  4053. pos += 6;
  4054. if (hwaddr_aton(pos, peer)) {
  4055. wpa_printf(MSG_DEBUG, "P2P: Invalid MAC address '%s'", pos);
  4056. return -1;
  4057. }
  4058. pos = os_strstr(pos, " go_dev_addr=");
  4059. if (pos) {
  4060. pos += 13;
  4061. if (hwaddr_aton(pos, go_dev_addr)) {
  4062. wpa_printf(MSG_DEBUG, "P2P: Invalid MAC address '%s'",
  4063. pos);
  4064. return -1;
  4065. }
  4066. go_dev = go_dev_addr;
  4067. }
  4068. return wpas_p2p_invite_group(wpa_s, cmd, peer, go_dev);
  4069. }
  4070. static int p2p_ctrl_invite(struct wpa_supplicant *wpa_s, char *cmd)
  4071. {
  4072. if (os_strncmp(cmd, "persistent=", 11) == 0)
  4073. return p2p_ctrl_invite_persistent(wpa_s, cmd + 11);
  4074. if (os_strncmp(cmd, "group=", 6) == 0)
  4075. return p2p_ctrl_invite_group(wpa_s, cmd + 6);
  4076. return -1;
  4077. }
  4078. static int p2p_ctrl_group_add_persistent(struct wpa_supplicant *wpa_s,
  4079. char *cmd, int freq, int ht40,
  4080. int vht)
  4081. {
  4082. int id;
  4083. struct wpa_ssid *ssid;
  4084. id = atoi(cmd);
  4085. ssid = wpa_config_get_network(wpa_s->conf, id);
  4086. if (ssid == NULL || ssid->disabled != 2) {
  4087. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
  4088. "for persistent P2P group",
  4089. id);
  4090. return -1;
  4091. }
  4092. return wpas_p2p_group_add_persistent(wpa_s, ssid, 0, freq, 0, ht40, vht,
  4093. NULL, 0);
  4094. }
  4095. static int p2p_ctrl_group_add(struct wpa_supplicant *wpa_s, char *cmd)
  4096. {
  4097. int freq = 0, ht40, vht;
  4098. char *pos;
  4099. pos = os_strstr(cmd, "freq=");
  4100. if (pos)
  4101. freq = atoi(pos + 5);
  4102. vht = (os_strstr(cmd, "vht") != NULL) || wpa_s->conf->p2p_go_vht;
  4103. ht40 = (os_strstr(cmd, "ht40") != NULL) || wpa_s->conf->p2p_go_ht40 ||
  4104. vht;
  4105. if (os_strncmp(cmd, "persistent=", 11) == 0)
  4106. return p2p_ctrl_group_add_persistent(wpa_s, cmd + 11, freq,
  4107. ht40, vht);
  4108. if (os_strcmp(cmd, "persistent") == 0 ||
  4109. os_strncmp(cmd, "persistent ", 11) == 0)
  4110. return wpas_p2p_group_add(wpa_s, 1, freq, ht40, vht);
  4111. if (os_strncmp(cmd, "freq=", 5) == 0)
  4112. return wpas_p2p_group_add(wpa_s, 0, freq, ht40, vht);
  4113. if (ht40)
  4114. return wpas_p2p_group_add(wpa_s, 0, freq, ht40, vht);
  4115. wpa_printf(MSG_DEBUG, "CTRL: Invalid P2P_GROUP_ADD parameters '%s'",
  4116. cmd);
  4117. return -1;
  4118. }
  4119. static int p2p_ctrl_peer(struct wpa_supplicant *wpa_s, char *cmd,
  4120. char *buf, size_t buflen)
  4121. {
  4122. u8 addr[ETH_ALEN], *addr_ptr;
  4123. int next, res;
  4124. const struct p2p_peer_info *info;
  4125. char *pos, *end;
  4126. char devtype[WPS_DEV_TYPE_BUFSIZE];
  4127. struct wpa_ssid *ssid;
  4128. size_t i;
  4129. if (!wpa_s->global->p2p)
  4130. return -1;
  4131. if (os_strcmp(cmd, "FIRST") == 0) {
  4132. addr_ptr = NULL;
  4133. next = 0;
  4134. } else if (os_strncmp(cmd, "NEXT-", 5) == 0) {
  4135. if (hwaddr_aton(cmd + 5, addr) < 0)
  4136. return -1;
  4137. addr_ptr = addr;
  4138. next = 1;
  4139. } else {
  4140. if (hwaddr_aton(cmd, addr) < 0)
  4141. return -1;
  4142. addr_ptr = addr;
  4143. next = 0;
  4144. }
  4145. info = p2p_get_peer_info(wpa_s->global->p2p, addr_ptr, next);
  4146. if (info == NULL)
  4147. return -1;
  4148. pos = buf;
  4149. end = buf + buflen;
  4150. res = os_snprintf(pos, end - pos, MACSTR "\n"
  4151. "pri_dev_type=%s\n"
  4152. "device_name=%s\n"
  4153. "manufacturer=%s\n"
  4154. "model_name=%s\n"
  4155. "model_number=%s\n"
  4156. "serial_number=%s\n"
  4157. "config_methods=0x%x\n"
  4158. "dev_capab=0x%x\n"
  4159. "group_capab=0x%x\n"
  4160. "level=%d\n",
  4161. MAC2STR(info->p2p_device_addr),
  4162. wps_dev_type_bin2str(info->pri_dev_type,
  4163. devtype, sizeof(devtype)),
  4164. info->device_name,
  4165. info->manufacturer,
  4166. info->model_name,
  4167. info->model_number,
  4168. info->serial_number,
  4169. info->config_methods,
  4170. info->dev_capab,
  4171. info->group_capab,
  4172. info->level);
  4173. if (res < 0 || res >= end - pos)
  4174. return pos - buf;
  4175. pos += res;
  4176. for (i = 0; i < info->wps_sec_dev_type_list_len / WPS_DEV_TYPE_LEN; i++)
  4177. {
  4178. const u8 *t;
  4179. t = &info->wps_sec_dev_type_list[i * WPS_DEV_TYPE_LEN];
  4180. res = os_snprintf(pos, end - pos, "sec_dev_type=%s\n",
  4181. wps_dev_type_bin2str(t, devtype,
  4182. sizeof(devtype)));
  4183. if (res < 0 || res >= end - pos)
  4184. return pos - buf;
  4185. pos += res;
  4186. }
  4187. ssid = wpas_p2p_get_persistent(wpa_s, info->p2p_device_addr, NULL, 0);
  4188. if (ssid) {
  4189. res = os_snprintf(pos, end - pos, "persistent=%d\n", ssid->id);
  4190. if (res < 0 || res >= end - pos)
  4191. return pos - buf;
  4192. pos += res;
  4193. }
  4194. res = p2p_get_peer_info_txt(info, pos, end - pos);
  4195. if (res < 0)
  4196. return pos - buf;
  4197. pos += res;
  4198. if (info->vendor_elems) {
  4199. res = os_snprintf(pos, end - pos, "vendor_elems=");
  4200. if (res < 0 || res >= end - pos)
  4201. return pos - buf;
  4202. pos += res;
  4203. pos += wpa_snprintf_hex(pos, end - pos,
  4204. wpabuf_head(info->vendor_elems),
  4205. wpabuf_len(info->vendor_elems));
  4206. res = os_snprintf(pos, end - pos, "\n");
  4207. if (res < 0 || res >= end - pos)
  4208. return pos - buf;
  4209. pos += res;
  4210. }
  4211. return pos - buf;
  4212. }
  4213. static int p2p_ctrl_disallow_freq(struct wpa_supplicant *wpa_s,
  4214. const char *param)
  4215. {
  4216. unsigned int i;
  4217. if (wpa_s->global->p2p == NULL)
  4218. return -1;
  4219. if (freq_range_list_parse(&wpa_s->global->p2p_disallow_freq, param) < 0)
  4220. return -1;
  4221. for (i = 0; i < wpa_s->global->p2p_disallow_freq.num; i++) {
  4222. struct wpa_freq_range *freq;
  4223. freq = &wpa_s->global->p2p_disallow_freq.range[i];
  4224. wpa_printf(MSG_DEBUG, "P2P: Disallowed frequency range %u-%u",
  4225. freq->min, freq->max);
  4226. }
  4227. wpas_p2p_update_channel_list(wpa_s);
  4228. return 0;
  4229. }
  4230. static int p2p_ctrl_set(struct wpa_supplicant *wpa_s, char *cmd)
  4231. {
  4232. char *param;
  4233. if (wpa_s->global->p2p == NULL)
  4234. return -1;
  4235. param = os_strchr(cmd, ' ');
  4236. if (param == NULL)
  4237. return -1;
  4238. *param++ = '\0';
  4239. if (os_strcmp(cmd, "discoverability") == 0) {
  4240. p2p_set_client_discoverability(wpa_s->global->p2p,
  4241. atoi(param));
  4242. return 0;
  4243. }
  4244. if (os_strcmp(cmd, "managed") == 0) {
  4245. p2p_set_managed_oper(wpa_s->global->p2p, atoi(param));
  4246. return 0;
  4247. }
  4248. if (os_strcmp(cmd, "listen_channel") == 0) {
  4249. return p2p_set_listen_channel(wpa_s->global->p2p, 81,
  4250. atoi(param), 1);
  4251. }
  4252. if (os_strcmp(cmd, "ssid_postfix") == 0) {
  4253. return p2p_set_ssid_postfix(wpa_s->global->p2p, (u8 *) param,
  4254. os_strlen(param));
  4255. }
  4256. if (os_strcmp(cmd, "noa") == 0) {
  4257. char *pos;
  4258. int count, start, duration;
  4259. /* GO NoA parameters: count,start_offset(ms),duration(ms) */
  4260. count = atoi(param);
  4261. pos = os_strchr(param, ',');
  4262. if (pos == NULL)
  4263. return -1;
  4264. pos++;
  4265. start = atoi(pos);
  4266. pos = os_strchr(pos, ',');
  4267. if (pos == NULL)
  4268. return -1;
  4269. pos++;
  4270. duration = atoi(pos);
  4271. if (count < 0 || count > 255 || start < 0 || duration < 0)
  4272. return -1;
  4273. if (count == 0 && duration > 0)
  4274. return -1;
  4275. wpa_printf(MSG_DEBUG, "CTRL_IFACE: P2P_SET GO NoA: count=%d "
  4276. "start=%d duration=%d", count, start, duration);
  4277. return wpas_p2p_set_noa(wpa_s, count, start, duration);
  4278. }
  4279. if (os_strcmp(cmd, "ps") == 0)
  4280. return wpa_drv_set_p2p_powersave(wpa_s, atoi(param), -1, -1);
  4281. if (os_strcmp(cmd, "oppps") == 0)
  4282. return wpa_drv_set_p2p_powersave(wpa_s, -1, atoi(param), -1);
  4283. if (os_strcmp(cmd, "ctwindow") == 0)
  4284. return wpa_drv_set_p2p_powersave(wpa_s, -1, -1, atoi(param));
  4285. if (os_strcmp(cmd, "disabled") == 0) {
  4286. wpa_s->global->p2p_disabled = atoi(param);
  4287. wpa_printf(MSG_DEBUG, "P2P functionality %s",
  4288. wpa_s->global->p2p_disabled ?
  4289. "disabled" : "enabled");
  4290. if (wpa_s->global->p2p_disabled) {
  4291. wpas_p2p_stop_find(wpa_s);
  4292. os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN);
  4293. p2p_flush(wpa_s->global->p2p);
  4294. }
  4295. return 0;
  4296. }
  4297. if (os_strcmp(cmd, "conc_pref") == 0) {
  4298. if (os_strcmp(param, "sta") == 0)
  4299. wpa_s->global->conc_pref = WPA_CONC_PREF_STA;
  4300. else if (os_strcmp(param, "p2p") == 0)
  4301. wpa_s->global->conc_pref = WPA_CONC_PREF_P2P;
  4302. else {
  4303. wpa_printf(MSG_INFO, "Invalid conc_pref value");
  4304. return -1;
  4305. }
  4306. wpa_printf(MSG_DEBUG, "Single channel concurrency preference: "
  4307. "%s", param);
  4308. return 0;
  4309. }
  4310. if (os_strcmp(cmd, "force_long_sd") == 0) {
  4311. wpa_s->force_long_sd = atoi(param);
  4312. return 0;
  4313. }
  4314. if (os_strcmp(cmd, "peer_filter") == 0) {
  4315. u8 addr[ETH_ALEN];
  4316. if (hwaddr_aton(param, addr))
  4317. return -1;
  4318. p2p_set_peer_filter(wpa_s->global->p2p, addr);
  4319. return 0;
  4320. }
  4321. if (os_strcmp(cmd, "cross_connect") == 0)
  4322. return wpas_p2p_set_cross_connect(wpa_s, atoi(param));
  4323. if (os_strcmp(cmd, "go_apsd") == 0) {
  4324. if (os_strcmp(param, "disable") == 0)
  4325. wpa_s->set_ap_uapsd = 0;
  4326. else {
  4327. wpa_s->set_ap_uapsd = 1;
  4328. wpa_s->ap_uapsd = atoi(param);
  4329. }
  4330. return 0;
  4331. }
  4332. if (os_strcmp(cmd, "client_apsd") == 0) {
  4333. if (os_strcmp(param, "disable") == 0)
  4334. wpa_s->set_sta_uapsd = 0;
  4335. else {
  4336. int be, bk, vi, vo;
  4337. char *pos;
  4338. /* format: BE,BK,VI,VO;max SP Length */
  4339. be = atoi(param);
  4340. pos = os_strchr(param, ',');
  4341. if (pos == NULL)
  4342. return -1;
  4343. pos++;
  4344. bk = atoi(pos);
  4345. pos = os_strchr(pos, ',');
  4346. if (pos == NULL)
  4347. return -1;
  4348. pos++;
  4349. vi = atoi(pos);
  4350. pos = os_strchr(pos, ',');
  4351. if (pos == NULL)
  4352. return -1;
  4353. pos++;
  4354. vo = atoi(pos);
  4355. /* ignore max SP Length for now */
  4356. wpa_s->set_sta_uapsd = 1;
  4357. wpa_s->sta_uapsd = 0;
  4358. if (be)
  4359. wpa_s->sta_uapsd |= BIT(0);
  4360. if (bk)
  4361. wpa_s->sta_uapsd |= BIT(1);
  4362. if (vi)
  4363. wpa_s->sta_uapsd |= BIT(2);
  4364. if (vo)
  4365. wpa_s->sta_uapsd |= BIT(3);
  4366. }
  4367. return 0;
  4368. }
  4369. if (os_strcmp(cmd, "disallow_freq") == 0)
  4370. return p2p_ctrl_disallow_freq(wpa_s, param);
  4371. if (os_strcmp(cmd, "disc_int") == 0) {
  4372. int min_disc_int, max_disc_int, max_disc_tu;
  4373. char *pos;
  4374. pos = param;
  4375. min_disc_int = atoi(pos);
  4376. pos = os_strchr(pos, ' ');
  4377. if (pos == NULL)
  4378. return -1;
  4379. *pos++ = '\0';
  4380. max_disc_int = atoi(pos);
  4381. pos = os_strchr(pos, ' ');
  4382. if (pos == NULL)
  4383. return -1;
  4384. *pos++ = '\0';
  4385. max_disc_tu = atoi(pos);
  4386. return p2p_set_disc_int(wpa_s->global->p2p, min_disc_int,
  4387. max_disc_int, max_disc_tu);
  4388. }
  4389. if (os_strcmp(cmd, "per_sta_psk") == 0) {
  4390. wpa_s->global->p2p_per_sta_psk = !!atoi(param);
  4391. return 0;
  4392. }
  4393. #ifdef CONFIG_WPS_NFC
  4394. if (os_strcmp(cmd, "nfc_tag") == 0)
  4395. return wpas_p2p_nfc_tag_enabled(wpa_s, !!atoi(param));
  4396. #endif /* CONFIG_WPS_NFC */
  4397. if (os_strcmp(cmd, "disable_ip_addr_req") == 0) {
  4398. wpa_s->p2p_disable_ip_addr_req = !!atoi(param);
  4399. return 0;
  4400. }
  4401. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown P2P_SET field value '%s'",
  4402. cmd);
  4403. return -1;
  4404. }
  4405. static void p2p_ctrl_flush(struct wpa_supplicant *wpa_s)
  4406. {
  4407. os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN);
  4408. wpa_s->force_long_sd = 0;
  4409. wpas_p2p_stop_find(wpa_s);
  4410. if (wpa_s->global->p2p)
  4411. p2p_flush(wpa_s->global->p2p);
  4412. }
  4413. static int p2p_ctrl_presence_req(struct wpa_supplicant *wpa_s, char *cmd)
  4414. {
  4415. char *pos, *pos2;
  4416. unsigned int dur1 = 0, int1 = 0, dur2 = 0, int2 = 0;
  4417. if (cmd[0]) {
  4418. pos = os_strchr(cmd, ' ');
  4419. if (pos == NULL)
  4420. return -1;
  4421. *pos++ = '\0';
  4422. dur1 = atoi(cmd);
  4423. pos2 = os_strchr(pos, ' ');
  4424. if (pos2)
  4425. *pos2++ = '\0';
  4426. int1 = atoi(pos);
  4427. } else
  4428. pos2 = NULL;
  4429. if (pos2) {
  4430. pos = os_strchr(pos2, ' ');
  4431. if (pos == NULL)
  4432. return -1;
  4433. *pos++ = '\0';
  4434. dur2 = atoi(pos2);
  4435. int2 = atoi(pos);
  4436. }
  4437. return wpas_p2p_presence_req(wpa_s, dur1, int1, dur2, int2);
  4438. }
  4439. static int p2p_ctrl_ext_listen(struct wpa_supplicant *wpa_s, char *cmd)
  4440. {
  4441. char *pos;
  4442. unsigned int period = 0, interval = 0;
  4443. if (cmd[0]) {
  4444. pos = os_strchr(cmd, ' ');
  4445. if (pos == NULL)
  4446. return -1;
  4447. *pos++ = '\0';
  4448. period = atoi(cmd);
  4449. interval = atoi(pos);
  4450. }
  4451. return wpas_p2p_ext_listen(wpa_s, period, interval);
  4452. }
  4453. static int p2p_ctrl_remove_client(struct wpa_supplicant *wpa_s, const char *cmd)
  4454. {
  4455. const char *pos;
  4456. u8 peer[ETH_ALEN];
  4457. int iface_addr = 0;
  4458. pos = cmd;
  4459. if (os_strncmp(pos, "iface=", 6) == 0) {
  4460. iface_addr = 1;
  4461. pos += 6;
  4462. }
  4463. if (hwaddr_aton(pos, peer))
  4464. return -1;
  4465. wpas_p2p_remove_client(wpa_s, peer, iface_addr);
  4466. return 0;
  4467. }
  4468. #endif /* CONFIG_P2P */
  4469. static int * freq_range_to_channel_list(struct wpa_supplicant *wpa_s, char *val)
  4470. {
  4471. struct wpa_freq_range_list ranges;
  4472. int *freqs = NULL;
  4473. struct hostapd_hw_modes *mode;
  4474. u16 i;
  4475. if (wpa_s->hw.modes == NULL)
  4476. return NULL;
  4477. os_memset(&ranges, 0, sizeof(ranges));
  4478. if (freq_range_list_parse(&ranges, val) < 0)
  4479. return NULL;
  4480. for (i = 0; i < wpa_s->hw.num_modes; i++) {
  4481. int j;
  4482. mode = &wpa_s->hw.modes[i];
  4483. for (j = 0; j < mode->num_channels; j++) {
  4484. unsigned int freq;
  4485. if (mode->channels[j].flag & HOSTAPD_CHAN_DISABLED)
  4486. continue;
  4487. freq = mode->channels[j].freq;
  4488. if (!freq_range_list_includes(&ranges, freq))
  4489. continue;
  4490. int_array_add_unique(&freqs, freq);
  4491. }
  4492. }
  4493. os_free(ranges.range);
  4494. return freqs;
  4495. }
  4496. #ifdef CONFIG_INTERWORKING
  4497. static int ctrl_interworking_select(struct wpa_supplicant *wpa_s, char *param)
  4498. {
  4499. int auto_sel = 0;
  4500. int *freqs = NULL;
  4501. if (param) {
  4502. char *pos;
  4503. auto_sel = os_strstr(param, "auto") != NULL;
  4504. pos = os_strstr(param, "freq=");
  4505. if (pos) {
  4506. freqs = freq_range_to_channel_list(wpa_s, pos + 5);
  4507. if (freqs == NULL)
  4508. return -1;
  4509. }
  4510. }
  4511. return interworking_select(wpa_s, auto_sel, freqs);
  4512. }
  4513. static int ctrl_interworking_connect(struct wpa_supplicant *wpa_s, char *dst)
  4514. {
  4515. u8 bssid[ETH_ALEN];
  4516. struct wpa_bss *bss;
  4517. if (hwaddr_aton(dst, bssid)) {
  4518. wpa_printf(MSG_DEBUG, "Invalid BSSID '%s'", dst);
  4519. return -1;
  4520. }
  4521. bss = wpa_bss_get_bssid(wpa_s, bssid);
  4522. if (bss == NULL) {
  4523. wpa_printf(MSG_DEBUG, "Could not find BSS " MACSTR,
  4524. MAC2STR(bssid));
  4525. return -1;
  4526. }
  4527. return interworking_connect(wpa_s, bss);
  4528. }
  4529. static int get_anqp(struct wpa_supplicant *wpa_s, char *dst)
  4530. {
  4531. u8 dst_addr[ETH_ALEN];
  4532. int used;
  4533. char *pos;
  4534. #define MAX_ANQP_INFO_ID 100
  4535. u16 id[MAX_ANQP_INFO_ID];
  4536. size_t num_id = 0;
  4537. u32 subtypes = 0;
  4538. used = hwaddr_aton2(dst, dst_addr);
  4539. if (used < 0)
  4540. return -1;
  4541. pos = dst + used;
  4542. while (num_id < MAX_ANQP_INFO_ID) {
  4543. if (os_strncmp(pos, "hs20:", 5) == 0) {
  4544. #ifdef CONFIG_HS20
  4545. int num = atoi(pos + 5);
  4546. if (num <= 0 || num > 31)
  4547. return -1;
  4548. subtypes |= BIT(num);
  4549. #else /* CONFIG_HS20 */
  4550. return -1;
  4551. #endif /* CONFIG_HS20 */
  4552. } else {
  4553. id[num_id] = atoi(pos);
  4554. if (id[num_id])
  4555. num_id++;
  4556. }
  4557. pos = os_strchr(pos + 1, ',');
  4558. if (pos == NULL)
  4559. break;
  4560. pos++;
  4561. }
  4562. if (num_id == 0)
  4563. return -1;
  4564. return anqp_send_req(wpa_s, dst_addr, id, num_id, subtypes);
  4565. }
  4566. static int gas_request(struct wpa_supplicant *wpa_s, char *cmd)
  4567. {
  4568. u8 dst_addr[ETH_ALEN];
  4569. struct wpabuf *advproto, *query = NULL;
  4570. int used, ret = -1;
  4571. char *pos, *end;
  4572. size_t len;
  4573. used = hwaddr_aton2(cmd, dst_addr);
  4574. if (used < 0)
  4575. return -1;
  4576. pos = cmd + used;
  4577. while (*pos == ' ')
  4578. pos++;
  4579. /* Advertisement Protocol ID */
  4580. end = os_strchr(pos, ' ');
  4581. if (end)
  4582. len = end - pos;
  4583. else
  4584. len = os_strlen(pos);
  4585. if (len & 0x01)
  4586. return -1;
  4587. len /= 2;
  4588. if (len == 0)
  4589. return -1;
  4590. advproto = wpabuf_alloc(len);
  4591. if (advproto == NULL)
  4592. return -1;
  4593. if (hexstr2bin(pos, wpabuf_put(advproto, len), len) < 0)
  4594. goto fail;
  4595. if (end) {
  4596. /* Optional Query Request */
  4597. pos = end + 1;
  4598. while (*pos == ' ')
  4599. pos++;
  4600. len = os_strlen(pos);
  4601. if (len) {
  4602. if (len & 0x01)
  4603. goto fail;
  4604. len /= 2;
  4605. if (len == 0)
  4606. goto fail;
  4607. query = wpabuf_alloc(len);
  4608. if (query == NULL)
  4609. goto fail;
  4610. if (hexstr2bin(pos, wpabuf_put(query, len), len) < 0)
  4611. goto fail;
  4612. }
  4613. }
  4614. ret = gas_send_request(wpa_s, dst_addr, advproto, query);
  4615. fail:
  4616. wpabuf_free(advproto);
  4617. wpabuf_free(query);
  4618. return ret;
  4619. }
  4620. static int gas_response_get(struct wpa_supplicant *wpa_s, char *cmd, char *buf,
  4621. size_t buflen)
  4622. {
  4623. u8 addr[ETH_ALEN];
  4624. int dialog_token;
  4625. int used;
  4626. char *pos;
  4627. size_t resp_len, start, requested_len;
  4628. struct wpabuf *resp;
  4629. int ret;
  4630. used = hwaddr_aton2(cmd, addr);
  4631. if (used < 0)
  4632. return -1;
  4633. pos = cmd + used;
  4634. while (*pos == ' ')
  4635. pos++;
  4636. dialog_token = atoi(pos);
  4637. if (wpa_s->last_gas_resp &&
  4638. os_memcmp(addr, wpa_s->last_gas_addr, ETH_ALEN) == 0 &&
  4639. dialog_token == wpa_s->last_gas_dialog_token)
  4640. resp = wpa_s->last_gas_resp;
  4641. else if (wpa_s->prev_gas_resp &&
  4642. os_memcmp(addr, wpa_s->prev_gas_addr, ETH_ALEN) == 0 &&
  4643. dialog_token == wpa_s->prev_gas_dialog_token)
  4644. resp = wpa_s->prev_gas_resp;
  4645. else
  4646. return -1;
  4647. resp_len = wpabuf_len(resp);
  4648. start = 0;
  4649. requested_len = resp_len;
  4650. pos = os_strchr(pos, ' ');
  4651. if (pos) {
  4652. start = atoi(pos);
  4653. if (start > resp_len)
  4654. return os_snprintf(buf, buflen, "FAIL-Invalid range");
  4655. pos = os_strchr(pos, ',');
  4656. if (pos == NULL)
  4657. return -1;
  4658. pos++;
  4659. requested_len = atoi(pos);
  4660. if (start + requested_len > resp_len)
  4661. return os_snprintf(buf, buflen, "FAIL-Invalid range");
  4662. }
  4663. if (requested_len * 2 + 1 > buflen)
  4664. return os_snprintf(buf, buflen, "FAIL-Too long response");
  4665. ret = wpa_snprintf_hex(buf, buflen, wpabuf_head_u8(resp) + start,
  4666. requested_len);
  4667. if (start + requested_len == resp_len) {
  4668. /*
  4669. * Free memory by dropping the response after it has been
  4670. * fetched.
  4671. */
  4672. if (resp == wpa_s->prev_gas_resp) {
  4673. wpabuf_free(wpa_s->prev_gas_resp);
  4674. wpa_s->prev_gas_resp = NULL;
  4675. } else {
  4676. wpabuf_free(wpa_s->last_gas_resp);
  4677. wpa_s->last_gas_resp = NULL;
  4678. }
  4679. }
  4680. return ret;
  4681. }
  4682. #endif /* CONFIG_INTERWORKING */
  4683. #ifdef CONFIG_HS20
  4684. static int get_hs20_anqp(struct wpa_supplicant *wpa_s, char *dst)
  4685. {
  4686. u8 dst_addr[ETH_ALEN];
  4687. int used;
  4688. char *pos;
  4689. u32 subtypes = 0;
  4690. used = hwaddr_aton2(dst, dst_addr);
  4691. if (used < 0)
  4692. return -1;
  4693. pos = dst + used;
  4694. for (;;) {
  4695. int num = atoi(pos);
  4696. if (num <= 0 || num > 31)
  4697. return -1;
  4698. subtypes |= BIT(num);
  4699. pos = os_strchr(pos + 1, ',');
  4700. if (pos == NULL)
  4701. break;
  4702. pos++;
  4703. }
  4704. if (subtypes == 0)
  4705. return -1;
  4706. return hs20_anqp_send_req(wpa_s, dst_addr, subtypes, NULL, 0);
  4707. }
  4708. static int hs20_nai_home_realm_list(struct wpa_supplicant *wpa_s,
  4709. const u8 *addr, const char *realm)
  4710. {
  4711. u8 *buf;
  4712. size_t rlen, len;
  4713. int ret;
  4714. rlen = os_strlen(realm);
  4715. len = 3 + rlen;
  4716. buf = os_malloc(len);
  4717. if (buf == NULL)
  4718. return -1;
  4719. buf[0] = 1; /* NAI Home Realm Count */
  4720. buf[1] = 0; /* Formatted in accordance with RFC 4282 */
  4721. buf[2] = rlen;
  4722. os_memcpy(buf + 3, realm, rlen);
  4723. ret = hs20_anqp_send_req(wpa_s, addr,
  4724. BIT(HS20_STYPE_NAI_HOME_REALM_QUERY),
  4725. buf, len);
  4726. os_free(buf);
  4727. return ret;
  4728. }
  4729. static int hs20_get_nai_home_realm_list(struct wpa_supplicant *wpa_s,
  4730. char *dst)
  4731. {
  4732. struct wpa_cred *cred = wpa_s->conf->cred;
  4733. u8 dst_addr[ETH_ALEN];
  4734. int used;
  4735. u8 *buf;
  4736. size_t len;
  4737. int ret;
  4738. used = hwaddr_aton2(dst, dst_addr);
  4739. if (used < 0)
  4740. return -1;
  4741. while (dst[used] == ' ')
  4742. used++;
  4743. if (os_strncmp(dst + used, "realm=", 6) == 0)
  4744. return hs20_nai_home_realm_list(wpa_s, dst_addr,
  4745. dst + used + 6);
  4746. len = os_strlen(dst + used);
  4747. if (len == 0 && cred && cred->realm)
  4748. return hs20_nai_home_realm_list(wpa_s, dst_addr, cred->realm);
  4749. if (len & 1)
  4750. return -1;
  4751. len /= 2;
  4752. buf = os_malloc(len);
  4753. if (buf == NULL)
  4754. return -1;
  4755. if (hexstr2bin(dst + used, buf, len) < 0) {
  4756. os_free(buf);
  4757. return -1;
  4758. }
  4759. ret = hs20_anqp_send_req(wpa_s, dst_addr,
  4760. BIT(HS20_STYPE_NAI_HOME_REALM_QUERY),
  4761. buf, len);
  4762. os_free(buf);
  4763. return ret;
  4764. }
  4765. static int hs20_icon_request(struct wpa_supplicant *wpa_s, char *cmd)
  4766. {
  4767. u8 dst_addr[ETH_ALEN];
  4768. int used;
  4769. char *icon;
  4770. used = hwaddr_aton2(cmd, dst_addr);
  4771. if (used < 0)
  4772. return -1;
  4773. while (cmd[used] == ' ')
  4774. used++;
  4775. icon = &cmd[used];
  4776. wpa_s->fetch_osu_icon_in_progress = 0;
  4777. return hs20_anqp_send_req(wpa_s, dst_addr, BIT(HS20_STYPE_ICON_REQUEST),
  4778. (u8 *) icon, os_strlen(icon));
  4779. }
  4780. #endif /* CONFIG_HS20 */
  4781. static int wpa_supplicant_ctrl_iface_sta_autoconnect(
  4782. struct wpa_supplicant *wpa_s, char *cmd)
  4783. {
  4784. wpa_s->auto_reconnect_disabled = atoi(cmd) == 0 ? 1 : 0;
  4785. return 0;
  4786. }
  4787. #ifdef CONFIG_AUTOSCAN
  4788. static int wpa_supplicant_ctrl_iface_autoscan(struct wpa_supplicant *wpa_s,
  4789. char *cmd)
  4790. {
  4791. enum wpa_states state = wpa_s->wpa_state;
  4792. char *new_params = NULL;
  4793. if (os_strlen(cmd) > 0) {
  4794. new_params = os_strdup(cmd);
  4795. if (new_params == NULL)
  4796. return -1;
  4797. }
  4798. os_free(wpa_s->conf->autoscan);
  4799. wpa_s->conf->autoscan = new_params;
  4800. if (wpa_s->conf->autoscan == NULL)
  4801. autoscan_deinit(wpa_s);
  4802. else if (state == WPA_DISCONNECTED || state == WPA_INACTIVE)
  4803. autoscan_init(wpa_s, 1);
  4804. else if (state == WPA_SCANNING)
  4805. wpa_supplicant_reinit_autoscan(wpa_s);
  4806. return 0;
  4807. }
  4808. #endif /* CONFIG_AUTOSCAN */
  4809. #ifdef CONFIG_WNM
  4810. static int wpas_ctrl_iface_wnm_sleep(struct wpa_supplicant *wpa_s, char *cmd)
  4811. {
  4812. int enter;
  4813. int intval = 0;
  4814. char *pos;
  4815. int ret;
  4816. struct wpabuf *tfs_req = NULL;
  4817. if (os_strncmp(cmd, "enter", 5) == 0)
  4818. enter = 1;
  4819. else if (os_strncmp(cmd, "exit", 4) == 0)
  4820. enter = 0;
  4821. else
  4822. return -1;
  4823. pos = os_strstr(cmd, " interval=");
  4824. if (pos)
  4825. intval = atoi(pos + 10);
  4826. pos = os_strstr(cmd, " tfs_req=");
  4827. if (pos) {
  4828. char *end;
  4829. size_t len;
  4830. pos += 9;
  4831. end = os_strchr(pos, ' ');
  4832. if (end)
  4833. len = end - pos;
  4834. else
  4835. len = os_strlen(pos);
  4836. if (len & 1)
  4837. return -1;
  4838. len /= 2;
  4839. tfs_req = wpabuf_alloc(len);
  4840. if (tfs_req == NULL)
  4841. return -1;
  4842. if (hexstr2bin(pos, wpabuf_put(tfs_req, len), len) < 0) {
  4843. wpabuf_free(tfs_req);
  4844. return -1;
  4845. }
  4846. }
  4847. ret = ieee802_11_send_wnmsleep_req(wpa_s, enter ? WNM_SLEEP_MODE_ENTER :
  4848. WNM_SLEEP_MODE_EXIT, intval,
  4849. tfs_req);
  4850. wpabuf_free(tfs_req);
  4851. return ret;
  4852. }
  4853. static int wpas_ctrl_iface_wnm_bss_query(struct wpa_supplicant *wpa_s, char *cmd)
  4854. {
  4855. int query_reason;
  4856. query_reason = atoi(cmd);
  4857. wpa_printf(MSG_DEBUG, "CTRL_IFACE: WNM_BSS_QUERY query_reason=%d",
  4858. query_reason);
  4859. return wnm_send_bss_transition_mgmt_query(wpa_s, query_reason);
  4860. }
  4861. #endif /* CONFIG_WNM */
  4862. static int wpa_supplicant_signal_poll(struct wpa_supplicant *wpa_s, char *buf,
  4863. size_t buflen)
  4864. {
  4865. struct wpa_signal_info si;
  4866. int ret;
  4867. char *pos, *end;
  4868. ret = wpa_drv_signal_poll(wpa_s, &si);
  4869. if (ret)
  4870. return -1;
  4871. pos = buf;
  4872. end = buf + buflen;
  4873. ret = os_snprintf(pos, end - pos, "RSSI=%d\nLINKSPEED=%d\n"
  4874. "NOISE=%d\nFREQUENCY=%u\n",
  4875. si.current_signal, si.current_txrate / 1000,
  4876. si.current_noise, si.frequency);
  4877. if (ret < 0 || ret > end - pos)
  4878. return -1;
  4879. pos += ret;
  4880. if (si.chanwidth != CHAN_WIDTH_UNKNOWN) {
  4881. ret = os_snprintf(pos, end - pos, "WIDTH=%s\n",
  4882. channel_width_to_string(si.chanwidth));
  4883. if (ret < 0 || ret > end - pos)
  4884. return -1;
  4885. pos += ret;
  4886. }
  4887. if (si.center_frq1 > 0 && si.center_frq2 > 0) {
  4888. ret = os_snprintf(pos, end - pos,
  4889. "CENTER_FRQ1=%d\nCENTER_FRQ2=%d\n",
  4890. si.center_frq1, si.center_frq2);
  4891. if (ret < 0 || ret > end - pos)
  4892. return -1;
  4893. pos += ret;
  4894. }
  4895. if (si.avg_signal) {
  4896. ret = os_snprintf(pos, end - pos,
  4897. "AVG_RSSI=%d\n", si.avg_signal);
  4898. if (ret < 0 || ret >= end - pos)
  4899. return -1;
  4900. pos += ret;
  4901. }
  4902. return pos - buf;
  4903. }
  4904. static int wpa_supplicant_pktcnt_poll(struct wpa_supplicant *wpa_s, char *buf,
  4905. size_t buflen)
  4906. {
  4907. struct hostap_sta_driver_data sta;
  4908. int ret;
  4909. ret = wpa_drv_pktcnt_poll(wpa_s, &sta);
  4910. if (ret)
  4911. return -1;
  4912. ret = os_snprintf(buf, buflen, "TXGOOD=%lu\nTXBAD=%lu\nRXGOOD=%lu\n",
  4913. sta.tx_packets, sta.tx_retry_failed, sta.rx_packets);
  4914. if (ret < 0 || (size_t) ret > buflen)
  4915. return -1;
  4916. return ret;
  4917. }
  4918. #ifdef ANDROID
  4919. static int wpa_supplicant_driver_cmd(struct wpa_supplicant *wpa_s, char *cmd,
  4920. char *buf, size_t buflen)
  4921. {
  4922. int ret;
  4923. ret = wpa_drv_driver_cmd(wpa_s, cmd, buf, buflen);
  4924. if (ret == 0) {
  4925. if (os_strncasecmp(cmd, "COUNTRY", 7) == 0) {
  4926. struct p2p_data *p2p = wpa_s->global->p2p;
  4927. if (p2p) {
  4928. char country[3];
  4929. country[0] = cmd[8];
  4930. country[1] = cmd[9];
  4931. country[2] = 0x04;
  4932. p2p_set_country(p2p, country);
  4933. }
  4934. }
  4935. ret = os_snprintf(buf, buflen, "%s\n", "OK");
  4936. }
  4937. return ret;
  4938. }
  4939. #endif /* ANDROID */
  4940. static int wpa_supplicant_vendor_cmd(struct wpa_supplicant *wpa_s, char *cmd,
  4941. char *buf, size_t buflen)
  4942. {
  4943. int ret;
  4944. char *pos;
  4945. u8 *data = NULL;
  4946. unsigned int vendor_id, subcmd;
  4947. struct wpabuf *reply;
  4948. size_t data_len = 0;
  4949. /* cmd: <vendor id> <subcommand id> [<hex formatted data>] */
  4950. vendor_id = strtoul(cmd, &pos, 16);
  4951. if (!isblank(*pos))
  4952. return -EINVAL;
  4953. subcmd = strtoul(pos, &pos, 10);
  4954. if (*pos != '\0') {
  4955. if (!isblank(*pos++))
  4956. return -EINVAL;
  4957. data_len = os_strlen(pos);
  4958. }
  4959. if (data_len) {
  4960. data_len /= 2;
  4961. data = os_malloc(data_len);
  4962. if (!data)
  4963. return -1;
  4964. if (hexstr2bin(pos, data, data_len)) {
  4965. wpa_printf(MSG_DEBUG,
  4966. "Vendor command: wrong parameter format");
  4967. os_free(data);
  4968. return -EINVAL;
  4969. }
  4970. }
  4971. reply = wpabuf_alloc((buflen - 1) / 2);
  4972. if (!reply) {
  4973. os_free(data);
  4974. return -1;
  4975. }
  4976. ret = wpa_drv_vendor_cmd(wpa_s, vendor_id, subcmd, data, data_len,
  4977. reply);
  4978. if (ret == 0)
  4979. ret = wpa_snprintf_hex(buf, buflen, wpabuf_head_u8(reply),
  4980. wpabuf_len(reply));
  4981. wpabuf_free(reply);
  4982. os_free(data);
  4983. return ret;
  4984. }
  4985. static void wpa_supplicant_ctrl_iface_flush(struct wpa_supplicant *wpa_s)
  4986. {
  4987. wpa_dbg(wpa_s, MSG_DEBUG, "Flush all wpa_supplicant state");
  4988. #ifdef CONFIG_P2P
  4989. wpas_p2p_cancel(wpa_s);
  4990. wpas_p2p_stop_find(wpa_s);
  4991. p2p_ctrl_flush(wpa_s);
  4992. wpas_p2p_group_remove(wpa_s, "*");
  4993. wpas_p2p_service_flush(wpa_s);
  4994. wpa_s->global->p2p_disabled = 0;
  4995. wpa_s->global->p2p_per_sta_psk = 0;
  4996. wpa_s->conf->num_sec_device_types = 0;
  4997. wpa_s->p2p_disable_ip_addr_req = 0;
  4998. os_free(wpa_s->global->p2p_go_avoid_freq.range);
  4999. wpa_s->global->p2p_go_avoid_freq.range = NULL;
  5000. #endif /* CONFIG_P2P */
  5001. #ifdef CONFIG_WPS_TESTING
  5002. wps_version_number = 0x20;
  5003. wps_testing_dummy_cred = 0;
  5004. wps_corrupt_pkhash = 0;
  5005. #endif /* CONFIG_WPS_TESTING */
  5006. #ifdef CONFIG_WPS
  5007. wpa_s->wps_fragment_size = 0;
  5008. wpas_wps_cancel(wpa_s);
  5009. #endif /* CONFIG_WPS */
  5010. wpa_s->after_wps = 0;
  5011. wpa_s->known_wps_freq = 0;
  5012. #ifdef CONFIG_TDLS
  5013. #ifdef CONFIG_TDLS_TESTING
  5014. extern unsigned int tdls_testing;
  5015. tdls_testing = 0;
  5016. #endif /* CONFIG_TDLS_TESTING */
  5017. wpa_drv_tdls_oper(wpa_s, TDLS_ENABLE, NULL);
  5018. wpa_tdls_enable(wpa_s->wpa, 1);
  5019. #endif /* CONFIG_TDLS */
  5020. eloop_cancel_timeout(wpa_supplicant_stop_countermeasures, wpa_s, NULL);
  5021. wpa_supplicant_stop_countermeasures(wpa_s, NULL);
  5022. wpa_s->no_keep_alive = 0;
  5023. os_free(wpa_s->disallow_aps_bssid);
  5024. wpa_s->disallow_aps_bssid = NULL;
  5025. wpa_s->disallow_aps_bssid_count = 0;
  5026. os_free(wpa_s->disallow_aps_ssid);
  5027. wpa_s->disallow_aps_ssid = NULL;
  5028. wpa_s->disallow_aps_ssid_count = 0;
  5029. wpa_s->set_sta_uapsd = 0;
  5030. wpa_s->sta_uapsd = 0;
  5031. wpa_drv_radio_disable(wpa_s, 0);
  5032. wpa_bss_flush(wpa_s);
  5033. wpa_blacklist_clear(wpa_s);
  5034. wpa_s->extra_blacklist_count = 0;
  5035. wpa_supplicant_ctrl_iface_remove_network(wpa_s, "all");
  5036. wpa_supplicant_ctrl_iface_remove_cred(wpa_s, "all");
  5037. wpa_config_flush_blobs(wpa_s->conf);
  5038. wpa_s->conf->auto_interworking = 0;
  5039. wpa_s->conf->okc = 0;
  5040. wpa_sm_pmksa_cache_flush(wpa_s->wpa, NULL);
  5041. rsn_preauth_deinit(wpa_s->wpa);
  5042. wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_LIFETIME, 43200);
  5043. wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_REAUTH_THRESHOLD, 70);
  5044. wpa_sm_set_param(wpa_s->wpa, RSNA_SA_TIMEOUT, 60);
  5045. eapol_sm_notify_logoff(wpa_s->eapol, FALSE);
  5046. radio_remove_works(wpa_s, NULL, 1);
  5047. wpa_s->next_ssid = NULL;
  5048. #ifdef CONFIG_INTERWORKING
  5049. hs20_cancel_fetch_osu(wpa_s);
  5050. #endif /* CONFIG_INTERWORKING */
  5051. wpa_s->ext_mgmt_frame_handling = 0;
  5052. wpa_s->ext_eapol_frame_io = 0;
  5053. #ifdef CONFIG_TESTING_OPTIONS
  5054. wpa_s->extra_roc_dur = 0;
  5055. #endif /* CONFIG_TESTING_OPTIONS */
  5056. }
  5057. static int wpas_ctrl_radio_work_show(struct wpa_supplicant *wpa_s,
  5058. char *buf, size_t buflen)
  5059. {
  5060. struct wpa_radio_work *work;
  5061. char *pos, *end;
  5062. struct os_reltime now, diff;
  5063. pos = buf;
  5064. end = buf + buflen;
  5065. os_get_reltime(&now);
  5066. dl_list_for_each(work, &wpa_s->radio->work, struct wpa_radio_work, list)
  5067. {
  5068. int ret;
  5069. os_reltime_sub(&now, &work->time, &diff);
  5070. ret = os_snprintf(pos, end - pos, "%s@%s:%u:%u:%ld.%06ld\n",
  5071. work->type, work->wpa_s->ifname, work->freq,
  5072. work->started, diff.sec, diff.usec);
  5073. if (ret < 0 || ret >= end - pos)
  5074. break;
  5075. pos += ret;
  5076. }
  5077. return pos - buf;
  5078. }
  5079. static void wpas_ctrl_radio_work_timeout(void *eloop_ctx, void *timeout_ctx)
  5080. {
  5081. struct wpa_radio_work *work = eloop_ctx;
  5082. struct wpa_external_work *ework = work->ctx;
  5083. wpa_dbg(work->wpa_s, MSG_DEBUG,
  5084. "Timing out external radio work %u (%s)",
  5085. ework->id, work->type);
  5086. wpa_msg(work->wpa_s, MSG_INFO, EXT_RADIO_WORK_TIMEOUT "%u", ework->id);
  5087. radio_work_done(work);
  5088. os_free(ework);
  5089. }
  5090. static void wpas_ctrl_radio_work_cb(struct wpa_radio_work *work, int deinit)
  5091. {
  5092. struct wpa_external_work *ework = work->ctx;
  5093. if (deinit) {
  5094. if (work->started)
  5095. eloop_cancel_timeout(wpas_ctrl_radio_work_timeout,
  5096. work, NULL);
  5097. os_free(ework);
  5098. return;
  5099. }
  5100. wpa_dbg(work->wpa_s, MSG_DEBUG, "Starting external radio work %u (%s)",
  5101. ework->id, ework->type);
  5102. wpa_msg(work->wpa_s, MSG_INFO, EXT_RADIO_WORK_START "%u", ework->id);
  5103. if (!ework->timeout)
  5104. ework->timeout = 10;
  5105. eloop_register_timeout(ework->timeout, 0, wpas_ctrl_radio_work_timeout,
  5106. work, NULL);
  5107. }
  5108. static int wpas_ctrl_radio_work_add(struct wpa_supplicant *wpa_s, char *cmd,
  5109. char *buf, size_t buflen)
  5110. {
  5111. struct wpa_external_work *ework;
  5112. char *pos, *pos2;
  5113. size_t type_len;
  5114. int ret;
  5115. unsigned int freq = 0;
  5116. /* format: <name> [freq=<MHz>] [timeout=<seconds>] */
  5117. ework = os_zalloc(sizeof(*ework));
  5118. if (ework == NULL)
  5119. return -1;
  5120. pos = os_strchr(cmd, ' ');
  5121. if (pos) {
  5122. type_len = pos - cmd;
  5123. pos++;
  5124. pos2 = os_strstr(pos, "freq=");
  5125. if (pos2)
  5126. freq = atoi(pos2 + 5);
  5127. pos2 = os_strstr(pos, "timeout=");
  5128. if (pos2)
  5129. ework->timeout = atoi(pos2 + 8);
  5130. } else {
  5131. type_len = os_strlen(cmd);
  5132. }
  5133. if (4 + type_len >= sizeof(ework->type))
  5134. type_len = sizeof(ework->type) - 4 - 1;
  5135. os_strlcpy(ework->type, "ext:", sizeof(ework->type));
  5136. os_memcpy(ework->type + 4, cmd, type_len);
  5137. ework->type[4 + type_len] = '\0';
  5138. wpa_s->ext_work_id++;
  5139. if (wpa_s->ext_work_id == 0)
  5140. wpa_s->ext_work_id++;
  5141. ework->id = wpa_s->ext_work_id;
  5142. if (radio_add_work(wpa_s, freq, ework->type, 0, wpas_ctrl_radio_work_cb,
  5143. ework) < 0) {
  5144. os_free(ework);
  5145. return -1;
  5146. }
  5147. ret = os_snprintf(buf, buflen, "%u", ework->id);
  5148. if (ret < 0 || (size_t) ret >= buflen)
  5149. return -1;
  5150. return ret;
  5151. }
  5152. static int wpas_ctrl_radio_work_done(struct wpa_supplicant *wpa_s, char *cmd)
  5153. {
  5154. struct wpa_radio_work *work;
  5155. unsigned int id = atoi(cmd);
  5156. dl_list_for_each(work, &wpa_s->radio->work, struct wpa_radio_work, list)
  5157. {
  5158. struct wpa_external_work *ework;
  5159. if (os_strncmp(work->type, "ext:", 4) != 0)
  5160. continue;
  5161. ework = work->ctx;
  5162. if (id && ework->id != id)
  5163. continue;
  5164. wpa_dbg(wpa_s, MSG_DEBUG,
  5165. "Completed external radio work %u (%s)",
  5166. ework->id, ework->type);
  5167. eloop_cancel_timeout(wpas_ctrl_radio_work_timeout, work, NULL);
  5168. radio_work_done(work);
  5169. os_free(ework);
  5170. return 3; /* "OK\n" */
  5171. }
  5172. return -1;
  5173. }
  5174. static int wpas_ctrl_radio_work(struct wpa_supplicant *wpa_s, char *cmd,
  5175. char *buf, size_t buflen)
  5176. {
  5177. if (os_strcmp(cmd, "show") == 0)
  5178. return wpas_ctrl_radio_work_show(wpa_s, buf, buflen);
  5179. if (os_strncmp(cmd, "add ", 4) == 0)
  5180. return wpas_ctrl_radio_work_add(wpa_s, cmd + 4, buf, buflen);
  5181. if (os_strncmp(cmd, "done ", 5) == 0)
  5182. return wpas_ctrl_radio_work_done(wpa_s, cmd + 4);
  5183. return -1;
  5184. }
  5185. void wpas_ctrl_radio_work_flush(struct wpa_supplicant *wpa_s)
  5186. {
  5187. struct wpa_radio_work *work, *tmp;
  5188. if (!wpa_s || !wpa_s->radio)
  5189. return;
  5190. dl_list_for_each_safe(work, tmp, &wpa_s->radio->work,
  5191. struct wpa_radio_work, list) {
  5192. struct wpa_external_work *ework;
  5193. if (os_strncmp(work->type, "ext:", 4) != 0)
  5194. continue;
  5195. ework = work->ctx;
  5196. wpa_dbg(wpa_s, MSG_DEBUG,
  5197. "Flushing%s external radio work %u (%s)",
  5198. work->started ? " started" : "", ework->id,
  5199. ework->type);
  5200. if (work->started)
  5201. eloop_cancel_timeout(wpas_ctrl_radio_work_timeout,
  5202. work, NULL);
  5203. radio_work_done(work);
  5204. os_free(ework);
  5205. }
  5206. }
  5207. static void wpas_ctrl_eapol_response(void *eloop_ctx, void *timeout_ctx)
  5208. {
  5209. struct wpa_supplicant *wpa_s = eloop_ctx;
  5210. eapol_sm_notify_ctrl_response(wpa_s->eapol);
  5211. }
  5212. static int set_scan_freqs(struct wpa_supplicant *wpa_s, char *val)
  5213. {
  5214. int *freqs = NULL;
  5215. freqs = freq_range_to_channel_list(wpa_s, val);
  5216. if (freqs == NULL)
  5217. return -1;
  5218. os_free(wpa_s->manual_scan_freqs);
  5219. wpa_s->manual_scan_freqs = freqs;
  5220. return 0;
  5221. }
  5222. static int scan_id_list_parse(struct wpa_supplicant *wpa_s, const char *value)
  5223. {
  5224. const char *pos = value;
  5225. while (pos) {
  5226. if (*pos == ' ' || *pos == '\0')
  5227. break;
  5228. if (wpa_s->scan_id_count == MAX_SCAN_ID)
  5229. return -1;
  5230. wpa_s->scan_id[wpa_s->scan_id_count++] = atoi(pos);
  5231. pos = os_strchr(pos, ',');
  5232. if (pos)
  5233. pos++;
  5234. }
  5235. return 0;
  5236. }
  5237. static void wpas_ctrl_scan(struct wpa_supplicant *wpa_s, char *params,
  5238. char *reply, int reply_size, int *reply_len)
  5239. {
  5240. char *pos;
  5241. if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED) {
  5242. *reply_len = -1;
  5243. return;
  5244. }
  5245. wpa_s->manual_scan_passive = 0;
  5246. wpa_s->manual_scan_use_id = 0;
  5247. wpa_s->manual_scan_only_new = 0;
  5248. wpa_s->scan_id_count = 0;
  5249. if (params) {
  5250. if (os_strncasecmp(params, "TYPE=ONLY", 9) == 0)
  5251. wpa_s->scan_res_handler = scan_only_handler;
  5252. pos = os_strstr(params, "freq=");
  5253. if (pos && set_scan_freqs(wpa_s, pos + 5) < 0) {
  5254. *reply_len = -1;
  5255. return;
  5256. }
  5257. pos = os_strstr(params, "passive=");
  5258. if (pos)
  5259. wpa_s->manual_scan_passive = !!atoi(pos + 8);
  5260. pos = os_strstr(params, "use_id=");
  5261. if (pos)
  5262. wpa_s->manual_scan_use_id = atoi(pos + 7);
  5263. pos = os_strstr(params, "only_new=1");
  5264. if (pos)
  5265. wpa_s->manual_scan_only_new = 1;
  5266. pos = os_strstr(params, "scan_id=");
  5267. if (pos && scan_id_list_parse(wpa_s, pos + 8) < 0) {
  5268. *reply_len = -1;
  5269. return;
  5270. }
  5271. } else {
  5272. os_free(wpa_s->manual_scan_freqs);
  5273. wpa_s->manual_scan_freqs = NULL;
  5274. if (wpa_s->scan_res_handler == scan_only_handler)
  5275. wpa_s->scan_res_handler = NULL;
  5276. }
  5277. if (!wpa_s->sched_scanning && !wpa_s->scanning &&
  5278. ((wpa_s->wpa_state <= WPA_SCANNING) ||
  5279. (wpa_s->wpa_state == WPA_COMPLETED))) {
  5280. wpa_s->normal_scans = 0;
  5281. wpa_s->scan_req = MANUAL_SCAN_REQ;
  5282. wpa_s->after_wps = 0;
  5283. wpa_s->known_wps_freq = 0;
  5284. wpa_supplicant_req_scan(wpa_s, 0, 0);
  5285. if (wpa_s->manual_scan_use_id) {
  5286. wpa_s->manual_scan_id++;
  5287. wpa_dbg(wpa_s, MSG_DEBUG, "Assigned scan id %u",
  5288. wpa_s->manual_scan_id);
  5289. *reply_len = os_snprintf(reply, reply_size, "%u\n",
  5290. wpa_s->manual_scan_id);
  5291. }
  5292. } else if (wpa_s->sched_scanning) {
  5293. wpa_printf(MSG_DEBUG, "Stop ongoing sched_scan to allow requested full scan to proceed");
  5294. wpa_supplicant_cancel_sched_scan(wpa_s);
  5295. wpa_s->scan_req = MANUAL_SCAN_REQ;
  5296. wpa_supplicant_req_scan(wpa_s, 0, 0);
  5297. if (wpa_s->manual_scan_use_id) {
  5298. wpa_s->manual_scan_id++;
  5299. *reply_len = os_snprintf(reply, reply_size, "%u\n",
  5300. wpa_s->manual_scan_id);
  5301. wpa_dbg(wpa_s, MSG_DEBUG, "Assigned scan id %u",
  5302. wpa_s->manual_scan_id);
  5303. }
  5304. } else {
  5305. wpa_printf(MSG_DEBUG, "Ongoing scan action - reject new request");
  5306. *reply_len = os_snprintf(reply, reply_size, "FAIL-BUSY\n");
  5307. }
  5308. }
  5309. #ifdef CONFIG_TESTING_OPTIONS
  5310. static void wpas_ctrl_iface_mgmt_tx_cb(struct wpa_supplicant *wpa_s,
  5311. unsigned int freq, const u8 *dst,
  5312. const u8 *src, const u8 *bssid,
  5313. const u8 *data, size_t data_len,
  5314. enum offchannel_send_action_result
  5315. result)
  5316. {
  5317. wpa_msg(wpa_s, MSG_INFO, "MGMT-TX-STATUS freq=%u dst=" MACSTR
  5318. " src=" MACSTR " bssid=" MACSTR " result=%s",
  5319. freq, MAC2STR(dst), MAC2STR(src), MAC2STR(bssid),
  5320. result == OFFCHANNEL_SEND_ACTION_SUCCESS ?
  5321. "SUCCESS" : (result == OFFCHANNEL_SEND_ACTION_NO_ACK ?
  5322. "NO_ACK" : "FAILED"));
  5323. }
  5324. static int wpas_ctrl_iface_mgmt_tx(struct wpa_supplicant *wpa_s, char *cmd)
  5325. {
  5326. char *pos, *param;
  5327. size_t len;
  5328. u8 *buf, da[ETH_ALEN], bssid[ETH_ALEN];
  5329. int res, used;
  5330. int freq = 0, no_cck = 0, wait_time = 0;
  5331. /* <DA> <BSSID> [freq=<MHz>] [wait_time=<ms>] [no_cck=1]
  5332. * <action=Action frame payload> */
  5333. wpa_printf(MSG_DEBUG, "External MGMT TX: %s", cmd);
  5334. pos = cmd;
  5335. used = hwaddr_aton2(pos, da);
  5336. if (used < 0)
  5337. return -1;
  5338. pos += used;
  5339. while (*pos == ' ')
  5340. pos++;
  5341. used = hwaddr_aton2(pos, bssid);
  5342. if (used < 0)
  5343. return -1;
  5344. pos += used;
  5345. param = os_strstr(pos, " freq=");
  5346. if (param) {
  5347. param += 6;
  5348. freq = atoi(param);
  5349. }
  5350. param = os_strstr(pos, " no_cck=");
  5351. if (param) {
  5352. param += 8;
  5353. no_cck = atoi(param);
  5354. }
  5355. param = os_strstr(pos, " wait_time=");
  5356. if (param) {
  5357. param += 11;
  5358. wait_time = atoi(param);
  5359. }
  5360. param = os_strstr(pos, " action=");
  5361. if (param == NULL)
  5362. return -1;
  5363. param += 8;
  5364. len = os_strlen(param);
  5365. if (len & 1)
  5366. return -1;
  5367. len /= 2;
  5368. buf = os_malloc(len);
  5369. if (buf == NULL)
  5370. return -1;
  5371. if (hexstr2bin(param, buf, len) < 0) {
  5372. os_free(buf);
  5373. return -1;
  5374. }
  5375. res = offchannel_send_action(wpa_s, freq, da, wpa_s->own_addr, bssid,
  5376. buf, len, wait_time,
  5377. wpas_ctrl_iface_mgmt_tx_cb, no_cck);
  5378. os_free(buf);
  5379. return res;
  5380. }
  5381. static void wpas_ctrl_iface_mgmt_tx_done(struct wpa_supplicant *wpa_s)
  5382. {
  5383. wpa_printf(MSG_DEBUG, "External MGMT TX - done waiting");
  5384. offchannel_send_action_done(wpa_s);
  5385. }
  5386. static int wpas_ctrl_iface_driver_event(struct wpa_supplicant *wpa_s, char *cmd)
  5387. {
  5388. char *pos, *param;
  5389. union wpa_event_data event;
  5390. enum wpa_event_type ev;
  5391. /* <event name> [parameters..] */
  5392. wpa_dbg(wpa_s, MSG_DEBUG, "Testing - external driver event: %s", cmd);
  5393. pos = cmd;
  5394. param = os_strchr(pos, ' ');
  5395. if (param)
  5396. *param++ = '\0';
  5397. os_memset(&event, 0, sizeof(event));
  5398. if (os_strcmp(cmd, "INTERFACE_ENABLED") == 0) {
  5399. ev = EVENT_INTERFACE_ENABLED;
  5400. } else if (os_strcmp(cmd, "INTERFACE_DISABLED") == 0) {
  5401. ev = EVENT_INTERFACE_DISABLED;
  5402. } else if (os_strcmp(cmd, "AVOID_FREQUENCIES") == 0) {
  5403. ev = EVENT_AVOID_FREQUENCIES;
  5404. if (param == NULL)
  5405. param = "";
  5406. if (freq_range_list_parse(&event.freq_range, param) < 0)
  5407. return -1;
  5408. wpa_supplicant_event(wpa_s, ev, &event);
  5409. os_free(event.freq_range.range);
  5410. return 0;
  5411. } else {
  5412. wpa_dbg(wpa_s, MSG_DEBUG, "Testing - unknown driver event: %s",
  5413. cmd);
  5414. return -1;
  5415. }
  5416. wpa_supplicant_event(wpa_s, ev, &event);
  5417. return 0;
  5418. }
  5419. static int wpas_ctrl_iface_eapol_rx(struct wpa_supplicant *wpa_s, char *cmd)
  5420. {
  5421. char *pos;
  5422. u8 src[ETH_ALEN], *buf;
  5423. int used;
  5424. size_t len;
  5425. wpa_printf(MSG_DEBUG, "External EAPOL RX: %s", cmd);
  5426. pos = cmd;
  5427. used = hwaddr_aton2(pos, src);
  5428. if (used < 0)
  5429. return -1;
  5430. pos += used;
  5431. while (*pos == ' ')
  5432. pos++;
  5433. len = os_strlen(pos);
  5434. if (len & 1)
  5435. return -1;
  5436. len /= 2;
  5437. buf = os_malloc(len);
  5438. if (buf == NULL)
  5439. return -1;
  5440. if (hexstr2bin(pos, buf, len) < 0) {
  5441. os_free(buf);
  5442. return -1;
  5443. }
  5444. wpa_supplicant_rx_eapol(wpa_s, src, buf, len);
  5445. os_free(buf);
  5446. return 0;
  5447. }
  5448. static u16 ipv4_hdr_checksum(const void *buf, size_t len)
  5449. {
  5450. size_t i;
  5451. u32 sum = 0;
  5452. const u16 *pos = buf;
  5453. for (i = 0; i < len / 2; i++)
  5454. sum += *pos++;
  5455. while (sum >> 16)
  5456. sum = (sum & 0xffff) + (sum >> 16);
  5457. return sum ^ 0xffff;
  5458. }
  5459. #define HWSIM_PACKETLEN 1500
  5460. #define HWSIM_IP_LEN (HWSIM_PACKETLEN - sizeof(struct ether_header))
  5461. void wpas_data_test_rx(void *ctx, const u8 *src_addr, const u8 *buf, size_t len)
  5462. {
  5463. struct wpa_supplicant *wpa_s = ctx;
  5464. const struct ether_header *eth;
  5465. const struct iphdr *ip;
  5466. const u8 *pos;
  5467. unsigned int i;
  5468. if (len != HWSIM_PACKETLEN)
  5469. return;
  5470. eth = (const struct ether_header *) buf;
  5471. ip = (const struct iphdr *) (eth + 1);
  5472. pos = (const u8 *) (ip + 1);
  5473. if (ip->ihl != 5 || ip->version != 4 ||
  5474. ntohs(ip->tot_len) != HWSIM_IP_LEN)
  5475. return;
  5476. for (i = 0; i < HWSIM_IP_LEN - sizeof(*ip); i++) {
  5477. if (*pos != (u8) i)
  5478. return;
  5479. pos++;
  5480. }
  5481. wpa_msg(wpa_s, MSG_INFO, "DATA-TEST-RX " MACSTR " " MACSTR,
  5482. MAC2STR(eth->ether_dhost), MAC2STR(eth->ether_shost));
  5483. }
  5484. static int wpas_ctrl_iface_data_test_config(struct wpa_supplicant *wpa_s,
  5485. char *cmd)
  5486. {
  5487. int enabled = atoi(cmd);
  5488. if (!enabled) {
  5489. if (wpa_s->l2_test) {
  5490. l2_packet_deinit(wpa_s->l2_test);
  5491. wpa_s->l2_test = NULL;
  5492. wpa_dbg(wpa_s, MSG_DEBUG, "test data: Disabled");
  5493. }
  5494. return 0;
  5495. }
  5496. if (wpa_s->l2_test)
  5497. return 0;
  5498. wpa_s->l2_test = l2_packet_init(wpa_s->ifname, wpa_s->own_addr,
  5499. ETHERTYPE_IP, wpas_data_test_rx,
  5500. wpa_s, 1);
  5501. if (wpa_s->l2_test == NULL)
  5502. return -1;
  5503. wpa_dbg(wpa_s, MSG_DEBUG, "test data: Enabled");
  5504. return 0;
  5505. }
  5506. static int wpas_ctrl_iface_data_test_tx(struct wpa_supplicant *wpa_s, char *cmd)
  5507. {
  5508. u8 dst[ETH_ALEN], src[ETH_ALEN];
  5509. char *pos;
  5510. int used;
  5511. long int val;
  5512. u8 tos;
  5513. u8 buf[HWSIM_PACKETLEN];
  5514. struct ether_header *eth;
  5515. struct iphdr *ip;
  5516. u8 *dpos;
  5517. unsigned int i;
  5518. if (wpa_s->l2_test == NULL)
  5519. return -1;
  5520. /* format: <dst> <src> <tos> */
  5521. pos = cmd;
  5522. used = hwaddr_aton2(pos, dst);
  5523. if (used < 0)
  5524. return -1;
  5525. pos += used;
  5526. while (*pos == ' ')
  5527. pos++;
  5528. used = hwaddr_aton2(pos, src);
  5529. if (used < 0)
  5530. return -1;
  5531. pos += used;
  5532. val = strtol(pos, NULL, 0);
  5533. if (val < 0 || val > 0xff)
  5534. return -1;
  5535. tos = val;
  5536. eth = (struct ether_header *) buf;
  5537. os_memcpy(eth->ether_dhost, dst, ETH_ALEN);
  5538. os_memcpy(eth->ether_shost, src, ETH_ALEN);
  5539. eth->ether_type = htons(ETHERTYPE_IP);
  5540. ip = (struct iphdr *) (eth + 1);
  5541. os_memset(ip, 0, sizeof(*ip));
  5542. ip->ihl = 5;
  5543. ip->version = 4;
  5544. ip->ttl = 64;
  5545. ip->tos = tos;
  5546. ip->tot_len = htons(HWSIM_IP_LEN);
  5547. ip->protocol = 1;
  5548. ip->saddr = htonl(192 << 24 | 168 << 16 | 1 << 8 | 1);
  5549. ip->daddr = htonl(192 << 24 | 168 << 16 | 1 << 8 | 2);
  5550. ip->check = ipv4_hdr_checksum(ip, sizeof(*ip));
  5551. dpos = (u8 *) (ip + 1);
  5552. for (i = 0; i < HWSIM_IP_LEN - sizeof(*ip); i++)
  5553. *dpos++ = i;
  5554. if (l2_packet_send(wpa_s->l2_test, dst, ETHERTYPE_IP, buf,
  5555. HWSIM_PACKETLEN) < 0)
  5556. return -1;
  5557. wpa_dbg(wpa_s, MSG_DEBUG, "test data: TX dst=" MACSTR " src=" MACSTR
  5558. " tos=0x%x", MAC2STR(dst), MAC2STR(src), tos);
  5559. return 0;
  5560. }
  5561. static int wpas_ctrl_iface_data_test_frame(struct wpa_supplicant *wpa_s,
  5562. char *cmd)
  5563. {
  5564. u8 *buf;
  5565. struct ether_header *eth;
  5566. struct l2_packet_data *l2 = NULL;
  5567. size_t len;
  5568. u16 ethertype;
  5569. int res = -1;
  5570. len = os_strlen(cmd);
  5571. if (len & 1 || len < ETH_HLEN * 2)
  5572. return -1;
  5573. len /= 2;
  5574. buf = os_malloc(len);
  5575. if (buf == NULL)
  5576. return -1;
  5577. if (hexstr2bin(cmd, buf, len) < 0)
  5578. goto done;
  5579. eth = (struct ether_header *) buf;
  5580. ethertype = ntohs(eth->ether_type);
  5581. l2 = l2_packet_init(wpa_s->ifname, wpa_s->own_addr, ethertype,
  5582. wpas_data_test_rx, wpa_s, 1);
  5583. if (l2 == NULL)
  5584. goto done;
  5585. res = l2_packet_send(l2, eth->ether_dhost, ethertype, buf, len);
  5586. wpa_dbg(wpa_s, MSG_DEBUG, "test data: TX frame res=%d", res);
  5587. done:
  5588. if (l2)
  5589. l2_packet_deinit(l2);
  5590. os_free(buf);
  5591. return res < 0 ? -1 : 0;
  5592. }
  5593. #endif /* CONFIG_TESTING_OPTIONS */
  5594. static void wpas_ctrl_vendor_elem_update(struct wpa_supplicant *wpa_s)
  5595. {
  5596. unsigned int i;
  5597. char buf[30];
  5598. wpa_printf(MSG_DEBUG, "Update vendor elements");
  5599. for (i = 0; i < NUM_VENDOR_ELEM_FRAMES; i++) {
  5600. if (wpa_s->vendor_elem[i]) {
  5601. os_snprintf(buf, sizeof(buf), "frame[%u]", i);
  5602. wpa_hexdump_buf(MSG_DEBUG, buf, wpa_s->vendor_elem[i]);
  5603. }
  5604. }
  5605. #ifdef CONFIG_P2P
  5606. if (wpa_s->parent == wpa_s &&
  5607. wpa_s->global->p2p &&
  5608. !wpa_s->global->p2p_disabled)
  5609. p2p_set_vendor_elems(wpa_s->global->p2p, wpa_s->vendor_elem);
  5610. #endif /* CONFIG_P2P */
  5611. }
  5612. static struct wpa_supplicant *
  5613. wpas_ctrl_vendor_elem_iface(struct wpa_supplicant *wpa_s,
  5614. enum wpa_vendor_elem_frame frame)
  5615. {
  5616. switch (frame) {
  5617. #ifdef CONFIG_P2P
  5618. case VENDOR_ELEM_PROBE_REQ_P2P:
  5619. case VENDOR_ELEM_PROBE_RESP_P2P:
  5620. case VENDOR_ELEM_PROBE_RESP_P2P_GO:
  5621. case VENDOR_ELEM_BEACON_P2P_GO:
  5622. case VENDOR_ELEM_P2P_PD_REQ:
  5623. case VENDOR_ELEM_P2P_PD_RESP:
  5624. case VENDOR_ELEM_P2P_GO_NEG_REQ:
  5625. case VENDOR_ELEM_P2P_GO_NEG_RESP:
  5626. case VENDOR_ELEM_P2P_GO_NEG_CONF:
  5627. case VENDOR_ELEM_P2P_INV_REQ:
  5628. case VENDOR_ELEM_P2P_INV_RESP:
  5629. case VENDOR_ELEM_P2P_ASSOC_REQ:
  5630. return wpa_s->parent;
  5631. #endif /* CONFIG_P2P */
  5632. default:
  5633. return wpa_s;
  5634. }
  5635. }
  5636. static int wpas_ctrl_vendor_elem_add(struct wpa_supplicant *wpa_s, char *cmd)
  5637. {
  5638. char *pos = cmd;
  5639. int frame;
  5640. size_t len;
  5641. struct wpabuf *buf;
  5642. struct ieee802_11_elems elems;
  5643. frame = atoi(pos);
  5644. if (frame < 0 || frame >= NUM_VENDOR_ELEM_FRAMES)
  5645. return -1;
  5646. wpa_s = wpas_ctrl_vendor_elem_iface(wpa_s, frame);
  5647. pos = os_strchr(pos, ' ');
  5648. if (pos == NULL)
  5649. return -1;
  5650. pos++;
  5651. len = os_strlen(pos);
  5652. if (len == 0)
  5653. return 0;
  5654. if (len & 1)
  5655. return -1;
  5656. len /= 2;
  5657. buf = wpabuf_alloc(len);
  5658. if (buf == NULL)
  5659. return -1;
  5660. if (hexstr2bin(pos, wpabuf_put(buf, len), len) < 0) {
  5661. wpabuf_free(buf);
  5662. return -1;
  5663. }
  5664. if (ieee802_11_parse_elems(wpabuf_head_u8(buf), len, &elems, 0) ==
  5665. ParseFailed) {
  5666. wpabuf_free(buf);
  5667. return -1;
  5668. }
  5669. if (wpa_s->vendor_elem[frame] == NULL) {
  5670. wpa_s->vendor_elem[frame] = buf;
  5671. wpas_ctrl_vendor_elem_update(wpa_s);
  5672. return 0;
  5673. }
  5674. if (wpabuf_resize(&wpa_s->vendor_elem[frame], len) < 0) {
  5675. wpabuf_free(buf);
  5676. return -1;
  5677. }
  5678. wpabuf_put_buf(wpa_s->vendor_elem[frame], buf);
  5679. wpabuf_free(buf);
  5680. wpas_ctrl_vendor_elem_update(wpa_s);
  5681. return 0;
  5682. }
  5683. static int wpas_ctrl_vendor_elem_get(struct wpa_supplicant *wpa_s, char *cmd,
  5684. char *buf, size_t buflen)
  5685. {
  5686. int frame = atoi(cmd);
  5687. if (frame < 0 || frame >= NUM_VENDOR_ELEM_FRAMES)
  5688. return -1;
  5689. wpa_s = wpas_ctrl_vendor_elem_iface(wpa_s, frame);
  5690. if (wpa_s->vendor_elem[frame] == NULL)
  5691. return 0;
  5692. return wpa_snprintf_hex(buf, buflen,
  5693. wpabuf_head_u8(wpa_s->vendor_elem[frame]),
  5694. wpabuf_len(wpa_s->vendor_elem[frame]));
  5695. }
  5696. static int wpas_ctrl_vendor_elem_remove(struct wpa_supplicant *wpa_s, char *cmd)
  5697. {
  5698. char *pos = cmd;
  5699. int frame;
  5700. size_t len;
  5701. u8 *buf;
  5702. struct ieee802_11_elems elems;
  5703. u8 *ie, *end;
  5704. frame = atoi(pos);
  5705. if (frame < 0 || frame >= NUM_VENDOR_ELEM_FRAMES)
  5706. return -1;
  5707. wpa_s = wpas_ctrl_vendor_elem_iface(wpa_s, frame);
  5708. pos = os_strchr(pos, ' ');
  5709. if (pos == NULL)
  5710. return -1;
  5711. pos++;
  5712. if (*pos == '*') {
  5713. wpabuf_free(wpa_s->vendor_elem[frame]);
  5714. wpa_s->vendor_elem[frame] = NULL;
  5715. wpas_ctrl_vendor_elem_update(wpa_s);
  5716. return 0;
  5717. }
  5718. if (wpa_s->vendor_elem[frame] == NULL)
  5719. return -1;
  5720. len = os_strlen(pos);
  5721. if (len == 0)
  5722. return 0;
  5723. if (len & 1)
  5724. return -1;
  5725. len /= 2;
  5726. buf = os_malloc(len);
  5727. if (buf == NULL)
  5728. return -1;
  5729. if (hexstr2bin(pos, buf, len) < 0) {
  5730. os_free(buf);
  5731. return -1;
  5732. }
  5733. if (ieee802_11_parse_elems(buf, len, &elems, 0) == ParseFailed) {
  5734. os_free(buf);
  5735. return -1;
  5736. }
  5737. ie = wpabuf_mhead_u8(wpa_s->vendor_elem[frame]);
  5738. end = ie + wpabuf_len(wpa_s->vendor_elem[frame]);
  5739. for (; ie + 1 < end; ie += 2 + ie[1]) {
  5740. if (ie + len > end)
  5741. break;
  5742. if (os_memcmp(ie, buf, len) != 0)
  5743. continue;
  5744. if (wpabuf_len(wpa_s->vendor_elem[frame]) == len) {
  5745. wpabuf_free(wpa_s->vendor_elem[frame]);
  5746. wpa_s->vendor_elem[frame] = NULL;
  5747. } else {
  5748. os_memmove(ie, ie + len,
  5749. end - (ie + len));
  5750. wpa_s->vendor_elem[frame]->used -= len;
  5751. }
  5752. os_free(buf);
  5753. wpas_ctrl_vendor_elem_update(wpa_s);
  5754. return 0;
  5755. }
  5756. os_free(buf);
  5757. return -1;
  5758. }
  5759. static void wpas_ctrl_neighbor_rep_cb(void *ctx, struct wpabuf *neighbor_rep)
  5760. {
  5761. struct wpa_supplicant *wpa_s = ctx;
  5762. if (neighbor_rep) {
  5763. wpa_msg_ctrl(wpa_s, MSG_INFO, RRM_EVENT_NEIGHBOR_REP_RXED
  5764. "length=%u",
  5765. (unsigned int) wpabuf_len(neighbor_rep));
  5766. wpabuf_free(neighbor_rep);
  5767. } else {
  5768. wpa_msg_ctrl(wpa_s, MSG_INFO, RRM_EVENT_NEIGHBOR_REP_FAILED);
  5769. }
  5770. }
  5771. static int wpas_ctrl_iface_send_neigbor_rep(struct wpa_supplicant *wpa_s,
  5772. char *cmd)
  5773. {
  5774. struct wpa_ssid ssid;
  5775. struct wpa_ssid *ssid_p = NULL;
  5776. int ret = 0;
  5777. if (os_strncmp(cmd, " ssid=", 6) == 0) {
  5778. ssid.ssid_len = os_strlen(cmd + 6);
  5779. if (ssid.ssid_len > 32)
  5780. return -1;
  5781. ssid.ssid = (u8 *) (cmd + 6);
  5782. ssid_p = &ssid;
  5783. }
  5784. ret = wpas_rrm_send_neighbor_rep_request(wpa_s, ssid_p,
  5785. wpas_ctrl_neighbor_rep_cb,
  5786. wpa_s);
  5787. return ret;
  5788. }
  5789. char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s,
  5790. char *buf, size_t *resp_len)
  5791. {
  5792. char *reply;
  5793. const int reply_size = 4096;
  5794. int reply_len;
  5795. if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0 ||
  5796. os_strncmp(buf, "SET_NETWORK ", 12) == 0) {
  5797. if (wpa_debug_show_keys)
  5798. wpa_dbg(wpa_s, MSG_DEBUG,
  5799. "Control interface command '%s'", buf);
  5800. else
  5801. wpa_dbg(wpa_s, MSG_DEBUG,
  5802. "Control interface command '%s [REMOVED]'",
  5803. os_strncmp(buf, WPA_CTRL_RSP,
  5804. os_strlen(WPA_CTRL_RSP)) == 0 ?
  5805. WPA_CTRL_RSP : "SET_NETWORK");
  5806. } else if (os_strncmp(buf, "WPS_NFC_TAG_READ", 16) == 0 ||
  5807. os_strncmp(buf, "NFC_REPORT_HANDOVER", 19) == 0) {
  5808. wpa_hexdump_ascii_key(MSG_DEBUG, "RX ctrl_iface",
  5809. (const u8 *) buf, os_strlen(buf));
  5810. } else {
  5811. int level = MSG_DEBUG;
  5812. if (os_strcmp(buf, "PING") == 0)
  5813. level = MSG_EXCESSIVE;
  5814. wpa_dbg(wpa_s, level, "Control interface command '%s'", buf);
  5815. }
  5816. reply = os_malloc(reply_size);
  5817. if (reply == NULL) {
  5818. *resp_len = 1;
  5819. return NULL;
  5820. }
  5821. os_memcpy(reply, "OK\n", 3);
  5822. reply_len = 3;
  5823. if (os_strcmp(buf, "PING") == 0) {
  5824. os_memcpy(reply, "PONG\n", 5);
  5825. reply_len = 5;
  5826. } else if (os_strcmp(buf, "IFNAME") == 0) {
  5827. reply_len = os_strlen(wpa_s->ifname);
  5828. os_memcpy(reply, wpa_s->ifname, reply_len);
  5829. } else if (os_strncmp(buf, "RELOG", 5) == 0) {
  5830. if (wpa_debug_reopen_file() < 0)
  5831. reply_len = -1;
  5832. } else if (os_strncmp(buf, "NOTE ", 5) == 0) {
  5833. wpa_printf(MSG_INFO, "NOTE: %s", buf + 5);
  5834. } else if (os_strcmp(buf, "MIB") == 0) {
  5835. reply_len = wpa_sm_get_mib(wpa_s->wpa, reply, reply_size);
  5836. if (reply_len >= 0) {
  5837. int res;
  5838. res = eapol_sm_get_mib(wpa_s->eapol, reply + reply_len,
  5839. reply_size - reply_len);
  5840. if (res < 0)
  5841. reply_len = -1;
  5842. else
  5843. reply_len += res;
  5844. }
  5845. } else if (os_strncmp(buf, "STATUS", 6) == 0) {
  5846. reply_len = wpa_supplicant_ctrl_iface_status(
  5847. wpa_s, buf + 6, reply, reply_size);
  5848. } else if (os_strcmp(buf, "PMKSA") == 0) {
  5849. reply_len = wpa_sm_pmksa_cache_list(wpa_s->wpa, reply,
  5850. reply_size);
  5851. } else if (os_strcmp(buf, "PMKSA_FLUSH") == 0) {
  5852. wpa_sm_pmksa_cache_flush(wpa_s->wpa, NULL);
  5853. } else if (os_strncmp(buf, "SET ", 4) == 0) {
  5854. if (wpa_supplicant_ctrl_iface_set(wpa_s, buf + 4))
  5855. reply_len = -1;
  5856. } else if (os_strncmp(buf, "GET ", 4) == 0) {
  5857. reply_len = wpa_supplicant_ctrl_iface_get(wpa_s, buf + 4,
  5858. reply, reply_size);
  5859. } else if (os_strcmp(buf, "LOGON") == 0) {
  5860. eapol_sm_notify_logoff(wpa_s->eapol, FALSE);
  5861. } else if (os_strcmp(buf, "LOGOFF") == 0) {
  5862. eapol_sm_notify_logoff(wpa_s->eapol, TRUE);
  5863. } else if (os_strcmp(buf, "REASSOCIATE") == 0) {
  5864. if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
  5865. reply_len = -1;
  5866. else
  5867. wpas_request_connection(wpa_s);
  5868. } else if (os_strcmp(buf, "REATTACH") == 0) {
  5869. if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED ||
  5870. !wpa_s->current_ssid)
  5871. reply_len = -1;
  5872. else {
  5873. wpa_s->reattach = 1;
  5874. wpas_request_connection(wpa_s);
  5875. }
  5876. } else if (os_strcmp(buf, "RECONNECT") == 0) {
  5877. if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
  5878. reply_len = -1;
  5879. else if (wpa_s->disconnected)
  5880. wpas_request_connection(wpa_s);
  5881. #ifdef IEEE8021X_EAPOL
  5882. } else if (os_strncmp(buf, "PREAUTH ", 8) == 0) {
  5883. if (wpa_supplicant_ctrl_iface_preauth(wpa_s, buf + 8))
  5884. reply_len = -1;
  5885. #endif /* IEEE8021X_EAPOL */
  5886. #ifdef CONFIG_PEERKEY
  5887. } else if (os_strncmp(buf, "STKSTART ", 9) == 0) {
  5888. if (wpa_supplicant_ctrl_iface_stkstart(wpa_s, buf + 9))
  5889. reply_len = -1;
  5890. #endif /* CONFIG_PEERKEY */
  5891. #ifdef CONFIG_IEEE80211R
  5892. } else if (os_strncmp(buf, "FT_DS ", 6) == 0) {
  5893. if (wpa_supplicant_ctrl_iface_ft_ds(wpa_s, buf + 6))
  5894. reply_len = -1;
  5895. #endif /* CONFIG_IEEE80211R */
  5896. #ifdef CONFIG_WPS
  5897. } else if (os_strcmp(buf, "WPS_PBC") == 0) {
  5898. int res = wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, NULL);
  5899. if (res == -2) {
  5900. os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
  5901. reply_len = 17;
  5902. } else if (res)
  5903. reply_len = -1;
  5904. } else if (os_strncmp(buf, "WPS_PBC ", 8) == 0) {
  5905. int res = wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, buf + 8);
  5906. if (res == -2) {
  5907. os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
  5908. reply_len = 17;
  5909. } else if (res)
  5910. reply_len = -1;
  5911. } else if (os_strncmp(buf, "WPS_PIN ", 8) == 0) {
  5912. reply_len = wpa_supplicant_ctrl_iface_wps_pin(wpa_s, buf + 8,
  5913. reply,
  5914. reply_size);
  5915. } else if (os_strncmp(buf, "WPS_CHECK_PIN ", 14) == 0) {
  5916. reply_len = wpa_supplicant_ctrl_iface_wps_check_pin(
  5917. wpa_s, buf + 14, reply, reply_size);
  5918. } else if (os_strcmp(buf, "WPS_CANCEL") == 0) {
  5919. if (wpas_wps_cancel(wpa_s))
  5920. reply_len = -1;
  5921. #ifdef CONFIG_WPS_NFC
  5922. } else if (os_strcmp(buf, "WPS_NFC") == 0) {
  5923. if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s, NULL))
  5924. reply_len = -1;
  5925. } else if (os_strncmp(buf, "WPS_NFC ", 8) == 0) {
  5926. if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s, buf + 8))
  5927. reply_len = -1;
  5928. } else if (os_strncmp(buf, "WPS_NFC_CONFIG_TOKEN ", 21) == 0) {
  5929. reply_len = wpa_supplicant_ctrl_iface_wps_nfc_config_token(
  5930. wpa_s, buf + 21, reply, reply_size);
  5931. } else if (os_strncmp(buf, "WPS_NFC_TOKEN ", 14) == 0) {
  5932. reply_len = wpa_supplicant_ctrl_iface_wps_nfc_token(
  5933. wpa_s, buf + 14, reply, reply_size);
  5934. } else if (os_strncmp(buf, "WPS_NFC_TAG_READ ", 17) == 0) {
  5935. if (wpa_supplicant_ctrl_iface_wps_nfc_tag_read(wpa_s,
  5936. buf + 17))
  5937. reply_len = -1;
  5938. } else if (os_strncmp(buf, "NFC_GET_HANDOVER_REQ ", 21) == 0) {
  5939. reply_len = wpas_ctrl_nfc_get_handover_req(
  5940. wpa_s, buf + 21, reply, reply_size);
  5941. } else if (os_strncmp(buf, "NFC_GET_HANDOVER_SEL ", 21) == 0) {
  5942. reply_len = wpas_ctrl_nfc_get_handover_sel(
  5943. wpa_s, buf + 21, reply, reply_size);
  5944. } else if (os_strncmp(buf, "NFC_REPORT_HANDOVER ", 20) == 0) {
  5945. if (wpas_ctrl_nfc_report_handover(wpa_s, buf + 20))
  5946. reply_len = -1;
  5947. #endif /* CONFIG_WPS_NFC */
  5948. } else if (os_strncmp(buf, "WPS_REG ", 8) == 0) {
  5949. if (wpa_supplicant_ctrl_iface_wps_reg(wpa_s, buf + 8))
  5950. reply_len = -1;
  5951. #ifdef CONFIG_AP
  5952. } else if (os_strncmp(buf, "WPS_AP_PIN ", 11) == 0) {
  5953. reply_len = wpa_supplicant_ctrl_iface_wps_ap_pin(
  5954. wpa_s, buf + 11, reply, reply_size);
  5955. #endif /* CONFIG_AP */
  5956. #ifdef CONFIG_WPS_ER
  5957. } else if (os_strcmp(buf, "WPS_ER_START") == 0) {
  5958. if (wpas_wps_er_start(wpa_s, NULL))
  5959. reply_len = -1;
  5960. } else if (os_strncmp(buf, "WPS_ER_START ", 13) == 0) {
  5961. if (wpas_wps_er_start(wpa_s, buf + 13))
  5962. reply_len = -1;
  5963. } else if (os_strcmp(buf, "WPS_ER_STOP") == 0) {
  5964. if (wpas_wps_er_stop(wpa_s))
  5965. reply_len = -1;
  5966. } else if (os_strncmp(buf, "WPS_ER_PIN ", 11) == 0) {
  5967. if (wpa_supplicant_ctrl_iface_wps_er_pin(wpa_s, buf + 11))
  5968. reply_len = -1;
  5969. } else if (os_strncmp(buf, "WPS_ER_PBC ", 11) == 0) {
  5970. int ret = wpas_wps_er_pbc(wpa_s, buf + 11);
  5971. if (ret == -2) {
  5972. os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
  5973. reply_len = 17;
  5974. } else if (ret == -3) {
  5975. os_memcpy(reply, "FAIL-UNKNOWN-UUID\n", 18);
  5976. reply_len = 18;
  5977. } else if (ret == -4) {
  5978. os_memcpy(reply, "FAIL-NO-AP-SETTINGS\n", 20);
  5979. reply_len = 20;
  5980. } else if (ret)
  5981. reply_len = -1;
  5982. } else if (os_strncmp(buf, "WPS_ER_LEARN ", 13) == 0) {
  5983. if (wpa_supplicant_ctrl_iface_wps_er_learn(wpa_s, buf + 13))
  5984. reply_len = -1;
  5985. } else if (os_strncmp(buf, "WPS_ER_SET_CONFIG ", 18) == 0) {
  5986. if (wpa_supplicant_ctrl_iface_wps_er_set_config(wpa_s,
  5987. buf + 18))
  5988. reply_len = -1;
  5989. } else if (os_strncmp(buf, "WPS_ER_CONFIG ", 14) == 0) {
  5990. if (wpa_supplicant_ctrl_iface_wps_er_config(wpa_s, buf + 14))
  5991. reply_len = -1;
  5992. #ifdef CONFIG_WPS_NFC
  5993. } else if (os_strncmp(buf, "WPS_ER_NFC_CONFIG_TOKEN ", 24) == 0) {
  5994. reply_len = wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
  5995. wpa_s, buf + 24, reply, reply_size);
  5996. #endif /* CONFIG_WPS_NFC */
  5997. #endif /* CONFIG_WPS_ER */
  5998. #endif /* CONFIG_WPS */
  5999. #ifdef CONFIG_IBSS_RSN
  6000. } else if (os_strncmp(buf, "IBSS_RSN ", 9) == 0) {
  6001. if (wpa_supplicant_ctrl_iface_ibss_rsn(wpa_s, buf + 9))
  6002. reply_len = -1;
  6003. #endif /* CONFIG_IBSS_RSN */
  6004. #ifdef CONFIG_MESH
  6005. } else if (os_strncmp(buf, "MESH_GROUP_ADD ", 15) == 0) {
  6006. if (wpa_supplicant_ctrl_iface_mesh_group_add(wpa_s, buf + 15))
  6007. reply_len = -1;
  6008. } else if (os_strncmp(buf, "MESH_GROUP_REMOVE ", 18) == 0) {
  6009. if (wpa_supplicant_ctrl_iface_mesh_group_remove(wpa_s,
  6010. buf + 18))
  6011. reply_len = -1;
  6012. #endif /* CONFIG_MESH */
  6013. #ifdef CONFIG_P2P
  6014. } else if (os_strncmp(buf, "P2P_FIND ", 9) == 0) {
  6015. if (p2p_ctrl_find(wpa_s, buf + 9))
  6016. reply_len = -1;
  6017. } else if (os_strcmp(buf, "P2P_FIND") == 0) {
  6018. if (p2p_ctrl_find(wpa_s, ""))
  6019. reply_len = -1;
  6020. } else if (os_strcmp(buf, "P2P_STOP_FIND") == 0) {
  6021. wpas_p2p_stop_find(wpa_s);
  6022. } else if (os_strncmp(buf, "P2P_CONNECT ", 12) == 0) {
  6023. reply_len = p2p_ctrl_connect(wpa_s, buf + 12, reply,
  6024. reply_size);
  6025. } else if (os_strncmp(buf, "P2P_LISTEN ", 11) == 0) {
  6026. if (p2p_ctrl_listen(wpa_s, buf + 11))
  6027. reply_len = -1;
  6028. } else if (os_strcmp(buf, "P2P_LISTEN") == 0) {
  6029. if (p2p_ctrl_listen(wpa_s, ""))
  6030. reply_len = -1;
  6031. } else if (os_strncmp(buf, "P2P_GROUP_REMOVE ", 17) == 0) {
  6032. if (wpas_p2p_group_remove(wpa_s, buf + 17))
  6033. reply_len = -1;
  6034. } else if (os_strcmp(buf, "P2P_GROUP_ADD") == 0) {
  6035. if (wpas_p2p_group_add(wpa_s, 0, 0, 0, 0))
  6036. reply_len = -1;
  6037. } else if (os_strncmp(buf, "P2P_GROUP_ADD ", 14) == 0) {
  6038. if (p2p_ctrl_group_add(wpa_s, buf + 14))
  6039. reply_len = -1;
  6040. } else if (os_strncmp(buf, "P2P_PROV_DISC ", 14) == 0) {
  6041. if (p2p_ctrl_prov_disc(wpa_s, buf + 14))
  6042. reply_len = -1;
  6043. } else if (os_strcmp(buf, "P2P_GET_PASSPHRASE") == 0) {
  6044. reply_len = p2p_get_passphrase(wpa_s, reply, reply_size);
  6045. } else if (os_strncmp(buf, "P2P_SERV_DISC_REQ ", 18) == 0) {
  6046. reply_len = p2p_ctrl_serv_disc_req(wpa_s, buf + 18, reply,
  6047. reply_size);
  6048. } else if (os_strncmp(buf, "P2P_SERV_DISC_CANCEL_REQ ", 25) == 0) {
  6049. if (p2p_ctrl_serv_disc_cancel_req(wpa_s, buf + 25) < 0)
  6050. reply_len = -1;
  6051. } else if (os_strncmp(buf, "P2P_SERV_DISC_RESP ", 19) == 0) {
  6052. if (p2p_ctrl_serv_disc_resp(wpa_s, buf + 19) < 0)
  6053. reply_len = -1;
  6054. } else if (os_strcmp(buf, "P2P_SERVICE_UPDATE") == 0) {
  6055. wpas_p2p_sd_service_update(wpa_s);
  6056. } else if (os_strncmp(buf, "P2P_SERV_DISC_EXTERNAL ", 23) == 0) {
  6057. if (p2p_ctrl_serv_disc_external(wpa_s, buf + 23) < 0)
  6058. reply_len = -1;
  6059. } else if (os_strcmp(buf, "P2P_SERVICE_FLUSH") == 0) {
  6060. wpas_p2p_service_flush(wpa_s);
  6061. } else if (os_strncmp(buf, "P2P_SERVICE_ADD ", 16) == 0) {
  6062. if (p2p_ctrl_service_add(wpa_s, buf + 16) < 0)
  6063. reply_len = -1;
  6064. } else if (os_strncmp(buf, "P2P_SERVICE_DEL ", 16) == 0) {
  6065. if (p2p_ctrl_service_del(wpa_s, buf + 16) < 0)
  6066. reply_len = -1;
  6067. } else if (os_strncmp(buf, "P2P_REJECT ", 11) == 0) {
  6068. if (p2p_ctrl_reject(wpa_s, buf + 11) < 0)
  6069. reply_len = -1;
  6070. } else if (os_strncmp(buf, "P2P_INVITE ", 11) == 0) {
  6071. if (p2p_ctrl_invite(wpa_s, buf + 11) < 0)
  6072. reply_len = -1;
  6073. } else if (os_strncmp(buf, "P2P_PEER ", 9) == 0) {
  6074. reply_len = p2p_ctrl_peer(wpa_s, buf + 9, reply,
  6075. reply_size);
  6076. } else if (os_strncmp(buf, "P2P_SET ", 8) == 0) {
  6077. if (p2p_ctrl_set(wpa_s, buf + 8) < 0)
  6078. reply_len = -1;
  6079. } else if (os_strcmp(buf, "P2P_FLUSH") == 0) {
  6080. p2p_ctrl_flush(wpa_s);
  6081. } else if (os_strncmp(buf, "P2P_UNAUTHORIZE ", 16) == 0) {
  6082. if (wpas_p2p_unauthorize(wpa_s, buf + 16) < 0)
  6083. reply_len = -1;
  6084. } else if (os_strcmp(buf, "P2P_CANCEL") == 0) {
  6085. if (wpas_p2p_cancel(wpa_s))
  6086. reply_len = -1;
  6087. } else if (os_strncmp(buf, "P2P_PRESENCE_REQ ", 17) == 0) {
  6088. if (p2p_ctrl_presence_req(wpa_s, buf + 17) < 0)
  6089. reply_len = -1;
  6090. } else if (os_strcmp(buf, "P2P_PRESENCE_REQ") == 0) {
  6091. if (p2p_ctrl_presence_req(wpa_s, "") < 0)
  6092. reply_len = -1;
  6093. } else if (os_strncmp(buf, "P2P_EXT_LISTEN ", 15) == 0) {
  6094. if (p2p_ctrl_ext_listen(wpa_s, buf + 15) < 0)
  6095. reply_len = -1;
  6096. } else if (os_strcmp(buf, "P2P_EXT_LISTEN") == 0) {
  6097. if (p2p_ctrl_ext_listen(wpa_s, "") < 0)
  6098. reply_len = -1;
  6099. } else if (os_strncmp(buf, "P2P_REMOVE_CLIENT ", 18) == 0) {
  6100. if (p2p_ctrl_remove_client(wpa_s, buf + 18) < 0)
  6101. reply_len = -1;
  6102. #endif /* CONFIG_P2P */
  6103. #ifdef CONFIG_WIFI_DISPLAY
  6104. } else if (os_strncmp(buf, "WFD_SUBELEM_SET ", 16) == 0) {
  6105. if (wifi_display_subelem_set(wpa_s->global, buf + 16) < 0)
  6106. reply_len = -1;
  6107. } else if (os_strncmp(buf, "WFD_SUBELEM_GET ", 16) == 0) {
  6108. reply_len = wifi_display_subelem_get(wpa_s->global, buf + 16,
  6109. reply, reply_size);
  6110. #endif /* CONFIG_WIFI_DISPLAY */
  6111. #ifdef CONFIG_INTERWORKING
  6112. } else if (os_strcmp(buf, "FETCH_ANQP") == 0) {
  6113. if (interworking_fetch_anqp(wpa_s) < 0)
  6114. reply_len = -1;
  6115. } else if (os_strcmp(buf, "STOP_FETCH_ANQP") == 0) {
  6116. interworking_stop_fetch_anqp(wpa_s);
  6117. } else if (os_strcmp(buf, "INTERWORKING_SELECT") == 0) {
  6118. if (ctrl_interworking_select(wpa_s, NULL) < 0)
  6119. reply_len = -1;
  6120. } else if (os_strncmp(buf, "INTERWORKING_SELECT ", 20) == 0) {
  6121. if (ctrl_interworking_select(wpa_s, buf + 20) < 0)
  6122. reply_len = -1;
  6123. } else if (os_strncmp(buf, "INTERWORKING_CONNECT ", 21) == 0) {
  6124. if (ctrl_interworking_connect(wpa_s, buf + 21) < 0)
  6125. reply_len = -1;
  6126. } else if (os_strncmp(buf, "ANQP_GET ", 9) == 0) {
  6127. if (get_anqp(wpa_s, buf + 9) < 0)
  6128. reply_len = -1;
  6129. } else if (os_strncmp(buf, "GAS_REQUEST ", 12) == 0) {
  6130. if (gas_request(wpa_s, buf + 12) < 0)
  6131. reply_len = -1;
  6132. } else if (os_strncmp(buf, "GAS_RESPONSE_GET ", 17) == 0) {
  6133. reply_len = gas_response_get(wpa_s, buf + 17, reply,
  6134. reply_size);
  6135. #endif /* CONFIG_INTERWORKING */
  6136. #ifdef CONFIG_HS20
  6137. } else if (os_strncmp(buf, "HS20_ANQP_GET ", 14) == 0) {
  6138. if (get_hs20_anqp(wpa_s, buf + 14) < 0)
  6139. reply_len = -1;
  6140. } else if (os_strncmp(buf, "HS20_GET_NAI_HOME_REALM_LIST ", 29) == 0) {
  6141. if (hs20_get_nai_home_realm_list(wpa_s, buf + 29) < 0)
  6142. reply_len = -1;
  6143. } else if (os_strncmp(buf, "HS20_ICON_REQUEST ", 18) == 0) {
  6144. if (hs20_icon_request(wpa_s, buf + 18) < 0)
  6145. reply_len = -1;
  6146. } else if (os_strcmp(buf, "FETCH_OSU") == 0) {
  6147. if (hs20_fetch_osu(wpa_s) < 0)
  6148. reply_len = -1;
  6149. } else if (os_strcmp(buf, "CANCEL_FETCH_OSU") == 0) {
  6150. hs20_cancel_fetch_osu(wpa_s);
  6151. #endif /* CONFIG_HS20 */
  6152. } else if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0)
  6153. {
  6154. if (wpa_supplicant_ctrl_iface_ctrl_rsp(
  6155. wpa_s, buf + os_strlen(WPA_CTRL_RSP)))
  6156. reply_len = -1;
  6157. else {
  6158. /*
  6159. * Notify response from timeout to allow the control
  6160. * interface response to be sent first.
  6161. */
  6162. eloop_register_timeout(0, 0, wpas_ctrl_eapol_response,
  6163. wpa_s, NULL);
  6164. }
  6165. } else if (os_strcmp(buf, "RECONFIGURE") == 0) {
  6166. if (wpa_supplicant_reload_configuration(wpa_s))
  6167. reply_len = -1;
  6168. } else if (os_strcmp(buf, "TERMINATE") == 0) {
  6169. wpa_supplicant_terminate_proc(wpa_s->global);
  6170. } else if (os_strncmp(buf, "BSSID ", 6) == 0) {
  6171. if (wpa_supplicant_ctrl_iface_bssid(wpa_s, buf + 6))
  6172. reply_len = -1;
  6173. } else if (os_strncmp(buf, "BLACKLIST", 9) == 0) {
  6174. reply_len = wpa_supplicant_ctrl_iface_blacklist(
  6175. wpa_s, buf + 9, reply, reply_size);
  6176. } else if (os_strncmp(buf, "LOG_LEVEL", 9) == 0) {
  6177. reply_len = wpa_supplicant_ctrl_iface_log_level(
  6178. wpa_s, buf + 9, reply, reply_size);
  6179. } else if (os_strcmp(buf, "LIST_NETWORKS") == 0) {
  6180. reply_len = wpa_supplicant_ctrl_iface_list_networks(
  6181. wpa_s, reply, reply_size);
  6182. } else if (os_strcmp(buf, "DISCONNECT") == 0) {
  6183. #ifdef CONFIG_SME
  6184. wpa_s->sme.prev_bssid_set = 0;
  6185. #endif /* CONFIG_SME */
  6186. wpa_s->reassociate = 0;
  6187. wpa_s->disconnected = 1;
  6188. wpa_supplicant_cancel_sched_scan(wpa_s);
  6189. wpa_supplicant_cancel_scan(wpa_s);
  6190. wpa_supplicant_deauthenticate(wpa_s,
  6191. WLAN_REASON_DEAUTH_LEAVING);
  6192. } else if (os_strcmp(buf, "SCAN") == 0) {
  6193. wpas_ctrl_scan(wpa_s, NULL, reply, reply_size, &reply_len);
  6194. } else if (os_strncmp(buf, "SCAN ", 5) == 0) {
  6195. wpas_ctrl_scan(wpa_s, buf + 5, reply, reply_size, &reply_len);
  6196. } else if (os_strcmp(buf, "SCAN_RESULTS") == 0) {
  6197. reply_len = wpa_supplicant_ctrl_iface_scan_results(
  6198. wpa_s, reply, reply_size);
  6199. } else if (os_strncmp(buf, "SELECT_NETWORK ", 15) == 0) {
  6200. if (wpa_supplicant_ctrl_iface_select_network(wpa_s, buf + 15))
  6201. reply_len = -1;
  6202. } else if (os_strncmp(buf, "ENABLE_NETWORK ", 15) == 0) {
  6203. if (wpa_supplicant_ctrl_iface_enable_network(wpa_s, buf + 15))
  6204. reply_len = -1;
  6205. } else if (os_strncmp(buf, "DISABLE_NETWORK ", 16) == 0) {
  6206. if (wpa_supplicant_ctrl_iface_disable_network(wpa_s, buf + 16))
  6207. reply_len = -1;
  6208. } else if (os_strcmp(buf, "ADD_NETWORK") == 0) {
  6209. reply_len = wpa_supplicant_ctrl_iface_add_network(
  6210. wpa_s, reply, reply_size);
  6211. } else if (os_strncmp(buf, "REMOVE_NETWORK ", 15) == 0) {
  6212. if (wpa_supplicant_ctrl_iface_remove_network(wpa_s, buf + 15))
  6213. reply_len = -1;
  6214. } else if (os_strncmp(buf, "SET_NETWORK ", 12) == 0) {
  6215. if (wpa_supplicant_ctrl_iface_set_network(wpa_s, buf + 12))
  6216. reply_len = -1;
  6217. } else if (os_strncmp(buf, "GET_NETWORK ", 12) == 0) {
  6218. reply_len = wpa_supplicant_ctrl_iface_get_network(
  6219. wpa_s, buf + 12, reply, reply_size);
  6220. } else if (os_strncmp(buf, "DUP_NETWORK ", 12) == 0) {
  6221. if (wpa_supplicant_ctrl_iface_dup_network(wpa_s, buf + 12))
  6222. reply_len = -1;
  6223. } else if (os_strcmp(buf, "LIST_CREDS") == 0) {
  6224. reply_len = wpa_supplicant_ctrl_iface_list_creds(
  6225. wpa_s, reply, reply_size);
  6226. } else if (os_strcmp(buf, "ADD_CRED") == 0) {
  6227. reply_len = wpa_supplicant_ctrl_iface_add_cred(
  6228. wpa_s, reply, reply_size);
  6229. } else if (os_strncmp(buf, "REMOVE_CRED ", 12) == 0) {
  6230. if (wpa_supplicant_ctrl_iface_remove_cred(wpa_s, buf + 12))
  6231. reply_len = -1;
  6232. } else if (os_strncmp(buf, "SET_CRED ", 9) == 0) {
  6233. if (wpa_supplicant_ctrl_iface_set_cred(wpa_s, buf + 9))
  6234. reply_len = -1;
  6235. } else if (os_strncmp(buf, "GET_CRED ", 9) == 0) {
  6236. reply_len = wpa_supplicant_ctrl_iface_get_cred(wpa_s, buf + 9,
  6237. reply,
  6238. reply_size);
  6239. #ifndef CONFIG_NO_CONFIG_WRITE
  6240. } else if (os_strcmp(buf, "SAVE_CONFIG") == 0) {
  6241. if (wpa_supplicant_ctrl_iface_save_config(wpa_s))
  6242. reply_len = -1;
  6243. #endif /* CONFIG_NO_CONFIG_WRITE */
  6244. } else if (os_strncmp(buf, "GET_CAPABILITY ", 15) == 0) {
  6245. reply_len = wpa_supplicant_ctrl_iface_get_capability(
  6246. wpa_s, buf + 15, reply, reply_size);
  6247. } else if (os_strncmp(buf, "AP_SCAN ", 8) == 0) {
  6248. if (wpa_supplicant_ctrl_iface_ap_scan(wpa_s, buf + 8))
  6249. reply_len = -1;
  6250. } else if (os_strncmp(buf, "SCAN_INTERVAL ", 14) == 0) {
  6251. if (wpa_supplicant_ctrl_iface_scan_interval(wpa_s, buf + 14))
  6252. reply_len = -1;
  6253. } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) {
  6254. reply_len = wpa_supplicant_global_iface_list(
  6255. wpa_s->global, reply, reply_size);
  6256. } else if (os_strcmp(buf, "INTERFACES") == 0) {
  6257. reply_len = wpa_supplicant_global_iface_interfaces(
  6258. wpa_s->global, reply, reply_size);
  6259. } else if (os_strncmp(buf, "BSS ", 4) == 0) {
  6260. reply_len = wpa_supplicant_ctrl_iface_bss(
  6261. wpa_s, buf + 4, reply, reply_size);
  6262. #ifdef CONFIG_AP
  6263. } else if (os_strcmp(buf, "STA-FIRST") == 0) {
  6264. reply_len = ap_ctrl_iface_sta_first(wpa_s, reply, reply_size);
  6265. } else if (os_strncmp(buf, "STA ", 4) == 0) {
  6266. reply_len = ap_ctrl_iface_sta(wpa_s, buf + 4, reply,
  6267. reply_size);
  6268. } else if (os_strncmp(buf, "STA-NEXT ", 9) == 0) {
  6269. reply_len = ap_ctrl_iface_sta_next(wpa_s, buf + 9, reply,
  6270. reply_size);
  6271. } else if (os_strncmp(buf, "DEAUTHENTICATE ", 15) == 0) {
  6272. if (ap_ctrl_iface_sta_deauthenticate(wpa_s, buf + 15))
  6273. reply_len = -1;
  6274. } else if (os_strncmp(buf, "DISASSOCIATE ", 13) == 0) {
  6275. if (ap_ctrl_iface_sta_disassociate(wpa_s, buf + 13))
  6276. reply_len = -1;
  6277. } else if (os_strncmp(buf, "CHAN_SWITCH ", 12) == 0) {
  6278. if (ap_ctrl_iface_chanswitch(wpa_s, buf + 12))
  6279. reply_len = -1;
  6280. #endif /* CONFIG_AP */
  6281. } else if (os_strcmp(buf, "SUSPEND") == 0) {
  6282. wpas_notify_suspend(wpa_s->global);
  6283. } else if (os_strcmp(buf, "RESUME") == 0) {
  6284. wpas_notify_resume(wpa_s->global);
  6285. #ifdef CONFIG_TESTING_OPTIONS
  6286. } else if (os_strcmp(buf, "DROP_SA") == 0) {
  6287. wpa_supplicant_ctrl_iface_drop_sa(wpa_s);
  6288. #endif /* CONFIG_TESTING_OPTIONS */
  6289. } else if (os_strncmp(buf, "ROAM ", 5) == 0) {
  6290. if (wpa_supplicant_ctrl_iface_roam(wpa_s, buf + 5))
  6291. reply_len = -1;
  6292. } else if (os_strncmp(buf, "STA_AUTOCONNECT ", 16) == 0) {
  6293. if (wpa_supplicant_ctrl_iface_sta_autoconnect(wpa_s, buf + 16))
  6294. reply_len = -1;
  6295. } else if (os_strncmp(buf, "BSS_EXPIRE_AGE ", 15) == 0) {
  6296. if (wpa_supplicant_ctrl_iface_bss_expire_age(wpa_s, buf + 15))
  6297. reply_len = -1;
  6298. } else if (os_strncmp(buf, "BSS_EXPIRE_COUNT ", 17) == 0) {
  6299. if (wpa_supplicant_ctrl_iface_bss_expire_count(wpa_s,
  6300. buf + 17))
  6301. reply_len = -1;
  6302. } else if (os_strncmp(buf, "BSS_FLUSH ", 10) == 0) {
  6303. if (wpa_supplicant_ctrl_iface_bss_flush(wpa_s, buf + 10))
  6304. reply_len = -1;
  6305. #ifdef CONFIG_TDLS
  6306. } else if (os_strncmp(buf, "TDLS_DISCOVER ", 14) == 0) {
  6307. if (wpa_supplicant_ctrl_iface_tdls_discover(wpa_s, buf + 14))
  6308. reply_len = -1;
  6309. } else if (os_strncmp(buf, "TDLS_SETUP ", 11) == 0) {
  6310. if (wpa_supplicant_ctrl_iface_tdls_setup(wpa_s, buf + 11))
  6311. reply_len = -1;
  6312. } else if (os_strncmp(buf, "TDLS_TEARDOWN ", 14) == 0) {
  6313. if (wpa_supplicant_ctrl_iface_tdls_teardown(wpa_s, buf + 14))
  6314. reply_len = -1;
  6315. #endif /* CONFIG_TDLS */
  6316. } else if (os_strcmp(buf, "WMM_AC_STATUS") == 0) {
  6317. reply_len = wpas_wmm_ac_status(wpa_s, reply, reply_size);
  6318. } else if (os_strncmp(buf, "WMM_AC_ADDTS ", 13) == 0) {
  6319. if (wmm_ac_ctrl_addts(wpa_s, buf + 13))
  6320. reply_len = -1;
  6321. } else if (os_strncmp(buf, "WMM_AC_DELTS ", 13) == 0) {
  6322. if (wmm_ac_ctrl_delts(wpa_s, buf + 13))
  6323. reply_len = -1;
  6324. } else if (os_strncmp(buf, "SIGNAL_POLL", 11) == 0) {
  6325. reply_len = wpa_supplicant_signal_poll(wpa_s, reply,
  6326. reply_size);
  6327. } else if (os_strncmp(buf, "PKTCNT_POLL", 11) == 0) {
  6328. reply_len = wpa_supplicant_pktcnt_poll(wpa_s, reply,
  6329. reply_size);
  6330. #ifdef CONFIG_AUTOSCAN
  6331. } else if (os_strncmp(buf, "AUTOSCAN ", 9) == 0) {
  6332. if (wpa_supplicant_ctrl_iface_autoscan(wpa_s, buf + 9))
  6333. reply_len = -1;
  6334. #endif /* CONFIG_AUTOSCAN */
  6335. #ifdef ANDROID
  6336. } else if (os_strncmp(buf, "DRIVER ", 7) == 0) {
  6337. reply_len = wpa_supplicant_driver_cmd(wpa_s, buf + 7, reply,
  6338. reply_size);
  6339. #endif /* ANDROID */
  6340. } else if (os_strncmp(buf, "VENDOR ", 7) == 0) {
  6341. reply_len = wpa_supplicant_vendor_cmd(wpa_s, buf + 7, reply,
  6342. reply_size);
  6343. } else if (os_strcmp(buf, "REAUTHENTICATE") == 0) {
  6344. pmksa_cache_clear_current(wpa_s->wpa);
  6345. eapol_sm_request_reauth(wpa_s->eapol);
  6346. #ifdef CONFIG_WNM
  6347. } else if (os_strncmp(buf, "WNM_SLEEP ", 10) == 0) {
  6348. if (wpas_ctrl_iface_wnm_sleep(wpa_s, buf + 10))
  6349. reply_len = -1;
  6350. } else if (os_strncmp(buf, "WNM_BSS_QUERY ", 10) == 0) {
  6351. if (wpas_ctrl_iface_wnm_bss_query(wpa_s, buf + 10))
  6352. reply_len = -1;
  6353. #endif /* CONFIG_WNM */
  6354. } else if (os_strcmp(buf, "FLUSH") == 0) {
  6355. wpa_supplicant_ctrl_iface_flush(wpa_s);
  6356. } else if (os_strncmp(buf, "RADIO_WORK ", 11) == 0) {
  6357. reply_len = wpas_ctrl_radio_work(wpa_s, buf + 11, reply,
  6358. reply_size);
  6359. #ifdef CONFIG_TESTING_OPTIONS
  6360. } else if (os_strncmp(buf, "MGMT_TX ", 8) == 0) {
  6361. if (wpas_ctrl_iface_mgmt_tx(wpa_s, buf + 8) < 0)
  6362. reply_len = -1;
  6363. } else if (os_strcmp(buf, "MGMT_TX_DONE") == 0) {
  6364. wpas_ctrl_iface_mgmt_tx_done(wpa_s);
  6365. } else if (os_strncmp(buf, "DRIVER_EVENT ", 13) == 0) {
  6366. if (wpas_ctrl_iface_driver_event(wpa_s, buf + 13) < 0)
  6367. reply_len = -1;
  6368. } else if (os_strncmp(buf, "EAPOL_RX ", 9) == 0) {
  6369. if (wpas_ctrl_iface_eapol_rx(wpa_s, buf + 9) < 0)
  6370. reply_len = -1;
  6371. } else if (os_strncmp(buf, "DATA_TEST_CONFIG ", 17) == 0) {
  6372. if (wpas_ctrl_iface_data_test_config(wpa_s, buf + 17) < 0)
  6373. reply_len = -1;
  6374. } else if (os_strncmp(buf, "DATA_TEST_TX ", 13) == 0) {
  6375. if (wpas_ctrl_iface_data_test_tx(wpa_s, buf + 13) < 0)
  6376. reply_len = -1;
  6377. } else if (os_strncmp(buf, "DATA_TEST_FRAME ", 16) == 0) {
  6378. if (wpas_ctrl_iface_data_test_frame(wpa_s, buf + 16) < 0)
  6379. reply_len = -1;
  6380. #endif /* CONFIG_TESTING_OPTIONS */
  6381. } else if (os_strncmp(buf, "VENDOR_ELEM_ADD ", 16) == 0) {
  6382. if (wpas_ctrl_vendor_elem_add(wpa_s, buf + 16) < 0)
  6383. reply_len = -1;
  6384. } else if (os_strncmp(buf, "VENDOR_ELEM_GET ", 16) == 0) {
  6385. reply_len = wpas_ctrl_vendor_elem_get(wpa_s, buf + 16, reply,
  6386. reply_size);
  6387. } else if (os_strncmp(buf, "VENDOR_ELEM_REMOVE ", 19) == 0) {
  6388. if (wpas_ctrl_vendor_elem_remove(wpa_s, buf + 19) < 0)
  6389. reply_len = -1;
  6390. } else if (os_strncmp(buf, "NEIGHBOR_REP_REQUEST", 20) == 0) {
  6391. if (wpas_ctrl_iface_send_neigbor_rep(wpa_s, buf + 20))
  6392. reply_len = -1;
  6393. } else {
  6394. os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
  6395. reply_len = 16;
  6396. }
  6397. if (reply_len < 0) {
  6398. os_memcpy(reply, "FAIL\n", 5);
  6399. reply_len = 5;
  6400. }
  6401. *resp_len = reply_len;
  6402. return reply;
  6403. }
  6404. static int wpa_supplicant_global_iface_add(struct wpa_global *global,
  6405. char *cmd)
  6406. {
  6407. struct wpa_interface iface;
  6408. char *pos;
  6409. /*
  6410. * <ifname>TAB<confname>TAB<driver>TAB<ctrl_interface>TAB<driver_param>
  6411. * TAB<bridge_ifname>
  6412. */
  6413. wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_ADD '%s'", cmd);
  6414. os_memset(&iface, 0, sizeof(iface));
  6415. do {
  6416. iface.ifname = pos = cmd;
  6417. pos = os_strchr(pos, '\t');
  6418. if (pos)
  6419. *pos++ = '\0';
  6420. if (iface.ifname[0] == '\0')
  6421. return -1;
  6422. if (pos == NULL)
  6423. break;
  6424. iface.confname = pos;
  6425. pos = os_strchr(pos, '\t');
  6426. if (pos)
  6427. *pos++ = '\0';
  6428. if (iface.confname[0] == '\0')
  6429. iface.confname = NULL;
  6430. if (pos == NULL)
  6431. break;
  6432. iface.driver = pos;
  6433. pos = os_strchr(pos, '\t');
  6434. if (pos)
  6435. *pos++ = '\0';
  6436. if (iface.driver[0] == '\0')
  6437. iface.driver = NULL;
  6438. if (pos == NULL)
  6439. break;
  6440. iface.ctrl_interface = pos;
  6441. pos = os_strchr(pos, '\t');
  6442. if (pos)
  6443. *pos++ = '\0';
  6444. if (iface.ctrl_interface[0] == '\0')
  6445. iface.ctrl_interface = NULL;
  6446. if (pos == NULL)
  6447. break;
  6448. iface.driver_param = pos;
  6449. pos = os_strchr(pos, '\t');
  6450. if (pos)
  6451. *pos++ = '\0';
  6452. if (iface.driver_param[0] == '\0')
  6453. iface.driver_param = NULL;
  6454. if (pos == NULL)
  6455. break;
  6456. iface.bridge_ifname = pos;
  6457. pos = os_strchr(pos, '\t');
  6458. if (pos)
  6459. *pos++ = '\0';
  6460. if (iface.bridge_ifname[0] == '\0')
  6461. iface.bridge_ifname = NULL;
  6462. if (pos == NULL)
  6463. break;
  6464. } while (0);
  6465. if (wpa_supplicant_get_iface(global, iface.ifname))
  6466. return -1;
  6467. return wpa_supplicant_add_iface(global, &iface) ? 0 : -1;
  6468. }
  6469. static int wpa_supplicant_global_iface_remove(struct wpa_global *global,
  6470. char *cmd)
  6471. {
  6472. struct wpa_supplicant *wpa_s;
  6473. wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_REMOVE '%s'", cmd);
  6474. wpa_s = wpa_supplicant_get_iface(global, cmd);
  6475. if (wpa_s == NULL)
  6476. return -1;
  6477. return wpa_supplicant_remove_iface(global, wpa_s, 0);
  6478. }
  6479. static void wpa_free_iface_info(struct wpa_interface_info *iface)
  6480. {
  6481. struct wpa_interface_info *prev;
  6482. while (iface) {
  6483. prev = iface;
  6484. iface = iface->next;
  6485. os_free(prev->ifname);
  6486. os_free(prev->desc);
  6487. os_free(prev);
  6488. }
  6489. }
  6490. static int wpa_supplicant_global_iface_list(struct wpa_global *global,
  6491. char *buf, int len)
  6492. {
  6493. int i, res;
  6494. struct wpa_interface_info *iface = NULL, *last = NULL, *tmp;
  6495. char *pos, *end;
  6496. for (i = 0; wpa_drivers[i]; i++) {
  6497. struct wpa_driver_ops *drv = wpa_drivers[i];
  6498. if (drv->get_interfaces == NULL)
  6499. continue;
  6500. tmp = drv->get_interfaces(global->drv_priv[i]);
  6501. if (tmp == NULL)
  6502. continue;
  6503. if (last == NULL)
  6504. iface = last = tmp;
  6505. else
  6506. last->next = tmp;
  6507. while (last->next)
  6508. last = last->next;
  6509. }
  6510. pos = buf;
  6511. end = buf + len;
  6512. for (tmp = iface; tmp; tmp = tmp->next) {
  6513. res = os_snprintf(pos, end - pos, "%s\t%s\t%s\n",
  6514. tmp->drv_name, tmp->ifname,
  6515. tmp->desc ? tmp->desc : "");
  6516. if (res < 0 || res >= end - pos) {
  6517. *pos = '\0';
  6518. break;
  6519. }
  6520. pos += res;
  6521. }
  6522. wpa_free_iface_info(iface);
  6523. return pos - buf;
  6524. }
  6525. static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global,
  6526. char *buf, int len)
  6527. {
  6528. int res;
  6529. char *pos, *end;
  6530. struct wpa_supplicant *wpa_s;
  6531. wpa_s = global->ifaces;
  6532. pos = buf;
  6533. end = buf + len;
  6534. while (wpa_s) {
  6535. res = os_snprintf(pos, end - pos, "%s\n", wpa_s->ifname);
  6536. if (res < 0 || res >= end - pos) {
  6537. *pos = '\0';
  6538. break;
  6539. }
  6540. pos += res;
  6541. wpa_s = wpa_s->next;
  6542. }
  6543. return pos - buf;
  6544. }
  6545. static char * wpas_global_ctrl_iface_ifname(struct wpa_global *global,
  6546. const char *ifname,
  6547. char *cmd, size_t *resp_len)
  6548. {
  6549. struct wpa_supplicant *wpa_s;
  6550. for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
  6551. if (os_strcmp(ifname, wpa_s->ifname) == 0)
  6552. break;
  6553. }
  6554. if (wpa_s == NULL) {
  6555. char *resp = os_strdup("FAIL-NO-IFNAME-MATCH\n");
  6556. if (resp)
  6557. *resp_len = os_strlen(resp);
  6558. else
  6559. *resp_len = 1;
  6560. return resp;
  6561. }
  6562. return wpa_supplicant_ctrl_iface_process(wpa_s, cmd, resp_len);
  6563. }
  6564. static char * wpas_global_ctrl_iface_redir_p2p(struct wpa_global *global,
  6565. char *buf, size_t *resp_len)
  6566. {
  6567. #ifdef CONFIG_P2P
  6568. static const char * cmd[] = {
  6569. "LIST_NETWORKS",
  6570. "P2P_FIND",
  6571. "P2P_STOP_FIND",
  6572. "P2P_LISTEN",
  6573. "P2P_GROUP_ADD",
  6574. "P2P_GET_PASSPHRASE",
  6575. "P2P_SERVICE_UPDATE",
  6576. "P2P_SERVICE_FLUSH",
  6577. "P2P_FLUSH",
  6578. "P2P_CANCEL",
  6579. "P2P_PRESENCE_REQ",
  6580. "P2P_EXT_LISTEN",
  6581. NULL
  6582. };
  6583. static const char * prefix[] = {
  6584. #ifdef ANDROID
  6585. "DRIVER ",
  6586. #endif /* ANDROID */
  6587. "GET_NETWORK ",
  6588. "REMOVE_NETWORK ",
  6589. "P2P_FIND ",
  6590. "P2P_CONNECT ",
  6591. "P2P_LISTEN ",
  6592. "P2P_GROUP_REMOVE ",
  6593. "P2P_GROUP_ADD ",
  6594. "P2P_PROV_DISC ",
  6595. "P2P_SERV_DISC_REQ ",
  6596. "P2P_SERV_DISC_CANCEL_REQ ",
  6597. "P2P_SERV_DISC_RESP ",
  6598. "P2P_SERV_DISC_EXTERNAL ",
  6599. "P2P_SERVICE_ADD ",
  6600. "P2P_SERVICE_DEL ",
  6601. "P2P_REJECT ",
  6602. "P2P_INVITE ",
  6603. "P2P_PEER ",
  6604. "P2P_SET ",
  6605. "P2P_UNAUTHORIZE ",
  6606. "P2P_PRESENCE_REQ ",
  6607. "P2P_EXT_LISTEN ",
  6608. "P2P_REMOVE_CLIENT ",
  6609. "NFC_GET_HANDOVER_SEL ",
  6610. "NFC_GET_HANDOVER_REQ ",
  6611. "NFC_REPORT_HANDOVER ",
  6612. NULL
  6613. };
  6614. int found = 0;
  6615. int i;
  6616. if (global->p2p_init_wpa_s == NULL)
  6617. return NULL;
  6618. for (i = 0; !found && cmd[i]; i++) {
  6619. if (os_strcmp(buf, cmd[i]) == 0)
  6620. found = 1;
  6621. }
  6622. for (i = 0; !found && prefix[i]; i++) {
  6623. if (os_strncmp(buf, prefix[i], os_strlen(prefix[i])) == 0)
  6624. found = 1;
  6625. }
  6626. if (found)
  6627. return wpa_supplicant_ctrl_iface_process(global->p2p_init_wpa_s,
  6628. buf, resp_len);
  6629. #endif /* CONFIG_P2P */
  6630. return NULL;
  6631. }
  6632. static char * wpas_global_ctrl_iface_redir_wfd(struct wpa_global *global,
  6633. char *buf, size_t *resp_len)
  6634. {
  6635. #ifdef CONFIG_WIFI_DISPLAY
  6636. if (global->p2p_init_wpa_s == NULL)
  6637. return NULL;
  6638. if (os_strncmp(buf, "WFD_SUBELEM_SET ", 16) == 0 ||
  6639. os_strncmp(buf, "WFD_SUBELEM_GET ", 16) == 0)
  6640. return wpa_supplicant_ctrl_iface_process(global->p2p_init_wpa_s,
  6641. buf, resp_len);
  6642. #endif /* CONFIG_WIFI_DISPLAY */
  6643. return NULL;
  6644. }
  6645. static char * wpas_global_ctrl_iface_redir(struct wpa_global *global,
  6646. char *buf, size_t *resp_len)
  6647. {
  6648. char *ret;
  6649. ret = wpas_global_ctrl_iface_redir_p2p(global, buf, resp_len);
  6650. if (ret)
  6651. return ret;
  6652. ret = wpas_global_ctrl_iface_redir_wfd(global, buf, resp_len);
  6653. if (ret)
  6654. return ret;
  6655. return NULL;
  6656. }
  6657. static int wpas_global_ctrl_iface_set(struct wpa_global *global, char *cmd)
  6658. {
  6659. char *value;
  6660. value = os_strchr(cmd, ' ');
  6661. if (value == NULL)
  6662. return -1;
  6663. *value++ = '\0';
  6664. wpa_printf(MSG_DEBUG, "GLOBAL_CTRL_IFACE SET '%s'='%s'", cmd, value);
  6665. #ifdef CONFIG_WIFI_DISPLAY
  6666. if (os_strcasecmp(cmd, "wifi_display") == 0) {
  6667. wifi_display_enable(global, !!atoi(value));
  6668. return 0;
  6669. }
  6670. #endif /* CONFIG_WIFI_DISPLAY */
  6671. /* Restore cmd to its original value to allow redirection */
  6672. value[-1] = ' ';
  6673. return -1;
  6674. }
  6675. #ifndef CONFIG_NO_CONFIG_WRITE
  6676. static int wpas_global_ctrl_iface_save_config(struct wpa_global *global)
  6677. {
  6678. int ret = 0, saved = 0;
  6679. struct wpa_supplicant *wpa_s;
  6680. for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
  6681. if (!wpa_s->conf->update_config) {
  6682. wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Not allowed to update configuration (update_config=0)");
  6683. continue;
  6684. }
  6685. if (wpa_config_write(wpa_s->confname, wpa_s->conf)) {
  6686. wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Failed to update configuration");
  6687. ret = 1;
  6688. } else {
  6689. wpa_dbg(wpa_s, MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Configuration updated");
  6690. saved++;
  6691. }
  6692. }
  6693. if (!saved && !ret) {
  6694. wpa_dbg(wpa_s, MSG_DEBUG,
  6695. "CTRL_IFACE: SAVE_CONFIG - No configuration files could be updated");
  6696. ret = 1;
  6697. }
  6698. return ret;
  6699. }
  6700. #endif /* CONFIG_NO_CONFIG_WRITE */
  6701. static int wpas_global_ctrl_iface_status(struct wpa_global *global,
  6702. char *buf, size_t buflen)
  6703. {
  6704. char *pos, *end;
  6705. int ret;
  6706. struct wpa_supplicant *wpa_s;
  6707. pos = buf;
  6708. end = buf + buflen;
  6709. #ifdef CONFIG_P2P
  6710. if (global->p2p && !global->p2p_disabled) {
  6711. ret = os_snprintf(pos, end - pos, "p2p_device_address=" MACSTR
  6712. "\n"
  6713. "p2p_state=%s\n",
  6714. MAC2STR(global->p2p_dev_addr),
  6715. p2p_get_state_txt(global->p2p));
  6716. if (ret < 0 || ret >= end - pos)
  6717. return pos - buf;
  6718. pos += ret;
  6719. } else if (global->p2p) {
  6720. ret = os_snprintf(pos, end - pos, "p2p_state=DISABLED\n");
  6721. if (ret < 0 || ret >= end - pos)
  6722. return pos - buf;
  6723. pos += ret;
  6724. }
  6725. #endif /* CONFIG_P2P */
  6726. #ifdef CONFIG_WIFI_DISPLAY
  6727. ret = os_snprintf(pos, end - pos, "wifi_display=%d\n",
  6728. !!global->wifi_display);
  6729. if (ret < 0 || ret >= end - pos)
  6730. return pos - buf;
  6731. pos += ret;
  6732. #endif /* CONFIG_WIFI_DISPLAY */
  6733. for (wpa_s = global->ifaces; wpa_s; wpa_s = wpa_s->next) {
  6734. ret = os_snprintf(pos, end - pos, "ifname=%s\n"
  6735. "address=" MACSTR "\n",
  6736. wpa_s->ifname, MAC2STR(wpa_s->own_addr));
  6737. if (ret < 0 || ret >= end - pos)
  6738. return pos - buf;
  6739. pos += ret;
  6740. }
  6741. return pos - buf;
  6742. }
  6743. char * wpa_supplicant_global_ctrl_iface_process(struct wpa_global *global,
  6744. char *buf, size_t *resp_len)
  6745. {
  6746. char *reply;
  6747. const int reply_size = 2048;
  6748. int reply_len;
  6749. int level = MSG_DEBUG;
  6750. if (os_strncmp(buf, "IFNAME=", 7) == 0) {
  6751. char *pos = os_strchr(buf + 7, ' ');
  6752. if (pos) {
  6753. *pos++ = '\0';
  6754. return wpas_global_ctrl_iface_ifname(global,
  6755. buf + 7, pos,
  6756. resp_len);
  6757. }
  6758. }
  6759. reply = wpas_global_ctrl_iface_redir(global, buf, resp_len);
  6760. if (reply)
  6761. return reply;
  6762. if (os_strcmp(buf, "PING") == 0)
  6763. level = MSG_EXCESSIVE;
  6764. wpa_hexdump_ascii(level, "RX global ctrl_iface",
  6765. (const u8 *) buf, os_strlen(buf));
  6766. reply = os_malloc(reply_size);
  6767. if (reply == NULL) {
  6768. *resp_len = 1;
  6769. return NULL;
  6770. }
  6771. os_memcpy(reply, "OK\n", 3);
  6772. reply_len = 3;
  6773. if (os_strcmp(buf, "PING") == 0) {
  6774. os_memcpy(reply, "PONG\n", 5);
  6775. reply_len = 5;
  6776. } else if (os_strncmp(buf, "INTERFACE_ADD ", 14) == 0) {
  6777. if (wpa_supplicant_global_iface_add(global, buf + 14))
  6778. reply_len = -1;
  6779. } else if (os_strncmp(buf, "INTERFACE_REMOVE ", 17) == 0) {
  6780. if (wpa_supplicant_global_iface_remove(global, buf + 17))
  6781. reply_len = -1;
  6782. } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) {
  6783. reply_len = wpa_supplicant_global_iface_list(
  6784. global, reply, reply_size);
  6785. } else if (os_strcmp(buf, "INTERFACES") == 0) {
  6786. reply_len = wpa_supplicant_global_iface_interfaces(
  6787. global, reply, reply_size);
  6788. } else if (os_strcmp(buf, "TERMINATE") == 0) {
  6789. wpa_supplicant_terminate_proc(global);
  6790. } else if (os_strcmp(buf, "SUSPEND") == 0) {
  6791. wpas_notify_suspend(global);
  6792. } else if (os_strcmp(buf, "RESUME") == 0) {
  6793. wpas_notify_resume(global);
  6794. } else if (os_strncmp(buf, "SET ", 4) == 0) {
  6795. if (wpas_global_ctrl_iface_set(global, buf + 4)) {
  6796. #ifdef CONFIG_P2P
  6797. if (global->p2p_init_wpa_s) {
  6798. os_free(reply);
  6799. /* Check if P2P redirection would work for this
  6800. * command. */
  6801. return wpa_supplicant_ctrl_iface_process(
  6802. global->p2p_init_wpa_s,
  6803. buf, resp_len);
  6804. }
  6805. #endif /* CONFIG_P2P */
  6806. reply_len = -1;
  6807. }
  6808. #ifndef CONFIG_NO_CONFIG_WRITE
  6809. } else if (os_strcmp(buf, "SAVE_CONFIG") == 0) {
  6810. if (wpas_global_ctrl_iface_save_config(global))
  6811. reply_len = -1;
  6812. #endif /* CONFIG_NO_CONFIG_WRITE */
  6813. } else if (os_strcmp(buf, "STATUS") == 0) {
  6814. reply_len = wpas_global_ctrl_iface_status(global, reply,
  6815. reply_size);
  6816. #ifdef CONFIG_MODULE_TESTS
  6817. } else if (os_strcmp(buf, "MODULE_TESTS") == 0) {
  6818. int wpas_module_tests(void);
  6819. if (wpas_module_tests() < 0)
  6820. reply_len = -1;
  6821. #endif /* CONFIG_MODULE_TESTS */
  6822. } else if (os_strncmp(buf, "RELOG", 5) == 0) {
  6823. if (wpa_debug_reopen_file() < 0)
  6824. reply_len = -1;
  6825. } else {
  6826. os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
  6827. reply_len = 16;
  6828. }
  6829. if (reply_len < 0) {
  6830. os_memcpy(reply, "FAIL\n", 5);
  6831. reply_len = 5;
  6832. }
  6833. *resp_len = reply_len;
  6834. return reply;
  6835. }