wpa_cli.c 110 KB

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