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 #ifdef CONFIG_WPS_OOB
450 static int wpa_cli_cmd_wps_oob(struct wpa_ctrl *ctrl, int argc, char *argv[])
456 printf("Invalid WPS_OOB command: need three arguments:\n"
457 "- OOB_DEV_TYPE: use 'ufd'\n"
458 "- OOB_PATH: path of OOB device like '/mnt'\n"
459 "- OOB_METHOD: OOB method 'pin-e' or 'pin-r', "
464 res = os_snprintf(cmd, sizeof(cmd), "WPS_OOB %s %s %s",
465 argv[0], argv[1], argv[2]);
466 if (res < 0 || (size_t) res >= sizeof(cmd) - 1) {
467 printf("Too long WPS_OOB command.\n");
470 return wpa_ctrl_command(ctrl, cmd);
472 #endif /* CONFIG_WPS_OOB */
475 static int wpa_cli_cmd_wps_reg(struct wpa_ctrl *ctrl, int argc, char *argv[])
481 printf("Invalid WPS_REG command: need two arguments:\n"
482 "- BSSID: use 'any' to select any\n"
487 res = os_snprintf(cmd, sizeof(cmd), "WPS_REG %s %s", argv[0], argv[1]);
488 if (res < 0 || (size_t) res >= sizeof(cmd) - 1) {
489 printf("Too long WPS_REG command.\n");
492 return wpa_ctrl_command(ctrl, cmd);
496 static int wpa_cli_cmd_ibss_rsn(struct wpa_ctrl *ctrl, int argc, char *argv[])
502 printf("Invalid IBSS_RSN command: needs one argument "
503 "(Peer STA MAC address)\n");
507 res = os_snprintf(cmd, sizeof(cmd), "IBSS_RSN %s", argv[0]);
508 if (res < 0 || (size_t) res >= sizeof(cmd) - 1) {
509 printf("Too long IBSS_RSN command.\n");
512 return wpa_ctrl_command(ctrl, cmd);
516 static int wpa_cli_cmd_level(struct wpa_ctrl *ctrl, int argc, char *argv[])
522 printf("Invalid LEVEL command: needs one argument (debug "
526 res = os_snprintf(cmd, sizeof(cmd), "LEVEL %s", argv[0]);
527 if (res < 0 || (size_t) res >= sizeof(cmd) - 1) {
528 printf("Too long LEVEL command.\n");
531 return wpa_ctrl_command(ctrl, cmd);
535 static int wpa_cli_cmd_identity(struct wpa_ctrl *ctrl, int argc, char *argv[])
537 char cmd[256], *pos, *end;
541 printf("Invalid IDENTITY command: needs two arguments "
542 "(network id and identity)\n");
546 end = cmd + sizeof(cmd);
548 ret = os_snprintf(pos, end - pos, WPA_CTRL_RSP "IDENTITY-%s:%s",
550 if (ret < 0 || ret >= end - pos) {
551 printf("Too long IDENTITY command.\n");
555 for (i = 2; i < argc; i++) {
556 ret = os_snprintf(pos, end - pos, " %s", argv[i]);
557 if (ret < 0 || ret >= end - pos) {
558 printf("Too long IDENTITY command.\n");
564 return wpa_ctrl_command(ctrl, cmd);
568 static int wpa_cli_cmd_password(struct wpa_ctrl *ctrl, int argc, char *argv[])
570 char cmd[256], *pos, *end;
574 printf("Invalid PASSWORD command: needs two arguments "
575 "(network id and password)\n");
579 end = cmd + sizeof(cmd);
581 ret = os_snprintf(pos, end - pos, WPA_CTRL_RSP "PASSWORD-%s:%s",
583 if (ret < 0 || ret >= end - pos) {
584 printf("Too long PASSWORD command.\n");
588 for (i = 2; i < argc; i++) {
589 ret = os_snprintf(pos, end - pos, " %s", argv[i]);
590 if (ret < 0 || ret >= end - pos) {
591 printf("Too long PASSWORD command.\n");
597 return wpa_ctrl_command(ctrl, cmd);
601 static int wpa_cli_cmd_new_password(struct wpa_ctrl *ctrl, int argc,
604 char cmd[256], *pos, *end;
608 printf("Invalid NEW_PASSWORD command: needs two arguments "
609 "(network id and password)\n");
613 end = cmd + sizeof(cmd);
615 ret = os_snprintf(pos, end - pos, WPA_CTRL_RSP "NEW_PASSWORD-%s:%s",
617 if (ret < 0 || ret >= end - pos) {
618 printf("Too long NEW_PASSWORD command.\n");
622 for (i = 2; i < argc; i++) {
623 ret = os_snprintf(pos, end - pos, " %s", argv[i]);
624 if (ret < 0 || ret >= end - pos) {
625 printf("Too long NEW_PASSWORD command.\n");
631 return wpa_ctrl_command(ctrl, cmd);
635 static int wpa_cli_cmd_pin(struct wpa_ctrl *ctrl, int argc, char *argv[])
637 char cmd[256], *pos, *end;
641 printf("Invalid PIN command: needs two arguments "
642 "(network id and pin)\n");
646 end = cmd + sizeof(cmd);
648 ret = os_snprintf(pos, end - pos, WPA_CTRL_RSP "PIN-%s:%s",
650 if (ret < 0 || ret >= end - pos) {
651 printf("Too long PIN command.\n");
655 for (i = 2; i < argc; i++) {
656 ret = os_snprintf(pos, end - pos, " %s", argv[i]);
657 if (ret < 0 || ret >= end - pos) {
658 printf("Too long PIN command.\n");
663 return wpa_ctrl_command(ctrl, cmd);
667 static int wpa_cli_cmd_otp(struct wpa_ctrl *ctrl, int argc, char *argv[])
669 char cmd[256], *pos, *end;
673 printf("Invalid OTP command: needs two arguments (network "
674 "id and password)\n");
678 end = cmd + sizeof(cmd);
680 ret = os_snprintf(pos, end - pos, WPA_CTRL_RSP "OTP-%s:%s",
682 if (ret < 0 || ret >= end - pos) {
683 printf("Too long OTP command.\n");
687 for (i = 2; i < argc; i++) {
688 ret = os_snprintf(pos, end - pos, " %s", argv[i]);
689 if (ret < 0 || ret >= end - pos) {
690 printf("Too long OTP command.\n");
696 return wpa_ctrl_command(ctrl, cmd);
700 static int wpa_cli_cmd_passphrase(struct wpa_ctrl *ctrl, int argc,
703 char cmd[256], *pos, *end;
707 printf("Invalid PASSPHRASE command: needs two arguments "
708 "(network id and passphrase)\n");
712 end = cmd + sizeof(cmd);
714 ret = os_snprintf(pos, end - pos, WPA_CTRL_RSP "PASSPHRASE-%s:%s",
716 if (ret < 0 || ret >= end - pos) {
717 printf("Too long PASSPHRASE command.\n");
721 for (i = 2; i < argc; i++) {
722 ret = os_snprintf(pos, end - pos, " %s", argv[i]);
723 if (ret < 0 || ret >= end - pos) {
724 printf("Too long PASSPHRASE command.\n");
730 return wpa_ctrl_command(ctrl, cmd);
734 static int wpa_cli_cmd_bssid(struct wpa_ctrl *ctrl, int argc, char *argv[])
736 char cmd[256], *pos, *end;
740 printf("Invalid BSSID command: needs two arguments (network "
745 end = cmd + sizeof(cmd);
747 ret = os_snprintf(pos, end - pos, "BSSID");
748 if (ret < 0 || ret >= end - pos) {
749 printf("Too long BSSID command.\n");
753 for (i = 0; i < argc; i++) {
754 ret = os_snprintf(pos, end - pos, " %s", argv[i]);
755 if (ret < 0 || ret >= end - pos) {
756 printf("Too long BSSID command.\n");
762 return wpa_ctrl_command(ctrl, cmd);
766 static int wpa_cli_cmd_list_networks(struct wpa_ctrl *ctrl, int argc,
769 return wpa_ctrl_command(ctrl, "LIST_NETWORKS");
773 static int wpa_cli_cmd_select_network(struct wpa_ctrl *ctrl, int argc,
780 printf("Invalid SELECT_NETWORK command: needs one argument "
785 res = os_snprintf(cmd, sizeof(cmd), "SELECT_NETWORK %s", argv[0]);
786 if (res < 0 || (size_t) res >= sizeof(cmd))
788 cmd[sizeof(cmd) - 1] = '\0';
790 return wpa_ctrl_command(ctrl, cmd);
794 static int wpa_cli_cmd_enable_network(struct wpa_ctrl *ctrl, int argc,
801 printf("Invalid ENABLE_NETWORK command: needs one argument "
806 res = os_snprintf(cmd, sizeof(cmd), "ENABLE_NETWORK %s", argv[0]);
807 if (res < 0 || (size_t) res >= sizeof(cmd))
809 cmd[sizeof(cmd) - 1] = '\0';
811 return wpa_ctrl_command(ctrl, cmd);
815 static int wpa_cli_cmd_disable_network(struct wpa_ctrl *ctrl, int argc,
822 printf("Invalid DISABLE_NETWORK command: needs one argument "
827 res = os_snprintf(cmd, sizeof(cmd), "DISABLE_NETWORK %s", argv[0]);
828 if (res < 0 || (size_t) res >= sizeof(cmd))
830 cmd[sizeof(cmd) - 1] = '\0';
832 return wpa_ctrl_command(ctrl, cmd);
836 static int wpa_cli_cmd_add_network(struct wpa_ctrl *ctrl, int argc,
839 return wpa_ctrl_command(ctrl, "ADD_NETWORK");
843 static int wpa_cli_cmd_remove_network(struct wpa_ctrl *ctrl, int argc,
850 printf("Invalid REMOVE_NETWORK command: needs one argument "
855 res = os_snprintf(cmd, sizeof(cmd), "REMOVE_NETWORK %s", argv[0]);
856 if (res < 0 || (size_t) res >= sizeof(cmd))
858 cmd[sizeof(cmd) - 1] = '\0';
860 return wpa_ctrl_command(ctrl, cmd);
864 static void wpa_cli_show_network_variables(void)
866 printf("set_network variables:\n"
867 " ssid (network name, SSID)\n"
868 " psk (WPA passphrase or pre-shared key)\n"
869 " key_mgmt (key management protocol)\n"
870 " identity (EAP identity)\n"
871 " password (EAP password)\n"
874 "Note: Values are entered in the same format as the "
875 "configuration file is using,\n"
876 "i.e., strings values need to be inside double quotation "
878 "For example: set_network 1 ssid \"network name\"\n"
880 "Please see wpa_supplicant.conf documentation for full list "
881 "of\navailable variables.\n");
885 static int wpa_cli_cmd_set_network(struct wpa_ctrl *ctrl, int argc,
892 wpa_cli_show_network_variables();
897 printf("Invalid SET_NETWORK command: needs three arguments\n"
898 "(network id, variable name, and value)\n");
902 res = os_snprintf(cmd, sizeof(cmd), "SET_NETWORK %s %s %s",
903 argv[0], argv[1], argv[2]);
904 if (res < 0 || (size_t) res >= sizeof(cmd) - 1) {
905 printf("Too long SET_NETWORK command.\n");
908 return wpa_ctrl_command(ctrl, cmd);
912 static int wpa_cli_cmd_get_network(struct wpa_ctrl *ctrl, int argc,
919 wpa_cli_show_network_variables();
924 printf("Invalid GET_NETWORK command: needs two arguments\n"
925 "(network id and variable name)\n");
929 res = os_snprintf(cmd, sizeof(cmd), "GET_NETWORK %s %s",
931 if (res < 0 || (size_t) res >= sizeof(cmd) - 1) {
932 printf("Too long GET_NETWORK command.\n");
935 return wpa_ctrl_command(ctrl, cmd);
939 static int wpa_cli_cmd_disconnect(struct wpa_ctrl *ctrl, int argc,
942 return wpa_ctrl_command(ctrl, "DISCONNECT");
946 static int wpa_cli_cmd_reconnect(struct wpa_ctrl *ctrl, int argc,
949 return wpa_ctrl_command(ctrl, "RECONNECT");
953 static int wpa_cli_cmd_save_config(struct wpa_ctrl *ctrl, int argc,
956 return wpa_ctrl_command(ctrl, "SAVE_CONFIG");
960 static int wpa_cli_cmd_scan(struct wpa_ctrl *ctrl, int argc, char *argv[])
962 return wpa_ctrl_command(ctrl, "SCAN");
966 static int wpa_cli_cmd_scan_results(struct wpa_ctrl *ctrl, int argc,
969 return wpa_ctrl_command(ctrl, "SCAN_RESULTS");
973 static int wpa_cli_cmd_bss(struct wpa_ctrl *ctrl, int argc, char *argv[])
979 printf("Invalid BSS command: need one argument (index or "
984 res = os_snprintf(cmd, sizeof(cmd), "BSS %s", argv[0]);
985 if (res < 0 || (size_t) res >= sizeof(cmd))
987 cmd[sizeof(cmd) - 1] = '\0';
989 return wpa_ctrl_command(ctrl, cmd);
993 static int wpa_cli_cmd_get_capability(struct wpa_ctrl *ctrl, int argc,
999 if (argc < 1 || argc > 2) {
1000 printf("Invalid GET_CAPABILITY command: need either one or "
1005 if ((argc == 2) && os_strcmp(argv[1], "strict") != 0) {
1006 printf("Invalid GET_CAPABILITY command: second argument, "
1007 "if any, must be 'strict'\n");
1011 res = os_snprintf(cmd, sizeof(cmd), "GET_CAPABILITY %s%s", argv[0],
1012 (argc == 2) ? " strict" : "");
1013 if (res < 0 || (size_t) res >= sizeof(cmd))
1015 cmd[sizeof(cmd) - 1] = '\0';
1017 return wpa_ctrl_command(ctrl, cmd);
1021 static int wpa_cli_list_interfaces(struct wpa_ctrl *ctrl)
1023 printf("Available interfaces:\n");
1024 return wpa_ctrl_command(ctrl, "INTERFACES");
1028 static int wpa_cli_cmd_interface(struct wpa_ctrl *ctrl, int argc, char *argv[])
1031 wpa_cli_list_interfaces(ctrl);
1035 wpa_cli_close_connection();
1036 os_free(ctrl_ifname);
1037 ctrl_ifname = os_strdup(argv[0]);
1039 if (wpa_cli_open_connection(ctrl_ifname)) {
1040 printf("Connected to interface '%s.\n", ctrl_ifname);
1041 if (wpa_ctrl_attach(ctrl_conn) == 0) {
1042 wpa_cli_attached = 1;
1044 printf("Warning: Failed to attach to "
1045 "wpa_supplicant.\n");
1048 printf("Could not connect to interface '%s' - re-trying\n",
1055 static int wpa_cli_cmd_reconfigure(struct wpa_ctrl *ctrl, int argc,
1058 return wpa_ctrl_command(ctrl, "RECONFIGURE");
1062 static int wpa_cli_cmd_terminate(struct wpa_ctrl *ctrl, int argc,
1065 return wpa_ctrl_command(ctrl, "TERMINATE");
1069 static int wpa_cli_cmd_interface_add(struct wpa_ctrl *ctrl, int argc,
1076 printf("Invalid INTERFACE_ADD command: needs at least one "
1077 "argument (interface name)\n"
1078 "All arguments: ifname confname driver ctrl_interface "
1079 "driver_param bridge_name\n");
1084 * INTERFACE_ADD <ifname>TAB<confname>TAB<driver>TAB<ctrl_interface>TAB
1085 * <driver_param>TAB<bridge_name>
1087 res = os_snprintf(cmd, sizeof(cmd),
1088 "INTERFACE_ADD %s\t%s\t%s\t%s\t%s\t%s",
1090 argc > 1 ? argv[1] : "", argc > 2 ? argv[2] : "",
1091 argc > 3 ? argv[3] : "", argc > 4 ? argv[4] : "",
1092 argc > 5 ? argv[5] : "");
1093 if (res < 0 || (size_t) res >= sizeof(cmd))
1095 cmd[sizeof(cmd) - 1] = '\0';
1096 return wpa_ctrl_command(ctrl, cmd);
1100 static int wpa_cli_cmd_interface_remove(struct wpa_ctrl *ctrl, int argc,
1107 printf("Invalid INTERFACE_REMOVE command: needs one argument "
1108 "(interface name)\n");
1112 res = os_snprintf(cmd, sizeof(cmd), "INTERFACE_REMOVE %s", argv[0]);
1113 if (res < 0 || (size_t) res >= sizeof(cmd))
1115 cmd[sizeof(cmd) - 1] = '\0';
1116 return wpa_ctrl_command(ctrl, cmd);
1120 static int wpa_cli_cmd_interface_list(struct wpa_ctrl *ctrl, int argc,
1123 return wpa_ctrl_command(ctrl, "INTERFACE_LIST");
1127 enum wpa_cli_cmd_flags {
1128 cli_cmd_flag_none = 0x00,
1129 cli_cmd_flag_sensitive = 0x01
1132 struct wpa_cli_cmd {
1134 int (*handler)(struct wpa_ctrl *ctrl, int argc, char *argv[]);
1135 enum wpa_cli_cmd_flags flags;
1139 static struct wpa_cli_cmd wpa_cli_commands[] = {
1140 { "status", wpa_cli_cmd_status,
1142 "[verbose] = get current WPA/EAPOL/EAP status" },
1143 { "ping", wpa_cli_cmd_ping,
1145 "= pings wpa_supplicant" },
1146 { "mib", wpa_cli_cmd_mib,
1148 "= get MIB variables (dot1x, dot11)" },
1149 { "help", wpa_cli_cmd_help,
1151 "= show this usage help" },
1152 { "interface", wpa_cli_cmd_interface,
1154 "[ifname] = show interfaces/select interface" },
1155 { "level", wpa_cli_cmd_level,
1157 "<debug level> = change debug level" },
1158 { "license", wpa_cli_cmd_license,
1160 "= show full wpa_cli license" },
1161 { "quit", wpa_cli_cmd_quit,
1164 { "set", wpa_cli_cmd_set,
1166 "= set variables (shows list of variables when run without "
1168 { "logon", wpa_cli_cmd_logon,
1170 "= IEEE 802.1X EAPOL state machine logon" },
1171 { "logoff", wpa_cli_cmd_logoff,
1173 "= IEEE 802.1X EAPOL state machine logoff" },
1174 { "pmksa", wpa_cli_cmd_pmksa,
1176 "= show PMKSA cache" },
1177 { "reassociate", wpa_cli_cmd_reassociate,
1179 "= force reassociation" },
1180 { "preauthenticate", wpa_cli_cmd_preauthenticate,
1182 "<BSSID> = force preauthentication" },
1183 { "identity", wpa_cli_cmd_identity,
1185 "<network id> <identity> = configure identity for an SSID" },
1186 { "password", wpa_cli_cmd_password,
1187 cli_cmd_flag_sensitive,
1188 "<network id> <password> = configure password for an SSID" },
1189 { "new_password", wpa_cli_cmd_new_password,
1190 cli_cmd_flag_sensitive,
1191 "<network id> <password> = change password for an SSID" },
1192 { "pin", wpa_cli_cmd_pin,
1193 cli_cmd_flag_sensitive,
1194 "<network id> <pin> = configure pin for an SSID" },
1195 { "otp", wpa_cli_cmd_otp,
1196 cli_cmd_flag_sensitive,
1197 "<network id> <password> = configure one-time-password for an SSID"
1199 { "passphrase", wpa_cli_cmd_passphrase,
1200 cli_cmd_flag_sensitive,
1201 "<network id> <passphrase> = configure private key passphrase\n"
1203 { "bssid", wpa_cli_cmd_bssid,
1205 "<network id> <BSSID> = set preferred BSSID for an SSID" },
1206 { "list_networks", wpa_cli_cmd_list_networks,
1208 "= list configured networks" },
1209 { "select_network", wpa_cli_cmd_select_network,
1211 "<network id> = select a network (disable others)" },
1212 { "enable_network", wpa_cli_cmd_enable_network,
1214 "<network id> = enable a network" },
1215 { "disable_network", wpa_cli_cmd_disable_network,
1217 "<network id> = disable a network" },
1218 { "add_network", wpa_cli_cmd_add_network,
1220 "= add a network" },
1221 { "remove_network", wpa_cli_cmd_remove_network,
1223 "<network id> = remove a network" },
1224 { "set_network", wpa_cli_cmd_set_network,
1225 cli_cmd_flag_sensitive,
1226 "<network id> <variable> <value> = set network variables (shows\n"
1227 " list of variables when run without arguments)" },
1228 { "get_network", wpa_cli_cmd_get_network,
1230 "<network id> <variable> = get network variables" },
1231 { "save_config", wpa_cli_cmd_save_config,
1233 "= save the current configuration" },
1234 { "disconnect", wpa_cli_cmd_disconnect,
1236 "= disconnect and wait for reassociate/reconnect command before\n"
1238 { "reconnect", wpa_cli_cmd_reconnect,
1240 "= like reassociate, but only takes effect if already disconnected"
1242 { "scan", wpa_cli_cmd_scan,
1244 "= request new BSS scan" },
1245 { "scan_results", wpa_cli_cmd_scan_results,
1247 "= get latest scan results" },
1248 { "bss", wpa_cli_cmd_bss,
1250 "<<idx> | <bssid>> = get detailed scan result info" },
1251 { "get_capability", wpa_cli_cmd_get_capability,
1253 "<eap/pairwise/group/key_mgmt/proto/auth_alg> = get capabilies" },
1254 { "reconfigure", wpa_cli_cmd_reconfigure,
1256 "= force wpa_supplicant to re-read its configuration file" },
1257 { "terminate", wpa_cli_cmd_terminate,
1259 "= terminate wpa_supplicant" },
1260 { "interface_add", wpa_cli_cmd_interface_add,
1262 "<ifname> <confname> <driver> <ctrl_interface> <driver_param>\n"
1263 " <bridge_name> = adds new interface, all parameters but <ifname>\n"
1265 { "interface_remove", wpa_cli_cmd_interface_remove,
1267 "<ifname> = removes the interface" },
1268 { "interface_list", wpa_cli_cmd_interface_list,
1270 "= list available interfaces" },
1271 { "ap_scan", wpa_cli_cmd_ap_scan,
1273 "<value> = set ap_scan parameter" },
1274 { "stkstart", wpa_cli_cmd_stkstart,
1276 "<addr> = request STK negotiation with <addr>" },
1277 { "ft_ds", wpa_cli_cmd_ft_ds,
1279 "<addr> = request over-the-DS FT with <addr>" },
1280 { "wps_pbc", wpa_cli_cmd_wps_pbc,
1282 "[BSSID] = start Wi-Fi Protected Setup: Push Button Configuration" },
1283 { "wps_pin", wpa_cli_cmd_wps_pin,
1284 cli_cmd_flag_sensitive,
1285 "<BSSID> [PIN] = start WPS PIN method (returns PIN, if not "
1287 #ifdef CONFIG_WPS_OOB
1288 { "wps_oob", wpa_cli_cmd_wps_oob,
1289 cli_cmd_flag_sensitive,
1290 "<OOB_DEV_TYPE> <OOB_PATH> <OOB_METHOD> = start WPS OOB" },
1291 #endif /* CONFIG_WPS_OOB */
1292 { "wps_reg", wpa_cli_cmd_wps_reg,
1293 cli_cmd_flag_sensitive,
1294 "<BSSID> <AP PIN> = start WPS Registrar to configure an AP" },
1295 { "ibss_rsn", wpa_cli_cmd_ibss_rsn,
1297 "<addr> = request RSN authentication with <addr> in IBSS" },
1298 { NULL, NULL, cli_cmd_flag_none, NULL }
1303 * Prints command usage, lines are padded with the specified string.
1305 static void print_cmd_help(struct wpa_cli_cmd *cmd, const char *pad)
1310 printf("%s%s ", pad, cmd->cmd);
1311 for (n = 0; (c = cmd->usage[n]); n++) {
1320 static void print_help(void)
1323 printf("commands:\n");
1324 for (n = 0; wpa_cli_commands[n].cmd; n++)
1325 print_cmd_help(&wpa_cli_commands[n], " ");
1329 #ifdef CONFIG_READLINE
1330 static int cmd_has_sensitive_data(const char *cmd)
1332 const char *c, *delim;
1336 delim = os_strchr(cmd, ' ');
1340 len = os_strlen(cmd);
1342 for (n = 0; (c = wpa_cli_commands[n].cmd); n++) {
1343 if (os_strncasecmp(cmd, c, len) == 0 && len == os_strlen(c))
1344 return (wpa_cli_commands[n].flags &
1345 cli_cmd_flag_sensitive);
1349 #endif /* CONFIG_READLINE */
1352 static int wpa_request(struct wpa_ctrl *ctrl, int argc, char *argv[])
1354 struct wpa_cli_cmd *cmd, *match = NULL;
1359 cmd = wpa_cli_commands;
1361 if (os_strncasecmp(cmd->cmd, argv[0], os_strlen(argv[0])) == 0)
1364 if (os_strcasecmp(cmd->cmd, argv[0]) == 0) {
1365 /* we have an exact match */
1375 printf("Ambiguous command '%s'; possible commands:", argv[0]);
1376 cmd = wpa_cli_commands;
1378 if (os_strncasecmp(cmd->cmd, argv[0],
1379 os_strlen(argv[0])) == 0) {
1380 printf(" %s", cmd->cmd);
1386 } else if (count == 0) {
1387 printf("Unknown command '%s'\n", argv[0]);
1390 ret = match->handler(ctrl, argc - 1, &argv[1]);
1397 static int str_match(const char *a, const char *b)
1399 return os_strncmp(a, b, os_strlen(b)) == 0;
1403 static int wpa_cli_exec(const char *program, const char *arg1,
1411 len = os_strlen(program) + os_strlen(arg1) + os_strlen(arg2) + 3;
1412 cmd = os_malloc(len);
1415 res = os_snprintf(cmd, len, "%s %s %s", program, arg1, arg2);
1416 if (res < 0 || (size_t) res >= len) {
1420 cmd[len - 1] = '\0';
1422 if (system(cmd) < 0)
1424 #endif /* _WIN32_WCE */
1431 static void wpa_cli_action_process(const char *msg)
1434 char *copy = NULL, *id, *pos2;
1439 pos = os_strchr(pos, '>');
1446 if (str_match(pos, WPA_EVENT_CONNECTED)) {
1448 os_unsetenv("WPA_ID");
1449 os_unsetenv("WPA_ID_STR");
1450 os_unsetenv("WPA_CTRL_DIR");
1452 pos = os_strstr(pos, "[id=");
1454 copy = os_strdup(pos + 4);
1458 while (*pos2 && *pos2 != ' ')
1462 os_setenv("WPA_ID", id, 1);
1463 while (*pos2 && *pos2 != '=')
1468 while (*pos2 && *pos2 != ']')
1471 os_setenv("WPA_ID_STR", id, 1);
1475 os_setenv("WPA_CTRL_DIR", ctrl_iface_dir, 1);
1477 if (!wpa_cli_connected || new_id != wpa_cli_last_id) {
1478 wpa_cli_connected = 1;
1479 wpa_cli_last_id = new_id;
1480 wpa_cli_exec(action_file, ctrl_ifname, "CONNECTED");
1482 } else if (str_match(pos, WPA_EVENT_DISCONNECTED)) {
1483 if (wpa_cli_connected) {
1484 wpa_cli_connected = 0;
1485 wpa_cli_exec(action_file, ctrl_ifname, "DISCONNECTED");
1487 } else if (str_match(pos, WPA_EVENT_TERMINATING)) {
1488 printf("wpa_supplicant is terminating - stop monitoring\n");
1494 #ifndef CONFIG_ANSI_C_EXTRA
1495 static void wpa_cli_action_cb(char *msg, size_t len)
1497 wpa_cli_action_process(msg);
1499 #endif /* CONFIG_ANSI_C_EXTRA */
1502 static void wpa_cli_reconnect(void)
1504 wpa_cli_close_connection();
1505 ctrl_conn = wpa_cli_open_connection(ctrl_ifname);
1507 printf("Connection to wpa_supplicant re-established\n");
1508 if (wpa_ctrl_attach(ctrl_conn) == 0) {
1509 wpa_cli_attached = 1;
1511 printf("Warning: Failed to attach to "
1512 "wpa_supplicant.\n");
1518 static void wpa_cli_recv_pending(struct wpa_ctrl *ctrl, int in_read,
1522 if (ctrl_conn == NULL) {
1523 wpa_cli_reconnect();
1526 while (wpa_ctrl_pending(ctrl) > 0) {
1528 size_t len = sizeof(buf) - 1;
1529 if (wpa_ctrl_recv(ctrl, buf, &len) == 0) {
1532 wpa_cli_action_process(buf);
1534 if (in_read && first)
1537 printf("%s\n", buf);
1540 printf("Could not read pending message.\n");
1545 if (wpa_ctrl_pending(ctrl) < 0) {
1546 printf("Connection to wpa_supplicant lost - trying to "
1548 wpa_cli_reconnect();
1553 #ifdef CONFIG_READLINE
1554 static char * wpa_cli_cmd_gen(const char *text, int state)
1561 len = os_strlen(text);
1564 while ((cmd = wpa_cli_commands[i].cmd)) {
1566 if (os_strncasecmp(cmd, text, len) == 0)
1567 return os_strdup(cmd);
1574 static char * wpa_cli_dummy_gen(const char *text, int state)
1580 static char ** wpa_cli_completion(const char *text, int start, int end)
1582 return rl_completion_matches(text, start == 0 ?
1583 wpa_cli_cmd_gen : wpa_cli_dummy_gen);
1585 #endif /* CONFIG_READLINE */
1588 static void wpa_cli_interactive(void)
1591 char cmdbuf[256], *cmd, *argv[max_args], *pos;
1593 #ifdef CONFIG_READLINE
1594 char *home, *hfile = NULL;
1595 #endif /* CONFIG_READLINE */
1597 printf("\nInteractive mode\n\n");
1599 #ifdef CONFIG_READLINE
1600 rl_attempted_completion_function = wpa_cli_completion;
1601 home = getenv("HOME");
1603 const char *fname = ".wpa_cli_history";
1604 int hfile_len = os_strlen(home) + 1 + os_strlen(fname) + 1;
1605 hfile = os_malloc(hfile_len);
1608 res = os_snprintf(hfile, hfile_len, "%s/%s", home,
1610 if (res >= 0 && res < hfile_len) {
1611 hfile[hfile_len - 1] = '\0';
1612 read_history(hfile);
1613 stifle_history(100);
1617 #endif /* CONFIG_READLINE */
1620 wpa_cli_recv_pending(ctrl_conn, 0, 0);
1621 #ifndef CONFIG_NATIVE_WINDOWS
1622 alarm(ping_interval);
1623 #endif /* CONFIG_NATIVE_WINDOWS */
1624 #ifdef CONFIG_READLINE
1625 cmd = readline("> ");
1628 while (next_history())
1630 h = previous_history();
1631 if (h == NULL || os_strcmp(cmd, h->line) != 0)
1635 #else /* CONFIG_READLINE */
1637 cmd = fgets(cmdbuf, sizeof(cmdbuf), stdin);
1638 #endif /* CONFIG_READLINE */
1639 #ifndef CONFIG_NATIVE_WINDOWS
1641 #endif /* CONFIG_NATIVE_WINDOWS */
1644 wpa_cli_recv_pending(ctrl_conn, 0, 0);
1646 while (*pos != '\0') {
1662 if (argc == max_args)
1665 char *pos2 = os_strrchr(pos, '"');
1669 while (*pos != '\0' && *pos != ' ')
1675 wpa_request(ctrl_conn, argc, argv);
1679 } while (!wpa_cli_quit);
1681 #ifdef CONFIG_READLINE
1683 /* Save command history, excluding lines that may contain
1687 while ((h = current_history())) {
1689 while (*p == ' ' || *p == '\t')
1691 if (cmd_has_sensitive_data(p)) {
1692 h = remove_history(where_history());
1702 write_history(hfile);
1705 #endif /* CONFIG_READLINE */
1709 static void wpa_cli_action(struct wpa_ctrl *ctrl)
1711 #ifdef CONFIG_ANSI_C_EXTRA
1712 /* TODO: ANSI C version(?) */
1713 printf("Action processing not supported in ANSI C build.\n");
1714 #else /* CONFIG_ANSI_C_EXTRA */
1718 char buf[256]; /* note: large enough to fit in unsolicited messages */
1721 fd = wpa_ctrl_get_fd(ctrl);
1723 while (!wpa_cli_quit) {
1726 tv.tv_sec = ping_interval;
1728 res = select(fd + 1, &rfds, NULL, NULL, &tv);
1729 if (res < 0 && errno != EINTR) {
1734 if (FD_ISSET(fd, &rfds))
1735 wpa_cli_recv_pending(ctrl, 0, 1);
1737 /* verify that connection is still working */
1738 len = sizeof(buf) - 1;
1739 if (wpa_ctrl_request(ctrl, "PING", 4, buf, &len,
1740 wpa_cli_action_cb) < 0 ||
1741 len < 4 || os_memcmp(buf, "PONG", 4) != 0) {
1742 printf("wpa_supplicant did not reply to PING "
1743 "command - exiting\n");
1748 #endif /* CONFIG_ANSI_C_EXTRA */
1752 static void wpa_cli_cleanup(void)
1754 wpa_cli_close_connection();
1756 os_daemonize_terminate(pid_file);
1758 os_program_deinit();
1761 static void wpa_cli_terminate(int sig)
1768 #ifndef CONFIG_NATIVE_WINDOWS
1769 static void wpa_cli_alarm(int sig)
1771 if (ctrl_conn && _wpa_ctrl_command(ctrl_conn, "PING", 0)) {
1772 printf("Connection to wpa_supplicant lost - trying to "
1774 wpa_cli_close_connection();
1777 wpa_cli_reconnect();
1779 wpa_cli_recv_pending(ctrl_conn, 1, 0);
1780 alarm(ping_interval);
1782 #endif /* CONFIG_NATIVE_WINDOWS */
1785 static char * wpa_cli_get_default_ifname(void)
1787 char *ifname = NULL;
1789 #ifdef CONFIG_CTRL_IFACE_UNIX
1790 struct dirent *dent;
1791 DIR *dir = opendir(ctrl_iface_dir);
1794 while ((dent = readdir(dir))) {
1795 #ifdef _DIRENT_HAVE_D_TYPE
1797 * Skip the file if it is not a socket. Also accept
1798 * DT_UNKNOWN (0) in case the C library or underlying
1799 * file system does not support d_type.
1801 if (dent->d_type != DT_SOCK && dent->d_type != DT_UNKNOWN)
1803 #endif /* _DIRENT_HAVE_D_TYPE */
1804 if (os_strcmp(dent->d_name, ".") == 0 ||
1805 os_strcmp(dent->d_name, "..") == 0)
1807 printf("Selected interface '%s'\n", dent->d_name);
1808 ifname = os_strdup(dent->d_name);
1812 #endif /* CONFIG_CTRL_IFACE_UNIX */
1814 #ifdef CONFIG_CTRL_IFACE_NAMED_PIPE
1815 char buf[2048], *pos;
1817 struct wpa_ctrl *ctrl;
1820 ctrl = wpa_ctrl_open(NULL);
1824 len = sizeof(buf) - 1;
1825 ret = wpa_ctrl_request(ctrl, "INTERFACES", 10, buf, &len, NULL);
1828 pos = os_strchr(buf, '\n');
1831 ifname = os_strdup(buf);
1833 wpa_ctrl_close(ctrl);
1834 #endif /* CONFIG_CTRL_IFACE_NAMED_PIPE */
1840 int main(int argc, char *argv[])
1843 int warning_displayed = 0;
1847 const char *global = NULL;
1849 if (os_program_init())
1853 c = getopt(argc, argv, "a:Bg:G:hi:p:P:v");
1858 action_file = optarg;
1867 ping_interval = atoi(optarg);
1873 printf("%s\n", wpa_cli_version);
1876 os_free(ctrl_ifname);
1877 ctrl_ifname = os_strdup(optarg);
1880 ctrl_iface_dir = optarg;
1891 interactive = (argc == optind) && (action_file == NULL);
1894 printf("%s\n\n%s\n\n", wpa_cli_version, wpa_cli_license);
1897 #ifdef CONFIG_CTRL_IFACE_NAMED_PIPE
1898 ctrl_conn = wpa_ctrl_open(NULL);
1899 #else /* CONFIG_CTRL_IFACE_NAMED_PIPE */
1900 ctrl_conn = wpa_ctrl_open(global);
1901 #endif /* CONFIG_CTRL_IFACE_NAMED_PIPE */
1902 if (ctrl_conn == NULL) {
1903 perror("Failed to connect to wpa_supplicant - "
1910 if (ctrl_ifname == NULL)
1911 ctrl_ifname = wpa_cli_get_default_ifname();
1912 ctrl_conn = wpa_cli_open_connection(ctrl_ifname);
1914 if (warning_displayed)
1915 printf("Connection established.\n");
1920 perror("Failed to connect to wpa_supplicant - "
1925 if (!warning_displayed) {
1926 printf("Could not connect to wpa_supplicant - "
1928 warning_displayed = 1;
1935 signal(SIGINT, wpa_cli_terminate);
1936 signal(SIGTERM, wpa_cli_terminate);
1937 #endif /* _WIN32_WCE */
1938 #ifndef CONFIG_NATIVE_WINDOWS
1939 signal(SIGALRM, wpa_cli_alarm);
1940 #endif /* CONFIG_NATIVE_WINDOWS */
1942 if (interactive || action_file) {
1943 if (wpa_ctrl_attach(ctrl_conn) == 0) {
1944 wpa_cli_attached = 1;
1946 printf("Warning: Failed to attach to "
1947 "wpa_supplicant.\n");
1953 if (daemonize && os_daemonize(pid_file))
1957 wpa_cli_interactive();
1958 else if (action_file)
1959 wpa_cli_action(ctrl_conn);
1961 ret = wpa_request(ctrl_conn, argc - optind, &argv[optind]);
1963 os_free(ctrl_ifname);
1969 #else /* CONFIG_CTRL_IFACE */
1970 int main(int argc, char *argv[])
1972 printf("CONFIG_CTRL_IFACE not defined - wpa_cli disabled\n");
1975 #endif /* CONFIG_CTRL_IFACE */