123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297 |
- /*
- * WPA Supplicant - command line interface for wpa_supplicant daemon
- * Copyright (c) 2004-2011, Jouni Malinen <j@w1.fi>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License version 2 as
- * published by the Free Software Foundation.
- *
- * Alternatively, this software may be distributed under the terms of BSD
- * license.
- *
- * See README and COPYING for more details.
- */
-
- #include "includes.h"
-
- #ifdef CONFIG_CTRL_IFACE
-
- #ifdef CONFIG_CTRL_IFACE_UNIX
- #include <dirent.h>
- #endif /* CONFIG_CTRL_IFACE_UNIX */
-
- #include "common/wpa_ctrl.h"
- #include "utils/common.h"
- #include "utils/eloop.h"
- #include "utils/edit.h"
- #include "common/version.h"
- #ifdef ANDROID
- #include <cutils/properties.h>
- #endif /* ANDROID */
-
-
- static const char *wpa_cli_version =
- "wpa_cli v" VERSION_STR "\n"
- "Copyright (c) 2004-2011, Jouni Malinen <j@w1.fi> and contributors";
-
-
- static const char *wpa_cli_license =
- "This program is free software. You can distribute it and/or modify it\n"
- "under the terms of the GNU General Public License version 2.\n"
- "\n"
- "Alternatively, this software may be distributed under the terms of the\n"
- "BSD license. See README and COPYING for more details.\n";
-
- static const char *wpa_cli_full_license =
- "This program is free software; you can redistribute it and/or modify\n"
- "it under the terms of the GNU General Public License version 2 as\n"
- "published by the Free Software Foundation.\n"
- "\n"
- "This program is distributed in the hope that it will be useful,\n"
- "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
- "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
- "GNU General Public License for more details.\n"
- "\n"
- "You should have received a copy of the GNU General Public License\n"
- "along with this program; if not, write to the Free Software\n"
- "Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA\n"
- "\n"
- "Alternatively, this software may be distributed under the terms of the\n"
- "BSD license.\n"
- "\n"
- "Redistribution and use in source and binary forms, with or without\n"
- "modification, are permitted provided that the following conditions are\n"
- "met:\n"
- "\n"
- "1. Redistributions of source code must retain the above copyright\n"
- " notice, this list of conditions and the following disclaimer.\n"
- "\n"
- "2. Redistributions in binary form must reproduce the above copyright\n"
- " notice, this list of conditions and the following disclaimer in the\n"
- " documentation and/or other materials provided with the distribution.\n"
- "\n"
- "3. Neither the name(s) of the above-listed copyright holder(s) nor the\n"
- " names of its contributors may be used to endorse or promote products\n"
- " derived from this software without specific prior written permission.\n"
- "\n"
- "THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n"
- "\"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n"
- "LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n"
- "A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n"
- "OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n"
- "SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n"
- "LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n"
- "DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n"
- "THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n"
- "(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n"
- "OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n"
- "\n";
-
- static struct wpa_ctrl *ctrl_conn;
- static struct wpa_ctrl *mon_conn;
- static int wpa_cli_quit = 0;
- static int wpa_cli_attached = 0;
- static int wpa_cli_connected = 0;
- static int wpa_cli_last_id = 0;
- #ifndef CONFIG_CTRL_IFACE_DIR
- #define CONFIG_CTRL_IFACE_DIR "/var/run/wpa_supplicant"
- #endif /* CONFIG_CTRL_IFACE_DIR */
- static const char *ctrl_iface_dir = CONFIG_CTRL_IFACE_DIR;
- static char *ctrl_ifname = NULL;
- static const char *pid_file = NULL;
- static const char *action_file = NULL;
- static int ping_interval = 5;
- static int interactive = 0;
-
-
- static void print_help(void);
- static void wpa_cli_mon_receive(int sock, void *eloop_ctx, void *sock_ctx);
-
-
- static void usage(void)
- {
- printf("wpa_cli [-p<path to ctrl sockets>] [-i<ifname>] [-hvB] "
- "[-a<action file>] \\\n"
- " [-P<pid file>] [-g<global ctrl>] [-G<ping interval>] "
- "[command..]\n"
- " -h = help (show this usage text)\n"
- " -v = shown version information\n"
- " -a = run in daemon mode executing the action file based on "
- "events from\n"
- " wpa_supplicant\n"
- " -B = run a daemon in the background\n"
- " default path: " CONFIG_CTRL_IFACE_DIR "\n"
- " default interface: first interface found in socket path\n");
- print_help();
- }
-
-
- static int str_starts(const char *src, const char *match)
- {
- return os_strncmp(src, match, os_strlen(match)) == 0;
- }
-
-
- static int wpa_cli_show_event(const char *event)
- {
- const char *start;
-
- start = os_strchr(event, '>');
- if (start == NULL)
- return 1;
-
- start++;
- /*
- * Skip BSS added/removed events since they can be relatively frequent
- * and are likely of not much use for an interactive user.
- */
- if (str_starts(start, WPA_EVENT_BSS_ADDED) ||
- str_starts(start, WPA_EVENT_BSS_REMOVED))
- return 0;
-
- return 1;
- }
-
-
- static int wpa_cli_open_connection(const char *ifname, int attach)
- {
- #if defined(CONFIG_CTRL_IFACE_UDP) || defined(CONFIG_CTRL_IFACE_NAMED_PIPE)
- ctrl_conn = wpa_ctrl_open(ifname);
- if (ctrl_conn == NULL)
- return -1;
-
- if (attach && interactive)
- mon_conn = wpa_ctrl_open(ifname);
- else
- mon_conn = NULL;
- #else /* CONFIG_CTRL_IFACE_UDP || CONFIG_CTRL_IFACE_NAMED_PIPE */
- char *cfile = NULL;
- int flen, res;
-
- if (ifname == NULL)
- return -1;
-
- #ifdef ANDROID
- if (access(ctrl_iface_dir, F_OK) < 0) {
- cfile = os_strdup(ifname);
- if (cfile == NULL)
- return -1;
- }
- #endif /* ANDROID */
-
- if (cfile == NULL) {
- flen = os_strlen(ctrl_iface_dir) + os_strlen(ifname) + 2;
- cfile = os_malloc(flen);
- if (cfile == NULL)
- return -1;
- res = os_snprintf(cfile, flen, "%s/%s", ctrl_iface_dir,
- ifname);
- if (res < 0 || res >= flen) {
- os_free(cfile);
- return -1;
- }
- }
-
- ctrl_conn = wpa_ctrl_open(cfile);
- if (ctrl_conn == NULL) {
- os_free(cfile);
- return -1;
- }
-
- if (attach && interactive)
- mon_conn = wpa_ctrl_open(cfile);
- else
- mon_conn = NULL;
- os_free(cfile);
- #endif /* CONFIG_CTRL_IFACE_UDP || CONFIG_CTRL_IFACE_NAMED_PIPE */
-
- if (mon_conn) {
- if (wpa_ctrl_attach(mon_conn) == 0) {
- wpa_cli_attached = 1;
- if (interactive)
- eloop_register_read_sock(
- wpa_ctrl_get_fd(mon_conn),
- wpa_cli_mon_receive, NULL, NULL);
- } else {
- printf("Warning: Failed to attach to "
- "wpa_supplicant.\n");
- return -1;
- }
- }
-
- return 0;
- }
-
-
- static void wpa_cli_close_connection(void)
- {
- if (ctrl_conn == NULL)
- return;
-
- if (wpa_cli_attached) {
- wpa_ctrl_detach(interactive ? mon_conn : ctrl_conn);
- wpa_cli_attached = 0;
- }
- wpa_ctrl_close(ctrl_conn);
- ctrl_conn = NULL;
- if (mon_conn) {
- eloop_unregister_read_sock(wpa_ctrl_get_fd(mon_conn));
- wpa_ctrl_close(mon_conn);
- mon_conn = NULL;
- }
- }
-
-
- static void wpa_cli_msg_cb(char *msg, size_t len)
- {
- printf("%s\n", msg);
- }
-
-
- static int _wpa_ctrl_command(struct wpa_ctrl *ctrl, char *cmd, int print)
- {
- //Modified by Kurt; enlarge command string for scan_result
- char buf[4096];
- size_t len;
- int ret;
-
- if (ctrl_conn == NULL) {
- printf("Not connected to wpa_supplicant - command dropped.\n");
- return -1;
- }
- len = sizeof(buf) - 1;
- ret = wpa_ctrl_request(ctrl, cmd, os_strlen(cmd), buf, &len,
- wpa_cli_msg_cb);
- if (ret == -2) {
- printf("'%s' command timed out.\n", cmd);
- return -2;
- } else if (ret < 0) {
- printf("'%s' command failed.\n", cmd);
- return -1;
- }
- if (print) {
- buf[len] = '\0';
- printf("%s", buf);
- if (interactive && len > 0 && buf[len - 1] != '\n')
- printf("\n");
- }
- return 0;
- }
-
-
- static int wpa_ctrl_command(struct wpa_ctrl *ctrl, char *cmd)
- {
- return _wpa_ctrl_command(ctrl, cmd, 1);
- }
-
-
- static int wpa_cli_cmd_status(struct wpa_ctrl *ctrl, int argc, char *argv[])
- {
- int verbose = argc > 0 && os_strcmp(argv[0], "verbose") == 0;
- return wpa_ctrl_command(ctrl, verbose ? "STATUS-VERBOSE" : "STATUS");
- }
-
-
- static int wpa_cli_cmd_ping(struct wpa_ctrl *ctrl, int argc, char *argv[])
- {
- return wpa_ctrl_command(ctrl, "PING");
- }
-
-
- static int wpa_cli_cmd_relog(struct wpa_ctrl *ctrl, int argc, char *argv[])
- {
- return wpa_ctrl_command(ctrl, "RELOG");
- }
-
-
- static int wpa_cli_cmd_note(struct wpa_ctrl *ctrl, int argc, char *argv[])
- {
- char cmd[256];
- int ret;
- if (argc == 0)
- return -1;
- ret = os_snprintf(cmd, sizeof(cmd), "NOTE %s", argv[0]);
- if (ret < 0 || (size_t) ret >= sizeof(cmd))
- return -1;
- return wpa_ctrl_command(ctrl, cmd);
- }
-
-
- static int wpa_cli_cmd_mib(struct wpa_ctrl *ctrl, int argc, char *argv[])
- {
- return wpa_ctrl_command(ctrl, "MIB");
- }
-
-
- static int wpa_cli_cmd_pmksa(struct wpa_ctrl *ctrl, int argc, char *argv[])
- {
- return wpa_ctrl_command(ctrl, "PMKSA");
- }
-
-
- static int wpa_cli_cmd_help(struct wpa_ctrl *ctrl, int argc, char *argv[])
- {
- print_help();
- return 0;
- }
-
-
- static int wpa_cli_cmd_license(struct wpa_ctrl *ctrl, int argc, char *argv[])
- {
- printf("%s\n\n%s\n", wpa_cli_version, wpa_cli_full_license);
- return 0;
- }
-
-
- static int wpa_cli_cmd_quit(struct wpa_ctrl *ctrl, int argc, char *argv[])
- {
- wpa_cli_quit = 1;
- if (interactive)
- eloop_terminate();
- return 0;
- }
-
-
- static void wpa_cli_show_variables(void)
- {
- printf("set variables:\n"
- " EAPOL::heldPeriod (EAPOL state machine held period, "
- "in seconds)\n"
- " EAPOL::authPeriod (EAPOL state machine authentication "
- "period, in seconds)\n"
- " EAPOL::startPeriod (EAPOL state machine start period, in "
- "seconds)\n"
- " EAPOL::maxStart (EAPOL state machine maximum start "
- "attempts)\n");
- printf(" dot11RSNAConfigPMKLifetime (WPA/WPA2 PMK lifetime in "
- "seconds)\n"
- " dot11RSNAConfigPMKReauthThreshold (WPA/WPA2 reauthentication"
- " threshold\n\tpercentage)\n"
- " dot11RSNAConfigSATimeout (WPA/WPA2 timeout for completing "
- "security\n\tassociation in seconds)\n");
- }
-
-
- static int wpa_cli_cmd_set(struct wpa_ctrl *ctrl, int argc, char *argv[])
- {
- char cmd[256];
- int res;
-
- if (argc == 0) {
- wpa_cli_show_variables();
- return 0;
- }
-
- if (argc != 2) {
- printf("Invalid SET command: needs two arguments (variable "
- "name and value)\n");
- return -1;
- }
-
- res = os_snprintf(cmd, sizeof(cmd), "SET %s %s", argv[0], argv[1]);
- if (res < 0 || (size_t) res >= sizeof(cmd) - 1) {
- printf("Too long SET command.\n");
- return -1;
- }
- return wpa_ctrl_command(ctrl, cmd);
- }
-
-
- static int wpa_cli_cmd_get(struct wpa_ctrl *ctrl, int argc, char *argv[])
- {
- char cmd[256];
- int res;
-
- if (argc != 1) {
- printf("Invalid GET command: need one argument (variable "
- "name)\n");
- return -1;
- }
-
- res = os_snprintf(cmd, sizeof(cmd), "GET %s", argv[0]);
- if (res < 0 || (size_t) res >= sizeof(cmd) - 1) {
- printf("Too long GET command.\n");
- return -1;
- }
- return wpa_ctrl_command(ctrl, cmd);
- }
-
-
- static int wpa_cli_cmd_logoff(struct wpa_ctrl *ctrl, int argc, char *argv[])
- {
- return wpa_ctrl_command(ctrl, "LOGOFF");
- }
-
-
- static int wpa_cli_cmd_logon(struct wpa_ctrl *ctrl, int argc, char *argv[])
- {
- return wpa_ctrl_command(ctrl, "LOGON");
- }
-
-
- static int wpa_cli_cmd_reassociate(struct wpa_ctrl *ctrl, int argc,
- char *argv[])
- {
- return wpa_ctrl_command(ctrl, "REASSOCIATE");
- }
-
-
- static int wpa_cli_cmd_preauthenticate(struct wpa_ctrl *ctrl, int argc,
- char *argv[])
- {
- char cmd[256];
- int res;
-
- if (argc != 1) {
- printf("Invalid PREAUTH command: needs one argument "
- "(BSSID)\n");
- return -1;
- }
-
- res = os_snprintf(cmd, sizeof(cmd), "PREAUTH %s", argv[0]);
- if (res < 0 || (size_t) res >= sizeof(cmd) - 1) {
- printf("Too long PREAUTH command.\n");
- return -1;
- }
- return wpa_ctrl_command(ctrl, cmd);
- }
-
-
- static int wpa_cli_cmd_ap_scan(struct wpa_ctrl *ctrl, int argc, char *argv[])
- {
- char cmd[256];
- int res;
-
- if (argc != 1) {
- printf("Invalid AP_SCAN command: needs one argument (ap_scan "
- "value)\n");
- return -1;
- }
- res = os_snprintf(cmd, sizeof(cmd), "AP_SCAN %s", argv[0]);
- if (res < 0 || (size_t) res >= sizeof(cmd) - 1) {
- printf("Too long AP_SCAN command.\n");
- return -1;
- }
- return wpa_ctrl_command(ctrl, cmd);
- }
-
-
- static int wpa_cli_cmd_scan_interval(struct wpa_ctrl *ctrl, int argc,
- char *argv[])
- {
- char cmd[256];
- int res;
-
- if (argc != 1) {
- printf("Invalid SCAN_INTERVAL command: needs one argument "
- "scan_interval value)\n");
- return -1;
- }
- res = os_snprintf(cmd, sizeof(cmd), "SCAN_INTERVAL %s", argv[0]);
- if (res < 0 || (size_t) res >= sizeof(cmd) - 1) {
- printf("Too long SCAN_INTERVAL command.\n");
- return -1;
- }
- return wpa_ctrl_command(ctrl, cmd);
- }
-
-
- static int wpa_cli_cmd_bss_expire_age(struct wpa_ctrl *ctrl, int argc,
- char *argv[])
- {
- char cmd[256];
- int res;
-
- if (argc != 1) {
- printf("Invalid BSS_EXPIRE_AGE command: needs one argument "
- "(bss_expire_age value)\n");
- return -1;
- }
- res = os_snprintf(cmd, sizeof(cmd), "BSS_EXPIRE_AGE %s", argv[0]);
- if (res < 0 || (size_t) res >= sizeof(cmd) - 1) {
- printf("Too long BSS_EXPIRE_AGE command.\n");
- return -1;
- }
- return wpa_ctrl_command(ctrl, cmd);
- }
-
-
- static int wpa_cli_cmd_bss_expire_count(struct wpa_ctrl *ctrl, int argc,
- char *argv[])
- {
- char cmd[256];
- int res;
-
- if (argc != 1) {
- printf("Invalid BSS_EXPIRE_COUNT command: needs one argument "
- "(bss_expire_count value)\n");
- return -1;
- }
- res = os_snprintf(cmd, sizeof(cmd), "BSS_EXPIRE_COUNT %s", argv[0]);
- if (res < 0 || (size_t) res >= sizeof(cmd) - 1) {
- printf("Too long BSS_EXPIRE_COUNT command.\n");
- return -1;
- }
- return wpa_ctrl_command(ctrl, cmd);
- }
-
-
- static int wpa_cli_cmd_stkstart(struct wpa_ctrl *ctrl, int argc,
- char *argv[])
- {
- char cmd[256];
- int res;
-
- if (argc != 1) {
- printf("Invalid STKSTART command: needs one argument "
- "(Peer STA MAC address)\n");
- return -1;
- }
-
- res = os_snprintf(cmd, sizeof(cmd), "STKSTART %s", argv[0]);
- if (res < 0 || (size_t) res >= sizeof(cmd) - 1) {
- printf("Too long STKSTART command.\n");
- return -1;
- }
- return wpa_ctrl_command(ctrl, cmd);
- }
-
-
- static int wpa_cli_cmd_ft_ds(struct wpa_ctrl *ctrl, int argc, char *argv[])
- {
- char cmd[256];
- int res;
-
- if (argc != 1) {
- printf("Invalid FT_DS command: needs one argument "
- "(Target AP MAC address)\n");
- return -1;
- }
-
- res = os_snprintf(cmd, sizeof(cmd), "FT_DS %s", argv[0]);
- if (res < 0 || (size_t) res >= sizeof(cmd) - 1) {
- printf("Too long FT_DS command.\n");
- return -1;
- }
- return wpa_ctrl_command(ctrl, cmd);
- }
-
-
- static int wpa_cli_cmd_wps_pbc(struct wpa_ctrl *ctrl, int argc, char *argv[])
- {
- char cmd[256];
- int res;
-
- if (argc == 0) {
- /* Any BSSID */
- return wpa_ctrl_command(ctrl, "WPS_PBC");
- }
-
- /* Specific BSSID */
- res = os_snprintf(cmd, sizeof(cmd), "WPS_PBC %s", argv[0]);
- if (res < 0 || (size_t) res >= sizeof(cmd) - 1) {
- printf("Too long WPS_PBC command.\n");
- return -1;
- }
- return wpa_ctrl_command(ctrl, cmd);
- }
-
-
- static int wpa_cli_cmd_wps_pin(struct wpa_ctrl *ctrl, int argc, char *argv[])
- {
- char cmd[256];
- int res;
-
- if (argc == 0) {
- printf("Invalid WPS_PIN command: need one or two arguments:\n"
- "- BSSID: use 'any' to select any\n"
- "- PIN: optional, used only with devices that have no "
- "display\n");
- return -1;
- }
-
- if (argc == 1) {
- /* Use dynamically generated PIN (returned as reply) */
- res = os_snprintf(cmd, sizeof(cmd), "WPS_PIN %s", argv[0]);
- if (res < 0 || (size_t) res >= sizeof(cmd) - 1) {
- printf("Too long WPS_PIN command.\n");
- return -1;
- }
- return wpa_ctrl_command(ctrl, cmd);
- }
-
- /* Use hardcoded PIN from a label */
- res = os_snprintf(cmd, sizeof(cmd), "WPS_PIN %s %s", argv[0], argv[1]);
- if (res < 0 || (size_t) res >= sizeof(cmd) - 1) {
- printf("Too long WPS_PIN command.\n");
- return -1;
- }
- return wpa_ctrl_command(ctrl, cmd);
- }
-
-
- static int wpa_cli_cmd_wps_check_pin(struct wpa_ctrl *ctrl, int argc,
- char *argv[])
- {
- char cmd[256];
- int res;
-
- if (argc != 1 && argc != 2) {
- printf("Invalid WPS_CHECK_PIN command: needs one argument:\n"
- "- PIN to be verified\n");
- return -1;
- }
-
- if (argc == 2)
- res = os_snprintf(cmd, sizeof(cmd), "WPS_CHECK_PIN %s %s",
- argv[0], argv[1]);
- else
- res = os_snprintf(cmd, sizeof(cmd), "WPS_CHECK_PIN %s",
- argv[0]);
- if (res < 0 || (size_t) res >= sizeof(cmd) - 1) {
- printf("Too long WPS_CHECK_PIN command.\n");
- return -1;
- }
- return wpa_ctrl_command(ctrl, cmd);
- }
-
-
- static int wpa_cli_cmd_wps_cancel(struct wpa_ctrl *ctrl, int argc,
- char *argv[])
- {
- return wpa_ctrl_command(ctrl, "WPS_CANCEL");
- }
-
-
- #ifdef CONFIG_WPS_OOB
- static int wpa_cli_cmd_wps_oob(struct wpa_ctrl *ctrl, int argc, char *argv[])
- {
- char cmd[256];
- int res;
-
- if (argc != 3 && argc != 4) {
- printf("Invalid WPS_OOB command: need three or four "
- "arguments:\n"
- "- DEV_TYPE: use 'ufd' or 'nfc'\n"
- "- PATH: path of OOB device like '/mnt'\n"
- "- METHOD: OOB method 'pin-e' or 'pin-r', "
- "'cred'\n"
- "- DEV_NAME: (only for NFC) device name like "
- "'pn531'\n");
- return -1;
- }
-
- if (argc == 3)
- res = os_snprintf(cmd, sizeof(cmd), "WPS_OOB %s %s %s",
- argv[0], argv[1], argv[2]);
- else
- res = os_snprintf(cmd, sizeof(cmd), "WPS_OOB %s %s %s %s",
- argv[0], argv[1], argv[2], argv[3]);
- if (res < 0 || (size_t) res >= sizeof(cmd) - 1) {
- printf("Too long WPS_OOB command.\n");
- return -1;
- }
- return wpa_ctrl_command(ctrl, cmd);
- }
- #endif /* CONFIG_WPS_OOB */
-
-
- static int wpa_cli_cmd_wps_reg(struct wpa_ctrl *ctrl, int argc, char *argv[])
- {
- char cmd[256];
- int res;
-
- if (argc == 2)
- res = os_snprintf(cmd, sizeof(cmd), "WPS_REG %s %s",
- argv[0], argv[1]);
- else if (argc == 5 || argc == 6) {
- char ssid_hex[2 * 32 + 1];
- char key_hex[2 * 64 + 1];
- int i;
-
- ssid_hex[0] = '\0';
- for (i = 0; i < 32; i++) {
- if (argv[2][i] == '\0')
- break;
- os_snprintf(&ssid_hex[i * 2], 3, "%02x", argv[2][i]);
- }
-
- key_hex[0] = '\0';
- if (argc == 6) {
- for (i = 0; i < 64; i++) {
- if (argv[5][i] == '\0')
- break;
- os_snprintf(&key_hex[i * 2], 3, "%02x",
- argv[5][i]);
- }
- }
-
- res = os_snprintf(cmd, sizeof(cmd),
- "WPS_REG %s %s %s %s %s %s",
- argv[0], argv[1], ssid_hex, argv[3], argv[4],
- key_hex);
- } else {
- printf("Invalid WPS_REG command: need two arguments:\n"
- "- BSSID of the target AP\n"
- "- AP PIN\n");
- printf("Alternatively, six arguments can be used to "
- "reconfigure the AP:\n"
- "- BSSID of the target AP\n"
- "- AP PIN\n"
- "- new SSID\n"
- "- new auth (OPEN, WPAPSK, WPA2PSK)\n"
- "- new encr (NONE, WEP, TKIP, CCMP)\n"
- "- new key\n");
- return -1;
- }
-
- if (res < 0 || (size_t) res >= sizeof(cmd) - 1) {
- printf("Too long WPS_REG command.\n");
- return -1;
- }
- return wpa_ctrl_command(ctrl, cmd);
- }
-
-
- static int wpa_cli_cmd_wps_ap_pin(struct wpa_ctrl *ctrl, int argc,
- char *argv[])
- {
- char cmd[256];
- int res;
-
- if (argc < 1) {
- printf("Invalid WPS_AP_PIN command: needs at least one "
- "argument\n");
- return -1;
- }
-
- if (argc > 2)
- res = os_snprintf(cmd, sizeof(cmd), "WPS_AP_PIN %s %s %s",
- argv[0], argv[1], argv[2]);
- else if (argc > 1)
- res = os_snprintf(cmd, sizeof(cmd), "WPS_AP_PIN %s %s",
- argv[0], argv[1]);
- else
- res = os_snprintf(cmd, sizeof(cmd), "WPS_AP_PIN %s",
- argv[0]);
- if (res < 0 || (size_t) res >= sizeof(cmd) - 1) {
- printf("Too long WPS_AP_PIN command.\n");
- return -1;
- }
- return wpa_ctrl_command(ctrl, cmd);
- }
-
-
- static int wpa_cli_cmd_wps_er_start(struct wpa_ctrl *ctrl, int argc,
- char *argv[])
- {
- char cmd[100];
- if (argc > 0) {
- os_snprintf(cmd, sizeof(cmd), "WPS_ER_START %s", argv[0]);
- return wpa_ctrl_command(ctrl, cmd);
- }
- return wpa_ctrl_command(ctrl, "WPS_ER_START");
- }
-
-
- static int wpa_cli_cmd_wps_er_stop(struct wpa_ctrl *ctrl, int argc,
- char *argv[])
- {
- return wpa_ctrl_command(ctrl, "WPS_ER_STOP");
-
- }
-
-
- static int wpa_cli_cmd_wps_er_pin(struct wpa_ctrl *ctrl, int argc,
- char *argv[])
- {
- char cmd[256];
- int res;
-
- if (argc < 2) {
- printf("Invalid WPS_ER_PIN command: need at least two "
- "arguments:\n"
- "- UUID: use 'any' to select any\n"
- "- PIN: Enrollee PIN\n"
- "optional: - Enrollee MAC address\n");
- return -1;
- }
-
- if (argc > 2)
- res = os_snprintf(cmd, sizeof(cmd), "WPS_ER_PIN %s %s %s",
- argv[0], argv[1], argv[2]);
- else
- res = os_snprintf(cmd, sizeof(cmd), "WPS_ER_PIN %s %s",
- argv[0], argv[1]);
- if (res < 0 || (size_t) res >= sizeof(cmd) - 1) {
- printf("Too long WPS_ER_PIN command.\n");
- return -1;
- }
- return wpa_ctrl_command(ctrl, cmd);
- }
-
-
- static int wpa_cli_cmd_wps_er_pbc(struct wpa_ctrl *ctrl, int argc,
- char *argv[])
- {
- char cmd[256];
- int res;
-
- if (argc != 1) {
- printf("Invalid WPS_ER_PBC command: need one argument:\n"
- "- UUID: Specify the Enrollee\n");
- return -1;
- }
-
- res = os_snprintf(cmd, sizeof(cmd), "WPS_ER_PBC %s",
- argv[0]);
- if (res < 0 || (size_t) res >= sizeof(cmd) - 1) {
- printf("Too long WPS_ER_PBC command.\n");
- return -1;
- }
- return wpa_ctrl_command(ctrl, cmd);
- }
-
-
- static int wpa_cli_cmd_wps_er_learn(struct wpa_ctrl *ctrl, int argc,
- char *argv[])
- {
- char cmd[256];
- int res;
-
- if (argc != 2) {
- printf("Invalid WPS_ER_LEARN command: need two arguments:\n"
- "- UUID: specify which AP to use\n"
- "- PIN: AP PIN\n");
- return -1;
- }
-
- res = os_snprintf(cmd, sizeof(cmd), "WPS_ER_LEARN %s %s",
- argv[0], argv[1]);
- if (res < 0 || (size_t) res >= sizeof(cmd) - 1) {
- printf("Too long WPS_ER_LEARN command.\n");
- return -1;
- }
- return wpa_ctrl_command(ctrl, cmd);
- }
-
-
- static int wpa_cli_cmd_wps_er_set_config(struct wpa_ctrl *ctrl, int argc,
- char *argv[])
- {
- char cmd[256];
- int res;
-
- if (argc != 2) {
- printf("Invalid WPS_ER_SET_CONFIG command: need two "
- "arguments:\n"
- "- UUID: specify which AP to use\n"
- "- Network configuration id\n");
- return -1;
- }
-
- res = os_snprintf(cmd, sizeof(cmd), "WPS_ER_SET_CONFIG %s %s",
- argv[0], argv[1]);
- if (res < 0 || (size_t) res >= sizeof(cmd) - 1) {
- printf("Too long WPS_ER_SET_CONFIG command.\n");
- return -1;
- }
- return wpa_ctrl_command(ctrl, cmd);
- }
-
-
- static int wpa_cli_cmd_wps_er_config(struct wpa_ctrl *ctrl, int argc,
- char *argv[])
- {
- char cmd[256];
- int res;
-
- if (argc == 5 || argc == 6) {
- char ssid_hex[2 * 32 + 1];
- char key_hex[2 * 64 + 1];
- int i;
-
- ssid_hex[0] = '\0';
- for (i = 0; i < 32; i++) {
- if (argv[2][i] == '\0')
- break;
- os_snprintf(&ssid_hex[i * 2], 3, "%02x", argv[2][i]);
- }
-
- key_hex[0] = '\0';
- if (argc == 6) {
- for (i = 0; i < 64; i++) {
- if (argv[5][i] == '\0')
- break;
- os_snprintf(&key_hex[i * 2], 3, "%02x",
- argv[5][i]);
- }
- }
-
- res = os_snprintf(cmd, sizeof(cmd),
- "WPS_ER_CONFIG %s %s %s %s %s %s",
- argv[0], argv[1], ssid_hex, argv[3], argv[4],
- key_hex);
- } else {
- printf("Invalid WPS_ER_CONFIG command: need six arguments:\n"
- "- AP UUID\n"
- "- AP PIN\n"
- "- new SSID\n"
- "- new auth (OPEN, WPAPSK, WPA2PSK)\n"
- "- new encr (NONE, WEP, TKIP, CCMP)\n"
- "- new key\n");
- return -1;
- }
-
- if (res < 0 || (size_t) res >= sizeof(cmd) - 1) {
- printf("Too long WPS_ER_CONFIG command.\n");
- return -1;
- }
- return wpa_ctrl_command(ctrl, cmd);
- }
-
-
- static int wpa_cli_cmd_ibss_rsn(struct wpa_ctrl *ctrl, int argc, char *argv[])
- {
- char cmd[256];
- int res;
-
- if (argc != 1) {
- printf("Invalid IBSS_RSN command: needs one argument "
- "(Peer STA MAC address)\n");
- return -1;
- }
-
- res = os_snprintf(cmd, sizeof(cmd), "IBSS_RSN %s", argv[0]);
- if (res < 0 || (size_t) res >= sizeof(cmd) - 1) {
- printf("Too long IBSS_RSN command.\n");
- return -1;
- }
- return wpa_ctrl_command(ctrl, cmd);
- }
-
-
- static int wpa_cli_cmd_level(struct wpa_ctrl *ctrl, int argc, char *argv[])
- {
- char cmd[256];
- int res;
-
- if (argc != 1) {
- printf("Invalid LEVEL command: needs one argument (debug "
- "level)\n");
- return -1;
- }
- res = os_snprintf(cmd, sizeof(cmd), "LEVEL %s", argv[0]);
- if (res < 0 || (size_t) res >= sizeof(cmd) - 1) {
- printf("Too long LEVEL command.\n");
- return -1;
- }
- return wpa_ctrl_command(ctrl, cmd);
- }
-
-
- static int wpa_cli_cmd_identity(struct wpa_ctrl *ctrl, int argc, char *argv[])
- {
- char cmd[256], *pos, *end;
- int i, ret;
-
- if (argc < 2) {
- printf("Invalid IDENTITY command: needs two arguments "
- "(network id and identity)\n");
- return -1;
- }
-
- end = cmd + sizeof(cmd);
- pos = cmd;
- ret = os_snprintf(pos, end - pos, WPA_CTRL_RSP "IDENTITY-%s:%s",
- argv[0], argv[1]);
- if (ret < 0 || ret >= end - pos) {
- printf("Too long IDENTITY command.\n");
- return -1;
- }
- pos += ret;
- for (i = 2; i < argc; i++) {
- ret = os_snprintf(pos, end - pos, " %s", argv[i]);
- if (ret < 0 || ret >= end - pos) {
- printf("Too long IDENTITY command.\n");
- return -1;
- }
- pos += ret;
- }
-
- return wpa_ctrl_command(ctrl, cmd);
- }
-
-
- static int wpa_cli_cmd_password(struct wpa_ctrl *ctrl, int argc, char *argv[])
- {
- char cmd[256], *pos, *end;
- int i, ret;
-
- if (argc < 2) {
- printf("Invalid PASSWORD command: needs two arguments "
- "(network id and password)\n");
- return -1;
- }
-
- end = cmd + sizeof(cmd);
- pos = cmd;
- ret = os_snprintf(pos, end - pos, WPA_CTRL_RSP "PASSWORD-%s:%s",
- argv[0], argv[1]);
- if (ret < 0 || ret >= end - pos) {
- printf("Too long PASSWORD command.\n");
- return -1;
- }
- pos += ret;
- for (i = 2; i < argc; i++) {
- ret = os_snprintf(pos, end - pos, " %s", argv[i]);
- if (ret < 0 || ret >= end - pos) {
- printf("Too long PASSWORD command.\n");
- return -1;
- }
- pos += ret;
- }
-
- return wpa_ctrl_command(ctrl, cmd);
- }
-
-
- static int wpa_cli_cmd_new_password(struct wpa_ctrl *ctrl, int argc,
- char *argv[])
- {
- char cmd[256], *pos, *end;
- int i, ret;
-
- if (argc < 2) {
- printf("Invalid NEW_PASSWORD command: needs two arguments "
- "(network id and password)\n");
- return -1;
- }
-
- end = cmd + sizeof(cmd);
- pos = cmd;
- ret = os_snprintf(pos, end - pos, WPA_CTRL_RSP "NEW_PASSWORD-%s:%s",
- argv[0], argv[1]);
- if (ret < 0 || ret >= end - pos) {
- printf("Too long NEW_PASSWORD command.\n");
- return -1;
- }
- pos += ret;
- for (i = 2; i < argc; i++) {
- ret = os_snprintf(pos, end - pos, " %s", argv[i]);
- if (ret < 0 || ret >= end - pos) {
- printf("Too long NEW_PASSWORD command.\n");
- return -1;
- }
- pos += ret;
- }
-
- return wpa_ctrl_command(ctrl, cmd);
- }
-
-
- static int wpa_cli_cmd_pin(struct wpa_ctrl *ctrl, int argc, char *argv[])
- {
- char cmd[256], *pos, *end;
- int i, ret;
-
- if (argc < 2) {
- printf("Invalid PIN command: needs two arguments "
- "(network id and pin)\n");
- return -1;
- }
-
- end = cmd + sizeof(cmd);
- pos = cmd;
- ret = os_snprintf(pos, end - pos, WPA_CTRL_RSP "PIN-%s:%s",
- argv[0], argv[1]);
- if (ret < 0 || ret >= end - pos) {
- printf("Too long PIN command.\n");
- return -1;
- }
- pos += ret;
- for (i = 2; i < argc; i++) {
- ret = os_snprintf(pos, end - pos, " %s", argv[i]);
- if (ret < 0 || ret >= end - pos) {
- printf("Too long PIN command.\n");
- return -1;
- }
- pos += ret;
- }
- return wpa_ctrl_command(ctrl, cmd);
- }
-
-
- static int wpa_cli_cmd_otp(struct wpa_ctrl *ctrl, int argc, char *argv[])
- {
- char cmd[256], *pos, *end;
- int i, ret;
-
- if (argc < 2) {
- printf("Invalid OTP command: needs two arguments (network "
- "id and password)\n");
- return -1;
- }
-
- end = cmd + sizeof(cmd);
- pos = cmd;
- ret = os_snprintf(pos, end - pos, WPA_CTRL_RSP "OTP-%s:%s",
- argv[0], argv[1]);
- if (ret < 0 || ret >= end - pos) {
- printf("Too long OTP command.\n");
- return -1;
- }
- pos += ret;
- for (i = 2; i < argc; i++) {
- ret = os_snprintf(pos, end - pos, " %s", argv[i]);
- if (ret < 0 || ret >= end - pos) {
- printf("Too long OTP command.\n");
- return -1;
- }
- pos += ret;
- }
-
- return wpa_ctrl_command(ctrl, cmd);
- }
-
-
- static int wpa_cli_cmd_passphrase(struct wpa_ctrl *ctrl, int argc,
- char *argv[])
- {
- char cmd[256], *pos, *end;
- int i, ret;
-
- if (argc < 2) {
- printf("Invalid PASSPHRASE command: needs two arguments "
- "(network id and passphrase)\n");
- return -1;
- }
-
- end = cmd + sizeof(cmd);
- pos = cmd;
- ret = os_snprintf(pos, end - pos, WPA_CTRL_RSP "PASSPHRASE-%s:%s",
- argv[0], argv[1]);
- if (ret < 0 || ret >= end - pos) {
- printf("Too long PASSPHRASE command.\n");
- return -1;
- }
- pos += ret;
- for (i = 2; i < argc; i++) {
- ret = os_snprintf(pos, end - pos, " %s", argv[i]);
- if (ret < 0 || ret >= end - pos) {
- printf("Too long PASSPHRASE command.\n");
- return -1;
- }
- pos += ret;
- }
-
- return wpa_ctrl_command(ctrl, cmd);
- }
-
-
- static int wpa_cli_cmd_bssid(struct wpa_ctrl *ctrl, int argc, char *argv[])
- {
- char cmd[256], *pos, *end;
- int i, ret;
-
- if (argc < 2) {
- printf("Invalid BSSID command: needs two arguments (network "
- "id and BSSID)\n");
- return -1;
- }
-
- end = cmd + sizeof(cmd);
- pos = cmd;
- ret = os_snprintf(pos, end - pos, "BSSID");
- if (ret < 0 || ret >= end - pos) {
- printf("Too long BSSID command.\n");
- return -1;
- }
- pos += ret;
- for (i = 0; i < argc; i++) {
- ret = os_snprintf(pos, end - pos, " %s", argv[i]);
- if (ret < 0 || ret >= end - pos) {
- printf("Too long BSSID command.\n");
- return -1;
- }
- pos += ret;
- }
-
- return wpa_ctrl_command(ctrl, cmd);
- }
-
-
- static int wpa_cli_cmd_list_networks(struct wpa_ctrl *ctrl, int argc,
- char *argv[])
- {
- return wpa_ctrl_command(ctrl, "LIST_NETWORKS");
- }
-
-
- static int wpa_cli_cmd_select_network(struct wpa_ctrl *ctrl, int argc,
- char *argv[])
- {
- char cmd[32];
- int res;
-
- if (argc < 1) {
- printf("Invalid SELECT_NETWORK command: needs one argument "
- "(network id)\n");
- return -1;
- }
-
- res = os_snprintf(cmd, sizeof(cmd), "SELECT_NETWORK %s", argv[0]);
- if (res < 0 || (size_t) res >= sizeof(cmd))
- return -1;
- cmd[sizeof(cmd) - 1] = '\0';
-
- return wpa_ctrl_command(ctrl, cmd);
- }
-
-
- static int wpa_cli_cmd_enable_network(struct wpa_ctrl *ctrl, int argc,
- char *argv[])
- {
- char cmd[32];
- int res;
-
- if (argc < 1) {
- printf("Invalid ENABLE_NETWORK command: needs one argument "
- "(network id)\n");
- return -1;
- }
-
- res = os_snprintf(cmd, sizeof(cmd), "ENABLE_NETWORK %s", argv[0]);
- if (res < 0 || (size_t) res >= sizeof(cmd))
- return -1;
- cmd[sizeof(cmd) - 1] = '\0';
-
- return wpa_ctrl_command(ctrl, cmd);
- }
-
-
- static int wpa_cli_cmd_disable_network(struct wpa_ctrl *ctrl, int argc,
- char *argv[])
- {
- char cmd[32];
- int res;
-
- if (argc < 1) {
- printf("Invalid DISABLE_NETWORK command: needs one argument "
- "(network id)\n");
- return -1;
- }
-
- res = os_snprintf(cmd, sizeof(cmd), "DISABLE_NETWORK %s", argv[0]);
- if (res < 0 || (size_t) res >= sizeof(cmd))
- return -1;
- cmd[sizeof(cmd) - 1] = '\0';
-
- return wpa_ctrl_command(ctrl, cmd);
- }
-
-
- static int wpa_cli_cmd_add_network(struct wpa_ctrl *ctrl, int argc,
- char *argv[])
- {
- return wpa_ctrl_command(ctrl, "ADD_NETWORK");
- }
-
-
- static int wpa_cli_cmd_remove_network(struct wpa_ctrl *ctrl, int argc,
- char *argv[])
- {
- char cmd[32];
- int res;
-
- if (argc < 1) {
- printf("Invalid REMOVE_NETWORK command: needs one argument "
- "(network id)\n");
- return -1;
- }
-
- res = os_snprintf(cmd, sizeof(cmd), "REMOVE_NETWORK %s", argv[0]);
- if (res < 0 || (size_t) res >= sizeof(cmd))
- return -1;
- cmd[sizeof(cmd) - 1] = '\0';
-
- return wpa_ctrl_command(ctrl, cmd);
- }
-
-
- static void wpa_cli_show_network_variables(void)
- {
- printf("set_network variables:\n"
- " ssid (network name, SSID)\n"
- " psk (WPA passphrase or pre-shared key)\n"
- " key_mgmt (key management protocol)\n"
- " identity (EAP identity)\n"
- " password (EAP password)\n"
- " ...\n"
- "\n"
- "Note: Values are entered in the same format as the "
- "configuration file is using,\n"
- "i.e., strings values need to be inside double quotation "
- "marks.\n"
- "For example: set_network 1 ssid \"network name\"\n"
- "\n"
- "Please see wpa_supplicant.conf documentation for full list "
- "of\navailable variables.\n");
- }
-
-
- static int wpa_cli_cmd_set_network(struct wpa_ctrl *ctrl, int argc,
- char *argv[])
- {
- char cmd[256];
- int res;
-
- if (argc == 0) {
- wpa_cli_show_network_variables();
- return 0;
- }
-
- if (argc != 3) {
- printf("Invalid SET_NETWORK command: needs three arguments\n"
- "(network id, variable name, and value)\n");
- return -1;
- }
-
- res = os_snprintf(cmd, sizeof(cmd), "SET_NETWORK %s %s %s",
- argv[0], argv[1], argv[2]);
- if (res < 0 || (size_t) res >= sizeof(cmd) - 1) {
- printf("Too long SET_NETWORK command.\n");
- return -1;
- }
- return wpa_ctrl_command(ctrl, cmd);
- }
-
-
- static int wpa_cli_cmd_get_network(struct wpa_ctrl *ctrl, int argc,
- char *argv[])
- {
- char cmd[256];
- int res;
-
- if (argc == 0) {
- wpa_cli_show_network_variables();
- return 0;
- }
-
- if (argc != 2) {
- printf("Invalid GET_NETWORK command: needs two arguments\n"
- "(network id and variable name)\n");
- return -1;
- }
-
- res = os_snprintf(cmd, sizeof(cmd), "GET_NETWORK %s %s",
- argv[0], argv[1]);
- if (res < 0 || (size_t) res >= sizeof(cmd) - 1) {
- printf("Too long GET_NETWORK command.\n");
- return -1;
- }
- return wpa_ctrl_command(ctrl, cmd);
- }
-
-
- static int wpa_cli_cmd_disconnect(struct wpa_ctrl *ctrl, int argc,
- char *argv[])
- {
- return wpa_ctrl_command(ctrl, "DISCONNECT");
- }
-
-
- static int wpa_cli_cmd_reconnect(struct wpa_ctrl *ctrl, int argc,
- char *argv[])
- {
- return wpa_ctrl_command(ctrl, "RECONNECT");
- }
-
-
- static int wpa_cli_cmd_save_config(struct wpa_ctrl *ctrl, int argc,
- char *argv[])
- {
- return wpa_ctrl_command(ctrl, "SAVE_CONFIG");
- }
-
-
- static int wpa_cli_cmd_scan(struct wpa_ctrl *ctrl, int argc, char *argv[])
- {
- return wpa_ctrl_command(ctrl, "SCAN");
- }
-
-
- static int wpa_cli_cmd_scan_results(struct wpa_ctrl *ctrl, int argc,
- char *argv[])
- {
- return wpa_ctrl_command(ctrl, "SCAN_RESULTS");
- }
-
-
- static int wpa_cli_cmd_bss(struct wpa_ctrl *ctrl, int argc, char *argv[])
- {
- char cmd[64];
- int res;
-
- if (argc != 1) {
- printf("Invalid BSS command: need one argument (index or "
- "BSSID)\n");
- return -1;
- }
-
- res = os_snprintf(cmd, sizeof(cmd), "BSS %s", argv[0]);
- if (res < 0 || (size_t) res >= sizeof(cmd))
- return -1;
- cmd[sizeof(cmd) - 1] = '\0';
-
- return wpa_ctrl_command(ctrl, cmd);
- }
-
-
- static int wpa_cli_cmd_get_capability(struct wpa_ctrl *ctrl, int argc,
- char *argv[])
- {
- char cmd[64];
- int res;
-
- if (argc < 1 || argc > 2) {
- printf("Invalid GET_CAPABILITY command: need either one or "
- "two arguments\n");
- return -1;
- }
-
- if ((argc == 2) && os_strcmp(argv[1], "strict") != 0) {
- printf("Invalid GET_CAPABILITY command: second argument, "
- "if any, must be 'strict'\n");
- return -1;
- }
-
- res = os_snprintf(cmd, sizeof(cmd), "GET_CAPABILITY %s%s", argv[0],
- (argc == 2) ? " strict" : "");
- if (res < 0 || (size_t) res >= sizeof(cmd))
- return -1;
- cmd[sizeof(cmd) - 1] = '\0';
-
- return wpa_ctrl_command(ctrl, cmd);
- }
-
-
- static int wpa_cli_list_interfaces(struct wpa_ctrl *ctrl)
- {
- printf("Available interfaces:\n");
- return wpa_ctrl_command(ctrl, "INTERFACES");
- }
-
-
- static int wpa_cli_cmd_interface(struct wpa_ctrl *ctrl, int argc, char *argv[])
- {
- if (argc < 1) {
- wpa_cli_list_interfaces(ctrl);
- return 0;
- }
-
- wpa_cli_close_connection();
- os_free(ctrl_ifname);
- ctrl_ifname = os_strdup(argv[0]);
-
- if (wpa_cli_open_connection(ctrl_ifname, 1)) {
- printf("Connected to interface '%s.\n", ctrl_ifname);
- } else {
- printf("Could not connect to interface '%s' - re-trying\n",
- ctrl_ifname);
- }
- return 0;
- }
-
-
- static int wpa_cli_cmd_reconfigure(struct wpa_ctrl *ctrl, int argc,
- char *argv[])
- {
- return wpa_ctrl_command(ctrl, "RECONFIGURE");
- }
-
-
- static int wpa_cli_cmd_terminate(struct wpa_ctrl *ctrl, int argc,
- char *argv[])
- {
- return wpa_ctrl_command(ctrl, "TERMINATE");
- }
-
-
- static int wpa_cli_cmd_interface_add(struct wpa_ctrl *ctrl, int argc,
- char *argv[])
- {
- char cmd[256];
- int res;
-
- if (argc < 1) {
- printf("Invalid INTERFACE_ADD command: needs at least one "
- "argument (interface name)\n"
- "All arguments: ifname confname driver ctrl_interface "
- "driver_param bridge_name\n");
- return -1;
- }
-
- /*
- * INTERFACE_ADD <ifname>TAB<confname>TAB<driver>TAB<ctrl_interface>TAB
- * <driver_param>TAB<bridge_name>
- */
- res = os_snprintf(cmd, sizeof(cmd),
- "INTERFACE_ADD %s\t%s\t%s\t%s\t%s\t%s",
- argv[0],
- argc > 1 ? argv[1] : "", argc > 2 ? argv[2] : "",
- argc > 3 ? argv[3] : "", argc > 4 ? argv[4] : "",
- argc > 5 ? argv[5] : "");
- if (res < 0 || (size_t) res >= sizeof(cmd))
- return -1;
- cmd[sizeof(cmd) - 1] = '\0';
- return wpa_ctrl_command(ctrl, cmd);
- }
-
-
- static int wpa_cli_cmd_interface_remove(struct wpa_ctrl *ctrl, int argc,
- char *argv[])
- {
- char cmd[128];
- int res;
-
- if (argc != 1) {
- printf("Invalid INTERFACE_REMOVE command: needs one argument "
- "(interface name)\n");
- return -1;
- }
-
- res = os_snprintf(cmd, sizeof(cmd), "INTERFACE_REMOVE %s", argv[0]);
- if (res < 0 || (size_t) res >= sizeof(cmd))
- return -1;
- cmd[sizeof(cmd) - 1] = '\0';
- return wpa_ctrl_command(ctrl, cmd);
- }
-
-
- static int wpa_cli_cmd_interface_list(struct wpa_ctrl *ctrl, int argc,
- char *argv[])
- {
- return wpa_ctrl_command(ctrl, "INTERFACE_LIST");
- }
-
-
- #ifdef CONFIG_AP
- static int wpa_cli_cmd_sta(struct wpa_ctrl *ctrl, int argc, char *argv[])
- {
- char buf[64];
- if (argc != 1) {
- printf("Invalid 'sta' command - exactly one argument, STA "
- "address, is required.\n");
- return -1;
- }
- os_snprintf(buf, sizeof(buf), "STA %s", argv[0]);
- return wpa_ctrl_command(ctrl, buf);
- }
-
-
- static int wpa_ctrl_command_sta(struct wpa_ctrl *ctrl, char *cmd,
- char *addr, size_t addr_len)
- {
- char buf[4096], *pos;
- size_t len;
- int ret;
-
- if (ctrl_conn == NULL) {
- printf("Not connected to hostapd - command dropped.\n");
- return -1;
- }
- len = sizeof(buf) - 1;
- ret = wpa_ctrl_request(ctrl, cmd, strlen(cmd), buf, &len,
- wpa_cli_msg_cb);
- if (ret == -2) {
- printf("'%s' command timed out.\n", cmd);
- return -2;
- } else if (ret < 0) {
- printf("'%s' command failed.\n", cmd);
- return -1;
- }
-
- buf[len] = '\0';
- if (memcmp(buf, "FAIL", 4) == 0)
- return -1;
- printf("%s", buf);
-
- pos = buf;
- while (*pos != '\0' && *pos != '\n')
- pos++;
- *pos = '\0';
- os_strlcpy(addr, buf, addr_len);
- return 0;
- }
-
-
- static int wpa_cli_cmd_all_sta(struct wpa_ctrl *ctrl, int argc, char *argv[])
- {
- char addr[32], cmd[64];
-
- if (wpa_ctrl_command_sta(ctrl, "STA-FIRST", addr, sizeof(addr)))
- return 0;
- do {
- os_snprintf(cmd, sizeof(cmd), "STA-NEXT %s", addr);
- } while (wpa_ctrl_command_sta(ctrl, cmd, addr, sizeof(addr)) == 0);
-
- return -1;
- }
- #endif /* CONFIG_AP */
-
-
- static int wpa_cli_cmd_suspend(struct wpa_ctrl *ctrl, int argc, char *argv[])
- {
- return wpa_ctrl_command(ctrl, "SUSPEND");
- }
-
-
- static int wpa_cli_cmd_resume(struct wpa_ctrl *ctrl, int argc, char *argv[])
- {
- return wpa_ctrl_command(ctrl, "RESUME");
- }
-
-
- static int wpa_cli_cmd_drop_sa(struct wpa_ctrl *ctrl, int argc, char *argv[])
- {
- return wpa_ctrl_command(ctrl, "DROP_SA");
- }
-
-
- static int wpa_cli_cmd_roam(struct wpa_ctrl *ctrl, int argc, char *argv[])
- {
- char cmd[128];
- int res;
-
- if (argc != 1) {
- printf("Invalid ROAM command: needs one argument "
- "(target AP's BSSID)\n");
- return -1;
- }
-
- res = os_snprintf(cmd, sizeof(cmd), "ROAM %s", argv[0]);
- if (res < 0 || (size_t) res >= sizeof(cmd) - 1) {
- printf("Too long ROAM command.\n");
- return -1;
- }
- return wpa_ctrl_command(ctrl, cmd);
- }
-
-
- #ifdef CONFIG_P2P
-
- static int wpa_cli_cmd_p2p_find(struct wpa_ctrl *ctrl, int argc, char *argv[])
- {
- char cmd[128];
- int res;
-
- if (argc == 0)
- return wpa_ctrl_command(ctrl, "P2P_FIND");
-
- if (argc > 1)
- res = os_snprintf(cmd, sizeof(cmd), "P2P_FIND %s %s",
- argv[0], argv[1]);
- else
- res = os_snprintf(cmd, sizeof(cmd), "P2P_FIND %s", argv[0]);
- if (res < 0 || (size_t) res >= sizeof(cmd))
- return -1;
- cmd[sizeof(cmd) - 1] = '\0';
- return wpa_ctrl_command(ctrl, cmd);
- }
-
-
- static int wpa_cli_cmd_p2p_stop_find(struct wpa_ctrl *ctrl, int argc,
- char *argv[])
- {
- return wpa_ctrl_command(ctrl, "P2P_STOP_FIND");
- }
-
-
- static int wpa_cli_cmd_p2p_connect(struct wpa_ctrl *ctrl, int argc,
- char *argv[])
- {
- char cmd[128];
- int res;
-
- if (argc < 2) {
- printf("Invalid P2P_CONNECT command: needs at least two "
- "arguments (address and pbc/PIN)\n");
- return -1;
- }
-
- if (argc > 4)
- res = os_snprintf(cmd, sizeof(cmd),
- "P2P_CONNECT %s %s %s %s %s",
- argv[0], argv[1], argv[2], argv[3],
- argv[4]);
- else if (argc > 3)
- res = os_snprintf(cmd, sizeof(cmd), "P2P_CONNECT %s %s %s %s",
- argv[0], argv[1], argv[2], argv[3]);
- else if (argc > 2)
- res = os_snprintf(cmd, sizeof(cmd), "P2P_CONNECT %s %s %s",
- argv[0], argv[1], argv[2]);
- else
- res = os_snprintf(cmd, sizeof(cmd), "P2P_CONNECT %s %s",
- argv[0], argv[1]);
- if (res < 0 || (size_t) res >= sizeof(cmd))
- return -1;
- cmd[sizeof(cmd) - 1] = '\0';
- return wpa_ctrl_command(ctrl, cmd);
- }
-
-
- static int wpa_cli_cmd_p2p_listen(struct wpa_ctrl *ctrl, int argc,
- char *argv[])
- {
- char cmd[128];
- int res;
-
- if (argc == 0)
- return wpa_ctrl_command(ctrl, "P2P_LISTEN");
-
- res = os_snprintf(cmd, sizeof(cmd), "P2P_LISTEN %s", argv[0]);
- if (res < 0 || (size_t) res >= sizeof(cmd))
- return -1;
- cmd[sizeof(cmd) - 1] = '\0';
- return wpa_ctrl_command(ctrl, cmd);
- }
-
-
- static int wpa_cli_cmd_p2p_group_remove(struct wpa_ctrl *ctrl, int argc,
- char *argv[])
- {
- char cmd[128];
- int res;
-
- if (argc != 1) {
- printf("Invalid P2P_GROUP_REMOVE command: needs one argument "
- "(interface name)\n");
- return -1;
- }
-
- res = os_snprintf(cmd, sizeof(cmd), "P2P_GROUP_REMOVE %s", argv[0]);
- if (res < 0 || (size_t) res >= sizeof(cmd))
- return -1;
- cmd[sizeof(cmd) - 1] = '\0';
- return wpa_ctrl_command(ctrl, cmd);
- }
-
-
- static int wpa_cli_cmd_p2p_group_add(struct wpa_ctrl *ctrl, int argc,
- char *argv[])
- {
- char cmd[128];
- int res;
-
- if (argc == 0)
- return wpa_ctrl_command(ctrl, "P2P_GROUP_ADD");
-
- res = os_snprintf(cmd, sizeof(cmd), "P2P_GROUP_ADD %s", argv[0]);
- if (res < 0 || (size_t) res >= sizeof(cmd))
- return -1;
- cmd[sizeof(cmd) - 1] = '\0';
- return wpa_ctrl_command(ctrl, cmd);
- }
-
-
- static int wpa_cli_cmd_p2p_prov_disc(struct wpa_ctrl *ctrl, int argc,
- char *argv[])
- {
- char cmd[128];
- int res;
-
- if (argc != 2) {
- printf("Invalid P2P_PROV_DISC command: needs two arguments "
- "(address and config method\n"
- "(display, keypad, or pbc)\n");
- return -1;
- }
-
- res = os_snprintf(cmd, sizeof(cmd), "P2P_PROV_DISC %s %s",
- argv[0], argv[1]);
- if (res < 0 || (size_t) res >= sizeof(cmd))
- return -1;
- cmd[sizeof(cmd) - 1] = '\0';
- return wpa_ctrl_command(ctrl, cmd);
- }
-
-
- static int wpa_cli_cmd_p2p_get_passphrase(struct wpa_ctrl *ctrl, int argc,
- char *argv[])
- {
- return wpa_ctrl_command(ctrl, "P2P_GET_PASSPHRASE");
- }
-
-
- static int wpa_cli_cmd_p2p_serv_disc_req(struct wpa_ctrl *ctrl, int argc,
- char *argv[])
- {
- char cmd[4096];
- int res;
-
- if (argc != 2 && argc != 4) {
- printf("Invalid P2P_SERV_DISC_REQ command: needs two "
- "arguments (address and TLVs) or four arguments "
- "(address, \"upnp\", version, search target "
- "(SSDP ST:)\n");
- return -1;
- }
-
- if (argc == 4)
- res = os_snprintf(cmd, sizeof(cmd),
- "P2P_SERV_DISC_REQ %s %s %s %s",
- argv[0], argv[1], argv[2], argv[3]);
- else
- res = os_snprintf(cmd, sizeof(cmd), "P2P_SERV_DISC_REQ %s %s",
- argv[0], argv[1]);
- if (res < 0 || (size_t) res >= sizeof(cmd))
- return -1;
- cmd[sizeof(cmd) - 1] = '\0';
- return wpa_ctrl_command(ctrl, cmd);
- }
-
-
- static int wpa_cli_cmd_p2p_serv_disc_cancel_req(struct wpa_ctrl *ctrl,
- int argc, char *argv[])
- {
- char cmd[128];
- int res;
-
- if (argc != 1) {
- printf("Invalid P2P_SERV_DISC_CANCEL_REQ command: needs one "
- "argument (pending request identifier)\n");
- return -1;
- }
-
- res = os_snprintf(cmd, sizeof(cmd), "P2P_SERV_DISC_CANCEL_REQ %s",
- argv[0]);
- if (res < 0 || (size_t) res >= sizeof(cmd))
- return -1;
- cmd[sizeof(cmd) - 1] = '\0';
- return wpa_ctrl_command(ctrl, cmd);
- }
-
-
- static int wpa_cli_cmd_p2p_serv_disc_resp(struct wpa_ctrl *ctrl, int argc,
- char *argv[])
- {
- char cmd[4096];
- int res;
-
- if (argc != 4) {
- printf("Invalid P2P_SERV_DISC_RESP command: needs four "
- "arguments (freq, address, dialog token, and TLVs)\n");
- return -1;
- }
-
- res = os_snprintf(cmd, sizeof(cmd), "P2P_SERV_DISC_RESP %s %s %s %s",
- argv[0], argv[1], argv[2], argv[3]);
- if (res < 0 || (size_t) res >= sizeof(cmd))
- return -1;
- cmd[sizeof(cmd) - 1] = '\0';
- return wpa_ctrl_command(ctrl, cmd);
- }
-
-
- static int wpa_cli_cmd_p2p_service_update(struct wpa_ctrl *ctrl, int argc,
- char *argv[])
- {
- return wpa_ctrl_command(ctrl, "P2P_SERVICE_UPDATE");
- }
-
-
- static int wpa_cli_cmd_p2p_serv_disc_external(struct wpa_ctrl *ctrl,
- int argc, char *argv[])
- {
- char cmd[128];
- int res;
-
- if (argc != 1) {
- printf("Invalid P2P_SERV_DISC_EXTERNAL command: needs one "
- "argument (external processing: 0/1)\n");
- return -1;
- }
-
- res = os_snprintf(cmd, sizeof(cmd), "P2P_SERV_DISC_EXTERNAL %s",
- argv[0]);
- if (res < 0 || (size_t) res >= sizeof(cmd))
- return -1;
- cmd[sizeof(cmd) - 1] = '\0';
- return wpa_ctrl_command(ctrl, cmd);
- }
-
-
- static int wpa_cli_cmd_p2p_service_flush(struct wpa_ctrl *ctrl, int argc,
- char *argv[])
- {
- return wpa_ctrl_command(ctrl, "P2P_SERVICE_FLUSH");
- }
-
-
- static int wpa_cli_cmd_p2p_service_add(struct wpa_ctrl *ctrl, int argc,
- char *argv[])
- {
- char cmd[4096];
- int res;
-
- if (argc != 3 && argc != 4) {
- printf("Invalid P2P_SERVICE_ADD command: needs three or four "
- "arguments\n");
- return -1;
- }
-
- if (argc == 4)
- res = os_snprintf(cmd, sizeof(cmd),
- "P2P_SERVICE_ADD %s %s %s %s",
- argv[0], argv[1], argv[2], argv[3]);
- else
- res = os_snprintf(cmd, sizeof(cmd),
- "P2P_SERVICE_ADD %s %s %s",
- argv[0], argv[1], argv[2]);
- if (res < 0 || (size_t) res >= sizeof(cmd))
- return -1;
- cmd[sizeof(cmd) - 1] = '\0';
- return wpa_ctrl_command(ctrl, cmd);
- }
-
-
- static int wpa_cli_cmd_p2p_service_del(struct wpa_ctrl *ctrl, int argc,
- char *argv[])
- {
- char cmd[4096];
- int res;
-
- if (argc != 2 && argc != 3) {
- printf("Invalid P2P_SERVICE_DEL command: needs two or three "
- "arguments\n");
- return -1;
- }
-
- if (argc == 3)
- res = os_snprintf(cmd, sizeof(cmd),
- "P2P_SERVICE_DEL %s %s %s",
- argv[0], argv[1], argv[2]);
- else
- res = os_snprintf(cmd, sizeof(cmd),
- "P2P_SERVICE_DEL %s %s",
- argv[0], argv[1]);
- if (res < 0 || (size_t) res >= sizeof(cmd))
- return -1;
- cmd[sizeof(cmd) - 1] = '\0';
- return wpa_ctrl_command(ctrl, cmd);
- }
-
-
- static int wpa_cli_cmd_p2p_reject(struct wpa_ctrl *ctrl,
- int argc, char *argv[])
- {
- char cmd[128];
- int res;
-
- if (argc != 1) {
- printf("Invalid P2P_REJECT command: needs one argument "
- "(peer address)\n");
- return -1;
- }
-
- res = os_snprintf(cmd, sizeof(cmd), "P2P_REJECT %s", argv[0]);
- if (res < 0 || (size_t) res >= sizeof(cmd))
- return -1;
- cmd[sizeof(cmd) - 1] = '\0';
- return wpa_ctrl_command(ctrl, cmd);
- }
-
-
- static int wpa_cli_cmd_p2p_invite(struct wpa_ctrl *ctrl,
- int argc, char *argv[])
- {
- char cmd[128];
- int res;
-
- if (argc < 1) {
- printf("Invalid P2P_INVITE command: needs at least one "
- "argument\n");
- return -1;
- }
-
- if (argc > 2)
- res = os_snprintf(cmd, sizeof(cmd), "P2P_INVITE %s %s %s",
- argv[0], argv[1], argv[2]);
- else if (argc > 1)
- res = os_snprintf(cmd, sizeof(cmd), "P2P_INVITE %s %s",
- argv[0], argv[1]);
- else
- res = os_snprintf(cmd, sizeof(cmd), "P2P_INVITE %s", argv[0]);
- if (res < 0 || (size_t) res >= sizeof(cmd))
- return -1;
- cmd[sizeof(cmd) - 1] = '\0';
- return wpa_ctrl_command(ctrl, cmd);
- }
-
-
- static int wpa_cli_cmd_p2p_peer(struct wpa_ctrl *ctrl, int argc, char *argv[])
- {
- char buf[64];
- if (argc != 1) {
- printf("Invalid 'p2p_peer' command - exactly one argument, "
- "P2P peer device address, is required.\n");
- return -1;
- }
- os_snprintf(buf, sizeof(buf), "P2P_PEER %s", argv[0]);
- return wpa_ctrl_command(ctrl, buf);
- }
-
-
- static int wpa_ctrl_command_p2p_peer(struct wpa_ctrl *ctrl, char *cmd,
- char *addr, size_t addr_len,
- int discovered)
- {
- char buf[4096], *pos;
- size_t len;
- int ret;
-
- if (ctrl_conn == NULL)
- return -1;
- len = sizeof(buf) - 1;
- ret = wpa_ctrl_request(ctrl, cmd, strlen(cmd), buf, &len,
- wpa_cli_msg_cb);
- if (ret == -2) {
- printf("'%s' command timed out.\n", cmd);
- return -2;
- } else if (ret < 0) {
- printf("'%s' command failed.\n", cmd);
- return -1;
- }
-
- buf[len] = '\0';
- if (memcmp(buf, "FAIL", 4) == 0)
- return -1;
-
- pos = buf;
- while (*pos != '\0' && *pos != '\n')
- pos++;
- *pos++ = '\0';
- os_strlcpy(addr, buf, addr_len);
- if (!discovered || os_strstr(pos, "[PROBE_REQ_ONLY]") == NULL)
- printf("%s\n", addr);
- return 0;
- }
-
-
- static int wpa_cli_cmd_p2p_peers(struct wpa_ctrl *ctrl, int argc, char *argv[])
- {
- char addr[32], cmd[64];
- int discovered;
-
- discovered = argc > 0 && os_strcmp(argv[0], "discovered") == 0;
-
- if (wpa_ctrl_command_p2p_peer(ctrl, "P2P_PEER FIRST",
- addr, sizeof(addr), discovered))
- return 0;
- do {
- os_snprintf(cmd, sizeof(cmd), "P2P_PEER NEXT-%s", addr);
- } while (wpa_ctrl_command_p2p_peer(ctrl, cmd, addr, sizeof(addr),
- discovered) == 0);
-
- return -1;
- }
-
-
- static int wpa_cli_cmd_p2p_set(struct wpa_ctrl *ctrl, int argc, char *argv[])
- {
- char cmd[100];
- int res;
-
- if (argc != 2) {
- printf("Invalid P2P_SET command: needs two arguments (field, "
- "value)\n");
- return -1;
- }
-
- res = os_snprintf(cmd, sizeof(cmd), "P2P_SET %s %s", argv[0], argv[1]);
- if (res < 0 || (size_t) res >= sizeof(cmd))
- return -1;
- cmd[sizeof(cmd) - 1] = '\0';
- return wpa_ctrl_command(ctrl, cmd);
- }
-
-
- static int wpa_cli_cmd_p2p_flush(struct wpa_ctrl *ctrl, int argc, char *argv[])
- {
- return wpa_ctrl_command(ctrl, "P2P_FLUSH");
- }
-
-
- static int wpa_cli_cmd_p2p_cancel(struct wpa_ctrl *ctrl, int argc,
- char *argv[])
- {
- return wpa_ctrl_command(ctrl, "P2P_CANCEL");
- }
-
-
- static int wpa_cli_cmd_p2p_unauthorize(struct wpa_ctrl *ctrl, int argc,
- char *argv[])
- {
- char cmd[100];
- int res;
-
- if (argc != 1) {
- printf("Invalid P2P_UNAUTHORIZE command: needs one argument "
- "(peer address)\n");
- return -1;
- }
-
- res = os_snprintf(cmd, sizeof(cmd), "P2P_UNAUTHORIZE %s", argv[0]);
-
- if (res < 0 || (size_t) res >= sizeof(cmd))
- return -1;
-
- cmd[sizeof(cmd) - 1] = '\0';
- return wpa_ctrl_command(ctrl, cmd);
- }
-
-
- static int wpa_cli_cmd_p2p_presence_req(struct wpa_ctrl *ctrl, int argc,
- char *argv[])
- {
- char cmd[100];
- int res;
-
- if (argc != 0 && argc != 2 && argc != 4) {
- printf("Invalid P2P_PRESENCE_REQ command: needs two arguments "
- "(preferred duration, interval; in microsecods).\n"
- "Optional second pair can be used to provide "
- "acceptable values.\n");
- return -1;
- }
-
- if (argc == 4)
- res = os_snprintf(cmd, sizeof(cmd),
- "P2P_PRESENCE_REQ %s %s %s %s",
- argv[0], argv[1], argv[2], argv[3]);
- else if (argc == 2)
- res = os_snprintf(cmd, sizeof(cmd), "P2P_PRESENCE_REQ %s %s",
- argv[0], argv[1]);
- else
- res = os_snprintf(cmd, sizeof(cmd), "P2P_PRESENCE_REQ");
- if (res < 0 || (size_t) res >= sizeof(cmd))
- return -1;
- cmd[sizeof(cmd) - 1] = '\0';
- return wpa_ctrl_command(ctrl, cmd);
- }
-
-
- static int wpa_cli_cmd_p2p_ext_listen(struct wpa_ctrl *ctrl, int argc,
- char *argv[])
- {
- char cmd[100];
- int res;
-
- if (argc != 0 && argc != 2) {
- printf("Invalid P2P_EXT_LISTEN command: needs two arguments "
- "(availability period, availability interval; in "
- "millisecods).\n"
- "Extended Listen Timing can be cancelled with this "
- "command when used without parameters.\n");
- return -1;
- }
-
- if (argc == 2)
- res = os_snprintf(cmd, sizeof(cmd), "P2P_EXT_LISTEN %s %s",
- argv[0], argv[1]);
- else
- res = os_snprintf(cmd, sizeof(cmd), "P2P_EXT_LISTEN");
- if (res < 0 || (size_t) res >= sizeof(cmd))
- return -1;
- cmd[sizeof(cmd) - 1] = '\0';
- return wpa_ctrl_command(ctrl, cmd);
- }
-
- #endif /* CONFIG_P2P */
-
-
- static int wpa_cli_cmd_sta_autoconnect(struct wpa_ctrl *ctrl, int argc,
- char *argv[])
- {
- char cmd[256];
- int res;
-
- if (argc != 1) {
- printf("Invalid STA_AUTOCONNECT command: needs one argument "
- "(0/1 = disable/enable automatic reconnection)\n");
- return -1;
- }
- res = os_snprintf(cmd, sizeof(cmd), "STA_AUTOCONNECT %s", argv[0]);
- if (res < 0 || (size_t) res >= sizeof(cmd) - 1) {
- printf("Too long STA_AUTOCONNECT command.\n");
- return -1;
- }
- return wpa_ctrl_command(ctrl, cmd);
- }
-
-
- static int wpa_cli_cmd_tdls_discover(struct wpa_ctrl *ctrl, int argc,
- char *argv[])
- {
- char cmd[256];
- int res;
-
- if (argc != 1) {
- printf("Invalid TDLS_DISCOVER command: needs one argument "
- "(Peer STA MAC address)\n");
- return -1;
- }
-
- res = os_snprintf(cmd, sizeof(cmd), "TDLS_DISCOVER %s", argv[0]);
- if (res < 0 || (size_t) res >= sizeof(cmd) - 1) {
- printf("Too long TDLS_DISCOVER command.\n");
- return -1;
- }
- return wpa_ctrl_command(ctrl, cmd);
- }
-
-
- static int wpa_cli_cmd_tdls_setup(struct wpa_ctrl *ctrl, int argc,
- char *argv[])
- {
- char cmd[256];
- int res;
-
- if (argc != 1) {
- printf("Invalid TDLS_SETUP command: needs one argument "
- "(Peer STA MAC address)\n");
- return -1;
- }
-
- res = os_snprintf(cmd, sizeof(cmd), "TDLS_SETUP %s", argv[0]);
- if (res < 0 || (size_t) res >= sizeof(cmd) - 1) {
- printf("Too long TDLS_SETUP command.\n");
- return -1;
- }
- return wpa_ctrl_command(ctrl, cmd);
- }
-
-
- static int wpa_cli_cmd_tdls_teardown(struct wpa_ctrl *ctrl, int argc,
- char *argv[])
- {
- char cmd[256];
- int res;
-
- if (argc != 1) {
- printf("Invalid TDLS_TEARDOWN command: needs one argument "
- "(Peer STA MAC address)\n");
- return -1;
- }
-
- res = os_snprintf(cmd, sizeof(cmd), "TDLS_TEARDOWN %s", argv[0]);
- if (res < 0 || (size_t) res >= sizeof(cmd) - 1) {
- printf("Too long TDLS_TEARDOWN command.\n");
- return -1;
- }
- return wpa_ctrl_command(ctrl, cmd);
- }
-
-
- static int wpa_cli_cmd_signal_poll(struct wpa_ctrl *ctrl, int argc,
- char *argv[])
- {
- return wpa_ctrl_command(ctrl, "SIGNAL_POLL");
- }
-
-
- enum wpa_cli_cmd_flags {
- cli_cmd_flag_none = 0x00,
- cli_cmd_flag_sensitive = 0x01
- };
-
- struct wpa_cli_cmd {
- const char *cmd;
- int (*handler)(struct wpa_ctrl *ctrl, int argc, char *argv[]);
- enum wpa_cli_cmd_flags flags;
- const char *usage;
- };
-
- static struct wpa_cli_cmd wpa_cli_commands[] = {
- { "status", wpa_cli_cmd_status,
- cli_cmd_flag_none,
- "[verbose] = get current WPA/EAPOL/EAP status" },
- { "ping", wpa_cli_cmd_ping,
- cli_cmd_flag_none,
- "= pings wpa_supplicant" },
- { "relog", wpa_cli_cmd_relog,
- cli_cmd_flag_none,
- "= re-open log-file (allow rolling logs)" },
- { "note", wpa_cli_cmd_note,
- cli_cmd_flag_none,
- "<text> = add a note to wpa_supplicant debug log" },
- { "mib", wpa_cli_cmd_mib,
- cli_cmd_flag_none,
- "= get MIB variables (dot1x, dot11)" },
- { "help", wpa_cli_cmd_help,
- cli_cmd_flag_none,
- "= show this usage help" },
- { "interface", wpa_cli_cmd_interface,
- cli_cmd_flag_none,
- "[ifname] = show interfaces/select interface" },
- { "level", wpa_cli_cmd_level,
- cli_cmd_flag_none,
- "<debug level> = change debug level" },
- { "license", wpa_cli_cmd_license,
- cli_cmd_flag_none,
- "= show full wpa_cli license" },
- { "quit", wpa_cli_cmd_quit,
- cli_cmd_flag_none,
- "= exit wpa_cli" },
- { "set", wpa_cli_cmd_set,
- cli_cmd_flag_none,
- "= set variables (shows list of variables when run without "
- "arguments)" },
- { "get", wpa_cli_cmd_get,
- cli_cmd_flag_none,
- "<name> = get information" },
- { "logon", wpa_cli_cmd_logon,
- cli_cmd_flag_none,
- "= IEEE 802.1X EAPOL state machine logon" },
- { "logoff", wpa_cli_cmd_logoff,
- cli_cmd_flag_none,
- "= IEEE 802.1X EAPOL state machine logoff" },
- { "pmksa", wpa_cli_cmd_pmksa,
- cli_cmd_flag_none,
- "= show PMKSA cache" },
- { "reassociate", wpa_cli_cmd_reassociate,
- cli_cmd_flag_none,
- "= force reassociation" },
- { "preauthenticate", wpa_cli_cmd_preauthenticate,
- cli_cmd_flag_none,
- "<BSSID> = force preauthentication" },
- { "identity", wpa_cli_cmd_identity,
- cli_cmd_flag_none,
- "<network id> <identity> = configure identity for an SSID" },
- { "password", wpa_cli_cmd_password,
- cli_cmd_flag_sensitive,
- "<network id> <password> = configure password for an SSID" },
- { "new_password", wpa_cli_cmd_new_password,
- cli_cmd_flag_sensitive,
- "<network id> <password> = change password for an SSID" },
- { "pin", wpa_cli_cmd_pin,
- cli_cmd_flag_sensitive,
- "<network id> <pin> = configure pin for an SSID" },
- { "otp", wpa_cli_cmd_otp,
- cli_cmd_flag_sensitive,
- "<network id> <password> = configure one-time-password for an SSID"
- },
- { "passphrase", wpa_cli_cmd_passphrase,
- cli_cmd_flag_sensitive,
- "<network id> <passphrase> = configure private key passphrase\n"
- " for an SSID" },
- { "bssid", wpa_cli_cmd_bssid,
- cli_cmd_flag_none,
- "<network id> <BSSID> = set preferred BSSID for an SSID" },
- { "list_networks", wpa_cli_cmd_list_networks,
- cli_cmd_flag_none,
- "= list configured networks" },
- { "select_network", wpa_cli_cmd_select_network,
- cli_cmd_flag_none,
- "<network id> = select a network (disable others)" },
- { "enable_network", wpa_cli_cmd_enable_network,
- cli_cmd_flag_none,
- "<network id> = enable a network" },
- { "disable_network", wpa_cli_cmd_disable_network,
- cli_cmd_flag_none,
- "<network id> = disable a network" },
- { "add_network", wpa_cli_cmd_add_network,
- cli_cmd_flag_none,
- "= add a network" },
- { "remove_network", wpa_cli_cmd_remove_network,
- cli_cmd_flag_none,
- "<network id> = remove a network" },
- { "set_network", wpa_cli_cmd_set_network,
- cli_cmd_flag_sensitive,
- "<network id> <variable> <value> = set network variables (shows\n"
- " list of variables when run without arguments)" },
- { "get_network", wpa_cli_cmd_get_network,
- cli_cmd_flag_none,
- "<network id> <variable> = get network variables" },
- { "save_config", wpa_cli_cmd_save_config,
- cli_cmd_flag_none,
- "= save the current configuration" },
- { "disconnect", wpa_cli_cmd_disconnect,
- cli_cmd_flag_none,
- "= disconnect and wait for reassociate/reconnect command before\n"
- " connecting" },
- { "reconnect", wpa_cli_cmd_reconnect,
- cli_cmd_flag_none,
- "= like reassociate, but only takes effect if already disconnected"
- },
- { "scan", wpa_cli_cmd_scan,
- cli_cmd_flag_none,
- "= request new BSS scan" },
- { "scan_results", wpa_cli_cmd_scan_results,
- cli_cmd_flag_none,
- "= get latest scan results" },
- { "bss", wpa_cli_cmd_bss,
- cli_cmd_flag_none,
- "<<idx> | <bssid>> = get detailed scan result info" },
- { "get_capability", wpa_cli_cmd_get_capability,
- cli_cmd_flag_none,
- "<eap/pairwise/group/key_mgmt/proto/auth_alg> = get capabilies" },
- { "reconfigure", wpa_cli_cmd_reconfigure,
- cli_cmd_flag_none,
- "= force wpa_supplicant to re-read its configuration file" },
- { "terminate", wpa_cli_cmd_terminate,
- cli_cmd_flag_none,
- "= terminate wpa_supplicant" },
- { "interface_add", wpa_cli_cmd_interface_add,
- cli_cmd_flag_none,
- "<ifname> <confname> <driver> <ctrl_interface> <driver_param>\n"
- " <bridge_name> = adds new interface, all parameters but <ifname>\n"
- " are optional" },
- { "interface_remove", wpa_cli_cmd_interface_remove,
- cli_cmd_flag_none,
- "<ifname> = removes the interface" },
- { "interface_list", wpa_cli_cmd_interface_list,
- cli_cmd_flag_none,
- "= list available interfaces" },
- { "ap_scan", wpa_cli_cmd_ap_scan,
- cli_cmd_flag_none,
- "<value> = set ap_scan parameter" },
- { "scan_interval", wpa_cli_cmd_scan_interval,
- cli_cmd_flag_none,
- "<value> = set scan_interval parameter (in seconds)" },
- { "bss_expire_age", wpa_cli_cmd_bss_expire_age,
- cli_cmd_flag_none,
- "<value> = set BSS expiration age parameter" },
- { "bss_expire_count", wpa_cli_cmd_bss_expire_count,
- cli_cmd_flag_none,
- "<value> = set BSS expiration scan count parameter" },
- { "stkstart", wpa_cli_cmd_stkstart,
- cli_cmd_flag_none,
- "<addr> = request STK negotiation with <addr>" },
- { "ft_ds", wpa_cli_cmd_ft_ds,
- cli_cmd_flag_none,
- "<addr> = request over-the-DS FT with <addr>" },
- { "wps_pbc", wpa_cli_cmd_wps_pbc,
- cli_cmd_flag_none,
- "[BSSID] = start Wi-Fi Protected Setup: Push Button Configuration" },
- { "wps_pin", wpa_cli_cmd_wps_pin,
- cli_cmd_flag_sensitive,
- "<BSSID> [PIN] = start WPS PIN method (returns PIN, if not "
- "hardcoded)" },
- { "wps_check_pin", wpa_cli_cmd_wps_check_pin,
- cli_cmd_flag_sensitive,
- "<PIN> = verify PIN checksum" },
- { "wps_cancel", wpa_cli_cmd_wps_cancel, cli_cmd_flag_none,
- "Cancels the pending WPS operation" },
- #ifdef CONFIG_WPS_OOB
- { "wps_oob", wpa_cli_cmd_wps_oob,
- cli_cmd_flag_sensitive,
- "<DEV_TYPE> <PATH> <METHOD> [DEV_NAME] = start WPS OOB" },
- #endif /* CONFIG_WPS_OOB */
- { "wps_reg", wpa_cli_cmd_wps_reg,
- cli_cmd_flag_sensitive,
- "<BSSID> <AP PIN> = start WPS Registrar to configure an AP" },
- { "wps_ap_pin", wpa_cli_cmd_wps_ap_pin,
- cli_cmd_flag_sensitive,
- "[params..] = enable/disable AP PIN" },
- { "wps_er_start", wpa_cli_cmd_wps_er_start,
- cli_cmd_flag_none,
- "[IP address] = start Wi-Fi Protected Setup External Registrar" },
- { "wps_er_stop", wpa_cli_cmd_wps_er_stop,
- cli_cmd_flag_none,
- "= stop Wi-Fi Protected Setup External Registrar" },
- { "wps_er_pin", wpa_cli_cmd_wps_er_pin,
- cli_cmd_flag_sensitive,
- "<UUID> <PIN> = add an Enrollee PIN to External Registrar" },
- { "wps_er_pbc", wpa_cli_cmd_wps_er_pbc,
- cli_cmd_flag_none,
- "<UUID> = accept an Enrollee PBC using External Registrar" },
- { "wps_er_learn", wpa_cli_cmd_wps_er_learn,
- cli_cmd_flag_sensitive,
- "<UUID> <PIN> = learn AP configuration" },
- { "wps_er_set_config", wpa_cli_cmd_wps_er_set_config,
- cli_cmd_flag_none,
- "<UUID> <network id> = set AP configuration for enrolling" },
- { "wps_er_config", wpa_cli_cmd_wps_er_config,
- cli_cmd_flag_sensitive,
- "<UUID> <PIN> <SSID> <auth> <encr> <key> = configure AP" },
- { "ibss_rsn", wpa_cli_cmd_ibss_rsn,
- cli_cmd_flag_none,
- "<addr> = request RSN authentication with <addr> in IBSS" },
- #ifdef CONFIG_AP
- { "sta", wpa_cli_cmd_sta,
- cli_cmd_flag_none,
- "<addr> = get information about an associated station (AP)" },
- { "all_sta", wpa_cli_cmd_all_sta,
- cli_cmd_flag_none,
- "= get information about all associated stations (AP)" },
- #endif /* CONFIG_AP */
- { "suspend", wpa_cli_cmd_suspend, cli_cmd_flag_none,
- "= notification of suspend/hibernate" },
- { "resume", wpa_cli_cmd_resume, cli_cmd_flag_none,
- "= notification of resume/thaw" },
- { "drop_sa", wpa_cli_cmd_drop_sa, cli_cmd_flag_none,
- "= drop SA without deauth/disassoc (test command)" },
- { "roam", wpa_cli_cmd_roam,
- cli_cmd_flag_none,
- "<addr> = roam to the specified BSS" },
- #ifdef CONFIG_P2P
- { "p2p_find", wpa_cli_cmd_p2p_find, cli_cmd_flag_none,
- "[timeout] [type=*] = find P2P Devices for up-to timeout seconds" },
- { "p2p_stop_find", wpa_cli_cmd_p2p_stop_find, cli_cmd_flag_none,
- "= stop P2P Devices search" },
- { "p2p_connect", wpa_cli_cmd_p2p_connect, cli_cmd_flag_none,
- "<addr> <\"pbc\"|PIN> = connect to a P2P Devices" },
- { "p2p_listen", wpa_cli_cmd_p2p_listen, cli_cmd_flag_none,
- "[timeout] = listen for P2P Devices for up-to timeout seconds" },
- { "p2p_group_remove", wpa_cli_cmd_p2p_group_remove, cli_cmd_flag_none,
- "<ifname> = remove P2P group interface (terminate group if GO)" },
- { "p2p_group_add", wpa_cli_cmd_p2p_group_add, cli_cmd_flag_none,
- "= add a new P2P group (local end as GO)" },
- { "p2p_prov_disc", wpa_cli_cmd_p2p_prov_disc, cli_cmd_flag_none,
- "<addr> <method> = request provisioning discovery" },
- { "p2p_get_passphrase", wpa_cli_cmd_p2p_get_passphrase,
- cli_cmd_flag_none,
- "= get the passphrase for a group (GO only)" },
- { "p2p_serv_disc_req", wpa_cli_cmd_p2p_serv_disc_req,
- cli_cmd_flag_none,
- "<addr> <TLVs> = schedule service discovery request" },
- { "p2p_serv_disc_cancel_req", wpa_cli_cmd_p2p_serv_disc_cancel_req,
- cli_cmd_flag_none,
- "<id> = cancel pending service discovery request" },
- { "p2p_serv_disc_resp", wpa_cli_cmd_p2p_serv_disc_resp,
- cli_cmd_flag_none,
- "<freq> <addr> <dialog token> <TLVs> = service discovery response" },
- { "p2p_service_update", wpa_cli_cmd_p2p_service_update,
- cli_cmd_flag_none,
- "= indicate change in local services" },
- { "p2p_serv_disc_external", wpa_cli_cmd_p2p_serv_disc_external,
- cli_cmd_flag_none,
- "<external> = set external processing of service discovery" },
- { "p2p_service_flush", wpa_cli_cmd_p2p_service_flush,
- cli_cmd_flag_none,
- "= remove all stored service entries" },
- { "p2p_service_add", wpa_cli_cmd_p2p_service_add,
- cli_cmd_flag_none,
- "<bonjour|upnp> <query|version> <response|service> = add a local "
- "service" },
- { "p2p_service_del", wpa_cli_cmd_p2p_service_del,
- cli_cmd_flag_none,
- "<bonjour|upnp> <query|version> [|service] = remove a local "
- "service" },
- { "p2p_reject", wpa_cli_cmd_p2p_reject,
- cli_cmd_flag_none,
- "<addr> = reject connection attempts from a specific peer" },
- { "p2p_invite", wpa_cli_cmd_p2p_invite,
- cli_cmd_flag_none,
- "<cmd> [peer=addr] = invite peer" },
- { "p2p_peers", wpa_cli_cmd_p2p_peers, cli_cmd_flag_none,
- "[discovered] = list known (optionally, only fully discovered) P2P "
- "peers" },
- { "p2p_peer", wpa_cli_cmd_p2p_peer, cli_cmd_flag_none,
- "<address> = show information about known P2P peer" },
- { "p2p_set", wpa_cli_cmd_p2p_set, cli_cmd_flag_none,
- "<field> <value> = set a P2P parameter" },
- { "p2p_flush", wpa_cli_cmd_p2p_flush, cli_cmd_flag_none,
- "= flush P2P state" },
- { "p2p_cancel", wpa_cli_cmd_p2p_cancel, cli_cmd_flag_none,
- "= cancel P2P group formation" },
- { "p2p_unauthorize", wpa_cli_cmd_p2p_unauthorize, cli_cmd_flag_none,
- "<address> = unauthorize a peer" },
- { "p2p_presence_req", wpa_cli_cmd_p2p_presence_req, cli_cmd_flag_none,
- "[<duration> <interval>] [<duration> <interval>] = request GO "
- "presence" },
- { "p2p_ext_listen", wpa_cli_cmd_p2p_ext_listen, cli_cmd_flag_none,
- "[<period> <interval>] = set extended listen timing" },
- #endif /* CONFIG_P2P */
- { "sta_autoconnect", wpa_cli_cmd_sta_autoconnect, cli_cmd_flag_none,
- "<0/1> = disable/enable automatic reconnection" },
- { "tdls_discover", wpa_cli_cmd_tdls_discover,
- cli_cmd_flag_none,
- "<addr> = request TDLS discovery with <addr>" },
- { "tdls_setup", wpa_cli_cmd_tdls_setup,
- cli_cmd_flag_none,
- "<addr> = request TDLS setup with <addr>" },
- { "tdls_teardown", wpa_cli_cmd_tdls_teardown,
- cli_cmd_flag_none,
- "<addr> = tear down TDLS with <addr>" },
- { "signal_poll", wpa_cli_cmd_signal_poll,
- cli_cmd_flag_none,
- "= get signal parameters" },
- { NULL, NULL, cli_cmd_flag_none, NULL }
- };
-
-
- /*
- * Prints command usage, lines are padded with the specified string.
- */
- static void print_cmd_help(struct wpa_cli_cmd *cmd, const char *pad)
- {
- char c;
- size_t n;
-
- printf("%s%s ", pad, cmd->cmd);
- for (n = 0; (c = cmd->usage[n]); n++) {
- printf("%c", c);
- if (c == '\n')
- printf("%s", pad);
- }
- printf("\n");
- }
-
-
- static void print_help(void)
- {
- int n;
- printf("commands:\n");
- for (n = 0; wpa_cli_commands[n].cmd; n++)
- print_cmd_help(&wpa_cli_commands[n], " ");
- }
-
-
- static int wpa_cli_edit_filter_history_cb(void *ctx, const char *cmd)
- {
- const char *c, *delim;
- int n;
- size_t len;
-
- delim = os_strchr(cmd, ' ');
- if (delim)
- len = delim - cmd;
- else
- len = os_strlen(cmd);
-
- for (n = 0; (c = wpa_cli_commands[n].cmd); n++) {
- if (os_strncasecmp(cmd, c, len) == 0 && len == os_strlen(c))
- return (wpa_cli_commands[n].flags &
- cli_cmd_flag_sensitive);
- }
- return 0;
- }
-
-
- static char ** wpa_list_cmd_list(void)
- {
- char **res;
- int i, count;
-
- count = sizeof(wpa_cli_commands) / sizeof(wpa_cli_commands[0]);
- res = os_zalloc(count * sizeof(char *));
- if (res == NULL)
- return NULL;
-
- for (i = 0; wpa_cli_commands[i].cmd; i++) {
- res[i] = os_strdup(wpa_cli_commands[i].cmd);
- if (res[i] == NULL)
- break;
- }
-
- return res;
- }
-
-
- static char ** wpa_cli_cmd_completion(const char *cmd, const char *str,
- int pos)
- {
- int i;
-
- for (i = 0; wpa_cli_commands[i].cmd; i++) {
- if (os_strcasecmp(wpa_cli_commands[i].cmd, cmd) == 0) {
- edit_clear_line();
- printf("\r%s\n", wpa_cli_commands[i].usage);
- edit_redraw();
- break;
- }
- }
-
- return NULL;
- }
-
-
- static char ** wpa_cli_edit_completion_cb(void *ctx, const char *str, int pos)
- {
- char **res;
- const char *end;
- char *cmd;
-
- end = os_strchr(str, ' ');
- if (end == NULL || str + pos < end)
- return wpa_list_cmd_list();
-
- cmd = os_malloc(pos + 1);
- if (cmd == NULL)
- return NULL;
- os_memcpy(cmd, str, pos);
- cmd[end - str] = '\0';
- res = wpa_cli_cmd_completion(cmd, str, pos);
- os_free(cmd);
- return res;
- }
-
-
- static int wpa_request(struct wpa_ctrl *ctrl, int argc, char *argv[])
- {
- struct wpa_cli_cmd *cmd, *match = NULL;
- int count;
- int ret = 0;
-
- count = 0;
- cmd = wpa_cli_commands;
- while (cmd->cmd) {
- if (os_strncasecmp(cmd->cmd, argv[0], os_strlen(argv[0])) == 0)
- {
- match = cmd;
- if (os_strcasecmp(cmd->cmd, argv[0]) == 0) {
- /* we have an exact match */
- count = 1;
- break;
- }
- count++;
- }
- cmd++;
- }
-
- if (count > 1) {
- printf("Ambiguous command '%s'; possible commands:", argv[0]);
- cmd = wpa_cli_commands;
- while (cmd->cmd) {
- if (os_strncasecmp(cmd->cmd, argv[0],
- os_strlen(argv[0])) == 0) {
- printf(" %s", cmd->cmd);
- }
- cmd++;
- }
- printf("\n");
- ret = 1;
- } else if (count == 0) {
- printf("Unknown command '%s'\n", argv[0]);
- ret = 1;
- } else {
- ret = match->handler(ctrl, argc - 1, &argv[1]);
- }
-
- return ret;
- }
-
-
- static int str_match(const char *a, const char *b)
- {
- return os_strncmp(a, b, os_strlen(b)) == 0;
- }
-
-
- static int wpa_cli_exec(const char *program, const char *arg1,
- const char *arg2)
- {
- char *cmd;
- size_t len;
- int res;
- int ret = 0;
-
- len = os_strlen(program) + os_strlen(arg1) + os_strlen(arg2) + 3;
- cmd = os_malloc(len);
- if (cmd == NULL)
- return -1;
- res = os_snprintf(cmd, len, "%s %s %s", program, arg1, arg2);
- if (res < 0 || (size_t) res >= len) {
- os_free(cmd);
- return -1;
- }
- cmd[len - 1] = '\0';
- #ifndef _WIN32_WCE
- if (system(cmd) < 0)
- ret = -1;
- #endif /* _WIN32_WCE */
- os_free(cmd);
-
- return ret;
- }
-
-
- static void wpa_cli_action_process(const char *msg)
- {
- const char *pos;
- char *copy = NULL, *id, *pos2;
-
- pos = msg;
- if (*pos == '<') {
- /* skip priority */
- pos = os_strchr(pos, '>');
- if (pos)
- pos++;
- else
- pos = msg;
- }
-
- if (str_match(pos, WPA_EVENT_CONNECTED)) {
- int new_id = -1;
- os_unsetenv("WPA_ID");
- os_unsetenv("WPA_ID_STR");
- os_unsetenv("WPA_CTRL_DIR");
-
- pos = os_strstr(pos, "[id=");
- if (pos)
- copy = os_strdup(pos + 4);
-
- if (copy) {
- pos2 = id = copy;
- while (*pos2 && *pos2 != ' ')
- pos2++;
- *pos2++ = '\0';
- new_id = atoi(id);
- os_setenv("WPA_ID", id, 1);
- while (*pos2 && *pos2 != '=')
- pos2++;
- if (*pos2 == '=')
- pos2++;
- id = pos2;
- while (*pos2 && *pos2 != ']')
- pos2++;
- *pos2 = '\0';
- os_setenv("WPA_ID_STR", id, 1);
- os_free(copy);
- }
-
- os_setenv("WPA_CTRL_DIR", ctrl_iface_dir, 1);
-
- if (!wpa_cli_connected || new_id != wpa_cli_last_id) {
- wpa_cli_connected = 1;
- wpa_cli_last_id = new_id;
- wpa_cli_exec(action_file, ctrl_ifname, "CONNECTED");
- }
- } else if (str_match(pos, WPA_EVENT_DISCONNECTED)) {
- if (wpa_cli_connected) {
- wpa_cli_connected = 0;
- wpa_cli_exec(action_file, ctrl_ifname, "DISCONNECTED");
- }
- } else if (str_match(pos, P2P_EVENT_GROUP_STARTED)) {
- wpa_cli_exec(action_file, ctrl_ifname, pos);
- } else if (str_match(pos, P2P_EVENT_GROUP_REMOVED)) {
- wpa_cli_exec(action_file, ctrl_ifname, pos);
- } else if (str_match(pos, P2P_EVENT_CROSS_CONNECT_ENABLE)) {
- wpa_cli_exec(action_file, ctrl_ifname, pos);
- } else if (str_match(pos, P2P_EVENT_CROSS_CONNECT_DISABLE)) {
- wpa_cli_exec(action_file, ctrl_ifname, pos);
- } else if (str_match(pos, WPS_EVENT_SUCCESS)) {
- wpa_cli_exec(action_file, ctrl_ifname, pos);
- } else if (str_match(pos, WPS_EVENT_FAIL)) {
- wpa_cli_exec(action_file, ctrl_ifname, pos);
- } else if (str_match(pos, WPA_EVENT_TERMINATING)) {
- printf("wpa_supplicant is terminating - stop monitoring\n");
- wpa_cli_quit = 1;
- }
- }
-
-
- #ifndef CONFIG_ANSI_C_EXTRA
- static void wpa_cli_action_cb(char *msg, size_t len)
- {
- wpa_cli_action_process(msg);
- }
- #endif /* CONFIG_ANSI_C_EXTRA */
-
-
- static void wpa_cli_reconnect(void)
- {
- wpa_cli_close_connection();
- wpa_cli_open_connection(ctrl_ifname, 1);
- }
-
-
- static void wpa_cli_recv_pending(struct wpa_ctrl *ctrl, int action_monitor)
- {
- if (ctrl_conn == NULL) {
- wpa_cli_reconnect();
- return;
- }
- while (wpa_ctrl_pending(ctrl) > 0) {
- char buf[256];
- size_t len = sizeof(buf) - 1;
- if (wpa_ctrl_recv(ctrl, buf, &len) == 0) {
- buf[len] = '\0';
- if (action_monitor)
- wpa_cli_action_process(buf);
- else {
- if (wpa_cli_show_event(buf)) {
- edit_clear_line();
- printf("\r%s\n", buf);
- edit_redraw();
- }
- }
- } else {
- printf("Could not read pending message.\n");
- break;
- }
- }
-
- if (wpa_ctrl_pending(ctrl) < 0) {
- printf("Connection to wpa_supplicant lost - trying to "
- "reconnect\n");
- wpa_cli_reconnect();
- }
- }
-
- #define max_args 10
-
- static int tokenize_cmd(char *cmd, char *argv[])
- {
- char *pos;
- int argc = 0;
-
- pos = cmd;
- for (;;) {
- while (*pos == ' ')
- pos++;
- if (*pos == '\0')
- break;
- argv[argc] = pos;
- argc++;
- if (argc == max_args)
- break;
- if (*pos == '"') {
- char *pos2 = os_strrchr(pos, '"');
- if (pos2)
- pos = pos2 + 1;
- }
- while (*pos != '\0' && *pos != ' ')
- pos++;
- if (*pos == ' ')
- *pos++ = '\0';
- }
-
- return argc;
- }
-
-
- static void wpa_cli_ping(void *eloop_ctx, void *timeout_ctx)
- {
- if (ctrl_conn && _wpa_ctrl_command(ctrl_conn, "PING", 0)) {
- printf("Connection to wpa_supplicant lost - trying to "
- "reconnect\n");
- wpa_cli_close_connection();
- }
- if (!ctrl_conn)
- wpa_cli_reconnect();
- eloop_register_timeout(ping_interval, 0, wpa_cli_ping, NULL, NULL);
- }
-
-
- static void wpa_cli_eloop_terminate(int sig, void *signal_ctx)
- {
- eloop_terminate();
- }
-
-
- static void wpa_cli_mon_receive(int sock, void *eloop_ctx, void *sock_ctx)
- {
- wpa_cli_recv_pending(mon_conn, 0);
- }
-
-
- static void wpa_cli_edit_cmd_cb(void *ctx, char *cmd)
- {
- char *argv[max_args];
- int argc;
- argc = tokenize_cmd(cmd, argv);
- if (argc)
- wpa_request(ctrl_conn, argc, argv);
- }
-
-
- static void wpa_cli_edit_eof_cb(void *ctx)
- {
- eloop_terminate();
- }
-
-
- static void wpa_cli_interactive(void)
- {
- char *home, *hfile = NULL;
-
- printf("\nInteractive mode\n\n");
-
- home = getenv("HOME");
- if (home) {
- const char *fname = ".wpa_cli_history";
- int hfile_len = os_strlen(home) + 1 + os_strlen(fname) + 1;
- hfile = os_malloc(hfile_len);
- if (hfile)
- os_snprintf(hfile, hfile_len, "%s/%s", home, fname);
- }
-
- eloop_register_signal_terminate(wpa_cli_eloop_terminate, NULL);
- edit_init(wpa_cli_edit_cmd_cb, wpa_cli_edit_eof_cb,
- wpa_cli_edit_completion_cb, NULL, hfile);
- eloop_register_timeout(ping_interval, 0, wpa_cli_ping, NULL, NULL);
-
- eloop_run();
-
- edit_deinit(hfile, wpa_cli_edit_filter_history_cb);
- os_free(hfile);
- eloop_cancel_timeout(wpa_cli_ping, NULL, NULL);
- wpa_cli_close_connection();
- }
-
-
- static void wpa_cli_action(struct wpa_ctrl *ctrl)
- {
- #ifdef CONFIG_ANSI_C_EXTRA
- /* TODO: ANSI C version(?) */
- printf("Action processing not supported in ANSI C build.\n");
- #else /* CONFIG_ANSI_C_EXTRA */
- fd_set rfds;
- int fd, res;
- struct timeval tv;
- char buf[256]; /* note: large enough to fit in unsolicited messages */
- size_t len;
-
- fd = wpa_ctrl_get_fd(ctrl);
-
- while (!wpa_cli_quit) {
- FD_ZERO(&rfds);
- FD_SET(fd, &rfds);
- tv.tv_sec = ping_interval;
- tv.tv_usec = 0;
- res = select(fd + 1, &rfds, NULL, NULL, &tv);
- if (res < 0 && errno != EINTR) {
- perror("select");
- break;
- }
-
- if (FD_ISSET(fd, &rfds))
- wpa_cli_recv_pending(ctrl, 1);
- else {
- /* verify that connection is still working */
- len = sizeof(buf) - 1;
- if (wpa_ctrl_request(ctrl, "PING", 4, buf, &len,
- wpa_cli_action_cb) < 0 ||
- len < 4 || os_memcmp(buf, "PONG", 4) != 0) {
- printf("wpa_supplicant did not reply to PING "
- "command - exiting\n");
- break;
- }
- }
- }
- #endif /* CONFIG_ANSI_C_EXTRA */
- }
-
-
- static void wpa_cli_cleanup(void)
- {
- wpa_cli_close_connection();
- if (pid_file)
- os_daemonize_terminate(pid_file);
-
- os_program_deinit();
- }
-
- static void wpa_cli_terminate(int sig)
- {
- wpa_cli_cleanup();
- exit(0);
- }
-
-
- static char * wpa_cli_get_default_ifname(void)
- {
- char *ifname = NULL;
-
- #ifdef CONFIG_CTRL_IFACE_UNIX
- struct dirent *dent;
- DIR *dir = opendir(ctrl_iface_dir);
- if (!dir) {
- #ifdef ANDROID
- char ifprop[PROPERTY_VALUE_MAX];
- if (property_get("wifi.interface", ifprop, NULL) != 0) {
- ifname = os_strdup(ifprop);
- printf("Using interface '%s'\n", ifname);
- return ifname;
- }
- #endif /* ANDROID */
- return NULL;
- }
- while ((dent = readdir(dir))) {
- #ifdef _DIRENT_HAVE_D_TYPE
- /*
- * Skip the file if it is not a socket. Also accept
- * DT_UNKNOWN (0) in case the C library or underlying
- * file system does not support d_type.
- */
- if (dent->d_type != DT_SOCK && dent->d_type != DT_UNKNOWN)
- continue;
- #endif /* _DIRENT_HAVE_D_TYPE */
- if (os_strcmp(dent->d_name, ".") == 0 ||
- os_strcmp(dent->d_name, "..") == 0)
- continue;
- printf("Selected interface '%s'\n", dent->d_name);
- ifname = os_strdup(dent->d_name);
- break;
- }
- closedir(dir);
- #endif /* CONFIG_CTRL_IFACE_UNIX */
-
- #ifdef CONFIG_CTRL_IFACE_NAMED_PIPE
- char buf[2048], *pos;
- size_t len;
- struct wpa_ctrl *ctrl;
- int ret;
-
- ctrl = wpa_ctrl_open(NULL);
- if (ctrl == NULL)
- return NULL;
-
- len = sizeof(buf) - 1;
- ret = wpa_ctrl_request(ctrl, "INTERFACES", 10, buf, &len, NULL);
- if (ret >= 0) {
- buf[len] = '\0';
- pos = os_strchr(buf, '\n');
- if (pos)
- *pos = '\0';
- ifname = os_strdup(buf);
- }
- wpa_ctrl_close(ctrl);
- #endif /* CONFIG_CTRL_IFACE_NAMED_PIPE */
-
- return ifname;
- }
-
-
- int main(int argc, char *argv[])
- {
- int warning_displayed = 0;
- int c;
- int daemonize = 0;
- int ret = 0;
- const char *global = NULL;
-
- if (os_program_init())
- return -1;
-
- for (;;) {
- c = getopt(argc, argv, "a:Bg:G:hi:p:P:v");
- if (c < 0)
- break;
- switch (c) {
- case 'a':
- action_file = optarg;
- break;
- case 'B':
- daemonize = 1;
- break;
- case 'g':
- global = optarg;
- break;
- case 'G':
- ping_interval = atoi(optarg);
- break;
- case 'h':
- usage();
- return 0;
- case 'v':
- printf("%s\n", wpa_cli_version);
- return 0;
- case 'i':
- os_free(ctrl_ifname);
- ctrl_ifname = os_strdup(optarg);
- break;
- case 'p':
- ctrl_iface_dir = optarg;
- break;
- case 'P':
- pid_file = optarg;
- break;
- default:
- usage();
- return -1;
- }
- }
-
- interactive = (argc == optind) && (action_file == NULL);
-
- if (interactive)
- printf("%s\n\n%s\n\n", wpa_cli_version, wpa_cli_license);
-
- if (eloop_init())
- return -1;
-
- if (global) {
- #ifdef CONFIG_CTRL_IFACE_NAMED_PIPE
- ctrl_conn = wpa_ctrl_open(NULL);
- #else /* CONFIG_CTRL_IFACE_NAMED_PIPE */
- ctrl_conn = wpa_ctrl_open(global);
- #endif /* CONFIG_CTRL_IFACE_NAMED_PIPE */
- if (ctrl_conn == NULL) {
- perror("Failed to connect to wpa_supplicant - "
- "wpa_ctrl_open");
- return -1;
- }
- }
-
- #ifndef _WIN32_WCE
- signal(SIGINT, wpa_cli_terminate);
- signal(SIGTERM, wpa_cli_terminate);
- #endif /* _WIN32_WCE */
-
- if (ctrl_ifname == NULL)
- ctrl_ifname = wpa_cli_get_default_ifname();
-
- if (interactive) {
- for (; !global;) {
- if (wpa_cli_open_connection(ctrl_ifname, 1) == 0) {
- if (warning_displayed)
- printf("Connection established.\n");
- break;
- }
-
- if (!warning_displayed) {
- printf("Could not connect to wpa_supplicant - "
- "re-trying\n");
- warning_displayed = 1;
- }
- os_sleep(1, 0);
- continue;
- }
- } else {
- if (!global &&
- wpa_cli_open_connection(ctrl_ifname, 0) < 0) {
- perror("Failed to connect to wpa_supplicant - "
- "wpa_ctrl_open");
- return -1;
- }
-
- if (action_file) {
- if (wpa_ctrl_attach(ctrl_conn) == 0) {
- wpa_cli_attached = 1;
- } else {
- printf("Warning: Failed to attach to "
- "wpa_supplicant.\n");
- return -1;
- }
- }
- }
-
- if (daemonize && os_daemonize(pid_file))
- return -1;
-
- if (interactive)
- wpa_cli_interactive();
- else if (action_file)
- wpa_cli_action(ctrl_conn);
- else
- ret = wpa_request(ctrl_conn, argc - optind, &argv[optind]);
-
- os_free(ctrl_ifname);
- eloop_destroy();
- wpa_cli_cleanup();
-
- return ret;
- }
-
- #else /* CONFIG_CTRL_IFACE */
- int main(int argc, char *argv[])
- {
- printf("CONFIG_CTRL_IFACE not defined - wpa_cli disabled\n");
- return -1;
- }
- #endif /* CONFIG_CTRL_IFACE */
|