wpa_cli.c 111 KB

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