wpa_cli.c 116 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584
  1. /*
  2. * WPA Supplicant - command line interface for wpa_supplicant daemon
  3. * Copyright (c) 2004-2017, 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 "includes.h"
  9. #ifdef CONFIG_CTRL_IFACE
  10. #ifdef CONFIG_CTRL_IFACE_UNIX
  11. #include <dirent.h>
  12. #endif /* CONFIG_CTRL_IFACE_UNIX */
  13. #include "common/cli.h"
  14. #include "common/wpa_ctrl.h"
  15. #include "utils/common.h"
  16. #include "utils/eloop.h"
  17. #include "utils/edit.h"
  18. #include "utils/list.h"
  19. #include "common/version.h"
  20. #include "common/ieee802_11_defs.h"
  21. #ifdef ANDROID
  22. #include <cutils/properties.h>
  23. #endif /* ANDROID */
  24. static const char *const wpa_cli_version =
  25. "wpa_cli v" VERSION_STR "\n"
  26. "Copyright (c) 2004-2017, Jouni Malinen <j@w1.fi> and contributors";
  27. #define VENDOR_ELEM_FRAME_ID \
  28. " 0: Probe Req (P2P), 1: Probe Resp (P2P) , 2: Probe Resp (GO), " \
  29. "3: Beacon (GO), 4: PD Req, 5: PD Resp, 6: GO Neg Req, " \
  30. "7: GO Neg Resp, 8: GO Neg Conf, 9: Inv Req, 10: Inv Resp, " \
  31. "11: Assoc Req (P2P), 12: Assoc Resp (P2P)"
  32. static struct wpa_ctrl *ctrl_conn;
  33. static struct wpa_ctrl *mon_conn;
  34. static int wpa_cli_quit = 0;
  35. static int wpa_cli_attached = 0;
  36. static int wpa_cli_connected = -1;
  37. static int wpa_cli_last_id = 0;
  38. #ifndef CONFIG_CTRL_IFACE_DIR
  39. #define CONFIG_CTRL_IFACE_DIR "/var/run/wpa_supplicant"
  40. #endif /* CONFIG_CTRL_IFACE_DIR */
  41. static const char *ctrl_iface_dir = CONFIG_CTRL_IFACE_DIR;
  42. static const char *client_socket_dir = NULL;
  43. static char *ctrl_ifname = NULL;
  44. static const char *pid_file = NULL;
  45. static const char *action_file = NULL;
  46. static int ping_interval = 5;
  47. static int interactive = 0;
  48. static char *ifname_prefix = NULL;
  49. static DEFINE_DL_LIST(bsses); /* struct cli_txt_entry */
  50. static DEFINE_DL_LIST(p2p_peers); /* struct cli_txt_entry */
  51. static DEFINE_DL_LIST(p2p_groups); /* struct cli_txt_entry */
  52. static DEFINE_DL_LIST(ifnames); /* struct cli_txt_entry */
  53. static DEFINE_DL_LIST(networks); /* struct cli_txt_entry */
  54. #ifdef CONFIG_AP
  55. static DEFINE_DL_LIST(stations); /* struct cli_txt_entry */
  56. #endif /* CONFIG_AP */
  57. static void print_help(const char *cmd);
  58. static void wpa_cli_mon_receive(int sock, void *eloop_ctx, void *sock_ctx);
  59. static void wpa_cli_close_connection(void);
  60. static char * wpa_cli_get_default_ifname(void);
  61. static char ** wpa_list_cmd_list(void);
  62. static void update_networks(struct wpa_ctrl *ctrl);
  63. static void update_stations(struct wpa_ctrl *ctrl);
  64. static void usage(void)
  65. {
  66. printf("wpa_cli [-p<path to ctrl sockets>] [-i<ifname>] [-hvB] "
  67. "[-a<action file>] \\\n"
  68. " [-P<pid file>] [-g<global ctrl>] [-G<ping interval>] "
  69. "\\\n"
  70. " [-s<wpa_client_socket_file_path>] "
  71. "[command..]\n"
  72. " -h = help (show this usage text)\n"
  73. " -v = shown version information\n"
  74. " -a = run in daemon mode executing the action file based on "
  75. "events from\n"
  76. " wpa_supplicant\n"
  77. " -B = run a daemon in the background\n"
  78. " default path: " CONFIG_CTRL_IFACE_DIR "\n"
  79. " default interface: first interface found in socket path\n");
  80. print_help(NULL);
  81. }
  82. static int wpa_cli_show_event(const char *event)
  83. {
  84. const char *start;
  85. start = os_strchr(event, '>');
  86. if (start == NULL)
  87. return 1;
  88. start++;
  89. /*
  90. * Skip BSS added/removed events since they can be relatively frequent
  91. * and are likely of not much use for an interactive user.
  92. */
  93. if (str_starts(start, WPA_EVENT_BSS_ADDED) ||
  94. str_starts(start, WPA_EVENT_BSS_REMOVED))
  95. return 0;
  96. return 1;
  97. }
  98. static int wpa_cli_open_connection(const char *ifname, int attach)
  99. {
  100. #if defined(CONFIG_CTRL_IFACE_UDP) || defined(CONFIG_CTRL_IFACE_NAMED_PIPE)
  101. ctrl_conn = wpa_ctrl_open(ifname);
  102. if (ctrl_conn == NULL)
  103. return -1;
  104. if (attach && interactive)
  105. mon_conn = wpa_ctrl_open(ifname);
  106. else
  107. mon_conn = NULL;
  108. #else /* CONFIG_CTRL_IFACE_UDP || CONFIG_CTRL_IFACE_NAMED_PIPE */
  109. char *cfile = NULL;
  110. int flen, res;
  111. if (ifname == NULL)
  112. return -1;
  113. #ifdef ANDROID
  114. if (access(ctrl_iface_dir, F_OK) < 0) {
  115. cfile = os_strdup(ifname);
  116. if (cfile == NULL)
  117. return -1;
  118. }
  119. #endif /* ANDROID */
  120. if (client_socket_dir && client_socket_dir[0] &&
  121. access(client_socket_dir, F_OK) < 0) {
  122. perror(client_socket_dir);
  123. os_free(cfile);
  124. return -1;
  125. }
  126. if (cfile == NULL) {
  127. flen = os_strlen(ctrl_iface_dir) + os_strlen(ifname) + 2;
  128. cfile = os_malloc(flen);
  129. if (cfile == NULL)
  130. return -1;
  131. res = os_snprintf(cfile, flen, "%s/%s", ctrl_iface_dir,
  132. ifname);
  133. if (os_snprintf_error(flen, res)) {
  134. os_free(cfile);
  135. return -1;
  136. }
  137. }
  138. ctrl_conn = wpa_ctrl_open2(cfile, client_socket_dir);
  139. if (ctrl_conn == NULL) {
  140. os_free(cfile);
  141. return -1;
  142. }
  143. if (attach && interactive)
  144. mon_conn = wpa_ctrl_open2(cfile, client_socket_dir);
  145. else
  146. mon_conn = NULL;
  147. os_free(cfile);
  148. #endif /* CONFIG_CTRL_IFACE_UDP || CONFIG_CTRL_IFACE_NAMED_PIPE */
  149. if (mon_conn) {
  150. if (wpa_ctrl_attach(mon_conn) == 0) {
  151. wpa_cli_attached = 1;
  152. if (interactive)
  153. eloop_register_read_sock(
  154. wpa_ctrl_get_fd(mon_conn),
  155. wpa_cli_mon_receive, NULL, NULL);
  156. } else {
  157. printf("Warning: Failed to attach to "
  158. "wpa_supplicant.\n");
  159. wpa_cli_close_connection();
  160. return -1;
  161. }
  162. }
  163. return 0;
  164. }
  165. static void wpa_cli_close_connection(void)
  166. {
  167. if (ctrl_conn == NULL)
  168. return;
  169. if (wpa_cli_attached) {
  170. wpa_ctrl_detach(interactive ? mon_conn : ctrl_conn);
  171. wpa_cli_attached = 0;
  172. }
  173. wpa_ctrl_close(ctrl_conn);
  174. ctrl_conn = NULL;
  175. if (mon_conn) {
  176. eloop_unregister_read_sock(wpa_ctrl_get_fd(mon_conn));
  177. wpa_ctrl_close(mon_conn);
  178. mon_conn = NULL;
  179. }
  180. }
  181. static void wpa_cli_msg_cb(char *msg, size_t len)
  182. {
  183. printf("%s\n", msg);
  184. }
  185. static int _wpa_ctrl_command(struct wpa_ctrl *ctrl, const char *cmd, int print)
  186. {
  187. char buf[4096];
  188. size_t len;
  189. int ret;
  190. if (ctrl_conn == NULL) {
  191. printf("Not connected to wpa_supplicant - command dropped.\n");
  192. return -1;
  193. }
  194. if (ifname_prefix) {
  195. os_snprintf(buf, sizeof(buf), "IFNAME=%s %s",
  196. ifname_prefix, cmd);
  197. buf[sizeof(buf) - 1] = '\0';
  198. cmd = buf;
  199. }
  200. len = sizeof(buf) - 1;
  201. ret = wpa_ctrl_request(ctrl, cmd, os_strlen(cmd), buf, &len,
  202. wpa_cli_msg_cb);
  203. if (ret == -2) {
  204. printf("'%s' command timed out.\n", cmd);
  205. return -2;
  206. } else if (ret < 0) {
  207. printf("'%s' command failed.\n", cmd);
  208. return -1;
  209. }
  210. if (print) {
  211. buf[len] = '\0';
  212. printf("%s", buf);
  213. if (interactive && len > 0 && buf[len - 1] != '\n')
  214. printf("\n");
  215. }
  216. return 0;
  217. }
  218. static int wpa_ctrl_command(struct wpa_ctrl *ctrl, const char *cmd)
  219. {
  220. return _wpa_ctrl_command(ctrl, cmd, 1);
  221. }
  222. static int wpa_cli_cmd(struct wpa_ctrl *ctrl, const char *cmd, int min_args,
  223. int argc, char *argv[])
  224. {
  225. char buf[4096];
  226. if (argc < min_args) {
  227. printf("Invalid %s command - at least %d argument%s "
  228. "required.\n", cmd, min_args,
  229. min_args > 1 ? "s are" : " is");
  230. return -1;
  231. }
  232. if (write_cmd(buf, sizeof(buf), cmd, argc, argv) < 0)
  233. return -1;
  234. return wpa_ctrl_command(ctrl, buf);
  235. }
  236. static int wpa_cli_cmd_ifname(struct wpa_ctrl *ctrl, int argc, char *argv[])
  237. {
  238. return wpa_ctrl_command(ctrl, "IFNAME");
  239. }
  240. static int wpa_cli_cmd_status(struct wpa_ctrl *ctrl, int argc, char *argv[])
  241. {
  242. if (argc > 0 && os_strcmp(argv[0], "verbose") == 0)
  243. return wpa_ctrl_command(ctrl, "STATUS-VERBOSE");
  244. if (argc > 0 && os_strcmp(argv[0], "wps") == 0)
  245. return wpa_ctrl_command(ctrl, "STATUS-WPS");
  246. if (argc > 0 && os_strcmp(argv[0], "driver") == 0)
  247. return wpa_ctrl_command(ctrl, "STATUS-DRIVER");
  248. #ifdef ANDROID
  249. if (argc > 0 && os_strcmp(argv[0], "no_events") == 0)
  250. return wpa_ctrl_command(ctrl, "STATUS-NO_EVENTS");
  251. #endif /* ANDROID */
  252. return wpa_ctrl_command(ctrl, "STATUS");
  253. }
  254. static int wpa_cli_cmd_ping(struct wpa_ctrl *ctrl, int argc, char *argv[])
  255. {
  256. return wpa_ctrl_command(ctrl, "PING");
  257. }
  258. static int wpa_cli_cmd_relog(struct wpa_ctrl *ctrl, int argc, char *argv[])
  259. {
  260. return wpa_ctrl_command(ctrl, "RELOG");
  261. }
  262. static int wpa_cli_cmd_note(struct wpa_ctrl *ctrl, int argc, char *argv[])
  263. {
  264. return wpa_cli_cmd(ctrl, "NOTE", 1, argc, argv);
  265. }
  266. static int wpa_cli_cmd_mib(struct wpa_ctrl *ctrl, int argc, char *argv[])
  267. {
  268. return wpa_ctrl_command(ctrl, "MIB");
  269. }
  270. static int wpa_cli_cmd_pmksa(struct wpa_ctrl *ctrl, int argc, char *argv[])
  271. {
  272. return wpa_ctrl_command(ctrl, "PMKSA");
  273. }
  274. static int wpa_cli_cmd_pmksa_flush(struct wpa_ctrl *ctrl, int argc,
  275. char *argv[])
  276. {
  277. return wpa_ctrl_command(ctrl, "PMKSA_FLUSH");
  278. }
  279. #ifdef CONFIG_PMKSA_CACHE_EXTERNAL
  280. static int wpa_cli_cmd_pmksa_get(struct wpa_ctrl *ctrl, int argc, char *argv[])
  281. {
  282. return wpa_cli_cmd(ctrl, "PMKSA_GET", 1, argc, argv);
  283. }
  284. static int wpa_cli_cmd_pmksa_add(struct wpa_ctrl *ctrl, int argc, char *argv[])
  285. {
  286. return wpa_cli_cmd(ctrl, "PMKSA_ADD", 8, argc, argv);
  287. }
  288. #ifdef CONFIG_MESH
  289. static int wpa_cli_mesh_cmd_pmksa_get(struct wpa_ctrl *ctrl, int argc,
  290. char *argv[])
  291. {
  292. return wpa_cli_cmd(ctrl, "MESH_PMKSA_GET", 1, argc, argv);
  293. }
  294. static int wpa_cli_mesh_cmd_pmksa_add(struct wpa_ctrl *ctrl, int argc,
  295. char *argv[])
  296. {
  297. return wpa_cli_cmd(ctrl, "MESH_PMKSA_ADD", 4, argc, argv);
  298. }
  299. #endif /* CONFIG_MESH */
  300. #endif /* CONFIG_PMKSA_CACHE_EXTERNAL */
  301. static int wpa_cli_cmd_help(struct wpa_ctrl *ctrl, int argc, char *argv[])
  302. {
  303. print_help(argc > 0 ? argv[0] : NULL);
  304. return 0;
  305. }
  306. static char ** wpa_cli_complete_help(const char *str, int pos)
  307. {
  308. int arg = get_cmd_arg_num(str, pos);
  309. char **res = NULL;
  310. switch (arg) {
  311. case 1:
  312. res = wpa_list_cmd_list();
  313. break;
  314. }
  315. return res;
  316. }
  317. static int wpa_cli_cmd_license(struct wpa_ctrl *ctrl, int argc, char *argv[])
  318. {
  319. printf("%s\n\n%s\n", wpa_cli_version, cli_full_license);
  320. return 0;
  321. }
  322. static int wpa_cli_cmd_quit(struct wpa_ctrl *ctrl, int argc, char *argv[])
  323. {
  324. wpa_cli_quit = 1;
  325. if (interactive)
  326. eloop_terminate();
  327. return 0;
  328. }
  329. static int wpa_cli_cmd_set(struct wpa_ctrl *ctrl, int argc, char *argv[])
  330. {
  331. char cmd[256];
  332. int res;
  333. if (argc == 1) {
  334. res = os_snprintf(cmd, sizeof(cmd), "SET %s ", argv[0]);
  335. if (os_snprintf_error(sizeof(cmd), res)) {
  336. printf("Too long SET command.\n");
  337. return -1;
  338. }
  339. return wpa_ctrl_command(ctrl, cmd);
  340. }
  341. return wpa_cli_cmd(ctrl, "SET", 2, argc, argv);
  342. }
  343. static char ** wpa_cli_complete_set(const char *str, int pos)
  344. {
  345. int arg = get_cmd_arg_num(str, pos);
  346. const char *fields[] = {
  347. /* runtime values */
  348. "EAPOL::heldPeriod", "EAPOL::authPeriod", "EAPOL::startPeriod",
  349. "EAPOL::maxStart", "dot11RSNAConfigPMKLifetime",
  350. "dot11RSNAConfigPMKReauthThreshold", "dot11RSNAConfigSATimeout",
  351. "wps_fragment_size", "wps_version_number", "ampdu",
  352. "tdls_testing", "tdls_disabled", "pno", "radio_disabled",
  353. "uapsd", "ps", "wifi_display", "bssid_filter", "disallow_aps",
  354. "no_keep_alive",
  355. /* global configuration parameters */
  356. #ifdef CONFIG_CTRL_IFACE
  357. "ctrl_interface", "no_ctrl_interface", "ctrl_interface_group",
  358. #endif /* CONFIG_CTRL_IFACE */
  359. "eapol_version", "ap_scan", "bgscan",
  360. #ifdef CONFIG_MESH
  361. "user_mpm", "max_peer_links", "mesh_max_inactivity",
  362. "dot11RSNASAERetransPeriod",
  363. #endif /* CONFIG_MESH */
  364. "disable_scan_offload", "fast_reauth", "opensc_engine_path",
  365. "pkcs11_engine_path", "pkcs11_module_path", "openssl_ciphers",
  366. "pcsc_reader", "pcsc_pin", "external_sim", "driver_param",
  367. "dot11RSNAConfigPMKLifetime",
  368. "dot11RSNAConfigPMKReauthThreshold",
  369. "dot11RSNAConfigSATimeout",
  370. #ifndef CONFIG_NO_CONFIG_WRITE
  371. "update_config",
  372. #endif /* CONFIG_NO_CONFIG_WRITE */
  373. "load_dynamic_eap",
  374. #ifdef CONFIG_WPS
  375. "uuid", "device_name", "manufacturer", "model_name",
  376. "model_number", "serial_number", "device_type", "os_version",
  377. "config_methods", "wps_cred_processing", "wps_vendor_ext_m1",
  378. #endif /* CONFIG_WPS */
  379. #ifdef CONFIG_P2P
  380. "sec_device_type",
  381. "p2p_listen_reg_class", "p2p_listen_channel",
  382. "p2p_oper_reg_class", "p2p_oper_channel", "p2p_go_intent",
  383. "p2p_ssid_postfix", "persistent_reconnect", "p2p_intra_bss",
  384. "p2p_group_idle", "p2p_passphrase_len", "p2p_pref_chan",
  385. "p2p_no_go_freq", "p2p_add_cli_chan",
  386. "p2p_optimize_listen_chan", "p2p_go_ht40", "p2p_go_vht",
  387. "p2p_disabled", "p2p_go_ctwindow", "p2p_no_group_iface",
  388. "p2p_ignore_shared_freq", "ip_addr_go", "ip_addr_mask",
  389. "ip_addr_start", "ip_addr_end",
  390. #endif /* CONFIG_P2P */
  391. "country", "bss_max_count", "bss_expiration_age",
  392. "bss_expiration_scan_count", "filter_ssids", "filter_rssi",
  393. "max_num_sta", "disassoc_low_ack",
  394. #ifdef CONFIG_HS20
  395. "hs20",
  396. #endif /* CONFIG_HS20 */
  397. "interworking", "hessid", "access_network_type", "pbc_in_m1",
  398. "go_interworking", "go_access_network_type", "go_internet",
  399. "go_venue_group", "go_venue_type",
  400. "autoscan", "wps_nfc_dev_pw_id", "wps_nfc_dh_pubkey",
  401. "wps_nfc_dh_privkey", "wps_nfc_dev_pw", "ext_password_backend",
  402. "p2p_go_max_inactivity", "auto_interworking", "okc", "pmf",
  403. "sae_groups", "dtim_period", "beacon_int",
  404. "ap_vendor_elements", "ignore_old_scan_res", "freq_list",
  405. "scan_cur_freq", "sched_scan_interval",
  406. "tdls_external_control", "osu_dir", "wowlan_triggers",
  407. "p2p_search_delay", "mac_addr", "rand_addr_lifetime",
  408. "preassoc_mac_addr", "key_mgmt_offload", "passive_scan",
  409. "reassoc_same_bss_optim", "wps_priority",
  410. #ifdef CONFIG_TESTING_OPTIONS
  411. "ignore_auth_resp",
  412. #endif /* CONFIG_TESTING_OPTIONS */
  413. "relative_rssi", "relative_band_adjust",
  414. };
  415. int i, num_fields = ARRAY_SIZE(fields);
  416. if (arg == 1) {
  417. char **res = os_calloc(num_fields + 1, sizeof(char *));
  418. if (res == NULL)
  419. return NULL;
  420. for (i = 0; i < num_fields; i++) {
  421. res[i] = os_strdup(fields[i]);
  422. if (res[i] == NULL)
  423. return res;
  424. }
  425. return res;
  426. }
  427. if (arg > 1 && os_strncasecmp(str, "set bssid_filter ", 17) == 0)
  428. return cli_txt_list_array(&bsses);
  429. return NULL;
  430. }
  431. static int wpa_cli_cmd_dump(struct wpa_ctrl *ctrl, int argc, char *argv[])
  432. {
  433. return wpa_ctrl_command(ctrl, "DUMP");
  434. }
  435. static int wpa_cli_cmd_driver_flags(struct wpa_ctrl *ctrl, int argc,
  436. char *argv[])
  437. {
  438. return wpa_ctrl_command(ctrl, "DRIVER_FLAGS");
  439. }
  440. static int wpa_cli_cmd_get(struct wpa_ctrl *ctrl, int argc, char *argv[])
  441. {
  442. return wpa_cli_cmd(ctrl, "GET", 1, argc, argv);
  443. }
  444. static char ** wpa_cli_complete_get(const char *str, int pos)
  445. {
  446. int arg = get_cmd_arg_num(str, pos);
  447. const char *fields[] = {
  448. #ifdef CONFIG_CTRL_IFACE
  449. "ctrl_interface", "ctrl_interface_group",
  450. #endif /* CONFIG_CTRL_IFACE */
  451. "eapol_version", "ap_scan",
  452. #ifdef CONFIG_MESH
  453. "user_mpm", "max_peer_links", "mesh_max_inactivity",
  454. #endif /* CONFIG_MESH */
  455. "disable_scan_offload", "fast_reauth", "opensc_engine_path",
  456. "pkcs11_engine_path", "pkcs11_module_path", "openssl_ciphers",
  457. "pcsc_reader", "pcsc_pin", "external_sim", "driver_param",
  458. "dot11RSNAConfigPMKLifetime",
  459. "dot11RSNAConfigPMKReauthThreshold",
  460. "dot11RSNAConfigSATimeout",
  461. #ifndef CONFIG_NO_CONFIG_WRITE
  462. "update_config",
  463. #endif /* CONFIG_NO_CONFIG_WRITE */
  464. #ifdef CONFIG_WPS
  465. "device_name", "manufacturer", "model_name", "model_number",
  466. "serial_number", "config_methods", "wps_cred_processing",
  467. #endif /* CONFIG_WPS */
  468. #ifdef CONFIG_P2P
  469. "p2p_listen_reg_class", "p2p_listen_channel",
  470. "p2p_oper_reg_class", "p2p_oper_channel", "p2p_go_intent",
  471. "p2p_ssid_postfix", "persistent_reconnect", "p2p_intra_bss",
  472. "p2p_group_idle", "p2p_passphrase_len", "p2p_add_cli_chan",
  473. "p2p_optimize_listen_chan", "p2p_go_ht40", "p2p_go_vht",
  474. "p2p_disabled", "p2p_go_ctwindow", "p2p_no_group_iface",
  475. "p2p_ignore_shared_freq", "ip_addr_go", "ip_addr_mask",
  476. "ip_addr_start", "ip_addr_end",
  477. #endif /* CONFIG_P2P */
  478. "bss_max_count", "bss_expiration_age",
  479. "bss_expiration_scan_count", "filter_ssids", "filter_rssi",
  480. "max_num_sta", "disassoc_low_ack",
  481. #ifdef CONFIG_HS20
  482. "hs20",
  483. #endif /* CONFIG_HS20 */
  484. "interworking", "access_network_type", "pbc_in_m1", "autoscan",
  485. "go_interworking", "go_access_network_type", "go_internet",
  486. "go_venue_group", "go_venue_type",
  487. "wps_nfc_dev_pw_id", "ext_password_backend",
  488. "p2p_go_max_inactivity", "auto_interworking", "okc", "pmf",
  489. "dtim_period", "beacon_int", "ignore_old_scan_res",
  490. "scan_cur_freq", "sched_scan_interval",
  491. "sched_scan_start_delay",
  492. "tdls_external_control", "osu_dir", "wowlan_triggers",
  493. "p2p_search_delay", "mac_addr", "rand_addr_lifetime",
  494. "preassoc_mac_addr", "key_mgmt_offload", "passive_scan",
  495. "reassoc_same_bss_optim"
  496. };
  497. int i, num_fields = ARRAY_SIZE(fields);
  498. if (arg == 1) {
  499. char **res = os_calloc(num_fields + 1, sizeof(char *));
  500. if (res == NULL)
  501. return NULL;
  502. for (i = 0; i < num_fields; i++) {
  503. res[i] = os_strdup(fields[i]);
  504. if (res[i] == NULL)
  505. return res;
  506. }
  507. return res;
  508. }
  509. return NULL;
  510. }
  511. static int wpa_cli_cmd_logoff(struct wpa_ctrl *ctrl, int argc, char *argv[])
  512. {
  513. return wpa_ctrl_command(ctrl, "LOGOFF");
  514. }
  515. static int wpa_cli_cmd_logon(struct wpa_ctrl *ctrl, int argc, char *argv[])
  516. {
  517. return wpa_ctrl_command(ctrl, "LOGON");
  518. }
  519. static int wpa_cli_cmd_reassociate(struct wpa_ctrl *ctrl, int argc,
  520. char *argv[])
  521. {
  522. return wpa_ctrl_command(ctrl, "REASSOCIATE");
  523. }
  524. static int wpa_cli_cmd_reattach(struct wpa_ctrl *ctrl, int argc, char *argv[])
  525. {
  526. return wpa_ctrl_command(ctrl, "REATTACH");
  527. }
  528. static int wpa_cli_cmd_preauthenticate(struct wpa_ctrl *ctrl, int argc,
  529. char *argv[])
  530. {
  531. return wpa_cli_cmd(ctrl, "PREAUTH", 1, argc, argv);
  532. }
  533. static int wpa_cli_cmd_ap_scan(struct wpa_ctrl *ctrl, int argc, char *argv[])
  534. {
  535. return wpa_cli_cmd(ctrl, "AP_SCAN", 1, argc, argv);
  536. }
  537. static int wpa_cli_cmd_scan_interval(struct wpa_ctrl *ctrl, int argc,
  538. char *argv[])
  539. {
  540. return wpa_cli_cmd(ctrl, "SCAN_INTERVAL", 1, argc, argv);
  541. }
  542. static int wpa_cli_cmd_bss_expire_age(struct wpa_ctrl *ctrl, int argc,
  543. char *argv[])
  544. {
  545. return wpa_cli_cmd(ctrl, "BSS_EXPIRE_AGE", 1, argc, argv);
  546. }
  547. static int wpa_cli_cmd_bss_expire_count(struct wpa_ctrl *ctrl, int argc,
  548. char *argv[])
  549. {
  550. return wpa_cli_cmd(ctrl, "BSS_EXPIRE_COUNT", 1, argc, argv);
  551. }
  552. static int wpa_cli_cmd_bss_flush(struct wpa_ctrl *ctrl, int argc, char *argv[])
  553. {
  554. char cmd[256];
  555. int res;
  556. if (argc < 1)
  557. res = os_snprintf(cmd, sizeof(cmd), "BSS_FLUSH 0");
  558. else
  559. res = os_snprintf(cmd, sizeof(cmd), "BSS_FLUSH %s", argv[0]);
  560. if (os_snprintf_error(sizeof(cmd), res)) {
  561. printf("Too long BSS_FLUSH command.\n");
  562. return -1;
  563. }
  564. return wpa_ctrl_command(ctrl, cmd);
  565. }
  566. static int wpa_cli_cmd_ft_ds(struct wpa_ctrl *ctrl, int argc, char *argv[])
  567. {
  568. return wpa_cli_cmd(ctrl, "FT_DS", 1, argc, argv);
  569. }
  570. static int wpa_cli_cmd_wps_pbc(struct wpa_ctrl *ctrl, int argc, char *argv[])
  571. {
  572. return wpa_cli_cmd(ctrl, "WPS_PBC", 0, argc, argv);
  573. }
  574. static int wpa_cli_cmd_wps_pin(struct wpa_ctrl *ctrl, int argc, char *argv[])
  575. {
  576. if (argc == 0) {
  577. printf("Invalid WPS_PIN command: need one or two arguments:\n"
  578. "- BSSID: use 'any' to select any\n"
  579. "- PIN: optional, used only with devices that have no "
  580. "display\n");
  581. return -1;
  582. }
  583. return wpa_cli_cmd(ctrl, "WPS_PIN", 1, argc, argv);
  584. }
  585. static int wpa_cli_cmd_wps_check_pin(struct wpa_ctrl *ctrl, int argc,
  586. char *argv[])
  587. {
  588. return wpa_cli_cmd(ctrl, "WPS_CHECK_PIN", 1, argc, argv);
  589. }
  590. static int wpa_cli_cmd_wps_cancel(struct wpa_ctrl *ctrl, int argc,
  591. char *argv[])
  592. {
  593. return wpa_ctrl_command(ctrl, "WPS_CANCEL");
  594. }
  595. #ifdef CONFIG_WPS_NFC
  596. static int wpa_cli_cmd_wps_nfc(struct wpa_ctrl *ctrl, int argc, char *argv[])
  597. {
  598. return wpa_cli_cmd(ctrl, "WPS_NFC", 0, argc, argv);
  599. }
  600. static int wpa_cli_cmd_wps_nfc_config_token(struct wpa_ctrl *ctrl, int argc,
  601. char *argv[])
  602. {
  603. return wpa_cli_cmd(ctrl, "WPS_NFC_CONFIG_TOKEN", 1, argc, argv);
  604. }
  605. static int wpa_cli_cmd_wps_nfc_token(struct wpa_ctrl *ctrl, int argc,
  606. char *argv[])
  607. {
  608. return wpa_cli_cmd(ctrl, "WPS_NFC_TOKEN", 1, argc, argv);
  609. }
  610. static int wpa_cli_cmd_wps_nfc_tag_read(struct wpa_ctrl *ctrl, int argc,
  611. char *argv[])
  612. {
  613. int ret;
  614. char *buf;
  615. size_t buflen;
  616. if (argc != 1) {
  617. printf("Invalid 'wps_nfc_tag_read' command - one argument "
  618. "is required.\n");
  619. return -1;
  620. }
  621. buflen = 18 + os_strlen(argv[0]);
  622. buf = os_malloc(buflen);
  623. if (buf == NULL)
  624. return -1;
  625. os_snprintf(buf, buflen, "WPS_NFC_TAG_READ %s", argv[0]);
  626. ret = wpa_ctrl_command(ctrl, buf);
  627. os_free(buf);
  628. return ret;
  629. }
  630. static int wpa_cli_cmd_nfc_get_handover_req(struct wpa_ctrl *ctrl, int argc,
  631. char *argv[])
  632. {
  633. return wpa_cli_cmd(ctrl, "NFC_GET_HANDOVER_REQ", 2, argc, argv);
  634. }
  635. static int wpa_cli_cmd_nfc_get_handover_sel(struct wpa_ctrl *ctrl, int argc,
  636. char *argv[])
  637. {
  638. return wpa_cli_cmd(ctrl, "NFC_GET_HANDOVER_SEL", 2, argc, argv);
  639. }
  640. static int wpa_cli_cmd_nfc_report_handover(struct wpa_ctrl *ctrl, int argc,
  641. char *argv[])
  642. {
  643. return wpa_cli_cmd(ctrl, "NFC_REPORT_HANDOVER", 4, argc, argv);
  644. }
  645. #endif /* CONFIG_WPS_NFC */
  646. static int wpa_cli_cmd_wps_reg(struct wpa_ctrl *ctrl, int argc, char *argv[])
  647. {
  648. char cmd[256];
  649. int res;
  650. if (argc == 2)
  651. res = os_snprintf(cmd, sizeof(cmd), "WPS_REG %s %s",
  652. argv[0], argv[1]);
  653. else if (argc == 5 || argc == 6) {
  654. char ssid_hex[2 * SSID_MAX_LEN + 1];
  655. char key_hex[2 * 64 + 1];
  656. int i;
  657. ssid_hex[0] = '\0';
  658. for (i = 0; i < SSID_MAX_LEN; i++) {
  659. if (argv[2][i] == '\0')
  660. break;
  661. os_snprintf(&ssid_hex[i * 2], 3, "%02x", argv[2][i]);
  662. }
  663. key_hex[0] = '\0';
  664. if (argc == 6) {
  665. for (i = 0; i < 64; i++) {
  666. if (argv[5][i] == '\0')
  667. break;
  668. os_snprintf(&key_hex[i * 2], 3, "%02x",
  669. argv[5][i]);
  670. }
  671. }
  672. res = os_snprintf(cmd, sizeof(cmd),
  673. "WPS_REG %s %s %s %s %s %s",
  674. argv[0], argv[1], ssid_hex, argv[3], argv[4],
  675. key_hex);
  676. } else {
  677. printf("Invalid WPS_REG command: need two arguments:\n"
  678. "- BSSID of the target AP\n"
  679. "- AP PIN\n");
  680. printf("Alternatively, six arguments can be used to "
  681. "reconfigure the AP:\n"
  682. "- BSSID of the target AP\n"
  683. "- AP PIN\n"
  684. "- new SSID\n"
  685. "- new auth (OPEN, WPAPSK, WPA2PSK)\n"
  686. "- new encr (NONE, WEP, TKIP, CCMP)\n"
  687. "- new key\n");
  688. return -1;
  689. }
  690. if (os_snprintf_error(sizeof(cmd), res)) {
  691. printf("Too long WPS_REG command.\n");
  692. return -1;
  693. }
  694. return wpa_ctrl_command(ctrl, cmd);
  695. }
  696. static int wpa_cli_cmd_wps_ap_pin(struct wpa_ctrl *ctrl, int argc,
  697. char *argv[])
  698. {
  699. return wpa_cli_cmd(ctrl, "WPS_AP_PIN", 1, argc, argv);
  700. }
  701. static int wpa_cli_cmd_wps_er_start(struct wpa_ctrl *ctrl, int argc,
  702. char *argv[])
  703. {
  704. return wpa_cli_cmd(ctrl, "WPS_ER_START", 0, argc, argv);
  705. }
  706. static int wpa_cli_cmd_wps_er_stop(struct wpa_ctrl *ctrl, int argc,
  707. char *argv[])
  708. {
  709. return wpa_ctrl_command(ctrl, "WPS_ER_STOP");
  710. }
  711. static int wpa_cli_cmd_wps_er_pin(struct wpa_ctrl *ctrl, int argc,
  712. char *argv[])
  713. {
  714. if (argc < 2) {
  715. printf("Invalid WPS_ER_PIN command: need at least two "
  716. "arguments:\n"
  717. "- UUID: use 'any' to select any\n"
  718. "- PIN: Enrollee PIN\n"
  719. "optional: - Enrollee MAC address\n");
  720. return -1;
  721. }
  722. return wpa_cli_cmd(ctrl, "WPS_ER_PIN", 2, argc, argv);
  723. }
  724. static int wpa_cli_cmd_wps_er_pbc(struct wpa_ctrl *ctrl, int argc,
  725. char *argv[])
  726. {
  727. return wpa_cli_cmd(ctrl, "WPS_ER_PBC", 1, argc, argv);
  728. }
  729. static int wpa_cli_cmd_wps_er_learn(struct wpa_ctrl *ctrl, int argc,
  730. char *argv[])
  731. {
  732. if (argc != 2) {
  733. printf("Invalid WPS_ER_LEARN command: need two arguments:\n"
  734. "- UUID: specify which AP to use\n"
  735. "- PIN: AP PIN\n");
  736. return -1;
  737. }
  738. return wpa_cli_cmd(ctrl, "WPS_ER_LEARN", 2, argc, argv);
  739. }
  740. static int wpa_cli_cmd_wps_er_set_config(struct wpa_ctrl *ctrl, int argc,
  741. char *argv[])
  742. {
  743. if (argc != 2) {
  744. printf("Invalid WPS_ER_SET_CONFIG command: need two "
  745. "arguments:\n"
  746. "- UUID: specify which AP to use\n"
  747. "- Network configuration id\n");
  748. return -1;
  749. }
  750. return wpa_cli_cmd(ctrl, "WPS_ER_SET_CONFIG", 2, argc, argv);
  751. }
  752. static int wpa_cli_cmd_wps_er_config(struct wpa_ctrl *ctrl, int argc,
  753. char *argv[])
  754. {
  755. char cmd[256];
  756. int res;
  757. if (argc == 5 || argc == 6) {
  758. char ssid_hex[2 * SSID_MAX_LEN + 1];
  759. char key_hex[2 * 64 + 1];
  760. int i;
  761. ssid_hex[0] = '\0';
  762. for (i = 0; i < SSID_MAX_LEN; i++) {
  763. if (argv[2][i] == '\0')
  764. break;
  765. os_snprintf(&ssid_hex[i * 2], 3, "%02x", argv[2][i]);
  766. }
  767. key_hex[0] = '\0';
  768. if (argc == 6) {
  769. for (i = 0; i < 64; i++) {
  770. if (argv[5][i] == '\0')
  771. break;
  772. os_snprintf(&key_hex[i * 2], 3, "%02x",
  773. argv[5][i]);
  774. }
  775. }
  776. res = os_snprintf(cmd, sizeof(cmd),
  777. "WPS_ER_CONFIG %s %s %s %s %s %s",
  778. argv[0], argv[1], ssid_hex, argv[3], argv[4],
  779. key_hex);
  780. } else {
  781. printf("Invalid WPS_ER_CONFIG command: need six arguments:\n"
  782. "- AP UUID\n"
  783. "- AP PIN\n"
  784. "- new SSID\n"
  785. "- new auth (OPEN, WPAPSK, WPA2PSK)\n"
  786. "- new encr (NONE, WEP, TKIP, CCMP)\n"
  787. "- new key\n");
  788. return -1;
  789. }
  790. if (os_snprintf_error(sizeof(cmd), res)) {
  791. printf("Too long WPS_ER_CONFIG command.\n");
  792. return -1;
  793. }
  794. return wpa_ctrl_command(ctrl, cmd);
  795. }
  796. #ifdef CONFIG_WPS_NFC
  797. static int wpa_cli_cmd_wps_er_nfc_config_token(struct wpa_ctrl *ctrl, int argc,
  798. char *argv[])
  799. {
  800. if (argc != 2) {
  801. printf("Invalid WPS_ER_NFC_CONFIG_TOKEN command: need two "
  802. "arguments:\n"
  803. "- WPS/NDEF: token format\n"
  804. "- UUID: specify which AP to use\n");
  805. return -1;
  806. }
  807. return wpa_cli_cmd(ctrl, "WPS_ER_NFC_CONFIG_TOKEN", 2, argc, argv);
  808. }
  809. #endif /* CONFIG_WPS_NFC */
  810. static int wpa_cli_cmd_ibss_rsn(struct wpa_ctrl *ctrl, int argc, char *argv[])
  811. {
  812. return wpa_cli_cmd(ctrl, "IBSS_RSN", 1, argc, argv);
  813. }
  814. static int wpa_cli_cmd_level(struct wpa_ctrl *ctrl, int argc, char *argv[])
  815. {
  816. return wpa_cli_cmd(ctrl, "LEVEL", 1, argc, argv);
  817. }
  818. static int wpa_cli_cmd_identity(struct wpa_ctrl *ctrl, int argc, char *argv[])
  819. {
  820. char cmd[256], *pos, *end;
  821. int i, ret;
  822. if (argc < 2) {
  823. printf("Invalid IDENTITY command: needs two arguments "
  824. "(network id and identity)\n");
  825. return -1;
  826. }
  827. end = cmd + sizeof(cmd);
  828. pos = cmd;
  829. ret = os_snprintf(pos, end - pos, WPA_CTRL_RSP "IDENTITY-%s:%s",
  830. argv[0], argv[1]);
  831. if (os_snprintf_error(end - pos, ret)) {
  832. printf("Too long IDENTITY command.\n");
  833. return -1;
  834. }
  835. pos += ret;
  836. for (i = 2; i < argc; i++) {
  837. ret = os_snprintf(pos, end - pos, " %s", argv[i]);
  838. if (os_snprintf_error(end - pos, ret)) {
  839. printf("Too long IDENTITY command.\n");
  840. return -1;
  841. }
  842. pos += ret;
  843. }
  844. return wpa_ctrl_command(ctrl, cmd);
  845. }
  846. static int wpa_cli_cmd_password(struct wpa_ctrl *ctrl, int argc, char *argv[])
  847. {
  848. char cmd[256], *pos, *end;
  849. int i, ret;
  850. if (argc < 2) {
  851. printf("Invalid PASSWORD command: needs two arguments "
  852. "(network id and password)\n");
  853. return -1;
  854. }
  855. end = cmd + sizeof(cmd);
  856. pos = cmd;
  857. ret = os_snprintf(pos, end - pos, WPA_CTRL_RSP "PASSWORD-%s:%s",
  858. argv[0], argv[1]);
  859. if (os_snprintf_error(end - pos, ret)) {
  860. printf("Too long PASSWORD command.\n");
  861. return -1;
  862. }
  863. pos += ret;
  864. for (i = 2; i < argc; i++) {
  865. ret = os_snprintf(pos, end - pos, " %s", argv[i]);
  866. if (os_snprintf_error(end - pos, ret)) {
  867. printf("Too long PASSWORD command.\n");
  868. return -1;
  869. }
  870. pos += ret;
  871. }
  872. return wpa_ctrl_command(ctrl, cmd);
  873. }
  874. static int wpa_cli_cmd_new_password(struct wpa_ctrl *ctrl, int argc,
  875. char *argv[])
  876. {
  877. char cmd[256], *pos, *end;
  878. int i, ret;
  879. if (argc < 2) {
  880. printf("Invalid NEW_PASSWORD command: needs two arguments "
  881. "(network id and password)\n");
  882. return -1;
  883. }
  884. end = cmd + sizeof(cmd);
  885. pos = cmd;
  886. ret = os_snprintf(pos, end - pos, WPA_CTRL_RSP "NEW_PASSWORD-%s:%s",
  887. argv[0], argv[1]);
  888. if (os_snprintf_error(end - pos, ret)) {
  889. printf("Too long NEW_PASSWORD command.\n");
  890. return -1;
  891. }
  892. pos += ret;
  893. for (i = 2; i < argc; i++) {
  894. ret = os_snprintf(pos, end - pos, " %s", argv[i]);
  895. if (os_snprintf_error(end - pos, ret)) {
  896. printf("Too long NEW_PASSWORD command.\n");
  897. return -1;
  898. }
  899. pos += ret;
  900. }
  901. return wpa_ctrl_command(ctrl, cmd);
  902. }
  903. static int wpa_cli_cmd_pin(struct wpa_ctrl *ctrl, int argc, char *argv[])
  904. {
  905. char cmd[256], *pos, *end;
  906. int i, ret;
  907. if (argc < 2) {
  908. printf("Invalid PIN command: needs two arguments "
  909. "(network id and pin)\n");
  910. return -1;
  911. }
  912. end = cmd + sizeof(cmd);
  913. pos = cmd;
  914. ret = os_snprintf(pos, end - pos, WPA_CTRL_RSP "PIN-%s:%s",
  915. argv[0], argv[1]);
  916. if (os_snprintf_error(end - pos, ret)) {
  917. printf("Too long PIN command.\n");
  918. return -1;
  919. }
  920. pos += ret;
  921. for (i = 2; i < argc; i++) {
  922. ret = os_snprintf(pos, end - pos, " %s", argv[i]);
  923. if (os_snprintf_error(end - pos, ret)) {
  924. printf("Too long PIN command.\n");
  925. return -1;
  926. }
  927. pos += ret;
  928. }
  929. return wpa_ctrl_command(ctrl, cmd);
  930. }
  931. static int wpa_cli_cmd_otp(struct wpa_ctrl *ctrl, int argc, char *argv[])
  932. {
  933. char cmd[256], *pos, *end;
  934. int i, ret;
  935. if (argc < 2) {
  936. printf("Invalid OTP command: needs two arguments (network "
  937. "id and password)\n");
  938. return -1;
  939. }
  940. end = cmd + sizeof(cmd);
  941. pos = cmd;
  942. ret = os_snprintf(pos, end - pos, WPA_CTRL_RSP "OTP-%s:%s",
  943. argv[0], argv[1]);
  944. if (os_snprintf_error(end - pos, ret)) {
  945. printf("Too long OTP command.\n");
  946. return -1;
  947. }
  948. pos += ret;
  949. for (i = 2; i < argc; i++) {
  950. ret = os_snprintf(pos, end - pos, " %s", argv[i]);
  951. if (os_snprintf_error(end - pos, ret)) {
  952. printf("Too long OTP command.\n");
  953. return -1;
  954. }
  955. pos += ret;
  956. }
  957. return wpa_ctrl_command(ctrl, cmd);
  958. }
  959. static int wpa_cli_cmd_sim(struct wpa_ctrl *ctrl, int argc, char *argv[])
  960. {
  961. char cmd[256], *pos, *end;
  962. int i, ret;
  963. if (argc < 2) {
  964. printf("Invalid SIM command: needs two arguments "
  965. "(network id and SIM operation response)\n");
  966. return -1;
  967. }
  968. end = cmd + sizeof(cmd);
  969. pos = cmd;
  970. ret = os_snprintf(pos, end - pos, WPA_CTRL_RSP "SIM-%s:%s",
  971. argv[0], argv[1]);
  972. if (os_snprintf_error(end - pos, ret)) {
  973. printf("Too long SIM command.\n");
  974. return -1;
  975. }
  976. pos += ret;
  977. for (i = 2; i < argc; i++) {
  978. ret = os_snprintf(pos, end - pos, " %s", argv[i]);
  979. if (os_snprintf_error(end - pos, ret)) {
  980. printf("Too long SIM command.\n");
  981. return -1;
  982. }
  983. pos += ret;
  984. }
  985. return wpa_ctrl_command(ctrl, cmd);
  986. }
  987. static int wpa_cli_cmd_passphrase(struct wpa_ctrl *ctrl, int argc,
  988. char *argv[])
  989. {
  990. char cmd[256], *pos, *end;
  991. int i, ret;
  992. if (argc < 2) {
  993. printf("Invalid PASSPHRASE command: needs two arguments "
  994. "(network id and passphrase)\n");
  995. return -1;
  996. }
  997. end = cmd + sizeof(cmd);
  998. pos = cmd;
  999. ret = os_snprintf(pos, end - pos, WPA_CTRL_RSP "PASSPHRASE-%s:%s",
  1000. argv[0], argv[1]);
  1001. if (os_snprintf_error(end - pos, ret)) {
  1002. printf("Too long PASSPHRASE command.\n");
  1003. return -1;
  1004. }
  1005. pos += ret;
  1006. for (i = 2; i < argc; i++) {
  1007. ret = os_snprintf(pos, end - pos, " %s", argv[i]);
  1008. if (os_snprintf_error(end - pos, ret)) {
  1009. printf("Too long PASSPHRASE command.\n");
  1010. return -1;
  1011. }
  1012. pos += ret;
  1013. }
  1014. return wpa_ctrl_command(ctrl, cmd);
  1015. }
  1016. static int wpa_cli_cmd_bssid(struct wpa_ctrl *ctrl, int argc, char *argv[])
  1017. {
  1018. if (argc < 2) {
  1019. printf("Invalid BSSID command: needs two arguments (network "
  1020. "id and BSSID)\n");
  1021. return -1;
  1022. }
  1023. return wpa_cli_cmd(ctrl, "BSSID", 2, argc, argv);
  1024. }
  1025. static int wpa_cli_cmd_blacklist(struct wpa_ctrl *ctrl, int argc, char *argv[])
  1026. {
  1027. return wpa_cli_cmd(ctrl, "BLACKLIST", 0, argc, argv);
  1028. }
  1029. static int wpa_cli_cmd_log_level(struct wpa_ctrl *ctrl, int argc, char *argv[])
  1030. {
  1031. return wpa_cli_cmd(ctrl, "LOG_LEVEL", 0, argc, argv);
  1032. }
  1033. static int wpa_cli_cmd_list_networks(struct wpa_ctrl *ctrl, int argc,
  1034. char *argv[])
  1035. {
  1036. return wpa_ctrl_command(ctrl, "LIST_NETWORKS");
  1037. }
  1038. static int wpa_cli_cmd_select_network(struct wpa_ctrl *ctrl, int argc,
  1039. char *argv[])
  1040. {
  1041. return wpa_cli_cmd(ctrl, "SELECT_NETWORK", 1, argc, argv);
  1042. }
  1043. static int wpa_cli_cmd_enable_network(struct wpa_ctrl *ctrl, int argc,
  1044. char *argv[])
  1045. {
  1046. return wpa_cli_cmd(ctrl, "ENABLE_NETWORK", 1, argc, argv);
  1047. }
  1048. static int wpa_cli_cmd_disable_network(struct wpa_ctrl *ctrl, int argc,
  1049. char *argv[])
  1050. {
  1051. return wpa_cli_cmd(ctrl, "DISABLE_NETWORK", 1, argc, argv);
  1052. }
  1053. static int wpa_cli_cmd_add_network(struct wpa_ctrl *ctrl, int argc,
  1054. char *argv[])
  1055. {
  1056. int res = wpa_ctrl_command(ctrl, "ADD_NETWORK");
  1057. if (interactive)
  1058. update_networks(ctrl);
  1059. return res;
  1060. }
  1061. static int wpa_cli_cmd_remove_network(struct wpa_ctrl *ctrl, int argc,
  1062. char *argv[])
  1063. {
  1064. int res = wpa_cli_cmd(ctrl, "REMOVE_NETWORK", 1, argc, argv);
  1065. if (interactive)
  1066. update_networks(ctrl);
  1067. return res;
  1068. }
  1069. static void wpa_cli_show_network_variables(void)
  1070. {
  1071. printf("set_network variables:\n"
  1072. " ssid (network name, SSID)\n"
  1073. " psk (WPA passphrase or pre-shared key)\n"
  1074. " key_mgmt (key management protocol)\n"
  1075. " identity (EAP identity)\n"
  1076. " password (EAP password)\n"
  1077. " ...\n"
  1078. "\n"
  1079. "Note: Values are entered in the same format as the "
  1080. "configuration file is using,\n"
  1081. "i.e., strings values need to be inside double quotation "
  1082. "marks.\n"
  1083. "For example: set_network 1 ssid \"network name\"\n"
  1084. "\n"
  1085. "Please see wpa_supplicant.conf documentation for full list "
  1086. "of\navailable variables.\n");
  1087. }
  1088. static int wpa_cli_cmd_set_network(struct wpa_ctrl *ctrl, int argc,
  1089. char *argv[])
  1090. {
  1091. if (argc == 0) {
  1092. wpa_cli_show_network_variables();
  1093. return 0;
  1094. }
  1095. if (argc < 3) {
  1096. printf("Invalid SET_NETWORK command: needs three arguments\n"
  1097. "(network id, variable name, and value)\n");
  1098. return -1;
  1099. }
  1100. return wpa_cli_cmd(ctrl, "SET_NETWORK", 3, argc, argv);
  1101. }
  1102. static int wpa_cli_cmd_get_network(struct wpa_ctrl *ctrl, int argc,
  1103. char *argv[])
  1104. {
  1105. if (argc == 0) {
  1106. wpa_cli_show_network_variables();
  1107. return 0;
  1108. }
  1109. if (argc != 2) {
  1110. printf("Invalid GET_NETWORK command: needs two arguments\n"
  1111. "(network id and variable name)\n");
  1112. return -1;
  1113. }
  1114. return wpa_cli_cmd(ctrl, "GET_NETWORK", 2, argc, argv);
  1115. }
  1116. static const char *network_fields[] = {
  1117. "ssid", "scan_ssid", "bssid", "bssid_blacklist",
  1118. "bssid_whitelist", "psk", "proto", "key_mgmt",
  1119. "bg_scan_period", "pairwise", "group", "auth_alg", "scan_freq",
  1120. "freq_list", "max_oper_chwidth", "ht40", "vht", "vht_center_freq1",
  1121. "vht_center_freq2", "ht",
  1122. #ifdef IEEE8021X_EAPOL
  1123. "eap", "identity", "anonymous_identity", "password", "ca_cert",
  1124. "ca_path", "client_cert", "private_key", "private_key_passwd",
  1125. "dh_file", "subject_match", "altsubject_match",
  1126. "domain_suffix_match", "domain_match", "ca_cert2", "ca_path2",
  1127. "client_cert2", "private_key2", "private_key2_passwd",
  1128. "dh_file2", "subject_match2", "altsubject_match2",
  1129. "domain_suffix_match2", "domain_match2", "phase1", "phase2",
  1130. "pcsc", "pin", "engine_id", "key_id", "cert_id", "ca_cert_id",
  1131. "pin2", "engine2_id", "key2_id", "cert2_id", "ca_cert2_id",
  1132. "engine", "engine2", "eapol_flags", "sim_num",
  1133. "openssl_ciphers", "erp",
  1134. #endif /* IEEE8021X_EAPOL */
  1135. "wep_key0", "wep_key1", "wep_key2", "wep_key3",
  1136. "wep_tx_keyidx", "priority",
  1137. #ifdef IEEE8021X_EAPOL
  1138. "eap_workaround", "pac_file", "fragment_size", "ocsp",
  1139. #endif /* IEEE8021X_EAPOL */
  1140. #ifdef CONFIG_MESH
  1141. "mode", "no_auto_peer", "mesh_rssi_threshold",
  1142. #else /* CONFIG_MESH */
  1143. "mode",
  1144. #endif /* CONFIG_MESH */
  1145. "proactive_key_caching", "disabled", "id_str",
  1146. #ifdef CONFIG_IEEE80211W
  1147. "ieee80211w",
  1148. #endif /* CONFIG_IEEE80211W */
  1149. "mixed_cell", "frequency", "fixed_freq",
  1150. #ifdef CONFIG_MESH
  1151. "mesh_basic_rates", "dot11MeshMaxRetries",
  1152. "dot11MeshRetryTimeout", "dot11MeshConfirmTimeout",
  1153. "dot11MeshHoldingTimeout",
  1154. #endif /* CONFIG_MESH */
  1155. "wpa_ptk_rekey", "bgscan", "ignore_broadcast_ssid",
  1156. #ifdef CONFIG_P2P
  1157. "go_p2p_dev_addr", "p2p_client_list", "psk_list",
  1158. #endif /* CONFIG_P2P */
  1159. #ifdef CONFIG_HT_OVERRIDES
  1160. "disable_ht", "disable_ht40", "disable_sgi", "disable_ldpc",
  1161. "ht40_intolerant", "disable_max_amsdu", "ampdu_factor",
  1162. "ampdu_density", "ht_mcs",
  1163. #endif /* CONFIG_HT_OVERRIDES */
  1164. #ifdef CONFIG_VHT_OVERRIDES
  1165. "disable_vht", "vht_capa", "vht_capa_mask", "vht_rx_mcs_nss_1",
  1166. "vht_rx_mcs_nss_2", "vht_rx_mcs_nss_3", "vht_rx_mcs_nss_4",
  1167. "vht_rx_mcs_nss_5", "vht_rx_mcs_nss_6", "vht_rx_mcs_nss_7",
  1168. "vht_rx_mcs_nss_8", "vht_tx_mcs_nss_1", "vht_tx_mcs_nss_2",
  1169. "vht_tx_mcs_nss_3", "vht_tx_mcs_nss_4", "vht_tx_mcs_nss_5",
  1170. "vht_tx_mcs_nss_6", "vht_tx_mcs_nss_7", "vht_tx_mcs_nss_8",
  1171. #endif /* CONFIG_VHT_OVERRIDES */
  1172. "ap_max_inactivity", "dtim_period", "beacon_int",
  1173. #ifdef CONFIG_MACSEC
  1174. "macsec_policy",
  1175. "macsec_integ_only",
  1176. "macsec_port",
  1177. "mka_priority",
  1178. #endif /* CONFIG_MACSEC */
  1179. #ifdef CONFIG_HS20
  1180. "update_identifier",
  1181. #endif /* CONFIG_HS20 */
  1182. "mac_addr", "pbss", "wps_disabled"
  1183. };
  1184. static char ** wpa_cli_complete_network(const char *str, int pos)
  1185. {
  1186. int arg = get_cmd_arg_num(str, pos);
  1187. int i, num_fields = ARRAY_SIZE(network_fields);
  1188. char **res = NULL;
  1189. switch (arg) {
  1190. case 1:
  1191. res = cli_txt_list_array(&networks);
  1192. break;
  1193. case 2:
  1194. res = os_calloc(num_fields + 1, sizeof(char *));
  1195. if (res == NULL)
  1196. return NULL;
  1197. for (i = 0; i < num_fields; i++) {
  1198. res[i] = os_strdup(network_fields[i]);
  1199. if (res[i] == NULL)
  1200. break;
  1201. }
  1202. }
  1203. return res;
  1204. }
  1205. static char ** wpa_cli_complete_network_id(const char *str, int pos)
  1206. {
  1207. int arg = get_cmd_arg_num(str, pos);
  1208. if (arg == 1)
  1209. return cli_txt_list_array(&networks);
  1210. return NULL;
  1211. }
  1212. static int wpa_cli_cmd_dup_network(struct wpa_ctrl *ctrl, int argc,
  1213. char *argv[])
  1214. {
  1215. if (argc == 0) {
  1216. wpa_cli_show_network_variables();
  1217. return 0;
  1218. }
  1219. if (argc < 3) {
  1220. printf("Invalid DUP_NETWORK command: needs three arguments\n"
  1221. "(src netid, dest netid, and variable name)\n");
  1222. return -1;
  1223. }
  1224. return wpa_cli_cmd(ctrl, "DUP_NETWORK", 3, argc, argv);
  1225. }
  1226. static char ** wpa_cli_complete_dup_network(const char *str, int pos)
  1227. {
  1228. int arg = get_cmd_arg_num(str, pos);
  1229. int i, num_fields = ARRAY_SIZE(network_fields);
  1230. char **res = NULL;
  1231. switch (arg) {
  1232. case 1:
  1233. case 2:
  1234. res = cli_txt_list_array(&networks);
  1235. break;
  1236. case 3:
  1237. res = os_calloc(num_fields + 1, sizeof(char *));
  1238. if (res == NULL)
  1239. return NULL;
  1240. for (i = 0; i < num_fields; i++) {
  1241. res[i] = os_strdup(network_fields[i]);
  1242. if (res[i] == NULL)
  1243. break;
  1244. }
  1245. }
  1246. return res;
  1247. }
  1248. static int wpa_cli_cmd_list_creds(struct wpa_ctrl *ctrl, int argc,
  1249. char *argv[])
  1250. {
  1251. return wpa_ctrl_command(ctrl, "LIST_CREDS");
  1252. }
  1253. static int wpa_cli_cmd_add_cred(struct wpa_ctrl *ctrl, int argc, char *argv[])
  1254. {
  1255. return wpa_ctrl_command(ctrl, "ADD_CRED");
  1256. }
  1257. static int wpa_cli_cmd_remove_cred(struct wpa_ctrl *ctrl, int argc,
  1258. char *argv[])
  1259. {
  1260. return wpa_cli_cmd(ctrl, "REMOVE_CRED", 1, argc, argv);
  1261. }
  1262. static int wpa_cli_cmd_set_cred(struct wpa_ctrl *ctrl, int argc, char *argv[])
  1263. {
  1264. if (argc != 3) {
  1265. printf("Invalid SET_CRED command: needs three arguments\n"
  1266. "(cred id, variable name, and value)\n");
  1267. return -1;
  1268. }
  1269. return wpa_cli_cmd(ctrl, "SET_CRED", 3, argc, argv);
  1270. }
  1271. static int wpa_cli_cmd_get_cred(struct wpa_ctrl *ctrl, int argc, char *argv[])
  1272. {
  1273. if (argc != 2) {
  1274. printf("Invalid GET_CRED command: needs two arguments\n"
  1275. "(cred id, variable name)\n");
  1276. return -1;
  1277. }
  1278. return wpa_cli_cmd(ctrl, "GET_CRED", 2, argc, argv);
  1279. }
  1280. static int wpa_cli_cmd_disconnect(struct wpa_ctrl *ctrl, int argc,
  1281. char *argv[])
  1282. {
  1283. return wpa_ctrl_command(ctrl, "DISCONNECT");
  1284. }
  1285. static int wpa_cli_cmd_reconnect(struct wpa_ctrl *ctrl, int argc,
  1286. char *argv[])
  1287. {
  1288. return wpa_ctrl_command(ctrl, "RECONNECT");
  1289. }
  1290. static int wpa_cli_cmd_save_config(struct wpa_ctrl *ctrl, int argc,
  1291. char *argv[])
  1292. {
  1293. return wpa_ctrl_command(ctrl, "SAVE_CONFIG");
  1294. }
  1295. static int wpa_cli_cmd_scan(struct wpa_ctrl *ctrl, int argc, char *argv[])
  1296. {
  1297. return wpa_cli_cmd(ctrl, "SCAN", 0, argc, argv);
  1298. }
  1299. static int wpa_cli_cmd_scan_results(struct wpa_ctrl *ctrl, int argc,
  1300. char *argv[])
  1301. {
  1302. return wpa_ctrl_command(ctrl, "SCAN_RESULTS");
  1303. }
  1304. static int wpa_cli_cmd_abort_scan(struct wpa_ctrl *ctrl, int argc,
  1305. char *argv[])
  1306. {
  1307. return wpa_ctrl_command(ctrl, "ABORT_SCAN");
  1308. }
  1309. static int wpa_cli_cmd_bss(struct wpa_ctrl *ctrl, int argc, char *argv[])
  1310. {
  1311. return wpa_cli_cmd(ctrl, "BSS", 1, argc, argv);
  1312. }
  1313. static char ** wpa_cli_complete_bss(const char *str, int pos)
  1314. {
  1315. int arg = get_cmd_arg_num(str, pos);
  1316. char **res = NULL;
  1317. switch (arg) {
  1318. case 1:
  1319. res = cli_txt_list_array(&bsses);
  1320. break;
  1321. }
  1322. return res;
  1323. }
  1324. static int wpa_cli_cmd_get_capability(struct wpa_ctrl *ctrl, int argc,
  1325. char *argv[])
  1326. {
  1327. if (argc < 1 || argc > 2) {
  1328. printf("Invalid GET_CAPABILITY command: need either one or "
  1329. "two arguments\n");
  1330. return -1;
  1331. }
  1332. if ((argc == 2) && os_strcmp(argv[1], "strict") != 0) {
  1333. printf("Invalid GET_CAPABILITY command: second argument, "
  1334. "if any, must be 'strict'\n");
  1335. return -1;
  1336. }
  1337. return wpa_cli_cmd(ctrl, "GET_CAPABILITY", 1, argc, argv);
  1338. }
  1339. static char ** wpa_cli_complete_get_capability(const char *str, int pos)
  1340. {
  1341. int arg = get_cmd_arg_num(str, pos);
  1342. const char *fields[] = {
  1343. "eap", "pairwise", "group", "group_mgmt", "key_mgmt",
  1344. "proto", "auth_alg", "modes", "channels", "freq",
  1345. #ifdef CONFIG_TDLS
  1346. "tdls",
  1347. #endif /* CONFIG_TDLS */
  1348. #ifdef CONFIG_ERP
  1349. "erp",
  1350. #endif /* CONFIG_ERP */
  1351. #ifdef CONFIG_FIPS
  1352. "fips",
  1353. #endif /* CONFIG_FIPS */
  1354. #ifdef CONFIG_ACS
  1355. "acs",
  1356. #endif /* CONFIG_ACS */
  1357. };
  1358. int i, num_fields = ARRAY_SIZE(fields);
  1359. char **res = NULL;
  1360. if (arg == 1) {
  1361. res = os_calloc(num_fields + 1, sizeof(char *));
  1362. if (res == NULL)
  1363. return NULL;
  1364. for (i = 0; i < num_fields; i++) {
  1365. res[i] = os_strdup(fields[i]);
  1366. if (res[i] == NULL)
  1367. return res;
  1368. }
  1369. }
  1370. if (arg == 2) {
  1371. res = os_calloc(1 + 1, sizeof(char *));
  1372. if (res == NULL)
  1373. return NULL;
  1374. res[0] = os_strdup("strict");
  1375. }
  1376. return res;
  1377. }
  1378. static int wpa_cli_list_interfaces(struct wpa_ctrl *ctrl)
  1379. {
  1380. printf("Available interfaces:\n");
  1381. return wpa_ctrl_command(ctrl, "INTERFACES");
  1382. }
  1383. static int wpa_cli_cmd_interface(struct wpa_ctrl *ctrl, int argc, char *argv[])
  1384. {
  1385. if (argc < 1) {
  1386. wpa_cli_list_interfaces(ctrl);
  1387. return 0;
  1388. }
  1389. wpa_cli_close_connection();
  1390. os_free(ctrl_ifname);
  1391. ctrl_ifname = os_strdup(argv[0]);
  1392. if (!ctrl_ifname) {
  1393. printf("Failed to allocate memory\n");
  1394. return 0;
  1395. }
  1396. if (wpa_cli_open_connection(ctrl_ifname, 1) == 0) {
  1397. printf("Connected to interface '%s.\n", ctrl_ifname);
  1398. } else {
  1399. printf("Could not connect to interface '%s' - re-trying\n",
  1400. ctrl_ifname);
  1401. }
  1402. return 0;
  1403. }
  1404. static int wpa_cli_cmd_reconfigure(struct wpa_ctrl *ctrl, int argc,
  1405. char *argv[])
  1406. {
  1407. return wpa_ctrl_command(ctrl, "RECONFIGURE");
  1408. }
  1409. static int wpa_cli_cmd_terminate(struct wpa_ctrl *ctrl, int argc,
  1410. char *argv[])
  1411. {
  1412. return wpa_ctrl_command(ctrl, "TERMINATE");
  1413. }
  1414. static int wpa_cli_cmd_interface_add(struct wpa_ctrl *ctrl, int argc,
  1415. char *argv[])
  1416. {
  1417. char cmd[256];
  1418. int res;
  1419. if (argc < 1) {
  1420. printf("Invalid INTERFACE_ADD command: needs at least one "
  1421. "argument (interface name)\n"
  1422. "All arguments: ifname confname driver ctrl_interface "
  1423. "driver_param bridge_name [create]\n");
  1424. return -1;
  1425. }
  1426. /*
  1427. * INTERFACE_ADD <ifname>TAB<confname>TAB<driver>TAB<ctrl_interface>TAB
  1428. * <driver_param>TAB<bridge_name>[TAB<create>[TAB<type>]]
  1429. */
  1430. res = os_snprintf(cmd, sizeof(cmd),
  1431. "INTERFACE_ADD %s\t%s\t%s\t%s\t%s\t%s\t%s\t%s",
  1432. argv[0],
  1433. argc > 1 ? argv[1] : "", argc > 2 ? argv[2] : "",
  1434. argc > 3 ? argv[3] : "", argc > 4 ? argv[4] : "",
  1435. argc > 5 ? argv[5] : "", argc > 6 ? argv[6] : "",
  1436. argc > 7 ? argv[7] : "");
  1437. if (os_snprintf_error(sizeof(cmd), res))
  1438. return -1;
  1439. cmd[sizeof(cmd) - 1] = '\0';
  1440. return wpa_ctrl_command(ctrl, cmd);
  1441. }
  1442. static int wpa_cli_cmd_interface_remove(struct wpa_ctrl *ctrl, int argc,
  1443. char *argv[])
  1444. {
  1445. return wpa_cli_cmd(ctrl, "INTERFACE_REMOVE", 1, argc, argv);
  1446. }
  1447. static int wpa_cli_cmd_interface_list(struct wpa_ctrl *ctrl, int argc,
  1448. char *argv[])
  1449. {
  1450. return wpa_ctrl_command(ctrl, "INTERFACE_LIST");
  1451. }
  1452. #ifdef CONFIG_AP
  1453. static int wpa_cli_cmd_sta(struct wpa_ctrl *ctrl, int argc, char *argv[])
  1454. {
  1455. return wpa_cli_cmd(ctrl, "STA", 1, argc, argv);
  1456. }
  1457. static char ** wpa_cli_complete_sta(const char *str, int pos)
  1458. {
  1459. int arg = get_cmd_arg_num(str, pos);
  1460. char **res = NULL;
  1461. switch (arg) {
  1462. case 1:
  1463. res = cli_txt_list_array(&stations);
  1464. break;
  1465. }
  1466. return res;
  1467. }
  1468. static int wpa_ctrl_command_sta(struct wpa_ctrl *ctrl, const char *cmd,
  1469. char *addr, size_t addr_len, int print)
  1470. {
  1471. char buf[4096], *pos;
  1472. size_t len;
  1473. int ret;
  1474. if (ctrl_conn == NULL) {
  1475. printf("Not connected to hostapd - command dropped.\n");
  1476. return -1;
  1477. }
  1478. if (ifname_prefix) {
  1479. os_snprintf(buf, sizeof(buf), "IFNAME=%s %s",
  1480. ifname_prefix, cmd);
  1481. buf[sizeof(buf) - 1] = '\0';
  1482. cmd = buf;
  1483. }
  1484. len = sizeof(buf) - 1;
  1485. ret = wpa_ctrl_request(ctrl, cmd, os_strlen(cmd), buf, &len,
  1486. wpa_cli_msg_cb);
  1487. if (ret == -2) {
  1488. printf("'%s' command timed out.\n", cmd);
  1489. return -2;
  1490. } else if (ret < 0) {
  1491. printf("'%s' command failed.\n", cmd);
  1492. return -1;
  1493. }
  1494. buf[len] = '\0';
  1495. if (os_memcmp(buf, "FAIL", 4) == 0 ||
  1496. os_memcmp(buf, "UNKNOWN COMMAND", 15) == 0)
  1497. return -1;
  1498. if (print)
  1499. printf("%s", buf);
  1500. pos = buf;
  1501. while (*pos != '\0' && *pos != '\n')
  1502. pos++;
  1503. *pos = '\0';
  1504. os_strlcpy(addr, buf, addr_len);
  1505. return 0;
  1506. }
  1507. static int wpa_cli_cmd_all_sta(struct wpa_ctrl *ctrl, int argc, char *argv[])
  1508. {
  1509. char addr[32], cmd[64];
  1510. if (wpa_ctrl_command_sta(ctrl, "STA-FIRST", addr, sizeof(addr), 1))
  1511. return 0;
  1512. do {
  1513. os_snprintf(cmd, sizeof(cmd), "STA-NEXT %s", addr);
  1514. } while (wpa_ctrl_command_sta(ctrl, cmd, addr, sizeof(addr), 1) == 0);
  1515. return -1;
  1516. }
  1517. static int wpa_cli_cmd_list_sta(struct wpa_ctrl *ctrl, int argc,
  1518. char *argv[])
  1519. {
  1520. char addr[32], cmd[64];
  1521. if (wpa_ctrl_command_sta(ctrl, "STA-FIRST", addr, sizeof(addr), 0))
  1522. return 0;
  1523. do {
  1524. if (os_strcmp(addr, "") != 0)
  1525. printf("%s\n", addr);
  1526. os_snprintf(cmd, sizeof(cmd), "STA-NEXT %s", addr);
  1527. } while (wpa_ctrl_command_sta(ctrl, cmd, addr, sizeof(addr), 0) == 0);
  1528. return 0;
  1529. }
  1530. static int wpa_cli_cmd_deauthenticate(struct wpa_ctrl *ctrl, int argc,
  1531. char *argv[])
  1532. {
  1533. return wpa_cli_cmd(ctrl, "DEAUTHENTICATE", 1, argc, argv);
  1534. }
  1535. static char ** wpa_cli_complete_deauthenticate(const char *str, int pos)
  1536. {
  1537. int arg = get_cmd_arg_num(str, pos);
  1538. char **res = NULL;
  1539. switch (arg) {
  1540. case 1:
  1541. res = cli_txt_list_array(&stations);
  1542. break;
  1543. }
  1544. return res;
  1545. }
  1546. static int wpa_cli_cmd_disassociate(struct wpa_ctrl *ctrl, int argc,
  1547. char *argv[])
  1548. {
  1549. return wpa_cli_cmd(ctrl, "DISASSOCIATE", 1, argc, argv);
  1550. }
  1551. static char ** wpa_cli_complete_disassociate(const char *str, int pos)
  1552. {
  1553. int arg = get_cmd_arg_num(str, pos);
  1554. char **res = NULL;
  1555. switch (arg) {
  1556. case 1:
  1557. res = cli_txt_list_array(&stations);
  1558. break;
  1559. }
  1560. return res;
  1561. }
  1562. static int wpa_cli_cmd_chanswitch(struct wpa_ctrl *ctrl, int argc,
  1563. char *argv[])
  1564. {
  1565. return wpa_cli_cmd(ctrl, "CHAN_SWITCH", 2, argc, argv);
  1566. }
  1567. #endif /* CONFIG_AP */
  1568. static int wpa_cli_cmd_suspend(struct wpa_ctrl *ctrl, int argc, char *argv[])
  1569. {
  1570. return wpa_ctrl_command(ctrl, "SUSPEND");
  1571. }
  1572. static int wpa_cli_cmd_resume(struct wpa_ctrl *ctrl, int argc, char *argv[])
  1573. {
  1574. return wpa_ctrl_command(ctrl, "RESUME");
  1575. }
  1576. #ifdef CONFIG_TESTING_OPTIONS
  1577. static int wpa_cli_cmd_drop_sa(struct wpa_ctrl *ctrl, int argc, char *argv[])
  1578. {
  1579. return wpa_ctrl_command(ctrl, "DROP_SA");
  1580. }
  1581. #endif /* CONFIG_TESTING_OPTIONS */
  1582. static int wpa_cli_cmd_roam(struct wpa_ctrl *ctrl, int argc, char *argv[])
  1583. {
  1584. return wpa_cli_cmd(ctrl, "ROAM", 1, argc, argv);
  1585. }
  1586. #ifdef CONFIG_MESH
  1587. static int wpa_cli_cmd_mesh_interface_add(struct wpa_ctrl *ctrl, int argc,
  1588. char *argv[])
  1589. {
  1590. return wpa_cli_cmd(ctrl, "MESH_INTERFACE_ADD", 0, argc, argv);
  1591. }
  1592. static int wpa_cli_cmd_mesh_group_add(struct wpa_ctrl *ctrl, int argc,
  1593. char *argv[])
  1594. {
  1595. return wpa_cli_cmd(ctrl, "MESH_GROUP_ADD", 1, argc, argv);
  1596. }
  1597. static int wpa_cli_cmd_mesh_group_remove(struct wpa_ctrl *ctrl, int argc,
  1598. char *argv[])
  1599. {
  1600. return wpa_cli_cmd(ctrl, "MESH_GROUP_REMOVE", 1, argc, argv);
  1601. }
  1602. static int wpa_cli_cmd_mesh_peer_remove(struct wpa_ctrl *ctrl, int argc,
  1603. char *argv[])
  1604. {
  1605. return wpa_cli_cmd(ctrl, "MESH_PEER_REMOVE", 1, argc, argv);
  1606. }
  1607. static int wpa_cli_cmd_mesh_peer_add(struct wpa_ctrl *ctrl, int argc,
  1608. char *argv[])
  1609. {
  1610. return wpa_cli_cmd(ctrl, "MESH_PEER_ADD", 1, argc, argv);
  1611. }
  1612. #endif /* CONFIG_MESH */
  1613. #ifdef CONFIG_P2P
  1614. static int wpa_cli_cmd_p2p_find(struct wpa_ctrl *ctrl, int argc, char *argv[])
  1615. {
  1616. return wpa_cli_cmd(ctrl, "P2P_FIND", 0, argc, argv);
  1617. }
  1618. static char ** wpa_cli_complete_p2p_find(const char *str, int pos)
  1619. {
  1620. char **res = NULL;
  1621. int arg = get_cmd_arg_num(str, pos);
  1622. res = os_calloc(6, sizeof(char *));
  1623. if (res == NULL)
  1624. return NULL;
  1625. res[0] = os_strdup("type=social");
  1626. if (res[0] == NULL) {
  1627. os_free(res);
  1628. return NULL;
  1629. }
  1630. res[1] = os_strdup("type=progressive");
  1631. if (res[1] == NULL)
  1632. return res;
  1633. res[2] = os_strdup("delay=");
  1634. if (res[2] == NULL)
  1635. return res;
  1636. res[3] = os_strdup("dev_id=");
  1637. if (res[3] == NULL)
  1638. return res;
  1639. if (arg == 1)
  1640. res[4] = os_strdup("[timeout]");
  1641. return res;
  1642. }
  1643. static int wpa_cli_cmd_p2p_stop_find(struct wpa_ctrl *ctrl, int argc,
  1644. char *argv[])
  1645. {
  1646. return wpa_ctrl_command(ctrl, "P2P_STOP_FIND");
  1647. }
  1648. static int wpa_cli_cmd_p2p_asp_provision(struct wpa_ctrl *ctrl, int argc,
  1649. char *argv[])
  1650. {
  1651. return wpa_cli_cmd(ctrl, "P2P_ASP_PROVISION", 3, argc, argv);
  1652. }
  1653. static int wpa_cli_cmd_p2p_asp_provision_resp(struct wpa_ctrl *ctrl, int argc,
  1654. char *argv[])
  1655. {
  1656. return wpa_cli_cmd(ctrl, "P2P_ASP_PROVISION_RESP", 2, argc, argv);
  1657. }
  1658. static int wpa_cli_cmd_p2p_connect(struct wpa_ctrl *ctrl, int argc,
  1659. char *argv[])
  1660. {
  1661. return wpa_cli_cmd(ctrl, "P2P_CONNECT", 2, argc, argv);
  1662. }
  1663. static char ** wpa_cli_complete_p2p_connect(const char *str, int pos)
  1664. {
  1665. int arg = get_cmd_arg_num(str, pos);
  1666. char **res = NULL;
  1667. switch (arg) {
  1668. case 1:
  1669. res = cli_txt_list_array(&p2p_peers);
  1670. break;
  1671. }
  1672. return res;
  1673. }
  1674. static int wpa_cli_cmd_p2p_listen(struct wpa_ctrl *ctrl, int argc,
  1675. char *argv[])
  1676. {
  1677. return wpa_cli_cmd(ctrl, "P2P_LISTEN", 0, argc, argv);
  1678. }
  1679. static int wpa_cli_cmd_p2p_group_remove(struct wpa_ctrl *ctrl, int argc,
  1680. char *argv[])
  1681. {
  1682. return wpa_cli_cmd(ctrl, "P2P_GROUP_REMOVE", 1, argc, argv);
  1683. }
  1684. static char ** wpa_cli_complete_p2p_group_remove(const char *str, int pos)
  1685. {
  1686. int arg = get_cmd_arg_num(str, pos);
  1687. char **res = NULL;
  1688. switch (arg) {
  1689. case 1:
  1690. res = cli_txt_list_array(&p2p_groups);
  1691. break;
  1692. }
  1693. return res;
  1694. }
  1695. static int wpa_cli_cmd_p2p_group_add(struct wpa_ctrl *ctrl, int argc,
  1696. char *argv[])
  1697. {
  1698. return wpa_cli_cmd(ctrl, "P2P_GROUP_ADD", 0, argc, argv);
  1699. }
  1700. static int wpa_cli_cmd_p2p_group_member(struct wpa_ctrl *ctrl, int argc,
  1701. char *argv[])
  1702. {
  1703. return wpa_cli_cmd(ctrl, "P2P_GROUP_MEMBER", 1, argc, argv);
  1704. }
  1705. static int wpa_cli_cmd_p2p_prov_disc(struct wpa_ctrl *ctrl, int argc,
  1706. char *argv[])
  1707. {
  1708. if (argc != 2 && argc != 3) {
  1709. printf("Invalid P2P_PROV_DISC command: needs at least "
  1710. "two arguments, address and config method\n"
  1711. "(display, keypad, or pbc) and an optional join\n");
  1712. return -1;
  1713. }
  1714. return wpa_cli_cmd(ctrl, "P2P_PROV_DISC", 2, argc, argv);
  1715. }
  1716. static int wpa_cli_cmd_p2p_get_passphrase(struct wpa_ctrl *ctrl, int argc,
  1717. char *argv[])
  1718. {
  1719. return wpa_ctrl_command(ctrl, "P2P_GET_PASSPHRASE");
  1720. }
  1721. static int wpa_cli_cmd_p2p_serv_disc_req(struct wpa_ctrl *ctrl, int argc,
  1722. char *argv[])
  1723. {
  1724. char cmd[4096];
  1725. if (argc < 2) {
  1726. printf("Invalid P2P_SERV_DISC_REQ command: needs two "
  1727. "or more arguments (address and TLVs)\n");
  1728. return -1;
  1729. }
  1730. if (write_cmd(cmd, sizeof(cmd), "P2P_SERV_DISC_REQ", argc, argv) < 0)
  1731. return -1;
  1732. return wpa_ctrl_command(ctrl, cmd);
  1733. }
  1734. static int wpa_cli_cmd_p2p_serv_disc_cancel_req(struct wpa_ctrl *ctrl,
  1735. int argc, char *argv[])
  1736. {
  1737. return wpa_cli_cmd(ctrl, "P2P_SERV_DISC_CANCEL_REQ", 1, argc, argv);
  1738. }
  1739. static int wpa_cli_cmd_p2p_serv_disc_resp(struct wpa_ctrl *ctrl, int argc,
  1740. char *argv[])
  1741. {
  1742. char cmd[4096];
  1743. int res;
  1744. if (argc != 4) {
  1745. printf("Invalid P2P_SERV_DISC_RESP command: needs four "
  1746. "arguments (freq, address, dialog token, and TLVs)\n");
  1747. return -1;
  1748. }
  1749. res = os_snprintf(cmd, sizeof(cmd), "P2P_SERV_DISC_RESP %s %s %s %s",
  1750. argv[0], argv[1], argv[2], argv[3]);
  1751. if (os_snprintf_error(sizeof(cmd), res))
  1752. return -1;
  1753. cmd[sizeof(cmd) - 1] = '\0';
  1754. return wpa_ctrl_command(ctrl, cmd);
  1755. }
  1756. static int wpa_cli_cmd_p2p_service_update(struct wpa_ctrl *ctrl, int argc,
  1757. char *argv[])
  1758. {
  1759. return wpa_ctrl_command(ctrl, "P2P_SERVICE_UPDATE");
  1760. }
  1761. static int wpa_cli_cmd_p2p_serv_disc_external(struct wpa_ctrl *ctrl,
  1762. int argc, char *argv[])
  1763. {
  1764. return wpa_cli_cmd(ctrl, "P2P_SERV_DISC_EXTERNAL", 1, argc, argv);
  1765. }
  1766. static int wpa_cli_cmd_p2p_service_flush(struct wpa_ctrl *ctrl, int argc,
  1767. char *argv[])
  1768. {
  1769. return wpa_ctrl_command(ctrl, "P2P_SERVICE_FLUSH");
  1770. }
  1771. static int wpa_cli_cmd_p2p_service_add(struct wpa_ctrl *ctrl, int argc,
  1772. char *argv[])
  1773. {
  1774. if (argc < 3) {
  1775. printf("Invalid P2P_SERVICE_ADD command: needs 3-6 arguments\n");
  1776. return -1;
  1777. }
  1778. return wpa_cli_cmd(ctrl, "P2P_SERVICE_ADD", 3, argc, argv);
  1779. }
  1780. static int wpa_cli_cmd_p2p_service_rep(struct wpa_ctrl *ctrl, int argc,
  1781. char *argv[])
  1782. {
  1783. if (argc < 5 || argc > 6) {
  1784. printf("Invalid P2P_SERVICE_REP command: needs 5-6 "
  1785. "arguments\n");
  1786. return -1;
  1787. }
  1788. return wpa_cli_cmd(ctrl, "P2P_SERVICE_REP", 5, argc, argv);
  1789. }
  1790. static int wpa_cli_cmd_p2p_service_del(struct wpa_ctrl *ctrl, int argc,
  1791. char *argv[])
  1792. {
  1793. char cmd[4096];
  1794. int res;
  1795. if (argc != 2 && argc != 3) {
  1796. printf("Invalid P2P_SERVICE_DEL command: needs two or three "
  1797. "arguments\n");
  1798. return -1;
  1799. }
  1800. if (argc == 3)
  1801. res = os_snprintf(cmd, sizeof(cmd),
  1802. "P2P_SERVICE_DEL %s %s %s",
  1803. argv[0], argv[1], argv[2]);
  1804. else
  1805. res = os_snprintf(cmd, sizeof(cmd),
  1806. "P2P_SERVICE_DEL %s %s",
  1807. argv[0], argv[1]);
  1808. if (os_snprintf_error(sizeof(cmd), res))
  1809. return -1;
  1810. cmd[sizeof(cmd) - 1] = '\0';
  1811. return wpa_ctrl_command(ctrl, cmd);
  1812. }
  1813. static int wpa_cli_cmd_p2p_reject(struct wpa_ctrl *ctrl,
  1814. int argc, char *argv[])
  1815. {
  1816. return wpa_cli_cmd(ctrl, "P2P_REJECT", 1, argc, argv);
  1817. }
  1818. static int wpa_cli_cmd_p2p_invite(struct wpa_ctrl *ctrl,
  1819. int argc, char *argv[])
  1820. {
  1821. return wpa_cli_cmd(ctrl, "P2P_INVITE", 1, argc, argv);
  1822. }
  1823. static int wpa_cli_cmd_p2p_peer(struct wpa_ctrl *ctrl, int argc, char *argv[])
  1824. {
  1825. return wpa_cli_cmd(ctrl, "P2P_PEER", 1, argc, argv);
  1826. }
  1827. static char ** wpa_cli_complete_p2p_peer(const char *str, int pos)
  1828. {
  1829. int arg = get_cmd_arg_num(str, pos);
  1830. char **res = NULL;
  1831. switch (arg) {
  1832. case 1:
  1833. res = cli_txt_list_array(&p2p_peers);
  1834. break;
  1835. }
  1836. return res;
  1837. }
  1838. static int wpa_ctrl_command_p2p_peer(struct wpa_ctrl *ctrl, const char *cmd,
  1839. char *addr, size_t addr_len,
  1840. int discovered)
  1841. {
  1842. char buf[4096], *pos;
  1843. size_t len;
  1844. int ret;
  1845. if (ctrl_conn == NULL)
  1846. return -1;
  1847. len = sizeof(buf) - 1;
  1848. ret = wpa_ctrl_request(ctrl, cmd, os_strlen(cmd), buf, &len,
  1849. wpa_cli_msg_cb);
  1850. if (ret == -2) {
  1851. printf("'%s' command timed out.\n", cmd);
  1852. return -2;
  1853. } else if (ret < 0) {
  1854. printf("'%s' command failed.\n", cmd);
  1855. return -1;
  1856. }
  1857. buf[len] = '\0';
  1858. if (os_memcmp(buf, "FAIL", 4) == 0)
  1859. return -1;
  1860. pos = buf;
  1861. while (*pos != '\0' && *pos != '\n')
  1862. pos++;
  1863. *pos++ = '\0';
  1864. os_strlcpy(addr, buf, addr_len);
  1865. if (!discovered || os_strstr(pos, "[PROBE_REQ_ONLY]") == NULL)
  1866. printf("%s\n", addr);
  1867. return 0;
  1868. }
  1869. static int wpa_cli_cmd_p2p_peers(struct wpa_ctrl *ctrl, int argc, char *argv[])
  1870. {
  1871. char addr[32], cmd[64];
  1872. int discovered;
  1873. discovered = argc > 0 && os_strcmp(argv[0], "discovered") == 0;
  1874. if (wpa_ctrl_command_p2p_peer(ctrl, "P2P_PEER FIRST",
  1875. addr, sizeof(addr), discovered))
  1876. return -1;
  1877. do {
  1878. os_snprintf(cmd, sizeof(cmd), "P2P_PEER NEXT-%s", addr);
  1879. } while (wpa_ctrl_command_p2p_peer(ctrl, cmd, addr, sizeof(addr),
  1880. discovered) == 0);
  1881. return 0;
  1882. }
  1883. static int wpa_cli_cmd_p2p_set(struct wpa_ctrl *ctrl, int argc, char *argv[])
  1884. {
  1885. return wpa_cli_cmd(ctrl, "P2P_SET", 2, argc, argv);
  1886. }
  1887. static char ** wpa_cli_complete_p2p_set(const char *str, int pos)
  1888. {
  1889. int arg = get_cmd_arg_num(str, pos);
  1890. const char *fields[] = {
  1891. "discoverability",
  1892. "managed",
  1893. "listen_channel",
  1894. "ssid_postfix",
  1895. "noa",
  1896. "ps",
  1897. "oppps",
  1898. "ctwindow",
  1899. "disabled",
  1900. "conc_pref",
  1901. "force_long_sd",
  1902. "peer_filter",
  1903. "cross_connect",
  1904. "go_apsd",
  1905. "client_apsd",
  1906. "disallow_freq",
  1907. "disc_int",
  1908. "per_sta_psk",
  1909. };
  1910. int i, num_fields = ARRAY_SIZE(fields);
  1911. if (arg == 1) {
  1912. char **res = os_calloc(num_fields + 1, sizeof(char *));
  1913. if (res == NULL)
  1914. return NULL;
  1915. for (i = 0; i < num_fields; i++) {
  1916. res[i] = os_strdup(fields[i]);
  1917. if (res[i] == NULL)
  1918. return res;
  1919. }
  1920. return res;
  1921. }
  1922. if (arg == 2 && os_strncasecmp(str, "p2p_set peer_filter ", 20) == 0)
  1923. return cli_txt_list_array(&p2p_peers);
  1924. return NULL;
  1925. }
  1926. static int wpa_cli_cmd_p2p_flush(struct wpa_ctrl *ctrl, int argc, char *argv[])
  1927. {
  1928. return wpa_ctrl_command(ctrl, "P2P_FLUSH");
  1929. }
  1930. static int wpa_cli_cmd_p2p_cancel(struct wpa_ctrl *ctrl, int argc,
  1931. char *argv[])
  1932. {
  1933. return wpa_ctrl_command(ctrl, "P2P_CANCEL");
  1934. }
  1935. static int wpa_cli_cmd_p2p_unauthorize(struct wpa_ctrl *ctrl, int argc,
  1936. char *argv[])
  1937. {
  1938. return wpa_cli_cmd(ctrl, "P2P_UNAUTHORIZE", 1, argc, argv);
  1939. }
  1940. static int wpa_cli_cmd_p2p_presence_req(struct wpa_ctrl *ctrl, int argc,
  1941. char *argv[])
  1942. {
  1943. if (argc != 0 && argc != 2 && argc != 4) {
  1944. printf("Invalid P2P_PRESENCE_REQ command: needs two arguments "
  1945. "(preferred duration, interval; in microsecods).\n"
  1946. "Optional second pair can be used to provide "
  1947. "acceptable values.\n");
  1948. return -1;
  1949. }
  1950. return wpa_cli_cmd(ctrl, "P2P_PRESENCE_REQ", 0, argc, argv);
  1951. }
  1952. static int wpa_cli_cmd_p2p_ext_listen(struct wpa_ctrl *ctrl, int argc,
  1953. char *argv[])
  1954. {
  1955. if (argc != 0 && argc != 2) {
  1956. printf("Invalid P2P_EXT_LISTEN command: needs two arguments "
  1957. "(availability period, availability interval; in "
  1958. "millisecods).\n"
  1959. "Extended Listen Timing can be cancelled with this "
  1960. "command when used without parameters.\n");
  1961. return -1;
  1962. }
  1963. return wpa_cli_cmd(ctrl, "P2P_EXT_LISTEN", 0, argc, argv);
  1964. }
  1965. static int wpa_cli_cmd_p2p_remove_client(struct wpa_ctrl *ctrl, int argc,
  1966. char *argv[])
  1967. {
  1968. return wpa_cli_cmd(ctrl, "P2P_REMOVE_CLIENT", 1, argc, argv);
  1969. }
  1970. static int wpa_cli_cmd_vendor_elem_add(struct wpa_ctrl *ctrl, int argc,
  1971. char *argv[])
  1972. {
  1973. return wpa_cli_cmd(ctrl, "VENDOR_ELEM_ADD", 2, argc, argv);
  1974. }
  1975. static int wpa_cli_cmd_vendor_elem_get(struct wpa_ctrl *ctrl, int argc,
  1976. char *argv[])
  1977. {
  1978. return wpa_cli_cmd(ctrl, "VENDOR_ELEM_GET", 1, argc, argv);
  1979. }
  1980. static int wpa_cli_cmd_vendor_elem_remove(struct wpa_ctrl *ctrl, int argc,
  1981. char *argv[])
  1982. {
  1983. return wpa_cli_cmd(ctrl, "VENDOR_ELEM_REMOVE", 2, argc, argv);
  1984. }
  1985. #endif /* CONFIG_P2P */
  1986. #ifdef CONFIG_WIFI_DISPLAY
  1987. static int wpa_cli_cmd_wfd_subelem_set(struct wpa_ctrl *ctrl, int argc,
  1988. char *argv[])
  1989. {
  1990. char cmd[100];
  1991. int res;
  1992. if (argc != 1 && argc != 2) {
  1993. printf("Invalid WFD_SUBELEM_SET command: needs one or two "
  1994. "arguments (subelem, hexdump)\n");
  1995. return -1;
  1996. }
  1997. res = os_snprintf(cmd, sizeof(cmd), "WFD_SUBELEM_SET %s %s",
  1998. argv[0], argc > 1 ? argv[1] : "");
  1999. if (os_snprintf_error(sizeof(cmd), res))
  2000. return -1;
  2001. cmd[sizeof(cmd) - 1] = '\0';
  2002. return wpa_ctrl_command(ctrl, cmd);
  2003. }
  2004. static int wpa_cli_cmd_wfd_subelem_get(struct wpa_ctrl *ctrl, int argc,
  2005. char *argv[])
  2006. {
  2007. char cmd[100];
  2008. int res;
  2009. if (argc != 1) {
  2010. printf("Invalid WFD_SUBELEM_GET command: needs one "
  2011. "argument (subelem)\n");
  2012. return -1;
  2013. }
  2014. res = os_snprintf(cmd, sizeof(cmd), "WFD_SUBELEM_GET %s",
  2015. argv[0]);
  2016. if (os_snprintf_error(sizeof(cmd), res))
  2017. return -1;
  2018. cmd[sizeof(cmd) - 1] = '\0';
  2019. return wpa_ctrl_command(ctrl, cmd);
  2020. }
  2021. #endif /* CONFIG_WIFI_DISPLAY */
  2022. #ifdef CONFIG_INTERWORKING
  2023. static int wpa_cli_cmd_fetch_anqp(struct wpa_ctrl *ctrl, int argc,
  2024. char *argv[])
  2025. {
  2026. return wpa_ctrl_command(ctrl, "FETCH_ANQP");
  2027. }
  2028. static int wpa_cli_cmd_stop_fetch_anqp(struct wpa_ctrl *ctrl, int argc,
  2029. char *argv[])
  2030. {
  2031. return wpa_ctrl_command(ctrl, "STOP_FETCH_ANQP");
  2032. }
  2033. static int wpa_cli_cmd_interworking_select(struct wpa_ctrl *ctrl, int argc,
  2034. char *argv[])
  2035. {
  2036. return wpa_cli_cmd(ctrl, "INTERWORKING_SELECT", 0, argc, argv);
  2037. }
  2038. static int wpa_cli_cmd_interworking_connect(struct wpa_ctrl *ctrl, int argc,
  2039. char *argv[])
  2040. {
  2041. return wpa_cli_cmd(ctrl, "INTERWORKING_CONNECT", 1, argc, argv);
  2042. }
  2043. static int wpa_cli_cmd_interworking_add_network(struct wpa_ctrl *ctrl, int argc,
  2044. char *argv[])
  2045. {
  2046. return wpa_cli_cmd(ctrl, "INTERWORKING_ADD_NETWORK", 1, argc, argv);
  2047. }
  2048. static int wpa_cli_cmd_anqp_get(struct wpa_ctrl *ctrl, int argc, char *argv[])
  2049. {
  2050. return wpa_cli_cmd(ctrl, "ANQP_GET", 2, argc, argv);
  2051. }
  2052. static int wpa_cli_cmd_gas_request(struct wpa_ctrl *ctrl, int argc,
  2053. char *argv[])
  2054. {
  2055. return wpa_cli_cmd(ctrl, "GAS_REQUEST", 2, argc, argv);
  2056. }
  2057. static int wpa_cli_cmd_gas_response_get(struct wpa_ctrl *ctrl, int argc,
  2058. char *argv[])
  2059. {
  2060. return wpa_cli_cmd(ctrl, "GAS_RESPONSE_GET", 2, argc, argv);
  2061. }
  2062. #endif /* CONFIG_INTERWORKING */
  2063. #ifdef CONFIG_HS20
  2064. static int wpa_cli_cmd_hs20_anqp_get(struct wpa_ctrl *ctrl, int argc,
  2065. char *argv[])
  2066. {
  2067. return wpa_cli_cmd(ctrl, "HS20_ANQP_GET", 2, argc, argv);
  2068. }
  2069. static int wpa_cli_cmd_get_nai_home_realm_list(struct wpa_ctrl *ctrl, int argc,
  2070. char *argv[])
  2071. {
  2072. char cmd[512];
  2073. if (argc == 0) {
  2074. printf("Command needs one or two arguments (dst mac addr and "
  2075. "optional home realm)\n");
  2076. return -1;
  2077. }
  2078. if (write_cmd(cmd, sizeof(cmd), "HS20_GET_NAI_HOME_REALM_LIST",
  2079. argc, argv) < 0)
  2080. return -1;
  2081. return wpa_ctrl_command(ctrl, cmd);
  2082. }
  2083. static int wpa_cli_cmd_hs20_icon_request(struct wpa_ctrl *ctrl, int argc,
  2084. char *argv[])
  2085. {
  2086. char cmd[512];
  2087. if (argc < 2) {
  2088. printf("Command needs two arguments (dst mac addr and "
  2089. "icon name)\n");
  2090. return -1;
  2091. }
  2092. if (write_cmd(cmd, sizeof(cmd), "HS20_ICON_REQUEST", argc, argv) < 0)
  2093. return -1;
  2094. return wpa_ctrl_command(ctrl, cmd);
  2095. }
  2096. static int wpa_cli_cmd_fetch_osu(struct wpa_ctrl *ctrl, int argc, char *argv[])
  2097. {
  2098. return wpa_ctrl_command(ctrl, "FETCH_OSU");
  2099. }
  2100. static int wpa_cli_cmd_cancel_fetch_osu(struct wpa_ctrl *ctrl, int argc,
  2101. char *argv[])
  2102. {
  2103. return wpa_ctrl_command(ctrl, "CANCEL_FETCH_OSU");
  2104. }
  2105. #endif /* CONFIG_HS20 */
  2106. static int wpa_cli_cmd_sta_autoconnect(struct wpa_ctrl *ctrl, int argc,
  2107. char *argv[])
  2108. {
  2109. return wpa_cli_cmd(ctrl, "STA_AUTOCONNECT", 1, argc, argv);
  2110. }
  2111. static int wpa_cli_cmd_tdls_discover(struct wpa_ctrl *ctrl, int argc,
  2112. char *argv[])
  2113. {
  2114. return wpa_cli_cmd(ctrl, "TDLS_DISCOVER", 1, argc, argv);
  2115. }
  2116. static int wpa_cli_cmd_tdls_setup(struct wpa_ctrl *ctrl, int argc,
  2117. char *argv[])
  2118. {
  2119. return wpa_cli_cmd(ctrl, "TDLS_SETUP", 1, argc, argv);
  2120. }
  2121. static int wpa_cli_cmd_tdls_teardown(struct wpa_ctrl *ctrl, int argc,
  2122. char *argv[])
  2123. {
  2124. return wpa_cli_cmd(ctrl, "TDLS_TEARDOWN", 1, argc, argv);
  2125. }
  2126. static int wpa_cli_cmd_tdls_link_status(struct wpa_ctrl *ctrl, int argc,
  2127. char *argv[])
  2128. {
  2129. return wpa_cli_cmd(ctrl, "TDLS_LINK_STATUS", 1, argc, argv);
  2130. }
  2131. static int wpa_cli_cmd_wmm_ac_addts(struct wpa_ctrl *ctrl, int argc,
  2132. char *argv[])
  2133. {
  2134. return wpa_cli_cmd(ctrl, "WMM_AC_ADDTS", 3, argc, argv);
  2135. }
  2136. static int wpa_cli_cmd_wmm_ac_delts(struct wpa_ctrl *ctrl, int argc,
  2137. char *argv[])
  2138. {
  2139. return wpa_cli_cmd(ctrl, "WMM_AC_DELTS", 1, argc, argv);
  2140. }
  2141. static int wpa_cli_cmd_wmm_ac_status(struct wpa_ctrl *ctrl, int argc,
  2142. char *argv[])
  2143. {
  2144. return wpa_ctrl_command(ctrl, "WMM_AC_STATUS");
  2145. }
  2146. static int wpa_cli_cmd_tdls_chan_switch(struct wpa_ctrl *ctrl, int argc,
  2147. char *argv[])
  2148. {
  2149. return wpa_cli_cmd(ctrl, "TDLS_CHAN_SWITCH", 2, argc, argv);
  2150. }
  2151. static int wpa_cli_cmd_tdls_cancel_chan_switch(struct wpa_ctrl *ctrl, int argc,
  2152. char *argv[])
  2153. {
  2154. return wpa_cli_cmd(ctrl, "TDLS_CANCEL_CHAN_SWITCH", 1, argc, argv);
  2155. }
  2156. static int wpa_cli_cmd_signal_poll(struct wpa_ctrl *ctrl, int argc,
  2157. char *argv[])
  2158. {
  2159. return wpa_ctrl_command(ctrl, "SIGNAL_POLL");
  2160. }
  2161. static int wpa_cli_cmd_signal_monitor(struct wpa_ctrl *ctrl, int argc,
  2162. char *argv[])
  2163. {
  2164. return wpa_cli_cmd(ctrl, "SIGNAL_MONITOR", 0, argc, argv);
  2165. }
  2166. static int wpa_cli_cmd_pktcnt_poll(struct wpa_ctrl *ctrl, int argc,
  2167. char *argv[])
  2168. {
  2169. return wpa_ctrl_command(ctrl, "PKTCNT_POLL");
  2170. }
  2171. static int wpa_cli_cmd_reauthenticate(struct wpa_ctrl *ctrl, int argc,
  2172. char *argv[])
  2173. {
  2174. return wpa_ctrl_command(ctrl, "REAUTHENTICATE");
  2175. }
  2176. #ifdef CONFIG_AUTOSCAN
  2177. static int wpa_cli_cmd_autoscan(struct wpa_ctrl *ctrl, int argc, char *argv[])
  2178. {
  2179. if (argc == 0)
  2180. return wpa_ctrl_command(ctrl, "AUTOSCAN ");
  2181. return wpa_cli_cmd(ctrl, "AUTOSCAN", 0, argc, argv);
  2182. }
  2183. #endif /* CONFIG_AUTOSCAN */
  2184. #ifdef CONFIG_WNM
  2185. static int wpa_cli_cmd_wnm_sleep(struct wpa_ctrl *ctrl, int argc, char *argv[])
  2186. {
  2187. return wpa_cli_cmd(ctrl, "WNM_SLEEP", 0, argc, argv);
  2188. }
  2189. static int wpa_cli_cmd_wnm_bss_query(struct wpa_ctrl *ctrl, int argc, char *argv[])
  2190. {
  2191. return wpa_cli_cmd(ctrl, "WNM_BSS_QUERY", 1, argc, argv);
  2192. }
  2193. #endif /* CONFIG_WNM */
  2194. static int wpa_cli_cmd_raw(struct wpa_ctrl *ctrl, int argc, char *argv[])
  2195. {
  2196. if (argc == 0)
  2197. return -1;
  2198. return wpa_cli_cmd(ctrl, argv[0], 0, argc - 1, &argv[1]);
  2199. }
  2200. #ifdef ANDROID
  2201. static int wpa_cli_cmd_driver(struct wpa_ctrl *ctrl, int argc, char *argv[])
  2202. {
  2203. return wpa_cli_cmd(ctrl, "DRIVER", 1, argc, argv);
  2204. }
  2205. #endif /* ANDROID */
  2206. static int wpa_cli_cmd_vendor(struct wpa_ctrl *ctrl, int argc, char *argv[])
  2207. {
  2208. return wpa_cli_cmd(ctrl, "VENDOR", 1, argc, argv);
  2209. }
  2210. static int wpa_cli_cmd_flush(struct wpa_ctrl *ctrl, int argc, char *argv[])
  2211. {
  2212. return wpa_ctrl_command(ctrl, "FLUSH");
  2213. }
  2214. static int wpa_cli_cmd_radio_work(struct wpa_ctrl *ctrl, int argc, char *argv[])
  2215. {
  2216. return wpa_cli_cmd(ctrl, "RADIO_WORK", 1, argc, argv);
  2217. }
  2218. static int wpa_cli_cmd_neighbor_rep_request(struct wpa_ctrl *ctrl, int argc,
  2219. char *argv[])
  2220. {
  2221. return wpa_cli_cmd(ctrl, "NEIGHBOR_REP_REQUEST", 0, argc, argv);
  2222. }
  2223. static int wpa_cli_cmd_erp_flush(struct wpa_ctrl *ctrl, int argc, char *argv[])
  2224. {
  2225. return wpa_ctrl_command(ctrl, "ERP_FLUSH");
  2226. }
  2227. static int wpa_cli_cmd_mac_rand_scan(struct wpa_ctrl *ctrl, int argc,
  2228. char *argv[])
  2229. {
  2230. return wpa_cli_cmd(ctrl, "MAC_RAND_SCAN", 1, argc, argv);
  2231. }
  2232. static int wpa_cli_cmd_get_pref_freq_list(struct wpa_ctrl *ctrl, int argc,
  2233. char *argv[])
  2234. {
  2235. return wpa_cli_cmd(ctrl, "GET_PREF_FREQ_LIST", 1, argc, argv);
  2236. }
  2237. static int wpa_cli_cmd_p2p_lo_start(struct wpa_ctrl *ctrl, int argc,
  2238. char *argv[])
  2239. {
  2240. return wpa_cli_cmd(ctrl, "P2P_LO_START", 4, argc, argv);
  2241. }
  2242. static int wpa_cli_cmd_p2p_lo_stop(struct wpa_ctrl *ctrl, int argc,
  2243. char *argv[])
  2244. {
  2245. return wpa_cli_cmd(ctrl, "P2P_LO_STOP", 0, argc, argv);
  2246. }
  2247. #ifdef CONFIG_DPP
  2248. static int wpa_cli_cmd_dpp_qr_code(struct wpa_ctrl *ctrl, int argc,
  2249. char *argv[])
  2250. {
  2251. return wpa_cli_cmd(ctrl, "DPP_QR_CODE", 1, argc, argv);
  2252. }
  2253. static int wpa_cli_cmd_dpp_bootstrap_gen(struct wpa_ctrl *ctrl, int argc,
  2254. char *argv[])
  2255. {
  2256. return wpa_cli_cmd(ctrl, "DPP_BOOTSTRAP_GEN", 1, argc, argv);
  2257. }
  2258. static int wpa_cli_cmd_dpp_bootstrap_remove(struct wpa_ctrl *ctrl, int argc,
  2259. char *argv[])
  2260. {
  2261. return wpa_cli_cmd(ctrl, "DPP_BOOTSTRAP_REMOVE", 1, argc, argv);
  2262. }
  2263. static int wpa_cli_cmd_dpp_bootstrap_get_uri(struct wpa_ctrl *ctrl, int argc,
  2264. char *argv[])
  2265. {
  2266. return wpa_cli_cmd(ctrl, "DPP_BOOTSTRAP_GET_URI", 1, argc, argv);
  2267. }
  2268. static int wpa_cli_cmd_dpp_bootstrap_info(struct wpa_ctrl *ctrl, int argc,
  2269. char *argv[])
  2270. {
  2271. return wpa_cli_cmd(ctrl, "DPP_BOOTSTRAP_INFO", 1, argc, argv);
  2272. }
  2273. static int wpa_cli_cmd_dpp_auth_init(struct wpa_ctrl *ctrl, int argc,
  2274. char *argv[])
  2275. {
  2276. return wpa_cli_cmd(ctrl, "DPP_AUTH_INIT", 1, argc, argv);
  2277. }
  2278. static int wpa_cli_cmd_dpp_listen(struct wpa_ctrl *ctrl, int argc,
  2279. char *argv[])
  2280. {
  2281. return wpa_cli_cmd(ctrl, "DPP_LISTEN", 1, argc, argv);
  2282. }
  2283. static int wpa_cli_cmd_dpp_stop_listen(struct wpa_ctrl *ctrl, int argc,
  2284. char *argv[])
  2285. {
  2286. return wpa_ctrl_command(ctrl, "DPP_STOP_LISTEN");
  2287. }
  2288. static int wpa_cli_cmd_dpp_configurator_add(struct wpa_ctrl *ctrl, int argc,
  2289. char *argv[])
  2290. {
  2291. return wpa_cli_cmd(ctrl, "DPP_CONFIGURATOR_ADD", 0, argc, argv);
  2292. }
  2293. static int wpa_cli_cmd_dpp_configurator_remove(struct wpa_ctrl *ctrl, int argc,
  2294. char *argv[])
  2295. {
  2296. return wpa_cli_cmd(ctrl, "DPP_CONFIGURATOR_REMOVE", 1, argc, argv);
  2297. }
  2298. static int wpa_cli_cmd_dpp_pkex_add(struct wpa_ctrl *ctrl, int argc,
  2299. char *argv[])
  2300. {
  2301. return wpa_cli_cmd(ctrl, "DPP_PKEX_ADD", 1, argc, argv);
  2302. }
  2303. static int wpa_cli_cmd_dpp_pkex_remove(struct wpa_ctrl *ctrl, int argc,
  2304. char *argv[])
  2305. {
  2306. return wpa_cli_cmd(ctrl, "DPP_PKEX_REMOVE", 1, argc, argv);
  2307. }
  2308. #endif /* CONFIG_DPP */
  2309. enum wpa_cli_cmd_flags {
  2310. cli_cmd_flag_none = 0x00,
  2311. cli_cmd_flag_sensitive = 0x01
  2312. };
  2313. struct wpa_cli_cmd {
  2314. const char *cmd;
  2315. int (*handler)(struct wpa_ctrl *ctrl, int argc, char *argv[]);
  2316. char ** (*completion)(const char *str, int pos);
  2317. enum wpa_cli_cmd_flags flags;
  2318. const char *usage;
  2319. };
  2320. static const struct wpa_cli_cmd wpa_cli_commands[] = {
  2321. { "status", wpa_cli_cmd_status, NULL,
  2322. cli_cmd_flag_none,
  2323. "[verbose] = get current WPA/EAPOL/EAP status" },
  2324. { "ifname", wpa_cli_cmd_ifname, NULL,
  2325. cli_cmd_flag_none,
  2326. "= get current interface name" },
  2327. { "ping", wpa_cli_cmd_ping, NULL,
  2328. cli_cmd_flag_none,
  2329. "= pings wpa_supplicant" },
  2330. { "relog", wpa_cli_cmd_relog, NULL,
  2331. cli_cmd_flag_none,
  2332. "= re-open log-file (allow rolling logs)" },
  2333. { "note", wpa_cli_cmd_note, NULL,
  2334. cli_cmd_flag_none,
  2335. "<text> = add a note to wpa_supplicant debug log" },
  2336. { "mib", wpa_cli_cmd_mib, NULL,
  2337. cli_cmd_flag_none,
  2338. "= get MIB variables (dot1x, dot11)" },
  2339. { "help", wpa_cli_cmd_help, wpa_cli_complete_help,
  2340. cli_cmd_flag_none,
  2341. "[command] = show usage help" },
  2342. { "interface", wpa_cli_cmd_interface, NULL,
  2343. cli_cmd_flag_none,
  2344. "[ifname] = show interfaces/select interface" },
  2345. { "level", wpa_cli_cmd_level, NULL,
  2346. cli_cmd_flag_none,
  2347. "<debug level> = change debug level" },
  2348. { "license", wpa_cli_cmd_license, NULL,
  2349. cli_cmd_flag_none,
  2350. "= show full wpa_cli license" },
  2351. { "quit", wpa_cli_cmd_quit, NULL,
  2352. cli_cmd_flag_none,
  2353. "= exit wpa_cli" },
  2354. { "set", wpa_cli_cmd_set, wpa_cli_complete_set,
  2355. cli_cmd_flag_none,
  2356. "= set variables (shows list of variables when run without "
  2357. "arguments)" },
  2358. { "dump", wpa_cli_cmd_dump, NULL,
  2359. cli_cmd_flag_none,
  2360. "= dump config variables" },
  2361. { "get", wpa_cli_cmd_get, wpa_cli_complete_get,
  2362. cli_cmd_flag_none,
  2363. "<name> = get information" },
  2364. { "driver_flags", wpa_cli_cmd_driver_flags, NULL,
  2365. cli_cmd_flag_none,
  2366. "= list driver flags" },
  2367. { "logon", wpa_cli_cmd_logon, NULL,
  2368. cli_cmd_flag_none,
  2369. "= IEEE 802.1X EAPOL state machine logon" },
  2370. { "logoff", wpa_cli_cmd_logoff, NULL,
  2371. cli_cmd_flag_none,
  2372. "= IEEE 802.1X EAPOL state machine logoff" },
  2373. { "pmksa", wpa_cli_cmd_pmksa, NULL,
  2374. cli_cmd_flag_none,
  2375. "= show PMKSA cache" },
  2376. { "pmksa_flush", wpa_cli_cmd_pmksa_flush, NULL,
  2377. cli_cmd_flag_none,
  2378. "= flush PMKSA cache entries" },
  2379. #ifdef CONFIG_PMKSA_CACHE_EXTERNAL
  2380. { "pmksa_get", wpa_cli_cmd_pmksa_get, NULL,
  2381. cli_cmd_flag_none,
  2382. "<network_id> = fetch all stored PMKSA cache entries" },
  2383. { "pmksa_add", wpa_cli_cmd_pmksa_add, NULL,
  2384. cli_cmd_flag_sensitive,
  2385. "<network_id> <BSSID> <PMKID> <PMK> <reauth_time in seconds> <expiration in seconds> <akmp> <opportunistic> = store PMKSA cache entry from external storage" },
  2386. #ifdef CONFIG_MESH
  2387. { "mesh_pmksa_get", wpa_cli_mesh_cmd_pmksa_get, NULL,
  2388. cli_cmd_flag_none,
  2389. "<peer MAC address | any> = fetch all stored mesh PMKSA cache entries" },
  2390. { "mesh_pmksa_add", wpa_cli_mesh_cmd_pmksa_add, NULL,
  2391. cli_cmd_flag_sensitive,
  2392. "<BSSID> <PMKID> <PMK> <expiration in seconds> = store mesh PMKSA cache entry from external storage" },
  2393. #endif /* CONFIG_MESH */
  2394. #endif /* CONFIG_PMKSA_CACHE_EXTERNAL */
  2395. { "reassociate", wpa_cli_cmd_reassociate, NULL,
  2396. cli_cmd_flag_none,
  2397. "= force reassociation" },
  2398. { "reattach", wpa_cli_cmd_reattach, NULL,
  2399. cli_cmd_flag_none,
  2400. "= force reassociation back to the same BSS" },
  2401. { "preauthenticate", wpa_cli_cmd_preauthenticate, wpa_cli_complete_bss,
  2402. cli_cmd_flag_none,
  2403. "<BSSID> = force preauthentication" },
  2404. { "identity", wpa_cli_cmd_identity, wpa_cli_complete_network_id,
  2405. cli_cmd_flag_none,
  2406. "<network id> <identity> = configure identity for an SSID" },
  2407. { "password", wpa_cli_cmd_password, wpa_cli_complete_network_id,
  2408. cli_cmd_flag_sensitive,
  2409. "<network id> <password> = configure password for an SSID" },
  2410. { "new_password", wpa_cli_cmd_new_password,
  2411. wpa_cli_complete_network_id, cli_cmd_flag_sensitive,
  2412. "<network id> <password> = change password for an SSID" },
  2413. { "pin", wpa_cli_cmd_pin, wpa_cli_complete_network_id,
  2414. cli_cmd_flag_sensitive,
  2415. "<network id> <pin> = configure pin for an SSID" },
  2416. { "otp", wpa_cli_cmd_otp, wpa_cli_complete_network_id,
  2417. cli_cmd_flag_sensitive,
  2418. "<network id> <password> = configure one-time-password for an SSID"
  2419. },
  2420. { "passphrase", wpa_cli_cmd_passphrase, wpa_cli_complete_network_id,
  2421. cli_cmd_flag_sensitive,
  2422. "<network id> <passphrase> = configure private key passphrase\n"
  2423. " for an SSID" },
  2424. { "sim", wpa_cli_cmd_sim, wpa_cli_complete_network_id,
  2425. cli_cmd_flag_sensitive,
  2426. "<network id> <pin> = report SIM operation result" },
  2427. { "bssid", wpa_cli_cmd_bssid, wpa_cli_complete_network_id,
  2428. cli_cmd_flag_none,
  2429. "<network id> <BSSID> = set preferred BSSID for an SSID" },
  2430. { "blacklist", wpa_cli_cmd_blacklist, wpa_cli_complete_bss,
  2431. cli_cmd_flag_none,
  2432. "<BSSID> = add a BSSID to the blacklist\n"
  2433. "blacklist clear = clear the blacklist\n"
  2434. "blacklist = display the blacklist" },
  2435. { "log_level", wpa_cli_cmd_log_level, NULL,
  2436. cli_cmd_flag_none,
  2437. "<level> [<timestamp>] = update the log level/timestamp\n"
  2438. "log_level = display the current log level and log options" },
  2439. { "list_networks", wpa_cli_cmd_list_networks, NULL,
  2440. cli_cmd_flag_none,
  2441. "= list configured networks" },
  2442. { "select_network", wpa_cli_cmd_select_network,
  2443. wpa_cli_complete_network_id,
  2444. cli_cmd_flag_none,
  2445. "<network id> = select a network (disable others)" },
  2446. { "enable_network", wpa_cli_cmd_enable_network,
  2447. wpa_cli_complete_network_id,
  2448. cli_cmd_flag_none,
  2449. "<network id> = enable a network" },
  2450. { "disable_network", wpa_cli_cmd_disable_network,
  2451. wpa_cli_complete_network_id,
  2452. cli_cmd_flag_none,
  2453. "<network id> = disable a network" },
  2454. { "add_network", wpa_cli_cmd_add_network, NULL,
  2455. cli_cmd_flag_none,
  2456. "= add a network" },
  2457. { "remove_network", wpa_cli_cmd_remove_network,
  2458. wpa_cli_complete_network_id,
  2459. cli_cmd_flag_none,
  2460. "<network id> = remove a network" },
  2461. { "set_network", wpa_cli_cmd_set_network, wpa_cli_complete_network,
  2462. cli_cmd_flag_sensitive,
  2463. "<network id> <variable> <value> = set network variables (shows\n"
  2464. " list of variables when run without arguments)" },
  2465. { "get_network", wpa_cli_cmd_get_network, wpa_cli_complete_network,
  2466. cli_cmd_flag_none,
  2467. "<network id> <variable> = get network variables" },
  2468. { "dup_network", wpa_cli_cmd_dup_network, wpa_cli_complete_dup_network,
  2469. cli_cmd_flag_none,
  2470. "<src network id> <dst network id> <variable> = duplicate network variables"
  2471. },
  2472. { "list_creds", wpa_cli_cmd_list_creds, NULL,
  2473. cli_cmd_flag_none,
  2474. "= list configured credentials" },
  2475. { "add_cred", wpa_cli_cmd_add_cred, NULL,
  2476. cli_cmd_flag_none,
  2477. "= add a credential" },
  2478. { "remove_cred", wpa_cli_cmd_remove_cred, NULL,
  2479. cli_cmd_flag_none,
  2480. "<cred id> = remove a credential" },
  2481. { "set_cred", wpa_cli_cmd_set_cred, NULL,
  2482. cli_cmd_flag_sensitive,
  2483. "<cred id> <variable> <value> = set credential variables" },
  2484. { "get_cred", wpa_cli_cmd_get_cred, NULL,
  2485. cli_cmd_flag_none,
  2486. "<cred id> <variable> = get credential variables" },
  2487. { "save_config", wpa_cli_cmd_save_config, NULL,
  2488. cli_cmd_flag_none,
  2489. "= save the current configuration" },
  2490. { "disconnect", wpa_cli_cmd_disconnect, NULL,
  2491. cli_cmd_flag_none,
  2492. "= disconnect and wait for reassociate/reconnect command before\n"
  2493. " connecting" },
  2494. { "reconnect", wpa_cli_cmd_reconnect, NULL,
  2495. cli_cmd_flag_none,
  2496. "= like reassociate, but only takes effect if already disconnected"
  2497. },
  2498. { "scan", wpa_cli_cmd_scan, NULL,
  2499. cli_cmd_flag_none,
  2500. "= request new BSS scan" },
  2501. { "scan_results", wpa_cli_cmd_scan_results, NULL,
  2502. cli_cmd_flag_none,
  2503. "= get latest scan results" },
  2504. { "abort_scan", wpa_cli_cmd_abort_scan, NULL,
  2505. cli_cmd_flag_none,
  2506. "= request ongoing scan to be aborted" },
  2507. { "bss", wpa_cli_cmd_bss, wpa_cli_complete_bss,
  2508. cli_cmd_flag_none,
  2509. "<<idx> | <bssid>> = get detailed scan result info" },
  2510. { "get_capability", wpa_cli_cmd_get_capability,
  2511. wpa_cli_complete_get_capability, cli_cmd_flag_none,
  2512. "<eap/pairwise/group/key_mgmt/proto/auth_alg/channels/freq/modes> "
  2513. "= get capabilities" },
  2514. { "reconfigure", wpa_cli_cmd_reconfigure, NULL,
  2515. cli_cmd_flag_none,
  2516. "= force wpa_supplicant to re-read its configuration file" },
  2517. { "terminate", wpa_cli_cmd_terminate, NULL,
  2518. cli_cmd_flag_none,
  2519. "= terminate wpa_supplicant" },
  2520. { "interface_add", wpa_cli_cmd_interface_add, NULL,
  2521. cli_cmd_flag_none,
  2522. "<ifname> <confname> <driver> <ctrl_interface> <driver_param>\n"
  2523. " <bridge_name> <create> <type> = adds new interface, all "
  2524. "parameters but\n"
  2525. " <ifname> are optional. Supported types are station ('sta') and "
  2526. "AP ('ap')" },
  2527. { "interface_remove", wpa_cli_cmd_interface_remove, NULL,
  2528. cli_cmd_flag_none,
  2529. "<ifname> = removes the interface" },
  2530. { "interface_list", wpa_cli_cmd_interface_list, NULL,
  2531. cli_cmd_flag_none,
  2532. "= list available interfaces" },
  2533. { "ap_scan", wpa_cli_cmd_ap_scan, NULL,
  2534. cli_cmd_flag_none,
  2535. "<value> = set ap_scan parameter" },
  2536. { "scan_interval", wpa_cli_cmd_scan_interval, NULL,
  2537. cli_cmd_flag_none,
  2538. "<value> = set scan_interval parameter (in seconds)" },
  2539. { "bss_expire_age", wpa_cli_cmd_bss_expire_age, NULL,
  2540. cli_cmd_flag_none,
  2541. "<value> = set BSS expiration age parameter" },
  2542. { "bss_expire_count", wpa_cli_cmd_bss_expire_count, NULL,
  2543. cli_cmd_flag_none,
  2544. "<value> = set BSS expiration scan count parameter" },
  2545. { "bss_flush", wpa_cli_cmd_bss_flush, NULL,
  2546. cli_cmd_flag_none,
  2547. "<value> = set BSS flush age (0 by default)" },
  2548. { "ft_ds", wpa_cli_cmd_ft_ds, wpa_cli_complete_bss,
  2549. cli_cmd_flag_none,
  2550. "<addr> = request over-the-DS FT with <addr>" },
  2551. { "wps_pbc", wpa_cli_cmd_wps_pbc, wpa_cli_complete_bss,
  2552. cli_cmd_flag_none,
  2553. "[BSSID] = start Wi-Fi Protected Setup: Push Button Configuration" },
  2554. { "wps_pin", wpa_cli_cmd_wps_pin, wpa_cli_complete_bss,
  2555. cli_cmd_flag_sensitive,
  2556. "<BSSID> [PIN] = start WPS PIN method (returns PIN, if not "
  2557. "hardcoded)" },
  2558. { "wps_check_pin", wpa_cli_cmd_wps_check_pin, NULL,
  2559. cli_cmd_flag_sensitive,
  2560. "<PIN> = verify PIN checksum" },
  2561. { "wps_cancel", wpa_cli_cmd_wps_cancel, NULL, cli_cmd_flag_none,
  2562. "Cancels the pending WPS operation" },
  2563. #ifdef CONFIG_WPS_NFC
  2564. { "wps_nfc", wpa_cli_cmd_wps_nfc, wpa_cli_complete_bss,
  2565. cli_cmd_flag_none,
  2566. "[BSSID] = start Wi-Fi Protected Setup: NFC" },
  2567. { "wps_nfc_config_token", wpa_cli_cmd_wps_nfc_config_token, NULL,
  2568. cli_cmd_flag_none,
  2569. "<WPS|NDEF> = build configuration token" },
  2570. { "wps_nfc_token", wpa_cli_cmd_wps_nfc_token, NULL,
  2571. cli_cmd_flag_none,
  2572. "<WPS|NDEF> = create password token" },
  2573. { "wps_nfc_tag_read", wpa_cli_cmd_wps_nfc_tag_read, NULL,
  2574. cli_cmd_flag_sensitive,
  2575. "<hexdump of payload> = report read NFC tag with WPS data" },
  2576. { "nfc_get_handover_req", wpa_cli_cmd_nfc_get_handover_req, NULL,
  2577. cli_cmd_flag_none,
  2578. "<NDEF> <WPS> = create NFC handover request" },
  2579. { "nfc_get_handover_sel", wpa_cli_cmd_nfc_get_handover_sel, NULL,
  2580. cli_cmd_flag_none,
  2581. "<NDEF> <WPS> = create NFC handover select" },
  2582. { "nfc_report_handover", wpa_cli_cmd_nfc_report_handover, NULL,
  2583. cli_cmd_flag_none,
  2584. "<role> <type> <hexdump of req> <hexdump of sel> = report completed "
  2585. "NFC handover" },
  2586. #endif /* CONFIG_WPS_NFC */
  2587. { "wps_reg", wpa_cli_cmd_wps_reg, wpa_cli_complete_bss,
  2588. cli_cmd_flag_sensitive,
  2589. "<BSSID> <AP PIN> = start WPS Registrar to configure an AP" },
  2590. { "wps_ap_pin", wpa_cli_cmd_wps_ap_pin, NULL,
  2591. cli_cmd_flag_sensitive,
  2592. "[params..] = enable/disable AP PIN" },
  2593. { "wps_er_start", wpa_cli_cmd_wps_er_start, NULL,
  2594. cli_cmd_flag_none,
  2595. "[IP address] = start Wi-Fi Protected Setup External Registrar" },
  2596. { "wps_er_stop", wpa_cli_cmd_wps_er_stop, NULL,
  2597. cli_cmd_flag_none,
  2598. "= stop Wi-Fi Protected Setup External Registrar" },
  2599. { "wps_er_pin", wpa_cli_cmd_wps_er_pin, NULL,
  2600. cli_cmd_flag_sensitive,
  2601. "<UUID> <PIN> = add an Enrollee PIN to External Registrar" },
  2602. { "wps_er_pbc", wpa_cli_cmd_wps_er_pbc, NULL,
  2603. cli_cmd_flag_none,
  2604. "<UUID> = accept an Enrollee PBC using External Registrar" },
  2605. { "wps_er_learn", wpa_cli_cmd_wps_er_learn, NULL,
  2606. cli_cmd_flag_sensitive,
  2607. "<UUID> <PIN> = learn AP configuration" },
  2608. { "wps_er_set_config", wpa_cli_cmd_wps_er_set_config, NULL,
  2609. cli_cmd_flag_none,
  2610. "<UUID> <network id> = set AP configuration for enrolling" },
  2611. { "wps_er_config", wpa_cli_cmd_wps_er_config, NULL,
  2612. cli_cmd_flag_sensitive,
  2613. "<UUID> <PIN> <SSID> <auth> <encr> <key> = configure AP" },
  2614. #ifdef CONFIG_WPS_NFC
  2615. { "wps_er_nfc_config_token", wpa_cli_cmd_wps_er_nfc_config_token, NULL,
  2616. cli_cmd_flag_none,
  2617. "<WPS/NDEF> <UUID> = build NFC configuration token" },
  2618. #endif /* CONFIG_WPS_NFC */
  2619. { "ibss_rsn", wpa_cli_cmd_ibss_rsn, NULL,
  2620. cli_cmd_flag_none,
  2621. "<addr> = request RSN authentication with <addr> in IBSS" },
  2622. #ifdef CONFIG_AP
  2623. { "sta", wpa_cli_cmd_sta, wpa_cli_complete_sta,
  2624. cli_cmd_flag_none,
  2625. "<addr> = get information about an associated station (AP)" },
  2626. { "all_sta", wpa_cli_cmd_all_sta, NULL,
  2627. cli_cmd_flag_none,
  2628. "= get information about all associated stations (AP)" },
  2629. { "list_sta", wpa_cli_cmd_list_sta, NULL,
  2630. cli_cmd_flag_none,
  2631. "= list all stations (AP)" },
  2632. { "deauthenticate", wpa_cli_cmd_deauthenticate,
  2633. wpa_cli_complete_deauthenticate, cli_cmd_flag_none,
  2634. "<addr> = deauthenticate a station" },
  2635. { "disassociate", wpa_cli_cmd_disassociate,
  2636. wpa_cli_complete_disassociate, cli_cmd_flag_none,
  2637. "<addr> = disassociate a station" },
  2638. { "chan_switch", wpa_cli_cmd_chanswitch, NULL,
  2639. cli_cmd_flag_none,
  2640. "<cs_count> <freq> [sec_channel_offset=] [center_freq1=]"
  2641. " [center_freq2=] [bandwidth=] [blocktx] [ht|vht]"
  2642. " = CSA parameters" },
  2643. #endif /* CONFIG_AP */
  2644. { "suspend", wpa_cli_cmd_suspend, NULL, cli_cmd_flag_none,
  2645. "= notification of suspend/hibernate" },
  2646. { "resume", wpa_cli_cmd_resume, NULL, cli_cmd_flag_none,
  2647. "= notification of resume/thaw" },
  2648. #ifdef CONFIG_TESTING_OPTIONS
  2649. { "drop_sa", wpa_cli_cmd_drop_sa, NULL, cli_cmd_flag_none,
  2650. "= drop SA without deauth/disassoc (test command)" },
  2651. #endif /* CONFIG_TESTING_OPTIONS */
  2652. { "roam", wpa_cli_cmd_roam, wpa_cli_complete_bss,
  2653. cli_cmd_flag_none,
  2654. "<addr> = roam to the specified BSS" },
  2655. #ifdef CONFIG_MESH
  2656. { "mesh_interface_add", wpa_cli_cmd_mesh_interface_add, NULL,
  2657. cli_cmd_flag_none,
  2658. "[ifname] = Create a new mesh interface" },
  2659. { "mesh_group_add", wpa_cli_cmd_mesh_group_add, NULL,
  2660. cli_cmd_flag_none,
  2661. "<network id> = join a mesh network (disable others)" },
  2662. { "mesh_group_remove", wpa_cli_cmd_mesh_group_remove, NULL,
  2663. cli_cmd_flag_none,
  2664. "<ifname> = Remove mesh group interface" },
  2665. { "mesh_peer_remove", wpa_cli_cmd_mesh_peer_remove, NULL,
  2666. cli_cmd_flag_none,
  2667. "<addr> = Remove a mesh peer" },
  2668. { "mesh_peer_add", wpa_cli_cmd_mesh_peer_add, NULL,
  2669. cli_cmd_flag_none,
  2670. "<addr> [duration=<seconds>] = Add a mesh peer" },
  2671. #endif /* CONFIG_MESH */
  2672. #ifdef CONFIG_P2P
  2673. { "p2p_find", wpa_cli_cmd_p2p_find, wpa_cli_complete_p2p_find,
  2674. cli_cmd_flag_none,
  2675. "[timeout] [type=*] = find P2P Devices for up-to timeout seconds" },
  2676. { "p2p_stop_find", wpa_cli_cmd_p2p_stop_find, NULL, cli_cmd_flag_none,
  2677. "= stop P2P Devices search" },
  2678. { "p2p_asp_provision", wpa_cli_cmd_p2p_asp_provision, NULL,
  2679. cli_cmd_flag_none,
  2680. "<addr> adv_id=<adv_id> conncap=<conncap> [info=<infodata>] = provision with a P2P ASP Device" },
  2681. { "p2p_asp_provision_resp", wpa_cli_cmd_p2p_asp_provision_resp, NULL,
  2682. cli_cmd_flag_none,
  2683. "<addr> adv_id=<adv_id> [role<conncap>] [info=<infodata>] = provision with a P2P ASP Device" },
  2684. { "p2p_connect", wpa_cli_cmd_p2p_connect, wpa_cli_complete_p2p_connect,
  2685. cli_cmd_flag_none,
  2686. "<addr> <\"pbc\"|PIN> [ht40] = connect to a P2P Device" },
  2687. { "p2p_listen", wpa_cli_cmd_p2p_listen, NULL, cli_cmd_flag_none,
  2688. "[timeout] = listen for P2P Devices for up-to timeout seconds" },
  2689. { "p2p_group_remove", wpa_cli_cmd_p2p_group_remove,
  2690. wpa_cli_complete_p2p_group_remove, cli_cmd_flag_none,
  2691. "<ifname> = remove P2P group interface (terminate group if GO)" },
  2692. { "p2p_group_add", wpa_cli_cmd_p2p_group_add, NULL, cli_cmd_flag_none,
  2693. "[ht40] = add a new P2P group (local end as GO)" },
  2694. { "p2p_group_member", wpa_cli_cmd_p2p_group_member, NULL,
  2695. cli_cmd_flag_none,
  2696. "<dev_addr> = Get peer interface address on local GO using peer Device Address" },
  2697. { "p2p_prov_disc", wpa_cli_cmd_p2p_prov_disc,
  2698. wpa_cli_complete_p2p_peer, cli_cmd_flag_none,
  2699. "<addr> <method> = request provisioning discovery" },
  2700. { "p2p_get_passphrase", wpa_cli_cmd_p2p_get_passphrase, NULL,
  2701. cli_cmd_flag_none,
  2702. "= get the passphrase for a group (GO only)" },
  2703. { "p2p_serv_disc_req", wpa_cli_cmd_p2p_serv_disc_req,
  2704. wpa_cli_complete_p2p_peer, cli_cmd_flag_none,
  2705. "<addr> <TLVs> = schedule service discovery request" },
  2706. { "p2p_serv_disc_cancel_req", wpa_cli_cmd_p2p_serv_disc_cancel_req,
  2707. NULL, cli_cmd_flag_none,
  2708. "<id> = cancel pending service discovery request" },
  2709. { "p2p_serv_disc_resp", wpa_cli_cmd_p2p_serv_disc_resp, NULL,
  2710. cli_cmd_flag_none,
  2711. "<freq> <addr> <dialog token> <TLVs> = service discovery response" },
  2712. { "p2p_service_update", wpa_cli_cmd_p2p_service_update, NULL,
  2713. cli_cmd_flag_none,
  2714. "= indicate change in local services" },
  2715. { "p2p_serv_disc_external", wpa_cli_cmd_p2p_serv_disc_external, NULL,
  2716. cli_cmd_flag_none,
  2717. "<external> = set external processing of service discovery" },
  2718. { "p2p_service_flush", wpa_cli_cmd_p2p_service_flush, NULL,
  2719. cli_cmd_flag_none,
  2720. "= remove all stored service entries" },
  2721. { "p2p_service_add", wpa_cli_cmd_p2p_service_add, NULL,
  2722. cli_cmd_flag_none,
  2723. "<bonjour|upnp|asp> <query|version> <response|service> = add a local "
  2724. "service" },
  2725. { "p2p_service_rep", wpa_cli_cmd_p2p_service_rep, NULL,
  2726. cli_cmd_flag_none,
  2727. "asp <auto> <adv_id> <svc_state> <svc_string> [<svc_info>] = replace "
  2728. "local ASP service" },
  2729. { "p2p_service_del", wpa_cli_cmd_p2p_service_del, NULL,
  2730. cli_cmd_flag_none,
  2731. "<bonjour|upnp> <query|version> [|service] = remove a local "
  2732. "service" },
  2733. { "p2p_reject", wpa_cli_cmd_p2p_reject, wpa_cli_complete_p2p_peer,
  2734. cli_cmd_flag_none,
  2735. "<addr> = reject connection attempts from a specific peer" },
  2736. { "p2p_invite", wpa_cli_cmd_p2p_invite, NULL,
  2737. cli_cmd_flag_none,
  2738. "<cmd> [peer=addr] = invite peer" },
  2739. { "p2p_peers", wpa_cli_cmd_p2p_peers, NULL, cli_cmd_flag_none,
  2740. "[discovered] = list known (optionally, only fully discovered) P2P "
  2741. "peers" },
  2742. { "p2p_peer", wpa_cli_cmd_p2p_peer, wpa_cli_complete_p2p_peer,
  2743. cli_cmd_flag_none,
  2744. "<address> = show information about known P2P peer" },
  2745. { "p2p_set", wpa_cli_cmd_p2p_set, wpa_cli_complete_p2p_set,
  2746. cli_cmd_flag_none,
  2747. "<field> <value> = set a P2P parameter" },
  2748. { "p2p_flush", wpa_cli_cmd_p2p_flush, NULL, cli_cmd_flag_none,
  2749. "= flush P2P state" },
  2750. { "p2p_cancel", wpa_cli_cmd_p2p_cancel, NULL, cli_cmd_flag_none,
  2751. "= cancel P2P group formation" },
  2752. { "p2p_unauthorize", wpa_cli_cmd_p2p_unauthorize,
  2753. wpa_cli_complete_p2p_peer, cli_cmd_flag_none,
  2754. "<address> = unauthorize a peer" },
  2755. { "p2p_presence_req", wpa_cli_cmd_p2p_presence_req, NULL,
  2756. cli_cmd_flag_none,
  2757. "[<duration> <interval>] [<duration> <interval>] = request GO "
  2758. "presence" },
  2759. { "p2p_ext_listen", wpa_cli_cmd_p2p_ext_listen, NULL,
  2760. cli_cmd_flag_none,
  2761. "[<period> <interval>] = set extended listen timing" },
  2762. { "p2p_remove_client", wpa_cli_cmd_p2p_remove_client,
  2763. wpa_cli_complete_p2p_peer, cli_cmd_flag_none,
  2764. "<address|iface=address> = remove a peer from all groups" },
  2765. { "vendor_elem_add", wpa_cli_cmd_vendor_elem_add, NULL,
  2766. cli_cmd_flag_none,
  2767. "<frame id> <hexdump of elem(s)> = add vendor specific IEs to frame(s)\n"
  2768. VENDOR_ELEM_FRAME_ID },
  2769. { "vendor_elem_get", wpa_cli_cmd_vendor_elem_get, NULL,
  2770. cli_cmd_flag_none,
  2771. "<frame id> = get vendor specific IE(s) to frame(s)\n"
  2772. VENDOR_ELEM_FRAME_ID },
  2773. { "vendor_elem_remove", wpa_cli_cmd_vendor_elem_remove, NULL,
  2774. cli_cmd_flag_none,
  2775. "<frame id> <hexdump of elem(s)> = remove vendor specific IE(s) in frame(s)\n"
  2776. VENDOR_ELEM_FRAME_ID },
  2777. #endif /* CONFIG_P2P */
  2778. #ifdef CONFIG_WIFI_DISPLAY
  2779. { "wfd_subelem_set", wpa_cli_cmd_wfd_subelem_set, NULL,
  2780. cli_cmd_flag_none,
  2781. "<subelem> [contents] = set Wi-Fi Display subelement" },
  2782. { "wfd_subelem_get", wpa_cli_cmd_wfd_subelem_get, NULL,
  2783. cli_cmd_flag_none,
  2784. "<subelem> = get Wi-Fi Display subelement" },
  2785. #endif /* CONFIG_WIFI_DISPLAY */
  2786. #ifdef CONFIG_INTERWORKING
  2787. { "fetch_anqp", wpa_cli_cmd_fetch_anqp, NULL, cli_cmd_flag_none,
  2788. "= fetch ANQP information for all APs" },
  2789. { "stop_fetch_anqp", wpa_cli_cmd_stop_fetch_anqp, NULL,
  2790. cli_cmd_flag_none,
  2791. "= stop fetch_anqp operation" },
  2792. { "interworking_select", wpa_cli_cmd_interworking_select, NULL,
  2793. cli_cmd_flag_none,
  2794. "[auto] = perform Interworking network selection" },
  2795. { "interworking_connect", wpa_cli_cmd_interworking_connect,
  2796. wpa_cli_complete_bss, cli_cmd_flag_none,
  2797. "<BSSID> = connect using Interworking credentials" },
  2798. { "interworking_add_network", wpa_cli_cmd_interworking_add_network,
  2799. wpa_cli_complete_bss, cli_cmd_flag_none,
  2800. "<BSSID> = connect using Interworking credentials" },
  2801. { "anqp_get", wpa_cli_cmd_anqp_get, wpa_cli_complete_bss,
  2802. cli_cmd_flag_none,
  2803. "<addr> <info id>[,<info id>]... = request ANQP information" },
  2804. { "gas_request", wpa_cli_cmd_gas_request, wpa_cli_complete_bss,
  2805. cli_cmd_flag_none,
  2806. "<addr> <AdvProtoID> [QueryReq] = GAS request" },
  2807. { "gas_response_get", wpa_cli_cmd_gas_response_get,
  2808. wpa_cli_complete_bss, cli_cmd_flag_none,
  2809. "<addr> <dialog token> [start,len] = Fetch last GAS response" },
  2810. #endif /* CONFIG_INTERWORKING */
  2811. #ifdef CONFIG_HS20
  2812. { "hs20_anqp_get", wpa_cli_cmd_hs20_anqp_get, wpa_cli_complete_bss,
  2813. cli_cmd_flag_none,
  2814. "<addr> <subtype>[,<subtype>]... = request HS 2.0 ANQP information"
  2815. },
  2816. { "nai_home_realm_list", wpa_cli_cmd_get_nai_home_realm_list,
  2817. wpa_cli_complete_bss, cli_cmd_flag_none,
  2818. "<addr> <home realm> = get HS20 nai home realm list" },
  2819. { "hs20_icon_request", wpa_cli_cmd_hs20_icon_request,
  2820. wpa_cli_complete_bss, cli_cmd_flag_none,
  2821. "<addr> <icon name> = get Hotspot 2.0 OSU icon" },
  2822. { "fetch_osu", wpa_cli_cmd_fetch_osu, NULL, cli_cmd_flag_none,
  2823. "= fetch OSU provider information from all APs" },
  2824. { "cancel_fetch_osu", wpa_cli_cmd_cancel_fetch_osu, NULL,
  2825. cli_cmd_flag_none,
  2826. "= cancel fetch_osu command" },
  2827. #endif /* CONFIG_HS20 */
  2828. { "sta_autoconnect", wpa_cli_cmd_sta_autoconnect, NULL,
  2829. cli_cmd_flag_none,
  2830. "<0/1> = disable/enable automatic reconnection" },
  2831. { "tdls_discover", wpa_cli_cmd_tdls_discover, NULL,
  2832. cli_cmd_flag_none,
  2833. "<addr> = request TDLS discovery with <addr>" },
  2834. { "tdls_setup", wpa_cli_cmd_tdls_setup, NULL,
  2835. cli_cmd_flag_none,
  2836. "<addr> = request TDLS setup with <addr>" },
  2837. { "tdls_teardown", wpa_cli_cmd_tdls_teardown, NULL,
  2838. cli_cmd_flag_none,
  2839. "<addr> = tear down TDLS with <addr>" },
  2840. { "tdls_link_status", wpa_cli_cmd_tdls_link_status, NULL,
  2841. cli_cmd_flag_none,
  2842. "<addr> = TDLS link status with <addr>" },
  2843. { "wmm_ac_addts", wpa_cli_cmd_wmm_ac_addts, NULL,
  2844. cli_cmd_flag_none,
  2845. "<uplink/downlink/bidi> <tsid=0..7> <up=0..7> [nominal_msdu_size=#] "
  2846. "[mean_data_rate=#] [min_phy_rate=#] [sba=#] [fixed_nominal_msdu] "
  2847. "= add WMM-AC traffic stream" },
  2848. { "wmm_ac_delts", wpa_cli_cmd_wmm_ac_delts, NULL,
  2849. cli_cmd_flag_none,
  2850. "<tsid> = delete WMM-AC traffic stream" },
  2851. { "wmm_ac_status", wpa_cli_cmd_wmm_ac_status, NULL,
  2852. cli_cmd_flag_none,
  2853. "= show status for Wireless Multi-Media Admission-Control" },
  2854. { "tdls_chan_switch", wpa_cli_cmd_tdls_chan_switch, NULL,
  2855. cli_cmd_flag_none,
  2856. "<addr> <oper class> <freq> [sec_channel_offset=] [center_freq1=] "
  2857. "[center_freq2=] [bandwidth=] [ht|vht] = enable channel switching "
  2858. "with TDLS peer" },
  2859. { "tdls_cancel_chan_switch", wpa_cli_cmd_tdls_cancel_chan_switch, NULL,
  2860. cli_cmd_flag_none,
  2861. "<addr> = disable channel switching with TDLS peer <addr>" },
  2862. { "signal_poll", wpa_cli_cmd_signal_poll, NULL,
  2863. cli_cmd_flag_none,
  2864. "= get signal parameters" },
  2865. { "signal_monitor", wpa_cli_cmd_signal_monitor, NULL,
  2866. cli_cmd_flag_none,
  2867. "= set signal monitor parameters" },
  2868. { "pktcnt_poll", wpa_cli_cmd_pktcnt_poll, NULL,
  2869. cli_cmd_flag_none,
  2870. "= get TX/RX packet counters" },
  2871. { "reauthenticate", wpa_cli_cmd_reauthenticate, NULL,
  2872. cli_cmd_flag_none,
  2873. "= trigger IEEE 802.1X/EAPOL reauthentication" },
  2874. #ifdef CONFIG_AUTOSCAN
  2875. { "autoscan", wpa_cli_cmd_autoscan, NULL, cli_cmd_flag_none,
  2876. "[params] = Set or unset (if none) autoscan parameters" },
  2877. #endif /* CONFIG_AUTOSCAN */
  2878. #ifdef CONFIG_WNM
  2879. { "wnm_sleep", wpa_cli_cmd_wnm_sleep, NULL, cli_cmd_flag_none,
  2880. "<enter/exit> [interval=#] = enter/exit WNM-Sleep mode" },
  2881. { "wnm_bss_query", wpa_cli_cmd_wnm_bss_query, NULL, cli_cmd_flag_none,
  2882. "<query reason> [list]"
  2883. " [neighbor=<BSSID>,<BSSID information>,<operating class>,<channel number>,<PHY type>[,<hexdump of optional subelements>]"
  2884. " = Send BSS Transition Management Query" },
  2885. #endif /* CONFIG_WNM */
  2886. { "raw", wpa_cli_cmd_raw, NULL, cli_cmd_flag_sensitive,
  2887. "<params..> = Sent unprocessed command" },
  2888. { "flush", wpa_cli_cmd_flush, NULL, cli_cmd_flag_none,
  2889. "= flush wpa_supplicant state" },
  2890. #ifdef ANDROID
  2891. { "driver", wpa_cli_cmd_driver, NULL, cli_cmd_flag_none,
  2892. "<command> = driver private commands" },
  2893. #endif /* ANDROID */
  2894. { "radio_work", wpa_cli_cmd_radio_work, NULL, cli_cmd_flag_none,
  2895. "= radio_work <show/add/done>" },
  2896. { "vendor", wpa_cli_cmd_vendor, NULL, cli_cmd_flag_none,
  2897. "<vendor id> <command id> [<hex formatted command argument>] = Send vendor command"
  2898. },
  2899. { "neighbor_rep_request",
  2900. wpa_cli_cmd_neighbor_rep_request, NULL, cli_cmd_flag_none,
  2901. "[ssid=<SSID>] [lci] [civic] = Trigger request to AP for neighboring AP report (with optional given SSID in hex or enclosed in double quotes, default: current SSID; with optional LCI and location civic request)"
  2902. },
  2903. { "erp_flush", wpa_cli_cmd_erp_flush, NULL, cli_cmd_flag_none,
  2904. "= flush ERP keys" },
  2905. { "mac_rand_scan",
  2906. wpa_cli_cmd_mac_rand_scan, NULL, cli_cmd_flag_none,
  2907. "<scan|sched|pno|all> enable=<0/1> [addr=mac-address "
  2908. "mask=mac-address-mask] = scan MAC randomization"
  2909. },
  2910. { "get_pref_freq_list", wpa_cli_cmd_get_pref_freq_list, NULL,
  2911. cli_cmd_flag_none,
  2912. "<interface type> = retrieve preferred freq list for the specified interface type" },
  2913. { "p2p_lo_start", wpa_cli_cmd_p2p_lo_start, NULL,
  2914. cli_cmd_flag_none,
  2915. "<freq> <period> <interval> <count> = start P2P listen offload" },
  2916. { "p2p_lo_stop", wpa_cli_cmd_p2p_lo_stop, NULL,
  2917. cli_cmd_flag_none,
  2918. "= stop P2P listen offload" },
  2919. #ifdef CONFIG_DPP
  2920. { "dpp_qr_code", wpa_cli_cmd_dpp_qr_code, NULL, cli_cmd_flag_none,
  2921. "report a scanned DPP URI from a QR Code" },
  2922. { "dpp_bootstrap_gen", wpa_cli_cmd_dpp_bootstrap_gen, NULL,
  2923. cli_cmd_flag_sensitive,
  2924. "type=<qrcode> [chan=..] [mac=..] [info=..] [curve=..] [key=..] = generate DPP bootstrap information" },
  2925. { "dpp_bootstrap_remove", wpa_cli_cmd_dpp_bootstrap_remove, NULL,
  2926. cli_cmd_flag_none,
  2927. "*|<id> = remove DPP bootstrap information" },
  2928. { "dpp_bootstrap_get_uri", wpa_cli_cmd_dpp_bootstrap_get_uri, NULL,
  2929. cli_cmd_flag_none,
  2930. "<id> = get DPP bootstrap URI" },
  2931. { "dpp_bootstrap_info", wpa_cli_cmd_dpp_bootstrap_info, NULL,
  2932. cli_cmd_flag_none,
  2933. "<id> = show DPP bootstrap information" },
  2934. { "dpp_auth_init", wpa_cli_cmd_dpp_auth_init, NULL, cli_cmd_flag_none,
  2935. "peer=<id> [own=<id>] = initiate DPP bootstrapping" },
  2936. { "dpp_listen", wpa_cli_cmd_dpp_listen, NULL, cli_cmd_flag_none,
  2937. "<freq in MHz> = start DPP listen" },
  2938. { "dpp_stop_listen", wpa_cli_cmd_dpp_stop_listen, NULL,
  2939. cli_cmd_flag_none,
  2940. "= stop DPP listen" },
  2941. { "dpp_configurator_add", wpa_cli_cmd_dpp_configurator_add, NULL,
  2942. cli_cmd_flag_sensitive,
  2943. "[curve=..] [key=..] = add DPP configurator" },
  2944. { "dpp_configurator_remove", wpa_cli_cmd_dpp_configurator_remove, NULL,
  2945. cli_cmd_flag_none,
  2946. "*|<id> = remove DPP configurator" },
  2947. { "dpp_pkex_add", wpa_cli_cmd_dpp_pkex_add, NULL,
  2948. cli_cmd_flag_sensitive,
  2949. "add PKEX code" },
  2950. { "dpp_pkex_remove", wpa_cli_cmd_dpp_pkex_remove, NULL,
  2951. cli_cmd_flag_none,
  2952. "*|<id> = remove DPP pkex information" },
  2953. #endif /* CONFIG_DPP */
  2954. { NULL, NULL, NULL, cli_cmd_flag_none, NULL }
  2955. };
  2956. /*
  2957. * Prints command usage, lines are padded with the specified string.
  2958. */
  2959. static void print_cmd_help(const struct wpa_cli_cmd *cmd, const char *pad)
  2960. {
  2961. char c;
  2962. size_t n;
  2963. printf("%s%s ", pad, cmd->cmd);
  2964. for (n = 0; (c = cmd->usage[n]); n++) {
  2965. printf("%c", c);
  2966. if (c == '\n')
  2967. printf("%s", pad);
  2968. }
  2969. printf("\n");
  2970. }
  2971. static void print_help(const char *cmd)
  2972. {
  2973. int n;
  2974. printf("commands:\n");
  2975. for (n = 0; wpa_cli_commands[n].cmd; n++) {
  2976. if (cmd == NULL || str_starts(wpa_cli_commands[n].cmd, cmd))
  2977. print_cmd_help(&wpa_cli_commands[n], " ");
  2978. }
  2979. }
  2980. static int wpa_cli_edit_filter_history_cb(void *ctx, const char *cmd)
  2981. {
  2982. const char *c, *delim;
  2983. int n;
  2984. size_t len;
  2985. delim = os_strchr(cmd, ' ');
  2986. if (delim)
  2987. len = delim - cmd;
  2988. else
  2989. len = os_strlen(cmd);
  2990. for (n = 0; (c = wpa_cli_commands[n].cmd); n++) {
  2991. if (os_strncasecmp(cmd, c, len) == 0 && len == os_strlen(c))
  2992. return (wpa_cli_commands[n].flags &
  2993. cli_cmd_flag_sensitive);
  2994. }
  2995. return 0;
  2996. }
  2997. static char ** wpa_list_cmd_list(void)
  2998. {
  2999. char **res;
  3000. int i, count;
  3001. struct cli_txt_entry *e;
  3002. count = ARRAY_SIZE(wpa_cli_commands);
  3003. count += dl_list_len(&p2p_groups);
  3004. count += dl_list_len(&ifnames);
  3005. res = os_calloc(count + 1, sizeof(char *));
  3006. if (res == NULL)
  3007. return NULL;
  3008. for (i = 0; wpa_cli_commands[i].cmd; i++) {
  3009. res[i] = os_strdup(wpa_cli_commands[i].cmd);
  3010. if (res[i] == NULL)
  3011. break;
  3012. }
  3013. dl_list_for_each(e, &p2p_groups, struct cli_txt_entry, list) {
  3014. size_t len = 8 + os_strlen(e->txt);
  3015. res[i] = os_malloc(len);
  3016. if (res[i] == NULL)
  3017. break;
  3018. os_snprintf(res[i], len, "ifname=%s", e->txt);
  3019. i++;
  3020. }
  3021. dl_list_for_each(e, &ifnames, struct cli_txt_entry, list) {
  3022. res[i] = os_strdup(e->txt);
  3023. if (res[i] == NULL)
  3024. break;
  3025. i++;
  3026. }
  3027. return res;
  3028. }
  3029. static char ** wpa_cli_cmd_completion(const char *cmd, const char *str,
  3030. int pos)
  3031. {
  3032. int i;
  3033. for (i = 0; wpa_cli_commands[i].cmd; i++) {
  3034. if (os_strcasecmp(wpa_cli_commands[i].cmd, cmd) == 0) {
  3035. if (wpa_cli_commands[i].completion)
  3036. return wpa_cli_commands[i].completion(str,
  3037. pos);
  3038. edit_clear_line();
  3039. printf("\r%s\n", wpa_cli_commands[i].usage);
  3040. edit_redraw();
  3041. break;
  3042. }
  3043. }
  3044. return NULL;
  3045. }
  3046. static char ** wpa_cli_edit_completion_cb(void *ctx, const char *str, int pos)
  3047. {
  3048. char **res;
  3049. const char *end;
  3050. char *cmd;
  3051. if (pos > 7 && os_strncasecmp(str, "IFNAME=", 7) == 0) {
  3052. end = os_strchr(str, ' ');
  3053. if (end && pos > end - str) {
  3054. pos -= end - str + 1;
  3055. str = end + 1;
  3056. }
  3057. }
  3058. end = os_strchr(str, ' ');
  3059. if (end == NULL || str + pos < end)
  3060. return wpa_list_cmd_list();
  3061. cmd = os_malloc(pos + 1);
  3062. if (cmd == NULL)
  3063. return NULL;
  3064. os_memcpy(cmd, str, pos);
  3065. cmd[end - str] = '\0';
  3066. res = wpa_cli_cmd_completion(cmd, str, pos);
  3067. os_free(cmd);
  3068. return res;
  3069. }
  3070. static int wpa_request(struct wpa_ctrl *ctrl, int argc, char *argv[])
  3071. {
  3072. const struct wpa_cli_cmd *cmd, *match = NULL;
  3073. int count;
  3074. int ret = 0;
  3075. if (argc > 1 && os_strncasecmp(argv[0], "IFNAME=", 7) == 0) {
  3076. ifname_prefix = argv[0] + 7;
  3077. argv = &argv[1];
  3078. argc--;
  3079. } else
  3080. ifname_prefix = NULL;
  3081. if (argc == 0)
  3082. return -1;
  3083. count = 0;
  3084. cmd = wpa_cli_commands;
  3085. while (cmd->cmd) {
  3086. if (os_strncasecmp(cmd->cmd, argv[0], os_strlen(argv[0])) == 0)
  3087. {
  3088. match = cmd;
  3089. if (os_strcasecmp(cmd->cmd, argv[0]) == 0) {
  3090. /* we have an exact match */
  3091. count = 1;
  3092. break;
  3093. }
  3094. count++;
  3095. }
  3096. cmd++;
  3097. }
  3098. if (count > 1) {
  3099. printf("Ambiguous command '%s'; possible commands:", argv[0]);
  3100. cmd = wpa_cli_commands;
  3101. while (cmd->cmd) {
  3102. if (os_strncasecmp(cmd->cmd, argv[0],
  3103. os_strlen(argv[0])) == 0) {
  3104. printf(" %s", cmd->cmd);
  3105. }
  3106. cmd++;
  3107. }
  3108. printf("\n");
  3109. ret = 1;
  3110. } else if (count == 0) {
  3111. printf("Unknown command '%s'\n", argv[0]);
  3112. ret = 1;
  3113. } else {
  3114. ret = match->handler(ctrl, argc - 1, &argv[1]);
  3115. }
  3116. return ret;
  3117. }
  3118. static int wpa_cli_exec(const char *program, const char *arg1,
  3119. const char *arg2)
  3120. {
  3121. char *arg;
  3122. size_t len;
  3123. int res;
  3124. /* If no interface is specified, set the global */
  3125. if (!arg1)
  3126. arg1 = "global";
  3127. len = os_strlen(arg1) + os_strlen(arg2) + 2;
  3128. arg = os_malloc(len);
  3129. if (arg == NULL)
  3130. return -1;
  3131. os_snprintf(arg, len, "%s %s", arg1, arg2);
  3132. res = os_exec(program, arg, 1);
  3133. os_free(arg);
  3134. return res;
  3135. }
  3136. static void wpa_cli_action_process(const char *msg)
  3137. {
  3138. const char *pos;
  3139. char *copy = NULL, *id, *pos2;
  3140. const char *ifname = ctrl_ifname;
  3141. char ifname_buf[100];
  3142. if (eloop_terminated())
  3143. return;
  3144. pos = msg;
  3145. if (os_strncmp(pos, "IFNAME=", 7) == 0) {
  3146. const char *end;
  3147. end = os_strchr(pos + 7, ' ');
  3148. if (end && (unsigned int) (end - pos) < sizeof(ifname_buf)) {
  3149. pos += 7;
  3150. os_memcpy(ifname_buf, pos, end - pos);
  3151. ifname_buf[end - pos] = '\0';
  3152. ifname = ifname_buf;
  3153. pos = end + 1;
  3154. }
  3155. }
  3156. if (*pos == '<') {
  3157. const char *prev = pos;
  3158. /* skip priority */
  3159. pos = os_strchr(pos, '>');
  3160. if (pos)
  3161. pos++;
  3162. else
  3163. pos = prev;
  3164. }
  3165. if (str_starts(pos, WPA_EVENT_CONNECTED)) {
  3166. int new_id = -1;
  3167. os_unsetenv("WPA_ID");
  3168. os_unsetenv("WPA_ID_STR");
  3169. os_unsetenv("WPA_CTRL_DIR");
  3170. pos = os_strstr(pos, "[id=");
  3171. if (pos)
  3172. copy = os_strdup(pos + 4);
  3173. if (copy) {
  3174. pos2 = id = copy;
  3175. while (*pos2 && *pos2 != ' ')
  3176. pos2++;
  3177. *pos2++ = '\0';
  3178. new_id = atoi(id);
  3179. os_setenv("WPA_ID", id, 1);
  3180. while (*pos2 && *pos2 != '=')
  3181. pos2++;
  3182. if (*pos2 == '=')
  3183. pos2++;
  3184. id = pos2;
  3185. while (*pos2 && *pos2 != ']')
  3186. pos2++;
  3187. *pos2 = '\0';
  3188. os_setenv("WPA_ID_STR", id, 1);
  3189. os_free(copy);
  3190. }
  3191. os_setenv("WPA_CTRL_DIR", ctrl_iface_dir, 1);
  3192. if (wpa_cli_connected <= 0 || new_id != wpa_cli_last_id) {
  3193. wpa_cli_connected = 1;
  3194. wpa_cli_last_id = new_id;
  3195. wpa_cli_exec(action_file, ifname, "CONNECTED");
  3196. }
  3197. } else if (str_starts(pos, WPA_EVENT_DISCONNECTED)) {
  3198. if (wpa_cli_connected) {
  3199. wpa_cli_connected = 0;
  3200. wpa_cli_exec(action_file, ifname, "DISCONNECTED");
  3201. }
  3202. } else if (str_starts(pos, AP_EVENT_ENABLED)) {
  3203. wpa_cli_exec(action_file, ctrl_ifname, pos);
  3204. } else if (str_starts(pos, AP_EVENT_DISABLED)) {
  3205. wpa_cli_exec(action_file, ctrl_ifname, pos);
  3206. } else if (str_starts(pos, MESH_GROUP_STARTED)) {
  3207. wpa_cli_exec(action_file, ctrl_ifname, pos);
  3208. } else if (str_starts(pos, MESH_GROUP_REMOVED)) {
  3209. wpa_cli_exec(action_file, ctrl_ifname, pos);
  3210. } else if (str_starts(pos, MESH_PEER_CONNECTED)) {
  3211. wpa_cli_exec(action_file, ctrl_ifname, pos);
  3212. } else if (str_starts(pos, MESH_PEER_DISCONNECTED)) {
  3213. wpa_cli_exec(action_file, ctrl_ifname, pos);
  3214. } else if (str_starts(pos, P2P_EVENT_GROUP_STARTED)) {
  3215. wpa_cli_exec(action_file, ifname, pos);
  3216. } else if (str_starts(pos, P2P_EVENT_GROUP_REMOVED)) {
  3217. wpa_cli_exec(action_file, ifname, pos);
  3218. } else if (str_starts(pos, P2P_EVENT_CROSS_CONNECT_ENABLE)) {
  3219. wpa_cli_exec(action_file, ifname, pos);
  3220. } else if (str_starts(pos, P2P_EVENT_CROSS_CONNECT_DISABLE)) {
  3221. wpa_cli_exec(action_file, ifname, pos);
  3222. } else if (str_starts(pos, P2P_EVENT_GO_NEG_FAILURE)) {
  3223. wpa_cli_exec(action_file, ifname, pos);
  3224. } else if (str_starts(pos, WPS_EVENT_SUCCESS)) {
  3225. wpa_cli_exec(action_file, ifname, pos);
  3226. } else if (str_starts(pos, WPS_EVENT_ACTIVE)) {
  3227. wpa_cli_exec(action_file, ifname, pos);
  3228. } else if (str_starts(pos, WPS_EVENT_TIMEOUT)) {
  3229. wpa_cli_exec(action_file, ifname, pos);
  3230. } else if (str_starts(pos, WPS_EVENT_FAIL)) {
  3231. wpa_cli_exec(action_file, ifname, pos);
  3232. } else if (str_starts(pos, AP_STA_CONNECTED)) {
  3233. wpa_cli_exec(action_file, ifname, pos);
  3234. } else if (str_starts(pos, AP_STA_DISCONNECTED)) {
  3235. wpa_cli_exec(action_file, ifname, pos);
  3236. } else if (str_starts(pos, ESS_DISASSOC_IMMINENT)) {
  3237. wpa_cli_exec(action_file, ifname, pos);
  3238. } else if (str_starts(pos, HS20_SUBSCRIPTION_REMEDIATION)) {
  3239. wpa_cli_exec(action_file, ifname, pos);
  3240. } else if (str_starts(pos, HS20_DEAUTH_IMMINENT_NOTICE)) {
  3241. wpa_cli_exec(action_file, ifname, pos);
  3242. } else if (str_starts(pos, WPA_EVENT_TERMINATING)) {
  3243. printf("wpa_supplicant is terminating - stop monitoring\n");
  3244. wpa_cli_quit = 1;
  3245. }
  3246. }
  3247. #ifndef CONFIG_ANSI_C_EXTRA
  3248. static void wpa_cli_action_cb(char *msg, size_t len)
  3249. {
  3250. wpa_cli_action_process(msg);
  3251. }
  3252. #endif /* CONFIG_ANSI_C_EXTRA */
  3253. static void wpa_cli_reconnect(void)
  3254. {
  3255. wpa_cli_close_connection();
  3256. if (wpa_cli_open_connection(ctrl_ifname, 1) < 0)
  3257. return;
  3258. if (interactive) {
  3259. edit_clear_line();
  3260. printf("\rConnection to wpa_supplicant re-established\n");
  3261. edit_redraw();
  3262. update_stations(ctrl_conn);
  3263. }
  3264. }
  3265. static void cli_event(const char *str)
  3266. {
  3267. const char *start, *s;
  3268. start = os_strchr(str, '>');
  3269. if (start == NULL)
  3270. return;
  3271. start++;
  3272. if (str_starts(start, WPA_EVENT_BSS_ADDED)) {
  3273. s = os_strchr(start, ' ');
  3274. if (s == NULL)
  3275. return;
  3276. s = os_strchr(s + 1, ' ');
  3277. if (s == NULL)
  3278. return;
  3279. cli_txt_list_add(&bsses, s + 1);
  3280. return;
  3281. }
  3282. if (str_starts(start, WPA_EVENT_BSS_REMOVED)) {
  3283. s = os_strchr(start, ' ');
  3284. if (s == NULL)
  3285. return;
  3286. s = os_strchr(s + 1, ' ');
  3287. if (s == NULL)
  3288. return;
  3289. cli_txt_list_del_addr(&bsses, s + 1);
  3290. return;
  3291. }
  3292. #ifdef CONFIG_P2P
  3293. if (str_starts(start, P2P_EVENT_DEVICE_FOUND)) {
  3294. s = os_strstr(start, " p2p_dev_addr=");
  3295. if (s == NULL)
  3296. return;
  3297. cli_txt_list_add_addr(&p2p_peers, s + 14);
  3298. return;
  3299. }
  3300. if (str_starts(start, P2P_EVENT_DEVICE_LOST)) {
  3301. s = os_strstr(start, " p2p_dev_addr=");
  3302. if (s == NULL)
  3303. return;
  3304. cli_txt_list_del_addr(&p2p_peers, s + 14);
  3305. return;
  3306. }
  3307. if (str_starts(start, P2P_EVENT_GROUP_STARTED)) {
  3308. s = os_strchr(start, ' ');
  3309. if (s == NULL)
  3310. return;
  3311. cli_txt_list_add_word(&p2p_groups, s + 1, ' ');
  3312. return;
  3313. }
  3314. if (str_starts(start, P2P_EVENT_GROUP_REMOVED)) {
  3315. s = os_strchr(start, ' ');
  3316. if (s == NULL)
  3317. return;
  3318. cli_txt_list_del_word(&p2p_groups, s + 1, ' ');
  3319. return;
  3320. }
  3321. #endif /* CONFIG_P2P */
  3322. }
  3323. static int check_terminating(const char *msg)
  3324. {
  3325. const char *pos = msg;
  3326. if (*pos == '<') {
  3327. /* skip priority */
  3328. pos = os_strchr(pos, '>');
  3329. if (pos)
  3330. pos++;
  3331. else
  3332. pos = msg;
  3333. }
  3334. if (str_starts(pos, WPA_EVENT_TERMINATING) && ctrl_conn) {
  3335. edit_clear_line();
  3336. printf("\rConnection to wpa_supplicant lost - trying to "
  3337. "reconnect\n");
  3338. edit_redraw();
  3339. wpa_cli_attached = 0;
  3340. wpa_cli_close_connection();
  3341. return 1;
  3342. }
  3343. return 0;
  3344. }
  3345. static void wpa_cli_recv_pending(struct wpa_ctrl *ctrl, int action_monitor)
  3346. {
  3347. if (ctrl_conn == NULL) {
  3348. wpa_cli_reconnect();
  3349. return;
  3350. }
  3351. while (wpa_ctrl_pending(ctrl) > 0) {
  3352. char buf[4096];
  3353. size_t len = sizeof(buf) - 1;
  3354. if (wpa_ctrl_recv(ctrl, buf, &len) == 0) {
  3355. buf[len] = '\0';
  3356. if (action_monitor)
  3357. wpa_cli_action_process(buf);
  3358. else {
  3359. cli_event(buf);
  3360. if (wpa_cli_show_event(buf)) {
  3361. edit_clear_line();
  3362. printf("\r%s\n", buf);
  3363. edit_redraw();
  3364. }
  3365. if (interactive && check_terminating(buf) > 0)
  3366. return;
  3367. }
  3368. } else {
  3369. printf("Could not read pending message.\n");
  3370. break;
  3371. }
  3372. }
  3373. if (wpa_ctrl_pending(ctrl) < 0) {
  3374. printf("Connection to wpa_supplicant lost - trying to "
  3375. "reconnect\n");
  3376. wpa_cli_reconnect();
  3377. }
  3378. }
  3379. static void wpa_cli_ping(void *eloop_ctx, void *timeout_ctx)
  3380. {
  3381. if (ctrl_conn) {
  3382. int res;
  3383. char *prefix = ifname_prefix;
  3384. ifname_prefix = NULL;
  3385. res = _wpa_ctrl_command(ctrl_conn, "PING", 0);
  3386. ifname_prefix = prefix;
  3387. if (res) {
  3388. printf("Connection to wpa_supplicant lost - trying to "
  3389. "reconnect\n");
  3390. wpa_cli_close_connection();
  3391. }
  3392. }
  3393. if (!ctrl_conn)
  3394. wpa_cli_reconnect();
  3395. eloop_register_timeout(ping_interval, 0, wpa_cli_ping, NULL, NULL);
  3396. }
  3397. static void wpa_cli_mon_receive(int sock, void *eloop_ctx, void *sock_ctx)
  3398. {
  3399. wpa_cli_recv_pending(mon_conn, 0);
  3400. }
  3401. static void wpa_cli_edit_cmd_cb(void *ctx, char *cmd)
  3402. {
  3403. char *argv[max_args];
  3404. int argc;
  3405. argc = tokenize_cmd(cmd, argv);
  3406. if (argc)
  3407. wpa_request(ctrl_conn, argc, argv);
  3408. }
  3409. static void wpa_cli_edit_eof_cb(void *ctx)
  3410. {
  3411. eloop_terminate();
  3412. }
  3413. static int warning_displayed = 0;
  3414. static char *hfile = NULL;
  3415. static int edit_started = 0;
  3416. static void start_edit(void)
  3417. {
  3418. char *home;
  3419. char *ps = NULL;
  3420. #ifdef CONFIG_CTRL_IFACE_UDP_REMOTE
  3421. ps = wpa_ctrl_get_remote_ifname(ctrl_conn);
  3422. #endif /* CONFIG_CTRL_IFACE_UDP_REMOTE */
  3423. #ifdef CONFIG_WPA_CLI_HISTORY_DIR
  3424. home = CONFIG_WPA_CLI_HISTORY_DIR;
  3425. #else /* CONFIG_WPA_CLI_HISTORY_DIR */
  3426. home = getenv("HOME");
  3427. #endif /* CONFIG_WPA_CLI_HISTORY_DIR */
  3428. if (home) {
  3429. const char *fname = ".wpa_cli_history";
  3430. int hfile_len = os_strlen(home) + 1 + os_strlen(fname) + 1;
  3431. hfile = os_malloc(hfile_len);
  3432. if (hfile)
  3433. os_snprintf(hfile, hfile_len, "%s/%s", home, fname);
  3434. }
  3435. if (edit_init(wpa_cli_edit_cmd_cb, wpa_cli_edit_eof_cb,
  3436. wpa_cli_edit_completion_cb, NULL, hfile, ps) < 0) {
  3437. eloop_terminate();
  3438. return;
  3439. }
  3440. edit_started = 1;
  3441. eloop_register_timeout(ping_interval, 0, wpa_cli_ping, NULL, NULL);
  3442. }
  3443. static void update_bssid_list(struct wpa_ctrl *ctrl)
  3444. {
  3445. char buf[4096];
  3446. size_t len = sizeof(buf);
  3447. int ret;
  3448. const char *cmd = "BSS RANGE=ALL MASK=0x2";
  3449. char *pos, *end;
  3450. if (ctrl == NULL)
  3451. return;
  3452. ret = wpa_ctrl_request(ctrl, cmd, os_strlen(cmd), buf, &len, NULL);
  3453. if (ret < 0)
  3454. return;
  3455. buf[len] = '\0';
  3456. pos = buf;
  3457. while (pos) {
  3458. pos = os_strstr(pos, "bssid=");
  3459. if (pos == NULL)
  3460. break;
  3461. pos += 6;
  3462. end = os_strchr(pos, '\n');
  3463. if (end == NULL)
  3464. break;
  3465. *end = '\0';
  3466. cli_txt_list_add(&bsses, pos);
  3467. pos = end + 1;
  3468. }
  3469. }
  3470. static void update_ifnames(struct wpa_ctrl *ctrl)
  3471. {
  3472. char buf[4096];
  3473. size_t len = sizeof(buf);
  3474. int ret;
  3475. const char *cmd = "INTERFACES";
  3476. char *pos, *end;
  3477. char txt[200];
  3478. cli_txt_list_flush(&ifnames);
  3479. if (ctrl == NULL)
  3480. return;
  3481. ret = wpa_ctrl_request(ctrl, cmd, os_strlen(cmd), buf, &len, NULL);
  3482. if (ret < 0)
  3483. return;
  3484. buf[len] = '\0';
  3485. pos = buf;
  3486. while (pos) {
  3487. end = os_strchr(pos, '\n');
  3488. if (end == NULL)
  3489. break;
  3490. *end = '\0';
  3491. ret = os_snprintf(txt, sizeof(txt), "ifname=%s", pos);
  3492. if (!os_snprintf_error(sizeof(txt), ret))
  3493. cli_txt_list_add(&ifnames, txt);
  3494. pos = end + 1;
  3495. }
  3496. }
  3497. static void update_networks(struct wpa_ctrl *ctrl)
  3498. {
  3499. char buf[4096];
  3500. size_t len = sizeof(buf);
  3501. int ret;
  3502. const char *cmd = "LIST_NETWORKS";
  3503. char *pos, *end;
  3504. int header = 1;
  3505. cli_txt_list_flush(&networks);
  3506. if (ctrl == NULL)
  3507. return;
  3508. ret = wpa_ctrl_request(ctrl, cmd, os_strlen(cmd), buf, &len, NULL);
  3509. if (ret < 0)
  3510. return;
  3511. buf[len] = '\0';
  3512. pos = buf;
  3513. while (pos) {
  3514. end = os_strchr(pos, '\n');
  3515. if (end == NULL)
  3516. break;
  3517. *end = '\0';
  3518. if (!header)
  3519. cli_txt_list_add_word(&networks, pos, '\t');
  3520. header = 0;
  3521. pos = end + 1;
  3522. }
  3523. }
  3524. static void update_stations(struct wpa_ctrl *ctrl)
  3525. {
  3526. #ifdef CONFIG_AP
  3527. char addr[32], cmd[64];
  3528. if (!ctrl || !interactive)
  3529. return;
  3530. cli_txt_list_flush(&stations);
  3531. if (wpa_ctrl_command_sta(ctrl, "STA-FIRST", addr, sizeof(addr), 0))
  3532. return;
  3533. do {
  3534. if (os_strcmp(addr, "") != 0)
  3535. cli_txt_list_add(&stations, addr);
  3536. os_snprintf(cmd, sizeof(cmd), "STA-NEXT %s", addr);
  3537. } while (wpa_ctrl_command_sta(ctrl, cmd, addr, sizeof(addr), 0) == 0);
  3538. #endif /* CONFIG_AP */
  3539. }
  3540. static void try_connection(void *eloop_ctx, void *timeout_ctx)
  3541. {
  3542. if (ctrl_conn)
  3543. goto done;
  3544. if (ctrl_ifname == NULL)
  3545. ctrl_ifname = wpa_cli_get_default_ifname();
  3546. if (wpa_cli_open_connection(ctrl_ifname, 1)) {
  3547. if (!warning_displayed) {
  3548. printf("Could not connect to wpa_supplicant: "
  3549. "%s - re-trying\n",
  3550. ctrl_ifname ? ctrl_ifname : "(nil)");
  3551. warning_displayed = 1;
  3552. }
  3553. eloop_register_timeout(1, 0, try_connection, NULL, NULL);
  3554. return;
  3555. }
  3556. update_bssid_list(ctrl_conn);
  3557. update_networks(ctrl_conn);
  3558. update_stations(ctrl_conn);
  3559. if (warning_displayed)
  3560. printf("Connection established.\n");
  3561. done:
  3562. start_edit();
  3563. }
  3564. static void wpa_cli_interactive(void)
  3565. {
  3566. printf("\nInteractive mode\n\n");
  3567. eloop_register_timeout(0, 0, try_connection, NULL, NULL);
  3568. eloop_run();
  3569. eloop_cancel_timeout(try_connection, NULL, NULL);
  3570. cli_txt_list_flush(&p2p_peers);
  3571. cli_txt_list_flush(&p2p_groups);
  3572. cli_txt_list_flush(&bsses);
  3573. cli_txt_list_flush(&ifnames);
  3574. cli_txt_list_flush(&networks);
  3575. if (edit_started)
  3576. edit_deinit(hfile, wpa_cli_edit_filter_history_cb);
  3577. os_free(hfile);
  3578. eloop_cancel_timeout(wpa_cli_ping, NULL, NULL);
  3579. wpa_cli_close_connection();
  3580. }
  3581. static void wpa_cli_action_ping(void *eloop_ctx, void *timeout_ctx)
  3582. {
  3583. struct wpa_ctrl *ctrl = eloop_ctx;
  3584. char buf[256];
  3585. size_t len;
  3586. /* verify that connection is still working */
  3587. len = sizeof(buf) - 1;
  3588. if (wpa_ctrl_request(ctrl, "PING", 4, buf, &len,
  3589. wpa_cli_action_cb) < 0 ||
  3590. len < 4 || os_memcmp(buf, "PONG", 4) != 0) {
  3591. printf("wpa_supplicant did not reply to PING command - exiting\n");
  3592. eloop_terminate();
  3593. return;
  3594. }
  3595. eloop_register_timeout(ping_interval, 0, wpa_cli_action_ping,
  3596. ctrl, NULL);
  3597. }
  3598. static void wpa_cli_action_receive(int sock, void *eloop_ctx, void *sock_ctx)
  3599. {
  3600. struct wpa_ctrl *ctrl = eloop_ctx;
  3601. wpa_cli_recv_pending(ctrl, 1);
  3602. }
  3603. static void wpa_cli_action(struct wpa_ctrl *ctrl)
  3604. {
  3605. #ifdef CONFIG_ANSI_C_EXTRA
  3606. /* TODO: ANSI C version(?) */
  3607. printf("Action processing not supported in ANSI C build.\n");
  3608. #else /* CONFIG_ANSI_C_EXTRA */
  3609. int fd;
  3610. fd = wpa_ctrl_get_fd(ctrl);
  3611. eloop_register_timeout(ping_interval, 0, wpa_cli_action_ping,
  3612. ctrl, NULL);
  3613. eloop_register_read_sock(fd, wpa_cli_action_receive, ctrl, NULL);
  3614. eloop_run();
  3615. eloop_cancel_timeout(wpa_cli_action_ping, ctrl, NULL);
  3616. eloop_unregister_read_sock(fd);
  3617. #endif /* CONFIG_ANSI_C_EXTRA */
  3618. }
  3619. static void wpa_cli_cleanup(void)
  3620. {
  3621. wpa_cli_close_connection();
  3622. if (pid_file)
  3623. os_daemonize_terminate(pid_file);
  3624. os_program_deinit();
  3625. }
  3626. static void wpa_cli_terminate(int sig, void *ctx)
  3627. {
  3628. eloop_terminate();
  3629. }
  3630. static char * wpa_cli_get_default_ifname(void)
  3631. {
  3632. char *ifname = NULL;
  3633. #ifdef ANDROID
  3634. char ifprop[PROPERTY_VALUE_MAX];
  3635. if (property_get("wifi.interface", ifprop, NULL) != 0) {
  3636. ifname = os_strdup(ifprop);
  3637. printf("Using interface '%s'\n", ifname ? ifname : "N/A");
  3638. }
  3639. #else /* ANDROID */
  3640. #ifdef CONFIG_CTRL_IFACE_UNIX
  3641. struct dirent *dent;
  3642. DIR *dir = opendir(ctrl_iface_dir);
  3643. if (!dir) {
  3644. return NULL;
  3645. }
  3646. while ((dent = readdir(dir))) {
  3647. #ifdef _DIRENT_HAVE_D_TYPE
  3648. /*
  3649. * Skip the file if it is not a socket. Also accept
  3650. * DT_UNKNOWN (0) in case the C library or underlying
  3651. * file system does not support d_type.
  3652. */
  3653. if (dent->d_type != DT_SOCK && dent->d_type != DT_UNKNOWN)
  3654. continue;
  3655. #endif /* _DIRENT_HAVE_D_TYPE */
  3656. if (os_strcmp(dent->d_name, ".") == 0 ||
  3657. os_strcmp(dent->d_name, "..") == 0)
  3658. continue;
  3659. printf("Selected interface '%s'\n", dent->d_name);
  3660. ifname = os_strdup(dent->d_name);
  3661. break;
  3662. }
  3663. closedir(dir);
  3664. #endif /* CONFIG_CTRL_IFACE_UNIX */
  3665. #ifdef CONFIG_CTRL_IFACE_NAMED_PIPE
  3666. char buf[4096], *pos;
  3667. size_t len;
  3668. struct wpa_ctrl *ctrl;
  3669. int ret;
  3670. ctrl = wpa_ctrl_open(NULL);
  3671. if (ctrl == NULL)
  3672. return NULL;
  3673. len = sizeof(buf) - 1;
  3674. ret = wpa_ctrl_request(ctrl, "INTERFACES", 10, buf, &len, NULL);
  3675. if (ret >= 0) {
  3676. buf[len] = '\0';
  3677. pos = os_strchr(buf, '\n');
  3678. if (pos)
  3679. *pos = '\0';
  3680. ifname = os_strdup(buf);
  3681. }
  3682. wpa_ctrl_close(ctrl);
  3683. #endif /* CONFIG_CTRL_IFACE_NAMED_PIPE */
  3684. #endif /* ANDROID */
  3685. return ifname;
  3686. }
  3687. int main(int argc, char *argv[])
  3688. {
  3689. int c;
  3690. int daemonize = 0;
  3691. int ret = 0;
  3692. const char *global = NULL;
  3693. if (os_program_init())
  3694. return -1;
  3695. for (;;) {
  3696. c = getopt(argc, argv, "a:Bg:G:hi:p:P:s:v");
  3697. if (c < 0)
  3698. break;
  3699. switch (c) {
  3700. case 'a':
  3701. action_file = optarg;
  3702. break;
  3703. case 'B':
  3704. daemonize = 1;
  3705. break;
  3706. case 'g':
  3707. global = optarg;
  3708. break;
  3709. case 'G':
  3710. ping_interval = atoi(optarg);
  3711. break;
  3712. case 'h':
  3713. usage();
  3714. return 0;
  3715. case 'v':
  3716. printf("%s\n", wpa_cli_version);
  3717. return 0;
  3718. case 'i':
  3719. os_free(ctrl_ifname);
  3720. ctrl_ifname = os_strdup(optarg);
  3721. break;
  3722. case 'p':
  3723. ctrl_iface_dir = optarg;
  3724. break;
  3725. case 'P':
  3726. pid_file = optarg;
  3727. break;
  3728. case 's':
  3729. client_socket_dir = optarg;
  3730. break;
  3731. default:
  3732. usage();
  3733. return -1;
  3734. }
  3735. }
  3736. interactive = (argc == optind) && (action_file == NULL);
  3737. if (interactive)
  3738. printf("%s\n\n%s\n\n", wpa_cli_version, cli_license);
  3739. if (eloop_init())
  3740. return -1;
  3741. if (global) {
  3742. #ifdef CONFIG_CTRL_IFACE_NAMED_PIPE
  3743. ctrl_conn = wpa_ctrl_open(NULL);
  3744. #else /* CONFIG_CTRL_IFACE_NAMED_PIPE */
  3745. ctrl_conn = wpa_ctrl_open(global);
  3746. #endif /* CONFIG_CTRL_IFACE_NAMED_PIPE */
  3747. if (ctrl_conn == NULL) {
  3748. fprintf(stderr, "Failed to connect to wpa_supplicant "
  3749. "global interface: %s error: %s\n",
  3750. global, strerror(errno));
  3751. return -1;
  3752. }
  3753. if (interactive) {
  3754. update_ifnames(ctrl_conn);
  3755. mon_conn = wpa_ctrl_open(global);
  3756. if (mon_conn) {
  3757. if (wpa_ctrl_attach(mon_conn) == 0) {
  3758. wpa_cli_attached = 1;
  3759. eloop_register_read_sock(
  3760. wpa_ctrl_get_fd(mon_conn),
  3761. wpa_cli_mon_receive,
  3762. NULL, NULL);
  3763. } else {
  3764. printf("Failed to open monitor "
  3765. "connection through global "
  3766. "control interface\n");
  3767. }
  3768. }
  3769. update_stations(ctrl_conn);
  3770. }
  3771. }
  3772. eloop_register_signal_terminate(wpa_cli_terminate, NULL);
  3773. if (ctrl_ifname == NULL)
  3774. ctrl_ifname = wpa_cli_get_default_ifname();
  3775. if (interactive) {
  3776. wpa_cli_interactive();
  3777. } else {
  3778. if (!global &&
  3779. wpa_cli_open_connection(ctrl_ifname, 0) < 0) {
  3780. fprintf(stderr, "Failed to connect to non-global "
  3781. "ctrl_ifname: %s error: %s\n",
  3782. ctrl_ifname ? ctrl_ifname : "(nil)",
  3783. strerror(errno));
  3784. return -1;
  3785. }
  3786. if (action_file) {
  3787. if (wpa_ctrl_attach(ctrl_conn) == 0) {
  3788. wpa_cli_attached = 1;
  3789. } else {
  3790. printf("Warning: Failed to attach to "
  3791. "wpa_supplicant.\n");
  3792. return -1;
  3793. }
  3794. }
  3795. if (daemonize && os_daemonize(pid_file) && eloop_sock_requeue())
  3796. return -1;
  3797. if (action_file)
  3798. wpa_cli_action(ctrl_conn);
  3799. else
  3800. ret = wpa_request(ctrl_conn, argc - optind,
  3801. &argv[optind]);
  3802. }
  3803. os_free(ctrl_ifname);
  3804. eloop_destroy();
  3805. wpa_cli_cleanup();
  3806. return ret;
  3807. }
  3808. #else /* CONFIG_CTRL_IFACE */
  3809. int main(int argc, char *argv[])
  3810. {
  3811. printf("CONFIG_CTRL_IFACE not defined - wpa_cli disabled\n");
  3812. return -1;
  3813. }
  3814. #endif /* CONFIG_CTRL_IFACE */