wpa_cli.c 112 KB

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