wpa_cli.c 111 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408
  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. "macsec_integ_only",
  1152. "macsec_port",
  1153. "mka_priority",
  1154. #endif /* CONFIG_MACSEC */
  1155. #ifdef CONFIG_HS20
  1156. "update_identifier",
  1157. #endif /* CONFIG_HS20 */
  1158. "mac_addr", "pbss", "wps_disabled"
  1159. };
  1160. static char ** wpa_cli_complete_network(const char *str, int pos)
  1161. {
  1162. int arg = get_cmd_arg_num(str, pos);
  1163. int i, num_fields = ARRAY_SIZE(network_fields);
  1164. char **res = NULL;
  1165. switch (arg) {
  1166. case 1:
  1167. res = cli_txt_list_array(&networks);
  1168. break;
  1169. case 2:
  1170. res = os_calloc(num_fields + 1, sizeof(char *));
  1171. if (res == NULL)
  1172. return NULL;
  1173. for (i = 0; i < num_fields; i++) {
  1174. res[i] = os_strdup(network_fields[i]);
  1175. if (res[i] == NULL)
  1176. break;
  1177. }
  1178. }
  1179. return res;
  1180. }
  1181. static char ** wpa_cli_complete_network_id(const char *str, int pos)
  1182. {
  1183. int arg = get_cmd_arg_num(str, pos);
  1184. if (arg == 1)
  1185. return cli_txt_list_array(&networks);
  1186. return NULL;
  1187. }
  1188. static int wpa_cli_cmd_dup_network(struct wpa_ctrl *ctrl, int argc,
  1189. char *argv[])
  1190. {
  1191. if (argc == 0) {
  1192. wpa_cli_show_network_variables();
  1193. return 0;
  1194. }
  1195. if (argc < 3) {
  1196. printf("Invalid DUP_NETWORK command: needs three arguments\n"
  1197. "(src netid, dest netid, and variable name)\n");
  1198. return -1;
  1199. }
  1200. return wpa_cli_cmd(ctrl, "DUP_NETWORK", 3, argc, argv);
  1201. }
  1202. static char ** wpa_cli_complete_dup_network(const char *str, int pos)
  1203. {
  1204. int arg = get_cmd_arg_num(str, pos);
  1205. int i, num_fields = ARRAY_SIZE(network_fields);
  1206. char **res = NULL;
  1207. switch (arg) {
  1208. case 1:
  1209. case 2:
  1210. res = cli_txt_list_array(&networks);
  1211. break;
  1212. case 3:
  1213. res = os_calloc(num_fields + 1, sizeof(char *));
  1214. if (res == NULL)
  1215. return NULL;
  1216. for (i = 0; i < num_fields; i++) {
  1217. res[i] = os_strdup(network_fields[i]);
  1218. if (res[i] == NULL)
  1219. break;
  1220. }
  1221. }
  1222. return res;
  1223. }
  1224. static int wpa_cli_cmd_list_creds(struct wpa_ctrl *ctrl, int argc,
  1225. char *argv[])
  1226. {
  1227. return wpa_ctrl_command(ctrl, "LIST_CREDS");
  1228. }
  1229. static int wpa_cli_cmd_add_cred(struct wpa_ctrl *ctrl, int argc, char *argv[])
  1230. {
  1231. return wpa_ctrl_command(ctrl, "ADD_CRED");
  1232. }
  1233. static int wpa_cli_cmd_remove_cred(struct wpa_ctrl *ctrl, int argc,
  1234. char *argv[])
  1235. {
  1236. return wpa_cli_cmd(ctrl, "REMOVE_CRED", 1, argc, argv);
  1237. }
  1238. static int wpa_cli_cmd_set_cred(struct wpa_ctrl *ctrl, int argc, char *argv[])
  1239. {
  1240. if (argc != 3) {
  1241. printf("Invalid SET_CRED command: needs three arguments\n"
  1242. "(cred id, variable name, and value)\n");
  1243. return -1;
  1244. }
  1245. return wpa_cli_cmd(ctrl, "SET_CRED", 3, argc, argv);
  1246. }
  1247. static int wpa_cli_cmd_get_cred(struct wpa_ctrl *ctrl, int argc, char *argv[])
  1248. {
  1249. if (argc != 2) {
  1250. printf("Invalid GET_CRED command: needs two arguments\n"
  1251. "(cred id, variable name)\n");
  1252. return -1;
  1253. }
  1254. return wpa_cli_cmd(ctrl, "GET_CRED", 2, argc, argv);
  1255. }
  1256. static int wpa_cli_cmd_disconnect(struct wpa_ctrl *ctrl, int argc,
  1257. char *argv[])
  1258. {
  1259. return wpa_ctrl_command(ctrl, "DISCONNECT");
  1260. }
  1261. static int wpa_cli_cmd_reconnect(struct wpa_ctrl *ctrl, int argc,
  1262. char *argv[])
  1263. {
  1264. return wpa_ctrl_command(ctrl, "RECONNECT");
  1265. }
  1266. static int wpa_cli_cmd_save_config(struct wpa_ctrl *ctrl, int argc,
  1267. char *argv[])
  1268. {
  1269. return wpa_ctrl_command(ctrl, "SAVE_CONFIG");
  1270. }
  1271. static int wpa_cli_cmd_scan(struct wpa_ctrl *ctrl, int argc, char *argv[])
  1272. {
  1273. return wpa_cli_cmd(ctrl, "SCAN", 0, argc, argv);
  1274. }
  1275. static int wpa_cli_cmd_scan_results(struct wpa_ctrl *ctrl, int argc,
  1276. char *argv[])
  1277. {
  1278. return wpa_ctrl_command(ctrl, "SCAN_RESULTS");
  1279. }
  1280. static int wpa_cli_cmd_abort_scan(struct wpa_ctrl *ctrl, int argc,
  1281. char *argv[])
  1282. {
  1283. return wpa_ctrl_command(ctrl, "ABORT_SCAN");
  1284. }
  1285. static int wpa_cli_cmd_bss(struct wpa_ctrl *ctrl, int argc, char *argv[])
  1286. {
  1287. return wpa_cli_cmd(ctrl, "BSS", 1, argc, argv);
  1288. }
  1289. static char ** wpa_cli_complete_bss(const char *str, int pos)
  1290. {
  1291. int arg = get_cmd_arg_num(str, pos);
  1292. char **res = NULL;
  1293. switch (arg) {
  1294. case 1:
  1295. res = cli_txt_list_array(&bsses);
  1296. break;
  1297. }
  1298. return res;
  1299. }
  1300. static int wpa_cli_cmd_get_capability(struct wpa_ctrl *ctrl, int argc,
  1301. char *argv[])
  1302. {
  1303. if (argc < 1 || argc > 2) {
  1304. printf("Invalid GET_CAPABILITY command: need either one or "
  1305. "two arguments\n");
  1306. return -1;
  1307. }
  1308. if ((argc == 2) && os_strcmp(argv[1], "strict") != 0) {
  1309. printf("Invalid GET_CAPABILITY command: second argument, "
  1310. "if any, must be 'strict'\n");
  1311. return -1;
  1312. }
  1313. return wpa_cli_cmd(ctrl, "GET_CAPABILITY", 1, argc, argv);
  1314. }
  1315. static char ** wpa_cli_complete_get_capability(const char *str, int pos)
  1316. {
  1317. int arg = get_cmd_arg_num(str, pos);
  1318. const char *fields[] = {
  1319. "eap", "pairwise", "group", "group_mgmt", "key_mgmt",
  1320. "proto", "auth_alg", "modes", "channels", "freq",
  1321. #ifdef CONFIG_TDLS
  1322. "tdls",
  1323. #endif /* CONFIG_TDLS */
  1324. #ifdef CONFIG_ERP
  1325. "erp",
  1326. #endif /* CONFIG_ERP */
  1327. #ifdef CONFIG_FIPS
  1328. "fips",
  1329. #endif /* CONFIG_FIPS */
  1330. #ifdef CONFIG_ACS
  1331. "acs",
  1332. #endif /* CONFIG_ACS */
  1333. };
  1334. int i, num_fields = ARRAY_SIZE(fields);
  1335. char **res = NULL;
  1336. if (arg == 1) {
  1337. res = os_calloc(num_fields + 1, sizeof(char *));
  1338. if (res == NULL)
  1339. return NULL;
  1340. for (i = 0; i < num_fields; i++) {
  1341. res[i] = os_strdup(fields[i]);
  1342. if (res[i] == NULL)
  1343. return res;
  1344. }
  1345. }
  1346. if (arg == 2) {
  1347. res = os_calloc(1 + 1, sizeof(char *));
  1348. if (res == NULL)
  1349. return NULL;
  1350. res[0] = os_strdup("strict");
  1351. }
  1352. return res;
  1353. }
  1354. static int wpa_cli_list_interfaces(struct wpa_ctrl *ctrl)
  1355. {
  1356. printf("Available interfaces:\n");
  1357. return wpa_ctrl_command(ctrl, "INTERFACES");
  1358. }
  1359. static int wpa_cli_cmd_interface(struct wpa_ctrl *ctrl, int argc, char *argv[])
  1360. {
  1361. if (argc < 1) {
  1362. wpa_cli_list_interfaces(ctrl);
  1363. return 0;
  1364. }
  1365. wpa_cli_close_connection();
  1366. os_free(ctrl_ifname);
  1367. ctrl_ifname = os_strdup(argv[0]);
  1368. if (!ctrl_ifname) {
  1369. printf("Failed to allocate memory\n");
  1370. return 0;
  1371. }
  1372. if (wpa_cli_open_connection(ctrl_ifname, 1) == 0) {
  1373. printf("Connected to interface '%s.\n", ctrl_ifname);
  1374. } else {
  1375. printf("Could not connect to interface '%s' - re-trying\n",
  1376. ctrl_ifname);
  1377. }
  1378. return 0;
  1379. }
  1380. static int wpa_cli_cmd_reconfigure(struct wpa_ctrl *ctrl, int argc,
  1381. char *argv[])
  1382. {
  1383. return wpa_ctrl_command(ctrl, "RECONFIGURE");
  1384. }
  1385. static int wpa_cli_cmd_terminate(struct wpa_ctrl *ctrl, int argc,
  1386. char *argv[])
  1387. {
  1388. return wpa_ctrl_command(ctrl, "TERMINATE");
  1389. }
  1390. static int wpa_cli_cmd_interface_add(struct wpa_ctrl *ctrl, int argc,
  1391. char *argv[])
  1392. {
  1393. char cmd[256];
  1394. int res;
  1395. if (argc < 1) {
  1396. printf("Invalid INTERFACE_ADD command: needs at least one "
  1397. "argument (interface name)\n"
  1398. "All arguments: ifname confname driver ctrl_interface "
  1399. "driver_param bridge_name [create]\n");
  1400. return -1;
  1401. }
  1402. /*
  1403. * INTERFACE_ADD <ifname>TAB<confname>TAB<driver>TAB<ctrl_interface>TAB
  1404. * <driver_param>TAB<bridge_name>[TAB<create>[TAB<type>]]
  1405. */
  1406. res = os_snprintf(cmd, sizeof(cmd),
  1407. "INTERFACE_ADD %s\t%s\t%s\t%s\t%s\t%s\t%s\t%s",
  1408. argv[0],
  1409. argc > 1 ? argv[1] : "", argc > 2 ? argv[2] : "",
  1410. argc > 3 ? argv[3] : "", argc > 4 ? argv[4] : "",
  1411. argc > 5 ? argv[5] : "", argc > 6 ? argv[6] : "",
  1412. argc > 7 ? argv[7] : "");
  1413. if (os_snprintf_error(sizeof(cmd), res))
  1414. return -1;
  1415. cmd[sizeof(cmd) - 1] = '\0';
  1416. return wpa_ctrl_command(ctrl, cmd);
  1417. }
  1418. static int wpa_cli_cmd_interface_remove(struct wpa_ctrl *ctrl, int argc,
  1419. char *argv[])
  1420. {
  1421. return wpa_cli_cmd(ctrl, "INTERFACE_REMOVE", 1, argc, argv);
  1422. }
  1423. static int wpa_cli_cmd_interface_list(struct wpa_ctrl *ctrl, int argc,
  1424. char *argv[])
  1425. {
  1426. return wpa_ctrl_command(ctrl, "INTERFACE_LIST");
  1427. }
  1428. #ifdef CONFIG_AP
  1429. static int wpa_cli_cmd_sta(struct wpa_ctrl *ctrl, int argc, char *argv[])
  1430. {
  1431. return wpa_cli_cmd(ctrl, "STA", 1, argc, argv);
  1432. }
  1433. static char ** wpa_cli_complete_sta(const char *str, int pos)
  1434. {
  1435. int arg = get_cmd_arg_num(str, pos);
  1436. char **res = NULL;
  1437. switch (arg) {
  1438. case 1:
  1439. res = cli_txt_list_array(&stations);
  1440. break;
  1441. }
  1442. return res;
  1443. }
  1444. static int wpa_ctrl_command_sta(struct wpa_ctrl *ctrl, const char *cmd,
  1445. char *addr, size_t addr_len, int print)
  1446. {
  1447. char buf[4096], *pos;
  1448. size_t len;
  1449. int ret;
  1450. if (ctrl_conn == NULL) {
  1451. printf("Not connected to hostapd - command dropped.\n");
  1452. return -1;
  1453. }
  1454. if (ifname_prefix) {
  1455. os_snprintf(buf, sizeof(buf), "IFNAME=%s %s",
  1456. ifname_prefix, cmd);
  1457. buf[sizeof(buf) - 1] = '\0';
  1458. cmd = buf;
  1459. }
  1460. len = sizeof(buf) - 1;
  1461. ret = wpa_ctrl_request(ctrl, cmd, os_strlen(cmd), buf, &len,
  1462. wpa_cli_msg_cb);
  1463. if (ret == -2) {
  1464. printf("'%s' command timed out.\n", cmd);
  1465. return -2;
  1466. } else if (ret < 0) {
  1467. printf("'%s' command failed.\n", cmd);
  1468. return -1;
  1469. }
  1470. buf[len] = '\0';
  1471. if (os_memcmp(buf, "FAIL", 4) == 0)
  1472. return -1;
  1473. if (print)
  1474. printf("%s", buf);
  1475. pos = buf;
  1476. while (*pos != '\0' && *pos != '\n')
  1477. pos++;
  1478. *pos = '\0';
  1479. os_strlcpy(addr, buf, addr_len);
  1480. return 0;
  1481. }
  1482. static int wpa_cli_cmd_all_sta(struct wpa_ctrl *ctrl, int argc, char *argv[])
  1483. {
  1484. char addr[32], cmd[64];
  1485. if (wpa_ctrl_command_sta(ctrl, "STA-FIRST", addr, sizeof(addr), 1))
  1486. return 0;
  1487. do {
  1488. os_snprintf(cmd, sizeof(cmd), "STA-NEXT %s", addr);
  1489. } while (wpa_ctrl_command_sta(ctrl, cmd, addr, sizeof(addr), 1) == 0);
  1490. return -1;
  1491. }
  1492. static int wpa_cli_cmd_list_sta(struct wpa_ctrl *ctrl, int argc,
  1493. char *argv[])
  1494. {
  1495. char addr[32], cmd[64];
  1496. if (wpa_ctrl_command_sta(ctrl, "STA-FIRST", addr, sizeof(addr), 0))
  1497. return 0;
  1498. do {
  1499. if (os_strcmp(addr, "") != 0)
  1500. printf("%s\n", addr);
  1501. os_snprintf(cmd, sizeof(cmd), "STA-NEXT %s", addr);
  1502. } while (wpa_ctrl_command_sta(ctrl, cmd, addr, sizeof(addr), 0) == 0);
  1503. return 0;
  1504. }
  1505. static int wpa_cli_cmd_deauthenticate(struct wpa_ctrl *ctrl, int argc,
  1506. char *argv[])
  1507. {
  1508. return wpa_cli_cmd(ctrl, "DEAUTHENTICATE", 1, argc, argv);
  1509. }
  1510. static char ** wpa_cli_complete_deauthenticate(const char *str, int pos)
  1511. {
  1512. int arg = get_cmd_arg_num(str, pos);
  1513. char **res = NULL;
  1514. switch (arg) {
  1515. case 1:
  1516. res = cli_txt_list_array(&stations);
  1517. break;
  1518. }
  1519. return res;
  1520. }
  1521. static int wpa_cli_cmd_disassociate(struct wpa_ctrl *ctrl, int argc,
  1522. char *argv[])
  1523. {
  1524. return wpa_cli_cmd(ctrl, "DISASSOCIATE", 1, argc, argv);
  1525. }
  1526. static char ** wpa_cli_complete_disassociate(const char *str, int pos)
  1527. {
  1528. int arg = get_cmd_arg_num(str, pos);
  1529. char **res = NULL;
  1530. switch (arg) {
  1531. case 1:
  1532. res = cli_txt_list_array(&stations);
  1533. break;
  1534. }
  1535. return res;
  1536. }
  1537. static int wpa_cli_cmd_chanswitch(struct wpa_ctrl *ctrl, int argc,
  1538. char *argv[])
  1539. {
  1540. return wpa_cli_cmd(ctrl, "CHAN_SWITCH", 2, argc, argv);
  1541. }
  1542. #endif /* CONFIG_AP */
  1543. static int wpa_cli_cmd_suspend(struct wpa_ctrl *ctrl, int argc, char *argv[])
  1544. {
  1545. return wpa_ctrl_command(ctrl, "SUSPEND");
  1546. }
  1547. static int wpa_cli_cmd_resume(struct wpa_ctrl *ctrl, int argc, char *argv[])
  1548. {
  1549. return wpa_ctrl_command(ctrl, "RESUME");
  1550. }
  1551. #ifdef CONFIG_TESTING_OPTIONS
  1552. static int wpa_cli_cmd_drop_sa(struct wpa_ctrl *ctrl, int argc, char *argv[])
  1553. {
  1554. return wpa_ctrl_command(ctrl, "DROP_SA");
  1555. }
  1556. #endif /* CONFIG_TESTING_OPTIONS */
  1557. static int wpa_cli_cmd_roam(struct wpa_ctrl *ctrl, int argc, char *argv[])
  1558. {
  1559. return wpa_cli_cmd(ctrl, "ROAM", 1, argc, argv);
  1560. }
  1561. #ifdef CONFIG_MESH
  1562. static int wpa_cli_cmd_mesh_interface_add(struct wpa_ctrl *ctrl, int argc,
  1563. char *argv[])
  1564. {
  1565. return wpa_cli_cmd(ctrl, "MESH_INTERFACE_ADD", 0, argc, argv);
  1566. }
  1567. static int wpa_cli_cmd_mesh_group_add(struct wpa_ctrl *ctrl, int argc,
  1568. char *argv[])
  1569. {
  1570. return wpa_cli_cmd(ctrl, "MESH_GROUP_ADD", 1, argc, argv);
  1571. }
  1572. static int wpa_cli_cmd_mesh_group_remove(struct wpa_ctrl *ctrl, int argc,
  1573. char *argv[])
  1574. {
  1575. return wpa_cli_cmd(ctrl, "MESH_GROUP_REMOVE", 1, argc, argv);
  1576. }
  1577. static int wpa_cli_cmd_mesh_peer_remove(struct wpa_ctrl *ctrl, int argc,
  1578. char *argv[])
  1579. {
  1580. return wpa_cli_cmd(ctrl, "MESH_PEER_REMOVE", 1, argc, argv);
  1581. }
  1582. static int wpa_cli_cmd_mesh_peer_add(struct wpa_ctrl *ctrl, int argc,
  1583. char *argv[])
  1584. {
  1585. return wpa_cli_cmd(ctrl, "MESH_PEER_ADD", 1, argc, argv);
  1586. }
  1587. #endif /* CONFIG_MESH */
  1588. #ifdef CONFIG_P2P
  1589. static int wpa_cli_cmd_p2p_find(struct wpa_ctrl *ctrl, int argc, char *argv[])
  1590. {
  1591. return wpa_cli_cmd(ctrl, "P2P_FIND", 0, argc, argv);
  1592. }
  1593. static char ** wpa_cli_complete_p2p_find(const char *str, int pos)
  1594. {
  1595. char **res = NULL;
  1596. int arg = get_cmd_arg_num(str, pos);
  1597. res = os_calloc(6, sizeof(char *));
  1598. if (res == NULL)
  1599. return NULL;
  1600. res[0] = os_strdup("type=social");
  1601. if (res[0] == NULL) {
  1602. os_free(res);
  1603. return NULL;
  1604. }
  1605. res[1] = os_strdup("type=progressive");
  1606. if (res[1] == NULL)
  1607. return res;
  1608. res[2] = os_strdup("delay=");
  1609. if (res[2] == NULL)
  1610. return res;
  1611. res[3] = os_strdup("dev_id=");
  1612. if (res[3] == NULL)
  1613. return res;
  1614. if (arg == 1)
  1615. res[4] = os_strdup("[timeout]");
  1616. return res;
  1617. }
  1618. static int wpa_cli_cmd_p2p_stop_find(struct wpa_ctrl *ctrl, int argc,
  1619. char *argv[])
  1620. {
  1621. return wpa_ctrl_command(ctrl, "P2P_STOP_FIND");
  1622. }
  1623. static int wpa_cli_cmd_p2p_asp_provision(struct wpa_ctrl *ctrl, int argc,
  1624. char *argv[])
  1625. {
  1626. return wpa_cli_cmd(ctrl, "P2P_ASP_PROVISION", 3, argc, argv);
  1627. }
  1628. static int wpa_cli_cmd_p2p_asp_provision_resp(struct wpa_ctrl *ctrl, int argc,
  1629. char *argv[])
  1630. {
  1631. return wpa_cli_cmd(ctrl, "P2P_ASP_PROVISION_RESP", 2, argc, argv);
  1632. }
  1633. static int wpa_cli_cmd_p2p_connect(struct wpa_ctrl *ctrl, int argc,
  1634. char *argv[])
  1635. {
  1636. return wpa_cli_cmd(ctrl, "P2P_CONNECT", 2, argc, argv);
  1637. }
  1638. static char ** wpa_cli_complete_p2p_connect(const char *str, int pos)
  1639. {
  1640. int arg = get_cmd_arg_num(str, pos);
  1641. char **res = NULL;
  1642. switch (arg) {
  1643. case 1:
  1644. res = cli_txt_list_array(&p2p_peers);
  1645. break;
  1646. }
  1647. return res;
  1648. }
  1649. static int wpa_cli_cmd_p2p_listen(struct wpa_ctrl *ctrl, int argc,
  1650. char *argv[])
  1651. {
  1652. return wpa_cli_cmd(ctrl, "P2P_LISTEN", 0, argc, argv);
  1653. }
  1654. static int wpa_cli_cmd_p2p_group_remove(struct wpa_ctrl *ctrl, int argc,
  1655. char *argv[])
  1656. {
  1657. return wpa_cli_cmd(ctrl, "P2P_GROUP_REMOVE", 1, argc, argv);
  1658. }
  1659. static char ** wpa_cli_complete_p2p_group_remove(const char *str, int pos)
  1660. {
  1661. int arg = get_cmd_arg_num(str, pos);
  1662. char **res = NULL;
  1663. switch (arg) {
  1664. case 1:
  1665. res = cli_txt_list_array(&p2p_groups);
  1666. break;
  1667. }
  1668. return res;
  1669. }
  1670. static int wpa_cli_cmd_p2p_group_add(struct wpa_ctrl *ctrl, int argc,
  1671. char *argv[])
  1672. {
  1673. return wpa_cli_cmd(ctrl, "P2P_GROUP_ADD", 0, argc, argv);
  1674. }
  1675. static int wpa_cli_cmd_p2p_group_member(struct wpa_ctrl *ctrl, int argc,
  1676. char *argv[])
  1677. {
  1678. return wpa_cli_cmd(ctrl, "P2P_GROUP_MEMBER", 1, argc, argv);
  1679. }
  1680. static int wpa_cli_cmd_p2p_prov_disc(struct wpa_ctrl *ctrl, int argc,
  1681. char *argv[])
  1682. {
  1683. if (argc != 2 && argc != 3) {
  1684. printf("Invalid P2P_PROV_DISC command: needs at least "
  1685. "two arguments, address and config method\n"
  1686. "(display, keypad, or pbc) and an optional join\n");
  1687. return -1;
  1688. }
  1689. return wpa_cli_cmd(ctrl, "P2P_PROV_DISC", 2, argc, argv);
  1690. }
  1691. static int wpa_cli_cmd_p2p_get_passphrase(struct wpa_ctrl *ctrl, int argc,
  1692. char *argv[])
  1693. {
  1694. return wpa_ctrl_command(ctrl, "P2P_GET_PASSPHRASE");
  1695. }
  1696. static int wpa_cli_cmd_p2p_serv_disc_req(struct wpa_ctrl *ctrl, int argc,
  1697. char *argv[])
  1698. {
  1699. char cmd[4096];
  1700. if (argc < 2) {
  1701. printf("Invalid P2P_SERV_DISC_REQ command: needs two "
  1702. "or more arguments (address and TLVs)\n");
  1703. return -1;
  1704. }
  1705. if (write_cmd(cmd, sizeof(cmd), "P2P_SERV_DISC_REQ", argc, argv) < 0)
  1706. return -1;
  1707. return wpa_ctrl_command(ctrl, cmd);
  1708. }
  1709. static int wpa_cli_cmd_p2p_serv_disc_cancel_req(struct wpa_ctrl *ctrl,
  1710. int argc, char *argv[])
  1711. {
  1712. return wpa_cli_cmd(ctrl, "P2P_SERV_DISC_CANCEL_REQ", 1, argc, argv);
  1713. }
  1714. static int wpa_cli_cmd_p2p_serv_disc_resp(struct wpa_ctrl *ctrl, int argc,
  1715. char *argv[])
  1716. {
  1717. char cmd[4096];
  1718. int res;
  1719. if (argc != 4) {
  1720. printf("Invalid P2P_SERV_DISC_RESP command: needs four "
  1721. "arguments (freq, address, dialog token, and TLVs)\n");
  1722. return -1;
  1723. }
  1724. res = os_snprintf(cmd, sizeof(cmd), "P2P_SERV_DISC_RESP %s %s %s %s",
  1725. argv[0], argv[1], argv[2], argv[3]);
  1726. if (os_snprintf_error(sizeof(cmd), res))
  1727. return -1;
  1728. cmd[sizeof(cmd) - 1] = '\0';
  1729. return wpa_ctrl_command(ctrl, cmd);
  1730. }
  1731. static int wpa_cli_cmd_p2p_service_update(struct wpa_ctrl *ctrl, int argc,
  1732. char *argv[])
  1733. {
  1734. return wpa_ctrl_command(ctrl, "P2P_SERVICE_UPDATE");
  1735. }
  1736. static int wpa_cli_cmd_p2p_serv_disc_external(struct wpa_ctrl *ctrl,
  1737. int argc, char *argv[])
  1738. {
  1739. return wpa_cli_cmd(ctrl, "P2P_SERV_DISC_EXTERNAL", 1, argc, argv);
  1740. }
  1741. static int wpa_cli_cmd_p2p_service_flush(struct wpa_ctrl *ctrl, int argc,
  1742. char *argv[])
  1743. {
  1744. return wpa_ctrl_command(ctrl, "P2P_SERVICE_FLUSH");
  1745. }
  1746. static int wpa_cli_cmd_p2p_service_add(struct wpa_ctrl *ctrl, int argc,
  1747. char *argv[])
  1748. {
  1749. if (argc < 3) {
  1750. printf("Invalid P2P_SERVICE_ADD command: needs 3-6 arguments\n");
  1751. return -1;
  1752. }
  1753. return wpa_cli_cmd(ctrl, "P2P_SERVICE_ADD", 3, argc, argv);
  1754. }
  1755. static int wpa_cli_cmd_p2p_service_rep(struct wpa_ctrl *ctrl, int argc,
  1756. char *argv[])
  1757. {
  1758. if (argc < 5 || argc > 6) {
  1759. printf("Invalid P2P_SERVICE_REP command: needs 5-6 "
  1760. "arguments\n");
  1761. return -1;
  1762. }
  1763. return wpa_cli_cmd(ctrl, "P2P_SERVICE_REP", 5, argc, argv);
  1764. }
  1765. static int wpa_cli_cmd_p2p_service_del(struct wpa_ctrl *ctrl, int argc,
  1766. char *argv[])
  1767. {
  1768. char cmd[4096];
  1769. int res;
  1770. if (argc != 2 && argc != 3) {
  1771. printf("Invalid P2P_SERVICE_DEL command: needs two or three "
  1772. "arguments\n");
  1773. return -1;
  1774. }
  1775. if (argc == 3)
  1776. res = os_snprintf(cmd, sizeof(cmd),
  1777. "P2P_SERVICE_DEL %s %s %s",
  1778. argv[0], argv[1], argv[2]);
  1779. else
  1780. res = os_snprintf(cmd, sizeof(cmd),
  1781. "P2P_SERVICE_DEL %s %s",
  1782. argv[0], argv[1]);
  1783. if (os_snprintf_error(sizeof(cmd), res))
  1784. return -1;
  1785. cmd[sizeof(cmd) - 1] = '\0';
  1786. return wpa_ctrl_command(ctrl, cmd);
  1787. }
  1788. static int wpa_cli_cmd_p2p_reject(struct wpa_ctrl *ctrl,
  1789. int argc, char *argv[])
  1790. {
  1791. return wpa_cli_cmd(ctrl, "P2P_REJECT", 1, argc, argv);
  1792. }
  1793. static int wpa_cli_cmd_p2p_invite(struct wpa_ctrl *ctrl,
  1794. int argc, char *argv[])
  1795. {
  1796. return wpa_cli_cmd(ctrl, "P2P_INVITE", 1, argc, argv);
  1797. }
  1798. static int wpa_cli_cmd_p2p_peer(struct wpa_ctrl *ctrl, int argc, char *argv[])
  1799. {
  1800. return wpa_cli_cmd(ctrl, "P2P_PEER", 1, argc, argv);
  1801. }
  1802. static char ** wpa_cli_complete_p2p_peer(const char *str, int pos)
  1803. {
  1804. int arg = get_cmd_arg_num(str, pos);
  1805. char **res = NULL;
  1806. switch (arg) {
  1807. case 1:
  1808. res = cli_txt_list_array(&p2p_peers);
  1809. break;
  1810. }
  1811. return res;
  1812. }
  1813. static int wpa_ctrl_command_p2p_peer(struct wpa_ctrl *ctrl, const char *cmd,
  1814. char *addr, size_t addr_len,
  1815. int discovered)
  1816. {
  1817. char buf[4096], *pos;
  1818. size_t len;
  1819. int ret;
  1820. if (ctrl_conn == NULL)
  1821. return -1;
  1822. len = sizeof(buf) - 1;
  1823. ret = wpa_ctrl_request(ctrl, cmd, os_strlen(cmd), buf, &len,
  1824. wpa_cli_msg_cb);
  1825. if (ret == -2) {
  1826. printf("'%s' command timed out.\n", cmd);
  1827. return -2;
  1828. } else if (ret < 0) {
  1829. printf("'%s' command failed.\n", cmd);
  1830. return -1;
  1831. }
  1832. buf[len] = '\0';
  1833. if (os_memcmp(buf, "FAIL", 4) == 0)
  1834. return -1;
  1835. pos = buf;
  1836. while (*pos != '\0' && *pos != '\n')
  1837. pos++;
  1838. *pos++ = '\0';
  1839. os_strlcpy(addr, buf, addr_len);
  1840. if (!discovered || os_strstr(pos, "[PROBE_REQ_ONLY]") == NULL)
  1841. printf("%s\n", addr);
  1842. return 0;
  1843. }
  1844. static int wpa_cli_cmd_p2p_peers(struct wpa_ctrl *ctrl, int argc, char *argv[])
  1845. {
  1846. char addr[32], cmd[64];
  1847. int discovered;
  1848. discovered = argc > 0 && os_strcmp(argv[0], "discovered") == 0;
  1849. if (wpa_ctrl_command_p2p_peer(ctrl, "P2P_PEER FIRST",
  1850. addr, sizeof(addr), discovered))
  1851. return -1;
  1852. do {
  1853. os_snprintf(cmd, sizeof(cmd), "P2P_PEER NEXT-%s", addr);
  1854. } while (wpa_ctrl_command_p2p_peer(ctrl, cmd, addr, sizeof(addr),
  1855. discovered) == 0);
  1856. return 0;
  1857. }
  1858. static int wpa_cli_cmd_p2p_set(struct wpa_ctrl *ctrl, int argc, char *argv[])
  1859. {
  1860. return wpa_cli_cmd(ctrl, "P2P_SET", 2, argc, argv);
  1861. }
  1862. static char ** wpa_cli_complete_p2p_set(const char *str, int pos)
  1863. {
  1864. int arg = get_cmd_arg_num(str, pos);
  1865. const char *fields[] = {
  1866. "discoverability",
  1867. "managed",
  1868. "listen_channel",
  1869. "ssid_postfix",
  1870. "noa",
  1871. "ps",
  1872. "oppps",
  1873. "ctwindow",
  1874. "disabled",
  1875. "conc_pref",
  1876. "force_long_sd",
  1877. "peer_filter",
  1878. "cross_connect",
  1879. "go_apsd",
  1880. "client_apsd",
  1881. "disallow_freq",
  1882. "disc_int",
  1883. "per_sta_psk",
  1884. };
  1885. int i, num_fields = ARRAY_SIZE(fields);
  1886. if (arg == 1) {
  1887. char **res = os_calloc(num_fields + 1, sizeof(char *));
  1888. if (res == NULL)
  1889. return NULL;
  1890. for (i = 0; i < num_fields; i++) {
  1891. res[i] = os_strdup(fields[i]);
  1892. if (res[i] == NULL)
  1893. return res;
  1894. }
  1895. return res;
  1896. }
  1897. if (arg == 2 && os_strncasecmp(str, "p2p_set peer_filter ", 20) == 0)
  1898. return cli_txt_list_array(&p2p_peers);
  1899. return NULL;
  1900. }
  1901. static int wpa_cli_cmd_p2p_flush(struct wpa_ctrl *ctrl, int argc, char *argv[])
  1902. {
  1903. return wpa_ctrl_command(ctrl, "P2P_FLUSH");
  1904. }
  1905. static int wpa_cli_cmd_p2p_cancel(struct wpa_ctrl *ctrl, int argc,
  1906. char *argv[])
  1907. {
  1908. return wpa_ctrl_command(ctrl, "P2P_CANCEL");
  1909. }
  1910. static int wpa_cli_cmd_p2p_unauthorize(struct wpa_ctrl *ctrl, int argc,
  1911. char *argv[])
  1912. {
  1913. return wpa_cli_cmd(ctrl, "P2P_UNAUTHORIZE", 1, argc, argv);
  1914. }
  1915. static int wpa_cli_cmd_p2p_presence_req(struct wpa_ctrl *ctrl, int argc,
  1916. char *argv[])
  1917. {
  1918. if (argc != 0 && argc != 2 && argc != 4) {
  1919. printf("Invalid P2P_PRESENCE_REQ command: needs two arguments "
  1920. "(preferred duration, interval; in microsecods).\n"
  1921. "Optional second pair can be used to provide "
  1922. "acceptable values.\n");
  1923. return -1;
  1924. }
  1925. return wpa_cli_cmd(ctrl, "P2P_PRESENCE_REQ", 0, argc, argv);
  1926. }
  1927. static int wpa_cli_cmd_p2p_ext_listen(struct wpa_ctrl *ctrl, int argc,
  1928. char *argv[])
  1929. {
  1930. if (argc != 0 && argc != 2) {
  1931. printf("Invalid P2P_EXT_LISTEN command: needs two arguments "
  1932. "(availability period, availability interval; in "
  1933. "millisecods).\n"
  1934. "Extended Listen Timing can be cancelled with this "
  1935. "command when used without parameters.\n");
  1936. return -1;
  1937. }
  1938. return wpa_cli_cmd(ctrl, "P2P_EXT_LISTEN", 0, argc, argv);
  1939. }
  1940. static int wpa_cli_cmd_p2p_remove_client(struct wpa_ctrl *ctrl, int argc,
  1941. char *argv[])
  1942. {
  1943. return wpa_cli_cmd(ctrl, "P2P_REMOVE_CLIENT", 1, argc, argv);
  1944. }
  1945. static int wpa_cli_cmd_vendor_elem_add(struct wpa_ctrl *ctrl, int argc,
  1946. char *argv[])
  1947. {
  1948. return wpa_cli_cmd(ctrl, "VENDOR_ELEM_ADD", 2, argc, argv);
  1949. }
  1950. static int wpa_cli_cmd_vendor_elem_get(struct wpa_ctrl *ctrl, int argc,
  1951. char *argv[])
  1952. {
  1953. return wpa_cli_cmd(ctrl, "VENDOR_ELEM_GET", 1, argc, argv);
  1954. }
  1955. static int wpa_cli_cmd_vendor_elem_remove(struct wpa_ctrl *ctrl, int argc,
  1956. char *argv[])
  1957. {
  1958. return wpa_cli_cmd(ctrl, "VENDOR_ELEM_REMOVE", 2, argc, argv);
  1959. }
  1960. #endif /* CONFIG_P2P */
  1961. #ifdef CONFIG_WIFI_DISPLAY
  1962. static int wpa_cli_cmd_wfd_subelem_set(struct wpa_ctrl *ctrl, int argc,
  1963. char *argv[])
  1964. {
  1965. char cmd[100];
  1966. int res;
  1967. if (argc != 1 && argc != 2) {
  1968. printf("Invalid WFD_SUBELEM_SET command: needs one or two "
  1969. "arguments (subelem, hexdump)\n");
  1970. return -1;
  1971. }
  1972. res = os_snprintf(cmd, sizeof(cmd), "WFD_SUBELEM_SET %s %s",
  1973. argv[0], argc > 1 ? argv[1] : "");
  1974. if (os_snprintf_error(sizeof(cmd), res))
  1975. return -1;
  1976. cmd[sizeof(cmd) - 1] = '\0';
  1977. return wpa_ctrl_command(ctrl, cmd);
  1978. }
  1979. static int wpa_cli_cmd_wfd_subelem_get(struct wpa_ctrl *ctrl, int argc,
  1980. char *argv[])
  1981. {
  1982. char cmd[100];
  1983. int res;
  1984. if (argc != 1) {
  1985. printf("Invalid WFD_SUBELEM_GET command: needs one "
  1986. "argument (subelem)\n");
  1987. return -1;
  1988. }
  1989. res = os_snprintf(cmd, sizeof(cmd), "WFD_SUBELEM_GET %s",
  1990. argv[0]);
  1991. if (os_snprintf_error(sizeof(cmd), res))
  1992. return -1;
  1993. cmd[sizeof(cmd) - 1] = '\0';
  1994. return wpa_ctrl_command(ctrl, cmd);
  1995. }
  1996. #endif /* CONFIG_WIFI_DISPLAY */
  1997. #ifdef CONFIG_INTERWORKING
  1998. static int wpa_cli_cmd_fetch_anqp(struct wpa_ctrl *ctrl, int argc,
  1999. char *argv[])
  2000. {
  2001. return wpa_ctrl_command(ctrl, "FETCH_ANQP");
  2002. }
  2003. static int wpa_cli_cmd_stop_fetch_anqp(struct wpa_ctrl *ctrl, int argc,
  2004. char *argv[])
  2005. {
  2006. return wpa_ctrl_command(ctrl, "STOP_FETCH_ANQP");
  2007. }
  2008. static int wpa_cli_cmd_interworking_select(struct wpa_ctrl *ctrl, int argc,
  2009. char *argv[])
  2010. {
  2011. return wpa_cli_cmd(ctrl, "INTERWORKING_SELECT", 0, argc, argv);
  2012. }
  2013. static int wpa_cli_cmd_interworking_connect(struct wpa_ctrl *ctrl, int argc,
  2014. char *argv[])
  2015. {
  2016. return wpa_cli_cmd(ctrl, "INTERWORKING_CONNECT", 1, argc, argv);
  2017. }
  2018. static int wpa_cli_cmd_interworking_add_network(struct wpa_ctrl *ctrl, int argc,
  2019. char *argv[])
  2020. {
  2021. return wpa_cli_cmd(ctrl, "INTERWORKING_ADD_NETWORK", 1, argc, argv);
  2022. }
  2023. static int wpa_cli_cmd_anqp_get(struct wpa_ctrl *ctrl, int argc, char *argv[])
  2024. {
  2025. return wpa_cli_cmd(ctrl, "ANQP_GET", 2, argc, argv);
  2026. }
  2027. static int wpa_cli_cmd_gas_request(struct wpa_ctrl *ctrl, int argc,
  2028. char *argv[])
  2029. {
  2030. return wpa_cli_cmd(ctrl, "GAS_REQUEST", 2, argc, argv);
  2031. }
  2032. static int wpa_cli_cmd_gas_response_get(struct wpa_ctrl *ctrl, int argc,
  2033. char *argv[])
  2034. {
  2035. return wpa_cli_cmd(ctrl, "GAS_RESPONSE_GET", 2, argc, argv);
  2036. }
  2037. #endif /* CONFIG_INTERWORKING */
  2038. #ifdef CONFIG_HS20
  2039. static int wpa_cli_cmd_hs20_anqp_get(struct wpa_ctrl *ctrl, int argc,
  2040. char *argv[])
  2041. {
  2042. return wpa_cli_cmd(ctrl, "HS20_ANQP_GET", 2, argc, argv);
  2043. }
  2044. static int wpa_cli_cmd_get_nai_home_realm_list(struct wpa_ctrl *ctrl, int argc,
  2045. char *argv[])
  2046. {
  2047. char cmd[512];
  2048. if (argc == 0) {
  2049. printf("Command needs one or two arguments (dst mac addr and "
  2050. "optional home realm)\n");
  2051. return -1;
  2052. }
  2053. if (write_cmd(cmd, sizeof(cmd), "HS20_GET_NAI_HOME_REALM_LIST",
  2054. argc, argv) < 0)
  2055. return -1;
  2056. return wpa_ctrl_command(ctrl, cmd);
  2057. }
  2058. static int wpa_cli_cmd_hs20_icon_request(struct wpa_ctrl *ctrl, int argc,
  2059. char *argv[])
  2060. {
  2061. char cmd[512];
  2062. if (argc < 2) {
  2063. printf("Command needs two arguments (dst mac addr and "
  2064. "icon name)\n");
  2065. return -1;
  2066. }
  2067. if (write_cmd(cmd, sizeof(cmd), "HS20_ICON_REQUEST", argc, argv) < 0)
  2068. return -1;
  2069. return wpa_ctrl_command(ctrl, cmd);
  2070. }
  2071. static int wpa_cli_cmd_fetch_osu(struct wpa_ctrl *ctrl, int argc, char *argv[])
  2072. {
  2073. return wpa_ctrl_command(ctrl, "FETCH_OSU");
  2074. }
  2075. static int wpa_cli_cmd_cancel_fetch_osu(struct wpa_ctrl *ctrl, int argc,
  2076. char *argv[])
  2077. {
  2078. return wpa_ctrl_command(ctrl, "CANCEL_FETCH_OSU");
  2079. }
  2080. #endif /* CONFIG_HS20 */
  2081. static int wpa_cli_cmd_sta_autoconnect(struct wpa_ctrl *ctrl, int argc,
  2082. char *argv[])
  2083. {
  2084. return wpa_cli_cmd(ctrl, "STA_AUTOCONNECT", 1, argc, argv);
  2085. }
  2086. static int wpa_cli_cmd_tdls_discover(struct wpa_ctrl *ctrl, int argc,
  2087. char *argv[])
  2088. {
  2089. return wpa_cli_cmd(ctrl, "TDLS_DISCOVER", 1, argc, argv);
  2090. }
  2091. static int wpa_cli_cmd_tdls_setup(struct wpa_ctrl *ctrl, int argc,
  2092. char *argv[])
  2093. {
  2094. return wpa_cli_cmd(ctrl, "TDLS_SETUP", 1, argc, argv);
  2095. }
  2096. static int wpa_cli_cmd_tdls_teardown(struct wpa_ctrl *ctrl, int argc,
  2097. char *argv[])
  2098. {
  2099. return wpa_cli_cmd(ctrl, "TDLS_TEARDOWN", 1, argc, argv);
  2100. }
  2101. static int wpa_cli_cmd_tdls_link_status(struct wpa_ctrl *ctrl, int argc,
  2102. char *argv[])
  2103. {
  2104. return wpa_cli_cmd(ctrl, "TDLS_LINK_STATUS", 1, argc, argv);
  2105. }
  2106. static int wpa_cli_cmd_wmm_ac_addts(struct wpa_ctrl *ctrl, int argc,
  2107. char *argv[])
  2108. {
  2109. return wpa_cli_cmd(ctrl, "WMM_AC_ADDTS", 3, argc, argv);
  2110. }
  2111. static int wpa_cli_cmd_wmm_ac_delts(struct wpa_ctrl *ctrl, int argc,
  2112. char *argv[])
  2113. {
  2114. return wpa_cli_cmd(ctrl, "WMM_AC_DELTS", 1, argc, argv);
  2115. }
  2116. static int wpa_cli_cmd_wmm_ac_status(struct wpa_ctrl *ctrl, int argc,
  2117. char *argv[])
  2118. {
  2119. return wpa_ctrl_command(ctrl, "WMM_AC_STATUS");
  2120. }
  2121. static int wpa_cli_cmd_tdls_chan_switch(struct wpa_ctrl *ctrl, int argc,
  2122. char *argv[])
  2123. {
  2124. return wpa_cli_cmd(ctrl, "TDLS_CHAN_SWITCH", 2, argc, argv);
  2125. }
  2126. static int wpa_cli_cmd_tdls_cancel_chan_switch(struct wpa_ctrl *ctrl, int argc,
  2127. char *argv[])
  2128. {
  2129. return wpa_cli_cmd(ctrl, "TDLS_CANCEL_CHAN_SWITCH", 1, argc, argv);
  2130. }
  2131. static int wpa_cli_cmd_signal_poll(struct wpa_ctrl *ctrl, int argc,
  2132. char *argv[])
  2133. {
  2134. return wpa_ctrl_command(ctrl, "SIGNAL_POLL");
  2135. }
  2136. static int wpa_cli_cmd_signal_monitor(struct wpa_ctrl *ctrl, int argc,
  2137. char *argv[])
  2138. {
  2139. return wpa_cli_cmd(ctrl, "SIGNAL_MONITOR", 0, argc, argv);
  2140. }
  2141. static int wpa_cli_cmd_pktcnt_poll(struct wpa_ctrl *ctrl, int argc,
  2142. char *argv[])
  2143. {
  2144. return wpa_ctrl_command(ctrl, "PKTCNT_POLL");
  2145. }
  2146. static int wpa_cli_cmd_reauthenticate(struct wpa_ctrl *ctrl, int argc,
  2147. char *argv[])
  2148. {
  2149. return wpa_ctrl_command(ctrl, "REAUTHENTICATE");
  2150. }
  2151. #ifdef CONFIG_AUTOSCAN
  2152. static int wpa_cli_cmd_autoscan(struct wpa_ctrl *ctrl, int argc, char *argv[])
  2153. {
  2154. if (argc == 0)
  2155. return wpa_ctrl_command(ctrl, "AUTOSCAN ");
  2156. return wpa_cli_cmd(ctrl, "AUTOSCAN", 0, argc, argv);
  2157. }
  2158. #endif /* CONFIG_AUTOSCAN */
  2159. #ifdef CONFIG_WNM
  2160. static int wpa_cli_cmd_wnm_sleep(struct wpa_ctrl *ctrl, int argc, char *argv[])
  2161. {
  2162. return wpa_cli_cmd(ctrl, "WNM_SLEEP", 0, argc, argv);
  2163. }
  2164. static int wpa_cli_cmd_wnm_bss_query(struct wpa_ctrl *ctrl, int argc, char *argv[])
  2165. {
  2166. return wpa_cli_cmd(ctrl, "WNM_BSS_QUERY", 1, argc, argv);
  2167. }
  2168. #endif /* CONFIG_WNM */
  2169. static int wpa_cli_cmd_raw(struct wpa_ctrl *ctrl, int argc, char *argv[])
  2170. {
  2171. if (argc == 0)
  2172. return -1;
  2173. return wpa_cli_cmd(ctrl, argv[0], 0, argc - 1, &argv[1]);
  2174. }
  2175. #ifdef ANDROID
  2176. static int wpa_cli_cmd_driver(struct wpa_ctrl *ctrl, int argc, char *argv[])
  2177. {
  2178. return wpa_cli_cmd(ctrl, "DRIVER", 1, argc, argv);
  2179. }
  2180. #endif /* ANDROID */
  2181. static int wpa_cli_cmd_vendor(struct wpa_ctrl *ctrl, int argc, char *argv[])
  2182. {
  2183. return wpa_cli_cmd(ctrl, "VENDOR", 1, argc, argv);
  2184. }
  2185. static int wpa_cli_cmd_flush(struct wpa_ctrl *ctrl, int argc, char *argv[])
  2186. {
  2187. return wpa_ctrl_command(ctrl, "FLUSH");
  2188. }
  2189. static int wpa_cli_cmd_radio_work(struct wpa_ctrl *ctrl, int argc, char *argv[])
  2190. {
  2191. return wpa_cli_cmd(ctrl, "RADIO_WORK", 1, argc, argv);
  2192. }
  2193. static int wpa_cli_cmd_neighbor_rep_request(struct wpa_ctrl *ctrl, int argc,
  2194. char *argv[])
  2195. {
  2196. return wpa_cli_cmd(ctrl, "NEIGHBOR_REP_REQUEST", 0, argc, argv);
  2197. }
  2198. static int wpa_cli_cmd_erp_flush(struct wpa_ctrl *ctrl, int argc, char *argv[])
  2199. {
  2200. return wpa_ctrl_command(ctrl, "ERP_FLUSH");
  2201. }
  2202. static int wpa_cli_cmd_mac_rand_scan(struct wpa_ctrl *ctrl, int argc,
  2203. char *argv[])
  2204. {
  2205. return wpa_cli_cmd(ctrl, "MAC_RAND_SCAN", 1, argc, argv);
  2206. }
  2207. static int wpa_cli_cmd_get_pref_freq_list(struct wpa_ctrl *ctrl, int argc,
  2208. char *argv[])
  2209. {
  2210. return wpa_cli_cmd(ctrl, "GET_PREF_FREQ_LIST", 1, argc, argv);
  2211. }
  2212. static int wpa_cli_cmd_p2p_lo_start(struct wpa_ctrl *ctrl, int argc,
  2213. char *argv[])
  2214. {
  2215. return wpa_cli_cmd(ctrl, "P2P_LO_START", 4, argc, argv);
  2216. }
  2217. static int wpa_cli_cmd_p2p_lo_stop(struct wpa_ctrl *ctrl, int argc,
  2218. char *argv[])
  2219. {
  2220. return wpa_cli_cmd(ctrl, "P2P_LO_STOP", 0, argc, argv);
  2221. }
  2222. enum wpa_cli_cmd_flags {
  2223. cli_cmd_flag_none = 0x00,
  2224. cli_cmd_flag_sensitive = 0x01
  2225. };
  2226. struct wpa_cli_cmd {
  2227. const char *cmd;
  2228. int (*handler)(struct wpa_ctrl *ctrl, int argc, char *argv[]);
  2229. char ** (*completion)(const char *str, int pos);
  2230. enum wpa_cli_cmd_flags flags;
  2231. const char *usage;
  2232. };
  2233. static const struct wpa_cli_cmd wpa_cli_commands[] = {
  2234. { "status", wpa_cli_cmd_status, NULL,
  2235. cli_cmd_flag_none,
  2236. "[verbose] = get current WPA/EAPOL/EAP status" },
  2237. { "ifname", wpa_cli_cmd_ifname, NULL,
  2238. cli_cmd_flag_none,
  2239. "= get current interface name" },
  2240. { "ping", wpa_cli_cmd_ping, NULL,
  2241. cli_cmd_flag_none,
  2242. "= pings wpa_supplicant" },
  2243. { "relog", wpa_cli_cmd_relog, NULL,
  2244. cli_cmd_flag_none,
  2245. "= re-open log-file (allow rolling logs)" },
  2246. { "note", wpa_cli_cmd_note, NULL,
  2247. cli_cmd_flag_none,
  2248. "<text> = add a note to wpa_supplicant debug log" },
  2249. { "mib", wpa_cli_cmd_mib, NULL,
  2250. cli_cmd_flag_none,
  2251. "= get MIB variables (dot1x, dot11)" },
  2252. { "help", wpa_cli_cmd_help, wpa_cli_complete_help,
  2253. cli_cmd_flag_none,
  2254. "[command] = show usage help" },
  2255. { "interface", wpa_cli_cmd_interface, NULL,
  2256. cli_cmd_flag_none,
  2257. "[ifname] = show interfaces/select interface" },
  2258. { "level", wpa_cli_cmd_level, NULL,
  2259. cli_cmd_flag_none,
  2260. "<debug level> = change debug level" },
  2261. { "license", wpa_cli_cmd_license, NULL,
  2262. cli_cmd_flag_none,
  2263. "= show full wpa_cli license" },
  2264. { "quit", wpa_cli_cmd_quit, NULL,
  2265. cli_cmd_flag_none,
  2266. "= exit wpa_cli" },
  2267. { "set", wpa_cli_cmd_set, wpa_cli_complete_set,
  2268. cli_cmd_flag_none,
  2269. "= set variables (shows list of variables when run without "
  2270. "arguments)" },
  2271. { "dump", wpa_cli_cmd_dump, NULL,
  2272. cli_cmd_flag_none,
  2273. "= dump config variables" },
  2274. { "get", wpa_cli_cmd_get, wpa_cli_complete_get,
  2275. cli_cmd_flag_none,
  2276. "<name> = get information" },
  2277. { "driver_flags", wpa_cli_cmd_driver_flags, NULL,
  2278. cli_cmd_flag_none,
  2279. "= list driver flags" },
  2280. { "logon", wpa_cli_cmd_logon, NULL,
  2281. cli_cmd_flag_none,
  2282. "= IEEE 802.1X EAPOL state machine logon" },
  2283. { "logoff", wpa_cli_cmd_logoff, NULL,
  2284. cli_cmd_flag_none,
  2285. "= IEEE 802.1X EAPOL state machine logoff" },
  2286. { "pmksa", wpa_cli_cmd_pmksa, NULL,
  2287. cli_cmd_flag_none,
  2288. "= show PMKSA cache" },
  2289. { "pmksa_flush", wpa_cli_cmd_pmksa_flush, NULL,
  2290. cli_cmd_flag_none,
  2291. "= flush PMKSA cache entries" },
  2292. { "reassociate", wpa_cli_cmd_reassociate, NULL,
  2293. cli_cmd_flag_none,
  2294. "= force reassociation" },
  2295. { "reattach", wpa_cli_cmd_reattach, NULL,
  2296. cli_cmd_flag_none,
  2297. "= force reassociation back to the same BSS" },
  2298. { "preauthenticate", wpa_cli_cmd_preauthenticate, wpa_cli_complete_bss,
  2299. cli_cmd_flag_none,
  2300. "<BSSID> = force preauthentication" },
  2301. { "identity", wpa_cli_cmd_identity, wpa_cli_complete_network_id,
  2302. cli_cmd_flag_none,
  2303. "<network id> <identity> = configure identity for an SSID" },
  2304. { "password", wpa_cli_cmd_password, wpa_cli_complete_network_id,
  2305. cli_cmd_flag_sensitive,
  2306. "<network id> <password> = configure password for an SSID" },
  2307. { "new_password", wpa_cli_cmd_new_password,
  2308. wpa_cli_complete_network_id, cli_cmd_flag_sensitive,
  2309. "<network id> <password> = change password for an SSID" },
  2310. { "pin", wpa_cli_cmd_pin, wpa_cli_complete_network_id,
  2311. cli_cmd_flag_sensitive,
  2312. "<network id> <pin> = configure pin for an SSID" },
  2313. { "otp", wpa_cli_cmd_otp, wpa_cli_complete_network_id,
  2314. cli_cmd_flag_sensitive,
  2315. "<network id> <password> = configure one-time-password for an SSID"
  2316. },
  2317. { "passphrase", wpa_cli_cmd_passphrase, wpa_cli_complete_network_id,
  2318. cli_cmd_flag_sensitive,
  2319. "<network id> <passphrase> = configure private key passphrase\n"
  2320. " for an SSID" },
  2321. { "sim", wpa_cli_cmd_sim, wpa_cli_complete_network_id,
  2322. cli_cmd_flag_sensitive,
  2323. "<network id> <pin> = report SIM operation result" },
  2324. { "bssid", wpa_cli_cmd_bssid, wpa_cli_complete_network_id,
  2325. cli_cmd_flag_none,
  2326. "<network id> <BSSID> = set preferred BSSID for an SSID" },
  2327. { "blacklist", wpa_cli_cmd_blacklist, wpa_cli_complete_bss,
  2328. cli_cmd_flag_none,
  2329. "<BSSID> = add a BSSID to the blacklist\n"
  2330. "blacklist clear = clear the blacklist\n"
  2331. "blacklist = display the blacklist" },
  2332. { "log_level", wpa_cli_cmd_log_level, NULL,
  2333. cli_cmd_flag_none,
  2334. "<level> [<timestamp>] = update the log level/timestamp\n"
  2335. "log_level = display the current log level and log options" },
  2336. { "list_networks", wpa_cli_cmd_list_networks, NULL,
  2337. cli_cmd_flag_none,
  2338. "= list configured networks" },
  2339. { "select_network", wpa_cli_cmd_select_network,
  2340. wpa_cli_complete_network_id,
  2341. cli_cmd_flag_none,
  2342. "<network id> = select a network (disable others)" },
  2343. { "enable_network", wpa_cli_cmd_enable_network,
  2344. wpa_cli_complete_network_id,
  2345. cli_cmd_flag_none,
  2346. "<network id> = enable a network" },
  2347. { "disable_network", wpa_cli_cmd_disable_network,
  2348. wpa_cli_complete_network_id,
  2349. cli_cmd_flag_none,
  2350. "<network id> = disable a network" },
  2351. { "add_network", wpa_cli_cmd_add_network, NULL,
  2352. cli_cmd_flag_none,
  2353. "= add a network" },
  2354. { "remove_network", wpa_cli_cmd_remove_network,
  2355. wpa_cli_complete_network_id,
  2356. cli_cmd_flag_none,
  2357. "<network id> = remove a network" },
  2358. { "set_network", wpa_cli_cmd_set_network, wpa_cli_complete_network,
  2359. cli_cmd_flag_sensitive,
  2360. "<network id> <variable> <value> = set network variables (shows\n"
  2361. " list of variables when run without arguments)" },
  2362. { "get_network", wpa_cli_cmd_get_network, wpa_cli_complete_network,
  2363. cli_cmd_flag_none,
  2364. "<network id> <variable> = get network variables" },
  2365. { "dup_network", wpa_cli_cmd_dup_network, wpa_cli_complete_dup_network,
  2366. cli_cmd_flag_none,
  2367. "<src network id> <dst network id> <variable> = duplicate network variables"
  2368. },
  2369. { "list_creds", wpa_cli_cmd_list_creds, NULL,
  2370. cli_cmd_flag_none,
  2371. "= list configured credentials" },
  2372. { "add_cred", wpa_cli_cmd_add_cred, NULL,
  2373. cli_cmd_flag_none,
  2374. "= add a credential" },
  2375. { "remove_cred", wpa_cli_cmd_remove_cred, NULL,
  2376. cli_cmd_flag_none,
  2377. "<cred id> = remove a credential" },
  2378. { "set_cred", wpa_cli_cmd_set_cred, NULL,
  2379. cli_cmd_flag_sensitive,
  2380. "<cred id> <variable> <value> = set credential variables" },
  2381. { "get_cred", wpa_cli_cmd_get_cred, NULL,
  2382. cli_cmd_flag_none,
  2383. "<cred id> <variable> = get credential variables" },
  2384. { "save_config", wpa_cli_cmd_save_config, NULL,
  2385. cli_cmd_flag_none,
  2386. "= save the current configuration" },
  2387. { "disconnect", wpa_cli_cmd_disconnect, NULL,
  2388. cli_cmd_flag_none,
  2389. "= disconnect and wait for reassociate/reconnect command before\n"
  2390. " connecting" },
  2391. { "reconnect", wpa_cli_cmd_reconnect, NULL,
  2392. cli_cmd_flag_none,
  2393. "= like reassociate, but only takes effect if already disconnected"
  2394. },
  2395. { "scan", wpa_cli_cmd_scan, NULL,
  2396. cli_cmd_flag_none,
  2397. "= request new BSS scan" },
  2398. { "scan_results", wpa_cli_cmd_scan_results, NULL,
  2399. cli_cmd_flag_none,
  2400. "= get latest scan results" },
  2401. { "abort_scan", wpa_cli_cmd_abort_scan, NULL,
  2402. cli_cmd_flag_none,
  2403. "= request ongoing scan to be aborted" },
  2404. { "bss", wpa_cli_cmd_bss, wpa_cli_complete_bss,
  2405. cli_cmd_flag_none,
  2406. "<<idx> | <bssid>> = get detailed scan result info" },
  2407. { "get_capability", wpa_cli_cmd_get_capability,
  2408. wpa_cli_complete_get_capability, cli_cmd_flag_none,
  2409. "<eap/pairwise/group/key_mgmt/proto/auth_alg/channels/freq/modes> "
  2410. "= get capabilities" },
  2411. { "reconfigure", wpa_cli_cmd_reconfigure, NULL,
  2412. cli_cmd_flag_none,
  2413. "= force wpa_supplicant to re-read its configuration file" },
  2414. { "terminate", wpa_cli_cmd_terminate, NULL,
  2415. cli_cmd_flag_none,
  2416. "= terminate wpa_supplicant" },
  2417. { "interface_add", wpa_cli_cmd_interface_add, NULL,
  2418. cli_cmd_flag_none,
  2419. "<ifname> <confname> <driver> <ctrl_interface> <driver_param>\n"
  2420. " <bridge_name> <create> <type> = adds new interface, all "
  2421. "parameters but\n"
  2422. " <ifname> are optional. Supported types are station ('sta') and "
  2423. "AP ('ap')" },
  2424. { "interface_remove", wpa_cli_cmd_interface_remove, NULL,
  2425. cli_cmd_flag_none,
  2426. "<ifname> = removes the interface" },
  2427. { "interface_list", wpa_cli_cmd_interface_list, NULL,
  2428. cli_cmd_flag_none,
  2429. "= list available interfaces" },
  2430. { "ap_scan", wpa_cli_cmd_ap_scan, NULL,
  2431. cli_cmd_flag_none,
  2432. "<value> = set ap_scan parameter" },
  2433. { "scan_interval", wpa_cli_cmd_scan_interval, NULL,
  2434. cli_cmd_flag_none,
  2435. "<value> = set scan_interval parameter (in seconds)" },
  2436. { "bss_expire_age", wpa_cli_cmd_bss_expire_age, NULL,
  2437. cli_cmd_flag_none,
  2438. "<value> = set BSS expiration age parameter" },
  2439. { "bss_expire_count", wpa_cli_cmd_bss_expire_count, NULL,
  2440. cli_cmd_flag_none,
  2441. "<value> = set BSS expiration scan count parameter" },
  2442. { "bss_flush", wpa_cli_cmd_bss_flush, NULL,
  2443. cli_cmd_flag_none,
  2444. "<value> = set BSS flush age (0 by default)" },
  2445. { "stkstart", wpa_cli_cmd_stkstart, NULL,
  2446. cli_cmd_flag_none,
  2447. "<addr> = request STK negotiation with <addr>" },
  2448. { "ft_ds", wpa_cli_cmd_ft_ds, wpa_cli_complete_bss,
  2449. cli_cmd_flag_none,
  2450. "<addr> = request over-the-DS FT with <addr>" },
  2451. { "wps_pbc", wpa_cli_cmd_wps_pbc, wpa_cli_complete_bss,
  2452. cli_cmd_flag_none,
  2453. "[BSSID] = start Wi-Fi Protected Setup: Push Button Configuration" },
  2454. { "wps_pin", wpa_cli_cmd_wps_pin, wpa_cli_complete_bss,
  2455. cli_cmd_flag_sensitive,
  2456. "<BSSID> [PIN] = start WPS PIN method (returns PIN, if not "
  2457. "hardcoded)" },
  2458. { "wps_check_pin", wpa_cli_cmd_wps_check_pin, NULL,
  2459. cli_cmd_flag_sensitive,
  2460. "<PIN> = verify PIN checksum" },
  2461. { "wps_cancel", wpa_cli_cmd_wps_cancel, NULL, cli_cmd_flag_none,
  2462. "Cancels the pending WPS operation" },
  2463. #ifdef CONFIG_WPS_NFC
  2464. { "wps_nfc", wpa_cli_cmd_wps_nfc, wpa_cli_complete_bss,
  2465. cli_cmd_flag_none,
  2466. "[BSSID] = start Wi-Fi Protected Setup: NFC" },
  2467. { "wps_nfc_config_token", wpa_cli_cmd_wps_nfc_config_token, NULL,
  2468. cli_cmd_flag_none,
  2469. "<WPS|NDEF> = build configuration token" },
  2470. { "wps_nfc_token", wpa_cli_cmd_wps_nfc_token, NULL,
  2471. cli_cmd_flag_none,
  2472. "<WPS|NDEF> = create password token" },
  2473. { "wps_nfc_tag_read", wpa_cli_cmd_wps_nfc_tag_read, NULL,
  2474. cli_cmd_flag_sensitive,
  2475. "<hexdump of payload> = report read NFC tag with WPS data" },
  2476. { "nfc_get_handover_req", wpa_cli_cmd_nfc_get_handover_req, NULL,
  2477. cli_cmd_flag_none,
  2478. "<NDEF> <WPS> = create NFC handover request" },
  2479. { "nfc_get_handover_sel", wpa_cli_cmd_nfc_get_handover_sel, NULL,
  2480. cli_cmd_flag_none,
  2481. "<NDEF> <WPS> = create NFC handover select" },
  2482. { "nfc_report_handover", wpa_cli_cmd_nfc_report_handover, NULL,
  2483. cli_cmd_flag_none,
  2484. "<role> <type> <hexdump of req> <hexdump of sel> = report completed "
  2485. "NFC handover" },
  2486. #endif /* CONFIG_WPS_NFC */
  2487. { "wps_reg", wpa_cli_cmd_wps_reg, wpa_cli_complete_bss,
  2488. cli_cmd_flag_sensitive,
  2489. "<BSSID> <AP PIN> = start WPS Registrar to configure an AP" },
  2490. { "wps_ap_pin", wpa_cli_cmd_wps_ap_pin, NULL,
  2491. cli_cmd_flag_sensitive,
  2492. "[params..] = enable/disable AP PIN" },
  2493. { "wps_er_start", wpa_cli_cmd_wps_er_start, NULL,
  2494. cli_cmd_flag_none,
  2495. "[IP address] = start Wi-Fi Protected Setup External Registrar" },
  2496. { "wps_er_stop", wpa_cli_cmd_wps_er_stop, NULL,
  2497. cli_cmd_flag_none,
  2498. "= stop Wi-Fi Protected Setup External Registrar" },
  2499. { "wps_er_pin", wpa_cli_cmd_wps_er_pin, NULL,
  2500. cli_cmd_flag_sensitive,
  2501. "<UUID> <PIN> = add an Enrollee PIN to External Registrar" },
  2502. { "wps_er_pbc", wpa_cli_cmd_wps_er_pbc, NULL,
  2503. cli_cmd_flag_none,
  2504. "<UUID> = accept an Enrollee PBC using External Registrar" },
  2505. { "wps_er_learn", wpa_cli_cmd_wps_er_learn, NULL,
  2506. cli_cmd_flag_sensitive,
  2507. "<UUID> <PIN> = learn AP configuration" },
  2508. { "wps_er_set_config", wpa_cli_cmd_wps_er_set_config, NULL,
  2509. cli_cmd_flag_none,
  2510. "<UUID> <network id> = set AP configuration for enrolling" },
  2511. { "wps_er_config", wpa_cli_cmd_wps_er_config, NULL,
  2512. cli_cmd_flag_sensitive,
  2513. "<UUID> <PIN> <SSID> <auth> <encr> <key> = configure AP" },
  2514. #ifdef CONFIG_WPS_NFC
  2515. { "wps_er_nfc_config_token", wpa_cli_cmd_wps_er_nfc_config_token, NULL,
  2516. cli_cmd_flag_none,
  2517. "<WPS/NDEF> <UUID> = build NFC configuration token" },
  2518. #endif /* CONFIG_WPS_NFC */
  2519. { "ibss_rsn", wpa_cli_cmd_ibss_rsn, NULL,
  2520. cli_cmd_flag_none,
  2521. "<addr> = request RSN authentication with <addr> in IBSS" },
  2522. #ifdef CONFIG_AP
  2523. { "sta", wpa_cli_cmd_sta, wpa_cli_complete_sta,
  2524. cli_cmd_flag_none,
  2525. "<addr> = get information about an associated station (AP)" },
  2526. { "all_sta", wpa_cli_cmd_all_sta, NULL,
  2527. cli_cmd_flag_none,
  2528. "= get information about all associated stations (AP)" },
  2529. { "list_sta", wpa_cli_cmd_list_sta, NULL,
  2530. cli_cmd_flag_none,
  2531. "= list all stations (AP)" },
  2532. { "deauthenticate", wpa_cli_cmd_deauthenticate,
  2533. wpa_cli_complete_deauthenticate, cli_cmd_flag_none,
  2534. "<addr> = deauthenticate a station" },
  2535. { "disassociate", wpa_cli_cmd_disassociate,
  2536. wpa_cli_complete_disassociate, cli_cmd_flag_none,
  2537. "<addr> = disassociate a station" },
  2538. { "chan_switch", wpa_cli_cmd_chanswitch, NULL,
  2539. cli_cmd_flag_none,
  2540. "<cs_count> <freq> [sec_channel_offset=] [center_freq1=]"
  2541. " [center_freq2=] [bandwidth=] [blocktx] [ht|vht]"
  2542. " = CSA parameters" },
  2543. #endif /* CONFIG_AP */
  2544. { "suspend", wpa_cli_cmd_suspend, NULL, cli_cmd_flag_none,
  2545. "= notification of suspend/hibernate" },
  2546. { "resume", wpa_cli_cmd_resume, NULL, cli_cmd_flag_none,
  2547. "= notification of resume/thaw" },
  2548. #ifdef CONFIG_TESTING_OPTIONS
  2549. { "drop_sa", wpa_cli_cmd_drop_sa, NULL, cli_cmd_flag_none,
  2550. "= drop SA without deauth/disassoc (test command)" },
  2551. #endif /* CONFIG_TESTING_OPTIONS */
  2552. { "roam", wpa_cli_cmd_roam, wpa_cli_complete_bss,
  2553. cli_cmd_flag_none,
  2554. "<addr> = roam to the specified BSS" },
  2555. #ifdef CONFIG_MESH
  2556. { "mesh_interface_add", wpa_cli_cmd_mesh_interface_add, NULL,
  2557. cli_cmd_flag_none,
  2558. "[ifname] = Create a new mesh interface" },
  2559. { "mesh_group_add", wpa_cli_cmd_mesh_group_add, NULL,
  2560. cli_cmd_flag_none,
  2561. "<network id> = join a mesh network (disable others)" },
  2562. { "mesh_group_remove", wpa_cli_cmd_mesh_group_remove, NULL,
  2563. cli_cmd_flag_none,
  2564. "<ifname> = Remove mesh group interface" },
  2565. { "mesh_peer_remove", wpa_cli_cmd_mesh_peer_remove, NULL,
  2566. cli_cmd_flag_none,
  2567. "<addr> = Remove a mesh peer" },
  2568. { "mesh_peer_add", wpa_cli_cmd_mesh_peer_add, NULL,
  2569. cli_cmd_flag_none,
  2570. "<addr> [duration=<seconds>] = Add a mesh peer" },
  2571. #endif /* CONFIG_MESH */
  2572. #ifdef CONFIG_P2P
  2573. { "p2p_find", wpa_cli_cmd_p2p_find, wpa_cli_complete_p2p_find,
  2574. cli_cmd_flag_none,
  2575. "[timeout] [type=*] = find P2P Devices for up-to timeout seconds" },
  2576. { "p2p_stop_find", wpa_cli_cmd_p2p_stop_find, NULL, cli_cmd_flag_none,
  2577. "= stop P2P Devices search" },
  2578. { "p2p_asp_provision", wpa_cli_cmd_p2p_asp_provision, NULL,
  2579. cli_cmd_flag_none,
  2580. "<addr> adv_id=<adv_id> conncap=<conncap> [info=<infodata>] = provision with a P2P ASP Device" },
  2581. { "p2p_asp_provision_resp", wpa_cli_cmd_p2p_asp_provision_resp, NULL,
  2582. cli_cmd_flag_none,
  2583. "<addr> adv_id=<adv_id> [role<conncap>] [info=<infodata>] = provision with a P2P ASP Device" },
  2584. { "p2p_connect", wpa_cli_cmd_p2p_connect, wpa_cli_complete_p2p_connect,
  2585. cli_cmd_flag_none,
  2586. "<addr> <\"pbc\"|PIN> [ht40] = connect to a P2P Device" },
  2587. { "p2p_listen", wpa_cli_cmd_p2p_listen, NULL, cli_cmd_flag_none,
  2588. "[timeout] = listen for P2P Devices for up-to timeout seconds" },
  2589. { "p2p_group_remove", wpa_cli_cmd_p2p_group_remove,
  2590. wpa_cli_complete_p2p_group_remove, cli_cmd_flag_none,
  2591. "<ifname> = remove P2P group interface (terminate group if GO)" },
  2592. { "p2p_group_add", wpa_cli_cmd_p2p_group_add, NULL, cli_cmd_flag_none,
  2593. "[ht40] = add a new P2P group (local end as GO)" },
  2594. { "p2p_group_member", wpa_cli_cmd_p2p_group_member, NULL,
  2595. cli_cmd_flag_none,
  2596. "<dev_addr> = Get peer interface address on local GO using peer Device Address" },
  2597. { "p2p_prov_disc", wpa_cli_cmd_p2p_prov_disc,
  2598. wpa_cli_complete_p2p_peer, cli_cmd_flag_none,
  2599. "<addr> <method> = request provisioning discovery" },
  2600. { "p2p_get_passphrase", wpa_cli_cmd_p2p_get_passphrase, NULL,
  2601. cli_cmd_flag_none,
  2602. "= get the passphrase for a group (GO only)" },
  2603. { "p2p_serv_disc_req", wpa_cli_cmd_p2p_serv_disc_req,
  2604. wpa_cli_complete_p2p_peer, cli_cmd_flag_none,
  2605. "<addr> <TLVs> = schedule service discovery request" },
  2606. { "p2p_serv_disc_cancel_req", wpa_cli_cmd_p2p_serv_disc_cancel_req,
  2607. NULL, cli_cmd_flag_none,
  2608. "<id> = cancel pending service discovery request" },
  2609. { "p2p_serv_disc_resp", wpa_cli_cmd_p2p_serv_disc_resp, NULL,
  2610. cli_cmd_flag_none,
  2611. "<freq> <addr> <dialog token> <TLVs> = service discovery response" },
  2612. { "p2p_service_update", wpa_cli_cmd_p2p_service_update, NULL,
  2613. cli_cmd_flag_none,
  2614. "= indicate change in local services" },
  2615. { "p2p_serv_disc_external", wpa_cli_cmd_p2p_serv_disc_external, NULL,
  2616. cli_cmd_flag_none,
  2617. "<external> = set external processing of service discovery" },
  2618. { "p2p_service_flush", wpa_cli_cmd_p2p_service_flush, NULL,
  2619. cli_cmd_flag_none,
  2620. "= remove all stored service entries" },
  2621. { "p2p_service_add", wpa_cli_cmd_p2p_service_add, NULL,
  2622. cli_cmd_flag_none,
  2623. "<bonjour|upnp|asp> <query|version> <response|service> = add a local "
  2624. "service" },
  2625. { "p2p_service_rep", wpa_cli_cmd_p2p_service_rep, NULL,
  2626. cli_cmd_flag_none,
  2627. "asp <auto> <adv_id> <svc_state> <svc_string> [<svc_info>] = replace "
  2628. "local ASP service" },
  2629. { "p2p_service_del", wpa_cli_cmd_p2p_service_del, NULL,
  2630. cli_cmd_flag_none,
  2631. "<bonjour|upnp> <query|version> [|service] = remove a local "
  2632. "service" },
  2633. { "p2p_reject", wpa_cli_cmd_p2p_reject, wpa_cli_complete_p2p_peer,
  2634. cli_cmd_flag_none,
  2635. "<addr> = reject connection attempts from a specific peer" },
  2636. { "p2p_invite", wpa_cli_cmd_p2p_invite, NULL,
  2637. cli_cmd_flag_none,
  2638. "<cmd> [peer=addr] = invite peer" },
  2639. { "p2p_peers", wpa_cli_cmd_p2p_peers, NULL, cli_cmd_flag_none,
  2640. "[discovered] = list known (optionally, only fully discovered) P2P "
  2641. "peers" },
  2642. { "p2p_peer", wpa_cli_cmd_p2p_peer, wpa_cli_complete_p2p_peer,
  2643. cli_cmd_flag_none,
  2644. "<address> = show information about known P2P peer" },
  2645. { "p2p_set", wpa_cli_cmd_p2p_set, wpa_cli_complete_p2p_set,
  2646. cli_cmd_flag_none,
  2647. "<field> <value> = set a P2P parameter" },
  2648. { "p2p_flush", wpa_cli_cmd_p2p_flush, NULL, cli_cmd_flag_none,
  2649. "= flush P2P state" },
  2650. { "p2p_cancel", wpa_cli_cmd_p2p_cancel, NULL, cli_cmd_flag_none,
  2651. "= cancel P2P group formation" },
  2652. { "p2p_unauthorize", wpa_cli_cmd_p2p_unauthorize,
  2653. wpa_cli_complete_p2p_peer, cli_cmd_flag_none,
  2654. "<address> = unauthorize a peer" },
  2655. { "p2p_presence_req", wpa_cli_cmd_p2p_presence_req, NULL,
  2656. cli_cmd_flag_none,
  2657. "[<duration> <interval>] [<duration> <interval>] = request GO "
  2658. "presence" },
  2659. { "p2p_ext_listen", wpa_cli_cmd_p2p_ext_listen, NULL,
  2660. cli_cmd_flag_none,
  2661. "[<period> <interval>] = set extended listen timing" },
  2662. { "p2p_remove_client", wpa_cli_cmd_p2p_remove_client,
  2663. wpa_cli_complete_p2p_peer, cli_cmd_flag_none,
  2664. "<address|iface=address> = remove a peer from all groups" },
  2665. { "vendor_elem_add", wpa_cli_cmd_vendor_elem_add, NULL,
  2666. cli_cmd_flag_none,
  2667. "<frame id> <hexdump of elem(s)> = add vendor specific IEs to frame(s)\n"
  2668. VENDOR_ELEM_FRAME_ID },
  2669. { "vendor_elem_get", wpa_cli_cmd_vendor_elem_get, NULL,
  2670. cli_cmd_flag_none,
  2671. "<frame id> = get vendor specific IE(s) to frame(s)\n"
  2672. VENDOR_ELEM_FRAME_ID },
  2673. { "vendor_elem_remove", wpa_cli_cmd_vendor_elem_remove, NULL,
  2674. cli_cmd_flag_none,
  2675. "<frame id> <hexdump of elem(s)> = remove vendor specific IE(s) in frame(s)\n"
  2676. VENDOR_ELEM_FRAME_ID },
  2677. #endif /* CONFIG_P2P */
  2678. #ifdef CONFIG_WIFI_DISPLAY
  2679. { "wfd_subelem_set", wpa_cli_cmd_wfd_subelem_set, NULL,
  2680. cli_cmd_flag_none,
  2681. "<subelem> [contents] = set Wi-Fi Display subelement" },
  2682. { "wfd_subelem_get", wpa_cli_cmd_wfd_subelem_get, NULL,
  2683. cli_cmd_flag_none,
  2684. "<subelem> = get Wi-Fi Display subelement" },
  2685. #endif /* CONFIG_WIFI_DISPLAY */
  2686. #ifdef CONFIG_INTERWORKING
  2687. { "fetch_anqp", wpa_cli_cmd_fetch_anqp, NULL, cli_cmd_flag_none,
  2688. "= fetch ANQP information for all APs" },
  2689. { "stop_fetch_anqp", wpa_cli_cmd_stop_fetch_anqp, NULL,
  2690. cli_cmd_flag_none,
  2691. "= stop fetch_anqp operation" },
  2692. { "interworking_select", wpa_cli_cmd_interworking_select, NULL,
  2693. cli_cmd_flag_none,
  2694. "[auto] = perform Interworking network selection" },
  2695. { "interworking_connect", wpa_cli_cmd_interworking_connect,
  2696. wpa_cli_complete_bss, cli_cmd_flag_none,
  2697. "<BSSID> = connect using Interworking credentials" },
  2698. { "interworking_add_network", wpa_cli_cmd_interworking_add_network,
  2699. wpa_cli_complete_bss, cli_cmd_flag_none,
  2700. "<BSSID> = connect using Interworking credentials" },
  2701. { "anqp_get", wpa_cli_cmd_anqp_get, wpa_cli_complete_bss,
  2702. cli_cmd_flag_none,
  2703. "<addr> <info id>[,<info id>]... = request ANQP information" },
  2704. { "gas_request", wpa_cli_cmd_gas_request, wpa_cli_complete_bss,
  2705. cli_cmd_flag_none,
  2706. "<addr> <AdvProtoID> [QueryReq] = GAS request" },
  2707. { "gas_response_get", wpa_cli_cmd_gas_response_get,
  2708. wpa_cli_complete_bss, cli_cmd_flag_none,
  2709. "<addr> <dialog token> [start,len] = Fetch last GAS response" },
  2710. #endif /* CONFIG_INTERWORKING */
  2711. #ifdef CONFIG_HS20
  2712. { "hs20_anqp_get", wpa_cli_cmd_hs20_anqp_get, wpa_cli_complete_bss,
  2713. cli_cmd_flag_none,
  2714. "<addr> <subtype>[,<subtype>]... = request HS 2.0 ANQP information"
  2715. },
  2716. { "nai_home_realm_list", wpa_cli_cmd_get_nai_home_realm_list,
  2717. wpa_cli_complete_bss, cli_cmd_flag_none,
  2718. "<addr> <home realm> = get HS20 nai home realm list" },
  2719. { "hs20_icon_request", wpa_cli_cmd_hs20_icon_request,
  2720. wpa_cli_complete_bss, cli_cmd_flag_none,
  2721. "<addr> <icon name> = get Hotspot 2.0 OSU icon" },
  2722. { "fetch_osu", wpa_cli_cmd_fetch_osu, NULL, cli_cmd_flag_none,
  2723. "= fetch OSU provider information from all APs" },
  2724. { "cancel_fetch_osu", wpa_cli_cmd_cancel_fetch_osu, NULL,
  2725. cli_cmd_flag_none,
  2726. "= cancel fetch_osu command" },
  2727. #endif /* CONFIG_HS20 */
  2728. { "sta_autoconnect", wpa_cli_cmd_sta_autoconnect, NULL,
  2729. cli_cmd_flag_none,
  2730. "<0/1> = disable/enable automatic reconnection" },
  2731. { "tdls_discover", wpa_cli_cmd_tdls_discover, NULL,
  2732. cli_cmd_flag_none,
  2733. "<addr> = request TDLS discovery with <addr>" },
  2734. { "tdls_setup", wpa_cli_cmd_tdls_setup, NULL,
  2735. cli_cmd_flag_none,
  2736. "<addr> = request TDLS setup with <addr>" },
  2737. { "tdls_teardown", wpa_cli_cmd_tdls_teardown, NULL,
  2738. cli_cmd_flag_none,
  2739. "<addr> = tear down TDLS with <addr>" },
  2740. { "tdls_link_status", wpa_cli_cmd_tdls_link_status, NULL,
  2741. cli_cmd_flag_none,
  2742. "<addr> = TDLS link status with <addr>" },
  2743. { "wmm_ac_addts", wpa_cli_cmd_wmm_ac_addts, NULL,
  2744. cli_cmd_flag_none,
  2745. "<uplink/downlink/bidi> <tsid=0..7> <up=0..7> [nominal_msdu_size=#] "
  2746. "[mean_data_rate=#] [min_phy_rate=#] [sba=#] [fixed_nominal_msdu] "
  2747. "= add WMM-AC traffic stream" },
  2748. { "wmm_ac_delts", wpa_cli_cmd_wmm_ac_delts, NULL,
  2749. cli_cmd_flag_none,
  2750. "<tsid> = delete WMM-AC traffic stream" },
  2751. { "wmm_ac_status", wpa_cli_cmd_wmm_ac_status, NULL,
  2752. cli_cmd_flag_none,
  2753. "= show status for Wireless Multi-Media Admission-Control" },
  2754. { "tdls_chan_switch", wpa_cli_cmd_tdls_chan_switch, NULL,
  2755. cli_cmd_flag_none,
  2756. "<addr> <oper class> <freq> [sec_channel_offset=] [center_freq1=] "
  2757. "[center_freq2=] [bandwidth=] [ht|vht] = enable channel switching "
  2758. "with TDLS peer" },
  2759. { "tdls_cancel_chan_switch", wpa_cli_cmd_tdls_cancel_chan_switch, NULL,
  2760. cli_cmd_flag_none,
  2761. "<addr> = disable channel switching with TDLS peer <addr>" },
  2762. { "signal_poll", wpa_cli_cmd_signal_poll, NULL,
  2763. cli_cmd_flag_none,
  2764. "= get signal parameters" },
  2765. { "signal_monitor", wpa_cli_cmd_signal_monitor, NULL,
  2766. cli_cmd_flag_none,
  2767. "= set signal monitor parameters" },
  2768. { "pktcnt_poll", wpa_cli_cmd_pktcnt_poll, NULL,
  2769. cli_cmd_flag_none,
  2770. "= get TX/RX packet counters" },
  2771. { "reauthenticate", wpa_cli_cmd_reauthenticate, NULL,
  2772. cli_cmd_flag_none,
  2773. "= trigger IEEE 802.1X/EAPOL reauthentication" },
  2774. #ifdef CONFIG_AUTOSCAN
  2775. { "autoscan", wpa_cli_cmd_autoscan, NULL, cli_cmd_flag_none,
  2776. "[params] = Set or unset (if none) autoscan parameters" },
  2777. #endif /* CONFIG_AUTOSCAN */
  2778. #ifdef CONFIG_WNM
  2779. { "wnm_sleep", wpa_cli_cmd_wnm_sleep, NULL, cli_cmd_flag_none,
  2780. "<enter/exit> [interval=#] = enter/exit WNM-Sleep mode" },
  2781. { "wnm_bss_query", wpa_cli_cmd_wnm_bss_query, NULL, cli_cmd_flag_none,
  2782. "<query reason> [list] = Send BSS Transition Management Query" },
  2783. #endif /* CONFIG_WNM */
  2784. { "raw", wpa_cli_cmd_raw, NULL, cli_cmd_flag_sensitive,
  2785. "<params..> = Sent unprocessed command" },
  2786. { "flush", wpa_cli_cmd_flush, NULL, cli_cmd_flag_none,
  2787. "= flush wpa_supplicant state" },
  2788. #ifdef ANDROID
  2789. { "driver", wpa_cli_cmd_driver, NULL, cli_cmd_flag_none,
  2790. "<command> = driver private commands" },
  2791. #endif /* ANDROID */
  2792. { "radio_work", wpa_cli_cmd_radio_work, NULL, cli_cmd_flag_none,
  2793. "= radio_work <show/add/done>" },
  2794. { "vendor", wpa_cli_cmd_vendor, NULL, cli_cmd_flag_none,
  2795. "<vendor id> <command id> [<hex formatted command argument>] = Send vendor command"
  2796. },
  2797. { "neighbor_rep_request",
  2798. wpa_cli_cmd_neighbor_rep_request, NULL, cli_cmd_flag_none,
  2799. "[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)"
  2800. },
  2801. { "erp_flush", wpa_cli_cmd_erp_flush, NULL, cli_cmd_flag_none,
  2802. "= flush ERP keys" },
  2803. { "mac_rand_scan",
  2804. wpa_cli_cmd_mac_rand_scan, NULL, cli_cmd_flag_none,
  2805. "<scan|sched|pno|all> enable=<0/1> [addr=mac-address "
  2806. "mask=mac-address-mask] = scan MAC randomization"
  2807. },
  2808. { "get_pref_freq_list", wpa_cli_cmd_get_pref_freq_list, NULL,
  2809. cli_cmd_flag_none,
  2810. "<interface type> = retrieve preferred freq list for the specified interface type" },
  2811. { "p2p_lo_start", wpa_cli_cmd_p2p_lo_start, NULL,
  2812. cli_cmd_flag_none,
  2813. "<freq> <period> <interval> <count> = start P2P listen offload" },
  2814. { "p2p_lo_stop", wpa_cli_cmd_p2p_lo_stop, NULL,
  2815. cli_cmd_flag_none,
  2816. "= stop P2P listen offload" },
  2817. { NULL, NULL, NULL, cli_cmd_flag_none, NULL }
  2818. };
  2819. /*
  2820. * Prints command usage, lines are padded with the specified string.
  2821. */
  2822. static void print_cmd_help(const struct wpa_cli_cmd *cmd, const char *pad)
  2823. {
  2824. char c;
  2825. size_t n;
  2826. printf("%s%s ", pad, cmd->cmd);
  2827. for (n = 0; (c = cmd->usage[n]); n++) {
  2828. printf("%c", c);
  2829. if (c == '\n')
  2830. printf("%s", pad);
  2831. }
  2832. printf("\n");
  2833. }
  2834. static void print_help(const char *cmd)
  2835. {
  2836. int n;
  2837. printf("commands:\n");
  2838. for (n = 0; wpa_cli_commands[n].cmd; n++) {
  2839. if (cmd == NULL || str_starts(wpa_cli_commands[n].cmd, cmd))
  2840. print_cmd_help(&wpa_cli_commands[n], " ");
  2841. }
  2842. }
  2843. static int wpa_cli_edit_filter_history_cb(void *ctx, const char *cmd)
  2844. {
  2845. const char *c, *delim;
  2846. int n;
  2847. size_t len;
  2848. delim = os_strchr(cmd, ' ');
  2849. if (delim)
  2850. len = delim - cmd;
  2851. else
  2852. len = os_strlen(cmd);
  2853. for (n = 0; (c = wpa_cli_commands[n].cmd); n++) {
  2854. if (os_strncasecmp(cmd, c, len) == 0 && len == os_strlen(c))
  2855. return (wpa_cli_commands[n].flags &
  2856. cli_cmd_flag_sensitive);
  2857. }
  2858. return 0;
  2859. }
  2860. static char ** wpa_list_cmd_list(void)
  2861. {
  2862. char **res;
  2863. int i, count;
  2864. struct cli_txt_entry *e;
  2865. count = ARRAY_SIZE(wpa_cli_commands);
  2866. count += dl_list_len(&p2p_groups);
  2867. count += dl_list_len(&ifnames);
  2868. res = os_calloc(count + 1, sizeof(char *));
  2869. if (res == NULL)
  2870. return NULL;
  2871. for (i = 0; wpa_cli_commands[i].cmd; i++) {
  2872. res[i] = os_strdup(wpa_cli_commands[i].cmd);
  2873. if (res[i] == NULL)
  2874. break;
  2875. }
  2876. dl_list_for_each(e, &p2p_groups, struct cli_txt_entry, list) {
  2877. size_t len = 8 + os_strlen(e->txt);
  2878. res[i] = os_malloc(len);
  2879. if (res[i] == NULL)
  2880. break;
  2881. os_snprintf(res[i], len, "ifname=%s", e->txt);
  2882. i++;
  2883. }
  2884. dl_list_for_each(e, &ifnames, struct cli_txt_entry, list) {
  2885. res[i] = os_strdup(e->txt);
  2886. if (res[i] == NULL)
  2887. break;
  2888. i++;
  2889. }
  2890. return res;
  2891. }
  2892. static char ** wpa_cli_cmd_completion(const char *cmd, const char *str,
  2893. int pos)
  2894. {
  2895. int i;
  2896. for (i = 0; wpa_cli_commands[i].cmd; i++) {
  2897. if (os_strcasecmp(wpa_cli_commands[i].cmd, cmd) == 0) {
  2898. if (wpa_cli_commands[i].completion)
  2899. return wpa_cli_commands[i].completion(str,
  2900. pos);
  2901. edit_clear_line();
  2902. printf("\r%s\n", wpa_cli_commands[i].usage);
  2903. edit_redraw();
  2904. break;
  2905. }
  2906. }
  2907. return NULL;
  2908. }
  2909. static char ** wpa_cli_edit_completion_cb(void *ctx, const char *str, int pos)
  2910. {
  2911. char **res;
  2912. const char *end;
  2913. char *cmd;
  2914. if (pos > 7 && os_strncasecmp(str, "IFNAME=", 7) == 0) {
  2915. end = os_strchr(str, ' ');
  2916. if (end && pos > end - str) {
  2917. pos -= end - str + 1;
  2918. str = end + 1;
  2919. }
  2920. }
  2921. end = os_strchr(str, ' ');
  2922. if (end == NULL || str + pos < end)
  2923. return wpa_list_cmd_list();
  2924. cmd = os_malloc(pos + 1);
  2925. if (cmd == NULL)
  2926. return NULL;
  2927. os_memcpy(cmd, str, pos);
  2928. cmd[end - str] = '\0';
  2929. res = wpa_cli_cmd_completion(cmd, str, pos);
  2930. os_free(cmd);
  2931. return res;
  2932. }
  2933. static int wpa_request(struct wpa_ctrl *ctrl, int argc, char *argv[])
  2934. {
  2935. const struct wpa_cli_cmd *cmd, *match = NULL;
  2936. int count;
  2937. int ret = 0;
  2938. if (argc > 1 && os_strncasecmp(argv[0], "IFNAME=", 7) == 0) {
  2939. ifname_prefix = argv[0] + 7;
  2940. argv = &argv[1];
  2941. argc--;
  2942. } else
  2943. ifname_prefix = NULL;
  2944. if (argc == 0)
  2945. return -1;
  2946. count = 0;
  2947. cmd = wpa_cli_commands;
  2948. while (cmd->cmd) {
  2949. if (os_strncasecmp(cmd->cmd, argv[0], os_strlen(argv[0])) == 0)
  2950. {
  2951. match = cmd;
  2952. if (os_strcasecmp(cmd->cmd, argv[0]) == 0) {
  2953. /* we have an exact match */
  2954. count = 1;
  2955. break;
  2956. }
  2957. count++;
  2958. }
  2959. cmd++;
  2960. }
  2961. if (count > 1) {
  2962. printf("Ambiguous command '%s'; possible commands:", argv[0]);
  2963. cmd = wpa_cli_commands;
  2964. while (cmd->cmd) {
  2965. if (os_strncasecmp(cmd->cmd, argv[0],
  2966. os_strlen(argv[0])) == 0) {
  2967. printf(" %s", cmd->cmd);
  2968. }
  2969. cmd++;
  2970. }
  2971. printf("\n");
  2972. ret = 1;
  2973. } else if (count == 0) {
  2974. printf("Unknown command '%s'\n", argv[0]);
  2975. ret = 1;
  2976. } else {
  2977. ret = match->handler(ctrl, argc - 1, &argv[1]);
  2978. }
  2979. return ret;
  2980. }
  2981. static int wpa_cli_exec(const char *program, const char *arg1,
  2982. const char *arg2)
  2983. {
  2984. char *arg;
  2985. size_t len;
  2986. int res;
  2987. /* If no interface is specified, set the global */
  2988. if (!arg1)
  2989. arg1 = "global";
  2990. len = os_strlen(arg1) + os_strlen(arg2) + 2;
  2991. arg = os_malloc(len);
  2992. if (arg == NULL)
  2993. return -1;
  2994. os_snprintf(arg, len, "%s %s", arg1, arg2);
  2995. res = os_exec(program, arg, 1);
  2996. os_free(arg);
  2997. return res;
  2998. }
  2999. static void wpa_cli_action_process(const char *msg)
  3000. {
  3001. const char *pos;
  3002. char *copy = NULL, *id, *pos2;
  3003. const char *ifname = ctrl_ifname;
  3004. char ifname_buf[100];
  3005. if (eloop_terminated())
  3006. return;
  3007. pos = msg;
  3008. if (os_strncmp(pos, "IFNAME=", 7) == 0) {
  3009. const char *end;
  3010. end = os_strchr(pos + 7, ' ');
  3011. if (end && (unsigned int) (end - pos) < sizeof(ifname_buf)) {
  3012. pos += 7;
  3013. os_memcpy(ifname_buf, pos, end - pos);
  3014. ifname_buf[end - pos] = '\0';
  3015. ifname = ifname_buf;
  3016. pos = end + 1;
  3017. }
  3018. }
  3019. if (*pos == '<') {
  3020. const char *prev = pos;
  3021. /* skip priority */
  3022. pos = os_strchr(pos, '>');
  3023. if (pos)
  3024. pos++;
  3025. else
  3026. pos = prev;
  3027. }
  3028. if (str_starts(pos, WPA_EVENT_CONNECTED)) {
  3029. int new_id = -1;
  3030. os_unsetenv("WPA_ID");
  3031. os_unsetenv("WPA_ID_STR");
  3032. os_unsetenv("WPA_CTRL_DIR");
  3033. pos = os_strstr(pos, "[id=");
  3034. if (pos)
  3035. copy = os_strdup(pos + 4);
  3036. if (copy) {
  3037. pos2 = id = copy;
  3038. while (*pos2 && *pos2 != ' ')
  3039. pos2++;
  3040. *pos2++ = '\0';
  3041. new_id = atoi(id);
  3042. os_setenv("WPA_ID", id, 1);
  3043. while (*pos2 && *pos2 != '=')
  3044. pos2++;
  3045. if (*pos2 == '=')
  3046. pos2++;
  3047. id = pos2;
  3048. while (*pos2 && *pos2 != ']')
  3049. pos2++;
  3050. *pos2 = '\0';
  3051. os_setenv("WPA_ID_STR", id, 1);
  3052. os_free(copy);
  3053. }
  3054. os_setenv("WPA_CTRL_DIR", ctrl_iface_dir, 1);
  3055. if (wpa_cli_connected <= 0 || new_id != wpa_cli_last_id) {
  3056. wpa_cli_connected = 1;
  3057. wpa_cli_last_id = new_id;
  3058. wpa_cli_exec(action_file, ifname, "CONNECTED");
  3059. }
  3060. } else if (str_starts(pos, WPA_EVENT_DISCONNECTED)) {
  3061. if (wpa_cli_connected) {
  3062. wpa_cli_connected = 0;
  3063. wpa_cli_exec(action_file, ifname, "DISCONNECTED");
  3064. }
  3065. } else if (str_starts(pos, AP_EVENT_ENABLED)) {
  3066. wpa_cli_exec(action_file, ctrl_ifname, pos);
  3067. } else if (str_starts(pos, AP_EVENT_DISABLED)) {
  3068. wpa_cli_exec(action_file, ctrl_ifname, pos);
  3069. } else if (str_starts(pos, MESH_GROUP_STARTED)) {
  3070. wpa_cli_exec(action_file, ctrl_ifname, pos);
  3071. } else if (str_starts(pos, MESH_GROUP_REMOVED)) {
  3072. wpa_cli_exec(action_file, ctrl_ifname, pos);
  3073. } else if (str_starts(pos, MESH_PEER_CONNECTED)) {
  3074. wpa_cli_exec(action_file, ctrl_ifname, pos);
  3075. } else if (str_starts(pos, MESH_PEER_DISCONNECTED)) {
  3076. wpa_cli_exec(action_file, ctrl_ifname, pos);
  3077. } else if (str_starts(pos, P2P_EVENT_GROUP_STARTED)) {
  3078. wpa_cli_exec(action_file, ifname, pos);
  3079. } else if (str_starts(pos, P2P_EVENT_GROUP_REMOVED)) {
  3080. wpa_cli_exec(action_file, ifname, pos);
  3081. } else if (str_starts(pos, P2P_EVENT_CROSS_CONNECT_ENABLE)) {
  3082. wpa_cli_exec(action_file, ifname, pos);
  3083. } else if (str_starts(pos, P2P_EVENT_CROSS_CONNECT_DISABLE)) {
  3084. wpa_cli_exec(action_file, ifname, pos);
  3085. } else if (str_starts(pos, P2P_EVENT_GO_NEG_FAILURE)) {
  3086. wpa_cli_exec(action_file, ifname, pos);
  3087. } else if (str_starts(pos, WPS_EVENT_SUCCESS)) {
  3088. wpa_cli_exec(action_file, ifname, pos);
  3089. } else if (str_starts(pos, WPS_EVENT_FAIL)) {
  3090. wpa_cli_exec(action_file, ifname, pos);
  3091. } else if (str_starts(pos, AP_STA_CONNECTED)) {
  3092. wpa_cli_exec(action_file, ifname, pos);
  3093. } else if (str_starts(pos, AP_STA_DISCONNECTED)) {
  3094. wpa_cli_exec(action_file, ifname, pos);
  3095. } else if (str_starts(pos, ESS_DISASSOC_IMMINENT)) {
  3096. wpa_cli_exec(action_file, ifname, pos);
  3097. } else if (str_starts(pos, HS20_SUBSCRIPTION_REMEDIATION)) {
  3098. wpa_cli_exec(action_file, ifname, pos);
  3099. } else if (str_starts(pos, HS20_DEAUTH_IMMINENT_NOTICE)) {
  3100. wpa_cli_exec(action_file, ifname, pos);
  3101. } else if (str_starts(pos, WPA_EVENT_TERMINATING)) {
  3102. printf("wpa_supplicant is terminating - stop monitoring\n");
  3103. wpa_cli_quit = 1;
  3104. }
  3105. }
  3106. #ifndef CONFIG_ANSI_C_EXTRA
  3107. static void wpa_cli_action_cb(char *msg, size_t len)
  3108. {
  3109. wpa_cli_action_process(msg);
  3110. }
  3111. #endif /* CONFIG_ANSI_C_EXTRA */
  3112. static void wpa_cli_reconnect(void)
  3113. {
  3114. wpa_cli_close_connection();
  3115. if (wpa_cli_open_connection(ctrl_ifname, 1) < 0)
  3116. return;
  3117. if (interactive) {
  3118. edit_clear_line();
  3119. printf("\rConnection to wpa_supplicant re-established\n");
  3120. edit_redraw();
  3121. update_stations(ctrl_conn);
  3122. }
  3123. }
  3124. static void cli_event(const char *str)
  3125. {
  3126. const char *start, *s;
  3127. start = os_strchr(str, '>');
  3128. if (start == NULL)
  3129. return;
  3130. start++;
  3131. if (str_starts(start, WPA_EVENT_BSS_ADDED)) {
  3132. s = os_strchr(start, ' ');
  3133. if (s == NULL)
  3134. return;
  3135. s = os_strchr(s + 1, ' ');
  3136. if (s == NULL)
  3137. return;
  3138. cli_txt_list_add(&bsses, s + 1);
  3139. return;
  3140. }
  3141. if (str_starts(start, WPA_EVENT_BSS_REMOVED)) {
  3142. s = os_strchr(start, ' ');
  3143. if (s == NULL)
  3144. return;
  3145. s = os_strchr(s + 1, ' ');
  3146. if (s == NULL)
  3147. return;
  3148. cli_txt_list_del_addr(&bsses, s + 1);
  3149. return;
  3150. }
  3151. #ifdef CONFIG_P2P
  3152. if (str_starts(start, P2P_EVENT_DEVICE_FOUND)) {
  3153. s = os_strstr(start, " p2p_dev_addr=");
  3154. if (s == NULL)
  3155. return;
  3156. cli_txt_list_add_addr(&p2p_peers, s + 14);
  3157. return;
  3158. }
  3159. if (str_starts(start, P2P_EVENT_DEVICE_LOST)) {
  3160. s = os_strstr(start, " p2p_dev_addr=");
  3161. if (s == NULL)
  3162. return;
  3163. cli_txt_list_del_addr(&p2p_peers, s + 14);
  3164. return;
  3165. }
  3166. if (str_starts(start, P2P_EVENT_GROUP_STARTED)) {
  3167. s = os_strchr(start, ' ');
  3168. if (s == NULL)
  3169. return;
  3170. cli_txt_list_add_word(&p2p_groups, s + 1, ' ');
  3171. return;
  3172. }
  3173. if (str_starts(start, P2P_EVENT_GROUP_REMOVED)) {
  3174. s = os_strchr(start, ' ');
  3175. if (s == NULL)
  3176. return;
  3177. cli_txt_list_del_word(&p2p_groups, s + 1, ' ');
  3178. return;
  3179. }
  3180. #endif /* CONFIG_P2P */
  3181. }
  3182. static int check_terminating(const char *msg)
  3183. {
  3184. const char *pos = msg;
  3185. if (*pos == '<') {
  3186. /* skip priority */
  3187. pos = os_strchr(pos, '>');
  3188. if (pos)
  3189. pos++;
  3190. else
  3191. pos = msg;
  3192. }
  3193. if (str_starts(pos, WPA_EVENT_TERMINATING) && ctrl_conn) {
  3194. edit_clear_line();
  3195. printf("\rConnection to wpa_supplicant lost - trying to "
  3196. "reconnect\n");
  3197. edit_redraw();
  3198. wpa_cli_attached = 0;
  3199. wpa_cli_close_connection();
  3200. return 1;
  3201. }
  3202. return 0;
  3203. }
  3204. static void wpa_cli_recv_pending(struct wpa_ctrl *ctrl, int action_monitor)
  3205. {
  3206. if (ctrl_conn == NULL) {
  3207. wpa_cli_reconnect();
  3208. return;
  3209. }
  3210. while (wpa_ctrl_pending(ctrl) > 0) {
  3211. char buf[4096];
  3212. size_t len = sizeof(buf) - 1;
  3213. if (wpa_ctrl_recv(ctrl, buf, &len) == 0) {
  3214. buf[len] = '\0';
  3215. if (action_monitor)
  3216. wpa_cli_action_process(buf);
  3217. else {
  3218. cli_event(buf);
  3219. if (wpa_cli_show_event(buf)) {
  3220. edit_clear_line();
  3221. printf("\r%s\n", buf);
  3222. edit_redraw();
  3223. }
  3224. if (interactive && check_terminating(buf) > 0)
  3225. return;
  3226. }
  3227. } else {
  3228. printf("Could not read pending message.\n");
  3229. break;
  3230. }
  3231. }
  3232. if (wpa_ctrl_pending(ctrl) < 0) {
  3233. printf("Connection to wpa_supplicant lost - trying to "
  3234. "reconnect\n");
  3235. wpa_cli_reconnect();
  3236. }
  3237. }
  3238. static void wpa_cli_ping(void *eloop_ctx, void *timeout_ctx)
  3239. {
  3240. if (ctrl_conn) {
  3241. int res;
  3242. char *prefix = ifname_prefix;
  3243. ifname_prefix = NULL;
  3244. res = _wpa_ctrl_command(ctrl_conn, "PING", 0);
  3245. ifname_prefix = prefix;
  3246. if (res) {
  3247. printf("Connection to wpa_supplicant lost - trying to "
  3248. "reconnect\n");
  3249. wpa_cli_close_connection();
  3250. }
  3251. }
  3252. if (!ctrl_conn)
  3253. wpa_cli_reconnect();
  3254. eloop_register_timeout(ping_interval, 0, wpa_cli_ping, NULL, NULL);
  3255. }
  3256. static void wpa_cli_mon_receive(int sock, void *eloop_ctx, void *sock_ctx)
  3257. {
  3258. wpa_cli_recv_pending(mon_conn, 0);
  3259. }
  3260. static void wpa_cli_edit_cmd_cb(void *ctx, char *cmd)
  3261. {
  3262. char *argv[max_args];
  3263. int argc;
  3264. argc = tokenize_cmd(cmd, argv);
  3265. if (argc)
  3266. wpa_request(ctrl_conn, argc, argv);
  3267. }
  3268. static void wpa_cli_edit_eof_cb(void *ctx)
  3269. {
  3270. eloop_terminate();
  3271. }
  3272. static int warning_displayed = 0;
  3273. static char *hfile = NULL;
  3274. static int edit_started = 0;
  3275. static void start_edit(void)
  3276. {
  3277. char *home;
  3278. char *ps = NULL;
  3279. #ifdef CONFIG_CTRL_IFACE_UDP_REMOTE
  3280. ps = wpa_ctrl_get_remote_ifname(ctrl_conn);
  3281. #endif /* CONFIG_CTRL_IFACE_UDP_REMOTE */
  3282. #ifdef CONFIG_WPA_CLI_HISTORY_DIR
  3283. home = CONFIG_WPA_CLI_HISTORY_DIR;
  3284. #else /* CONFIG_WPA_CLI_HISTORY_DIR */
  3285. home = getenv("HOME");
  3286. #endif /* CONFIG_WPA_CLI_HISTORY_DIR */
  3287. if (home) {
  3288. const char *fname = ".wpa_cli_history";
  3289. int hfile_len = os_strlen(home) + 1 + os_strlen(fname) + 1;
  3290. hfile = os_malloc(hfile_len);
  3291. if (hfile)
  3292. os_snprintf(hfile, hfile_len, "%s/%s", home, fname);
  3293. }
  3294. if (edit_init(wpa_cli_edit_cmd_cb, wpa_cli_edit_eof_cb,
  3295. wpa_cli_edit_completion_cb, NULL, hfile, ps) < 0) {
  3296. eloop_terminate();
  3297. return;
  3298. }
  3299. edit_started = 1;
  3300. eloop_register_timeout(ping_interval, 0, wpa_cli_ping, NULL, NULL);
  3301. }
  3302. static void update_bssid_list(struct wpa_ctrl *ctrl)
  3303. {
  3304. char buf[4096];
  3305. size_t len = sizeof(buf);
  3306. int ret;
  3307. const char *cmd = "BSS RANGE=ALL MASK=0x2";
  3308. char *pos, *end;
  3309. if (ctrl == NULL)
  3310. return;
  3311. ret = wpa_ctrl_request(ctrl, cmd, os_strlen(cmd), buf, &len, NULL);
  3312. if (ret < 0)
  3313. return;
  3314. buf[len] = '\0';
  3315. pos = buf;
  3316. while (pos) {
  3317. pos = os_strstr(pos, "bssid=");
  3318. if (pos == NULL)
  3319. break;
  3320. pos += 6;
  3321. end = os_strchr(pos, '\n');
  3322. if (end == NULL)
  3323. break;
  3324. *end = '\0';
  3325. cli_txt_list_add(&bsses, pos);
  3326. pos = end + 1;
  3327. }
  3328. }
  3329. static void update_ifnames(struct wpa_ctrl *ctrl)
  3330. {
  3331. char buf[4096];
  3332. size_t len = sizeof(buf);
  3333. int ret;
  3334. const char *cmd = "INTERFACES";
  3335. char *pos, *end;
  3336. char txt[200];
  3337. cli_txt_list_flush(&ifnames);
  3338. if (ctrl == NULL)
  3339. return;
  3340. ret = wpa_ctrl_request(ctrl, cmd, os_strlen(cmd), buf, &len, NULL);
  3341. if (ret < 0)
  3342. return;
  3343. buf[len] = '\0';
  3344. pos = buf;
  3345. while (pos) {
  3346. end = os_strchr(pos, '\n');
  3347. if (end == NULL)
  3348. break;
  3349. *end = '\0';
  3350. ret = os_snprintf(txt, sizeof(txt), "ifname=%s", pos);
  3351. if (!os_snprintf_error(sizeof(txt), ret))
  3352. cli_txt_list_add(&ifnames, txt);
  3353. pos = end + 1;
  3354. }
  3355. }
  3356. static void update_networks(struct wpa_ctrl *ctrl)
  3357. {
  3358. char buf[4096];
  3359. size_t len = sizeof(buf);
  3360. int ret;
  3361. const char *cmd = "LIST_NETWORKS";
  3362. char *pos, *end;
  3363. int header = 1;
  3364. cli_txt_list_flush(&networks);
  3365. if (ctrl == NULL)
  3366. return;
  3367. ret = wpa_ctrl_request(ctrl, cmd, os_strlen(cmd), buf, &len, NULL);
  3368. if (ret < 0)
  3369. return;
  3370. buf[len] = '\0';
  3371. pos = buf;
  3372. while (pos) {
  3373. end = os_strchr(pos, '\n');
  3374. if (end == NULL)
  3375. break;
  3376. *end = '\0';
  3377. if (!header)
  3378. cli_txt_list_add_word(&networks, pos, '\t');
  3379. header = 0;
  3380. pos = end + 1;
  3381. }
  3382. }
  3383. static void update_stations(struct wpa_ctrl *ctrl)
  3384. {
  3385. #ifdef CONFIG_AP
  3386. char addr[32], cmd[64];
  3387. if (!ctrl || !interactive)
  3388. return;
  3389. cli_txt_list_flush(&stations);
  3390. if (wpa_ctrl_command_sta(ctrl, "STA-FIRST", addr, sizeof(addr), 0))
  3391. return;
  3392. do {
  3393. if (os_strcmp(addr, "") != 0)
  3394. cli_txt_list_add(&stations, addr);
  3395. os_snprintf(cmd, sizeof(cmd), "STA-NEXT %s", addr);
  3396. } while (wpa_ctrl_command_sta(ctrl, cmd, addr, sizeof(addr), 0) == 0);
  3397. #endif /* CONFIG_AP */
  3398. }
  3399. static void try_connection(void *eloop_ctx, void *timeout_ctx)
  3400. {
  3401. if (ctrl_conn)
  3402. goto done;
  3403. if (ctrl_ifname == NULL)
  3404. ctrl_ifname = wpa_cli_get_default_ifname();
  3405. if (wpa_cli_open_connection(ctrl_ifname, 1)) {
  3406. if (!warning_displayed) {
  3407. printf("Could not connect to wpa_supplicant: "
  3408. "%s - re-trying\n",
  3409. ctrl_ifname ? ctrl_ifname : "(nil)");
  3410. warning_displayed = 1;
  3411. }
  3412. eloop_register_timeout(1, 0, try_connection, NULL, NULL);
  3413. return;
  3414. }
  3415. update_bssid_list(ctrl_conn);
  3416. update_networks(ctrl_conn);
  3417. update_stations(ctrl_conn);
  3418. if (warning_displayed)
  3419. printf("Connection established.\n");
  3420. done:
  3421. start_edit();
  3422. }
  3423. static void wpa_cli_interactive(void)
  3424. {
  3425. printf("\nInteractive mode\n\n");
  3426. eloop_register_timeout(0, 0, try_connection, NULL, NULL);
  3427. eloop_run();
  3428. eloop_cancel_timeout(try_connection, NULL, NULL);
  3429. cli_txt_list_flush(&p2p_peers);
  3430. cli_txt_list_flush(&p2p_groups);
  3431. cli_txt_list_flush(&bsses);
  3432. cli_txt_list_flush(&ifnames);
  3433. cli_txt_list_flush(&networks);
  3434. if (edit_started)
  3435. edit_deinit(hfile, wpa_cli_edit_filter_history_cb);
  3436. os_free(hfile);
  3437. eloop_cancel_timeout(wpa_cli_ping, NULL, NULL);
  3438. wpa_cli_close_connection();
  3439. }
  3440. static void wpa_cli_action_ping(void *eloop_ctx, void *timeout_ctx)
  3441. {
  3442. struct wpa_ctrl *ctrl = eloop_ctx;
  3443. char buf[256];
  3444. size_t len;
  3445. /* verify that connection is still working */
  3446. len = sizeof(buf) - 1;
  3447. if (wpa_ctrl_request(ctrl, "PING", 4, buf, &len,
  3448. wpa_cli_action_cb) < 0 ||
  3449. len < 4 || os_memcmp(buf, "PONG", 4) != 0) {
  3450. printf("wpa_supplicant did not reply to PING command - exiting\n");
  3451. eloop_terminate();
  3452. return;
  3453. }
  3454. eloop_register_timeout(ping_interval, 0, wpa_cli_action_ping,
  3455. ctrl, NULL);
  3456. }
  3457. static void wpa_cli_action_receive(int sock, void *eloop_ctx, void *sock_ctx)
  3458. {
  3459. struct wpa_ctrl *ctrl = eloop_ctx;
  3460. wpa_cli_recv_pending(ctrl, 1);
  3461. }
  3462. static void wpa_cli_action(struct wpa_ctrl *ctrl)
  3463. {
  3464. #ifdef CONFIG_ANSI_C_EXTRA
  3465. /* TODO: ANSI C version(?) */
  3466. printf("Action processing not supported in ANSI C build.\n");
  3467. #else /* CONFIG_ANSI_C_EXTRA */
  3468. int fd;
  3469. fd = wpa_ctrl_get_fd(ctrl);
  3470. eloop_register_timeout(ping_interval, 0, wpa_cli_action_ping,
  3471. ctrl, NULL);
  3472. eloop_register_read_sock(fd, wpa_cli_action_receive, ctrl, NULL);
  3473. eloop_run();
  3474. eloop_cancel_timeout(wpa_cli_action_ping, ctrl, NULL);
  3475. eloop_unregister_read_sock(fd);
  3476. #endif /* CONFIG_ANSI_C_EXTRA */
  3477. }
  3478. static void wpa_cli_cleanup(void)
  3479. {
  3480. wpa_cli_close_connection();
  3481. if (pid_file)
  3482. os_daemonize_terminate(pid_file);
  3483. os_program_deinit();
  3484. }
  3485. static void wpa_cli_terminate(int sig, void *ctx)
  3486. {
  3487. eloop_terminate();
  3488. }
  3489. static char * wpa_cli_get_default_ifname(void)
  3490. {
  3491. char *ifname = NULL;
  3492. #ifdef ANDROID
  3493. char ifprop[PROPERTY_VALUE_MAX];
  3494. if (property_get("wifi.interface", ifprop, NULL) != 0) {
  3495. ifname = os_strdup(ifprop);
  3496. printf("Using interface '%s'\n", ifname ? ifname : "N/A");
  3497. }
  3498. #else /* ANDROID */
  3499. #ifdef CONFIG_CTRL_IFACE_UNIX
  3500. struct dirent *dent;
  3501. DIR *dir = opendir(ctrl_iface_dir);
  3502. if (!dir) {
  3503. return NULL;
  3504. }
  3505. while ((dent = readdir(dir))) {
  3506. #ifdef _DIRENT_HAVE_D_TYPE
  3507. /*
  3508. * Skip the file if it is not a socket. Also accept
  3509. * DT_UNKNOWN (0) in case the C library or underlying
  3510. * file system does not support d_type.
  3511. */
  3512. if (dent->d_type != DT_SOCK && dent->d_type != DT_UNKNOWN)
  3513. continue;
  3514. #endif /* _DIRENT_HAVE_D_TYPE */
  3515. if (os_strcmp(dent->d_name, ".") == 0 ||
  3516. os_strcmp(dent->d_name, "..") == 0)
  3517. continue;
  3518. printf("Selected interface '%s'\n", dent->d_name);
  3519. ifname = os_strdup(dent->d_name);
  3520. break;
  3521. }
  3522. closedir(dir);
  3523. #endif /* CONFIG_CTRL_IFACE_UNIX */
  3524. #ifdef CONFIG_CTRL_IFACE_NAMED_PIPE
  3525. char buf[4096], *pos;
  3526. size_t len;
  3527. struct wpa_ctrl *ctrl;
  3528. int ret;
  3529. ctrl = wpa_ctrl_open(NULL);
  3530. if (ctrl == NULL)
  3531. return NULL;
  3532. len = sizeof(buf) - 1;
  3533. ret = wpa_ctrl_request(ctrl, "INTERFACES", 10, buf, &len, NULL);
  3534. if (ret >= 0) {
  3535. buf[len] = '\0';
  3536. pos = os_strchr(buf, '\n');
  3537. if (pos)
  3538. *pos = '\0';
  3539. ifname = os_strdup(buf);
  3540. }
  3541. wpa_ctrl_close(ctrl);
  3542. #endif /* CONFIG_CTRL_IFACE_NAMED_PIPE */
  3543. #endif /* ANDROID */
  3544. return ifname;
  3545. }
  3546. int main(int argc, char *argv[])
  3547. {
  3548. int c;
  3549. int daemonize = 0;
  3550. int ret = 0;
  3551. const char *global = NULL;
  3552. if (os_program_init())
  3553. return -1;
  3554. for (;;) {
  3555. c = getopt(argc, argv, "a:Bg:G:hi:p:P:s:v");
  3556. if (c < 0)
  3557. break;
  3558. switch (c) {
  3559. case 'a':
  3560. action_file = optarg;
  3561. break;
  3562. case 'B':
  3563. daemonize = 1;
  3564. break;
  3565. case 'g':
  3566. global = optarg;
  3567. break;
  3568. case 'G':
  3569. ping_interval = atoi(optarg);
  3570. break;
  3571. case 'h':
  3572. usage();
  3573. return 0;
  3574. case 'v':
  3575. printf("%s\n", wpa_cli_version);
  3576. return 0;
  3577. case 'i':
  3578. os_free(ctrl_ifname);
  3579. ctrl_ifname = os_strdup(optarg);
  3580. break;
  3581. case 'p':
  3582. ctrl_iface_dir = optarg;
  3583. break;
  3584. case 'P':
  3585. pid_file = optarg;
  3586. break;
  3587. case 's':
  3588. client_socket_dir = optarg;
  3589. break;
  3590. default:
  3591. usage();
  3592. return -1;
  3593. }
  3594. }
  3595. interactive = (argc == optind) && (action_file == NULL);
  3596. if (interactive)
  3597. printf("%s\n\n%s\n\n", wpa_cli_version, cli_license);
  3598. if (eloop_init())
  3599. return -1;
  3600. if (global) {
  3601. #ifdef CONFIG_CTRL_IFACE_NAMED_PIPE
  3602. ctrl_conn = wpa_ctrl_open(NULL);
  3603. #else /* CONFIG_CTRL_IFACE_NAMED_PIPE */
  3604. ctrl_conn = wpa_ctrl_open(global);
  3605. #endif /* CONFIG_CTRL_IFACE_NAMED_PIPE */
  3606. if (ctrl_conn == NULL) {
  3607. fprintf(stderr, "Failed to connect to wpa_supplicant "
  3608. "global interface: %s error: %s\n",
  3609. global, strerror(errno));
  3610. return -1;
  3611. }
  3612. if (interactive) {
  3613. update_ifnames(ctrl_conn);
  3614. mon_conn = wpa_ctrl_open(global);
  3615. if (mon_conn) {
  3616. if (wpa_ctrl_attach(mon_conn) == 0) {
  3617. wpa_cli_attached = 1;
  3618. eloop_register_read_sock(
  3619. wpa_ctrl_get_fd(mon_conn),
  3620. wpa_cli_mon_receive,
  3621. NULL, NULL);
  3622. } else {
  3623. printf("Failed to open monitor "
  3624. "connection through global "
  3625. "control interface\n");
  3626. }
  3627. }
  3628. update_stations(ctrl_conn);
  3629. }
  3630. }
  3631. eloop_register_signal_terminate(wpa_cli_terminate, NULL);
  3632. if (ctrl_ifname == NULL)
  3633. ctrl_ifname = wpa_cli_get_default_ifname();
  3634. if (interactive) {
  3635. wpa_cli_interactive();
  3636. } else {
  3637. if (!global &&
  3638. wpa_cli_open_connection(ctrl_ifname, 0) < 0) {
  3639. fprintf(stderr, "Failed to connect to non-global "
  3640. "ctrl_ifname: %s error: %s\n",
  3641. ctrl_ifname ? ctrl_ifname : "(nil)",
  3642. strerror(errno));
  3643. return -1;
  3644. }
  3645. if (action_file) {
  3646. if (wpa_ctrl_attach(ctrl_conn) == 0) {
  3647. wpa_cli_attached = 1;
  3648. } else {
  3649. printf("Warning: Failed to attach to "
  3650. "wpa_supplicant.\n");
  3651. return -1;
  3652. }
  3653. }
  3654. if (daemonize && os_daemonize(pid_file) && eloop_sock_requeue())
  3655. return -1;
  3656. if (action_file)
  3657. wpa_cli_action(ctrl_conn);
  3658. else
  3659. ret = wpa_request(ctrl_conn, argc - optind,
  3660. &argv[optind]);
  3661. }
  3662. os_free(ctrl_ifname);
  3663. eloop_destroy();
  3664. wpa_cli_cleanup();
  3665. return ret;
  3666. }
  3667. #else /* CONFIG_CTRL_IFACE */
  3668. int main(int argc, char *argv[])
  3669. {
  3670. printf("CONFIG_CTRL_IFACE not defined - wpa_cli disabled\n");
  3671. return -1;
  3672. }
  3673. #endif /* CONFIG_CTRL_IFACE */