ctrl_iface.c 108 KB

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