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_oob(struct wpa_ctrl *ctrl, int argc, char *argv[])
455 printf("Invalid WPS_OOB command: need three arguments:\n"
456 "- OOB_DEV_TYPE: use 'ufd'\n"
457 "- OOB_PATH: path of OOB device like '/mnt'\n"
458 "- OOB_METHOD: OOB method 'pin-e' or 'pin-r', "
463 res = os_snprintf(cmd, sizeof(cmd), "WPS_OOB %s %s %s",
464 argv[0], argv[1], argv[2]);
465 if (res < 0 || (size_t) res >= sizeof(cmd) - 1) {
466 printf("Too long WPS_OOB command.\n");
469 return wpa_ctrl_command(ctrl, cmd);
473 static int wpa_cli_cmd_wps_reg(struct wpa_ctrl *ctrl, int argc, char *argv[])
479 printf("Invalid WPS_REG command: need two arguments:\n"
480 "- BSSID: use 'any' to select any\n"
485 res = os_snprintf(cmd, sizeof(cmd), "WPS_REG %s %s", argv[0], argv[1]);
486 if (res < 0 || (size_t) res >= sizeof(cmd) - 1) {
487 printf("Too long WPS_REG command.\n");
490 return wpa_ctrl_command(ctrl, cmd);
494 static int wpa_cli_cmd_ibss_rsn(struct wpa_ctrl *ctrl, int argc, char *argv[])
500 printf("Invalid IBSS_RSN command: needs one argument "
501 "(Peer STA MAC address)\n");
505 res = os_snprintf(cmd, sizeof(cmd), "IBSS_RSN %s", argv[0]);
506 if (res < 0 || (size_t) res >= sizeof(cmd) - 1) {
507 printf("Too long IBSS_RSN command.\n");
510 return wpa_ctrl_command(ctrl, cmd);
514 static int wpa_cli_cmd_level(struct wpa_ctrl *ctrl, int argc, char *argv[])
520 printf("Invalid LEVEL command: needs one argument (debug "
524 res = os_snprintf(cmd, sizeof(cmd), "LEVEL %s", argv[0]);
525 if (res < 0 || (size_t) res >= sizeof(cmd) - 1) {
526 printf("Too long LEVEL command.\n");
529 return wpa_ctrl_command(ctrl, cmd);
533 static int wpa_cli_cmd_identity(struct wpa_ctrl *ctrl, int argc, char *argv[])
535 char cmd[256], *pos, *end;
539 printf("Invalid IDENTITY command: needs two arguments "
540 "(network id and identity)\n");
544 end = cmd + sizeof(cmd);
546 ret = os_snprintf(pos, end - pos, WPA_CTRL_RSP "IDENTITY-%s:%s",
548 if (ret < 0 || ret >= end - pos) {
549 printf("Too long IDENTITY command.\n");
553 for (i = 2; i < argc; i++) {
554 ret = os_snprintf(pos, end - pos, " %s", argv[i]);
555 if (ret < 0 || ret >= end - pos) {
556 printf("Too long IDENTITY command.\n");
562 return wpa_ctrl_command(ctrl, cmd);
566 static int wpa_cli_cmd_password(struct wpa_ctrl *ctrl, int argc, char *argv[])
568 char cmd[256], *pos, *end;
572 printf("Invalid PASSWORD command: needs two arguments "
573 "(network id and password)\n");
577 end = cmd + sizeof(cmd);
579 ret = os_snprintf(pos, end - pos, WPA_CTRL_RSP "PASSWORD-%s:%s",
581 if (ret < 0 || ret >= end - pos) {
582 printf("Too long PASSWORD command.\n");
586 for (i = 2; i < argc; i++) {
587 ret = os_snprintf(pos, end - pos, " %s", argv[i]);
588 if (ret < 0 || ret >= end - pos) {
589 printf("Too long PASSWORD command.\n");
595 return wpa_ctrl_command(ctrl, cmd);
599 static int wpa_cli_cmd_new_password(struct wpa_ctrl *ctrl, int argc,
602 char cmd[256], *pos, *end;
606 printf("Invalid NEW_PASSWORD command: needs two arguments "
607 "(network id and password)\n");
611 end = cmd + sizeof(cmd);
613 ret = os_snprintf(pos, end - pos, WPA_CTRL_RSP "NEW_PASSWORD-%s:%s",
615 if (ret < 0 || ret >= end - pos) {
616 printf("Too long NEW_PASSWORD command.\n");
620 for (i = 2; i < argc; i++) {
621 ret = os_snprintf(pos, end - pos, " %s", argv[i]);
622 if (ret < 0 || ret >= end - pos) {
623 printf("Too long NEW_PASSWORD command.\n");
629 return wpa_ctrl_command(ctrl, cmd);
633 static int wpa_cli_cmd_pin(struct wpa_ctrl *ctrl, int argc, char *argv[])
635 char cmd[256], *pos, *end;
639 printf("Invalid PIN command: needs two arguments "
640 "(network id and pin)\n");
644 end = cmd + sizeof(cmd);
646 ret = os_snprintf(pos, end - pos, WPA_CTRL_RSP "PIN-%s:%s",
648 if (ret < 0 || ret >= end - pos) {
649 printf("Too long PIN command.\n");
653 for (i = 2; i < argc; i++) {
654 ret = os_snprintf(pos, end - pos, " %s", argv[i]);
655 if (ret < 0 || ret >= end - pos) {
656 printf("Too long PIN command.\n");
661 return wpa_ctrl_command(ctrl, cmd);
665 static int wpa_cli_cmd_otp(struct wpa_ctrl *ctrl, int argc, char *argv[])
667 char cmd[256], *pos, *end;
671 printf("Invalid OTP command: needs two arguments (network "
672 "id and password)\n");
676 end = cmd + sizeof(cmd);
678 ret = os_snprintf(pos, end - pos, WPA_CTRL_RSP "OTP-%s:%s",
680 if (ret < 0 || ret >= end - pos) {
681 printf("Too long OTP command.\n");
685 for (i = 2; i < argc; i++) {
686 ret = os_snprintf(pos, end - pos, " %s", argv[i]);
687 if (ret < 0 || ret >= end - pos) {
688 printf("Too long OTP command.\n");
694 return wpa_ctrl_command(ctrl, cmd);
698 static int wpa_cli_cmd_passphrase(struct wpa_ctrl *ctrl, int argc,
701 char cmd[256], *pos, *end;
705 printf("Invalid PASSPHRASE command: needs two arguments "
706 "(network id and passphrase)\n");
710 end = cmd + sizeof(cmd);
712 ret = os_snprintf(pos, end - pos, WPA_CTRL_RSP "PASSPHRASE-%s:%s",
714 if (ret < 0 || ret >= end - pos) {
715 printf("Too long PASSPHRASE command.\n");
719 for (i = 2; i < argc; i++) {
720 ret = os_snprintf(pos, end - pos, " %s", argv[i]);
721 if (ret < 0 || ret >= end - pos) {
722 printf("Too long PASSPHRASE command.\n");
728 return wpa_ctrl_command(ctrl, cmd);
732 static int wpa_cli_cmd_bssid(struct wpa_ctrl *ctrl, int argc, char *argv[])
734 char cmd[256], *pos, *end;
738 printf("Invalid BSSID command: needs two arguments (network "
743 end = cmd + sizeof(cmd);
745 ret = os_snprintf(pos, end - pos, "BSSID");
746 if (ret < 0 || ret >= end - pos) {
747 printf("Too long BSSID command.\n");
751 for (i = 0; i < argc; i++) {
752 ret = os_snprintf(pos, end - pos, " %s", argv[i]);
753 if (ret < 0 || ret >= end - pos) {
754 printf("Too long BSSID command.\n");
760 return wpa_ctrl_command(ctrl, cmd);
764 static int wpa_cli_cmd_list_networks(struct wpa_ctrl *ctrl, int argc,
767 return wpa_ctrl_command(ctrl, "LIST_NETWORKS");
771 static int wpa_cli_cmd_select_network(struct wpa_ctrl *ctrl, int argc,
778 printf("Invalid SELECT_NETWORK command: needs one argument "
783 res = os_snprintf(cmd, sizeof(cmd), "SELECT_NETWORK %s", argv[0]);
784 if (res < 0 || (size_t) res >= sizeof(cmd))
786 cmd[sizeof(cmd) - 1] = '\0';
788 return wpa_ctrl_command(ctrl, cmd);
792 static int wpa_cli_cmd_enable_network(struct wpa_ctrl *ctrl, int argc,
799 printf("Invalid ENABLE_NETWORK command: needs one argument "
804 res = os_snprintf(cmd, sizeof(cmd), "ENABLE_NETWORK %s", argv[0]);
805 if (res < 0 || (size_t) res >= sizeof(cmd))
807 cmd[sizeof(cmd) - 1] = '\0';
809 return wpa_ctrl_command(ctrl, cmd);
813 static int wpa_cli_cmd_disable_network(struct wpa_ctrl *ctrl, int argc,
820 printf("Invalid DISABLE_NETWORK command: needs one argument "
825 res = os_snprintf(cmd, sizeof(cmd), "DISABLE_NETWORK %s", argv[0]);
826 if (res < 0 || (size_t) res >= sizeof(cmd))
828 cmd[sizeof(cmd) - 1] = '\0';
830 return wpa_ctrl_command(ctrl, cmd);
834 static int wpa_cli_cmd_add_network(struct wpa_ctrl *ctrl, int argc,
837 return wpa_ctrl_command(ctrl, "ADD_NETWORK");
841 static int wpa_cli_cmd_remove_network(struct wpa_ctrl *ctrl, int argc,
848 printf("Invalid REMOVE_NETWORK command: needs one argument "
853 res = os_snprintf(cmd, sizeof(cmd), "REMOVE_NETWORK %s", argv[0]);
854 if (res < 0 || (size_t) res >= sizeof(cmd))
856 cmd[sizeof(cmd) - 1] = '\0';
858 return wpa_ctrl_command(ctrl, cmd);
862 static void wpa_cli_show_network_variables(void)
864 printf("set_network variables:\n"
865 " ssid (network name, SSID)\n"
866 " psk (WPA passphrase or pre-shared key)\n"
867 " key_mgmt (key management protocol)\n"
868 " identity (EAP identity)\n"
869 " password (EAP password)\n"
872 "Note: Values are entered in the same format as the "
873 "configuration file is using,\n"
874 "i.e., strings values need to be inside double quotation "
876 "For example: set_network 1 ssid \"network name\"\n"
878 "Please see wpa_supplicant.conf documentation for full list "
879 "of\navailable variables.\n");
883 static int wpa_cli_cmd_set_network(struct wpa_ctrl *ctrl, int argc,
890 wpa_cli_show_network_variables();
895 printf("Invalid SET_NETWORK command: needs three arguments\n"
896 "(network id, variable name, and value)\n");
900 res = os_snprintf(cmd, sizeof(cmd), "SET_NETWORK %s %s %s",
901 argv[0], argv[1], argv[2]);
902 if (res < 0 || (size_t) res >= sizeof(cmd) - 1) {
903 printf("Too long SET_NETWORK command.\n");
906 return wpa_ctrl_command(ctrl, cmd);
910 static int wpa_cli_cmd_get_network(struct wpa_ctrl *ctrl, int argc,
917 wpa_cli_show_network_variables();
922 printf("Invalid GET_NETWORK command: needs two arguments\n"
923 "(network id and variable name)\n");
927 res = os_snprintf(cmd, sizeof(cmd), "GET_NETWORK %s %s",
929 if (res < 0 || (size_t) res >= sizeof(cmd) - 1) {
930 printf("Too long GET_NETWORK command.\n");
933 return wpa_ctrl_command(ctrl, cmd);
937 static int wpa_cli_cmd_disconnect(struct wpa_ctrl *ctrl, int argc,
940 return wpa_ctrl_command(ctrl, "DISCONNECT");
944 static int wpa_cli_cmd_reconnect(struct wpa_ctrl *ctrl, int argc,
947 return wpa_ctrl_command(ctrl, "RECONNECT");
951 static int wpa_cli_cmd_save_config(struct wpa_ctrl *ctrl, int argc,
954 return wpa_ctrl_command(ctrl, "SAVE_CONFIG");
958 static int wpa_cli_cmd_scan(struct wpa_ctrl *ctrl, int argc, char *argv[])
960 return wpa_ctrl_command(ctrl, "SCAN");
964 static int wpa_cli_cmd_scan_results(struct wpa_ctrl *ctrl, int argc,
967 return wpa_ctrl_command(ctrl, "SCAN_RESULTS");
971 static int wpa_cli_cmd_bss(struct wpa_ctrl *ctrl, int argc, char *argv[])
977 printf("Invalid BSS command: need one argument (index or "
982 res = os_snprintf(cmd, sizeof(cmd), "BSS %s", argv[0]);
983 if (res < 0 || (size_t) res >= sizeof(cmd))
985 cmd[sizeof(cmd) - 1] = '\0';
987 return wpa_ctrl_command(ctrl, cmd);
991 static int wpa_cli_cmd_get_capability(struct wpa_ctrl *ctrl, int argc,
997 if (argc < 1 || argc > 2) {
998 printf("Invalid GET_CAPABILITY command: need either one or "
1003 if ((argc == 2) && os_strcmp(argv[1], "strict") != 0) {
1004 printf("Invalid GET_CAPABILITY command: second argument, "
1005 "if any, must be 'strict'\n");
1009 res = os_snprintf(cmd, sizeof(cmd), "GET_CAPABILITY %s%s", argv[0],
1010 (argc == 2) ? " strict" : "");
1011 if (res < 0 || (size_t) res >= sizeof(cmd))
1013 cmd[sizeof(cmd) - 1] = '\0';
1015 return wpa_ctrl_command(ctrl, cmd);
1019 static int wpa_cli_list_interfaces(struct wpa_ctrl *ctrl)
1021 printf("Available interfaces:\n");
1022 return wpa_ctrl_command(ctrl, "INTERFACES");
1026 static int wpa_cli_cmd_interface(struct wpa_ctrl *ctrl, int argc, char *argv[])
1029 wpa_cli_list_interfaces(ctrl);
1033 wpa_cli_close_connection();
1034 os_free(ctrl_ifname);
1035 ctrl_ifname = os_strdup(argv[0]);
1037 if (wpa_cli_open_connection(ctrl_ifname)) {
1038 printf("Connected to interface '%s.\n", ctrl_ifname);
1039 if (wpa_ctrl_attach(ctrl_conn) == 0) {
1040 wpa_cli_attached = 1;
1042 printf("Warning: Failed to attach to "
1043 "wpa_supplicant.\n");
1046 printf("Could not connect to interface '%s' - re-trying\n",
1053 static int wpa_cli_cmd_reconfigure(struct wpa_ctrl *ctrl, int argc,
1056 return wpa_ctrl_command(ctrl, "RECONFIGURE");
1060 static int wpa_cli_cmd_terminate(struct wpa_ctrl *ctrl, int argc,
1063 return wpa_ctrl_command(ctrl, "TERMINATE");
1067 static int wpa_cli_cmd_interface_add(struct wpa_ctrl *ctrl, int argc,
1074 printf("Invalid INTERFACE_ADD command: needs at least one "
1075 "argument (interface name)\n"
1076 "All arguments: ifname confname driver ctrl_interface "
1077 "driver_param bridge_name\n");
1082 * INTERFACE_ADD <ifname>TAB<confname>TAB<driver>TAB<ctrl_interface>TAB
1083 * <driver_param>TAB<bridge_name>
1085 res = os_snprintf(cmd, sizeof(cmd),
1086 "INTERFACE_ADD %s\t%s\t%s\t%s\t%s\t%s",
1088 argc > 1 ? argv[1] : "", argc > 2 ? argv[2] : "",
1089 argc > 3 ? argv[3] : "", argc > 4 ? argv[4] : "",
1090 argc > 5 ? argv[5] : "");
1091 if (res < 0 || (size_t) res >= sizeof(cmd))
1093 cmd[sizeof(cmd) - 1] = '\0';
1094 return wpa_ctrl_command(ctrl, cmd);
1098 static int wpa_cli_cmd_interface_remove(struct wpa_ctrl *ctrl, int argc,
1105 printf("Invalid INTERFACE_REMOVE command: needs one argument "
1106 "(interface name)\n");
1110 res = os_snprintf(cmd, sizeof(cmd), "INTERFACE_REMOVE %s", argv[0]);
1111 if (res < 0 || (size_t) res >= sizeof(cmd))
1113 cmd[sizeof(cmd) - 1] = '\0';
1114 return wpa_ctrl_command(ctrl, cmd);
1118 static int wpa_cli_cmd_interface_list(struct wpa_ctrl *ctrl, int argc,
1121 return wpa_ctrl_command(ctrl, "INTERFACE_LIST");
1125 enum wpa_cli_cmd_flags {
1126 cli_cmd_flag_none = 0x00,
1127 cli_cmd_flag_sensitive = 0x01
1130 struct wpa_cli_cmd {
1132 int (*handler)(struct wpa_ctrl *ctrl, int argc, char *argv[]);
1133 enum wpa_cli_cmd_flags flags;
1137 static struct wpa_cli_cmd wpa_cli_commands[] = {
1138 { "status", wpa_cli_cmd_status,
1140 "[verbose] = get current WPA/EAPOL/EAP status" },
1141 { "ping", wpa_cli_cmd_ping,
1143 "= pings wpa_supplicant" },
1144 { "mib", wpa_cli_cmd_mib,
1146 "= get MIB variables (dot1x, dot11)" },
1147 { "help", wpa_cli_cmd_help,
1149 "= show this usage help" },
1150 { "interface", wpa_cli_cmd_interface,
1152 "[ifname] = show interfaces/select interface" },
1153 { "level", wpa_cli_cmd_level,
1155 "<debug level> = change debug level" },
1156 { "license", wpa_cli_cmd_license,
1158 "= show full wpa_cli license" },
1159 { "quit", wpa_cli_cmd_quit,
1162 { "set", wpa_cli_cmd_set,
1164 "= set variables (shows list of variables when run without "
1166 { "logon", wpa_cli_cmd_logon,
1168 "= IEEE 802.1X EAPOL state machine logon" },
1169 { "logoff", wpa_cli_cmd_logoff,
1171 "= IEEE 802.1X EAPOL state machine logoff" },
1172 { "pmksa", wpa_cli_cmd_pmksa,
1174 "= show PMKSA cache" },
1175 { "reassociate", wpa_cli_cmd_reassociate,
1177 "= force reassociation" },
1178 { "preauthenticate", wpa_cli_cmd_preauthenticate,
1180 "<BSSID> = force preauthentication" },
1181 { "identity", wpa_cli_cmd_identity,
1183 "<network id> <identity> = configure identity for an SSID" },
1184 { "password", wpa_cli_cmd_password,
1185 cli_cmd_flag_sensitive,
1186 "<network id> <password> = configure password for an SSID" },
1187 { "new_password", wpa_cli_cmd_new_password,
1188 cli_cmd_flag_sensitive,
1189 "<network id> <password> = change password for an SSID" },
1190 { "pin", wpa_cli_cmd_pin,
1191 cli_cmd_flag_sensitive,
1192 "<network id> <pin> = configure pin for an SSID" },
1193 { "otp", wpa_cli_cmd_otp,
1194 cli_cmd_flag_sensitive,
1195 "<network id> <password> = configure one-time-password for an SSID"
1197 { "passphrase", wpa_cli_cmd_passphrase,
1198 cli_cmd_flag_sensitive,
1199 "<network id> <passphrase> = configure private key passphrase\n"
1201 { "bssid", wpa_cli_cmd_bssid,
1203 "<network id> <BSSID> = set preferred BSSID for an SSID" },
1204 { "list_networks", wpa_cli_cmd_list_networks,
1206 "= list configured networks" },
1207 { "select_network", wpa_cli_cmd_select_network,
1209 "<network id> = select a network (disable others)" },
1210 { "enable_network", wpa_cli_cmd_enable_network,
1212 "<network id> = enable a network" },
1213 { "disable_network", wpa_cli_cmd_disable_network,
1215 "<network id> = disable a network" },
1216 { "add_network", wpa_cli_cmd_add_network,
1218 "= add a network" },
1219 { "remove_network", wpa_cli_cmd_remove_network,
1221 "<network id> = remove a network" },
1222 { "set_network", wpa_cli_cmd_set_network,
1223 cli_cmd_flag_sensitive,
1224 "<network id> <variable> <value> = set network variables (shows\n"
1225 " list of variables when run without arguments)" },
1226 { "get_network", wpa_cli_cmd_get_network,
1228 "<network id> <variable> = get network variables" },
1229 { "save_config", wpa_cli_cmd_save_config,
1231 "= save the current configuration" },
1232 { "disconnect", wpa_cli_cmd_disconnect,
1234 "= disconnect and wait for reassociate/reconnect command before\n"
1236 { "reconnect", wpa_cli_cmd_reconnect,
1238 "= like reassociate, but only takes effect if already disconnected"
1240 { "scan", wpa_cli_cmd_scan,
1242 "= request new BSS scan" },
1243 { "scan_results", wpa_cli_cmd_scan_results,
1245 "= get latest scan results" },
1246 { "bss", wpa_cli_cmd_bss,
1248 "<<idx> | <bssid>> = get detailed scan result info" },
1249 { "get_capability", wpa_cli_cmd_get_capability,
1251 "<eap/pairwise/group/key_mgmt/proto/auth_alg> = get capabilies" },
1252 { "reconfigure", wpa_cli_cmd_reconfigure,
1254 "= force wpa_supplicant to re-read its configuration file" },
1255 { "terminate", wpa_cli_cmd_terminate,
1257 "= terminate wpa_supplicant" },
1258 { "interface_add", wpa_cli_cmd_interface_add,
1260 "<ifname> <confname> <driver> <ctrl_interface> <driver_param>\n"
1261 " <bridge_name> = adds new interface, all parameters but <ifname>\n"
1263 { "interface_remove", wpa_cli_cmd_interface_remove,
1265 "<ifname> = removes the interface" },
1266 { "interface_list", wpa_cli_cmd_interface_list,
1268 "= list available interfaces" },
1269 { "ap_scan", wpa_cli_cmd_ap_scan,
1271 "<value> = set ap_scan parameter" },
1272 { "stkstart", wpa_cli_cmd_stkstart,
1274 "<addr> = request STK negotiation with <addr>" },
1275 { "ft_ds", wpa_cli_cmd_ft_ds,
1277 "<addr> = request over-the-DS FT with <addr>" },
1278 { "wps_pbc", wpa_cli_cmd_wps_pbc,
1280 "[BSSID] = start Wi-Fi Protected Setup: Push Button Configuration" },
1281 { "wps_pin", wpa_cli_cmd_wps_pin,
1282 cli_cmd_flag_sensitive,
1283 "<BSSID> [PIN] = start WPS PIN method (returns PIN, if not "
1285 { "wps_oob", wpa_cli_cmd_wps_oob,
1286 cli_cmd_flag_sensitive,
1287 "<OOB_DEV_TYPE> <OOB_PATH> <OOB_METHOD> = start WPS OOB" },
1288 { "wps_reg", wpa_cli_cmd_wps_reg,
1289 cli_cmd_flag_sensitive,
1290 "<BSSID> <AP PIN> = start WPS Registrar to configure an AP" },
1291 { "ibss_rsn", wpa_cli_cmd_ibss_rsn,
1293 "<addr> = request RSN authentication with <addr> in IBSS" },
1294 { NULL, NULL, cli_cmd_flag_none, NULL }
1299 * Prints command usage, lines are padded with the specified string.
1301 static void print_cmd_help(struct wpa_cli_cmd *cmd, const char *pad)
1306 printf("%s%s ", pad, cmd->cmd);
1307 for (n = 0; (c = cmd->usage[n]); n++) {
1316 static void print_help(void)
1319 printf("commands:\n");
1320 for (n = 0; wpa_cli_commands[n].cmd; n++)
1321 print_cmd_help(&wpa_cli_commands[n], " ");
1325 #ifdef CONFIG_READLINE
1326 static int cmd_has_sensitive_data(const char *cmd)
1328 const char *c, *delim;
1332 delim = os_strchr(cmd, ' ');
1336 len = os_strlen(cmd);
1338 for (n = 0; (c = wpa_cli_commands[n].cmd); n++) {
1339 if (os_strncasecmp(cmd, c, len) == 0 && len == os_strlen(c))
1340 return (wpa_cli_commands[n].flags &
1341 cli_cmd_flag_sensitive);
1345 #endif /* CONFIG_READLINE */
1348 static int wpa_request(struct wpa_ctrl *ctrl, int argc, char *argv[])
1350 struct wpa_cli_cmd *cmd, *match = NULL;
1355 cmd = wpa_cli_commands;
1357 if (os_strncasecmp(cmd->cmd, argv[0], os_strlen(argv[0])) == 0)
1360 if (os_strcasecmp(cmd->cmd, argv[0]) == 0) {
1361 /* we have an exact match */
1371 printf("Ambiguous command '%s'; possible commands:", argv[0]);
1372 cmd = wpa_cli_commands;
1374 if (os_strncasecmp(cmd->cmd, argv[0],
1375 os_strlen(argv[0])) == 0) {
1376 printf(" %s", cmd->cmd);
1382 } else if (count == 0) {
1383 printf("Unknown command '%s'\n", argv[0]);
1386 ret = match->handler(ctrl, argc - 1, &argv[1]);
1393 static int str_match(const char *a, const char *b)
1395 return os_strncmp(a, b, os_strlen(b)) == 0;
1399 static int wpa_cli_exec(const char *program, const char *arg1,
1407 len = os_strlen(program) + os_strlen(arg1) + os_strlen(arg2) + 3;
1408 cmd = os_malloc(len);
1411 res = os_snprintf(cmd, len, "%s %s %s", program, arg1, arg2);
1412 if (res < 0 || (size_t) res >= len) {
1416 cmd[len - 1] = '\0';
1418 if (system(cmd) < 0)
1420 #endif /* _WIN32_WCE */
1427 static void wpa_cli_action_process(const char *msg)
1430 char *copy = NULL, *id, *pos2;
1435 pos = os_strchr(pos, '>');
1442 if (str_match(pos, WPA_EVENT_CONNECTED)) {
1444 os_unsetenv("WPA_ID");
1445 os_unsetenv("WPA_ID_STR");
1446 os_unsetenv("WPA_CTRL_DIR");
1448 pos = os_strstr(pos, "[id=");
1450 copy = os_strdup(pos + 4);
1454 while (*pos2 && *pos2 != ' ')
1458 os_setenv("WPA_ID", id, 1);
1459 while (*pos2 && *pos2 != '=')
1464 while (*pos2 && *pos2 != ']')
1467 os_setenv("WPA_ID_STR", id, 1);
1471 os_setenv("WPA_CTRL_DIR", ctrl_iface_dir, 1);
1473 if (!wpa_cli_connected || new_id != wpa_cli_last_id) {
1474 wpa_cli_connected = 1;
1475 wpa_cli_last_id = new_id;
1476 wpa_cli_exec(action_file, ctrl_ifname, "CONNECTED");
1478 } else if (str_match(pos, WPA_EVENT_DISCONNECTED)) {
1479 if (wpa_cli_connected) {
1480 wpa_cli_connected = 0;
1481 wpa_cli_exec(action_file, ctrl_ifname, "DISCONNECTED");
1483 } else if (str_match(pos, WPA_EVENT_TERMINATING)) {
1484 printf("wpa_supplicant is terminating - stop monitoring\n");
1490 #ifndef CONFIG_ANSI_C_EXTRA
1491 static void wpa_cli_action_cb(char *msg, size_t len)
1493 wpa_cli_action_process(msg);
1495 #endif /* CONFIG_ANSI_C_EXTRA */
1498 static void wpa_cli_reconnect(void)
1500 wpa_cli_close_connection();
1501 ctrl_conn = wpa_cli_open_connection(ctrl_ifname);
1503 printf("Connection to wpa_supplicant re-established\n");
1504 if (wpa_ctrl_attach(ctrl_conn) == 0) {
1505 wpa_cli_attached = 1;
1507 printf("Warning: Failed to attach to "
1508 "wpa_supplicant.\n");
1514 static void wpa_cli_recv_pending(struct wpa_ctrl *ctrl, int in_read,
1518 if (ctrl_conn == NULL) {
1519 wpa_cli_reconnect();
1522 while (wpa_ctrl_pending(ctrl) > 0) {
1524 size_t len = sizeof(buf) - 1;
1525 if (wpa_ctrl_recv(ctrl, buf, &len) == 0) {
1528 wpa_cli_action_process(buf);
1530 if (in_read && first)
1533 printf("%s\n", buf);
1536 printf("Could not read pending message.\n");
1541 if (wpa_ctrl_pending(ctrl) < 0) {
1542 printf("Connection to wpa_supplicant lost - trying to "
1544 wpa_cli_reconnect();
1549 #ifdef CONFIG_READLINE
1550 static char * wpa_cli_cmd_gen(const char *text, int state)
1557 len = os_strlen(text);
1560 while ((cmd = wpa_cli_commands[i].cmd)) {
1562 if (os_strncasecmp(cmd, text, len) == 0)
1563 return os_strdup(cmd);
1570 static char * wpa_cli_dummy_gen(const char *text, int state)
1576 static char ** wpa_cli_completion(const char *text, int start, int end)
1578 return rl_completion_matches(text, start == 0 ?
1579 wpa_cli_cmd_gen : wpa_cli_dummy_gen);
1581 #endif /* CONFIG_READLINE */
1584 static void wpa_cli_interactive(void)
1587 char cmdbuf[256], *cmd, *argv[max_args], *pos;
1589 #ifdef CONFIG_READLINE
1590 char *home, *hfile = NULL;
1591 #endif /* CONFIG_READLINE */
1593 printf("\nInteractive mode\n\n");
1595 #ifdef CONFIG_READLINE
1596 rl_attempted_completion_function = wpa_cli_completion;
1597 home = getenv("HOME");
1599 const char *fname = ".wpa_cli_history";
1600 int hfile_len = os_strlen(home) + 1 + os_strlen(fname) + 1;
1601 hfile = os_malloc(hfile_len);
1604 res = os_snprintf(hfile, hfile_len, "%s/%s", home,
1606 if (res >= 0 && res < hfile_len) {
1607 hfile[hfile_len - 1] = '\0';
1608 read_history(hfile);
1609 stifle_history(100);
1613 #endif /* CONFIG_READLINE */
1616 wpa_cli_recv_pending(ctrl_conn, 0, 0);
1617 #ifndef CONFIG_NATIVE_WINDOWS
1618 alarm(ping_interval);
1619 #endif /* CONFIG_NATIVE_WINDOWS */
1620 #ifdef CONFIG_READLINE
1621 cmd = readline("> ");
1624 while (next_history())
1626 h = previous_history();
1627 if (h == NULL || os_strcmp(cmd, h->line) != 0)
1631 #else /* CONFIG_READLINE */
1633 cmd = fgets(cmdbuf, sizeof(cmdbuf), stdin);
1634 #endif /* CONFIG_READLINE */
1635 #ifndef CONFIG_NATIVE_WINDOWS
1637 #endif /* CONFIG_NATIVE_WINDOWS */
1640 wpa_cli_recv_pending(ctrl_conn, 0, 0);
1642 while (*pos != '\0') {
1658 if (argc == max_args)
1661 char *pos2 = os_strrchr(pos, '"');
1665 while (*pos != '\0' && *pos != ' ')
1671 wpa_request(ctrl_conn, argc, argv);
1675 } while (!wpa_cli_quit);
1677 #ifdef CONFIG_READLINE
1679 /* Save command history, excluding lines that may contain
1683 while ((h = current_history())) {
1685 while (*p == ' ' || *p == '\t')
1687 if (cmd_has_sensitive_data(p)) {
1688 h = remove_history(where_history());
1698 write_history(hfile);
1701 #endif /* CONFIG_READLINE */
1705 static void wpa_cli_action(struct wpa_ctrl *ctrl)
1707 #ifdef CONFIG_ANSI_C_EXTRA
1708 /* TODO: ANSI C version(?) */
1709 printf("Action processing not supported in ANSI C build.\n");
1710 #else /* CONFIG_ANSI_C_EXTRA */
1714 char buf[256]; /* note: large enough to fit in unsolicited messages */
1717 fd = wpa_ctrl_get_fd(ctrl);
1719 while (!wpa_cli_quit) {
1722 tv.tv_sec = ping_interval;
1724 res = select(fd + 1, &rfds, NULL, NULL, &tv);
1725 if (res < 0 && errno != EINTR) {
1730 if (FD_ISSET(fd, &rfds))
1731 wpa_cli_recv_pending(ctrl, 0, 1);
1733 /* verify that connection is still working */
1734 len = sizeof(buf) - 1;
1735 if (wpa_ctrl_request(ctrl, "PING", 4, buf, &len,
1736 wpa_cli_action_cb) < 0 ||
1737 len < 4 || os_memcmp(buf, "PONG", 4) != 0) {
1738 printf("wpa_supplicant did not reply to PING "
1739 "command - exiting\n");
1744 #endif /* CONFIG_ANSI_C_EXTRA */
1748 static void wpa_cli_cleanup(void)
1750 wpa_cli_close_connection();
1752 os_daemonize_terminate(pid_file);
1754 os_program_deinit();
1757 static void wpa_cli_terminate(int sig)
1764 #ifndef CONFIG_NATIVE_WINDOWS
1765 static void wpa_cli_alarm(int sig)
1767 if (ctrl_conn && _wpa_ctrl_command(ctrl_conn, "PING", 0)) {
1768 printf("Connection to wpa_supplicant lost - trying to "
1770 wpa_cli_close_connection();
1773 wpa_cli_reconnect();
1775 wpa_cli_recv_pending(ctrl_conn, 1, 0);
1776 alarm(ping_interval);
1778 #endif /* CONFIG_NATIVE_WINDOWS */
1781 static char * wpa_cli_get_default_ifname(void)
1783 char *ifname = NULL;
1785 #ifdef CONFIG_CTRL_IFACE_UNIX
1786 struct dirent *dent;
1787 DIR *dir = opendir(ctrl_iface_dir);
1790 while ((dent = readdir(dir))) {
1791 #ifdef _DIRENT_HAVE_D_TYPE
1793 * Skip the file if it is not a socket. Also accept
1794 * DT_UNKNOWN (0) in case the C library or underlying
1795 * file system does not support d_type.
1797 if (dent->d_type != DT_SOCK && dent->d_type != DT_UNKNOWN)
1799 #endif /* _DIRENT_HAVE_D_TYPE */
1800 if (os_strcmp(dent->d_name, ".") == 0 ||
1801 os_strcmp(dent->d_name, "..") == 0)
1803 printf("Selected interface '%s'\n", dent->d_name);
1804 ifname = os_strdup(dent->d_name);
1808 #endif /* CONFIG_CTRL_IFACE_UNIX */
1810 #ifdef CONFIG_CTRL_IFACE_NAMED_PIPE
1811 char buf[2048], *pos;
1813 struct wpa_ctrl *ctrl;
1816 ctrl = wpa_ctrl_open(NULL);
1820 len = sizeof(buf) - 1;
1821 ret = wpa_ctrl_request(ctrl, "INTERFACES", 10, buf, &len, NULL);
1824 pos = os_strchr(buf, '\n');
1827 ifname = os_strdup(buf);
1829 wpa_ctrl_close(ctrl);
1830 #endif /* CONFIG_CTRL_IFACE_NAMED_PIPE */
1836 int main(int argc, char *argv[])
1839 int warning_displayed = 0;
1843 const char *global = NULL;
1845 if (os_program_init())
1849 c = getopt(argc, argv, "a:Bg:G:hi:p:P:v");
1854 action_file = optarg;
1863 ping_interval = atoi(optarg);
1869 printf("%s\n", wpa_cli_version);
1872 os_free(ctrl_ifname);
1873 ctrl_ifname = os_strdup(optarg);
1876 ctrl_iface_dir = optarg;
1887 interactive = (argc == optind) && (action_file == NULL);
1890 printf("%s\n\n%s\n\n", wpa_cli_version, wpa_cli_license);
1893 #ifdef CONFIG_CTRL_IFACE_NAMED_PIPE
1894 ctrl_conn = wpa_ctrl_open(NULL);
1895 #else /* CONFIG_CTRL_IFACE_NAMED_PIPE */
1896 ctrl_conn = wpa_ctrl_open(global);
1897 #endif /* CONFIG_CTRL_IFACE_NAMED_PIPE */
1898 if (ctrl_conn == NULL) {
1899 perror("Failed to connect to wpa_supplicant - "
1906 if (ctrl_ifname == NULL)
1907 ctrl_ifname = wpa_cli_get_default_ifname();
1908 ctrl_conn = wpa_cli_open_connection(ctrl_ifname);
1910 if (warning_displayed)
1911 printf("Connection established.\n");
1916 perror("Failed to connect to wpa_supplicant - "
1921 if (!warning_displayed) {
1922 printf("Could not connect to wpa_supplicant - "
1924 warning_displayed = 1;
1931 signal(SIGINT, wpa_cli_terminate);
1932 signal(SIGTERM, wpa_cli_terminate);
1933 #endif /* _WIN32_WCE */
1934 #ifndef CONFIG_NATIVE_WINDOWS
1935 signal(SIGALRM, wpa_cli_alarm);
1936 #endif /* CONFIG_NATIVE_WINDOWS */
1938 if (interactive || action_file) {
1939 if (wpa_ctrl_attach(ctrl_conn) == 0) {
1940 wpa_cli_attached = 1;
1942 printf("Warning: Failed to attach to "
1943 "wpa_supplicant.\n");
1949 if (daemonize && os_daemonize(pid_file))
1953 wpa_cli_interactive();
1954 else if (action_file)
1955 wpa_cli_action(ctrl_conn);
1957 ret = wpa_request(ctrl_conn, argc - optind, &argv[optind]);
1959 os_free(ctrl_ifname);
1965 #else /* CONFIG_CTRL_IFACE */
1966 int main(int argc, char *argv[])
1968 printf("CONFIG_CTRL_IFACE not defined - wpa_cli disabled\n");
1971 #endif /* CONFIG_CTRL_IFACE */