wpa_cli.c 110 KB

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