2 * WPA Supplicant - command line interface for wpa_supplicant daemon
3 * Copyright (c) 2004-2009, Jouni Malinen <j@w1.fi>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation.
9 * Alternatively, this software may be distributed under the terms of BSD
12 * See README and COPYING for more details.
17 #ifdef CONFIG_CTRL_IFACE
19 #ifdef CONFIG_CTRL_IFACE_UNIX
21 #endif /* CONFIG_CTRL_IFACE_UNIX */
22 #ifdef CONFIG_READLINE
23 #include <readline/readline.h>
24 #include <readline/history.h>
25 #endif /* CONFIG_READLINE */
32 static const char *wpa_cli_version =
33 "wpa_cli v" VERSION_STR "\n"
34 "Copyright (c) 2004-2009, Jouni Malinen <j@w1.fi> and contributors";
37 static const char *wpa_cli_license =
38 "This program is free software. You can distribute it and/or modify it\n"
39 "under the terms of the GNU General Public License version 2.\n"
41 "Alternatively, this software may be distributed under the terms of the\n"
42 "BSD license. See README and COPYING for more details.\n";
44 static const char *wpa_cli_full_license =
45 "This program is free software; you can redistribute it and/or modify\n"
46 "it under the terms of the GNU General Public License version 2 as\n"
47 "published by the Free Software Foundation.\n"
49 "This program is distributed in the hope that it will be useful,\n"
50 "but WITHOUT ANY WARRANTY; without even the implied warranty of\n"
51 "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n"
52 "GNU General Public License for more details.\n"
54 "You should have received a copy of the GNU General Public License\n"
55 "along with this program; if not, write to the Free Software\n"
56 "Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA\n"
58 "Alternatively, this software may be distributed under the terms of the\n"
61 "Redistribution and use in source and binary forms, with or without\n"
62 "modification, are permitted provided that the following conditions are\n"
65 "1. Redistributions of source code must retain the above copyright\n"
66 " notice, this list of conditions and the following disclaimer.\n"
68 "2. Redistributions in binary form must reproduce the above copyright\n"
69 " notice, this list of conditions and the following disclaimer in the\n"
70 " documentation and/or other materials provided with the distribution.\n"
72 "3. Neither the name(s) of the above-listed copyright holder(s) nor the\n"
73 " names of its contributors may be used to endorse or promote products\n"
74 " derived from this software without specific prior written permission.\n"
76 "THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n"
77 "\"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n"
78 "LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n"
79 "A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n"
80 "OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n"
81 "SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n"
82 "LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n"
83 "DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n"
84 "THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n"
85 "(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n"
86 "OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n"
89 static struct wpa_ctrl *ctrl_conn;
90 static int wpa_cli_quit = 0;
91 static int wpa_cli_attached = 0;
92 static int wpa_cli_connected = 0;
93 static int wpa_cli_last_id = 0;
94 static const char *ctrl_iface_dir = "/var/run/wpa_supplicant";
95 static char *ctrl_ifname = NULL;
96 static const char *pid_file = NULL;
97 static const char *action_file = NULL;
98 static int ping_interval = 5;
101 static void print_help();
104 static void usage(void)
106 printf("wpa_cli [-p<path to ctrl sockets>] [-i<ifname>] [-hvB] "
107 "[-a<action file>] \\\n"
108 " [-P<pid file>] [-g<global ctrl>] [-G<ping interval>] "
110 " -h = help (show this usage text)\n"
111 " -v = shown version information\n"
112 " -a = run in daemon mode executing the action file based on "
115 " -B = run a daemon in the background\n"
116 " default path: /var/run/wpa_supplicant\n"
117 " default interface: first interface found in socket path\n");
122 static struct wpa_ctrl * wpa_cli_open_connection(const char *ifname)
124 #if defined(CONFIG_CTRL_IFACE_UDP) || defined(CONFIG_CTRL_IFACE_NAMED_PIPE)
125 ctrl_conn = wpa_ctrl_open(ifname);
127 #else /* CONFIG_CTRL_IFACE_UDP || CONFIG_CTRL_IFACE_NAMED_PIPE */
134 flen = os_strlen(ctrl_iface_dir) + os_strlen(ifname) + 2;
135 cfile = os_malloc(flen);
138 res = os_snprintf(cfile, flen, "%s/%s", ctrl_iface_dir, ifname);
139 if (res < 0 || res >= flen) {
144 ctrl_conn = wpa_ctrl_open(cfile);
147 #endif /* CONFIG_CTRL_IFACE_UDP || CONFIG_CTRL_IFACE_NAMED_PIPE */
151 static void wpa_cli_close_connection(void)
153 if (ctrl_conn == NULL)
156 if (wpa_cli_attached) {
157 wpa_ctrl_detach(ctrl_conn);
158 wpa_cli_attached = 0;
160 wpa_ctrl_close(ctrl_conn);
165 static void wpa_cli_msg_cb(char *msg, size_t len)
171 static int _wpa_ctrl_command(struct wpa_ctrl *ctrl, char *cmd, int print)
177 if (ctrl_conn == NULL) {
178 printf("Not connected to wpa_supplicant - command dropped.\n");
181 len = sizeof(buf) - 1;
182 ret = wpa_ctrl_request(ctrl, cmd, os_strlen(cmd), buf, &len,
185 printf("'%s' command timed out.\n", cmd);
187 } else if (ret < 0) {
188 printf("'%s' command failed.\n", cmd);
199 static int wpa_ctrl_command(struct wpa_ctrl *ctrl, char *cmd)
201 return _wpa_ctrl_command(ctrl, cmd, 1);
205 static int wpa_cli_cmd_status(struct wpa_ctrl *ctrl, int argc, char *argv[])
207 int verbose = argc > 0 && os_strcmp(argv[0], "verbose") == 0;
208 return wpa_ctrl_command(ctrl, verbose ? "STATUS-VERBOSE" : "STATUS");
212 static int wpa_cli_cmd_ping(struct wpa_ctrl *ctrl, int argc, char *argv[])
214 return wpa_ctrl_command(ctrl, "PING");
218 static int wpa_cli_cmd_mib(struct wpa_ctrl *ctrl, int argc, char *argv[])
220 return wpa_ctrl_command(ctrl, "MIB");
224 static int wpa_cli_cmd_pmksa(struct wpa_ctrl *ctrl, int argc, char *argv[])
226 return wpa_ctrl_command(ctrl, "PMKSA");
230 static int wpa_cli_cmd_help(struct wpa_ctrl *ctrl, int argc, char *argv[])
237 static int wpa_cli_cmd_license(struct wpa_ctrl *ctrl, int argc, char *argv[])
239 printf("%s\n\n%s\n", wpa_cli_version, wpa_cli_full_license);
244 static int wpa_cli_cmd_quit(struct wpa_ctrl *ctrl, int argc, char *argv[])
251 static void wpa_cli_show_variables(void)
253 printf("set variables:\n"
254 " EAPOL::heldPeriod (EAPOL state machine held period, "
256 " EAPOL::authPeriod (EAPOL state machine authentication "
257 "period, in seconds)\n"
258 " EAPOL::startPeriod (EAPOL state machine start period, in "
260 " EAPOL::maxStart (EAPOL state machine maximum start "
262 printf(" dot11RSNAConfigPMKLifetime (WPA/WPA2 PMK lifetime in "
264 " dot11RSNAConfigPMKReauthThreshold (WPA/WPA2 reauthentication"
265 " threshold\n\tpercentage)\n"
266 " dot11RSNAConfigSATimeout (WPA/WPA2 timeout for completing "
267 "security\n\tassociation in seconds)\n");
271 static int wpa_cli_cmd_set(struct wpa_ctrl *ctrl, int argc, char *argv[])
277 wpa_cli_show_variables();
282 printf("Invalid SET command: needs two arguments (variable "
283 "name and value)\n");
287 res = os_snprintf(cmd, sizeof(cmd), "SET %s %s", argv[0], argv[1]);
288 if (res < 0 || (size_t) res >= sizeof(cmd) - 1) {
289 printf("Too long SET command.\n");
292 return wpa_ctrl_command(ctrl, cmd);
296 static int wpa_cli_cmd_logoff(struct wpa_ctrl *ctrl, int argc, char *argv[])
298 return wpa_ctrl_command(ctrl, "LOGOFF");
302 static int wpa_cli_cmd_logon(struct wpa_ctrl *ctrl, int argc, char *argv[])
304 return wpa_ctrl_command(ctrl, "LOGON");
308 static int wpa_cli_cmd_reassociate(struct wpa_ctrl *ctrl, int argc,
311 return wpa_ctrl_command(ctrl, "REASSOCIATE");
315 static int wpa_cli_cmd_preauthenticate(struct wpa_ctrl *ctrl, int argc,
322 printf("Invalid PREAUTH command: needs one argument "
327 res = os_snprintf(cmd, sizeof(cmd), "PREAUTH %s", argv[0]);
328 if (res < 0 || (size_t) res >= sizeof(cmd) - 1) {
329 printf("Too long PREAUTH command.\n");
332 return wpa_ctrl_command(ctrl, cmd);
336 static int wpa_cli_cmd_ap_scan(struct wpa_ctrl *ctrl, int argc, char *argv[])
342 printf("Invalid AP_SCAN command: needs one argument (ap_scan "
346 res = os_snprintf(cmd, sizeof(cmd), "AP_SCAN %s", argv[0]);
347 if (res < 0 || (size_t) res >= sizeof(cmd) - 1) {
348 printf("Too long AP_SCAN command.\n");
351 return wpa_ctrl_command(ctrl, cmd);
355 static int wpa_cli_cmd_stkstart(struct wpa_ctrl *ctrl, int argc,
362 printf("Invalid STKSTART command: needs one argument "
363 "(Peer STA MAC address)\n");
367 res = os_snprintf(cmd, sizeof(cmd), "STKSTART %s", argv[0]);
368 if (res < 0 || (size_t) res >= sizeof(cmd) - 1) {
369 printf("Too long STKSTART command.\n");
372 return wpa_ctrl_command(ctrl, cmd);
376 static int wpa_cli_cmd_ft_ds(struct wpa_ctrl *ctrl, int argc, char *argv[])
382 printf("Invalid FT_DS command: needs one argument "
383 "(Target AP MAC address)\n");
387 res = os_snprintf(cmd, sizeof(cmd), "FT_DS %s", argv[0]);
388 if (res < 0 || (size_t) res >= sizeof(cmd) - 1) {
389 printf("Too long FT_DS command.\n");
392 return wpa_ctrl_command(ctrl, cmd);
396 static int wpa_cli_cmd_wps_pbc(struct wpa_ctrl *ctrl, int argc, char *argv[])
403 return wpa_ctrl_command(ctrl, "WPS_PBC");
407 res = os_snprintf(cmd, sizeof(cmd), "WPS_PBC %s", argv[0]);
408 if (res < 0 || (size_t) res >= sizeof(cmd) - 1) {
409 printf("Too long WPS_PBC command.\n");
412 return wpa_ctrl_command(ctrl, cmd);
416 static int wpa_cli_cmd_wps_pin(struct wpa_ctrl *ctrl, int argc, char *argv[])
422 printf("Invalid WPS_PIN command: need one or two arguments:\n"
423 "- BSSID: use 'any' to select any\n"
424 "- PIN: optional, used only with devices that have no "
430 /* Use dynamically generated PIN (returned as reply) */
431 res = os_snprintf(cmd, sizeof(cmd), "WPS_PIN %s", argv[0]);
432 if (res < 0 || (size_t) res >= sizeof(cmd) - 1) {
433 printf("Too long WPS_PIN command.\n");
436 return wpa_ctrl_command(ctrl, cmd);
439 /* Use hardcoded PIN from a label */
440 res = os_snprintf(cmd, sizeof(cmd), "WPS_PIN %s %s", argv[0], argv[1]);
441 if (res < 0 || (size_t) res >= sizeof(cmd) - 1) {
442 printf("Too long WPS_PIN command.\n");
445 return wpa_ctrl_command(ctrl, cmd);
449 static int wpa_cli_cmd_wps_reg(struct wpa_ctrl *ctrl, int argc, char *argv[])
455 printf("Invalid WPS_REG command: need two arguments:\n"
456 "- BSSID: use 'any' to select any\n"
461 res = os_snprintf(cmd, sizeof(cmd), "WPS_REG %s %s", argv[0], argv[1]);
462 if (res < 0 || (size_t) res >= sizeof(cmd) - 1) {
463 printf("Too long WPS_REG command.\n");
466 return wpa_ctrl_command(ctrl, cmd);
470 static int wpa_cli_cmd_ibss_rsn(struct wpa_ctrl *ctrl, int argc, char *argv[])
476 printf("Invalid IBSS_RSN command: needs one argument "
477 "(Peer STA MAC address)\n");
481 res = os_snprintf(cmd, sizeof(cmd), "IBSS_RSN %s", argv[0]);
482 if (res < 0 || (size_t) res >= sizeof(cmd) - 1) {
483 printf("Too long IBSS_RSN command.\n");
486 return wpa_ctrl_command(ctrl, cmd);
490 static int wpa_cli_cmd_level(struct wpa_ctrl *ctrl, int argc, char *argv[])
496 printf("Invalid LEVEL command: needs one argument (debug "
500 res = os_snprintf(cmd, sizeof(cmd), "LEVEL %s", argv[0]);
501 if (res < 0 || (size_t) res >= sizeof(cmd) - 1) {
502 printf("Too long LEVEL command.\n");
505 return wpa_ctrl_command(ctrl, cmd);
509 static int wpa_cli_cmd_identity(struct wpa_ctrl *ctrl, int argc, char *argv[])
511 char cmd[256], *pos, *end;
515 printf("Invalid IDENTITY command: needs two arguments "
516 "(network id and identity)\n");
520 end = cmd + sizeof(cmd);
522 ret = os_snprintf(pos, end - pos, WPA_CTRL_RSP "IDENTITY-%s:%s",
524 if (ret < 0 || ret >= end - pos) {
525 printf("Too long IDENTITY command.\n");
529 for (i = 2; i < argc; i++) {
530 ret = os_snprintf(pos, end - pos, " %s", argv[i]);
531 if (ret < 0 || ret >= end - pos) {
532 printf("Too long IDENTITY command.\n");
538 return wpa_ctrl_command(ctrl, cmd);
542 static int wpa_cli_cmd_password(struct wpa_ctrl *ctrl, int argc, char *argv[])
544 char cmd[256], *pos, *end;
548 printf("Invalid PASSWORD command: needs two arguments "
549 "(network id and password)\n");
553 end = cmd + sizeof(cmd);
555 ret = os_snprintf(pos, end - pos, WPA_CTRL_RSP "PASSWORD-%s:%s",
557 if (ret < 0 || ret >= end - pos) {
558 printf("Too long PASSWORD command.\n");
562 for (i = 2; i < argc; i++) {
563 ret = os_snprintf(pos, end - pos, " %s", argv[i]);
564 if (ret < 0 || ret >= end - pos) {
565 printf("Too long PASSWORD command.\n");
571 return wpa_ctrl_command(ctrl, cmd);
575 static int wpa_cli_cmd_new_password(struct wpa_ctrl *ctrl, int argc,
578 char cmd[256], *pos, *end;
582 printf("Invalid NEW_PASSWORD command: needs two arguments "
583 "(network id and password)\n");
587 end = cmd + sizeof(cmd);
589 ret = os_snprintf(pos, end - pos, WPA_CTRL_RSP "NEW_PASSWORD-%s:%s",
591 if (ret < 0 || ret >= end - pos) {
592 printf("Too long NEW_PASSWORD command.\n");
596 for (i = 2; i < argc; i++) {
597 ret = os_snprintf(pos, end - pos, " %s", argv[i]);
598 if (ret < 0 || ret >= end - pos) {
599 printf("Too long NEW_PASSWORD command.\n");
605 return wpa_ctrl_command(ctrl, cmd);
609 static int wpa_cli_cmd_pin(struct wpa_ctrl *ctrl, int argc, char *argv[])
611 char cmd[256], *pos, *end;
615 printf("Invalid PIN command: needs two arguments "
616 "(network id and pin)\n");
620 end = cmd + sizeof(cmd);
622 ret = os_snprintf(pos, end - pos, WPA_CTRL_RSP "PIN-%s:%s",
624 if (ret < 0 || ret >= end - pos) {
625 printf("Too long PIN command.\n");
629 for (i = 2; i < argc; i++) {
630 ret = os_snprintf(pos, end - pos, " %s", argv[i]);
631 if (ret < 0 || ret >= end - pos) {
632 printf("Too long PIN command.\n");
637 return wpa_ctrl_command(ctrl, cmd);
641 static int wpa_cli_cmd_otp(struct wpa_ctrl *ctrl, int argc, char *argv[])
643 char cmd[256], *pos, *end;
647 printf("Invalid OTP command: needs two arguments (network "
648 "id and password)\n");
652 end = cmd + sizeof(cmd);
654 ret = os_snprintf(pos, end - pos, WPA_CTRL_RSP "OTP-%s:%s",
656 if (ret < 0 || ret >= end - pos) {
657 printf("Too long OTP command.\n");
661 for (i = 2; i < argc; i++) {
662 ret = os_snprintf(pos, end - pos, " %s", argv[i]);
663 if (ret < 0 || ret >= end - pos) {
664 printf("Too long OTP command.\n");
670 return wpa_ctrl_command(ctrl, cmd);
674 static int wpa_cli_cmd_passphrase(struct wpa_ctrl *ctrl, int argc,
677 char cmd[256], *pos, *end;
681 printf("Invalid PASSPHRASE command: needs two arguments "
682 "(network id and passphrase)\n");
686 end = cmd + sizeof(cmd);
688 ret = os_snprintf(pos, end - pos, WPA_CTRL_RSP "PASSPHRASE-%s:%s",
690 if (ret < 0 || ret >= end - pos) {
691 printf("Too long PASSPHRASE command.\n");
695 for (i = 2; i < argc; i++) {
696 ret = os_snprintf(pos, end - pos, " %s", argv[i]);
697 if (ret < 0 || ret >= end - pos) {
698 printf("Too long PASSPHRASE command.\n");
704 return wpa_ctrl_command(ctrl, cmd);
708 static int wpa_cli_cmd_bssid(struct wpa_ctrl *ctrl, int argc, char *argv[])
710 char cmd[256], *pos, *end;
714 printf("Invalid BSSID command: needs two arguments (network "
719 end = cmd + sizeof(cmd);
721 ret = os_snprintf(pos, end - pos, "BSSID");
722 if (ret < 0 || ret >= end - pos) {
723 printf("Too long BSSID command.\n");
727 for (i = 0; i < argc; i++) {
728 ret = os_snprintf(pos, end - pos, " %s", argv[i]);
729 if (ret < 0 || ret >= end - pos) {
730 printf("Too long BSSID command.\n");
736 return wpa_ctrl_command(ctrl, cmd);
740 static int wpa_cli_cmd_list_networks(struct wpa_ctrl *ctrl, int argc,
743 return wpa_ctrl_command(ctrl, "LIST_NETWORKS");
747 static int wpa_cli_cmd_select_network(struct wpa_ctrl *ctrl, int argc,
754 printf("Invalid SELECT_NETWORK command: needs one argument "
759 res = os_snprintf(cmd, sizeof(cmd), "SELECT_NETWORK %s", argv[0]);
760 if (res < 0 || (size_t) res >= sizeof(cmd))
762 cmd[sizeof(cmd) - 1] = '\0';
764 return wpa_ctrl_command(ctrl, cmd);
768 static int wpa_cli_cmd_enable_network(struct wpa_ctrl *ctrl, int argc,
775 printf("Invalid ENABLE_NETWORK command: needs one argument "
780 res = os_snprintf(cmd, sizeof(cmd), "ENABLE_NETWORK %s", argv[0]);
781 if (res < 0 || (size_t) res >= sizeof(cmd))
783 cmd[sizeof(cmd) - 1] = '\0';
785 return wpa_ctrl_command(ctrl, cmd);
789 static int wpa_cli_cmd_disable_network(struct wpa_ctrl *ctrl, int argc,
796 printf("Invalid DISABLE_NETWORK command: needs one argument "
801 res = os_snprintf(cmd, sizeof(cmd), "DISABLE_NETWORK %s", argv[0]);
802 if (res < 0 || (size_t) res >= sizeof(cmd))
804 cmd[sizeof(cmd) - 1] = '\0';
806 return wpa_ctrl_command(ctrl, cmd);
810 static int wpa_cli_cmd_add_network(struct wpa_ctrl *ctrl, int argc,
813 return wpa_ctrl_command(ctrl, "ADD_NETWORK");
817 static int wpa_cli_cmd_remove_network(struct wpa_ctrl *ctrl, int argc,
824 printf("Invalid REMOVE_NETWORK command: needs one argument "
829 res = os_snprintf(cmd, sizeof(cmd), "REMOVE_NETWORK %s", argv[0]);
830 if (res < 0 || (size_t) res >= sizeof(cmd))
832 cmd[sizeof(cmd) - 1] = '\0';
834 return wpa_ctrl_command(ctrl, cmd);
838 static void wpa_cli_show_network_variables(void)
840 printf("set_network variables:\n"
841 " ssid (network name, SSID)\n"
842 " psk (WPA passphrase or pre-shared key)\n"
843 " key_mgmt (key management protocol)\n"
844 " identity (EAP identity)\n"
845 " password (EAP password)\n"
848 "Note: Values are entered in the same format as the "
849 "configuration file is using,\n"
850 "i.e., strings values need to be inside double quotation "
852 "For example: set_network 1 ssid \"network name\"\n"
854 "Please see wpa_supplicant.conf documentation for full list "
855 "of\navailable variables.\n");
859 static int wpa_cli_cmd_set_network(struct wpa_ctrl *ctrl, int argc,
866 wpa_cli_show_network_variables();
871 printf("Invalid SET_NETWORK command: needs three arguments\n"
872 "(network id, variable name, and value)\n");
876 res = os_snprintf(cmd, sizeof(cmd), "SET_NETWORK %s %s %s",
877 argv[0], argv[1], argv[2]);
878 if (res < 0 || (size_t) res >= sizeof(cmd) - 1) {
879 printf("Too long SET_NETWORK command.\n");
882 return wpa_ctrl_command(ctrl, cmd);
886 static int wpa_cli_cmd_get_network(struct wpa_ctrl *ctrl, int argc,
893 wpa_cli_show_network_variables();
898 printf("Invalid GET_NETWORK command: needs two arguments\n"
899 "(network id and variable name)\n");
903 res = os_snprintf(cmd, sizeof(cmd), "GET_NETWORK %s %s",
905 if (res < 0 || (size_t) res >= sizeof(cmd) - 1) {
906 printf("Too long GET_NETWORK command.\n");
909 return wpa_ctrl_command(ctrl, cmd);
913 static int wpa_cli_cmd_disconnect(struct wpa_ctrl *ctrl, int argc,
916 return wpa_ctrl_command(ctrl, "DISCONNECT");
920 static int wpa_cli_cmd_reconnect(struct wpa_ctrl *ctrl, int argc,
923 return wpa_ctrl_command(ctrl, "RECONNECT");
927 static int wpa_cli_cmd_save_config(struct wpa_ctrl *ctrl, int argc,
930 return wpa_ctrl_command(ctrl, "SAVE_CONFIG");
934 static int wpa_cli_cmd_scan(struct wpa_ctrl *ctrl, int argc, char *argv[])
936 return wpa_ctrl_command(ctrl, "SCAN");
940 static int wpa_cli_cmd_scan_results(struct wpa_ctrl *ctrl, int argc,
943 return wpa_ctrl_command(ctrl, "SCAN_RESULTS");
947 static int wpa_cli_cmd_bss(struct wpa_ctrl *ctrl, int argc, char *argv[])
953 printf("Invalid BSS command: need one argument (index or "
958 res = os_snprintf(cmd, sizeof(cmd), "BSS %s", argv[0]);
959 if (res < 0 || (size_t) res >= sizeof(cmd))
961 cmd[sizeof(cmd) - 1] = '\0';
963 return wpa_ctrl_command(ctrl, cmd);
967 static int wpa_cli_cmd_get_capability(struct wpa_ctrl *ctrl, int argc,
973 if (argc < 1 || argc > 2) {
974 printf("Invalid GET_CAPABILITY command: need either one or "
979 if ((argc == 2) && os_strcmp(argv[1], "strict") != 0) {
980 printf("Invalid GET_CAPABILITY command: second argument, "
981 "if any, must be 'strict'\n");
985 res = os_snprintf(cmd, sizeof(cmd), "GET_CAPABILITY %s%s", argv[0],
986 (argc == 2) ? " strict" : "");
987 if (res < 0 || (size_t) res >= sizeof(cmd))
989 cmd[sizeof(cmd) - 1] = '\0';
991 return wpa_ctrl_command(ctrl, cmd);
995 static int wpa_cli_list_interfaces(struct wpa_ctrl *ctrl)
997 printf("Available interfaces:\n");
998 return wpa_ctrl_command(ctrl, "INTERFACES");
1002 static int wpa_cli_cmd_interface(struct wpa_ctrl *ctrl, int argc, char *argv[])
1005 wpa_cli_list_interfaces(ctrl);
1009 wpa_cli_close_connection();
1010 os_free(ctrl_ifname);
1011 ctrl_ifname = os_strdup(argv[0]);
1013 if (wpa_cli_open_connection(ctrl_ifname)) {
1014 printf("Connected to interface '%s.\n", ctrl_ifname);
1015 if (wpa_ctrl_attach(ctrl_conn) == 0) {
1016 wpa_cli_attached = 1;
1018 printf("Warning: Failed to attach to "
1019 "wpa_supplicant.\n");
1022 printf("Could not connect to interface '%s' - re-trying\n",
1029 static int wpa_cli_cmd_reconfigure(struct wpa_ctrl *ctrl, int argc,
1032 return wpa_ctrl_command(ctrl, "RECONFIGURE");
1036 static int wpa_cli_cmd_terminate(struct wpa_ctrl *ctrl, int argc,
1039 return wpa_ctrl_command(ctrl, "TERMINATE");
1043 static int wpa_cli_cmd_interface_add(struct wpa_ctrl *ctrl, int argc,
1050 printf("Invalid INTERFACE_ADD command: needs at least one "
1051 "argument (interface name)\n"
1052 "All arguments: ifname confname driver ctrl_interface "
1053 "driver_param bridge_name\n");
1058 * INTERFACE_ADD <ifname>TAB<confname>TAB<driver>TAB<ctrl_interface>TAB
1059 * <driver_param>TAB<bridge_name>
1061 res = os_snprintf(cmd, sizeof(cmd),
1062 "INTERFACE_ADD %s\t%s\t%s\t%s\t%s\t%s",
1064 argc > 1 ? argv[1] : "", argc > 2 ? argv[2] : "",
1065 argc > 3 ? argv[3] : "", argc > 4 ? argv[4] : "",
1066 argc > 5 ? argv[5] : "");
1067 if (res < 0 || (size_t) res >= sizeof(cmd))
1069 cmd[sizeof(cmd) - 1] = '\0';
1070 return wpa_ctrl_command(ctrl, cmd);
1074 static int wpa_cli_cmd_interface_remove(struct wpa_ctrl *ctrl, int argc,
1081 printf("Invalid INTERFACE_REMOVE command: needs one argument "
1082 "(interface name)\n");
1086 res = os_snprintf(cmd, sizeof(cmd), "INTERFACE_REMOVE %s", argv[0]);
1087 if (res < 0 || (size_t) res >= sizeof(cmd))
1089 cmd[sizeof(cmd) - 1] = '\0';
1090 return wpa_ctrl_command(ctrl, cmd);
1094 static int wpa_cli_cmd_interface_list(struct wpa_ctrl *ctrl, int argc,
1097 return wpa_ctrl_command(ctrl, "INTERFACE_LIST");
1101 enum wpa_cli_cmd_flags {
1102 cli_cmd_flag_none = 0x00,
1103 cli_cmd_flag_sensitive = 0x01
1106 struct wpa_cli_cmd {
1108 int (*handler)(struct wpa_ctrl *ctrl, int argc, char *argv[]);
1109 enum wpa_cli_cmd_flags flags;
1113 static struct wpa_cli_cmd wpa_cli_commands[] = {
1114 { "status", wpa_cli_cmd_status,
1116 "[verbose] = get current WPA/EAPOL/EAP status" },
1117 { "ping", wpa_cli_cmd_ping,
1119 "= pings wpa_supplicant" },
1120 { "mib", wpa_cli_cmd_mib,
1122 "= get MIB variables (dot1x, dot11)" },
1123 { "help", wpa_cli_cmd_help,
1125 "= show this usage help" },
1126 { "interface", wpa_cli_cmd_interface,
1128 "[ifname] = show interfaces/select interface" },
1129 { "level", wpa_cli_cmd_level,
1131 "<debug level> = change debug level" },
1132 { "license", wpa_cli_cmd_license,
1134 "= show full wpa_cli license" },
1135 { "quit", wpa_cli_cmd_quit,
1138 { "set", wpa_cli_cmd_set,
1140 "= set variables (shows list of variables when run without "
1142 { "logon", wpa_cli_cmd_logon,
1144 "= IEEE 802.1X EAPOL state machine logon" },
1145 { "logoff", wpa_cli_cmd_logoff,
1147 "= IEEE 802.1X EAPOL state machine logoff" },
1148 { "pmksa", wpa_cli_cmd_pmksa,
1150 "= show PMKSA cache" },
1151 { "reassociate", wpa_cli_cmd_reassociate,
1153 "= force reassociation" },
1154 { "preauthenticate", wpa_cli_cmd_preauthenticate,
1156 "<BSSID> = force preauthentication" },
1157 { "identity", wpa_cli_cmd_identity,
1159 "<network id> <identity> = configure identity for an SSID" },
1160 { "password", wpa_cli_cmd_password,
1161 cli_cmd_flag_sensitive,
1162 "<network id> <password> = configure password for an SSID" },
1163 { "new_password", wpa_cli_cmd_new_password,
1164 cli_cmd_flag_sensitive,
1165 "<network id> <password> = change password for an SSID" },
1166 { "pin", wpa_cli_cmd_pin,
1167 cli_cmd_flag_sensitive,
1168 "<network id> <pin> = configure pin for an SSID" },
1169 { "otp", wpa_cli_cmd_otp,
1170 cli_cmd_flag_sensitive,
1171 "<network id> <password> = configure one-time-password for an SSID"
1173 { "passphrase", wpa_cli_cmd_passphrase,
1174 cli_cmd_flag_sensitive,
1175 "<network id> <passphrase> = configure private key passphrase\n"
1177 { "bssid", wpa_cli_cmd_bssid,
1179 "<network id> <BSSID> = set preferred BSSID for an SSID" },
1180 { "list_networks", wpa_cli_cmd_list_networks,
1182 "= list configured networks" },
1183 { "select_network", wpa_cli_cmd_select_network,
1185 "<network id> = select a network (disable others)" },
1186 { "enable_network", wpa_cli_cmd_enable_network,
1188 "<network id> = enable a network" },
1189 { "disable_network", wpa_cli_cmd_disable_network,
1191 "<network id> = disable a network" },
1192 { "add_network", wpa_cli_cmd_add_network,
1194 "= add a network" },
1195 { "remove_network", wpa_cli_cmd_remove_network,
1197 "<network id> = remove a network" },
1198 { "set_network", wpa_cli_cmd_set_network,
1199 cli_cmd_flag_sensitive,
1200 "<network id> <variable> <value> = set network variables (shows\n"
1201 " list of variables when run without arguments)" },
1202 { "get_network", wpa_cli_cmd_get_network,
1204 "<network id> <variable> = get network variables" },
1205 { "save_config", wpa_cli_cmd_save_config,
1207 "= save the current configuration" },
1208 { "disconnect", wpa_cli_cmd_disconnect,
1210 "= disconnect and wait for reassociate/reconnect command before\n"
1212 { "reconnect", wpa_cli_cmd_reconnect,
1214 "= like reassociate, but only takes effect if already disconnected"
1216 { "scan", wpa_cli_cmd_scan,
1218 "= request new BSS scan" },
1219 { "scan_results", wpa_cli_cmd_scan_results,
1221 "= get latest scan results" },
1222 { "bss", wpa_cli_cmd_bss,
1224 "<<idx> | <bssid>> = get detailed scan result info" },
1225 { "get_capability", wpa_cli_cmd_get_capability,
1227 "<eap/pairwise/group/key_mgmt/proto/auth_alg> = get capabilies" },
1228 { "reconfigure", wpa_cli_cmd_reconfigure,
1230 "= force wpa_supplicant to re-read its configuration file" },
1231 { "terminate", wpa_cli_cmd_terminate,
1233 "= terminate wpa_supplicant" },
1234 { "interface_add", wpa_cli_cmd_interface_add,
1236 "<ifname> <confname> <driver> <ctrl_interface> <driver_param>\n"
1237 " <bridge_name> = adds new interface, all parameters but <ifname>\n"
1239 { "interface_remove", wpa_cli_cmd_interface_remove,
1241 "<ifname> = removes the interface" },
1242 { "interface_list", wpa_cli_cmd_interface_list,
1244 "= list available interfaces" },
1245 { "ap_scan", wpa_cli_cmd_ap_scan,
1247 "<value> = set ap_scan parameter" },
1248 { "stkstart", wpa_cli_cmd_stkstart,
1250 "<addr> = request STK negotiation with <addr>" },
1251 { "ft_ds", wpa_cli_cmd_ft_ds,
1253 "<addr> = request over-the-DS FT with <addr>" },
1254 { "wps_pbc", wpa_cli_cmd_wps_pbc,
1256 "[BSSID] = start Wi-Fi Protected Setup: Push Button Configuration" },
1257 { "wps_pin", wpa_cli_cmd_wps_pin,
1258 cli_cmd_flag_sensitive,
1259 "<BSSID> [PIN] = start WPS PIN method (returns PIN, if not "
1261 { "wps_reg", wpa_cli_cmd_wps_reg,
1262 cli_cmd_flag_sensitive,
1263 "<BSSID> <AP PIN> = start WPS Registrar to configure an AP" },
1264 { "ibss_rsn", wpa_cli_cmd_ibss_rsn,
1266 "<addr> = request RSN authentication with <addr> in IBSS" },
1267 { NULL, NULL, cli_cmd_flag_none, NULL }
1272 * Prints command usage, lines are padded with the specified string.
1274 static void print_cmd_help(struct wpa_cli_cmd *cmd, const char *pad)
1279 printf("%s%s ", pad, cmd->cmd);
1280 for (n = 0; (c = cmd->usage[n]); n++) {
1289 static void print_help(void)
1292 printf("commands:\n");
1293 for (n = 0; wpa_cli_commands[n].cmd; n++)
1294 print_cmd_help(&wpa_cli_commands[n], " ");
1298 #ifdef CONFIG_READLINE
1299 static int cmd_has_sensitive_data(const char *cmd)
1301 const char *c, *delim;
1305 delim = os_strchr(cmd, ' ');
1309 len = os_strlen(cmd);
1311 for (n = 0; (c = wpa_cli_commands[n].cmd); n++) {
1312 if (os_strncasecmp(cmd, c, len) == 0 && len == os_strlen(c))
1313 return (wpa_cli_commands[n].flags &
1314 cli_cmd_flag_sensitive);
1318 #endif /* CONFIG_READLINE */
1321 static int wpa_request(struct wpa_ctrl *ctrl, int argc, char *argv[])
1323 struct wpa_cli_cmd *cmd, *match = NULL;
1328 cmd = wpa_cli_commands;
1330 if (os_strncasecmp(cmd->cmd, argv[0], os_strlen(argv[0])) == 0)
1333 if (os_strcasecmp(cmd->cmd, argv[0]) == 0) {
1334 /* we have an exact match */
1344 printf("Ambiguous command '%s'; possible commands:", argv[0]);
1345 cmd = wpa_cli_commands;
1347 if (os_strncasecmp(cmd->cmd, argv[0],
1348 os_strlen(argv[0])) == 0) {
1349 printf(" %s", cmd->cmd);
1355 } else if (count == 0) {
1356 printf("Unknown command '%s'\n", argv[0]);
1359 ret = match->handler(ctrl, argc - 1, &argv[1]);
1366 static int str_match(const char *a, const char *b)
1368 return os_strncmp(a, b, os_strlen(b)) == 0;
1372 static int wpa_cli_exec(const char *program, const char *arg1,
1380 len = os_strlen(program) + os_strlen(arg1) + os_strlen(arg2) + 3;
1381 cmd = os_malloc(len);
1384 res = os_snprintf(cmd, len, "%s %s %s", program, arg1, arg2);
1385 if (res < 0 || (size_t) res >= len) {
1389 cmd[len - 1] = '\0';
1391 if (system(cmd) < 0)
1393 #endif /* _WIN32_WCE */
1400 static void wpa_cli_action_process(const char *msg)
1403 char *copy = NULL, *id, *pos2;
1408 pos = os_strchr(pos, '>');
1415 if (str_match(pos, WPA_EVENT_CONNECTED)) {
1417 os_unsetenv("WPA_ID");
1418 os_unsetenv("WPA_ID_STR");
1419 os_unsetenv("WPA_CTRL_DIR");
1421 pos = os_strstr(pos, "[id=");
1423 copy = os_strdup(pos + 4);
1427 while (*pos2 && *pos2 != ' ')
1431 os_setenv("WPA_ID", id, 1);
1432 while (*pos2 && *pos2 != '=')
1437 while (*pos2 && *pos2 != ']')
1440 os_setenv("WPA_ID_STR", id, 1);
1444 os_setenv("WPA_CTRL_DIR", ctrl_iface_dir, 1);
1446 if (!wpa_cli_connected || new_id != wpa_cli_last_id) {
1447 wpa_cli_connected = 1;
1448 wpa_cli_last_id = new_id;
1449 wpa_cli_exec(action_file, ctrl_ifname, "CONNECTED");
1451 } else if (str_match(pos, WPA_EVENT_DISCONNECTED)) {
1452 if (wpa_cli_connected) {
1453 wpa_cli_connected = 0;
1454 wpa_cli_exec(action_file, ctrl_ifname, "DISCONNECTED");
1456 } else if (str_match(pos, WPA_EVENT_TERMINATING)) {
1457 printf("wpa_supplicant is terminating - stop monitoring\n");
1463 #ifndef CONFIG_ANSI_C_EXTRA
1464 static void wpa_cli_action_cb(char *msg, size_t len)
1466 wpa_cli_action_process(msg);
1468 #endif /* CONFIG_ANSI_C_EXTRA */
1471 static void wpa_cli_reconnect(void)
1473 wpa_cli_close_connection();
1474 ctrl_conn = wpa_cli_open_connection(ctrl_ifname);
1476 printf("Connection to wpa_supplicant re-established\n");
1477 if (wpa_ctrl_attach(ctrl_conn) == 0) {
1478 wpa_cli_attached = 1;
1480 printf("Warning: Failed to attach to "
1481 "wpa_supplicant.\n");
1487 static void wpa_cli_recv_pending(struct wpa_ctrl *ctrl, int in_read,
1491 if (ctrl_conn == NULL) {
1492 wpa_cli_reconnect();
1495 while (wpa_ctrl_pending(ctrl) > 0) {
1497 size_t len = sizeof(buf) - 1;
1498 if (wpa_ctrl_recv(ctrl, buf, &len) == 0) {
1501 wpa_cli_action_process(buf);
1503 if (in_read && first)
1506 printf("%s\n", buf);
1509 printf("Could not read pending message.\n");
1514 if (wpa_ctrl_pending(ctrl) < 0) {
1515 printf("Connection to wpa_supplicant lost - trying to "
1517 wpa_cli_reconnect();
1522 #ifdef CONFIG_READLINE
1523 static char * wpa_cli_cmd_gen(const char *text, int state)
1530 len = os_strlen(text);
1533 while ((cmd = wpa_cli_commands[i].cmd)) {
1535 if (os_strncasecmp(cmd, text, len) == 0)
1536 return os_strdup(cmd);
1543 static char * wpa_cli_dummy_gen(const char *text, int state)
1549 static char ** wpa_cli_completion(const char *text, int start, int end)
1551 return rl_completion_matches(text, start == 0 ?
1552 wpa_cli_cmd_gen : wpa_cli_dummy_gen);
1554 #endif /* CONFIG_READLINE */
1557 static void wpa_cli_interactive(void)
1560 char cmdbuf[256], *cmd, *argv[max_args], *pos;
1562 #ifdef CONFIG_READLINE
1563 char *home, *hfile = NULL;
1564 #endif /* CONFIG_READLINE */
1566 printf("\nInteractive mode\n\n");
1568 #ifdef CONFIG_READLINE
1569 rl_attempted_completion_function = wpa_cli_completion;
1570 home = getenv("HOME");
1572 const char *fname = ".wpa_cli_history";
1573 int hfile_len = os_strlen(home) + 1 + os_strlen(fname) + 1;
1574 hfile = os_malloc(hfile_len);
1577 res = os_snprintf(hfile, hfile_len, "%s/%s", home,
1579 if (res >= 0 && res < hfile_len) {
1580 hfile[hfile_len - 1] = '\0';
1581 read_history(hfile);
1582 stifle_history(100);
1586 #endif /* CONFIG_READLINE */
1589 wpa_cli_recv_pending(ctrl_conn, 0, 0);
1590 #ifndef CONFIG_NATIVE_WINDOWS
1591 alarm(ping_interval);
1592 #endif /* CONFIG_NATIVE_WINDOWS */
1593 #ifdef CONFIG_READLINE
1594 cmd = readline("> ");
1597 while (next_history())
1599 h = previous_history();
1600 if (h == NULL || os_strcmp(cmd, h->line) != 0)
1604 #else /* CONFIG_READLINE */
1606 cmd = fgets(cmdbuf, sizeof(cmdbuf), stdin);
1607 #endif /* CONFIG_READLINE */
1608 #ifndef CONFIG_NATIVE_WINDOWS
1610 #endif /* CONFIG_NATIVE_WINDOWS */
1613 wpa_cli_recv_pending(ctrl_conn, 0, 0);
1615 while (*pos != '\0') {
1631 if (argc == max_args)
1634 char *pos2 = os_strrchr(pos, '"');
1638 while (*pos != '\0' && *pos != ' ')
1644 wpa_request(ctrl_conn, argc, argv);
1648 } while (!wpa_cli_quit);
1650 #ifdef CONFIG_READLINE
1652 /* Save command history, excluding lines that may contain
1656 while ((h = current_history())) {
1658 while (*p == ' ' || *p == '\t')
1660 if (cmd_has_sensitive_data(p)) {
1661 h = remove_history(where_history());
1671 write_history(hfile);
1674 #endif /* CONFIG_READLINE */
1678 static void wpa_cli_action(struct wpa_ctrl *ctrl)
1680 #ifdef CONFIG_ANSI_C_EXTRA
1681 /* TODO: ANSI C version(?) */
1682 printf("Action processing not supported in ANSI C build.\n");
1683 #else /* CONFIG_ANSI_C_EXTRA */
1687 char buf[256]; /* note: large enough to fit in unsolicited messages */
1690 fd = wpa_ctrl_get_fd(ctrl);
1692 while (!wpa_cli_quit) {
1695 tv.tv_sec = ping_interval;
1697 res = select(fd + 1, &rfds, NULL, NULL, &tv);
1698 if (res < 0 && errno != EINTR) {
1703 if (FD_ISSET(fd, &rfds))
1704 wpa_cli_recv_pending(ctrl, 0, 1);
1706 /* verify that connection is still working */
1707 len = sizeof(buf) - 1;
1708 if (wpa_ctrl_request(ctrl, "PING", 4, buf, &len,
1709 wpa_cli_action_cb) < 0 ||
1710 len < 4 || os_memcmp(buf, "PONG", 4) != 0) {
1711 printf("wpa_supplicant did not reply to PING "
1712 "command - exiting\n");
1717 #endif /* CONFIG_ANSI_C_EXTRA */
1721 static void wpa_cli_cleanup(void)
1723 wpa_cli_close_connection();
1725 os_daemonize_terminate(pid_file);
1727 os_program_deinit();
1730 static void wpa_cli_terminate(int sig)
1737 #ifndef CONFIG_NATIVE_WINDOWS
1738 static void wpa_cli_alarm(int sig)
1740 if (ctrl_conn && _wpa_ctrl_command(ctrl_conn, "PING", 0)) {
1741 printf("Connection to wpa_supplicant lost - trying to "
1743 wpa_cli_close_connection();
1746 wpa_cli_reconnect();
1748 wpa_cli_recv_pending(ctrl_conn, 1, 0);
1749 alarm(ping_interval);
1751 #endif /* CONFIG_NATIVE_WINDOWS */
1754 static char * wpa_cli_get_default_ifname(void)
1756 char *ifname = NULL;
1758 #ifdef CONFIG_CTRL_IFACE_UNIX
1759 struct dirent *dent;
1760 DIR *dir = opendir(ctrl_iface_dir);
1763 while ((dent = readdir(dir))) {
1764 #ifdef _DIRENT_HAVE_D_TYPE
1766 * Skip the file if it is not a socket. Also accept
1767 * DT_UNKNOWN (0) in case the C library or underlying
1768 * file system does not support d_type.
1770 if (dent->d_type != DT_SOCK && dent->d_type != DT_UNKNOWN)
1772 #endif /* _DIRENT_HAVE_D_TYPE */
1773 if (os_strcmp(dent->d_name, ".") == 0 ||
1774 os_strcmp(dent->d_name, "..") == 0)
1776 printf("Selected interface '%s'\n", dent->d_name);
1777 ifname = os_strdup(dent->d_name);
1781 #endif /* CONFIG_CTRL_IFACE_UNIX */
1783 #ifdef CONFIG_CTRL_IFACE_NAMED_PIPE
1784 char buf[2048], *pos;
1786 struct wpa_ctrl *ctrl;
1789 ctrl = wpa_ctrl_open(NULL);
1793 len = sizeof(buf) - 1;
1794 ret = wpa_ctrl_request(ctrl, "INTERFACES", 10, buf, &len, NULL);
1797 pos = os_strchr(buf, '\n');
1800 ifname = os_strdup(buf);
1802 wpa_ctrl_close(ctrl);
1803 #endif /* CONFIG_CTRL_IFACE_NAMED_PIPE */
1809 int main(int argc, char *argv[])
1812 int warning_displayed = 0;
1816 const char *global = NULL;
1818 if (os_program_init())
1822 c = getopt(argc, argv, "a:Bg:G:hi:p:P:v");
1827 action_file = optarg;
1836 ping_interval = atoi(optarg);
1842 printf("%s\n", wpa_cli_version);
1845 os_free(ctrl_ifname);
1846 ctrl_ifname = os_strdup(optarg);
1849 ctrl_iface_dir = optarg;
1860 interactive = (argc == optind) && (action_file == NULL);
1863 printf("%s\n\n%s\n\n", wpa_cli_version, wpa_cli_license);
1866 #ifdef CONFIG_CTRL_IFACE_NAMED_PIPE
1867 ctrl_conn = wpa_ctrl_open(NULL);
1868 #else /* CONFIG_CTRL_IFACE_NAMED_PIPE */
1869 ctrl_conn = wpa_ctrl_open(global);
1870 #endif /* CONFIG_CTRL_IFACE_NAMED_PIPE */
1871 if (ctrl_conn == NULL) {
1872 perror("Failed to connect to wpa_supplicant - "
1879 if (ctrl_ifname == NULL)
1880 ctrl_ifname = wpa_cli_get_default_ifname();
1881 ctrl_conn = wpa_cli_open_connection(ctrl_ifname);
1883 if (warning_displayed)
1884 printf("Connection established.\n");
1889 perror("Failed to connect to wpa_supplicant - "
1894 if (!warning_displayed) {
1895 printf("Could not connect to wpa_supplicant - "
1897 warning_displayed = 1;
1904 signal(SIGINT, wpa_cli_terminate);
1905 signal(SIGTERM, wpa_cli_terminate);
1906 #endif /* _WIN32_WCE */
1907 #ifndef CONFIG_NATIVE_WINDOWS
1908 signal(SIGALRM, wpa_cli_alarm);
1909 #endif /* CONFIG_NATIVE_WINDOWS */
1911 if (interactive || action_file) {
1912 if (wpa_ctrl_attach(ctrl_conn) == 0) {
1913 wpa_cli_attached = 1;
1915 printf("Warning: Failed to attach to "
1916 "wpa_supplicant.\n");
1922 if (daemonize && os_daemonize(pid_file))
1926 wpa_cli_interactive();
1927 else if (action_file)
1928 wpa_cli_action(ctrl_conn);
1930 ret = wpa_request(ctrl_conn, argc - optind, &argv[optind]);
1932 os_free(ctrl_ifname);
1938 #else /* CONFIG_CTRL_IFACE */
1939 int main(int argc, char *argv[])
1941 printf("CONFIG_CTRL_IFACE not defined - wpa_cli disabled\n");
1944 #endif /* CONFIG_CTRL_IFACE */