ctrl_iface.c 114 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827
  1. /*
  2. * WPA Supplicant / Control interface (shared code for all backends)
  3. * Copyright (c) 2004-2012, 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. #include "utils/common.h"
  10. #include "utils/eloop.h"
  11. #include "common/version.h"
  12. #include "common/ieee802_11_defs.h"
  13. #include "common/wpa_ctrl.h"
  14. #include "eap_peer/eap.h"
  15. #include "eapol_supp/eapol_supp_sm.h"
  16. #include "rsn_supp/wpa.h"
  17. #include "rsn_supp/preauth.h"
  18. #include "rsn_supp/pmksa_cache.h"
  19. #include "l2_packet/l2_packet.h"
  20. #include "wps/wps.h"
  21. #include "config.h"
  22. #include "wpa_supplicant_i.h"
  23. #include "driver_i.h"
  24. #include "wps_supplicant.h"
  25. #include "ibss_rsn.h"
  26. #include "ap.h"
  27. #include "p2p_supplicant.h"
  28. #include "p2p/p2p.h"
  29. #include "hs20_supplicant.h"
  30. #include "notify.h"
  31. #include "bss.h"
  32. #include "scan.h"
  33. #include "ctrl_iface.h"
  34. #include "interworking.h"
  35. #include "blacklist.h"
  36. #include "wpas_glue.h"
  37. #include "autoscan.h"
  38. extern struct wpa_driver_ops *wpa_drivers[];
  39. static int wpa_supplicant_global_iface_list(struct wpa_global *global,
  40. char *buf, int len);
  41. static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global,
  42. char *buf, int len);
  43. static int pno_start(struct wpa_supplicant *wpa_s)
  44. {
  45. int ret;
  46. size_t i, num_ssid;
  47. struct wpa_ssid *ssid;
  48. struct wpa_driver_scan_params params;
  49. if (wpa_s->pno)
  50. return 0;
  51. os_memset(&params, 0, sizeof(params));
  52. num_ssid = 0;
  53. ssid = wpa_s->conf->ssid;
  54. while (ssid) {
  55. if (!wpas_network_disabled(wpa_s, ssid))
  56. num_ssid++;
  57. ssid = ssid->next;
  58. }
  59. if (num_ssid > WPAS_MAX_SCAN_SSIDS) {
  60. wpa_printf(MSG_DEBUG, "PNO: Use only the first %u SSIDs from "
  61. "%u", WPAS_MAX_SCAN_SSIDS, (unsigned int) num_ssid);
  62. num_ssid = WPAS_MAX_SCAN_SSIDS;
  63. }
  64. if (num_ssid == 0) {
  65. wpa_printf(MSG_DEBUG, "PNO: No configured SSIDs");
  66. return -1;
  67. }
  68. params.filter_ssids = os_malloc(sizeof(struct wpa_driver_scan_filter) *
  69. num_ssid);
  70. if (params.filter_ssids == NULL)
  71. return -1;
  72. i = 0;
  73. ssid = wpa_s->conf->ssid;
  74. while (ssid) {
  75. if (!wpas_network_disabled(wpa_s, ssid)) {
  76. params.ssids[i].ssid = ssid->ssid;
  77. params.ssids[i].ssid_len = ssid->ssid_len;
  78. params.num_ssids++;
  79. os_memcpy(params.filter_ssids[i].ssid, ssid->ssid,
  80. ssid->ssid_len);
  81. params.filter_ssids[i].ssid_len = ssid->ssid_len;
  82. params.num_filter_ssids++;
  83. i++;
  84. if (i == num_ssid)
  85. break;
  86. }
  87. ssid = ssid->next;
  88. }
  89. if (wpa_s->conf->filter_rssi)
  90. params.filter_rssi = wpa_s->conf->filter_rssi;
  91. ret = wpa_drv_sched_scan(wpa_s, &params, 10 * 1000);
  92. os_free(params.filter_ssids);
  93. if (ret == 0)
  94. wpa_s->pno = 1;
  95. return ret;
  96. }
  97. static int pno_stop(struct wpa_supplicant *wpa_s)
  98. {
  99. if (wpa_s->pno) {
  100. wpa_s->pno = 0;
  101. return wpa_drv_stop_sched_scan(wpa_s);
  102. }
  103. return 0;
  104. }
  105. static int set_bssid_filter(struct wpa_supplicant *wpa_s, char *val)
  106. {
  107. char *pos;
  108. u8 addr[ETH_ALEN], *filter = NULL, *n;
  109. size_t count = 0;
  110. pos = val;
  111. while (pos) {
  112. if (*pos == '\0')
  113. break;
  114. if (hwaddr_aton(pos, addr)) {
  115. os_free(filter);
  116. return -1;
  117. }
  118. n = os_realloc_array(filter, count + 1, ETH_ALEN);
  119. if (n == NULL) {
  120. os_free(filter);
  121. return -1;
  122. }
  123. filter = n;
  124. os_memcpy(filter + count * ETH_ALEN, addr, ETH_ALEN);
  125. count++;
  126. pos = os_strchr(pos, ' ');
  127. if (pos)
  128. pos++;
  129. }
  130. wpa_hexdump(MSG_DEBUG, "bssid_filter", filter, count * ETH_ALEN);
  131. os_free(wpa_s->bssid_filter);
  132. wpa_s->bssid_filter = filter;
  133. wpa_s->bssid_filter_count = count;
  134. return 0;
  135. }
  136. static int wpa_supplicant_ctrl_iface_set(struct wpa_supplicant *wpa_s,
  137. char *cmd)
  138. {
  139. char *value;
  140. int ret = 0;
  141. value = os_strchr(cmd, ' ');
  142. if (value == NULL)
  143. return -1;
  144. *value++ = '\0';
  145. wpa_printf(MSG_DEBUG, "CTRL_IFACE SET '%s'='%s'", cmd, value);
  146. if (os_strcasecmp(cmd, "EAPOL::heldPeriod") == 0) {
  147. eapol_sm_configure(wpa_s->eapol,
  148. atoi(value), -1, -1, -1);
  149. } else if (os_strcasecmp(cmd, "EAPOL::authPeriod") == 0) {
  150. eapol_sm_configure(wpa_s->eapol,
  151. -1, atoi(value), -1, -1);
  152. } else if (os_strcasecmp(cmd, "EAPOL::startPeriod") == 0) {
  153. eapol_sm_configure(wpa_s->eapol,
  154. -1, -1, atoi(value), -1);
  155. } else if (os_strcasecmp(cmd, "EAPOL::maxStart") == 0) {
  156. eapol_sm_configure(wpa_s->eapol,
  157. -1, -1, -1, atoi(value));
  158. } else if (os_strcasecmp(cmd, "dot11RSNAConfigPMKLifetime") == 0) {
  159. if (wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_LIFETIME,
  160. atoi(value)))
  161. ret = -1;
  162. } else if (os_strcasecmp(cmd, "dot11RSNAConfigPMKReauthThreshold") ==
  163. 0) {
  164. if (wpa_sm_set_param(wpa_s->wpa, RSNA_PMK_REAUTH_THRESHOLD,
  165. atoi(value)))
  166. ret = -1;
  167. } else if (os_strcasecmp(cmd, "dot11RSNAConfigSATimeout") == 0) {
  168. if (wpa_sm_set_param(wpa_s->wpa, RSNA_SA_TIMEOUT, atoi(value)))
  169. ret = -1;
  170. } else if (os_strcasecmp(cmd, "wps_fragment_size") == 0) {
  171. wpa_s->wps_fragment_size = atoi(value);
  172. #ifdef CONFIG_WPS_TESTING
  173. } else if (os_strcasecmp(cmd, "wps_version_number") == 0) {
  174. long int val;
  175. val = strtol(value, NULL, 0);
  176. if (val < 0 || val > 0xff) {
  177. ret = -1;
  178. wpa_printf(MSG_DEBUG, "WPS: Invalid "
  179. "wps_version_number %ld", val);
  180. } else {
  181. wps_version_number = val;
  182. wpa_printf(MSG_DEBUG, "WPS: Testing - force WPS "
  183. "version %u.%u",
  184. (wps_version_number & 0xf0) >> 4,
  185. wps_version_number & 0x0f);
  186. }
  187. } else if (os_strcasecmp(cmd, "wps_testing_dummy_cred") == 0) {
  188. wps_testing_dummy_cred = atoi(value);
  189. wpa_printf(MSG_DEBUG, "WPS: Testing - dummy_cred=%d",
  190. wps_testing_dummy_cred);
  191. #endif /* CONFIG_WPS_TESTING */
  192. } else if (os_strcasecmp(cmd, "ampdu") == 0) {
  193. if (wpa_drv_ampdu(wpa_s, atoi(value)) < 0)
  194. ret = -1;
  195. #ifdef CONFIG_TDLS_TESTING
  196. } else if (os_strcasecmp(cmd, "tdls_testing") == 0) {
  197. extern unsigned int tdls_testing;
  198. tdls_testing = strtol(value, NULL, 0);
  199. wpa_printf(MSG_DEBUG, "TDLS: tdls_testing=0x%x", tdls_testing);
  200. #endif /* CONFIG_TDLS_TESTING */
  201. #ifdef CONFIG_TDLS
  202. } else if (os_strcasecmp(cmd, "tdls_disabled") == 0) {
  203. int disabled = atoi(value);
  204. wpa_printf(MSG_DEBUG, "TDLS: tdls_disabled=%d", disabled);
  205. if (disabled) {
  206. if (wpa_drv_tdls_oper(wpa_s, TDLS_DISABLE, NULL) < 0)
  207. ret = -1;
  208. } else if (wpa_drv_tdls_oper(wpa_s, TDLS_ENABLE, NULL) < 0)
  209. ret = -1;
  210. wpa_tdls_enable(wpa_s->wpa, !disabled);
  211. #endif /* CONFIG_TDLS */
  212. } else if (os_strcasecmp(cmd, "pno") == 0) {
  213. if (atoi(value))
  214. ret = pno_start(wpa_s);
  215. else
  216. ret = pno_stop(wpa_s);
  217. } else if (os_strcasecmp(cmd, "radio_disabled") == 0) {
  218. int disabled = atoi(value);
  219. if (wpa_drv_radio_disable(wpa_s, disabled) < 0)
  220. ret = -1;
  221. else if (disabled)
  222. wpa_supplicant_set_state(wpa_s, WPA_INACTIVE);
  223. } else if (os_strcasecmp(cmd, "uapsd") == 0) {
  224. if (os_strcmp(value, "disable") == 0)
  225. wpa_s->set_sta_uapsd = 0;
  226. else {
  227. int be, bk, vi, vo;
  228. char *pos;
  229. /* format: BE,BK,VI,VO;max SP Length */
  230. be = atoi(value);
  231. pos = os_strchr(value, ',');
  232. if (pos == NULL)
  233. return -1;
  234. pos++;
  235. bk = atoi(pos);
  236. pos = os_strchr(pos, ',');
  237. if (pos == NULL)
  238. return -1;
  239. pos++;
  240. vi = atoi(pos);
  241. pos = os_strchr(pos, ',');
  242. if (pos == NULL)
  243. return -1;
  244. pos++;
  245. vo = atoi(pos);
  246. /* ignore max SP Length for now */
  247. wpa_s->set_sta_uapsd = 1;
  248. wpa_s->sta_uapsd = 0;
  249. if (be)
  250. wpa_s->sta_uapsd |= BIT(0);
  251. if (bk)
  252. wpa_s->sta_uapsd |= BIT(1);
  253. if (vi)
  254. wpa_s->sta_uapsd |= BIT(2);
  255. if (vo)
  256. wpa_s->sta_uapsd |= BIT(3);
  257. }
  258. } else if (os_strcasecmp(cmd, "ps") == 0) {
  259. ret = wpa_drv_set_p2p_powersave(wpa_s, atoi(value), -1, -1);
  260. } else if (os_strcasecmp(cmd, "bssid_filter") == 0) {
  261. ret = set_bssid_filter(wpa_s, value);
  262. } else {
  263. value[-1] = '=';
  264. ret = wpa_config_process_global(wpa_s->conf, cmd, -1);
  265. if (ret == 0)
  266. wpa_supplicant_update_config(wpa_s);
  267. }
  268. return ret;
  269. }
  270. static int wpa_supplicant_ctrl_iface_get(struct wpa_supplicant *wpa_s,
  271. char *cmd, char *buf, size_t buflen)
  272. {
  273. int res = -1;
  274. wpa_printf(MSG_DEBUG, "CTRL_IFACE GET '%s'", cmd);
  275. if (os_strcmp(cmd, "version") == 0) {
  276. res = os_snprintf(buf, buflen, "%s", VERSION_STR);
  277. } else if (os_strcasecmp(cmd, "country") == 0) {
  278. if (wpa_s->conf->country[0] && wpa_s->conf->country[1])
  279. res = os_snprintf(buf, buflen, "%c%c",
  280. wpa_s->conf->country[0],
  281. wpa_s->conf->country[1]);
  282. }
  283. if (res < 0 || (unsigned int) res >= buflen)
  284. return -1;
  285. return res;
  286. }
  287. #ifdef IEEE8021X_EAPOL
  288. static int wpa_supplicant_ctrl_iface_preauth(struct wpa_supplicant *wpa_s,
  289. char *addr)
  290. {
  291. u8 bssid[ETH_ALEN];
  292. struct wpa_ssid *ssid = wpa_s->current_ssid;
  293. if (hwaddr_aton(addr, bssid)) {
  294. wpa_printf(MSG_DEBUG, "CTRL_IFACE PREAUTH: invalid address "
  295. "'%s'", addr);
  296. return -1;
  297. }
  298. wpa_printf(MSG_DEBUG, "CTRL_IFACE PREAUTH " MACSTR, MAC2STR(bssid));
  299. rsn_preauth_deinit(wpa_s->wpa);
  300. if (rsn_preauth_init(wpa_s->wpa, bssid, ssid ? &ssid->eap : NULL))
  301. return -1;
  302. return 0;
  303. }
  304. #endif /* IEEE8021X_EAPOL */
  305. #ifdef CONFIG_PEERKEY
  306. /* MLME-STKSTART.request(peer) */
  307. static int wpa_supplicant_ctrl_iface_stkstart(
  308. struct wpa_supplicant *wpa_s, char *addr)
  309. {
  310. u8 peer[ETH_ALEN];
  311. if (hwaddr_aton(addr, peer)) {
  312. wpa_printf(MSG_DEBUG, "CTRL_IFACE STKSTART: invalid "
  313. "address '%s'", addr);
  314. return -1;
  315. }
  316. wpa_printf(MSG_DEBUG, "CTRL_IFACE STKSTART " MACSTR,
  317. MAC2STR(peer));
  318. return wpa_sm_stkstart(wpa_s->wpa, peer);
  319. }
  320. #endif /* CONFIG_PEERKEY */
  321. #ifdef CONFIG_TDLS
  322. static int wpa_supplicant_ctrl_iface_tdls_discover(
  323. struct wpa_supplicant *wpa_s, char *addr)
  324. {
  325. u8 peer[ETH_ALEN];
  326. int ret;
  327. if (hwaddr_aton(addr, peer)) {
  328. wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_DISCOVER: invalid "
  329. "address '%s'", addr);
  330. return -1;
  331. }
  332. wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_DISCOVER " MACSTR,
  333. MAC2STR(peer));
  334. if (wpa_tdls_is_external_setup(wpa_s->wpa))
  335. ret = wpa_tdls_send_discovery_request(wpa_s->wpa, peer);
  336. else
  337. ret = wpa_drv_tdls_oper(wpa_s, TDLS_DISCOVERY_REQ, peer);
  338. return ret;
  339. }
  340. static int wpa_supplicant_ctrl_iface_tdls_setup(
  341. struct wpa_supplicant *wpa_s, char *addr)
  342. {
  343. u8 peer[ETH_ALEN];
  344. int ret;
  345. if (hwaddr_aton(addr, peer)) {
  346. wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_SETUP: invalid "
  347. "address '%s'", addr);
  348. return -1;
  349. }
  350. wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_SETUP " MACSTR,
  351. MAC2STR(peer));
  352. ret = wpa_tdls_reneg(wpa_s->wpa, peer);
  353. if (ret) {
  354. if (wpa_tdls_is_external_setup(wpa_s->wpa))
  355. ret = wpa_tdls_start(wpa_s->wpa, peer);
  356. else
  357. ret = wpa_drv_tdls_oper(wpa_s, TDLS_SETUP, peer);
  358. }
  359. return ret;
  360. }
  361. static int wpa_supplicant_ctrl_iface_tdls_teardown(
  362. struct wpa_supplicant *wpa_s, char *addr)
  363. {
  364. u8 peer[ETH_ALEN];
  365. if (hwaddr_aton(addr, peer)) {
  366. wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN: invalid "
  367. "address '%s'", addr);
  368. return -1;
  369. }
  370. wpa_printf(MSG_DEBUG, "CTRL_IFACE TDLS_TEARDOWN " MACSTR,
  371. MAC2STR(peer));
  372. return wpa_tdls_teardown_link(wpa_s->wpa, peer,
  373. WLAN_REASON_TDLS_TEARDOWN_UNSPECIFIED);
  374. }
  375. #endif /* CONFIG_TDLS */
  376. #ifdef CONFIG_IEEE80211R
  377. static int wpa_supplicant_ctrl_iface_ft_ds(
  378. struct wpa_supplicant *wpa_s, char *addr)
  379. {
  380. u8 target_ap[ETH_ALEN];
  381. struct wpa_bss *bss;
  382. const u8 *mdie;
  383. if (hwaddr_aton(addr, target_ap)) {
  384. wpa_printf(MSG_DEBUG, "CTRL_IFACE FT_DS: invalid "
  385. "address '%s'", addr);
  386. return -1;
  387. }
  388. wpa_printf(MSG_DEBUG, "CTRL_IFACE FT_DS " MACSTR, MAC2STR(target_ap));
  389. bss = wpa_bss_get_bssid(wpa_s, target_ap);
  390. if (bss)
  391. mdie = wpa_bss_get_ie(bss, WLAN_EID_MOBILITY_DOMAIN);
  392. else
  393. mdie = NULL;
  394. return wpa_ft_start_over_ds(wpa_s->wpa, target_ap, mdie);
  395. }
  396. #endif /* CONFIG_IEEE80211R */
  397. #ifdef CONFIG_WPS
  398. static int wpa_supplicant_ctrl_iface_wps_pbc(struct wpa_supplicant *wpa_s,
  399. char *cmd)
  400. {
  401. u8 bssid[ETH_ALEN], *_bssid = bssid;
  402. #ifdef CONFIG_P2P
  403. u8 p2p_dev_addr[ETH_ALEN];
  404. #endif /* CONFIG_P2P */
  405. #ifdef CONFIG_AP
  406. u8 *_p2p_dev_addr = NULL;
  407. #endif /* CONFIG_AP */
  408. if (cmd == NULL || os_strcmp(cmd, "any") == 0) {
  409. _bssid = NULL;
  410. #ifdef CONFIG_P2P
  411. } else if (os_strncmp(cmd, "p2p_dev_addr=", 13) == 0) {
  412. if (hwaddr_aton(cmd + 13, p2p_dev_addr)) {
  413. wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PBC: invalid "
  414. "P2P Device Address '%s'",
  415. cmd + 13);
  416. return -1;
  417. }
  418. _p2p_dev_addr = p2p_dev_addr;
  419. #endif /* CONFIG_P2P */
  420. } else if (hwaddr_aton(cmd, bssid)) {
  421. wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PBC: invalid BSSID '%s'",
  422. cmd);
  423. return -1;
  424. }
  425. #ifdef CONFIG_AP
  426. if (wpa_s->ap_iface)
  427. return wpa_supplicant_ap_wps_pbc(wpa_s, _bssid, _p2p_dev_addr);
  428. #endif /* CONFIG_AP */
  429. return wpas_wps_start_pbc(wpa_s, _bssid, 0);
  430. }
  431. static int wpa_supplicant_ctrl_iface_wps_pin(struct wpa_supplicant *wpa_s,
  432. char *cmd, char *buf,
  433. size_t buflen)
  434. {
  435. u8 bssid[ETH_ALEN], *_bssid = bssid;
  436. char *pin;
  437. int ret;
  438. pin = os_strchr(cmd, ' ');
  439. if (pin)
  440. *pin++ = '\0';
  441. if (os_strcmp(cmd, "any") == 0)
  442. _bssid = NULL;
  443. else if (os_strcmp(cmd, "get") == 0) {
  444. ret = wps_generate_pin();
  445. goto done;
  446. } else if (hwaddr_aton(cmd, bssid)) {
  447. wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_PIN: invalid BSSID '%s'",
  448. cmd);
  449. return -1;
  450. }
  451. #ifdef CONFIG_AP
  452. if (wpa_s->ap_iface)
  453. return wpa_supplicant_ap_wps_pin(wpa_s, _bssid, pin,
  454. buf, buflen);
  455. #endif /* CONFIG_AP */
  456. if (pin) {
  457. ret = wpas_wps_start_pin(wpa_s, _bssid, pin, 0,
  458. DEV_PW_DEFAULT);
  459. if (ret < 0)
  460. return -1;
  461. ret = os_snprintf(buf, buflen, "%s", pin);
  462. if (ret < 0 || (size_t) ret >= buflen)
  463. return -1;
  464. return ret;
  465. }
  466. ret = wpas_wps_start_pin(wpa_s, _bssid, NULL, 0, DEV_PW_DEFAULT);
  467. if (ret < 0)
  468. return -1;
  469. done:
  470. /* Return the generated PIN */
  471. ret = os_snprintf(buf, buflen, "%08d", ret);
  472. if (ret < 0 || (size_t) ret >= buflen)
  473. return -1;
  474. return ret;
  475. }
  476. static int wpa_supplicant_ctrl_iface_wps_check_pin(
  477. struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
  478. {
  479. char pin[9];
  480. size_t len;
  481. char *pos;
  482. int ret;
  483. wpa_hexdump_ascii_key(MSG_DEBUG, "WPS_CHECK_PIN",
  484. (u8 *) cmd, os_strlen(cmd));
  485. for (pos = cmd, len = 0; *pos != '\0'; pos++) {
  486. if (*pos < '0' || *pos > '9')
  487. continue;
  488. pin[len++] = *pos;
  489. if (len == 9) {
  490. wpa_printf(MSG_DEBUG, "WPS: Too long PIN");
  491. return -1;
  492. }
  493. }
  494. if (len != 4 && len != 8) {
  495. wpa_printf(MSG_DEBUG, "WPS: Invalid PIN length %d", (int) len);
  496. return -1;
  497. }
  498. pin[len] = '\0';
  499. if (len == 8) {
  500. unsigned int pin_val;
  501. pin_val = atoi(pin);
  502. if (!wps_pin_valid(pin_val)) {
  503. wpa_printf(MSG_DEBUG, "WPS: Invalid checksum digit");
  504. ret = os_snprintf(buf, buflen, "FAIL-CHECKSUM\n");
  505. if (ret < 0 || (size_t) ret >= buflen)
  506. return -1;
  507. return ret;
  508. }
  509. }
  510. ret = os_snprintf(buf, buflen, "%s", pin);
  511. if (ret < 0 || (size_t) ret >= buflen)
  512. return -1;
  513. return ret;
  514. }
  515. #ifdef CONFIG_WPS_OOB
  516. static int wpa_supplicant_ctrl_iface_wps_oob(struct wpa_supplicant *wpa_s,
  517. char *cmd)
  518. {
  519. char *path, *method, *name;
  520. path = os_strchr(cmd, ' ');
  521. if (path == NULL)
  522. return -1;
  523. *path++ = '\0';
  524. method = os_strchr(path, ' ');
  525. if (method == NULL)
  526. return -1;
  527. *method++ = '\0';
  528. name = os_strchr(method, ' ');
  529. if (name != NULL)
  530. *name++ = '\0';
  531. return wpas_wps_start_oob(wpa_s, cmd, path, method, name);
  532. }
  533. #endif /* CONFIG_WPS_OOB */
  534. #ifdef CONFIG_WPS_NFC
  535. static int wpa_supplicant_ctrl_iface_wps_nfc(struct wpa_supplicant *wpa_s,
  536. char *cmd)
  537. {
  538. u8 bssid[ETH_ALEN], *_bssid = bssid;
  539. if (cmd == NULL || cmd[0] == '\0')
  540. _bssid = NULL;
  541. else if (hwaddr_aton(cmd, bssid))
  542. return -1;
  543. return wpas_wps_start_nfc(wpa_s, _bssid);
  544. }
  545. static int wpa_supplicant_ctrl_iface_wps_nfc_token(
  546. struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
  547. {
  548. int ndef;
  549. struct wpabuf *buf;
  550. int res;
  551. if (os_strcmp(cmd, "WPS") == 0)
  552. ndef = 0;
  553. else if (os_strcmp(cmd, "NDEF") == 0)
  554. ndef = 1;
  555. else
  556. return -1;
  557. buf = wpas_wps_nfc_token(wpa_s, ndef);
  558. if (buf == NULL)
  559. return -1;
  560. res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
  561. wpabuf_len(buf));
  562. reply[res++] = '\n';
  563. reply[res] = '\0';
  564. wpabuf_free(buf);
  565. return res;
  566. }
  567. static int wpa_supplicant_ctrl_iface_wps_nfc_tag_read(
  568. struct wpa_supplicant *wpa_s, char *pos)
  569. {
  570. size_t len;
  571. struct wpabuf *buf;
  572. int ret;
  573. len = os_strlen(pos);
  574. if (len & 0x01)
  575. return -1;
  576. len /= 2;
  577. buf = wpabuf_alloc(len);
  578. if (buf == NULL)
  579. return -1;
  580. if (hexstr2bin(pos, wpabuf_put(buf, len), len) < 0) {
  581. wpabuf_free(buf);
  582. return -1;
  583. }
  584. ret = wpas_wps_nfc_tag_read(wpa_s, buf);
  585. wpabuf_free(buf);
  586. return ret;
  587. }
  588. #endif /* CONFIG_WPS_NFC */
  589. static int wpa_supplicant_ctrl_iface_wps_reg(struct wpa_supplicant *wpa_s,
  590. char *cmd)
  591. {
  592. u8 bssid[ETH_ALEN];
  593. char *pin;
  594. char *new_ssid;
  595. char *new_auth;
  596. char *new_encr;
  597. char *new_key;
  598. struct wps_new_ap_settings ap;
  599. pin = os_strchr(cmd, ' ');
  600. if (pin == NULL)
  601. return -1;
  602. *pin++ = '\0';
  603. if (hwaddr_aton(cmd, bssid)) {
  604. wpa_printf(MSG_DEBUG, "CTRL_IFACE WPS_REG: invalid BSSID '%s'",
  605. cmd);
  606. return -1;
  607. }
  608. new_ssid = os_strchr(pin, ' ');
  609. if (new_ssid == NULL)
  610. return wpas_wps_start_reg(wpa_s, bssid, pin, NULL);
  611. *new_ssid++ = '\0';
  612. new_auth = os_strchr(new_ssid, ' ');
  613. if (new_auth == NULL)
  614. return -1;
  615. *new_auth++ = '\0';
  616. new_encr = os_strchr(new_auth, ' ');
  617. if (new_encr == NULL)
  618. return -1;
  619. *new_encr++ = '\0';
  620. new_key = os_strchr(new_encr, ' ');
  621. if (new_key == NULL)
  622. return -1;
  623. *new_key++ = '\0';
  624. os_memset(&ap, 0, sizeof(ap));
  625. ap.ssid_hex = new_ssid;
  626. ap.auth = new_auth;
  627. ap.encr = new_encr;
  628. ap.key_hex = new_key;
  629. return wpas_wps_start_reg(wpa_s, bssid, pin, &ap);
  630. }
  631. #ifdef CONFIG_AP
  632. static int wpa_supplicant_ctrl_iface_wps_ap_pin(struct wpa_supplicant *wpa_s,
  633. char *cmd, char *buf,
  634. size_t buflen)
  635. {
  636. int timeout = 300;
  637. char *pos;
  638. const char *pin_txt;
  639. if (!wpa_s->ap_iface)
  640. return -1;
  641. pos = os_strchr(cmd, ' ');
  642. if (pos)
  643. *pos++ = '\0';
  644. if (os_strcmp(cmd, "disable") == 0) {
  645. wpas_wps_ap_pin_disable(wpa_s);
  646. return os_snprintf(buf, buflen, "OK\n");
  647. }
  648. if (os_strcmp(cmd, "random") == 0) {
  649. if (pos)
  650. timeout = atoi(pos);
  651. pin_txt = wpas_wps_ap_pin_random(wpa_s, timeout);
  652. if (pin_txt == NULL)
  653. return -1;
  654. return os_snprintf(buf, buflen, "%s", pin_txt);
  655. }
  656. if (os_strcmp(cmd, "get") == 0) {
  657. pin_txt = wpas_wps_ap_pin_get(wpa_s);
  658. if (pin_txt == NULL)
  659. return -1;
  660. return os_snprintf(buf, buflen, "%s", pin_txt);
  661. }
  662. if (os_strcmp(cmd, "set") == 0) {
  663. char *pin;
  664. if (pos == NULL)
  665. return -1;
  666. pin = pos;
  667. pos = os_strchr(pos, ' ');
  668. if (pos) {
  669. *pos++ = '\0';
  670. timeout = atoi(pos);
  671. }
  672. if (os_strlen(pin) > buflen)
  673. return -1;
  674. if (wpas_wps_ap_pin_set(wpa_s, pin, timeout) < 0)
  675. return -1;
  676. return os_snprintf(buf, buflen, "%s", pin);
  677. }
  678. return -1;
  679. }
  680. #endif /* CONFIG_AP */
  681. #ifdef CONFIG_WPS_ER
  682. static int wpa_supplicant_ctrl_iface_wps_er_pin(struct wpa_supplicant *wpa_s,
  683. char *cmd)
  684. {
  685. char *uuid = cmd, *pin, *pos;
  686. u8 addr_buf[ETH_ALEN], *addr = NULL;
  687. pin = os_strchr(uuid, ' ');
  688. if (pin == NULL)
  689. return -1;
  690. *pin++ = '\0';
  691. pos = os_strchr(pin, ' ');
  692. if (pos) {
  693. *pos++ = '\0';
  694. if (hwaddr_aton(pos, addr_buf) == 0)
  695. addr = addr_buf;
  696. }
  697. return wpas_wps_er_add_pin(wpa_s, addr, uuid, pin);
  698. }
  699. static int wpa_supplicant_ctrl_iface_wps_er_learn(struct wpa_supplicant *wpa_s,
  700. char *cmd)
  701. {
  702. char *uuid = cmd, *pin;
  703. pin = os_strchr(uuid, ' ');
  704. if (pin == NULL)
  705. return -1;
  706. *pin++ = '\0';
  707. return wpas_wps_er_learn(wpa_s, uuid, pin);
  708. }
  709. static int wpa_supplicant_ctrl_iface_wps_er_set_config(
  710. struct wpa_supplicant *wpa_s, char *cmd)
  711. {
  712. char *uuid = cmd, *id;
  713. id = os_strchr(uuid, ' ');
  714. if (id == NULL)
  715. return -1;
  716. *id++ = '\0';
  717. return wpas_wps_er_set_config(wpa_s, uuid, atoi(id));
  718. }
  719. static int wpa_supplicant_ctrl_iface_wps_er_config(
  720. struct wpa_supplicant *wpa_s, char *cmd)
  721. {
  722. char *pin;
  723. char *new_ssid;
  724. char *new_auth;
  725. char *new_encr;
  726. char *new_key;
  727. struct wps_new_ap_settings ap;
  728. pin = os_strchr(cmd, ' ');
  729. if (pin == NULL)
  730. return -1;
  731. *pin++ = '\0';
  732. new_ssid = os_strchr(pin, ' ');
  733. if (new_ssid == NULL)
  734. return -1;
  735. *new_ssid++ = '\0';
  736. new_auth = os_strchr(new_ssid, ' ');
  737. if (new_auth == NULL)
  738. return -1;
  739. *new_auth++ = '\0';
  740. new_encr = os_strchr(new_auth, ' ');
  741. if (new_encr == NULL)
  742. return -1;
  743. *new_encr++ = '\0';
  744. new_key = os_strchr(new_encr, ' ');
  745. if (new_key == NULL)
  746. return -1;
  747. *new_key++ = '\0';
  748. os_memset(&ap, 0, sizeof(ap));
  749. ap.ssid_hex = new_ssid;
  750. ap.auth = new_auth;
  751. ap.encr = new_encr;
  752. ap.key_hex = new_key;
  753. return wpas_wps_er_config(wpa_s, cmd, pin, &ap);
  754. }
  755. #ifdef CONFIG_WPS_NFC
  756. static int wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
  757. struct wpa_supplicant *wpa_s, char *cmd, char *reply, size_t max_len)
  758. {
  759. int ndef;
  760. struct wpabuf *buf;
  761. int res;
  762. char *uuid;
  763. uuid = os_strchr(cmd, ' ');
  764. if (uuid == NULL)
  765. return -1;
  766. *uuid++ = '\0';
  767. if (os_strcmp(cmd, "WPS") == 0)
  768. ndef = 0;
  769. else if (os_strcmp(cmd, "NDEF") == 0)
  770. ndef = 1;
  771. else
  772. return -1;
  773. buf = wpas_wps_er_nfc_config_token(wpa_s, ndef, uuid);
  774. if (buf == NULL)
  775. return -1;
  776. res = wpa_snprintf_hex_uppercase(reply, max_len, wpabuf_head(buf),
  777. wpabuf_len(buf));
  778. reply[res++] = '\n';
  779. reply[res] = '\0';
  780. wpabuf_free(buf);
  781. return res;
  782. }
  783. #endif /* CONFIG_WPS_NFC */
  784. #endif /* CONFIG_WPS_ER */
  785. #endif /* CONFIG_WPS */
  786. #ifdef CONFIG_IBSS_RSN
  787. static int wpa_supplicant_ctrl_iface_ibss_rsn(
  788. struct wpa_supplicant *wpa_s, char *addr)
  789. {
  790. u8 peer[ETH_ALEN];
  791. if (hwaddr_aton(addr, peer)) {
  792. wpa_printf(MSG_DEBUG, "CTRL_IFACE IBSS_RSN: invalid "
  793. "address '%s'", addr);
  794. return -1;
  795. }
  796. wpa_printf(MSG_DEBUG, "CTRL_IFACE IBSS_RSN " MACSTR,
  797. MAC2STR(peer));
  798. return ibss_rsn_start(wpa_s->ibss_rsn, peer);
  799. }
  800. #endif /* CONFIG_IBSS_RSN */
  801. static int wpa_supplicant_ctrl_iface_ctrl_rsp(struct wpa_supplicant *wpa_s,
  802. char *rsp)
  803. {
  804. #ifdef IEEE8021X_EAPOL
  805. char *pos, *id_pos;
  806. int id;
  807. struct wpa_ssid *ssid;
  808. pos = os_strchr(rsp, '-');
  809. if (pos == NULL)
  810. return -1;
  811. *pos++ = '\0';
  812. id_pos = pos;
  813. pos = os_strchr(pos, ':');
  814. if (pos == NULL)
  815. return -1;
  816. *pos++ = '\0';
  817. id = atoi(id_pos);
  818. wpa_printf(MSG_DEBUG, "CTRL_IFACE: field=%s id=%d", rsp, id);
  819. wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
  820. (u8 *) pos, os_strlen(pos));
  821. ssid = wpa_config_get_network(wpa_s->conf, id);
  822. if (ssid == NULL) {
  823. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
  824. "to update", id);
  825. return -1;
  826. }
  827. return wpa_supplicant_ctrl_iface_ctrl_rsp_handle(wpa_s, ssid, rsp,
  828. pos);
  829. #else /* IEEE8021X_EAPOL */
  830. wpa_printf(MSG_DEBUG, "CTRL_IFACE: 802.1X not included");
  831. return -1;
  832. #endif /* IEEE8021X_EAPOL */
  833. }
  834. static int wpa_supplicant_ctrl_iface_status(struct wpa_supplicant *wpa_s,
  835. const char *params,
  836. char *buf, size_t buflen)
  837. {
  838. char *pos, *end, tmp[30];
  839. int res, verbose, wps, ret;
  840. verbose = os_strcmp(params, "-VERBOSE") == 0;
  841. wps = os_strcmp(params, "-WPS") == 0;
  842. pos = buf;
  843. end = buf + buflen;
  844. if (wpa_s->wpa_state >= WPA_ASSOCIATED) {
  845. struct wpa_ssid *ssid = wpa_s->current_ssid;
  846. ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n",
  847. MAC2STR(wpa_s->bssid));
  848. if (ret < 0 || ret >= end - pos)
  849. return pos - buf;
  850. pos += ret;
  851. if (ssid) {
  852. u8 *_ssid = ssid->ssid;
  853. size_t ssid_len = ssid->ssid_len;
  854. u8 ssid_buf[MAX_SSID_LEN];
  855. if (ssid_len == 0) {
  856. int _res = wpa_drv_get_ssid(wpa_s, ssid_buf);
  857. if (_res < 0)
  858. ssid_len = 0;
  859. else
  860. ssid_len = _res;
  861. _ssid = ssid_buf;
  862. }
  863. ret = os_snprintf(pos, end - pos, "ssid=%s\nid=%d\n",
  864. wpa_ssid_txt(_ssid, ssid_len),
  865. ssid->id);
  866. if (ret < 0 || ret >= end - pos)
  867. return pos - buf;
  868. pos += ret;
  869. if (wps && ssid->passphrase &&
  870. wpa_key_mgmt_wpa_psk(ssid->key_mgmt) &&
  871. (ssid->mode == WPAS_MODE_AP ||
  872. ssid->mode == WPAS_MODE_P2P_GO)) {
  873. ret = os_snprintf(pos, end - pos,
  874. "passphrase=%s\n",
  875. ssid->passphrase);
  876. if (ret < 0 || ret >= end - pos)
  877. return pos - buf;
  878. pos += ret;
  879. }
  880. if (ssid->id_str) {
  881. ret = os_snprintf(pos, end - pos,
  882. "id_str=%s\n",
  883. ssid->id_str);
  884. if (ret < 0 || ret >= end - pos)
  885. return pos - buf;
  886. pos += ret;
  887. }
  888. switch (ssid->mode) {
  889. case WPAS_MODE_INFRA:
  890. ret = os_snprintf(pos, end - pos,
  891. "mode=station\n");
  892. break;
  893. case WPAS_MODE_IBSS:
  894. ret = os_snprintf(pos, end - pos,
  895. "mode=IBSS\n");
  896. break;
  897. case WPAS_MODE_AP:
  898. ret = os_snprintf(pos, end - pos,
  899. "mode=AP\n");
  900. break;
  901. case WPAS_MODE_P2P_GO:
  902. ret = os_snprintf(pos, end - pos,
  903. "mode=P2P GO\n");
  904. break;
  905. case WPAS_MODE_P2P_GROUP_FORMATION:
  906. ret = os_snprintf(pos, end - pos,
  907. "mode=P2P GO - group "
  908. "formation\n");
  909. break;
  910. default:
  911. ret = 0;
  912. break;
  913. }
  914. if (ret < 0 || ret >= end - pos)
  915. return pos - buf;
  916. pos += ret;
  917. }
  918. #ifdef CONFIG_AP
  919. if (wpa_s->ap_iface) {
  920. pos += ap_ctrl_iface_wpa_get_status(wpa_s, pos,
  921. end - pos,
  922. verbose);
  923. } else
  924. #endif /* CONFIG_AP */
  925. pos += wpa_sm_get_status(wpa_s->wpa, pos, end - pos, verbose);
  926. }
  927. ret = os_snprintf(pos, end - pos, "wpa_state=%s\n",
  928. wpa_supplicant_state_txt(wpa_s->wpa_state));
  929. if (ret < 0 || ret >= end - pos)
  930. return pos - buf;
  931. pos += ret;
  932. if (wpa_s->l2 &&
  933. l2_packet_get_ip_addr(wpa_s->l2, tmp, sizeof(tmp)) >= 0) {
  934. ret = os_snprintf(pos, end - pos, "ip_address=%s\n", tmp);
  935. if (ret < 0 || ret >= end - pos)
  936. return pos - buf;
  937. pos += ret;
  938. }
  939. #ifdef CONFIG_P2P
  940. if (wpa_s->global->p2p) {
  941. ret = os_snprintf(pos, end - pos, "p2p_device_address=" MACSTR
  942. "\n", MAC2STR(wpa_s->global->p2p_dev_addr));
  943. if (ret < 0 || ret >= end - pos)
  944. return pos - buf;
  945. pos += ret;
  946. }
  947. #endif /* CONFIG_P2P */
  948. ret = os_snprintf(pos, end - pos, "address=" MACSTR "\n",
  949. MAC2STR(wpa_s->own_addr));
  950. if (ret < 0 || ret >= end - pos)
  951. return pos - buf;
  952. pos += ret;
  953. #ifdef CONFIG_HS20
  954. if (wpa_s->current_bss &&
  955. wpa_bss_get_vendor_ie(wpa_s->current_bss, HS20_IE_VENDOR_TYPE)) {
  956. ret = os_snprintf(pos, end - pos, "hs20=1\n");
  957. if (ret < 0 || ret >= end - pos)
  958. return pos - buf;
  959. pos += ret;
  960. }
  961. #endif /* CONFIG_HS20 */
  962. if (wpa_key_mgmt_wpa_ieee8021x(wpa_s->key_mgmt) ||
  963. wpa_s->key_mgmt == WPA_KEY_MGMT_IEEE8021X_NO_WPA) {
  964. res = eapol_sm_get_status(wpa_s->eapol, pos, end - pos,
  965. verbose);
  966. if (res >= 0)
  967. pos += res;
  968. }
  969. res = rsn_preauth_get_status(wpa_s->wpa, pos, end - pos, verbose);
  970. if (res >= 0)
  971. pos += res;
  972. return pos - buf;
  973. }
  974. static int wpa_supplicant_ctrl_iface_bssid(struct wpa_supplicant *wpa_s,
  975. char *cmd)
  976. {
  977. char *pos;
  978. int id;
  979. struct wpa_ssid *ssid;
  980. u8 bssid[ETH_ALEN];
  981. /* cmd: "<network id> <BSSID>" */
  982. pos = os_strchr(cmd, ' ');
  983. if (pos == NULL)
  984. return -1;
  985. *pos++ = '\0';
  986. id = atoi(cmd);
  987. wpa_printf(MSG_DEBUG, "CTRL_IFACE: id=%d bssid='%s'", id, pos);
  988. if (hwaddr_aton(pos, bssid)) {
  989. wpa_printf(MSG_DEBUG ,"CTRL_IFACE: invalid BSSID '%s'", pos);
  990. return -1;
  991. }
  992. ssid = wpa_config_get_network(wpa_s->conf, id);
  993. if (ssid == NULL) {
  994. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
  995. "to update", id);
  996. return -1;
  997. }
  998. os_memcpy(ssid->bssid, bssid, ETH_ALEN);
  999. ssid->bssid_set = !is_zero_ether_addr(bssid);
  1000. return 0;
  1001. }
  1002. static int wpa_supplicant_ctrl_iface_blacklist(struct wpa_supplicant *wpa_s,
  1003. char *cmd, char *buf,
  1004. size_t buflen)
  1005. {
  1006. u8 bssid[ETH_ALEN];
  1007. struct wpa_blacklist *e;
  1008. char *pos, *end;
  1009. int ret;
  1010. /* cmd: "BLACKLIST [<BSSID>]" */
  1011. if (*cmd == '\0') {
  1012. pos = buf;
  1013. end = buf + buflen;
  1014. e = wpa_s->blacklist;
  1015. while (e) {
  1016. ret = os_snprintf(pos, end - pos, MACSTR "\n",
  1017. MAC2STR(e->bssid));
  1018. if (ret < 0 || ret >= end - pos)
  1019. return pos - buf;
  1020. pos += ret;
  1021. e = e->next;
  1022. }
  1023. return pos - buf;
  1024. }
  1025. cmd++;
  1026. if (os_strncmp(cmd, "clear", 5) == 0) {
  1027. wpa_blacklist_clear(wpa_s);
  1028. os_memcpy(buf, "OK\n", 3);
  1029. return 3;
  1030. }
  1031. wpa_printf(MSG_DEBUG, "CTRL_IFACE: BLACKLIST bssid='%s'", cmd);
  1032. if (hwaddr_aton(cmd, bssid)) {
  1033. wpa_printf(MSG_DEBUG, "CTRL_IFACE: invalid BSSID '%s'", cmd);
  1034. return -1;
  1035. }
  1036. /*
  1037. * Add the BSSID twice, so its count will be 2, causing it to be
  1038. * skipped when processing scan results.
  1039. */
  1040. ret = wpa_blacklist_add(wpa_s, bssid);
  1041. if (ret != 0)
  1042. return -1;
  1043. ret = wpa_blacklist_add(wpa_s, bssid);
  1044. if (ret != 0)
  1045. return -1;
  1046. os_memcpy(buf, "OK\n", 3);
  1047. return 3;
  1048. }
  1049. extern int wpa_debug_level;
  1050. extern int wpa_debug_timestamp;
  1051. static const char * debug_level_str(int level)
  1052. {
  1053. switch (level) {
  1054. case MSG_EXCESSIVE:
  1055. return "EXCESSIVE";
  1056. case MSG_MSGDUMP:
  1057. return "MSGDUMP";
  1058. case MSG_DEBUG:
  1059. return "DEBUG";
  1060. case MSG_INFO:
  1061. return "INFO";
  1062. case MSG_WARNING:
  1063. return "WARNING";
  1064. case MSG_ERROR:
  1065. return "ERROR";
  1066. default:
  1067. return "?";
  1068. }
  1069. }
  1070. static int str_to_debug_level(const char *s)
  1071. {
  1072. if (os_strcasecmp(s, "EXCESSIVE") == 0)
  1073. return MSG_EXCESSIVE;
  1074. if (os_strcasecmp(s, "MSGDUMP") == 0)
  1075. return MSG_MSGDUMP;
  1076. if (os_strcasecmp(s, "DEBUG") == 0)
  1077. return MSG_DEBUG;
  1078. if (os_strcasecmp(s, "INFO") == 0)
  1079. return MSG_INFO;
  1080. if (os_strcasecmp(s, "WARNING") == 0)
  1081. return MSG_WARNING;
  1082. if (os_strcasecmp(s, "ERROR") == 0)
  1083. return MSG_ERROR;
  1084. return -1;
  1085. }
  1086. static int wpa_supplicant_ctrl_iface_log_level(struct wpa_supplicant *wpa_s,
  1087. char *cmd, char *buf,
  1088. size_t buflen)
  1089. {
  1090. char *pos, *end, *stamp;
  1091. int ret;
  1092. if (cmd == NULL) {
  1093. return -1;
  1094. }
  1095. /* cmd: "LOG_LEVEL [<level>]" */
  1096. if (*cmd == '\0') {
  1097. pos = buf;
  1098. end = buf + buflen;
  1099. ret = os_snprintf(pos, end - pos, "Current level: %s\n"
  1100. "Timestamp: %d\n",
  1101. debug_level_str(wpa_debug_level),
  1102. wpa_debug_timestamp);
  1103. if (ret < 0 || ret >= end - pos)
  1104. ret = 0;
  1105. return ret;
  1106. }
  1107. while (*cmd == ' ')
  1108. cmd++;
  1109. stamp = os_strchr(cmd, ' ');
  1110. if (stamp) {
  1111. *stamp++ = '\0';
  1112. while (*stamp == ' ') {
  1113. stamp++;
  1114. }
  1115. }
  1116. if (cmd && os_strlen(cmd)) {
  1117. int level = str_to_debug_level(cmd);
  1118. if (level < 0)
  1119. return -1;
  1120. wpa_debug_level = level;
  1121. }
  1122. if (stamp && os_strlen(stamp))
  1123. wpa_debug_timestamp = atoi(stamp);
  1124. os_memcpy(buf, "OK\n", 3);
  1125. return 3;
  1126. }
  1127. static int wpa_supplicant_ctrl_iface_list_networks(
  1128. struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
  1129. {
  1130. char *pos, *end;
  1131. struct wpa_ssid *ssid;
  1132. int ret;
  1133. pos = buf;
  1134. end = buf + buflen;
  1135. ret = os_snprintf(pos, end - pos,
  1136. "network id / ssid / bssid / flags\n");
  1137. if (ret < 0 || ret >= end - pos)
  1138. return pos - buf;
  1139. pos += ret;
  1140. ssid = wpa_s->conf->ssid;
  1141. while (ssid) {
  1142. ret = os_snprintf(pos, end - pos, "%d\t%s",
  1143. ssid->id,
  1144. wpa_ssid_txt(ssid->ssid, ssid->ssid_len));
  1145. if (ret < 0 || ret >= end - pos)
  1146. return pos - buf;
  1147. pos += ret;
  1148. if (ssid->bssid_set) {
  1149. ret = os_snprintf(pos, end - pos, "\t" MACSTR,
  1150. MAC2STR(ssid->bssid));
  1151. } else {
  1152. ret = os_snprintf(pos, end - pos, "\tany");
  1153. }
  1154. if (ret < 0 || ret >= end - pos)
  1155. return pos - buf;
  1156. pos += ret;
  1157. ret = os_snprintf(pos, end - pos, "\t%s%s%s",
  1158. ssid == wpa_s->current_ssid ?
  1159. "[CURRENT]" : "",
  1160. ssid->disabled ? "[DISABLED]" : "",
  1161. ssid->disabled == 2 ? "[P2P-PERSISTENT]" :
  1162. "");
  1163. if (ret < 0 || ret >= end - pos)
  1164. return pos - buf;
  1165. pos += ret;
  1166. ret = os_snprintf(pos, end - pos, "\n");
  1167. if (ret < 0 || ret >= end - pos)
  1168. return pos - buf;
  1169. pos += ret;
  1170. ssid = ssid->next;
  1171. }
  1172. return pos - buf;
  1173. }
  1174. static char * wpa_supplicant_cipher_txt(char *pos, char *end, int cipher)
  1175. {
  1176. int first = 1, ret;
  1177. ret = os_snprintf(pos, end - pos, "-");
  1178. if (ret < 0 || ret >= end - pos)
  1179. return pos;
  1180. pos += ret;
  1181. if (cipher & WPA_CIPHER_NONE) {
  1182. ret = os_snprintf(pos, end - pos, "%sNONE", first ? "" : "+");
  1183. if (ret < 0 || ret >= end - pos)
  1184. return pos;
  1185. pos += ret;
  1186. first = 0;
  1187. }
  1188. if (cipher & WPA_CIPHER_WEP40) {
  1189. ret = os_snprintf(pos, end - pos, "%sWEP40", first ? "" : "+");
  1190. if (ret < 0 || ret >= end - pos)
  1191. return pos;
  1192. pos += ret;
  1193. first = 0;
  1194. }
  1195. if (cipher & WPA_CIPHER_WEP104) {
  1196. ret = os_snprintf(pos, end - pos, "%sWEP104",
  1197. first ? "" : "+");
  1198. if (ret < 0 || ret >= end - pos)
  1199. return pos;
  1200. pos += ret;
  1201. first = 0;
  1202. }
  1203. if (cipher & WPA_CIPHER_TKIP) {
  1204. ret = os_snprintf(pos, end - pos, "%sTKIP", first ? "" : "+");
  1205. if (ret < 0 || ret >= end - pos)
  1206. return pos;
  1207. pos += ret;
  1208. first = 0;
  1209. }
  1210. if (cipher & WPA_CIPHER_CCMP) {
  1211. ret = os_snprintf(pos, end - pos, "%sCCMP", first ? "" : "+");
  1212. if (ret < 0 || ret >= end - pos)
  1213. return pos;
  1214. pos += ret;
  1215. first = 0;
  1216. }
  1217. return pos;
  1218. }
  1219. static char * wpa_supplicant_ie_txt(char *pos, char *end, const char *proto,
  1220. const u8 *ie, size_t ie_len)
  1221. {
  1222. struct wpa_ie_data data;
  1223. int first, ret;
  1224. ret = os_snprintf(pos, end - pos, "[%s-", proto);
  1225. if (ret < 0 || ret >= end - pos)
  1226. return pos;
  1227. pos += ret;
  1228. if (wpa_parse_wpa_ie(ie, ie_len, &data) < 0) {
  1229. ret = os_snprintf(pos, end - pos, "?]");
  1230. if (ret < 0 || ret >= end - pos)
  1231. return pos;
  1232. pos += ret;
  1233. return pos;
  1234. }
  1235. first = 1;
  1236. if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X) {
  1237. ret = os_snprintf(pos, end - pos, "%sEAP", first ? "" : "+");
  1238. if (ret < 0 || ret >= end - pos)
  1239. return pos;
  1240. pos += ret;
  1241. first = 0;
  1242. }
  1243. if (data.key_mgmt & WPA_KEY_MGMT_PSK) {
  1244. ret = os_snprintf(pos, end - pos, "%sPSK", first ? "" : "+");
  1245. if (ret < 0 || ret >= end - pos)
  1246. return pos;
  1247. pos += ret;
  1248. first = 0;
  1249. }
  1250. if (data.key_mgmt & WPA_KEY_MGMT_WPA_NONE) {
  1251. ret = os_snprintf(pos, end - pos, "%sNone", first ? "" : "+");
  1252. if (ret < 0 || ret >= end - pos)
  1253. return pos;
  1254. pos += ret;
  1255. first = 0;
  1256. }
  1257. #ifdef CONFIG_IEEE80211R
  1258. if (data.key_mgmt & WPA_KEY_MGMT_FT_IEEE8021X) {
  1259. ret = os_snprintf(pos, end - pos, "%sFT/EAP",
  1260. first ? "" : "+");
  1261. if (ret < 0 || ret >= end - pos)
  1262. return pos;
  1263. pos += ret;
  1264. first = 0;
  1265. }
  1266. if (data.key_mgmt & WPA_KEY_MGMT_FT_PSK) {
  1267. ret = os_snprintf(pos, end - pos, "%sFT/PSK",
  1268. first ? "" : "+");
  1269. if (ret < 0 || ret >= end - pos)
  1270. return pos;
  1271. pos += ret;
  1272. first = 0;
  1273. }
  1274. #endif /* CONFIG_IEEE80211R */
  1275. #ifdef CONFIG_IEEE80211W
  1276. if (data.key_mgmt & WPA_KEY_MGMT_IEEE8021X_SHA256) {
  1277. ret = os_snprintf(pos, end - pos, "%sEAP-SHA256",
  1278. first ? "" : "+");
  1279. if (ret < 0 || ret >= end - pos)
  1280. return pos;
  1281. pos += ret;
  1282. first = 0;
  1283. }
  1284. if (data.key_mgmt & WPA_KEY_MGMT_PSK_SHA256) {
  1285. ret = os_snprintf(pos, end - pos, "%sPSK-SHA256",
  1286. first ? "" : "+");
  1287. if (ret < 0 || ret >= end - pos)
  1288. return pos;
  1289. pos += ret;
  1290. first = 0;
  1291. }
  1292. #endif /* CONFIG_IEEE80211W */
  1293. pos = wpa_supplicant_cipher_txt(pos, end, data.pairwise_cipher);
  1294. if (data.capabilities & WPA_CAPABILITY_PREAUTH) {
  1295. ret = os_snprintf(pos, end - pos, "-preauth");
  1296. if (ret < 0 || ret >= end - pos)
  1297. return pos;
  1298. pos += ret;
  1299. }
  1300. ret = os_snprintf(pos, end - pos, "]");
  1301. if (ret < 0 || ret >= end - pos)
  1302. return pos;
  1303. pos += ret;
  1304. return pos;
  1305. }
  1306. #ifdef CONFIG_WPS
  1307. static char * wpa_supplicant_wps_ie_txt_buf(struct wpa_supplicant *wpa_s,
  1308. char *pos, char *end,
  1309. struct wpabuf *wps_ie)
  1310. {
  1311. int ret;
  1312. const char *txt;
  1313. if (wps_ie == NULL)
  1314. return pos;
  1315. if (wps_is_selected_pbc_registrar(wps_ie))
  1316. txt = "[WPS-PBC]";
  1317. #ifdef CONFIG_WPS2
  1318. else if (wps_is_addr_authorized(wps_ie, wpa_s->own_addr, 0))
  1319. txt = "[WPS-AUTH]";
  1320. #endif /* CONFIG_WPS2 */
  1321. else if (wps_is_selected_pin_registrar(wps_ie))
  1322. txt = "[WPS-PIN]";
  1323. else
  1324. txt = "[WPS]";
  1325. ret = os_snprintf(pos, end - pos, "%s", txt);
  1326. if (ret >= 0 && ret < end - pos)
  1327. pos += ret;
  1328. wpabuf_free(wps_ie);
  1329. return pos;
  1330. }
  1331. #endif /* CONFIG_WPS */
  1332. static char * wpa_supplicant_wps_ie_txt(struct wpa_supplicant *wpa_s,
  1333. char *pos, char *end,
  1334. const struct wpa_bss *bss)
  1335. {
  1336. #ifdef CONFIG_WPS
  1337. struct wpabuf *wps_ie;
  1338. wps_ie = wpa_bss_get_vendor_ie_multi(bss, WPS_IE_VENDOR_TYPE);
  1339. return wpa_supplicant_wps_ie_txt_buf(wpa_s, pos, end, wps_ie);
  1340. #else /* CONFIG_WPS */
  1341. return pos;
  1342. #endif /* CONFIG_WPS */
  1343. }
  1344. /* Format one result on one text line into a buffer. */
  1345. static int wpa_supplicant_ctrl_iface_scan_result(
  1346. struct wpa_supplicant *wpa_s,
  1347. const struct wpa_bss *bss, char *buf, size_t buflen)
  1348. {
  1349. char *pos, *end;
  1350. int ret;
  1351. const u8 *ie, *ie2, *p2p;
  1352. p2p = wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE);
  1353. if (p2p && bss->ssid_len == P2P_WILDCARD_SSID_LEN &&
  1354. os_memcmp(bss->ssid, P2P_WILDCARD_SSID, P2P_WILDCARD_SSID_LEN) ==
  1355. 0)
  1356. return 0; /* Do not show P2P listen discovery results here */
  1357. pos = buf;
  1358. end = buf + buflen;
  1359. ret = os_snprintf(pos, end - pos, MACSTR "\t%d\t%d\t",
  1360. MAC2STR(bss->bssid), bss->freq, bss->level);
  1361. if (ret < 0 || ret >= end - pos)
  1362. return -1;
  1363. pos += ret;
  1364. ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
  1365. if (ie)
  1366. pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie, 2 + ie[1]);
  1367. ie2 = wpa_bss_get_ie(bss, WLAN_EID_RSN);
  1368. if (ie2)
  1369. pos = wpa_supplicant_ie_txt(pos, end, "WPA2", ie2, 2 + ie2[1]);
  1370. pos = wpa_supplicant_wps_ie_txt(wpa_s, pos, end, bss);
  1371. if (!ie && !ie2 && bss->caps & IEEE80211_CAP_PRIVACY) {
  1372. ret = os_snprintf(pos, end - pos, "[WEP]");
  1373. if (ret < 0 || ret >= end - pos)
  1374. return -1;
  1375. pos += ret;
  1376. }
  1377. if (bss->caps & IEEE80211_CAP_IBSS) {
  1378. ret = os_snprintf(pos, end - pos, "[IBSS]");
  1379. if (ret < 0 || ret >= end - pos)
  1380. return -1;
  1381. pos += ret;
  1382. }
  1383. if (bss->caps & IEEE80211_CAP_ESS) {
  1384. ret = os_snprintf(pos, end - pos, "[ESS]");
  1385. if (ret < 0 || ret >= end - pos)
  1386. return -1;
  1387. pos += ret;
  1388. }
  1389. if (p2p) {
  1390. ret = os_snprintf(pos, end - pos, "[P2P]");
  1391. if (ret < 0 || ret >= end - pos)
  1392. return -1;
  1393. pos += ret;
  1394. }
  1395. #ifdef CONFIG_HS20
  1396. if (wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE)) {
  1397. ret = os_snprintf(pos, end - pos, "[HS20]");
  1398. if (ret < 0 || ret >= end - pos)
  1399. return -1;
  1400. pos += ret;
  1401. }
  1402. #endif /* CONFIG_HS20 */
  1403. ret = os_snprintf(pos, end - pos, "\t%s",
  1404. wpa_ssid_txt(bss->ssid, bss->ssid_len));
  1405. if (ret < 0 || ret >= end - pos)
  1406. return -1;
  1407. pos += ret;
  1408. ret = os_snprintf(pos, end - pos, "\n");
  1409. if (ret < 0 || ret >= end - pos)
  1410. return -1;
  1411. pos += ret;
  1412. return pos - buf;
  1413. }
  1414. static int wpa_supplicant_ctrl_iface_scan_results(
  1415. struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
  1416. {
  1417. char *pos, *end;
  1418. struct wpa_bss *bss;
  1419. int ret;
  1420. pos = buf;
  1421. end = buf + buflen;
  1422. ret = os_snprintf(pos, end - pos, "bssid / frequency / signal level / "
  1423. "flags / ssid\n");
  1424. if (ret < 0 || ret >= end - pos)
  1425. return pos - buf;
  1426. pos += ret;
  1427. dl_list_for_each(bss, &wpa_s->bss_id, struct wpa_bss, list_id) {
  1428. ret = wpa_supplicant_ctrl_iface_scan_result(wpa_s, bss, pos,
  1429. end - pos);
  1430. if (ret < 0 || ret >= end - pos)
  1431. return pos - buf;
  1432. pos += ret;
  1433. }
  1434. return pos - buf;
  1435. }
  1436. static int wpa_supplicant_ctrl_iface_select_network(
  1437. struct wpa_supplicant *wpa_s, char *cmd)
  1438. {
  1439. int id;
  1440. struct wpa_ssid *ssid;
  1441. /* cmd: "<network id>" or "any" */
  1442. if (os_strcmp(cmd, "any") == 0) {
  1443. wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK any");
  1444. ssid = NULL;
  1445. } else {
  1446. id = atoi(cmd);
  1447. wpa_printf(MSG_DEBUG, "CTRL_IFACE: SELECT_NETWORK id=%d", id);
  1448. ssid = wpa_config_get_network(wpa_s->conf, id);
  1449. if (ssid == NULL) {
  1450. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
  1451. "network id=%d", id);
  1452. return -1;
  1453. }
  1454. if (ssid->disabled == 2) {
  1455. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
  1456. "SELECT_NETWORK with persistent P2P group");
  1457. return -1;
  1458. }
  1459. }
  1460. wpa_supplicant_select_network(wpa_s, ssid);
  1461. return 0;
  1462. }
  1463. static int wpa_supplicant_ctrl_iface_enable_network(
  1464. struct wpa_supplicant *wpa_s, char *cmd)
  1465. {
  1466. int id;
  1467. struct wpa_ssid *ssid;
  1468. /* cmd: "<network id>" or "all" */
  1469. if (os_strcmp(cmd, "all") == 0) {
  1470. wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK all");
  1471. ssid = NULL;
  1472. } else {
  1473. id = atoi(cmd);
  1474. wpa_printf(MSG_DEBUG, "CTRL_IFACE: ENABLE_NETWORK id=%d", id);
  1475. ssid = wpa_config_get_network(wpa_s->conf, id);
  1476. if (ssid == NULL) {
  1477. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
  1478. "network id=%d", id);
  1479. return -1;
  1480. }
  1481. if (ssid->disabled == 2) {
  1482. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
  1483. "ENABLE_NETWORK with persistent P2P group");
  1484. return -1;
  1485. }
  1486. if (os_strstr(cmd, " no-connect")) {
  1487. ssid->disabled = 0;
  1488. return 0;
  1489. }
  1490. }
  1491. wpa_supplicant_enable_network(wpa_s, ssid);
  1492. return 0;
  1493. }
  1494. static int wpa_supplicant_ctrl_iface_disable_network(
  1495. struct wpa_supplicant *wpa_s, char *cmd)
  1496. {
  1497. int id;
  1498. struct wpa_ssid *ssid;
  1499. /* cmd: "<network id>" or "all" */
  1500. if (os_strcmp(cmd, "all") == 0) {
  1501. wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK all");
  1502. ssid = NULL;
  1503. } else {
  1504. id = atoi(cmd);
  1505. wpa_printf(MSG_DEBUG, "CTRL_IFACE: DISABLE_NETWORK id=%d", id);
  1506. ssid = wpa_config_get_network(wpa_s->conf, id);
  1507. if (ssid == NULL) {
  1508. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
  1509. "network id=%d", id);
  1510. return -1;
  1511. }
  1512. if (ssid->disabled == 2) {
  1513. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Cannot use "
  1514. "DISABLE_NETWORK with persistent P2P "
  1515. "group");
  1516. return -1;
  1517. }
  1518. }
  1519. wpa_supplicant_disable_network(wpa_s, ssid);
  1520. return 0;
  1521. }
  1522. static int wpa_supplicant_ctrl_iface_add_network(
  1523. struct wpa_supplicant *wpa_s, char *buf, size_t buflen)
  1524. {
  1525. struct wpa_ssid *ssid;
  1526. int ret;
  1527. wpa_printf(MSG_DEBUG, "CTRL_IFACE: ADD_NETWORK");
  1528. ssid = wpa_config_add_network(wpa_s->conf);
  1529. if (ssid == NULL)
  1530. return -1;
  1531. wpas_notify_network_added(wpa_s, ssid);
  1532. ssid->disabled = 1;
  1533. wpa_config_set_network_defaults(ssid);
  1534. ret = os_snprintf(buf, buflen, "%d\n", ssid->id);
  1535. if (ret < 0 || (size_t) ret >= buflen)
  1536. return -1;
  1537. return ret;
  1538. }
  1539. static int wpa_supplicant_ctrl_iface_remove_network(
  1540. struct wpa_supplicant *wpa_s, char *cmd)
  1541. {
  1542. int id;
  1543. struct wpa_ssid *ssid;
  1544. /* cmd: "<network id>" or "all" */
  1545. if (os_strcmp(cmd, "all") == 0) {
  1546. wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK all");
  1547. ssid = wpa_s->conf->ssid;
  1548. while (ssid) {
  1549. struct wpa_ssid *remove_ssid = ssid;
  1550. id = ssid->id;
  1551. ssid = ssid->next;
  1552. wpas_notify_network_removed(wpa_s, remove_ssid);
  1553. wpa_config_remove_network(wpa_s->conf, id);
  1554. }
  1555. eapol_sm_invalidate_cached_session(wpa_s->eapol);
  1556. if (wpa_s->current_ssid) {
  1557. #ifdef CONFIG_SME
  1558. wpa_s->sme.prev_bssid_set = 0;
  1559. #endif /* CONFIG_SME */
  1560. wpa_sm_set_config(wpa_s->wpa, NULL);
  1561. eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
  1562. wpa_supplicant_disassociate(wpa_s,
  1563. WLAN_REASON_DEAUTH_LEAVING);
  1564. }
  1565. return 0;
  1566. }
  1567. id = atoi(cmd);
  1568. wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_NETWORK id=%d", id);
  1569. ssid = wpa_config_get_network(wpa_s->conf, id);
  1570. if (ssid)
  1571. wpas_notify_network_removed(wpa_s, ssid);
  1572. if (ssid == NULL ||
  1573. wpa_config_remove_network(wpa_s->conf, id) < 0) {
  1574. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
  1575. "id=%d", id);
  1576. return -1;
  1577. }
  1578. if (ssid == wpa_s->current_ssid || wpa_s->current_ssid == NULL) {
  1579. #ifdef CONFIG_SME
  1580. wpa_s->sme.prev_bssid_set = 0;
  1581. #endif /* CONFIG_SME */
  1582. /*
  1583. * Invalidate the EAP session cache if the current or
  1584. * previously used network is removed.
  1585. */
  1586. eapol_sm_invalidate_cached_session(wpa_s->eapol);
  1587. }
  1588. if (ssid == wpa_s->current_ssid) {
  1589. wpa_sm_set_config(wpa_s->wpa, NULL);
  1590. eapol_sm_notify_config(wpa_s->eapol, NULL, NULL);
  1591. wpa_supplicant_disassociate(wpa_s, WLAN_REASON_DEAUTH_LEAVING);
  1592. }
  1593. return 0;
  1594. }
  1595. static int wpa_supplicant_ctrl_iface_set_network(
  1596. struct wpa_supplicant *wpa_s, char *cmd)
  1597. {
  1598. int id;
  1599. struct wpa_ssid *ssid;
  1600. char *name, *value;
  1601. /* cmd: "<network id> <variable name> <value>" */
  1602. name = os_strchr(cmd, ' ');
  1603. if (name == NULL)
  1604. return -1;
  1605. *name++ = '\0';
  1606. value = os_strchr(name, ' ');
  1607. if (value == NULL)
  1608. return -1;
  1609. *value++ = '\0';
  1610. id = atoi(cmd);
  1611. wpa_printf(MSG_DEBUG, "CTRL_IFACE: SET_NETWORK id=%d name='%s'",
  1612. id, name);
  1613. wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
  1614. (u8 *) value, os_strlen(value));
  1615. ssid = wpa_config_get_network(wpa_s->conf, id);
  1616. if (ssid == NULL) {
  1617. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
  1618. "id=%d", id);
  1619. return -1;
  1620. }
  1621. if (wpa_config_set(ssid, name, value, 0) < 0) {
  1622. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set network "
  1623. "variable '%s'", name);
  1624. return -1;
  1625. }
  1626. wpa_sm_pmksa_cache_flush(wpa_s->wpa, ssid);
  1627. if (wpa_s->current_ssid == ssid || wpa_s->current_ssid == NULL) {
  1628. /*
  1629. * Invalidate the EAP session cache if anything in the current
  1630. * or previously used configuration changes.
  1631. */
  1632. eapol_sm_invalidate_cached_session(wpa_s->eapol);
  1633. }
  1634. if ((os_strcmp(name, "psk") == 0 &&
  1635. value[0] == '"' && ssid->ssid_len) ||
  1636. (os_strcmp(name, "ssid") == 0 && ssid->passphrase))
  1637. wpa_config_update_psk(ssid);
  1638. else if (os_strcmp(name, "priority") == 0)
  1639. wpa_config_update_prio_list(wpa_s->conf);
  1640. return 0;
  1641. }
  1642. static int wpa_supplicant_ctrl_iface_get_network(
  1643. struct wpa_supplicant *wpa_s, char *cmd, char *buf, size_t buflen)
  1644. {
  1645. int id;
  1646. size_t res;
  1647. struct wpa_ssid *ssid;
  1648. char *name, *value;
  1649. /* cmd: "<network id> <variable name>" */
  1650. name = os_strchr(cmd, ' ');
  1651. if (name == NULL || buflen == 0)
  1652. return -1;
  1653. *name++ = '\0';
  1654. id = atoi(cmd);
  1655. wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_NETWORK id=%d name='%s'",
  1656. id, name);
  1657. ssid = wpa_config_get_network(wpa_s->conf, id);
  1658. if (ssid == NULL) {
  1659. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find network "
  1660. "id=%d", id);
  1661. return -1;
  1662. }
  1663. value = wpa_config_get_no_key(ssid, name);
  1664. if (value == NULL) {
  1665. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to get network "
  1666. "variable '%s'", name);
  1667. return -1;
  1668. }
  1669. res = os_strlcpy(buf, value, buflen);
  1670. if (res >= buflen) {
  1671. os_free(value);
  1672. return -1;
  1673. }
  1674. os_free(value);
  1675. return res;
  1676. }
  1677. static int wpa_supplicant_ctrl_iface_list_creds(struct wpa_supplicant *wpa_s,
  1678. char *buf, size_t buflen)
  1679. {
  1680. char *pos, *end;
  1681. struct wpa_cred *cred;
  1682. int ret;
  1683. pos = buf;
  1684. end = buf + buflen;
  1685. ret = os_snprintf(pos, end - pos,
  1686. "cred id / realm / username / domain / imsi\n");
  1687. if (ret < 0 || ret >= end - pos)
  1688. return pos - buf;
  1689. pos += ret;
  1690. cred = wpa_s->conf->cred;
  1691. while (cred) {
  1692. ret = os_snprintf(pos, end - pos, "%d\t%s\t%s\t%s\t%s\n",
  1693. cred->id, cred->realm ? cred->realm : "",
  1694. cred->username ? cred->username : "",
  1695. cred->domain ? cred->domain : "",
  1696. cred->imsi ? cred->imsi : "");
  1697. if (ret < 0 || ret >= end - pos)
  1698. return pos - buf;
  1699. pos += ret;
  1700. cred = cred->next;
  1701. }
  1702. return pos - buf;
  1703. }
  1704. static int wpa_supplicant_ctrl_iface_add_cred(struct wpa_supplicant *wpa_s,
  1705. char *buf, size_t buflen)
  1706. {
  1707. struct wpa_cred *cred;
  1708. int ret;
  1709. wpa_printf(MSG_DEBUG, "CTRL_IFACE: ADD_CRED");
  1710. cred = wpa_config_add_cred(wpa_s->conf);
  1711. if (cred == NULL)
  1712. return -1;
  1713. ret = os_snprintf(buf, buflen, "%d\n", cred->id);
  1714. if (ret < 0 || (size_t) ret >= buflen)
  1715. return -1;
  1716. return ret;
  1717. }
  1718. static int wpa_supplicant_ctrl_iface_remove_cred(struct wpa_supplicant *wpa_s,
  1719. char *cmd)
  1720. {
  1721. int id;
  1722. struct wpa_cred *cred;
  1723. /* cmd: "<cred id>" or "all" */
  1724. if (os_strcmp(cmd, "all") == 0) {
  1725. wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED all");
  1726. cred = wpa_s->conf->cred;
  1727. while (cred) {
  1728. id = cred->id;
  1729. cred = cred->next;
  1730. wpa_config_remove_cred(wpa_s->conf, id);
  1731. }
  1732. return 0;
  1733. }
  1734. id = atoi(cmd);
  1735. wpa_printf(MSG_DEBUG, "CTRL_IFACE: REMOVE_CRED id=%d", id);
  1736. cred = wpa_config_get_cred(wpa_s->conf, id);
  1737. if (cred == NULL ||
  1738. wpa_config_remove_cred(wpa_s->conf, id) < 0) {
  1739. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred id=%d",
  1740. id);
  1741. return -1;
  1742. }
  1743. return 0;
  1744. }
  1745. static int wpa_supplicant_ctrl_iface_set_cred(struct wpa_supplicant *wpa_s,
  1746. char *cmd)
  1747. {
  1748. int id;
  1749. struct wpa_cred *cred;
  1750. char *name, *value;
  1751. /* cmd: "<cred id> <variable name> <value>" */
  1752. name = os_strchr(cmd, ' ');
  1753. if (name == NULL)
  1754. return -1;
  1755. *name++ = '\0';
  1756. value = os_strchr(name, ' ');
  1757. if (value == NULL)
  1758. return -1;
  1759. *value++ = '\0';
  1760. id = atoi(cmd);
  1761. wpa_printf(MSG_DEBUG, "CTRL_IFACE: SET_CRED id=%d name='%s'",
  1762. id, name);
  1763. wpa_hexdump_ascii_key(MSG_DEBUG, "CTRL_IFACE: value",
  1764. (u8 *) value, os_strlen(value));
  1765. cred = wpa_config_get_cred(wpa_s->conf, id);
  1766. if (cred == NULL) {
  1767. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find cred id=%d",
  1768. id);
  1769. return -1;
  1770. }
  1771. if (wpa_config_set_cred(cred, name, value, 0) < 0) {
  1772. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Failed to set cred "
  1773. "variable '%s'", name);
  1774. return -1;
  1775. }
  1776. return 0;
  1777. }
  1778. #ifndef CONFIG_NO_CONFIG_WRITE
  1779. static int wpa_supplicant_ctrl_iface_save_config(struct wpa_supplicant *wpa_s)
  1780. {
  1781. int ret;
  1782. if (!wpa_s->conf->update_config) {
  1783. wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Not allowed "
  1784. "to update configuration (update_config=0)");
  1785. return -1;
  1786. }
  1787. ret = wpa_config_write(wpa_s->confname, wpa_s->conf);
  1788. if (ret) {
  1789. wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Failed to "
  1790. "update configuration");
  1791. } else {
  1792. wpa_printf(MSG_DEBUG, "CTRL_IFACE: SAVE_CONFIG - Configuration"
  1793. " updated");
  1794. }
  1795. return ret;
  1796. }
  1797. #endif /* CONFIG_NO_CONFIG_WRITE */
  1798. static int ctrl_iface_get_capability_pairwise(int res, char *strict,
  1799. struct wpa_driver_capa *capa,
  1800. char *buf, size_t buflen)
  1801. {
  1802. int ret, first = 1;
  1803. char *pos, *end;
  1804. size_t len;
  1805. pos = buf;
  1806. end = pos + buflen;
  1807. if (res < 0) {
  1808. if (strict)
  1809. return 0;
  1810. len = os_strlcpy(buf, "CCMP TKIP NONE", buflen);
  1811. if (len >= buflen)
  1812. return -1;
  1813. return len;
  1814. }
  1815. if (capa->enc & WPA_DRIVER_CAPA_ENC_CCMP) {
  1816. ret = os_snprintf(pos, end - pos, "%sCCMP", first ? "" : " ");
  1817. if (ret < 0 || ret >= end - pos)
  1818. return pos - buf;
  1819. pos += ret;
  1820. first = 0;
  1821. }
  1822. if (capa->enc & WPA_DRIVER_CAPA_ENC_TKIP) {
  1823. ret = os_snprintf(pos, end - pos, "%sTKIP", first ? "" : " ");
  1824. if (ret < 0 || ret >= end - pos)
  1825. return pos - buf;
  1826. pos += ret;
  1827. first = 0;
  1828. }
  1829. if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE) {
  1830. ret = os_snprintf(pos, end - pos, "%sNONE", first ? "" : " ");
  1831. if (ret < 0 || ret >= end - pos)
  1832. return pos - buf;
  1833. pos += ret;
  1834. first = 0;
  1835. }
  1836. return pos - buf;
  1837. }
  1838. static int ctrl_iface_get_capability_group(int res, char *strict,
  1839. struct wpa_driver_capa *capa,
  1840. char *buf, size_t buflen)
  1841. {
  1842. int ret, first = 1;
  1843. char *pos, *end;
  1844. size_t len;
  1845. pos = buf;
  1846. end = pos + buflen;
  1847. if (res < 0) {
  1848. if (strict)
  1849. return 0;
  1850. len = os_strlcpy(buf, "CCMP TKIP WEP104 WEP40", buflen);
  1851. if (len >= buflen)
  1852. return -1;
  1853. return len;
  1854. }
  1855. if (capa->enc & WPA_DRIVER_CAPA_ENC_CCMP) {
  1856. ret = os_snprintf(pos, end - pos, "%sCCMP", first ? "" : " ");
  1857. if (ret < 0 || ret >= end - pos)
  1858. return pos - buf;
  1859. pos += ret;
  1860. first = 0;
  1861. }
  1862. if (capa->enc & WPA_DRIVER_CAPA_ENC_TKIP) {
  1863. ret = os_snprintf(pos, end - pos, "%sTKIP", first ? "" : " ");
  1864. if (ret < 0 || ret >= end - pos)
  1865. return pos - buf;
  1866. pos += ret;
  1867. first = 0;
  1868. }
  1869. if (capa->enc & WPA_DRIVER_CAPA_ENC_WEP104) {
  1870. ret = os_snprintf(pos, end - pos, "%sWEP104",
  1871. first ? "" : " ");
  1872. if (ret < 0 || ret >= end - pos)
  1873. return pos - buf;
  1874. pos += ret;
  1875. first = 0;
  1876. }
  1877. if (capa->enc & WPA_DRIVER_CAPA_ENC_WEP40) {
  1878. ret = os_snprintf(pos, end - pos, "%sWEP40", first ? "" : " ");
  1879. if (ret < 0 || ret >= end - pos)
  1880. return pos - buf;
  1881. pos += ret;
  1882. first = 0;
  1883. }
  1884. return pos - buf;
  1885. }
  1886. static int ctrl_iface_get_capability_key_mgmt(int res, char *strict,
  1887. struct wpa_driver_capa *capa,
  1888. char *buf, size_t buflen)
  1889. {
  1890. int ret;
  1891. char *pos, *end;
  1892. size_t len;
  1893. pos = buf;
  1894. end = pos + buflen;
  1895. if (res < 0) {
  1896. if (strict)
  1897. return 0;
  1898. len = os_strlcpy(buf, "WPA-PSK WPA-EAP IEEE8021X WPA-NONE "
  1899. "NONE", buflen);
  1900. if (len >= buflen)
  1901. return -1;
  1902. return len;
  1903. }
  1904. ret = os_snprintf(pos, end - pos, "NONE IEEE8021X");
  1905. if (ret < 0 || ret >= end - pos)
  1906. return pos - buf;
  1907. pos += ret;
  1908. if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
  1909. WPA_DRIVER_CAPA_KEY_MGMT_WPA2)) {
  1910. ret = os_snprintf(pos, end - pos, " WPA-EAP");
  1911. if (ret < 0 || ret >= end - pos)
  1912. return pos - buf;
  1913. pos += ret;
  1914. }
  1915. if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK |
  1916. WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
  1917. ret = os_snprintf(pos, end - pos, " WPA-PSK");
  1918. if (ret < 0 || ret >= end - pos)
  1919. return pos - buf;
  1920. pos += ret;
  1921. }
  1922. if (capa->key_mgmt & WPA_DRIVER_CAPA_KEY_MGMT_WPA_NONE) {
  1923. ret = os_snprintf(pos, end - pos, " WPA-NONE");
  1924. if (ret < 0 || ret >= end - pos)
  1925. return pos - buf;
  1926. pos += ret;
  1927. }
  1928. return pos - buf;
  1929. }
  1930. static int ctrl_iface_get_capability_proto(int res, char *strict,
  1931. struct wpa_driver_capa *capa,
  1932. char *buf, size_t buflen)
  1933. {
  1934. int ret, first = 1;
  1935. char *pos, *end;
  1936. size_t len;
  1937. pos = buf;
  1938. end = pos + buflen;
  1939. if (res < 0) {
  1940. if (strict)
  1941. return 0;
  1942. len = os_strlcpy(buf, "RSN WPA", buflen);
  1943. if (len >= buflen)
  1944. return -1;
  1945. return len;
  1946. }
  1947. if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA2 |
  1948. WPA_DRIVER_CAPA_KEY_MGMT_WPA2_PSK)) {
  1949. ret = os_snprintf(pos, end - pos, "%sRSN", first ? "" : " ");
  1950. if (ret < 0 || ret >= end - pos)
  1951. return pos - buf;
  1952. pos += ret;
  1953. first = 0;
  1954. }
  1955. if (capa->key_mgmt & (WPA_DRIVER_CAPA_KEY_MGMT_WPA |
  1956. WPA_DRIVER_CAPA_KEY_MGMT_WPA_PSK)) {
  1957. ret = os_snprintf(pos, end - pos, "%sWPA", first ? "" : " ");
  1958. if (ret < 0 || ret >= end - pos)
  1959. return pos - buf;
  1960. pos += ret;
  1961. first = 0;
  1962. }
  1963. return pos - buf;
  1964. }
  1965. static int ctrl_iface_get_capability_auth_alg(int res, char *strict,
  1966. struct wpa_driver_capa *capa,
  1967. char *buf, size_t buflen)
  1968. {
  1969. int ret, first = 1;
  1970. char *pos, *end;
  1971. size_t len;
  1972. pos = buf;
  1973. end = pos + buflen;
  1974. if (res < 0) {
  1975. if (strict)
  1976. return 0;
  1977. len = os_strlcpy(buf, "OPEN SHARED LEAP", buflen);
  1978. if (len >= buflen)
  1979. return -1;
  1980. return len;
  1981. }
  1982. if (capa->auth & (WPA_DRIVER_AUTH_OPEN)) {
  1983. ret = os_snprintf(pos, end - pos, "%sOPEN", first ? "" : " ");
  1984. if (ret < 0 || ret >= end - pos)
  1985. return pos - buf;
  1986. pos += ret;
  1987. first = 0;
  1988. }
  1989. if (capa->auth & (WPA_DRIVER_AUTH_SHARED)) {
  1990. ret = os_snprintf(pos, end - pos, "%sSHARED",
  1991. first ? "" : " ");
  1992. if (ret < 0 || ret >= end - pos)
  1993. return pos - buf;
  1994. pos += ret;
  1995. first = 0;
  1996. }
  1997. if (capa->auth & (WPA_DRIVER_AUTH_LEAP)) {
  1998. ret = os_snprintf(pos, end - pos, "%sLEAP", first ? "" : " ");
  1999. if (ret < 0 || ret >= end - pos)
  2000. return pos - buf;
  2001. pos += ret;
  2002. first = 0;
  2003. }
  2004. return pos - buf;
  2005. }
  2006. static int ctrl_iface_get_capability_channels(struct wpa_supplicant *wpa_s,
  2007. char *buf, size_t buflen)
  2008. {
  2009. struct hostapd_channel_data *chnl;
  2010. int ret, i, j;
  2011. char *pos, *end, *hmode;
  2012. pos = buf;
  2013. end = pos + buflen;
  2014. for (j = 0; j < wpa_s->hw.num_modes; j++) {
  2015. switch (wpa_s->hw.modes[j].mode) {
  2016. case HOSTAPD_MODE_IEEE80211B:
  2017. hmode = "B";
  2018. break;
  2019. case HOSTAPD_MODE_IEEE80211G:
  2020. hmode = "G";
  2021. break;
  2022. case HOSTAPD_MODE_IEEE80211A:
  2023. hmode = "A";
  2024. break;
  2025. default:
  2026. continue;
  2027. }
  2028. ret = os_snprintf(pos, end - pos, "Mode[%s] Channels:", hmode);
  2029. if (ret < 0 || ret >= end - pos)
  2030. return pos - buf;
  2031. pos += ret;
  2032. chnl = wpa_s->hw.modes[j].channels;
  2033. for (i = 0; i < wpa_s->hw.modes[j].num_channels; i++) {
  2034. if (chnl[i].flag & HOSTAPD_CHAN_DISABLED)
  2035. continue;
  2036. ret = os_snprintf(pos, end - pos, " %d", chnl[i].chan);
  2037. if (ret < 0 || ret >= end - pos)
  2038. return pos - buf;
  2039. pos += ret;
  2040. }
  2041. ret = os_snprintf(pos, end - pos, "\n");
  2042. if (ret < 0 || ret >= end - pos)
  2043. return pos - buf;
  2044. pos += ret;
  2045. }
  2046. return pos - buf;
  2047. }
  2048. static int wpa_supplicant_ctrl_iface_get_capability(
  2049. struct wpa_supplicant *wpa_s, const char *_field, char *buf,
  2050. size_t buflen)
  2051. {
  2052. struct wpa_driver_capa capa;
  2053. int res;
  2054. char *strict;
  2055. char field[30];
  2056. size_t len;
  2057. /* Determine whether or not strict checking was requested */
  2058. len = os_strlcpy(field, _field, sizeof(field));
  2059. if (len >= sizeof(field))
  2060. return -1;
  2061. strict = os_strchr(field, ' ');
  2062. if (strict != NULL) {
  2063. *strict++ = '\0';
  2064. if (os_strcmp(strict, "strict") != 0)
  2065. return -1;
  2066. }
  2067. wpa_printf(MSG_DEBUG, "CTRL_IFACE: GET_CAPABILITY '%s' %s",
  2068. field, strict ? strict : "");
  2069. if (os_strcmp(field, "eap") == 0) {
  2070. return eap_get_names(buf, buflen);
  2071. }
  2072. res = wpa_drv_get_capa(wpa_s, &capa);
  2073. if (os_strcmp(field, "pairwise") == 0)
  2074. return ctrl_iface_get_capability_pairwise(res, strict, &capa,
  2075. buf, buflen);
  2076. if (os_strcmp(field, "group") == 0)
  2077. return ctrl_iface_get_capability_group(res, strict, &capa,
  2078. buf, buflen);
  2079. if (os_strcmp(field, "key_mgmt") == 0)
  2080. return ctrl_iface_get_capability_key_mgmt(res, strict, &capa,
  2081. buf, buflen);
  2082. if (os_strcmp(field, "proto") == 0)
  2083. return ctrl_iface_get_capability_proto(res, strict, &capa,
  2084. buf, buflen);
  2085. if (os_strcmp(field, "auth_alg") == 0)
  2086. return ctrl_iface_get_capability_auth_alg(res, strict, &capa,
  2087. buf, buflen);
  2088. if (os_strcmp(field, "channels") == 0)
  2089. return ctrl_iface_get_capability_channels(wpa_s, buf, buflen);
  2090. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown GET_CAPABILITY field '%s'",
  2091. field);
  2092. return -1;
  2093. }
  2094. #ifdef CONFIG_INTERWORKING
  2095. static char * anqp_add_hex(char *pos, char *end, const char *title,
  2096. struct wpabuf *data)
  2097. {
  2098. char *start = pos;
  2099. size_t i;
  2100. int ret;
  2101. const u8 *d;
  2102. if (data == NULL)
  2103. return start;
  2104. ret = os_snprintf(pos, end - pos, "%s=", title);
  2105. if (ret < 0 || ret >= end - pos)
  2106. return start;
  2107. pos += ret;
  2108. d = wpabuf_head_u8(data);
  2109. for (i = 0; i < wpabuf_len(data); i++) {
  2110. ret = os_snprintf(pos, end - pos, "%02x", *d++);
  2111. if (ret < 0 || ret >= end - pos)
  2112. return start;
  2113. pos += ret;
  2114. }
  2115. ret = os_snprintf(pos, end - pos, "\n");
  2116. if (ret < 0 || ret >= end - pos)
  2117. return start;
  2118. pos += ret;
  2119. return pos;
  2120. }
  2121. #endif /* CONFIG_INTERWORKING */
  2122. static int print_bss_info(struct wpa_supplicant *wpa_s, struct wpa_bss *bss,
  2123. unsigned long mask, char *buf, size_t buflen)
  2124. {
  2125. size_t i;
  2126. int ret;
  2127. char *pos, *end;
  2128. const u8 *ie, *ie2;
  2129. pos = buf;
  2130. end = buf + buflen;
  2131. if (mask & WPA_BSS_MASK_ID) {
  2132. ret = os_snprintf(pos, end - pos, "id=%u\n", bss->id);
  2133. if (ret < 0 || ret >= end - pos)
  2134. return 0;
  2135. pos += ret;
  2136. }
  2137. if (mask & WPA_BSS_MASK_BSSID) {
  2138. ret = os_snprintf(pos, end - pos, "bssid=" MACSTR "\n",
  2139. MAC2STR(bss->bssid));
  2140. if (ret < 0 || ret >= end - pos)
  2141. return 0;
  2142. pos += ret;
  2143. }
  2144. if (mask & WPA_BSS_MASK_FREQ) {
  2145. ret = os_snprintf(pos, end - pos, "freq=%d\n", bss->freq);
  2146. if (ret < 0 || ret >= end - pos)
  2147. return 0;
  2148. pos += ret;
  2149. }
  2150. if (mask & WPA_BSS_MASK_BEACON_INT) {
  2151. ret = os_snprintf(pos, end - pos, "beacon_int=%d\n",
  2152. bss->beacon_int);
  2153. if (ret < 0 || ret >= end - pos)
  2154. return 0;
  2155. pos += ret;
  2156. }
  2157. if (mask & WPA_BSS_MASK_CAPABILITIES) {
  2158. ret = os_snprintf(pos, end - pos, "capabilities=0x%04x\n",
  2159. bss->caps);
  2160. if (ret < 0 || ret >= end - pos)
  2161. return 0;
  2162. pos += ret;
  2163. }
  2164. if (mask & WPA_BSS_MASK_QUAL) {
  2165. ret = os_snprintf(pos, end - pos, "qual=%d\n", bss->qual);
  2166. if (ret < 0 || ret >= end - pos)
  2167. return 0;
  2168. pos += ret;
  2169. }
  2170. if (mask & WPA_BSS_MASK_NOISE) {
  2171. ret = os_snprintf(pos, end - pos, "noise=%d\n", bss->noise);
  2172. if (ret < 0 || ret >= end - pos)
  2173. return 0;
  2174. pos += ret;
  2175. }
  2176. if (mask & WPA_BSS_MASK_LEVEL) {
  2177. ret = os_snprintf(pos, end - pos, "level=%d\n", bss->level);
  2178. if (ret < 0 || ret >= end - pos)
  2179. return 0;
  2180. pos += ret;
  2181. }
  2182. if (mask & WPA_BSS_MASK_TSF) {
  2183. ret = os_snprintf(pos, end - pos, "tsf=%016llu\n",
  2184. (unsigned long long) bss->tsf);
  2185. if (ret < 0 || ret >= end - pos)
  2186. return 0;
  2187. pos += ret;
  2188. }
  2189. if (mask & WPA_BSS_MASK_AGE) {
  2190. struct os_time now;
  2191. os_get_time(&now);
  2192. ret = os_snprintf(pos, end - pos, "age=%d\n",
  2193. (int) (now.sec - bss->last_update.sec));
  2194. if (ret < 0 || ret >= end - pos)
  2195. return 0;
  2196. pos += ret;
  2197. }
  2198. if (mask & WPA_BSS_MASK_IE) {
  2199. ret = os_snprintf(pos, end - pos, "ie=");
  2200. if (ret < 0 || ret >= end - pos)
  2201. return 0;
  2202. pos += ret;
  2203. ie = (const u8 *) (bss + 1);
  2204. for (i = 0; i < bss->ie_len; i++) {
  2205. ret = os_snprintf(pos, end - pos, "%02x", *ie++);
  2206. if (ret < 0 || ret >= end - pos)
  2207. return 0;
  2208. pos += ret;
  2209. }
  2210. ret = os_snprintf(pos, end - pos, "\n");
  2211. if (ret < 0 || ret >= end - pos)
  2212. return 0;
  2213. pos += ret;
  2214. }
  2215. if (mask & WPA_BSS_MASK_FLAGS) {
  2216. ret = os_snprintf(pos, end - pos, "flags=");
  2217. if (ret < 0 || ret >= end - pos)
  2218. return 0;
  2219. pos += ret;
  2220. ie = wpa_bss_get_vendor_ie(bss, WPA_IE_VENDOR_TYPE);
  2221. if (ie)
  2222. pos = wpa_supplicant_ie_txt(pos, end, "WPA", ie,
  2223. 2 + ie[1]);
  2224. ie2 = wpa_bss_get_ie(bss, WLAN_EID_RSN);
  2225. if (ie2)
  2226. pos = wpa_supplicant_ie_txt(pos, end, "WPA2", ie2,
  2227. 2 + ie2[1]);
  2228. pos = wpa_supplicant_wps_ie_txt(wpa_s, pos, end, bss);
  2229. if (!ie && !ie2 && bss->caps & IEEE80211_CAP_PRIVACY) {
  2230. ret = os_snprintf(pos, end - pos, "[WEP]");
  2231. if (ret < 0 || ret >= end - pos)
  2232. return 0;
  2233. pos += ret;
  2234. }
  2235. if (bss->caps & IEEE80211_CAP_IBSS) {
  2236. ret = os_snprintf(pos, end - pos, "[IBSS]");
  2237. if (ret < 0 || ret >= end - pos)
  2238. return 0;
  2239. pos += ret;
  2240. }
  2241. if (bss->caps & IEEE80211_CAP_ESS) {
  2242. ret = os_snprintf(pos, end - pos, "[ESS]");
  2243. if (ret < 0 || ret >= end - pos)
  2244. return 0;
  2245. pos += ret;
  2246. }
  2247. if (wpa_bss_get_vendor_ie(bss, P2P_IE_VENDOR_TYPE)) {
  2248. ret = os_snprintf(pos, end - pos, "[P2P]");
  2249. if (ret < 0 || ret >= end - pos)
  2250. return 0;
  2251. pos += ret;
  2252. }
  2253. #ifdef CONFIG_HS20
  2254. if (wpa_bss_get_vendor_ie(bss, HS20_IE_VENDOR_TYPE)) {
  2255. ret = os_snprintf(pos, end - pos, "[HS20]");
  2256. if (ret < 0 || ret >= end - pos)
  2257. return -1;
  2258. pos += ret;
  2259. }
  2260. #endif /* CONFIG_HS20 */
  2261. ret = os_snprintf(pos, end - pos, "\n");
  2262. if (ret < 0 || ret >= end - pos)
  2263. return 0;
  2264. pos += ret;
  2265. }
  2266. if (mask & WPA_BSS_MASK_SSID) {
  2267. ret = os_snprintf(pos, end - pos, "ssid=%s\n",
  2268. wpa_ssid_txt(bss->ssid, bss->ssid_len));
  2269. if (ret < 0 || ret >= end - pos)
  2270. return 0;
  2271. pos += ret;
  2272. }
  2273. #ifdef CONFIG_WPS
  2274. if (mask & WPA_BSS_MASK_WPS_SCAN) {
  2275. ie = (const u8 *) (bss + 1);
  2276. ret = wpas_wps_scan_result_text(ie, bss->ie_len, pos, end);
  2277. if (ret < 0 || ret >= end - pos)
  2278. return 0;
  2279. pos += ret;
  2280. }
  2281. #endif /* CONFIG_WPS */
  2282. #ifdef CONFIG_P2P
  2283. if (mask & WPA_BSS_MASK_P2P_SCAN) {
  2284. ie = (const u8 *) (bss + 1);
  2285. ret = wpas_p2p_scan_result_text(ie, bss->ie_len, pos, end);
  2286. if (ret < 0 || ret >= end - pos)
  2287. return 0;
  2288. pos += ret;
  2289. }
  2290. #endif /* CONFIG_P2P */
  2291. #ifdef CONFIG_INTERWORKING
  2292. if (mask & WPA_BSS_MASK_INTERNETW) {
  2293. pos = anqp_add_hex(pos, end, "anqp_venue_name",
  2294. bss->anqp_venue_name);
  2295. pos = anqp_add_hex(pos, end, "anqp_network_auth_type",
  2296. bss->anqp_network_auth_type);
  2297. pos = anqp_add_hex(pos, end, "anqp_roaming_consortium",
  2298. bss->anqp_roaming_consortium);
  2299. pos = anqp_add_hex(pos, end, "anqp_ip_addr_type_availability",
  2300. bss->anqp_ip_addr_type_availability);
  2301. pos = anqp_add_hex(pos, end, "anqp_nai_realm",
  2302. bss->anqp_nai_realm);
  2303. pos = anqp_add_hex(pos, end, "anqp_3gpp", bss->anqp_3gpp);
  2304. pos = anqp_add_hex(pos, end, "anqp_domain_name",
  2305. bss->anqp_domain_name);
  2306. #ifdef CONFIG_HS20
  2307. pos = anqp_add_hex(pos, end, "hs20_operator_friendly_name",
  2308. bss->hs20_operator_friendly_name);
  2309. pos = anqp_add_hex(pos, end, "hs20_wan_metrics",
  2310. bss->hs20_wan_metrics);
  2311. pos = anqp_add_hex(pos, end, "hs20_connection_capability",
  2312. bss->hs20_connection_capability);
  2313. #endif /* CONFIG_HS20 */
  2314. }
  2315. #endif /* CONFIG_INTERWORKING */
  2316. return pos - buf;
  2317. }
  2318. static int wpa_supplicant_ctrl_iface_bss(struct wpa_supplicant *wpa_s,
  2319. const char *cmd, char *buf,
  2320. size_t buflen)
  2321. {
  2322. u8 bssid[ETH_ALEN];
  2323. size_t i;
  2324. struct wpa_bss *bss;
  2325. struct wpa_bss *bsslast = NULL;
  2326. struct dl_list *next;
  2327. int ret = 0;
  2328. int len;
  2329. char *ctmp;
  2330. unsigned long mask = WPA_BSS_MASK_ALL;
  2331. if (os_strncmp(cmd, "RANGE=", 6) == 0) {
  2332. if (os_strncmp(cmd + 6, "ALL", 3) == 0) {
  2333. bss = dl_list_first(&wpa_s->bss_id, struct wpa_bss,
  2334. list_id);
  2335. bsslast = dl_list_last(&wpa_s->bss_id, struct wpa_bss,
  2336. list_id);
  2337. } else { /* N1-N2 */
  2338. unsigned int id1, id2;
  2339. if ((ctmp = os_strchr(cmd + 6, '-')) == NULL) {
  2340. wpa_printf(MSG_INFO, "Wrong BSS range "
  2341. "format");
  2342. return 0;
  2343. }
  2344. id1 = atoi(cmd + 6);
  2345. bss = wpa_bss_get_id(wpa_s, id1);
  2346. id2 = atoi(ctmp + 1);
  2347. if (id2 == 0)
  2348. bsslast = dl_list_last(&wpa_s->bss_id,
  2349. struct wpa_bss,
  2350. list_id);
  2351. else {
  2352. bsslast = wpa_bss_get_id(wpa_s, id2);
  2353. if (bsslast == NULL && bss && id2 > id1) {
  2354. struct wpa_bss *tmp = bss;
  2355. for (;;) {
  2356. next = tmp->list_id.next;
  2357. if (next == &wpa_s->bss_id)
  2358. break;
  2359. tmp = dl_list_entry(
  2360. next, struct wpa_bss,
  2361. list_id);
  2362. if (tmp->id > id2)
  2363. break;
  2364. bsslast = tmp;
  2365. }
  2366. }
  2367. }
  2368. }
  2369. } else if (os_strcmp(cmd, "FIRST") == 0)
  2370. bss = dl_list_first(&wpa_s->bss_id, struct wpa_bss, list_id);
  2371. else if (os_strncmp(cmd, "ID-", 3) == 0) {
  2372. i = atoi(cmd + 3);
  2373. bss = wpa_bss_get_id(wpa_s, i);
  2374. } else if (os_strncmp(cmd, "NEXT-", 5) == 0) {
  2375. i = atoi(cmd + 5);
  2376. bss = wpa_bss_get_id(wpa_s, i);
  2377. if (bss) {
  2378. next = bss->list_id.next;
  2379. if (next == &wpa_s->bss_id)
  2380. bss = NULL;
  2381. else
  2382. bss = dl_list_entry(next, struct wpa_bss,
  2383. list_id);
  2384. }
  2385. #ifdef CONFIG_P2P
  2386. } else if (os_strncmp(cmd, "p2p_dev_addr=", 13) == 0) {
  2387. if (hwaddr_aton(cmd + 13, bssid) == 0)
  2388. bss = wpa_bss_get_p2p_dev_addr(wpa_s, bssid);
  2389. else
  2390. bss = NULL;
  2391. #endif /* CONFIG_P2P */
  2392. } else if (hwaddr_aton(cmd, bssid) == 0)
  2393. bss = wpa_bss_get_bssid(wpa_s, bssid);
  2394. else {
  2395. struct wpa_bss *tmp;
  2396. i = atoi(cmd);
  2397. bss = NULL;
  2398. dl_list_for_each(tmp, &wpa_s->bss_id, struct wpa_bss, list_id)
  2399. {
  2400. if (i-- == 0) {
  2401. bss = tmp;
  2402. break;
  2403. }
  2404. }
  2405. }
  2406. if ((ctmp = os_strstr(cmd, "MASK=")) != NULL) {
  2407. mask = strtoul(ctmp + 5, NULL, 0x10);
  2408. if (mask == 0)
  2409. mask = WPA_BSS_MASK_ALL;
  2410. }
  2411. if (bss == NULL)
  2412. return 0;
  2413. if (bsslast == NULL)
  2414. bsslast = bss;
  2415. do {
  2416. len = print_bss_info(wpa_s, bss, mask, buf, buflen);
  2417. ret += len;
  2418. buf += len;
  2419. buflen -= len;
  2420. if (bss == bsslast)
  2421. break;
  2422. next = bss->list_id.next;
  2423. if (next == &wpa_s->bss_id)
  2424. break;
  2425. bss = dl_list_entry(next, struct wpa_bss, list_id);
  2426. } while (bss && len);
  2427. return ret;
  2428. }
  2429. static int wpa_supplicant_ctrl_iface_ap_scan(
  2430. struct wpa_supplicant *wpa_s, char *cmd)
  2431. {
  2432. int ap_scan = atoi(cmd);
  2433. return wpa_supplicant_set_ap_scan(wpa_s, ap_scan);
  2434. }
  2435. static int wpa_supplicant_ctrl_iface_scan_interval(
  2436. struct wpa_supplicant *wpa_s, char *cmd)
  2437. {
  2438. int scan_int = atoi(cmd);
  2439. return wpa_supplicant_set_scan_interval(wpa_s, scan_int);
  2440. }
  2441. static int wpa_supplicant_ctrl_iface_bss_expire_age(
  2442. struct wpa_supplicant *wpa_s, char *cmd)
  2443. {
  2444. int expire_age = atoi(cmd);
  2445. return wpa_supplicant_set_bss_expiration_age(wpa_s, expire_age);
  2446. }
  2447. static int wpa_supplicant_ctrl_iface_bss_expire_count(
  2448. struct wpa_supplicant *wpa_s, char *cmd)
  2449. {
  2450. int expire_count = atoi(cmd);
  2451. return wpa_supplicant_set_bss_expiration_count(wpa_s, expire_count);
  2452. }
  2453. static void wpa_supplicant_ctrl_iface_drop_sa(struct wpa_supplicant *wpa_s)
  2454. {
  2455. wpa_printf(MSG_DEBUG, "Dropping SA without deauthentication");
  2456. /* MLME-DELETEKEYS.request */
  2457. wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 0, 0, NULL, 0, NULL, 0);
  2458. wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 1, 0, NULL, 0, NULL, 0);
  2459. wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 2, 0, NULL, 0, NULL, 0);
  2460. wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 3, 0, NULL, 0, NULL, 0);
  2461. #ifdef CONFIG_IEEE80211W
  2462. wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 4, 0, NULL, 0, NULL, 0);
  2463. wpa_drv_set_key(wpa_s, WPA_ALG_NONE, NULL, 5, 0, NULL, 0, NULL, 0);
  2464. #endif /* CONFIG_IEEE80211W */
  2465. wpa_drv_set_key(wpa_s, WPA_ALG_NONE, wpa_s->bssid, 0, 0, NULL, 0, NULL,
  2466. 0);
  2467. /* MLME-SETPROTECTION.request(None) */
  2468. wpa_drv_mlme_setprotection(wpa_s, wpa_s->bssid,
  2469. MLME_SETPROTECTION_PROTECT_TYPE_NONE,
  2470. MLME_SETPROTECTION_KEY_TYPE_PAIRWISE);
  2471. wpa_sm_drop_sa(wpa_s->wpa);
  2472. }
  2473. static int wpa_supplicant_ctrl_iface_roam(struct wpa_supplicant *wpa_s,
  2474. char *addr)
  2475. {
  2476. #ifdef CONFIG_NO_SCAN_PROCESSING
  2477. return -1;
  2478. #else /* CONFIG_NO_SCAN_PROCESSING */
  2479. u8 bssid[ETH_ALEN];
  2480. struct wpa_bss *bss;
  2481. struct wpa_ssid *ssid = wpa_s->current_ssid;
  2482. if (hwaddr_aton(addr, bssid)) {
  2483. wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: invalid "
  2484. "address '%s'", addr);
  2485. return -1;
  2486. }
  2487. wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM " MACSTR, MAC2STR(bssid));
  2488. bss = wpa_bss_get_bssid(wpa_s, bssid);
  2489. if (!bss) {
  2490. wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: Target AP not found "
  2491. "from BSS table");
  2492. return -1;
  2493. }
  2494. /*
  2495. * TODO: Find best network configuration block from configuration to
  2496. * allow roaming to other networks
  2497. */
  2498. if (!ssid) {
  2499. wpa_printf(MSG_DEBUG, "CTRL_IFACE ROAM: No network "
  2500. "configuration known for the target AP");
  2501. return -1;
  2502. }
  2503. wpa_s->reassociate = 1;
  2504. wpa_supplicant_connect(wpa_s, bss, ssid);
  2505. return 0;
  2506. #endif /* CONFIG_NO_SCAN_PROCESSING */
  2507. }
  2508. #ifdef CONFIG_P2P
  2509. static int p2p_ctrl_find(struct wpa_supplicant *wpa_s, char *cmd)
  2510. {
  2511. unsigned int timeout = atoi(cmd);
  2512. enum p2p_discovery_type type = P2P_FIND_START_WITH_FULL;
  2513. u8 dev_id[ETH_ALEN], *_dev_id = NULL;
  2514. char *pos;
  2515. if (os_strstr(cmd, "type=social"))
  2516. type = P2P_FIND_ONLY_SOCIAL;
  2517. else if (os_strstr(cmd, "type=progressive"))
  2518. type = P2P_FIND_PROGRESSIVE;
  2519. pos = os_strstr(cmd, "dev_id=");
  2520. if (pos) {
  2521. pos += 7;
  2522. if (hwaddr_aton(pos, dev_id))
  2523. return -1;
  2524. _dev_id = dev_id;
  2525. }
  2526. return wpas_p2p_find(wpa_s, timeout, type, 0, NULL, _dev_id);
  2527. }
  2528. static int p2p_ctrl_connect(struct wpa_supplicant *wpa_s, char *cmd,
  2529. char *buf, size_t buflen)
  2530. {
  2531. u8 addr[ETH_ALEN];
  2532. char *pos, *pos2;
  2533. char *pin = NULL;
  2534. enum p2p_wps_method wps_method;
  2535. int new_pin;
  2536. int ret;
  2537. int persistent_group, persistent_id = -1;
  2538. int join;
  2539. int auth;
  2540. int automatic;
  2541. int go_intent = -1;
  2542. int freq = 0;
  2543. int pd;
  2544. /* <addr> <"pbc" | "pin" | PIN> [label|display|keypad]
  2545. * [persistent|persistent=<network id>]
  2546. * [join] [auth] [go_intent=<0..15>] [freq=<in MHz>] [provdisc] */
  2547. if (hwaddr_aton(cmd, addr))
  2548. return -1;
  2549. pos = cmd + 17;
  2550. if (*pos != ' ')
  2551. return -1;
  2552. pos++;
  2553. persistent_group = os_strstr(pos, " persistent") != NULL;
  2554. pos2 = os_strstr(pos, " persistent=");
  2555. if (pos2) {
  2556. struct wpa_ssid *ssid;
  2557. persistent_id = atoi(pos2 + 12);
  2558. ssid = wpa_config_get_network(wpa_s->conf, persistent_id);
  2559. if (ssid == NULL || ssid->disabled != 2 ||
  2560. ssid->mode != WPAS_MODE_P2P_GO) {
  2561. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find "
  2562. "SSID id=%d for persistent P2P group (GO)",
  2563. persistent_id);
  2564. return -1;
  2565. }
  2566. }
  2567. join = os_strstr(pos, " join") != NULL;
  2568. auth = os_strstr(pos, " auth") != NULL;
  2569. automatic = os_strstr(pos, " auto") != NULL;
  2570. pd = os_strstr(pos, " provdisc") != NULL;
  2571. pos2 = os_strstr(pos, " go_intent=");
  2572. if (pos2) {
  2573. pos2 += 11;
  2574. go_intent = atoi(pos2);
  2575. if (go_intent < 0 || go_intent > 15)
  2576. return -1;
  2577. }
  2578. pos2 = os_strstr(pos, " freq=");
  2579. if (pos2) {
  2580. pos2 += 6;
  2581. freq = atoi(pos2);
  2582. if (freq <= 0)
  2583. return -1;
  2584. }
  2585. if (os_strncmp(pos, "pin", 3) == 0) {
  2586. /* Request random PIN (to be displayed) and enable the PIN */
  2587. wps_method = WPS_PIN_DISPLAY;
  2588. } else if (os_strncmp(pos, "pbc", 3) == 0) {
  2589. wps_method = WPS_PBC;
  2590. } else {
  2591. pin = pos;
  2592. pos = os_strchr(pin, ' ');
  2593. wps_method = WPS_PIN_KEYPAD;
  2594. if (pos) {
  2595. *pos++ = '\0';
  2596. if (os_strncmp(pos, "display", 7) == 0)
  2597. wps_method = WPS_PIN_DISPLAY;
  2598. }
  2599. if (!wps_pin_str_valid(pin)) {
  2600. os_memcpy(buf, "FAIL-INVALID-PIN\n", 17);
  2601. return 17;
  2602. }
  2603. }
  2604. new_pin = wpas_p2p_connect(wpa_s, addr, pin, wps_method,
  2605. persistent_group, automatic, join,
  2606. auth, go_intent, freq, persistent_id, pd);
  2607. if (new_pin == -2) {
  2608. os_memcpy(buf, "FAIL-CHANNEL-UNAVAILABLE\n", 25);
  2609. return 25;
  2610. }
  2611. if (new_pin == -3) {
  2612. os_memcpy(buf, "FAIL-CHANNEL-UNSUPPORTED\n", 25);
  2613. return 25;
  2614. }
  2615. if (new_pin < 0)
  2616. return -1;
  2617. if (wps_method == WPS_PIN_DISPLAY && pin == NULL) {
  2618. ret = os_snprintf(buf, buflen, "%08d", new_pin);
  2619. if (ret < 0 || (size_t) ret >= buflen)
  2620. return -1;
  2621. return ret;
  2622. }
  2623. os_memcpy(buf, "OK\n", 3);
  2624. return 3;
  2625. }
  2626. static int p2p_ctrl_listen(struct wpa_supplicant *wpa_s, char *cmd)
  2627. {
  2628. unsigned int timeout = atoi(cmd);
  2629. return wpas_p2p_listen(wpa_s, timeout);
  2630. }
  2631. static int p2p_ctrl_prov_disc(struct wpa_supplicant *wpa_s, char *cmd)
  2632. {
  2633. u8 addr[ETH_ALEN];
  2634. char *pos;
  2635. enum wpas_p2p_prov_disc_use use = WPAS_P2P_PD_FOR_GO_NEG;
  2636. /* <addr> <config method> [join|auto] */
  2637. if (hwaddr_aton(cmd, addr))
  2638. return -1;
  2639. pos = cmd + 17;
  2640. if (*pos != ' ')
  2641. return -1;
  2642. pos++;
  2643. if (os_strstr(pos, " join") != NULL)
  2644. use = WPAS_P2P_PD_FOR_JOIN;
  2645. else if (os_strstr(pos, " auto") != NULL)
  2646. use = WPAS_P2P_PD_AUTO;
  2647. return wpas_p2p_prov_disc(wpa_s, addr, pos, use);
  2648. }
  2649. static int p2p_get_passphrase(struct wpa_supplicant *wpa_s, char *buf,
  2650. size_t buflen)
  2651. {
  2652. struct wpa_ssid *ssid = wpa_s->current_ssid;
  2653. if (ssid == NULL || ssid->mode != WPAS_MODE_P2P_GO ||
  2654. ssid->passphrase == NULL)
  2655. return -1;
  2656. os_strlcpy(buf, ssid->passphrase, buflen);
  2657. return os_strlen(buf);
  2658. }
  2659. static int p2p_ctrl_serv_disc_req(struct wpa_supplicant *wpa_s, char *cmd,
  2660. char *buf, size_t buflen)
  2661. {
  2662. u64 ref;
  2663. int res;
  2664. u8 dst_buf[ETH_ALEN], *dst;
  2665. struct wpabuf *tlvs;
  2666. char *pos;
  2667. size_t len;
  2668. if (hwaddr_aton(cmd, dst_buf))
  2669. return -1;
  2670. dst = dst_buf;
  2671. if (dst[0] == 0 && dst[1] == 0 && dst[2] == 0 &&
  2672. dst[3] == 0 && dst[4] == 0 && dst[5] == 0)
  2673. dst = NULL;
  2674. pos = cmd + 17;
  2675. if (*pos != ' ')
  2676. return -1;
  2677. pos++;
  2678. if (os_strncmp(pos, "upnp ", 5) == 0) {
  2679. u8 version;
  2680. pos += 5;
  2681. if (hexstr2bin(pos, &version, 1) < 0)
  2682. return -1;
  2683. pos += 2;
  2684. if (*pos != ' ')
  2685. return -1;
  2686. pos++;
  2687. ref = wpas_p2p_sd_request_upnp(wpa_s, dst, version, pos);
  2688. } else {
  2689. len = os_strlen(pos);
  2690. if (len & 1)
  2691. return -1;
  2692. len /= 2;
  2693. tlvs = wpabuf_alloc(len);
  2694. if (tlvs == NULL)
  2695. return -1;
  2696. if (hexstr2bin(pos, wpabuf_put(tlvs, len), len) < 0) {
  2697. wpabuf_free(tlvs);
  2698. return -1;
  2699. }
  2700. ref = wpas_p2p_sd_request(wpa_s, dst, tlvs);
  2701. wpabuf_free(tlvs);
  2702. }
  2703. if (ref == 0)
  2704. return -1;
  2705. res = os_snprintf(buf, buflen, "%llx", (long long unsigned) ref);
  2706. if (res < 0 || (unsigned) res >= buflen)
  2707. return -1;
  2708. return res;
  2709. }
  2710. static int p2p_ctrl_serv_disc_cancel_req(struct wpa_supplicant *wpa_s,
  2711. char *cmd)
  2712. {
  2713. long long unsigned val;
  2714. u64 req;
  2715. if (sscanf(cmd, "%llx", &val) != 1)
  2716. return -1;
  2717. req = val;
  2718. return wpas_p2p_sd_cancel_request(wpa_s, req);
  2719. }
  2720. static int p2p_ctrl_serv_disc_resp(struct wpa_supplicant *wpa_s, char *cmd)
  2721. {
  2722. int freq;
  2723. u8 dst[ETH_ALEN];
  2724. u8 dialog_token;
  2725. struct wpabuf *resp_tlvs;
  2726. char *pos, *pos2;
  2727. size_t len;
  2728. pos = os_strchr(cmd, ' ');
  2729. if (pos == NULL)
  2730. return -1;
  2731. *pos++ = '\0';
  2732. freq = atoi(cmd);
  2733. if (freq == 0)
  2734. return -1;
  2735. if (hwaddr_aton(pos, dst))
  2736. return -1;
  2737. pos += 17;
  2738. if (*pos != ' ')
  2739. return -1;
  2740. pos++;
  2741. pos2 = os_strchr(pos, ' ');
  2742. if (pos2 == NULL)
  2743. return -1;
  2744. *pos2++ = '\0';
  2745. dialog_token = atoi(pos);
  2746. len = os_strlen(pos2);
  2747. if (len & 1)
  2748. return -1;
  2749. len /= 2;
  2750. resp_tlvs = wpabuf_alloc(len);
  2751. if (resp_tlvs == NULL)
  2752. return -1;
  2753. if (hexstr2bin(pos2, wpabuf_put(resp_tlvs, len), len) < 0) {
  2754. wpabuf_free(resp_tlvs);
  2755. return -1;
  2756. }
  2757. wpas_p2p_sd_response(wpa_s, freq, dst, dialog_token, resp_tlvs);
  2758. wpabuf_free(resp_tlvs);
  2759. return 0;
  2760. }
  2761. static int p2p_ctrl_serv_disc_external(struct wpa_supplicant *wpa_s,
  2762. char *cmd)
  2763. {
  2764. if (os_strcmp(cmd, "0") && os_strcmp(cmd, "1"))
  2765. return -1;
  2766. wpa_s->p2p_sd_over_ctrl_iface = atoi(cmd);
  2767. return 0;
  2768. }
  2769. static int p2p_ctrl_service_add_bonjour(struct wpa_supplicant *wpa_s,
  2770. char *cmd)
  2771. {
  2772. char *pos;
  2773. size_t len;
  2774. struct wpabuf *query, *resp;
  2775. pos = os_strchr(cmd, ' ');
  2776. if (pos == NULL)
  2777. return -1;
  2778. *pos++ = '\0';
  2779. len = os_strlen(cmd);
  2780. if (len & 1)
  2781. return -1;
  2782. len /= 2;
  2783. query = wpabuf_alloc(len);
  2784. if (query == NULL)
  2785. return -1;
  2786. if (hexstr2bin(cmd, wpabuf_put(query, len), len) < 0) {
  2787. wpabuf_free(query);
  2788. return -1;
  2789. }
  2790. len = os_strlen(pos);
  2791. if (len & 1) {
  2792. wpabuf_free(query);
  2793. return -1;
  2794. }
  2795. len /= 2;
  2796. resp = wpabuf_alloc(len);
  2797. if (resp == NULL) {
  2798. wpabuf_free(query);
  2799. return -1;
  2800. }
  2801. if (hexstr2bin(pos, wpabuf_put(resp, len), len) < 0) {
  2802. wpabuf_free(query);
  2803. wpabuf_free(resp);
  2804. return -1;
  2805. }
  2806. if (wpas_p2p_service_add_bonjour(wpa_s, query, resp) < 0) {
  2807. wpabuf_free(query);
  2808. wpabuf_free(resp);
  2809. return -1;
  2810. }
  2811. return 0;
  2812. }
  2813. static int p2p_ctrl_service_add_upnp(struct wpa_supplicant *wpa_s, char *cmd)
  2814. {
  2815. char *pos;
  2816. u8 version;
  2817. pos = os_strchr(cmd, ' ');
  2818. if (pos == NULL)
  2819. return -1;
  2820. *pos++ = '\0';
  2821. if (hexstr2bin(cmd, &version, 1) < 0)
  2822. return -1;
  2823. return wpas_p2p_service_add_upnp(wpa_s, version, pos);
  2824. }
  2825. static int p2p_ctrl_service_add(struct wpa_supplicant *wpa_s, char *cmd)
  2826. {
  2827. char *pos;
  2828. pos = os_strchr(cmd, ' ');
  2829. if (pos == NULL)
  2830. return -1;
  2831. *pos++ = '\0';
  2832. if (os_strcmp(cmd, "bonjour") == 0)
  2833. return p2p_ctrl_service_add_bonjour(wpa_s, pos);
  2834. if (os_strcmp(cmd, "upnp") == 0)
  2835. return p2p_ctrl_service_add_upnp(wpa_s, pos);
  2836. wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd);
  2837. return -1;
  2838. }
  2839. static int p2p_ctrl_service_del_bonjour(struct wpa_supplicant *wpa_s,
  2840. char *cmd)
  2841. {
  2842. size_t len;
  2843. struct wpabuf *query;
  2844. int ret;
  2845. len = os_strlen(cmd);
  2846. if (len & 1)
  2847. return -1;
  2848. len /= 2;
  2849. query = wpabuf_alloc(len);
  2850. if (query == NULL)
  2851. return -1;
  2852. if (hexstr2bin(cmd, wpabuf_put(query, len), len) < 0) {
  2853. wpabuf_free(query);
  2854. return -1;
  2855. }
  2856. ret = wpas_p2p_service_del_bonjour(wpa_s, query);
  2857. wpabuf_free(query);
  2858. return ret;
  2859. }
  2860. static int p2p_ctrl_service_del_upnp(struct wpa_supplicant *wpa_s, char *cmd)
  2861. {
  2862. char *pos;
  2863. u8 version;
  2864. pos = os_strchr(cmd, ' ');
  2865. if (pos == NULL)
  2866. return -1;
  2867. *pos++ = '\0';
  2868. if (hexstr2bin(cmd, &version, 1) < 0)
  2869. return -1;
  2870. return wpas_p2p_service_del_upnp(wpa_s, version, pos);
  2871. }
  2872. static int p2p_ctrl_service_del(struct wpa_supplicant *wpa_s, char *cmd)
  2873. {
  2874. char *pos;
  2875. pos = os_strchr(cmd, ' ');
  2876. if (pos == NULL)
  2877. return -1;
  2878. *pos++ = '\0';
  2879. if (os_strcmp(cmd, "bonjour") == 0)
  2880. return p2p_ctrl_service_del_bonjour(wpa_s, pos);
  2881. if (os_strcmp(cmd, "upnp") == 0)
  2882. return p2p_ctrl_service_del_upnp(wpa_s, pos);
  2883. wpa_printf(MSG_DEBUG, "Unknown service '%s'", cmd);
  2884. return -1;
  2885. }
  2886. static int p2p_ctrl_reject(struct wpa_supplicant *wpa_s, char *cmd)
  2887. {
  2888. u8 addr[ETH_ALEN];
  2889. /* <addr> */
  2890. if (hwaddr_aton(cmd, addr))
  2891. return -1;
  2892. return wpas_p2p_reject(wpa_s, addr);
  2893. }
  2894. static int p2p_ctrl_invite_persistent(struct wpa_supplicant *wpa_s, char *cmd)
  2895. {
  2896. char *pos;
  2897. int id;
  2898. struct wpa_ssid *ssid;
  2899. u8 peer[ETH_ALEN];
  2900. id = atoi(cmd);
  2901. pos = os_strstr(cmd, " peer=");
  2902. if (pos) {
  2903. pos += 6;
  2904. if (hwaddr_aton(pos, peer))
  2905. return -1;
  2906. }
  2907. ssid = wpa_config_get_network(wpa_s->conf, id);
  2908. if (ssid == NULL || ssid->disabled != 2) {
  2909. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
  2910. "for persistent P2P group",
  2911. id);
  2912. return -1;
  2913. }
  2914. return wpas_p2p_invite(wpa_s, pos ? peer : NULL, ssid, NULL);
  2915. }
  2916. static int p2p_ctrl_invite_group(struct wpa_supplicant *wpa_s, char *cmd)
  2917. {
  2918. char *pos;
  2919. u8 peer[ETH_ALEN], go_dev_addr[ETH_ALEN], *go_dev = NULL;
  2920. pos = os_strstr(cmd, " peer=");
  2921. if (!pos)
  2922. return -1;
  2923. *pos = '\0';
  2924. pos += 6;
  2925. if (hwaddr_aton(pos, peer)) {
  2926. wpa_printf(MSG_DEBUG, "P2P: Invalid MAC address '%s'", pos);
  2927. return -1;
  2928. }
  2929. pos = os_strstr(pos, " go_dev_addr=");
  2930. if (pos) {
  2931. pos += 13;
  2932. if (hwaddr_aton(pos, go_dev_addr)) {
  2933. wpa_printf(MSG_DEBUG, "P2P: Invalid MAC address '%s'",
  2934. pos);
  2935. return -1;
  2936. }
  2937. go_dev = go_dev_addr;
  2938. }
  2939. return wpas_p2p_invite_group(wpa_s, cmd, peer, go_dev);
  2940. }
  2941. static int p2p_ctrl_invite(struct wpa_supplicant *wpa_s, char *cmd)
  2942. {
  2943. if (os_strncmp(cmd, "persistent=", 11) == 0)
  2944. return p2p_ctrl_invite_persistent(wpa_s, cmd + 11);
  2945. if (os_strncmp(cmd, "group=", 6) == 0)
  2946. return p2p_ctrl_invite_group(wpa_s, cmd + 6);
  2947. return -1;
  2948. }
  2949. static int p2p_ctrl_group_add_persistent(struct wpa_supplicant *wpa_s,
  2950. char *cmd, int freq)
  2951. {
  2952. int id;
  2953. struct wpa_ssid *ssid;
  2954. id = atoi(cmd);
  2955. ssid = wpa_config_get_network(wpa_s->conf, id);
  2956. if (ssid == NULL || ssid->disabled != 2) {
  2957. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Could not find SSID id=%d "
  2958. "for persistent P2P group",
  2959. id);
  2960. return -1;
  2961. }
  2962. return wpas_p2p_group_add_persistent(wpa_s, ssid, 0, freq);
  2963. }
  2964. static int p2p_ctrl_group_add(struct wpa_supplicant *wpa_s, char *cmd)
  2965. {
  2966. int freq = 0;
  2967. char *pos;
  2968. pos = os_strstr(cmd, "freq=");
  2969. if (pos)
  2970. freq = atoi(pos + 5);
  2971. if (os_strncmp(cmd, "persistent=", 11) == 0)
  2972. return p2p_ctrl_group_add_persistent(wpa_s, cmd + 11, freq);
  2973. if (os_strcmp(cmd, "persistent") == 0 ||
  2974. os_strncmp(cmd, "persistent ", 11) == 0)
  2975. return wpas_p2p_group_add(wpa_s, 1, freq);
  2976. if (os_strncmp(cmd, "freq=", 5) == 0)
  2977. return wpas_p2p_group_add(wpa_s, 0, freq);
  2978. wpa_printf(MSG_DEBUG, "CTRL: Invalid P2P_GROUP_ADD parameters '%s'",
  2979. cmd);
  2980. return -1;
  2981. }
  2982. static int p2p_ctrl_peer(struct wpa_supplicant *wpa_s, char *cmd,
  2983. char *buf, size_t buflen)
  2984. {
  2985. u8 addr[ETH_ALEN], *addr_ptr;
  2986. int next, res;
  2987. const struct p2p_peer_info *info;
  2988. char *pos, *end;
  2989. char devtype[WPS_DEV_TYPE_BUFSIZE];
  2990. struct wpa_ssid *ssid;
  2991. if (!wpa_s->global->p2p)
  2992. return -1;
  2993. if (os_strcmp(cmd, "FIRST") == 0) {
  2994. addr_ptr = NULL;
  2995. next = 0;
  2996. } else if (os_strncmp(cmd, "NEXT-", 5) == 0) {
  2997. if (hwaddr_aton(cmd + 5, addr) < 0)
  2998. return -1;
  2999. addr_ptr = addr;
  3000. next = 1;
  3001. } else {
  3002. if (hwaddr_aton(cmd, addr) < 0)
  3003. return -1;
  3004. addr_ptr = addr;
  3005. next = 0;
  3006. }
  3007. info = p2p_get_peer_info(wpa_s->global->p2p, addr_ptr, next);
  3008. if (info == NULL)
  3009. return -1;
  3010. pos = buf;
  3011. end = buf + buflen;
  3012. res = os_snprintf(pos, end - pos, MACSTR "\n"
  3013. "pri_dev_type=%s\n"
  3014. "device_name=%s\n"
  3015. "manufacturer=%s\n"
  3016. "model_name=%s\n"
  3017. "model_number=%s\n"
  3018. "serial_number=%s\n"
  3019. "config_methods=0x%x\n"
  3020. "dev_capab=0x%x\n"
  3021. "group_capab=0x%x\n"
  3022. "level=%d\n",
  3023. MAC2STR(info->p2p_device_addr),
  3024. wps_dev_type_bin2str(info->pri_dev_type,
  3025. devtype, sizeof(devtype)),
  3026. info->device_name,
  3027. info->manufacturer,
  3028. info->model_name,
  3029. info->model_number,
  3030. info->serial_number,
  3031. info->config_methods,
  3032. info->dev_capab,
  3033. info->group_capab,
  3034. info->level);
  3035. if (res < 0 || res >= end - pos)
  3036. return pos - buf;
  3037. pos += res;
  3038. ssid = wpas_p2p_get_persistent(wpa_s, info->p2p_device_addr, NULL, 0);
  3039. if (ssid) {
  3040. res = os_snprintf(pos, end - pos, "persistent=%d\n", ssid->id);
  3041. if (res < 0 || res >= end - pos)
  3042. return pos - buf;
  3043. pos += res;
  3044. }
  3045. res = p2p_get_peer_info_txt(info, pos, end - pos);
  3046. if (res < 0)
  3047. return pos - buf;
  3048. pos += res;
  3049. return pos - buf;
  3050. }
  3051. static int p2p_ctrl_disallow_freq(struct wpa_supplicant *wpa_s,
  3052. const char *param)
  3053. {
  3054. struct wpa_freq_range *freq = NULL, *n;
  3055. unsigned int count = 0, i;
  3056. const char *pos, *pos2, *pos3;
  3057. if (wpa_s->global->p2p == NULL)
  3058. return -1;
  3059. /*
  3060. * param includes comma separated frequency range.
  3061. * For example: 2412-2432,2462,5000-6000
  3062. */
  3063. pos = param;
  3064. while (pos && pos[0]) {
  3065. n = os_realloc_array(freq, count + 1,
  3066. sizeof(struct wpa_freq_range));
  3067. if (n == NULL) {
  3068. os_free(freq);
  3069. return -1;
  3070. }
  3071. freq = n;
  3072. freq[count].min = atoi(pos);
  3073. pos2 = os_strchr(pos, '-');
  3074. pos3 = os_strchr(pos, ',');
  3075. if (pos2 && (!pos3 || pos2 < pos3)) {
  3076. pos2++;
  3077. freq[count].max = atoi(pos2);
  3078. } else
  3079. freq[count].max = freq[count].min;
  3080. pos = pos3;
  3081. if (pos)
  3082. pos++;
  3083. count++;
  3084. }
  3085. for (i = 0; i < count; i++) {
  3086. wpa_printf(MSG_DEBUG, "P2P: Disallowed frequency range %u-%u",
  3087. freq[i].min, freq[i].max);
  3088. }
  3089. os_free(wpa_s->global->p2p_disallow_freq);
  3090. wpa_s->global->p2p_disallow_freq = freq;
  3091. wpa_s->global->num_p2p_disallow_freq = count;
  3092. wpas_p2p_update_channel_list(wpa_s);
  3093. return 0;
  3094. }
  3095. static int p2p_ctrl_set(struct wpa_supplicant *wpa_s, char *cmd)
  3096. {
  3097. char *param;
  3098. if (wpa_s->global->p2p == NULL)
  3099. return -1;
  3100. param = os_strchr(cmd, ' ');
  3101. if (param == NULL)
  3102. return -1;
  3103. *param++ = '\0';
  3104. if (os_strcmp(cmd, "discoverability") == 0) {
  3105. p2p_set_client_discoverability(wpa_s->global->p2p,
  3106. atoi(param));
  3107. return 0;
  3108. }
  3109. if (os_strcmp(cmd, "managed") == 0) {
  3110. p2p_set_managed_oper(wpa_s->global->p2p, atoi(param));
  3111. return 0;
  3112. }
  3113. if (os_strcmp(cmd, "listen_channel") == 0) {
  3114. return p2p_set_listen_channel(wpa_s->global->p2p, 81,
  3115. atoi(param));
  3116. }
  3117. if (os_strcmp(cmd, "ssid_postfix") == 0) {
  3118. return p2p_set_ssid_postfix(wpa_s->global->p2p, (u8 *) param,
  3119. os_strlen(param));
  3120. }
  3121. if (os_strcmp(cmd, "noa") == 0) {
  3122. char *pos;
  3123. int count, start, duration;
  3124. /* GO NoA parameters: count,start_offset(ms),duration(ms) */
  3125. count = atoi(param);
  3126. pos = os_strchr(param, ',');
  3127. if (pos == NULL)
  3128. return -1;
  3129. pos++;
  3130. start = atoi(pos);
  3131. pos = os_strchr(pos, ',');
  3132. if (pos == NULL)
  3133. return -1;
  3134. pos++;
  3135. duration = atoi(pos);
  3136. if (count < 0 || count > 255 || start < 0 || duration < 0)
  3137. return -1;
  3138. if (count == 0 && duration > 0)
  3139. return -1;
  3140. wpa_printf(MSG_DEBUG, "CTRL_IFACE: P2P_SET GO NoA: count=%d "
  3141. "start=%d duration=%d", count, start, duration);
  3142. return wpas_p2p_set_noa(wpa_s, count, start, duration);
  3143. }
  3144. if (os_strcmp(cmd, "ps") == 0)
  3145. return wpa_drv_set_p2p_powersave(wpa_s, atoi(param), -1, -1);
  3146. if (os_strcmp(cmd, "oppps") == 0)
  3147. return wpa_drv_set_p2p_powersave(wpa_s, -1, atoi(param), -1);
  3148. if (os_strcmp(cmd, "ctwindow") == 0)
  3149. return wpa_drv_set_p2p_powersave(wpa_s, -1, -1, atoi(param));
  3150. if (os_strcmp(cmd, "disabled") == 0) {
  3151. wpa_s->global->p2p_disabled = atoi(param);
  3152. wpa_printf(MSG_DEBUG, "P2P functionality %s",
  3153. wpa_s->global->p2p_disabled ?
  3154. "disabled" : "enabled");
  3155. if (wpa_s->global->p2p_disabled) {
  3156. wpas_p2p_stop_find(wpa_s);
  3157. os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN);
  3158. p2p_flush(wpa_s->global->p2p);
  3159. }
  3160. return 0;
  3161. }
  3162. if (os_strcmp(cmd, "conc_pref") == 0) {
  3163. if (os_strcmp(param, "sta") == 0)
  3164. wpa_s->global->conc_pref = WPA_CONC_PREF_STA;
  3165. else if (os_strcmp(param, "p2p") == 0)
  3166. wpa_s->global->conc_pref = WPA_CONC_PREF_P2P;
  3167. else {
  3168. wpa_printf(MSG_INFO, "Invalid conc_pref value");
  3169. return -1;
  3170. }
  3171. wpa_printf(MSG_DEBUG, "Single channel concurrency preference: "
  3172. "%s", param);
  3173. return 0;
  3174. }
  3175. if (os_strcmp(cmd, "force_long_sd") == 0) {
  3176. wpa_s->force_long_sd = atoi(param);
  3177. return 0;
  3178. }
  3179. if (os_strcmp(cmd, "peer_filter") == 0) {
  3180. u8 addr[ETH_ALEN];
  3181. if (hwaddr_aton(param, addr))
  3182. return -1;
  3183. p2p_set_peer_filter(wpa_s->global->p2p, addr);
  3184. return 0;
  3185. }
  3186. if (os_strcmp(cmd, "cross_connect") == 0)
  3187. return wpas_p2p_set_cross_connect(wpa_s, atoi(param));
  3188. if (os_strcmp(cmd, "go_apsd") == 0) {
  3189. if (os_strcmp(param, "disable") == 0)
  3190. wpa_s->set_ap_uapsd = 0;
  3191. else {
  3192. wpa_s->set_ap_uapsd = 1;
  3193. wpa_s->ap_uapsd = atoi(param);
  3194. }
  3195. return 0;
  3196. }
  3197. if (os_strcmp(cmd, "client_apsd") == 0) {
  3198. if (os_strcmp(param, "disable") == 0)
  3199. wpa_s->set_sta_uapsd = 0;
  3200. else {
  3201. int be, bk, vi, vo;
  3202. char *pos;
  3203. /* format: BE,BK,VI,VO;max SP Length */
  3204. be = atoi(param);
  3205. pos = os_strchr(param, ',');
  3206. if (pos == NULL)
  3207. return -1;
  3208. pos++;
  3209. bk = atoi(pos);
  3210. pos = os_strchr(pos, ',');
  3211. if (pos == NULL)
  3212. return -1;
  3213. pos++;
  3214. vi = atoi(pos);
  3215. pos = os_strchr(pos, ',');
  3216. if (pos == NULL)
  3217. return -1;
  3218. pos++;
  3219. vo = atoi(pos);
  3220. /* ignore max SP Length for now */
  3221. wpa_s->set_sta_uapsd = 1;
  3222. wpa_s->sta_uapsd = 0;
  3223. if (be)
  3224. wpa_s->sta_uapsd |= BIT(0);
  3225. if (bk)
  3226. wpa_s->sta_uapsd |= BIT(1);
  3227. if (vi)
  3228. wpa_s->sta_uapsd |= BIT(2);
  3229. if (vo)
  3230. wpa_s->sta_uapsd |= BIT(3);
  3231. }
  3232. return 0;
  3233. }
  3234. if (os_strcmp(cmd, "disallow_freq") == 0)
  3235. return p2p_ctrl_disallow_freq(wpa_s, param);
  3236. wpa_printf(MSG_DEBUG, "CTRL_IFACE: Unknown P2P_SET field value '%s'",
  3237. cmd);
  3238. return -1;
  3239. }
  3240. static int p2p_ctrl_presence_req(struct wpa_supplicant *wpa_s, char *cmd)
  3241. {
  3242. char *pos, *pos2;
  3243. unsigned int dur1 = 0, int1 = 0, dur2 = 0, int2 = 0;
  3244. if (cmd[0]) {
  3245. pos = os_strchr(cmd, ' ');
  3246. if (pos == NULL)
  3247. return -1;
  3248. *pos++ = '\0';
  3249. dur1 = atoi(cmd);
  3250. pos2 = os_strchr(pos, ' ');
  3251. if (pos2)
  3252. *pos2++ = '\0';
  3253. int1 = atoi(pos);
  3254. } else
  3255. pos2 = NULL;
  3256. if (pos2) {
  3257. pos = os_strchr(pos2, ' ');
  3258. if (pos == NULL)
  3259. return -1;
  3260. *pos++ = '\0';
  3261. dur2 = atoi(pos2);
  3262. int2 = atoi(pos);
  3263. }
  3264. return wpas_p2p_presence_req(wpa_s, dur1, int1, dur2, int2);
  3265. }
  3266. static int p2p_ctrl_ext_listen(struct wpa_supplicant *wpa_s, char *cmd)
  3267. {
  3268. char *pos;
  3269. unsigned int period = 0, interval = 0;
  3270. if (cmd[0]) {
  3271. pos = os_strchr(cmd, ' ');
  3272. if (pos == NULL)
  3273. return -1;
  3274. *pos++ = '\0';
  3275. period = atoi(cmd);
  3276. interval = atoi(pos);
  3277. }
  3278. return wpas_p2p_ext_listen(wpa_s, period, interval);
  3279. }
  3280. #endif /* CONFIG_P2P */
  3281. #ifdef CONFIG_INTERWORKING
  3282. static int ctrl_interworking_connect(struct wpa_supplicant *wpa_s, char *dst)
  3283. {
  3284. u8 bssid[ETH_ALEN];
  3285. struct wpa_bss *bss;
  3286. if (hwaddr_aton(dst, bssid)) {
  3287. wpa_printf(MSG_DEBUG, "Invalid BSSID '%s'", dst);
  3288. return -1;
  3289. }
  3290. bss = wpa_bss_get_bssid(wpa_s, bssid);
  3291. if (bss == NULL) {
  3292. wpa_printf(MSG_DEBUG, "Could not find BSS " MACSTR,
  3293. MAC2STR(bssid));
  3294. return -1;
  3295. }
  3296. return interworking_connect(wpa_s, bss);
  3297. }
  3298. static int get_anqp(struct wpa_supplicant *wpa_s, char *dst)
  3299. {
  3300. u8 dst_addr[ETH_ALEN];
  3301. int used;
  3302. char *pos;
  3303. #define MAX_ANQP_INFO_ID 100
  3304. u16 id[MAX_ANQP_INFO_ID];
  3305. size_t num_id = 0;
  3306. used = hwaddr_aton2(dst, dst_addr);
  3307. if (used < 0)
  3308. return -1;
  3309. pos = dst + used;
  3310. while (num_id < MAX_ANQP_INFO_ID) {
  3311. id[num_id] = atoi(pos);
  3312. if (id[num_id])
  3313. num_id++;
  3314. pos = os_strchr(pos + 1, ',');
  3315. if (pos == NULL)
  3316. break;
  3317. pos++;
  3318. }
  3319. if (num_id == 0)
  3320. return -1;
  3321. return anqp_send_req(wpa_s, dst_addr, id, num_id);
  3322. }
  3323. #endif /* CONFIG_INTERWORKING */
  3324. #ifdef CONFIG_HS20
  3325. static int get_hs20_anqp(struct wpa_supplicant *wpa_s, char *dst)
  3326. {
  3327. u8 dst_addr[ETH_ALEN];
  3328. int used;
  3329. char *pos;
  3330. u32 subtypes = 0;
  3331. used = hwaddr_aton2(dst, dst_addr);
  3332. if (used < 0)
  3333. return -1;
  3334. pos = dst + used;
  3335. for (;;) {
  3336. int num = atoi(pos);
  3337. if (num <= 0 || num > 31)
  3338. return -1;
  3339. subtypes |= BIT(num);
  3340. pos = os_strchr(pos + 1, ',');
  3341. if (pos == NULL)
  3342. break;
  3343. pos++;
  3344. }
  3345. if (subtypes == 0)
  3346. return -1;
  3347. return hs20_anqp_send_req(wpa_s, dst_addr, subtypes, NULL, 0);
  3348. }
  3349. static int hs20_nai_home_realm_list(struct wpa_supplicant *wpa_s,
  3350. const u8 *addr, const char *realm)
  3351. {
  3352. u8 *buf;
  3353. size_t rlen, len;
  3354. int ret;
  3355. rlen = os_strlen(realm);
  3356. len = 3 + rlen;
  3357. buf = os_malloc(len);
  3358. if (buf == NULL)
  3359. return -1;
  3360. buf[0] = 1; /* NAI Home Realm Count */
  3361. buf[1] = 0; /* Formatted in accordance with RFC 4282 */
  3362. buf[2] = rlen;
  3363. os_memcpy(buf + 3, realm, rlen);
  3364. ret = hs20_anqp_send_req(wpa_s, addr,
  3365. BIT(HS20_STYPE_NAI_HOME_REALM_QUERY),
  3366. buf, len);
  3367. os_free(buf);
  3368. return ret;
  3369. }
  3370. static int hs20_get_nai_home_realm_list(struct wpa_supplicant *wpa_s,
  3371. char *dst)
  3372. {
  3373. struct wpa_cred *cred = wpa_s->conf->cred;
  3374. u8 dst_addr[ETH_ALEN];
  3375. int used;
  3376. u8 *buf;
  3377. size_t len;
  3378. int ret;
  3379. used = hwaddr_aton2(dst, dst_addr);
  3380. if (used < 0)
  3381. return -1;
  3382. while (dst[used] == ' ')
  3383. used++;
  3384. if (os_strncmp(dst + used, "realm=", 6) == 0)
  3385. return hs20_nai_home_realm_list(wpa_s, dst_addr,
  3386. dst + used + 6);
  3387. len = os_strlen(dst + used);
  3388. if (len == 0 && cred && cred->realm)
  3389. return hs20_nai_home_realm_list(wpa_s, dst_addr, cred->realm);
  3390. if (len % 1)
  3391. return -1;
  3392. len /= 2;
  3393. buf = os_malloc(len);
  3394. if (buf == NULL)
  3395. return -1;
  3396. if (hexstr2bin(dst + used, buf, len) < 0) {
  3397. os_free(buf);
  3398. return -1;
  3399. }
  3400. ret = hs20_anqp_send_req(wpa_s, dst_addr,
  3401. BIT(HS20_STYPE_NAI_HOME_REALM_QUERY),
  3402. buf, len);
  3403. os_free(buf);
  3404. return ret;
  3405. }
  3406. #endif /* CONFIG_HS20 */
  3407. static int wpa_supplicant_ctrl_iface_sta_autoconnect(
  3408. struct wpa_supplicant *wpa_s, char *cmd)
  3409. {
  3410. wpa_s->auto_reconnect_disabled = atoi(cmd) == 0 ? 1 : 0;
  3411. return 0;
  3412. }
  3413. #ifdef CONFIG_AUTOSCAN
  3414. static int wpa_supplicant_ctrl_iface_autoscan(struct wpa_supplicant *wpa_s,
  3415. char *cmd)
  3416. {
  3417. enum wpa_states state = wpa_s->wpa_state;
  3418. char *new_params = NULL;
  3419. if (os_strlen(cmd) > 0) {
  3420. new_params = os_strdup(cmd);
  3421. if (new_params == NULL)
  3422. return -1;
  3423. }
  3424. os_free(wpa_s->conf->autoscan);
  3425. wpa_s->conf->autoscan = new_params;
  3426. if (wpa_s->conf->autoscan == NULL)
  3427. autoscan_deinit(wpa_s);
  3428. else if (state == WPA_DISCONNECTED || state == WPA_INACTIVE)
  3429. autoscan_init(wpa_s, 1);
  3430. else if (state == WPA_SCANNING)
  3431. wpa_supplicant_reinit_autoscan(wpa_s);
  3432. return 0;
  3433. }
  3434. #endif /* CONFIG_AUTOSCAN */
  3435. static int wpa_supplicant_signal_poll(struct wpa_supplicant *wpa_s, char *buf,
  3436. size_t buflen)
  3437. {
  3438. struct wpa_signal_info si;
  3439. int ret;
  3440. ret = wpa_drv_signal_poll(wpa_s, &si);
  3441. if (ret)
  3442. return -1;
  3443. ret = os_snprintf(buf, buflen, "RSSI=%d\nLINKSPEED=%d\n"
  3444. "NOISE=%d\nFREQUENCY=%u\n",
  3445. si.current_signal, si.current_txrate / 1000,
  3446. si.current_noise, si.frequency);
  3447. if (ret < 0 || (unsigned int) ret > buflen)
  3448. return -1;
  3449. return ret;
  3450. }
  3451. char * wpa_supplicant_ctrl_iface_process(struct wpa_supplicant *wpa_s,
  3452. char *buf, size_t *resp_len)
  3453. {
  3454. char *reply;
  3455. const int reply_size = 4096;
  3456. int ctrl_rsp = 0;
  3457. int reply_len;
  3458. if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0 ||
  3459. os_strncmp(buf, "SET_NETWORK ", 12) == 0) {
  3460. wpa_hexdump_ascii_key(MSG_DEBUG, "RX ctrl_iface",
  3461. (const u8 *) buf, os_strlen(buf));
  3462. } else {
  3463. int level = MSG_DEBUG;
  3464. if (os_strcmp(buf, "PING") == 0)
  3465. level = MSG_EXCESSIVE;
  3466. wpa_hexdump_ascii(level, "RX ctrl_iface",
  3467. (const u8 *) buf, os_strlen(buf));
  3468. }
  3469. reply = os_malloc(reply_size);
  3470. if (reply == NULL) {
  3471. *resp_len = 1;
  3472. return NULL;
  3473. }
  3474. os_memcpy(reply, "OK\n", 3);
  3475. reply_len = 3;
  3476. if (os_strcmp(buf, "PING") == 0) {
  3477. os_memcpy(reply, "PONG\n", 5);
  3478. reply_len = 5;
  3479. } else if (os_strcmp(buf, "IFNAME") == 0) {
  3480. reply_len = os_strlen(wpa_s->ifname);
  3481. os_memcpy(reply, wpa_s->ifname, reply_len);
  3482. } else if (os_strncmp(buf, "RELOG", 5) == 0) {
  3483. if (wpa_debug_reopen_file() < 0)
  3484. reply_len = -1;
  3485. } else if (os_strncmp(buf, "NOTE ", 5) == 0) {
  3486. wpa_printf(MSG_INFO, "NOTE: %s", buf + 5);
  3487. } else if (os_strcmp(buf, "MIB") == 0) {
  3488. reply_len = wpa_sm_get_mib(wpa_s->wpa, reply, reply_size);
  3489. if (reply_len >= 0) {
  3490. int res;
  3491. res = eapol_sm_get_mib(wpa_s->eapol, reply + reply_len,
  3492. reply_size - reply_len);
  3493. if (res < 0)
  3494. reply_len = -1;
  3495. else
  3496. reply_len += res;
  3497. }
  3498. } else if (os_strncmp(buf, "STATUS", 6) == 0) {
  3499. reply_len = wpa_supplicant_ctrl_iface_status(
  3500. wpa_s, buf + 6, reply, reply_size);
  3501. } else if (os_strcmp(buf, "PMKSA") == 0) {
  3502. reply_len = wpa_sm_pmksa_cache_list(wpa_s->wpa, reply,
  3503. reply_size);
  3504. } else if (os_strncmp(buf, "SET ", 4) == 0) {
  3505. if (wpa_supplicant_ctrl_iface_set(wpa_s, buf + 4))
  3506. reply_len = -1;
  3507. } else if (os_strncmp(buf, "GET ", 4) == 0) {
  3508. reply_len = wpa_supplicant_ctrl_iface_get(wpa_s, buf + 4,
  3509. reply, reply_size);
  3510. } else if (os_strcmp(buf, "LOGON") == 0) {
  3511. eapol_sm_notify_logoff(wpa_s->eapol, FALSE);
  3512. } else if (os_strcmp(buf, "LOGOFF") == 0) {
  3513. eapol_sm_notify_logoff(wpa_s->eapol, TRUE);
  3514. } else if (os_strcmp(buf, "REASSOCIATE") == 0) {
  3515. wpa_s->normal_scans = 0;
  3516. wpa_supplicant_reinit_autoscan(wpa_s);
  3517. if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
  3518. reply_len = -1;
  3519. else {
  3520. wpa_s->disconnected = 0;
  3521. wpa_s->reassociate = 1;
  3522. wpa_supplicant_req_scan(wpa_s, 0, 0);
  3523. }
  3524. } else if (os_strcmp(buf, "RECONNECT") == 0) {
  3525. wpa_s->normal_scans = 0;
  3526. wpa_supplicant_reinit_autoscan(wpa_s);
  3527. if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
  3528. reply_len = -1;
  3529. else if (wpa_s->disconnected) {
  3530. wpa_s->disconnected = 0;
  3531. wpa_s->reassociate = 1;
  3532. wpa_supplicant_req_scan(wpa_s, 0, 0);
  3533. }
  3534. #ifdef IEEE8021X_EAPOL
  3535. } else if (os_strncmp(buf, "PREAUTH ", 8) == 0) {
  3536. if (wpa_supplicant_ctrl_iface_preauth(wpa_s, buf + 8))
  3537. reply_len = -1;
  3538. #endif /* IEEE8021X_EAPOL */
  3539. #ifdef CONFIG_PEERKEY
  3540. } else if (os_strncmp(buf, "STKSTART ", 9) == 0) {
  3541. if (wpa_supplicant_ctrl_iface_stkstart(wpa_s, buf + 9))
  3542. reply_len = -1;
  3543. #endif /* CONFIG_PEERKEY */
  3544. #ifdef CONFIG_IEEE80211R
  3545. } else if (os_strncmp(buf, "FT_DS ", 6) == 0) {
  3546. if (wpa_supplicant_ctrl_iface_ft_ds(wpa_s, buf + 6))
  3547. reply_len = -1;
  3548. #endif /* CONFIG_IEEE80211R */
  3549. #ifdef CONFIG_WPS
  3550. } else if (os_strcmp(buf, "WPS_PBC") == 0) {
  3551. int res = wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, NULL);
  3552. if (res == -2) {
  3553. os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
  3554. reply_len = 17;
  3555. } else if (res)
  3556. reply_len = -1;
  3557. } else if (os_strncmp(buf, "WPS_PBC ", 8) == 0) {
  3558. int res = wpa_supplicant_ctrl_iface_wps_pbc(wpa_s, buf + 8);
  3559. if (res == -2) {
  3560. os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
  3561. reply_len = 17;
  3562. } else if (res)
  3563. reply_len = -1;
  3564. } else if (os_strncmp(buf, "WPS_PIN ", 8) == 0) {
  3565. reply_len = wpa_supplicant_ctrl_iface_wps_pin(wpa_s, buf + 8,
  3566. reply,
  3567. reply_size);
  3568. } else if (os_strncmp(buf, "WPS_CHECK_PIN ", 14) == 0) {
  3569. reply_len = wpa_supplicant_ctrl_iface_wps_check_pin(
  3570. wpa_s, buf + 14, reply, reply_size);
  3571. } else if (os_strcmp(buf, "WPS_CANCEL") == 0) {
  3572. if (wpas_wps_cancel(wpa_s))
  3573. reply_len = -1;
  3574. #ifdef CONFIG_WPS_OOB
  3575. } else if (os_strncmp(buf, "WPS_OOB ", 8) == 0) {
  3576. if (wpa_supplicant_ctrl_iface_wps_oob(wpa_s, buf + 8))
  3577. reply_len = -1;
  3578. #endif /* CONFIG_WPS_OOB */
  3579. #ifdef CONFIG_WPS_NFC
  3580. } else if (os_strcmp(buf, "WPS_NFC") == 0) {
  3581. if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s, NULL))
  3582. reply_len = -1;
  3583. } else if (os_strncmp(buf, "WPS_NFC ", 8) == 0) {
  3584. if (wpa_supplicant_ctrl_iface_wps_nfc(wpa_s, buf + 8))
  3585. reply_len = -1;
  3586. } else if (os_strncmp(buf, "WPS_NFC_TOKEN ", 14) == 0) {
  3587. reply_len = wpa_supplicant_ctrl_iface_wps_nfc_token(
  3588. wpa_s, buf + 14, reply, reply_size);
  3589. } else if (os_strncmp(buf, "WPS_NFC_TAG_READ ", 17) == 0) {
  3590. if (wpa_supplicant_ctrl_iface_wps_nfc_tag_read(wpa_s,
  3591. buf + 17))
  3592. reply_len = -1;
  3593. #endif /* CONFIG_WPS_NFC */
  3594. } else if (os_strncmp(buf, "WPS_REG ", 8) == 0) {
  3595. if (wpa_supplicant_ctrl_iface_wps_reg(wpa_s, buf + 8))
  3596. reply_len = -1;
  3597. #ifdef CONFIG_AP
  3598. } else if (os_strncmp(buf, "WPS_AP_PIN ", 11) == 0) {
  3599. reply_len = wpa_supplicant_ctrl_iface_wps_ap_pin(
  3600. wpa_s, buf + 11, reply, reply_size);
  3601. #endif /* CONFIG_AP */
  3602. #ifdef CONFIG_WPS_ER
  3603. } else if (os_strcmp(buf, "WPS_ER_START") == 0) {
  3604. if (wpas_wps_er_start(wpa_s, NULL))
  3605. reply_len = -1;
  3606. } else if (os_strncmp(buf, "WPS_ER_START ", 13) == 0) {
  3607. if (wpas_wps_er_start(wpa_s, buf + 13))
  3608. reply_len = -1;
  3609. } else if (os_strcmp(buf, "WPS_ER_STOP") == 0) {
  3610. if (wpas_wps_er_stop(wpa_s))
  3611. reply_len = -1;
  3612. } else if (os_strncmp(buf, "WPS_ER_PIN ", 11) == 0) {
  3613. if (wpa_supplicant_ctrl_iface_wps_er_pin(wpa_s, buf + 11))
  3614. reply_len = -1;
  3615. } else if (os_strncmp(buf, "WPS_ER_PBC ", 11) == 0) {
  3616. int ret = wpas_wps_er_pbc(wpa_s, buf + 11);
  3617. if (ret == -2) {
  3618. os_memcpy(reply, "FAIL-PBC-OVERLAP\n", 17);
  3619. reply_len = 17;
  3620. } else if (ret == -3) {
  3621. os_memcpy(reply, "FAIL-UNKNOWN-UUID\n", 18);
  3622. reply_len = 18;
  3623. } else if (ret == -4) {
  3624. os_memcpy(reply, "FAIL-NO-AP-SETTINGS\n", 20);
  3625. reply_len = 20;
  3626. } else if (ret)
  3627. reply_len = -1;
  3628. } else if (os_strncmp(buf, "WPS_ER_LEARN ", 13) == 0) {
  3629. if (wpa_supplicant_ctrl_iface_wps_er_learn(wpa_s, buf + 13))
  3630. reply_len = -1;
  3631. } else if (os_strncmp(buf, "WPS_ER_SET_CONFIG ", 18) == 0) {
  3632. if (wpa_supplicant_ctrl_iface_wps_er_set_config(wpa_s,
  3633. buf + 18))
  3634. reply_len = -1;
  3635. } else if (os_strncmp(buf, "WPS_ER_CONFIG ", 14) == 0) {
  3636. if (wpa_supplicant_ctrl_iface_wps_er_config(wpa_s, buf + 14))
  3637. reply_len = -1;
  3638. #ifdef CONFIG_WPS_NFC
  3639. } else if (os_strncmp(buf, "WPS_ER_NFC_CONFIG_TOKEN ", 24) == 0) {
  3640. reply_len = wpa_supplicant_ctrl_iface_wps_er_nfc_config_token(
  3641. wpa_s, buf + 24, reply, reply_size);
  3642. #endif /* CONFIG_WPS_NFC */
  3643. #endif /* CONFIG_WPS_ER */
  3644. #endif /* CONFIG_WPS */
  3645. #ifdef CONFIG_IBSS_RSN
  3646. } else if (os_strncmp(buf, "IBSS_RSN ", 9) == 0) {
  3647. if (wpa_supplicant_ctrl_iface_ibss_rsn(wpa_s, buf + 9))
  3648. reply_len = -1;
  3649. #endif /* CONFIG_IBSS_RSN */
  3650. #ifdef CONFIG_P2P
  3651. } else if (os_strncmp(buf, "P2P_FIND ", 9) == 0) {
  3652. if (p2p_ctrl_find(wpa_s, buf + 9))
  3653. reply_len = -1;
  3654. } else if (os_strcmp(buf, "P2P_FIND") == 0) {
  3655. if (p2p_ctrl_find(wpa_s, ""))
  3656. reply_len = -1;
  3657. } else if (os_strcmp(buf, "P2P_STOP_FIND") == 0) {
  3658. wpas_p2p_stop_find(wpa_s);
  3659. } else if (os_strncmp(buf, "P2P_CONNECT ", 12) == 0) {
  3660. reply_len = p2p_ctrl_connect(wpa_s, buf + 12, reply,
  3661. reply_size);
  3662. } else if (os_strncmp(buf, "P2P_LISTEN ", 11) == 0) {
  3663. if (p2p_ctrl_listen(wpa_s, buf + 11))
  3664. reply_len = -1;
  3665. } else if (os_strcmp(buf, "P2P_LISTEN") == 0) {
  3666. if (p2p_ctrl_listen(wpa_s, ""))
  3667. reply_len = -1;
  3668. } else if (os_strncmp(buf, "P2P_GROUP_REMOVE ", 17) == 0) {
  3669. if (wpas_p2p_group_remove(wpa_s, buf + 17))
  3670. reply_len = -1;
  3671. } else if (os_strcmp(buf, "P2P_GROUP_ADD") == 0) {
  3672. if (wpas_p2p_group_add(wpa_s, 0, 0))
  3673. reply_len = -1;
  3674. } else if (os_strncmp(buf, "P2P_GROUP_ADD ", 14) == 0) {
  3675. if (p2p_ctrl_group_add(wpa_s, buf + 14))
  3676. reply_len = -1;
  3677. } else if (os_strncmp(buf, "P2P_PROV_DISC ", 14) == 0) {
  3678. if (p2p_ctrl_prov_disc(wpa_s, buf + 14))
  3679. reply_len = -1;
  3680. } else if (os_strcmp(buf, "P2P_GET_PASSPHRASE") == 0) {
  3681. reply_len = p2p_get_passphrase(wpa_s, reply, reply_size);
  3682. } else if (os_strncmp(buf, "P2P_SERV_DISC_REQ ", 18) == 0) {
  3683. reply_len = p2p_ctrl_serv_disc_req(wpa_s, buf + 18, reply,
  3684. reply_size);
  3685. } else if (os_strncmp(buf, "P2P_SERV_DISC_CANCEL_REQ ", 25) == 0) {
  3686. if (p2p_ctrl_serv_disc_cancel_req(wpa_s, buf + 25) < 0)
  3687. reply_len = -1;
  3688. } else if (os_strncmp(buf, "P2P_SERV_DISC_RESP ", 19) == 0) {
  3689. if (p2p_ctrl_serv_disc_resp(wpa_s, buf + 19) < 0)
  3690. reply_len = -1;
  3691. } else if (os_strcmp(buf, "P2P_SERVICE_UPDATE") == 0) {
  3692. wpas_p2p_sd_service_update(wpa_s);
  3693. } else if (os_strncmp(buf, "P2P_SERV_DISC_EXTERNAL ", 23) == 0) {
  3694. if (p2p_ctrl_serv_disc_external(wpa_s, buf + 23) < 0)
  3695. reply_len = -1;
  3696. } else if (os_strcmp(buf, "P2P_SERVICE_FLUSH") == 0) {
  3697. wpas_p2p_service_flush(wpa_s);
  3698. } else if (os_strncmp(buf, "P2P_SERVICE_ADD ", 16) == 0) {
  3699. if (p2p_ctrl_service_add(wpa_s, buf + 16) < 0)
  3700. reply_len = -1;
  3701. } else if (os_strncmp(buf, "P2P_SERVICE_DEL ", 16) == 0) {
  3702. if (p2p_ctrl_service_del(wpa_s, buf + 16) < 0)
  3703. reply_len = -1;
  3704. } else if (os_strncmp(buf, "P2P_REJECT ", 11) == 0) {
  3705. if (p2p_ctrl_reject(wpa_s, buf + 11) < 0)
  3706. reply_len = -1;
  3707. } else if (os_strncmp(buf, "P2P_INVITE ", 11) == 0) {
  3708. if (p2p_ctrl_invite(wpa_s, buf + 11) < 0)
  3709. reply_len = -1;
  3710. } else if (os_strncmp(buf, "P2P_PEER ", 9) == 0) {
  3711. reply_len = p2p_ctrl_peer(wpa_s, buf + 9, reply,
  3712. reply_size);
  3713. } else if (os_strncmp(buf, "P2P_SET ", 8) == 0) {
  3714. if (p2p_ctrl_set(wpa_s, buf + 8) < 0)
  3715. reply_len = -1;
  3716. } else if (os_strcmp(buf, "P2P_FLUSH") == 0) {
  3717. os_memset(wpa_s->p2p_auth_invite, 0, ETH_ALEN);
  3718. wpa_s->force_long_sd = 0;
  3719. if (wpa_s->global->p2p)
  3720. p2p_flush(wpa_s->global->p2p);
  3721. } else if (os_strncmp(buf, "P2P_UNAUTHORIZE ", 16) == 0) {
  3722. if (wpas_p2p_unauthorize(wpa_s, buf + 16) < 0)
  3723. reply_len = -1;
  3724. } else if (os_strcmp(buf, "P2P_CANCEL") == 0) {
  3725. if (wpas_p2p_cancel(wpa_s))
  3726. reply_len = -1;
  3727. } else if (os_strncmp(buf, "P2P_PRESENCE_REQ ", 17) == 0) {
  3728. if (p2p_ctrl_presence_req(wpa_s, buf + 17) < 0)
  3729. reply_len = -1;
  3730. } else if (os_strcmp(buf, "P2P_PRESENCE_REQ") == 0) {
  3731. if (p2p_ctrl_presence_req(wpa_s, "") < 0)
  3732. reply_len = -1;
  3733. } else if (os_strncmp(buf, "P2P_EXT_LISTEN ", 15) == 0) {
  3734. if (p2p_ctrl_ext_listen(wpa_s, buf + 15) < 0)
  3735. reply_len = -1;
  3736. } else if (os_strcmp(buf, "P2P_EXT_LISTEN") == 0) {
  3737. if (p2p_ctrl_ext_listen(wpa_s, "") < 0)
  3738. reply_len = -1;
  3739. #endif /* CONFIG_P2P */
  3740. #ifdef CONFIG_INTERWORKING
  3741. } else if (os_strcmp(buf, "FETCH_ANQP") == 0) {
  3742. if (interworking_fetch_anqp(wpa_s) < 0)
  3743. reply_len = -1;
  3744. } else if (os_strcmp(buf, "STOP_FETCH_ANQP") == 0) {
  3745. interworking_stop_fetch_anqp(wpa_s);
  3746. } else if (os_strncmp(buf, "INTERWORKING_SELECT", 19) == 0) {
  3747. if (interworking_select(wpa_s, os_strstr(buf + 19, "auto") !=
  3748. NULL) < 0)
  3749. reply_len = -1;
  3750. } else if (os_strncmp(buf, "INTERWORKING_CONNECT ", 21) == 0) {
  3751. if (ctrl_interworking_connect(wpa_s, buf + 21) < 0)
  3752. reply_len = -1;
  3753. } else if (os_strncmp(buf, "ANQP_GET ", 9) == 0) {
  3754. if (get_anqp(wpa_s, buf + 9) < 0)
  3755. reply_len = -1;
  3756. #endif /* CONFIG_INTERWORKING */
  3757. #ifdef CONFIG_HS20
  3758. } else if (os_strncmp(buf, "HS20_ANQP_GET ", 14) == 0) {
  3759. if (get_hs20_anqp(wpa_s, buf + 14) < 0)
  3760. reply_len = -1;
  3761. } else if (os_strncmp(buf, "HS20_GET_NAI_HOME_REALM_LIST ", 29) == 0) {
  3762. if (hs20_get_nai_home_realm_list(wpa_s, buf + 29) < 0)
  3763. reply_len = -1;
  3764. #endif /* CONFIG_HS20 */
  3765. } else if (os_strncmp(buf, WPA_CTRL_RSP, os_strlen(WPA_CTRL_RSP)) == 0)
  3766. {
  3767. if (wpa_supplicant_ctrl_iface_ctrl_rsp(
  3768. wpa_s, buf + os_strlen(WPA_CTRL_RSP)))
  3769. reply_len = -1;
  3770. else
  3771. ctrl_rsp = 1;
  3772. } else if (os_strcmp(buf, "RECONFIGURE") == 0) {
  3773. if (wpa_supplicant_reload_configuration(wpa_s))
  3774. reply_len = -1;
  3775. } else if (os_strcmp(buf, "TERMINATE") == 0) {
  3776. wpa_supplicant_terminate_proc(wpa_s->global);
  3777. } else if (os_strncmp(buf, "BSSID ", 6) == 0) {
  3778. if (wpa_supplicant_ctrl_iface_bssid(wpa_s, buf + 6))
  3779. reply_len = -1;
  3780. } else if (os_strncmp(buf, "BLACKLIST", 9) == 0) {
  3781. reply_len = wpa_supplicant_ctrl_iface_blacklist(
  3782. wpa_s, buf + 9, reply, reply_size);
  3783. } else if (os_strncmp(buf, "LOG_LEVEL", 9) == 0) {
  3784. reply_len = wpa_supplicant_ctrl_iface_log_level(
  3785. wpa_s, buf + 9, reply, reply_size);
  3786. } else if (os_strcmp(buf, "LIST_NETWORKS") == 0) {
  3787. reply_len = wpa_supplicant_ctrl_iface_list_networks(
  3788. wpa_s, reply, reply_size);
  3789. } else if (os_strcmp(buf, "DISCONNECT") == 0) {
  3790. #ifdef CONFIG_SME
  3791. wpa_s->sme.prev_bssid_set = 0;
  3792. #endif /* CONFIG_SME */
  3793. wpa_s->reassociate = 0;
  3794. wpa_s->disconnected = 1;
  3795. wpa_supplicant_cancel_sched_scan(wpa_s);
  3796. wpa_supplicant_cancel_scan(wpa_s);
  3797. wpa_supplicant_deauthenticate(wpa_s,
  3798. WLAN_REASON_DEAUTH_LEAVING);
  3799. } else if (os_strcmp(buf, "SCAN") == 0) {
  3800. if (wpa_s->wpa_state == WPA_INTERFACE_DISABLED)
  3801. reply_len = -1;
  3802. else {
  3803. if (!wpa_s->scanning &&
  3804. ((wpa_s->wpa_state <= WPA_SCANNING) ||
  3805. (wpa_s->wpa_state == WPA_COMPLETED))) {
  3806. wpa_s->normal_scans = 0;
  3807. wpa_s->scan_req = 2;
  3808. wpa_supplicant_req_scan(wpa_s, 0, 0);
  3809. } else if (wpa_s->sched_scanning) {
  3810. wpa_printf(MSG_DEBUG, "Stop ongoing "
  3811. "sched_scan to allow requested "
  3812. "full scan to proceed");
  3813. wpa_supplicant_cancel_sched_scan(wpa_s);
  3814. wpa_s->scan_req = 2;
  3815. wpa_supplicant_req_scan(wpa_s, 0, 0);
  3816. } else {
  3817. wpa_printf(MSG_DEBUG, "Ongoing scan action - "
  3818. "reject new request");
  3819. reply_len = os_snprintf(reply, reply_size,
  3820. "FAIL-BUSY\n");
  3821. }
  3822. }
  3823. } else if (os_strcmp(buf, "SCAN_RESULTS") == 0) {
  3824. reply_len = wpa_supplicant_ctrl_iface_scan_results(
  3825. wpa_s, reply, reply_size);
  3826. } else if (os_strncmp(buf, "SELECT_NETWORK ", 15) == 0) {
  3827. if (wpa_supplicant_ctrl_iface_select_network(wpa_s, buf + 15))
  3828. reply_len = -1;
  3829. } else if (os_strncmp(buf, "ENABLE_NETWORK ", 15) == 0) {
  3830. if (wpa_supplicant_ctrl_iface_enable_network(wpa_s, buf + 15))
  3831. reply_len = -1;
  3832. } else if (os_strncmp(buf, "DISABLE_NETWORK ", 16) == 0) {
  3833. if (wpa_supplicant_ctrl_iface_disable_network(wpa_s, buf + 16))
  3834. reply_len = -1;
  3835. } else if (os_strcmp(buf, "ADD_NETWORK") == 0) {
  3836. reply_len = wpa_supplicant_ctrl_iface_add_network(
  3837. wpa_s, reply, reply_size);
  3838. } else if (os_strncmp(buf, "REMOVE_NETWORK ", 15) == 0) {
  3839. if (wpa_supplicant_ctrl_iface_remove_network(wpa_s, buf + 15))
  3840. reply_len = -1;
  3841. } else if (os_strncmp(buf, "SET_NETWORK ", 12) == 0) {
  3842. if (wpa_supplicant_ctrl_iface_set_network(wpa_s, buf + 12))
  3843. reply_len = -1;
  3844. } else if (os_strncmp(buf, "GET_NETWORK ", 12) == 0) {
  3845. reply_len = wpa_supplicant_ctrl_iface_get_network(
  3846. wpa_s, buf + 12, reply, reply_size);
  3847. } else if (os_strcmp(buf, "LIST_CREDS") == 0) {
  3848. reply_len = wpa_supplicant_ctrl_iface_list_creds(
  3849. wpa_s, reply, reply_size);
  3850. } else if (os_strcmp(buf, "ADD_CRED") == 0) {
  3851. reply_len = wpa_supplicant_ctrl_iface_add_cred(
  3852. wpa_s, reply, reply_size);
  3853. } else if (os_strncmp(buf, "REMOVE_CRED ", 12) == 0) {
  3854. if (wpa_supplicant_ctrl_iface_remove_cred(wpa_s, buf + 12))
  3855. reply_len = -1;
  3856. } else if (os_strncmp(buf, "SET_CRED ", 9) == 0) {
  3857. if (wpa_supplicant_ctrl_iface_set_cred(wpa_s, buf + 9))
  3858. reply_len = -1;
  3859. #ifndef CONFIG_NO_CONFIG_WRITE
  3860. } else if (os_strcmp(buf, "SAVE_CONFIG") == 0) {
  3861. if (wpa_supplicant_ctrl_iface_save_config(wpa_s))
  3862. reply_len = -1;
  3863. #endif /* CONFIG_NO_CONFIG_WRITE */
  3864. } else if (os_strncmp(buf, "GET_CAPABILITY ", 15) == 0) {
  3865. reply_len = wpa_supplicant_ctrl_iface_get_capability(
  3866. wpa_s, buf + 15, reply, reply_size);
  3867. } else if (os_strncmp(buf, "AP_SCAN ", 8) == 0) {
  3868. if (wpa_supplicant_ctrl_iface_ap_scan(wpa_s, buf + 8))
  3869. reply_len = -1;
  3870. } else if (os_strncmp(buf, "SCAN_INTERVAL ", 14) == 0) {
  3871. if (wpa_supplicant_ctrl_iface_scan_interval(wpa_s, buf + 14))
  3872. reply_len = -1;
  3873. } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) {
  3874. reply_len = wpa_supplicant_global_iface_list(
  3875. wpa_s->global, reply, reply_size);
  3876. } else if (os_strcmp(buf, "INTERFACES") == 0) {
  3877. reply_len = wpa_supplicant_global_iface_interfaces(
  3878. wpa_s->global, reply, reply_size);
  3879. } else if (os_strncmp(buf, "BSS ", 4) == 0) {
  3880. reply_len = wpa_supplicant_ctrl_iface_bss(
  3881. wpa_s, buf + 4, reply, reply_size);
  3882. #ifdef CONFIG_AP
  3883. } else if (os_strcmp(buf, "STA-FIRST") == 0) {
  3884. reply_len = ap_ctrl_iface_sta_first(wpa_s, reply, reply_size);
  3885. } else if (os_strncmp(buf, "STA ", 4) == 0) {
  3886. reply_len = ap_ctrl_iface_sta(wpa_s, buf + 4, reply,
  3887. reply_size);
  3888. } else if (os_strncmp(buf, "STA-NEXT ", 9) == 0) {
  3889. reply_len = ap_ctrl_iface_sta_next(wpa_s, buf + 9, reply,
  3890. reply_size);
  3891. } else if (os_strncmp(buf, "DEAUTHENTICATE ", 15) == 0) {
  3892. if (ap_ctrl_iface_sta_deauthenticate(wpa_s, buf + 15))
  3893. reply_len = -1;
  3894. } else if (os_strncmp(buf, "DISASSOCIATE ", 13) == 0) {
  3895. if (ap_ctrl_iface_sta_disassociate(wpa_s, buf + 13))
  3896. reply_len = -1;
  3897. #endif /* CONFIG_AP */
  3898. } else if (os_strcmp(buf, "SUSPEND") == 0) {
  3899. wpas_notify_suspend(wpa_s->global);
  3900. } else if (os_strcmp(buf, "RESUME") == 0) {
  3901. wpas_notify_resume(wpa_s->global);
  3902. } else if (os_strcmp(buf, "DROP_SA") == 0) {
  3903. wpa_supplicant_ctrl_iface_drop_sa(wpa_s);
  3904. } else if (os_strncmp(buf, "ROAM ", 5) == 0) {
  3905. if (wpa_supplicant_ctrl_iface_roam(wpa_s, buf + 5))
  3906. reply_len = -1;
  3907. } else if (os_strncmp(buf, "STA_AUTOCONNECT ", 16) == 0) {
  3908. if (wpa_supplicant_ctrl_iface_sta_autoconnect(wpa_s, buf + 16))
  3909. reply_len = -1;
  3910. } else if (os_strncmp(buf, "BSS_EXPIRE_AGE ", 15) == 0) {
  3911. if (wpa_supplicant_ctrl_iface_bss_expire_age(wpa_s, buf + 15))
  3912. reply_len = -1;
  3913. } else if (os_strncmp(buf, "BSS_EXPIRE_COUNT ", 17) == 0) {
  3914. if (wpa_supplicant_ctrl_iface_bss_expire_count(wpa_s,
  3915. buf + 17))
  3916. reply_len = -1;
  3917. #ifdef CONFIG_TDLS
  3918. } else if (os_strncmp(buf, "TDLS_DISCOVER ", 14) == 0) {
  3919. if (wpa_supplicant_ctrl_iface_tdls_discover(wpa_s, buf + 14))
  3920. reply_len = -1;
  3921. } else if (os_strncmp(buf, "TDLS_SETUP ", 11) == 0) {
  3922. if (wpa_supplicant_ctrl_iface_tdls_setup(wpa_s, buf + 11))
  3923. reply_len = -1;
  3924. } else if (os_strncmp(buf, "TDLS_TEARDOWN ", 14) == 0) {
  3925. if (wpa_supplicant_ctrl_iface_tdls_teardown(wpa_s, buf + 14))
  3926. reply_len = -1;
  3927. #endif /* CONFIG_TDLS */
  3928. } else if (os_strncmp(buf, "SIGNAL_POLL", 11) == 0) {
  3929. reply_len = wpa_supplicant_signal_poll(wpa_s, reply,
  3930. reply_size);
  3931. #ifdef CONFIG_AUTOSCAN
  3932. } else if (os_strncmp(buf, "AUTOSCAN ", 9) == 0) {
  3933. if (wpa_supplicant_ctrl_iface_autoscan(wpa_s, buf + 9))
  3934. reply_len = -1;
  3935. #endif /* CONFIG_AUTOSCAN */
  3936. } else if (os_strcmp(buf, "REAUTHENTICATE") == 0) {
  3937. eapol_sm_request_reauth(wpa_s->eapol);
  3938. } else {
  3939. os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
  3940. reply_len = 16;
  3941. }
  3942. if (reply_len < 0) {
  3943. os_memcpy(reply, "FAIL\n", 5);
  3944. reply_len = 5;
  3945. }
  3946. if (ctrl_rsp)
  3947. eapol_sm_notify_ctrl_response(wpa_s->eapol);
  3948. *resp_len = reply_len;
  3949. return reply;
  3950. }
  3951. static int wpa_supplicant_global_iface_add(struct wpa_global *global,
  3952. char *cmd)
  3953. {
  3954. struct wpa_interface iface;
  3955. char *pos;
  3956. /*
  3957. * <ifname>TAB<confname>TAB<driver>TAB<ctrl_interface>TAB<driver_param>
  3958. * TAB<bridge_ifname>
  3959. */
  3960. wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_ADD '%s'", cmd);
  3961. os_memset(&iface, 0, sizeof(iface));
  3962. do {
  3963. iface.ifname = pos = cmd;
  3964. pos = os_strchr(pos, '\t');
  3965. if (pos)
  3966. *pos++ = '\0';
  3967. if (iface.ifname[0] == '\0')
  3968. return -1;
  3969. if (pos == NULL)
  3970. break;
  3971. iface.confname = pos;
  3972. pos = os_strchr(pos, '\t');
  3973. if (pos)
  3974. *pos++ = '\0';
  3975. if (iface.confname[0] == '\0')
  3976. iface.confname = NULL;
  3977. if (pos == NULL)
  3978. break;
  3979. iface.driver = pos;
  3980. pos = os_strchr(pos, '\t');
  3981. if (pos)
  3982. *pos++ = '\0';
  3983. if (iface.driver[0] == '\0')
  3984. iface.driver = NULL;
  3985. if (pos == NULL)
  3986. break;
  3987. iface.ctrl_interface = pos;
  3988. pos = os_strchr(pos, '\t');
  3989. if (pos)
  3990. *pos++ = '\0';
  3991. if (iface.ctrl_interface[0] == '\0')
  3992. iface.ctrl_interface = NULL;
  3993. if (pos == NULL)
  3994. break;
  3995. iface.driver_param = pos;
  3996. pos = os_strchr(pos, '\t');
  3997. if (pos)
  3998. *pos++ = '\0';
  3999. if (iface.driver_param[0] == '\0')
  4000. iface.driver_param = NULL;
  4001. if (pos == NULL)
  4002. break;
  4003. iface.bridge_ifname = pos;
  4004. pos = os_strchr(pos, '\t');
  4005. if (pos)
  4006. *pos++ = '\0';
  4007. if (iface.bridge_ifname[0] == '\0')
  4008. iface.bridge_ifname = NULL;
  4009. if (pos == NULL)
  4010. break;
  4011. } while (0);
  4012. if (wpa_supplicant_get_iface(global, iface.ifname))
  4013. return -1;
  4014. return wpa_supplicant_add_iface(global, &iface) ? 0 : -1;
  4015. }
  4016. static int wpa_supplicant_global_iface_remove(struct wpa_global *global,
  4017. char *cmd)
  4018. {
  4019. struct wpa_supplicant *wpa_s;
  4020. wpa_printf(MSG_DEBUG, "CTRL_IFACE GLOBAL INTERFACE_REMOVE '%s'", cmd);
  4021. wpa_s = wpa_supplicant_get_iface(global, cmd);
  4022. if (wpa_s == NULL)
  4023. return -1;
  4024. return wpa_supplicant_remove_iface(global, wpa_s, 0);
  4025. }
  4026. static void wpa_free_iface_info(struct wpa_interface_info *iface)
  4027. {
  4028. struct wpa_interface_info *prev;
  4029. while (iface) {
  4030. prev = iface;
  4031. iface = iface->next;
  4032. os_free(prev->ifname);
  4033. os_free(prev->desc);
  4034. os_free(prev);
  4035. }
  4036. }
  4037. static int wpa_supplicant_global_iface_list(struct wpa_global *global,
  4038. char *buf, int len)
  4039. {
  4040. int i, res;
  4041. struct wpa_interface_info *iface = NULL, *last = NULL, *tmp;
  4042. char *pos, *end;
  4043. for (i = 0; wpa_drivers[i]; i++) {
  4044. struct wpa_driver_ops *drv = wpa_drivers[i];
  4045. if (drv->get_interfaces == NULL)
  4046. continue;
  4047. tmp = drv->get_interfaces(global->drv_priv[i]);
  4048. if (tmp == NULL)
  4049. continue;
  4050. if (last == NULL)
  4051. iface = last = tmp;
  4052. else
  4053. last->next = tmp;
  4054. while (last->next)
  4055. last = last->next;
  4056. }
  4057. pos = buf;
  4058. end = buf + len;
  4059. for (tmp = iface; tmp; tmp = tmp->next) {
  4060. res = os_snprintf(pos, end - pos, "%s\t%s\t%s\n",
  4061. tmp->drv_name, tmp->ifname,
  4062. tmp->desc ? tmp->desc : "");
  4063. if (res < 0 || res >= end - pos) {
  4064. *pos = '\0';
  4065. break;
  4066. }
  4067. pos += res;
  4068. }
  4069. wpa_free_iface_info(iface);
  4070. return pos - buf;
  4071. }
  4072. static int wpa_supplicant_global_iface_interfaces(struct wpa_global *global,
  4073. char *buf, int len)
  4074. {
  4075. int res;
  4076. char *pos, *end;
  4077. struct wpa_supplicant *wpa_s;
  4078. wpa_s = global->ifaces;
  4079. pos = buf;
  4080. end = buf + len;
  4081. while (wpa_s) {
  4082. res = os_snprintf(pos, end - pos, "%s\n", wpa_s->ifname);
  4083. if (res < 0 || res >= end - pos) {
  4084. *pos = '\0';
  4085. break;
  4086. }
  4087. pos += res;
  4088. wpa_s = wpa_s->next;
  4089. }
  4090. return pos - buf;
  4091. }
  4092. char * wpa_supplicant_global_ctrl_iface_process(struct wpa_global *global,
  4093. char *buf, size_t *resp_len)
  4094. {
  4095. char *reply;
  4096. const int reply_size = 2048;
  4097. int reply_len;
  4098. int level = MSG_DEBUG;
  4099. if (os_strcmp(buf, "PING") == 0)
  4100. level = MSG_EXCESSIVE;
  4101. wpa_hexdump_ascii(level, "RX global ctrl_iface",
  4102. (const u8 *) buf, os_strlen(buf));
  4103. reply = os_malloc(reply_size);
  4104. if (reply == NULL) {
  4105. *resp_len = 1;
  4106. return NULL;
  4107. }
  4108. os_memcpy(reply, "OK\n", 3);
  4109. reply_len = 3;
  4110. if (os_strcmp(buf, "PING") == 0) {
  4111. os_memcpy(reply, "PONG\n", 5);
  4112. reply_len = 5;
  4113. } else if (os_strncmp(buf, "INTERFACE_ADD ", 14) == 0) {
  4114. if (wpa_supplicant_global_iface_add(global, buf + 14))
  4115. reply_len = -1;
  4116. } else if (os_strncmp(buf, "INTERFACE_REMOVE ", 17) == 0) {
  4117. if (wpa_supplicant_global_iface_remove(global, buf + 17))
  4118. reply_len = -1;
  4119. } else if (os_strcmp(buf, "INTERFACE_LIST") == 0) {
  4120. reply_len = wpa_supplicant_global_iface_list(
  4121. global, reply, reply_size);
  4122. } else if (os_strcmp(buf, "INTERFACES") == 0) {
  4123. reply_len = wpa_supplicant_global_iface_interfaces(
  4124. global, reply, reply_size);
  4125. } else if (os_strcmp(buf, "TERMINATE") == 0) {
  4126. wpa_supplicant_terminate_proc(global);
  4127. } else if (os_strcmp(buf, "SUSPEND") == 0) {
  4128. wpas_notify_suspend(global);
  4129. } else if (os_strcmp(buf, "RESUME") == 0) {
  4130. wpas_notify_resume(global);
  4131. } else {
  4132. os_memcpy(reply, "UNKNOWN COMMAND\n", 16);
  4133. reply_len = 16;
  4134. }
  4135. if (reply_len < 0) {
  4136. os_memcpy(reply, "FAIL\n", 5);
  4137. reply_len = 5;
  4138. }
  4139. *resp_len = reply_len;
  4140. return reply;
  4141. }