2 * WPA Supplicant - command line interface for wpa_supplicant daemon
3 * Copyright (c) 2004-2012, Jouni Malinen <j@w1.fi>
5 * This software may be distributed under the terms of the BSD license.
6 * See README for more details.
11 #ifdef CONFIG_CTRL_IFACE
13 #ifdef CONFIG_CTRL_IFACE_UNIX
15 #endif /* CONFIG_CTRL_IFACE_UNIX */
17 #include "common/wpa_ctrl.h"
18 #include "utils/common.h"
19 #include "utils/eloop.h"
20 #include "utils/edit.h"
21 #include "utils/list.h"
22 #include "common/version.h"
23 #include "common/ieee802_11_defs.h"
25 #include <cutils/properties.h>
29 static const char *wpa_cli_version
=
30 "wpa_cli v" VERSION_STR
"\n"
31 "Copyright (c) 2004-2012, Jouni Malinen <j@w1.fi> and contributors";
34 static const char *wpa_cli_license
=
35 "This software may be distributed under the terms of the BSD license.\n"
36 "See README for more details.\n";
38 static const char *wpa_cli_full_license
=
39 "This software may be distributed under the terms of the BSD license.\n"
41 "Redistribution and use in source and binary forms, with or without\n"
42 "modification, are permitted provided that the following conditions are\n"
45 "1. Redistributions of source code must retain the above copyright\n"
46 " notice, this list of conditions and the following disclaimer.\n"
48 "2. Redistributions in binary form must reproduce the above copyright\n"
49 " notice, this list of conditions and the following disclaimer in the\n"
50 " documentation and/or other materials provided with the distribution.\n"
52 "3. Neither the name(s) of the above-listed copyright holder(s) nor the\n"
53 " names of its contributors may be used to endorse or promote products\n"
54 " derived from this software without specific prior written permission.\n"
56 "THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n"
57 "\"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n"
58 "LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n"
59 "A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n"
60 "OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n"
61 "SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n"
62 "LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n"
63 "DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n"
64 "THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n"
65 "(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n"
66 "OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n"
69 static struct wpa_ctrl
*ctrl_conn
;
70 static struct wpa_ctrl
*mon_conn
;
71 static int wpa_cli_quit
= 0;
72 static int wpa_cli_attached
= 0;
73 static int wpa_cli_connected
= 0;
74 static int wpa_cli_last_id
= 0;
75 #ifndef CONFIG_CTRL_IFACE_DIR
76 #define CONFIG_CTRL_IFACE_DIR "/var/run/wpa_supplicant"
77 #endif /* CONFIG_CTRL_IFACE_DIR */
78 static const char *ctrl_iface_dir
= CONFIG_CTRL_IFACE_DIR
;
79 static char *ctrl_ifname
= NULL
;
80 static const char *pid_file
= NULL
;
81 static const char *action_file
= NULL
;
82 static int ping_interval
= 5;
83 static int interactive
= 0;
85 struct cli_txt_entry
{
90 static DEFINE_DL_LIST(bsses
); /* struct cli_txt_entry */
91 static DEFINE_DL_LIST(p2p_peers
); /* struct cli_txt_entry */
92 static DEFINE_DL_LIST(p2p_groups
); /* struct cli_txt_entry */
95 static void print_help(void);
96 static void wpa_cli_mon_receive(int sock
, void *eloop_ctx
, void *sock_ctx
);
97 static void wpa_cli_close_connection(void);
100 static void usage(void)
102 printf("wpa_cli [-p<path to ctrl sockets>] [-i<ifname>] [-hvB] "
103 "[-a<action file>] \\\n"
104 " [-P<pid file>] [-g<global ctrl>] [-G<ping interval>] "
106 " -h = help (show this usage text)\n"
107 " -v = shown version information\n"
108 " -a = run in daemon mode executing the action file based on "
111 " -B = run a daemon in the background\n"
112 " default path: " CONFIG_CTRL_IFACE_DIR
"\n"
113 " default interface: first interface found in socket path\n");
118 static void cli_txt_list_free(struct cli_txt_entry
*e
)
120 dl_list_del(&e
->list
);
126 static void cli_txt_list_flush(struct dl_list
*list
)
128 struct cli_txt_entry
*e
;
129 while ((e
= dl_list_first(list
, struct cli_txt_entry
, list
)))
130 cli_txt_list_free(e
);
134 static struct cli_txt_entry
* cli_txt_list_get(struct dl_list
*txt_list
,
137 struct cli_txt_entry
*e
;
138 dl_list_for_each(e
, txt_list
, struct cli_txt_entry
, list
) {
139 if (os_strcmp(e
->txt
, txt
) == 0)
146 static void cli_txt_list_del(struct dl_list
*txt_list
, const char *txt
)
148 struct cli_txt_entry
*e
;
149 e
= cli_txt_list_get(txt_list
, txt
);
151 cli_txt_list_free(e
);
155 static void cli_txt_list_del_addr(struct dl_list
*txt_list
, const char *txt
)
159 if (hwaddr_aton(txt
, addr
) < 0)
161 os_snprintf(buf
, sizeof(buf
), MACSTR
, MAC2STR(addr
));
162 cli_txt_list_del(txt_list
, buf
);
167 static void cli_txt_list_del_word(struct dl_list
*txt_list
, const char *txt
)
171 end
= os_strchr(txt
, ' ');
173 end
= txt
+ os_strlen(txt
);
174 buf
= os_malloc(end
- txt
+ 1);
177 os_memcpy(buf
, txt
, end
- txt
);
178 buf
[end
- txt
] = '\0';
179 cli_txt_list_del(txt_list
, buf
);
182 #endif /* CONFIG_P2P */
185 static int cli_txt_list_add(struct dl_list
*txt_list
, const char *txt
)
187 struct cli_txt_entry
*e
;
188 e
= cli_txt_list_get(txt_list
, txt
);
191 e
= os_zalloc(sizeof(*e
));
194 e
->txt
= os_strdup(txt
);
195 if (e
->txt
== NULL
) {
199 dl_list_add(txt_list
, &e
->list
);
205 static int cli_txt_list_add_addr(struct dl_list
*txt_list
, const char *txt
)
209 if (hwaddr_aton(txt
, addr
) < 0)
211 os_snprintf(buf
, sizeof(buf
), MACSTR
, MAC2STR(addr
));
212 return cli_txt_list_add(txt_list
, buf
);
216 static int cli_txt_list_add_word(struct dl_list
*txt_list
, const char *txt
)
221 end
= os_strchr(txt
, ' ');
223 end
= txt
+ os_strlen(txt
);
224 buf
= os_malloc(end
- txt
+ 1);
227 os_memcpy(buf
, txt
, end
- txt
);
228 buf
[end
- txt
] = '\0';
229 ret
= cli_txt_list_add(txt_list
, buf
);
233 #endif /* CONFIG_P2P */
236 static char ** cli_txt_list_array(struct dl_list
*txt_list
)
238 unsigned int i
, count
= dl_list_len(txt_list
);
240 struct cli_txt_entry
*e
;
242 res
= os_zalloc((count
+ 1) * sizeof(char *));
247 dl_list_for_each(e
, txt_list
, struct cli_txt_entry
, list
) {
248 res
[i
] = os_strdup(e
->txt
);
258 static int get_cmd_arg_num(const char *str
, int pos
)
262 for (i
= 0; i
<= pos
; i
++) {
265 while (i
<= pos
&& str
[i
] != ' ')
276 static int str_starts(const char *src
, const char *match
)
278 return os_strncmp(src
, match
, os_strlen(match
)) == 0;
282 static int wpa_cli_show_event(const char *event
)
286 start
= os_strchr(event
, '>');
292 * Skip BSS added/removed events since they can be relatively frequent
293 * and are likely of not much use for an interactive user.
295 if (str_starts(start
, WPA_EVENT_BSS_ADDED
) ||
296 str_starts(start
, WPA_EVENT_BSS_REMOVED
))
303 static int wpa_cli_open_connection(const char *ifname
, int attach
)
305 #if defined(CONFIG_CTRL_IFACE_UDP) || defined(CONFIG_CTRL_IFACE_NAMED_PIPE)
306 ctrl_conn
= wpa_ctrl_open(ifname
);
307 if (ctrl_conn
== NULL
)
310 if (attach
&& interactive
)
311 mon_conn
= wpa_ctrl_open(ifname
);
314 #else /* CONFIG_CTRL_IFACE_UDP || CONFIG_CTRL_IFACE_NAMED_PIPE */
322 if (access(ctrl_iface_dir
, F_OK
) < 0) {
323 cfile
= os_strdup(ifname
);
330 flen
= os_strlen(ctrl_iface_dir
) + os_strlen(ifname
) + 2;
331 cfile
= os_malloc(flen
);
334 res
= os_snprintf(cfile
, flen
, "%s/%s", ctrl_iface_dir
,
336 if (res
< 0 || res
>= flen
) {
342 ctrl_conn
= wpa_ctrl_open(cfile
);
343 if (ctrl_conn
== NULL
) {
348 if (attach
&& interactive
)
349 mon_conn
= wpa_ctrl_open(cfile
);
353 #endif /* CONFIG_CTRL_IFACE_UDP || CONFIG_CTRL_IFACE_NAMED_PIPE */
356 if (wpa_ctrl_attach(mon_conn
) == 0) {
357 wpa_cli_attached
= 1;
359 eloop_register_read_sock(
360 wpa_ctrl_get_fd(mon_conn
),
361 wpa_cli_mon_receive
, NULL
, NULL
);
363 printf("Warning: Failed to attach to "
364 "wpa_supplicant.\n");
365 wpa_cli_close_connection();
374 static void wpa_cli_close_connection(void)
376 if (ctrl_conn
== NULL
)
379 if (wpa_cli_attached
) {
380 wpa_ctrl_detach(interactive
? mon_conn
: ctrl_conn
);
381 wpa_cli_attached
= 0;
383 wpa_ctrl_close(ctrl_conn
);
386 eloop_unregister_read_sock(wpa_ctrl_get_fd(mon_conn
));
387 wpa_ctrl_close(mon_conn
);
393 static void wpa_cli_msg_cb(char *msg
, size_t len
)
399 static int _wpa_ctrl_command(struct wpa_ctrl
*ctrl
, char *cmd
, int print
)
405 if (ctrl_conn
== NULL
) {
406 printf("Not connected to wpa_supplicant - command dropped.\n");
409 len
= sizeof(buf
) - 1;
410 ret
= wpa_ctrl_request(ctrl
, cmd
, os_strlen(cmd
), buf
, &len
,
413 printf("'%s' command timed out.\n", cmd
);
415 } else if (ret
< 0) {
416 printf("'%s' command failed.\n", cmd
);
422 if (interactive
&& len
> 0 && buf
[len
- 1] != '\n')
429 static int wpa_ctrl_command(struct wpa_ctrl
*ctrl
, char *cmd
)
431 return _wpa_ctrl_command(ctrl
, cmd
, 1);
435 static int wpa_cli_cmd_ifname(struct wpa_ctrl
*ctrl
, int argc
, char *argv
[])
437 return wpa_ctrl_command(ctrl
, "IFNAME");
441 static int wpa_cli_cmd_status(struct wpa_ctrl
*ctrl
, int argc
, char *argv
[])
443 if (argc
> 0 && os_strcmp(argv
[0], "verbose") == 0)
444 return wpa_ctrl_command(ctrl
, "STATUS-VERBOSE");
445 if (argc
> 0 && os_strcmp(argv
[0], "wps") == 0)
446 return wpa_ctrl_command(ctrl
, "STATUS-WPS");
447 return wpa_ctrl_command(ctrl
, "STATUS");
451 static int wpa_cli_cmd_ping(struct wpa_ctrl
*ctrl
, int argc
, char *argv
[])
453 return wpa_ctrl_command(ctrl
, "PING");
457 static int wpa_cli_cmd_relog(struct wpa_ctrl
*ctrl
, int argc
, char *argv
[])
459 return wpa_ctrl_command(ctrl
, "RELOG");
463 static int wpa_cli_cmd_note(struct wpa_ctrl
*ctrl
, int argc
, char *argv
[])
469 ret
= os_snprintf(cmd
, sizeof(cmd
), "NOTE %s", argv
[0]);
470 if (ret
< 0 || (size_t) ret
>= sizeof(cmd
))
472 return wpa_ctrl_command(ctrl
, cmd
);
476 static int wpa_cli_cmd_mib(struct wpa_ctrl
*ctrl
, int argc
, char *argv
[])
478 return wpa_ctrl_command(ctrl
, "MIB");
482 static int wpa_cli_cmd_pmksa(struct wpa_ctrl
*ctrl
, int argc
, char *argv
[])
484 return wpa_ctrl_command(ctrl
, "PMKSA");
488 static int wpa_cli_cmd_help(struct wpa_ctrl
*ctrl
, int argc
, char *argv
[])
495 static int wpa_cli_cmd_license(struct wpa_ctrl
*ctrl
, int argc
, char *argv
[])
497 printf("%s\n\n%s\n", wpa_cli_version
, wpa_cli_full_license
);
502 static int wpa_cli_cmd_quit(struct wpa_ctrl
*ctrl
, int argc
, char *argv
[])
511 static void wpa_cli_show_variables(void)
513 printf("set variables:\n"
514 " EAPOL::heldPeriod (EAPOL state machine held period, "
516 " EAPOL::authPeriod (EAPOL state machine authentication "
517 "period, in seconds)\n"
518 " EAPOL::startPeriod (EAPOL state machine start period, in "
520 " EAPOL::maxStart (EAPOL state machine maximum start "
522 printf(" dot11RSNAConfigPMKLifetime (WPA/WPA2 PMK lifetime in "
524 " dot11RSNAConfigPMKReauthThreshold (WPA/WPA2 reauthentication"
525 " threshold\n\tpercentage)\n"
526 " dot11RSNAConfigSATimeout (WPA/WPA2 timeout for completing "
527 "security\n\tassociation in seconds)\n");
531 static int wpa_cli_cmd_set(struct wpa_ctrl
*ctrl
, int argc
, char *argv
[])
537 wpa_cli_show_variables();
541 if (argc
!= 1 && argc
!= 2) {
542 printf("Invalid SET command: needs two arguments (variable "
543 "name and value)\n");
548 res
= os_snprintf(cmd
, sizeof(cmd
), "SET %s ", argv
[0]);
550 res
= os_snprintf(cmd
, sizeof(cmd
), "SET %s %s",
552 if (res
< 0 || (size_t) res
>= sizeof(cmd
) - 1) {
553 printf("Too long SET command.\n");
556 return wpa_ctrl_command(ctrl
, cmd
);
560 static int wpa_cli_cmd_get(struct wpa_ctrl
*ctrl
, int argc
, char *argv
[])
566 printf("Invalid GET command: need one argument (variable "
571 res
= os_snprintf(cmd
, sizeof(cmd
), "GET %s", argv
[0]);
572 if (res
< 0 || (size_t) res
>= sizeof(cmd
) - 1) {
573 printf("Too long GET command.\n");
576 return wpa_ctrl_command(ctrl
, cmd
);
580 static int wpa_cli_cmd_logoff(struct wpa_ctrl
*ctrl
, int argc
, char *argv
[])
582 return wpa_ctrl_command(ctrl
, "LOGOFF");
586 static int wpa_cli_cmd_logon(struct wpa_ctrl
*ctrl
, int argc
, char *argv
[])
588 return wpa_ctrl_command(ctrl
, "LOGON");
592 static int wpa_cli_cmd_reassociate(struct wpa_ctrl
*ctrl
, int argc
,
595 return wpa_ctrl_command(ctrl
, "REASSOCIATE");
599 static int wpa_cli_cmd_preauthenticate(struct wpa_ctrl
*ctrl
, int argc
,
606 printf("Invalid PREAUTH command: needs one argument "
611 res
= os_snprintf(cmd
, sizeof(cmd
), "PREAUTH %s", argv
[0]);
612 if (res
< 0 || (size_t) res
>= sizeof(cmd
) - 1) {
613 printf("Too long PREAUTH command.\n");
616 return wpa_ctrl_command(ctrl
, cmd
);
620 static int wpa_cli_cmd_ap_scan(struct wpa_ctrl
*ctrl
, int argc
, char *argv
[])
626 printf("Invalid AP_SCAN command: needs one argument (ap_scan "
630 res
= os_snprintf(cmd
, sizeof(cmd
), "AP_SCAN %s", argv
[0]);
631 if (res
< 0 || (size_t) res
>= sizeof(cmd
) - 1) {
632 printf("Too long AP_SCAN command.\n");
635 return wpa_ctrl_command(ctrl
, cmd
);
639 static int wpa_cli_cmd_scan_interval(struct wpa_ctrl
*ctrl
, int argc
,
646 printf("Invalid SCAN_INTERVAL command: needs one argument "
647 "scan_interval value)\n");
650 res
= os_snprintf(cmd
, sizeof(cmd
), "SCAN_INTERVAL %s", argv
[0]);
651 if (res
< 0 || (size_t) res
>= sizeof(cmd
) - 1) {
652 printf("Too long SCAN_INTERVAL command.\n");
655 return wpa_ctrl_command(ctrl
, cmd
);
659 static int wpa_cli_cmd_bss_expire_age(struct wpa_ctrl
*ctrl
, int argc
,
666 printf("Invalid BSS_EXPIRE_AGE command: needs one argument "
667 "(bss_expire_age value)\n");
670 res
= os_snprintf(cmd
, sizeof(cmd
), "BSS_EXPIRE_AGE %s", argv
[0]);
671 if (res
< 0 || (size_t) res
>= sizeof(cmd
) - 1) {
672 printf("Too long BSS_EXPIRE_AGE command.\n");
675 return wpa_ctrl_command(ctrl
, cmd
);
679 static int wpa_cli_cmd_bss_expire_count(struct wpa_ctrl
*ctrl
, int argc
,
686 printf("Invalid BSS_EXPIRE_COUNT command: needs one argument "
687 "(bss_expire_count value)\n");
690 res
= os_snprintf(cmd
, sizeof(cmd
), "BSS_EXPIRE_COUNT %s", argv
[0]);
691 if (res
< 0 || (size_t) res
>= sizeof(cmd
) - 1) {
692 printf("Too long BSS_EXPIRE_COUNT command.\n");
695 return wpa_ctrl_command(ctrl
, cmd
);
699 static int wpa_cli_cmd_stkstart(struct wpa_ctrl
*ctrl
, int argc
,
706 printf("Invalid STKSTART command: needs one argument "
707 "(Peer STA MAC address)\n");
711 res
= os_snprintf(cmd
, sizeof(cmd
), "STKSTART %s", argv
[0]);
712 if (res
< 0 || (size_t) res
>= sizeof(cmd
) - 1) {
713 printf("Too long STKSTART command.\n");
716 return wpa_ctrl_command(ctrl
, cmd
);
720 static int wpa_cli_cmd_ft_ds(struct wpa_ctrl
*ctrl
, int argc
, char *argv
[])
726 printf("Invalid FT_DS command: needs one argument "
727 "(Target AP MAC address)\n");
731 res
= os_snprintf(cmd
, sizeof(cmd
), "FT_DS %s", argv
[0]);
732 if (res
< 0 || (size_t) res
>= sizeof(cmd
) - 1) {
733 printf("Too long FT_DS command.\n");
736 return wpa_ctrl_command(ctrl
, cmd
);
740 static int wpa_cli_cmd_wps_pbc(struct wpa_ctrl
*ctrl
, int argc
, char *argv
[])
747 return wpa_ctrl_command(ctrl
, "WPS_PBC");
751 res
= os_snprintf(cmd
, sizeof(cmd
), "WPS_PBC %s", argv
[0]);
752 if (res
< 0 || (size_t) res
>= sizeof(cmd
) - 1) {
753 printf("Too long WPS_PBC command.\n");
756 return wpa_ctrl_command(ctrl
, cmd
);
760 static int wpa_cli_cmd_wps_pin(struct wpa_ctrl
*ctrl
, int argc
, char *argv
[])
766 printf("Invalid WPS_PIN command: need one or two arguments:\n"
767 "- BSSID: use 'any' to select any\n"
768 "- PIN: optional, used only with devices that have no "
774 /* Use dynamically generated PIN (returned as reply) */
775 res
= os_snprintf(cmd
, sizeof(cmd
), "WPS_PIN %s", argv
[0]);
776 if (res
< 0 || (size_t) res
>= sizeof(cmd
) - 1) {
777 printf("Too long WPS_PIN command.\n");
780 return wpa_ctrl_command(ctrl
, cmd
);
783 /* Use hardcoded PIN from a label */
784 res
= os_snprintf(cmd
, sizeof(cmd
), "WPS_PIN %s %s", argv
[0], argv
[1]);
785 if (res
< 0 || (size_t) res
>= sizeof(cmd
) - 1) {
786 printf("Too long WPS_PIN command.\n");
789 return wpa_ctrl_command(ctrl
, cmd
);
793 static int wpa_cli_cmd_wps_check_pin(struct wpa_ctrl
*ctrl
, int argc
,
799 if (argc
!= 1 && argc
!= 2) {
800 printf("Invalid WPS_CHECK_PIN command: needs one argument:\n"
801 "- PIN to be verified\n");
806 res
= os_snprintf(cmd
, sizeof(cmd
), "WPS_CHECK_PIN %s %s",
809 res
= os_snprintf(cmd
, sizeof(cmd
), "WPS_CHECK_PIN %s",
811 if (res
< 0 || (size_t) res
>= sizeof(cmd
) - 1) {
812 printf("Too long WPS_CHECK_PIN command.\n");
815 return wpa_ctrl_command(ctrl
, cmd
);
819 static int wpa_cli_cmd_wps_cancel(struct wpa_ctrl
*ctrl
, int argc
,
822 return wpa_ctrl_command(ctrl
, "WPS_CANCEL");
826 #ifdef CONFIG_WPS_OOB
827 static int wpa_cli_cmd_wps_oob(struct wpa_ctrl
*ctrl
, int argc
, char *argv
[])
832 if (argc
!= 3 && argc
!= 4) {
833 printf("Invalid WPS_OOB command: need three or four "
835 "- DEV_TYPE: use 'ufd' or 'nfc'\n"
836 "- PATH: path of OOB device like '/mnt'\n"
837 "- METHOD: OOB method 'pin-e' or 'pin-r', "
839 "- DEV_NAME: (only for NFC) device name like "
845 res
= os_snprintf(cmd
, sizeof(cmd
), "WPS_OOB %s %s %s",
846 argv
[0], argv
[1], argv
[2]);
848 res
= os_snprintf(cmd
, sizeof(cmd
), "WPS_OOB %s %s %s %s",
849 argv
[0], argv
[1], argv
[2], argv
[3]);
850 if (res
< 0 || (size_t) res
>= sizeof(cmd
) - 1) {
851 printf("Too long WPS_OOB command.\n");
854 return wpa_ctrl_command(ctrl
, cmd
);
856 #endif /* CONFIG_WPS_OOB */
859 #ifdef CONFIG_WPS_NFC
861 static int wpa_cli_cmd_wps_nfc(struct wpa_ctrl
*ctrl
, int argc
, char *argv
[])
867 res
= os_snprintf(cmd
, sizeof(cmd
), "WPS_NFC %s",
870 res
= os_snprintf(cmd
, sizeof(cmd
), "WPS_NFC");
871 if (res
< 0 || (size_t) res
>= sizeof(cmd
) - 1) {
872 printf("Too long WPS_NFC command.\n");
875 return wpa_ctrl_command(ctrl
, cmd
);
879 static int wpa_cli_cmd_wps_nfc_token(struct wpa_ctrl
*ctrl
, int argc
,
886 printf("Invalid WPS_NFC_TOKEN command: need one argument:\n"
887 "format: WPS or NDEF\n");
891 res
= os_snprintf(cmd
, sizeof(cmd
), "WPS_NFC_TOKEN %s",
894 res
= os_snprintf(cmd
, sizeof(cmd
), "WPS_NFC_TOKEN");
895 if (res
< 0 || (size_t) res
>= sizeof(cmd
) - 1) {
896 printf("Too long WPS_NFC_TOKEN command.\n");
899 return wpa_ctrl_command(ctrl
, cmd
);
903 static int wpa_cli_cmd_wps_nfc_tag_read(struct wpa_ctrl
*ctrl
, int argc
,
911 printf("Invalid 'wps_nfc_tag_read' command - one argument "
916 buflen
= 18 + os_strlen(argv
[0]);
917 buf
= os_malloc(buflen
);
920 os_snprintf(buf
, buflen
, "WPS_NFC_TAG_READ %s", argv
[0]);
922 ret
= wpa_ctrl_command(ctrl
, buf
);
928 #endif /* CONFIG_WPS_NFC */
931 static int wpa_cli_cmd_wps_reg(struct wpa_ctrl
*ctrl
, int argc
, char *argv
[])
937 res
= os_snprintf(cmd
, sizeof(cmd
), "WPS_REG %s %s",
939 else if (argc
== 5 || argc
== 6) {
940 char ssid_hex
[2 * 32 + 1];
941 char key_hex
[2 * 64 + 1];
945 for (i
= 0; i
< 32; i
++) {
946 if (argv
[2][i
] == '\0')
948 os_snprintf(&ssid_hex
[i
* 2], 3, "%02x", argv
[2][i
]);
953 for (i
= 0; i
< 64; i
++) {
954 if (argv
[5][i
] == '\0')
956 os_snprintf(&key_hex
[i
* 2], 3, "%02x",
961 res
= os_snprintf(cmd
, sizeof(cmd
),
962 "WPS_REG %s %s %s %s %s %s",
963 argv
[0], argv
[1], ssid_hex
, argv
[3], argv
[4],
966 printf("Invalid WPS_REG command: need two arguments:\n"
967 "- BSSID of the target AP\n"
969 printf("Alternatively, six arguments can be used to "
970 "reconfigure the AP:\n"
971 "- BSSID of the target AP\n"
974 "- new auth (OPEN, WPAPSK, WPA2PSK)\n"
975 "- new encr (NONE, WEP, TKIP, CCMP)\n"
980 if (res
< 0 || (size_t) res
>= sizeof(cmd
) - 1) {
981 printf("Too long WPS_REG command.\n");
984 return wpa_ctrl_command(ctrl
, cmd
);
988 static int wpa_cli_cmd_wps_ap_pin(struct wpa_ctrl
*ctrl
, int argc
,
995 printf("Invalid WPS_AP_PIN command: needs at least one "
1001 res
= os_snprintf(cmd
, sizeof(cmd
), "WPS_AP_PIN %s %s %s",
1002 argv
[0], argv
[1], argv
[2]);
1004 res
= os_snprintf(cmd
, sizeof(cmd
), "WPS_AP_PIN %s %s",
1007 res
= os_snprintf(cmd
, sizeof(cmd
), "WPS_AP_PIN %s",
1009 if (res
< 0 || (size_t) res
>= sizeof(cmd
) - 1) {
1010 printf("Too long WPS_AP_PIN command.\n");
1013 return wpa_ctrl_command(ctrl
, cmd
);
1017 static int wpa_cli_cmd_wps_er_start(struct wpa_ctrl
*ctrl
, int argc
,
1022 os_snprintf(cmd
, sizeof(cmd
), "WPS_ER_START %s", argv
[0]);
1023 return wpa_ctrl_command(ctrl
, cmd
);
1025 return wpa_ctrl_command(ctrl
, "WPS_ER_START");
1029 static int wpa_cli_cmd_wps_er_stop(struct wpa_ctrl
*ctrl
, int argc
,
1032 return wpa_ctrl_command(ctrl
, "WPS_ER_STOP");
1037 static int wpa_cli_cmd_wps_er_pin(struct wpa_ctrl
*ctrl
, int argc
,
1044 printf("Invalid WPS_ER_PIN command: need at least two "
1046 "- UUID: use 'any' to select any\n"
1047 "- PIN: Enrollee PIN\n"
1048 "optional: - Enrollee MAC address\n");
1053 res
= os_snprintf(cmd
, sizeof(cmd
), "WPS_ER_PIN %s %s %s",
1054 argv
[0], argv
[1], argv
[2]);
1056 res
= os_snprintf(cmd
, sizeof(cmd
), "WPS_ER_PIN %s %s",
1058 if (res
< 0 || (size_t) res
>= sizeof(cmd
) - 1) {
1059 printf("Too long WPS_ER_PIN command.\n");
1062 return wpa_ctrl_command(ctrl
, cmd
);
1066 static int wpa_cli_cmd_wps_er_pbc(struct wpa_ctrl
*ctrl
, int argc
,
1073 printf("Invalid WPS_ER_PBC command: need one argument:\n"
1074 "- UUID: Specify the Enrollee\n");
1078 res
= os_snprintf(cmd
, sizeof(cmd
), "WPS_ER_PBC %s",
1080 if (res
< 0 || (size_t) res
>= sizeof(cmd
) - 1) {
1081 printf("Too long WPS_ER_PBC command.\n");
1084 return wpa_ctrl_command(ctrl
, cmd
);
1088 static int wpa_cli_cmd_wps_er_learn(struct wpa_ctrl
*ctrl
, int argc
,
1095 printf("Invalid WPS_ER_LEARN command: need two arguments:\n"
1096 "- UUID: specify which AP to use\n"
1101 res
= os_snprintf(cmd
, sizeof(cmd
), "WPS_ER_LEARN %s %s",
1103 if (res
< 0 || (size_t) res
>= sizeof(cmd
) - 1) {
1104 printf("Too long WPS_ER_LEARN command.\n");
1107 return wpa_ctrl_command(ctrl
, cmd
);
1111 static int wpa_cli_cmd_wps_er_set_config(struct wpa_ctrl
*ctrl
, int argc
,
1118 printf("Invalid WPS_ER_SET_CONFIG command: need two "
1120 "- UUID: specify which AP to use\n"
1121 "- Network configuration id\n");
1125 res
= os_snprintf(cmd
, sizeof(cmd
), "WPS_ER_SET_CONFIG %s %s",
1127 if (res
< 0 || (size_t) res
>= sizeof(cmd
) - 1) {
1128 printf("Too long WPS_ER_SET_CONFIG command.\n");
1131 return wpa_ctrl_command(ctrl
, cmd
);
1135 static int wpa_cli_cmd_wps_er_config(struct wpa_ctrl
*ctrl
, int argc
,
1141 if (argc
== 5 || argc
== 6) {
1142 char ssid_hex
[2 * 32 + 1];
1143 char key_hex
[2 * 64 + 1];
1147 for (i
= 0; i
< 32; i
++) {
1148 if (argv
[2][i
] == '\0')
1150 os_snprintf(&ssid_hex
[i
* 2], 3, "%02x", argv
[2][i
]);
1155 for (i
= 0; i
< 64; i
++) {
1156 if (argv
[5][i
] == '\0')
1158 os_snprintf(&key_hex
[i
* 2], 3, "%02x",
1163 res
= os_snprintf(cmd
, sizeof(cmd
),
1164 "WPS_ER_CONFIG %s %s %s %s %s %s",
1165 argv
[0], argv
[1], ssid_hex
, argv
[3], argv
[4],
1168 printf("Invalid WPS_ER_CONFIG command: need six arguments:\n"
1172 "- new auth (OPEN, WPAPSK, WPA2PSK)\n"
1173 "- new encr (NONE, WEP, TKIP, CCMP)\n"
1178 if (res
< 0 || (size_t) res
>= sizeof(cmd
) - 1) {
1179 printf("Too long WPS_ER_CONFIG command.\n");
1182 return wpa_ctrl_command(ctrl
, cmd
);
1186 #ifdef CONFIG_WPS_NFC
1187 static int wpa_cli_cmd_wps_er_nfc_config_token(struct wpa_ctrl
*ctrl
, int argc
,
1194 printf("Invalid WPS_ER_NFC_CONFIG_TOKEN command: need two "
1196 "- WPS/NDEF: token format\n"
1197 "- UUID: specify which AP to use\n");
1201 res
= os_snprintf(cmd
, sizeof(cmd
), "WPS_ER_NFC_CONFIG_TOKEN %s %s",
1203 if (res
< 0 || (size_t) res
>= sizeof(cmd
) - 1) {
1204 printf("Too long WPS_ER_NFC_CONFIG_TOKEN command.\n");
1207 return wpa_ctrl_command(ctrl
, cmd
);
1209 #endif /* CONFIG_WPS_NFC */
1212 static int wpa_cli_cmd_ibss_rsn(struct wpa_ctrl
*ctrl
, int argc
, char *argv
[])
1218 printf("Invalid IBSS_RSN command: needs one argument "
1219 "(Peer STA MAC address)\n");
1223 res
= os_snprintf(cmd
, sizeof(cmd
), "IBSS_RSN %s", argv
[0]);
1224 if (res
< 0 || (size_t) res
>= sizeof(cmd
) - 1) {
1225 printf("Too long IBSS_RSN command.\n");
1228 return wpa_ctrl_command(ctrl
, cmd
);
1232 static int wpa_cli_cmd_level(struct wpa_ctrl
*ctrl
, int argc
, char *argv
[])
1238 printf("Invalid LEVEL command: needs one argument (debug "
1242 res
= os_snprintf(cmd
, sizeof(cmd
), "LEVEL %s", argv
[0]);
1243 if (res
< 0 || (size_t) res
>= sizeof(cmd
) - 1) {
1244 printf("Too long LEVEL command.\n");
1247 return wpa_ctrl_command(ctrl
, cmd
);
1251 static int wpa_cli_cmd_identity(struct wpa_ctrl
*ctrl
, int argc
, char *argv
[])
1253 char cmd
[256], *pos
, *end
;
1257 printf("Invalid IDENTITY command: needs two arguments "
1258 "(network id and identity)\n");
1262 end
= cmd
+ sizeof(cmd
);
1264 ret
= os_snprintf(pos
, end
- pos
, WPA_CTRL_RSP
"IDENTITY-%s:%s",
1266 if (ret
< 0 || ret
>= end
- pos
) {
1267 printf("Too long IDENTITY command.\n");
1271 for (i
= 2; i
< argc
; i
++) {
1272 ret
= os_snprintf(pos
, end
- pos
, " %s", argv
[i
]);
1273 if (ret
< 0 || ret
>= end
- pos
) {
1274 printf("Too long IDENTITY command.\n");
1280 return wpa_ctrl_command(ctrl
, cmd
);
1284 static int wpa_cli_cmd_password(struct wpa_ctrl
*ctrl
, int argc
, char *argv
[])
1286 char cmd
[256], *pos
, *end
;
1290 printf("Invalid PASSWORD command: needs two arguments "
1291 "(network id and password)\n");
1295 end
= cmd
+ sizeof(cmd
);
1297 ret
= os_snprintf(pos
, end
- pos
, WPA_CTRL_RSP
"PASSWORD-%s:%s",
1299 if (ret
< 0 || ret
>= end
- pos
) {
1300 printf("Too long PASSWORD command.\n");
1304 for (i
= 2; i
< argc
; i
++) {
1305 ret
= os_snprintf(pos
, end
- pos
, " %s", argv
[i
]);
1306 if (ret
< 0 || ret
>= end
- pos
) {
1307 printf("Too long PASSWORD command.\n");
1313 return wpa_ctrl_command(ctrl
, cmd
);
1317 static int wpa_cli_cmd_new_password(struct wpa_ctrl
*ctrl
, int argc
,
1320 char cmd
[256], *pos
, *end
;
1324 printf("Invalid NEW_PASSWORD command: needs two arguments "
1325 "(network id and password)\n");
1329 end
= cmd
+ sizeof(cmd
);
1331 ret
= os_snprintf(pos
, end
- pos
, WPA_CTRL_RSP
"NEW_PASSWORD-%s:%s",
1333 if (ret
< 0 || ret
>= end
- pos
) {
1334 printf("Too long NEW_PASSWORD command.\n");
1338 for (i
= 2; i
< argc
; i
++) {
1339 ret
= os_snprintf(pos
, end
- pos
, " %s", argv
[i
]);
1340 if (ret
< 0 || ret
>= end
- pos
) {
1341 printf("Too long NEW_PASSWORD command.\n");
1347 return wpa_ctrl_command(ctrl
, cmd
);
1351 static int wpa_cli_cmd_pin(struct wpa_ctrl
*ctrl
, int argc
, char *argv
[])
1353 char cmd
[256], *pos
, *end
;
1357 printf("Invalid PIN command: needs two arguments "
1358 "(network id and pin)\n");
1362 end
= cmd
+ sizeof(cmd
);
1364 ret
= os_snprintf(pos
, end
- pos
, WPA_CTRL_RSP
"PIN-%s:%s",
1366 if (ret
< 0 || ret
>= end
- pos
) {
1367 printf("Too long PIN command.\n");
1371 for (i
= 2; i
< argc
; i
++) {
1372 ret
= os_snprintf(pos
, end
- pos
, " %s", argv
[i
]);
1373 if (ret
< 0 || ret
>= end
- pos
) {
1374 printf("Too long PIN command.\n");
1379 return wpa_ctrl_command(ctrl
, cmd
);
1383 static int wpa_cli_cmd_otp(struct wpa_ctrl
*ctrl
, int argc
, char *argv
[])
1385 char cmd
[256], *pos
, *end
;
1389 printf("Invalid OTP command: needs two arguments (network "
1390 "id and password)\n");
1394 end
= cmd
+ sizeof(cmd
);
1396 ret
= os_snprintf(pos
, end
- pos
, WPA_CTRL_RSP
"OTP-%s:%s",
1398 if (ret
< 0 || ret
>= end
- pos
) {
1399 printf("Too long OTP command.\n");
1403 for (i
= 2; i
< argc
; i
++) {
1404 ret
= os_snprintf(pos
, end
- pos
, " %s", argv
[i
]);
1405 if (ret
< 0 || ret
>= end
- pos
) {
1406 printf("Too long OTP command.\n");
1412 return wpa_ctrl_command(ctrl
, cmd
);
1416 static int wpa_cli_cmd_passphrase(struct wpa_ctrl
*ctrl
, int argc
,
1419 char cmd
[256], *pos
, *end
;
1423 printf("Invalid PASSPHRASE command: needs two arguments "
1424 "(network id and passphrase)\n");
1428 end
= cmd
+ sizeof(cmd
);
1430 ret
= os_snprintf(pos
, end
- pos
, WPA_CTRL_RSP
"PASSPHRASE-%s:%s",
1432 if (ret
< 0 || ret
>= end
- pos
) {
1433 printf("Too long PASSPHRASE command.\n");
1437 for (i
= 2; i
< argc
; i
++) {
1438 ret
= os_snprintf(pos
, end
- pos
, " %s", argv
[i
]);
1439 if (ret
< 0 || ret
>= end
- pos
) {
1440 printf("Too long PASSPHRASE command.\n");
1446 return wpa_ctrl_command(ctrl
, cmd
);
1450 static int wpa_cli_cmd_bssid(struct wpa_ctrl
*ctrl
, int argc
, char *argv
[])
1452 char cmd
[256], *pos
, *end
;
1456 printf("Invalid BSSID command: needs two arguments (network "
1461 end
= cmd
+ sizeof(cmd
);
1463 ret
= os_snprintf(pos
, end
- pos
, "BSSID");
1464 if (ret
< 0 || ret
>= end
- pos
) {
1465 printf("Too long BSSID command.\n");
1469 for (i
= 0; i
< argc
; i
++) {
1470 ret
= os_snprintf(pos
, end
- pos
, " %s", argv
[i
]);
1471 if (ret
< 0 || ret
>= end
- pos
) {
1472 printf("Too long BSSID command.\n");
1478 return wpa_ctrl_command(ctrl
, cmd
);
1482 static int wpa_cli_cmd_blacklist(struct wpa_ctrl
*ctrl
, int argc
, char *argv
[])
1484 char cmd
[256], *pos
, *end
;
1487 end
= cmd
+ sizeof(cmd
);
1489 ret
= os_snprintf(pos
, end
- pos
, "BLACKLIST");
1490 if (ret
< 0 || ret
>= end
- pos
) {
1491 printf("Too long BLACKLIST command.\n");
1495 for (i
= 0; i
< argc
; i
++) {
1496 ret
= os_snprintf(pos
, end
- pos
, " %s", argv
[i
]);
1497 if (ret
< 0 || ret
>= end
- pos
) {
1498 printf("Too long BLACKLIST command.\n");
1504 return wpa_ctrl_command(ctrl
, cmd
);
1508 static int wpa_cli_cmd_log_level(struct wpa_ctrl
*ctrl
, int argc
, char *argv
[])
1510 char cmd
[256], *pos
, *end
;
1513 end
= cmd
+ sizeof(cmd
);
1515 ret
= os_snprintf(pos
, end
- pos
, "LOG_LEVEL");
1516 if (ret
< 0 || ret
>= end
- pos
) {
1517 printf("Too long LOG_LEVEL command.\n");
1521 for (i
= 0; i
< argc
; i
++) {
1522 ret
= os_snprintf(pos
, end
- pos
, " %s", argv
[i
]);
1523 if (ret
< 0 || ret
>= end
- pos
) {
1524 printf("Too long LOG_LEVEL command.\n");
1530 return wpa_ctrl_command(ctrl
, cmd
);
1534 static int wpa_cli_cmd_list_networks(struct wpa_ctrl
*ctrl
, int argc
,
1537 return wpa_ctrl_command(ctrl
, "LIST_NETWORKS");
1541 static int wpa_cli_cmd_select_network(struct wpa_ctrl
*ctrl
, int argc
,
1548 printf("Invalid SELECT_NETWORK command: needs one argument "
1553 res
= os_snprintf(cmd
, sizeof(cmd
), "SELECT_NETWORK %s", argv
[0]);
1554 if (res
< 0 || (size_t) res
>= sizeof(cmd
))
1556 cmd
[sizeof(cmd
) - 1] = '\0';
1558 return wpa_ctrl_command(ctrl
, cmd
);
1562 static int wpa_cli_cmd_enable_network(struct wpa_ctrl
*ctrl
, int argc
,
1569 printf("Invalid ENABLE_NETWORK command: needs one argument "
1575 res
= os_snprintf(cmd
, sizeof(cmd
), "ENABLE_NETWORK %s %s",
1578 res
= os_snprintf(cmd
, sizeof(cmd
), "ENABLE_NETWORK %s",
1580 if (res
< 0 || (size_t) res
>= sizeof(cmd
))
1582 cmd
[sizeof(cmd
) - 1] = '\0';
1584 return wpa_ctrl_command(ctrl
, cmd
);
1588 static int wpa_cli_cmd_disable_network(struct wpa_ctrl
*ctrl
, int argc
,
1595 printf("Invalid DISABLE_NETWORK command: needs one argument "
1600 res
= os_snprintf(cmd
, sizeof(cmd
), "DISABLE_NETWORK %s", argv
[0]);
1601 if (res
< 0 || (size_t) res
>= sizeof(cmd
))
1603 cmd
[sizeof(cmd
) - 1] = '\0';
1605 return wpa_ctrl_command(ctrl
, cmd
);
1609 static int wpa_cli_cmd_add_network(struct wpa_ctrl
*ctrl
, int argc
,
1612 return wpa_ctrl_command(ctrl
, "ADD_NETWORK");
1616 static int wpa_cli_cmd_remove_network(struct wpa_ctrl
*ctrl
, int argc
,
1623 printf("Invalid REMOVE_NETWORK command: needs one argument "
1628 res
= os_snprintf(cmd
, sizeof(cmd
), "REMOVE_NETWORK %s", argv
[0]);
1629 if (res
< 0 || (size_t) res
>= sizeof(cmd
))
1631 cmd
[sizeof(cmd
) - 1] = '\0';
1633 return wpa_ctrl_command(ctrl
, cmd
);
1637 static void wpa_cli_show_network_variables(void)
1639 printf("set_network variables:\n"
1640 " ssid (network name, SSID)\n"
1641 " psk (WPA passphrase or pre-shared key)\n"
1642 " key_mgmt (key management protocol)\n"
1643 " identity (EAP identity)\n"
1644 " password (EAP password)\n"
1647 "Note: Values are entered in the same format as the "
1648 "configuration file is using,\n"
1649 "i.e., strings values need to be inside double quotation "
1651 "For example: set_network 1 ssid \"network name\"\n"
1653 "Please see wpa_supplicant.conf documentation for full list "
1654 "of\navailable variables.\n");
1658 static int wpa_cli_cmd_set_network(struct wpa_ctrl
*ctrl
, int argc
,
1665 wpa_cli_show_network_variables();
1670 printf("Invalid SET_NETWORK command: needs three arguments\n"
1671 "(network id, variable name, and value)\n");
1675 res
= os_snprintf(cmd
, sizeof(cmd
), "SET_NETWORK %s %s %s",
1676 argv
[0], argv
[1], argv
[2]);
1677 if (res
< 0 || (size_t) res
>= sizeof(cmd
) - 1) {
1678 printf("Too long SET_NETWORK command.\n");
1681 return wpa_ctrl_command(ctrl
, cmd
);
1685 static int wpa_cli_cmd_get_network(struct wpa_ctrl
*ctrl
, int argc
,
1692 wpa_cli_show_network_variables();
1697 printf("Invalid GET_NETWORK command: needs two arguments\n"
1698 "(network id and variable name)\n");
1702 res
= os_snprintf(cmd
, sizeof(cmd
), "GET_NETWORK %s %s",
1704 if (res
< 0 || (size_t) res
>= sizeof(cmd
) - 1) {
1705 printf("Too long GET_NETWORK command.\n");
1708 return wpa_ctrl_command(ctrl
, cmd
);
1712 static int wpa_cli_cmd_list_creds(struct wpa_ctrl
*ctrl
, int argc
,
1715 return wpa_ctrl_command(ctrl
, "LIST_CREDS");
1719 static int wpa_cli_cmd_add_cred(struct wpa_ctrl
*ctrl
, int argc
, char *argv
[])
1721 return wpa_ctrl_command(ctrl
, "ADD_CRED");
1725 static int wpa_cli_cmd_remove_cred(struct wpa_ctrl
*ctrl
, int argc
,
1732 printf("Invalid REMOVE_CRED command: needs one argument "
1737 res
= os_snprintf(cmd
, sizeof(cmd
), "REMOVE_CRED %s", argv
[0]);
1738 if (res
< 0 || (size_t) res
>= sizeof(cmd
))
1740 cmd
[sizeof(cmd
) - 1] = '\0';
1742 return wpa_ctrl_command(ctrl
, cmd
);
1746 static int wpa_cli_cmd_set_cred(struct wpa_ctrl
*ctrl
, int argc
, char *argv
[])
1752 printf("Invalid SET_CRED command: needs three arguments\n"
1753 "(cred id, variable name, and value)\n");
1757 res
= os_snprintf(cmd
, sizeof(cmd
), "SET_CRED %s %s %s",
1758 argv
[0], argv
[1], argv
[2]);
1759 if (res
< 0 || (size_t) res
>= sizeof(cmd
) - 1) {
1760 printf("Too long SET_CRED command.\n");
1763 return wpa_ctrl_command(ctrl
, cmd
);
1767 static int wpa_cli_cmd_disconnect(struct wpa_ctrl
*ctrl
, int argc
,
1770 return wpa_ctrl_command(ctrl
, "DISCONNECT");
1774 static int wpa_cli_cmd_reconnect(struct wpa_ctrl
*ctrl
, int argc
,
1777 return wpa_ctrl_command(ctrl
, "RECONNECT");
1781 static int wpa_cli_cmd_save_config(struct wpa_ctrl
*ctrl
, int argc
,
1784 return wpa_ctrl_command(ctrl
, "SAVE_CONFIG");
1788 static int wpa_cli_cmd_scan(struct wpa_ctrl
*ctrl
, int argc
, char *argv
[])
1790 return wpa_ctrl_command(ctrl
, "SCAN");
1794 static int wpa_cli_cmd_scan_results(struct wpa_ctrl
*ctrl
, int argc
,
1797 return wpa_ctrl_command(ctrl
, "SCAN_RESULTS");
1801 static int wpa_cli_cmd_bss(struct wpa_ctrl
*ctrl
, int argc
, char *argv
[])
1807 printf("Invalid BSS command: need at least one argument"
1808 "(index or BSSID)\n");
1812 res
= os_snprintf(cmd
, sizeof(cmd
), "BSS %s%s%s%s%s", argv
[0],
1813 argc
> 1 ? " " : "", argc
> 1 ? argv
[1] : "",
1814 argc
> 2 ? " " : "", argc
> 2 ? argv
[2] : "");
1816 if (res
< 0 || (size_t) res
>= sizeof(cmd
))
1818 cmd
[sizeof(cmd
) - 1] = '\0';
1820 return wpa_ctrl_command(ctrl
, cmd
);
1824 static char ** wpa_cli_complete_bss(const char *str
, int pos
)
1826 int arg
= get_cmd_arg_num(str
, pos
);
1831 res
= cli_txt_list_array(&bsses
);
1839 static int wpa_cli_cmd_get_capability(struct wpa_ctrl
*ctrl
, int argc
,
1845 if (argc
< 1 || argc
> 2) {
1846 printf("Invalid GET_CAPABILITY command: need either one or "
1851 if ((argc
== 2) && os_strcmp(argv
[1], "strict") != 0) {
1852 printf("Invalid GET_CAPABILITY command: second argument, "
1853 "if any, must be 'strict'\n");
1857 res
= os_snprintf(cmd
, sizeof(cmd
), "GET_CAPABILITY %s%s", argv
[0],
1858 (argc
== 2) ? " strict" : "");
1859 if (res
< 0 || (size_t) res
>= sizeof(cmd
))
1861 cmd
[sizeof(cmd
) - 1] = '\0';
1863 return wpa_ctrl_command(ctrl
, cmd
);
1867 static int wpa_cli_list_interfaces(struct wpa_ctrl
*ctrl
)
1869 printf("Available interfaces:\n");
1870 return wpa_ctrl_command(ctrl
, "INTERFACES");
1874 static int wpa_cli_cmd_interface(struct wpa_ctrl
*ctrl
, int argc
, char *argv
[])
1877 wpa_cli_list_interfaces(ctrl
);
1881 wpa_cli_close_connection();
1882 os_free(ctrl_ifname
);
1883 ctrl_ifname
= os_strdup(argv
[0]);
1885 if (wpa_cli_open_connection(ctrl_ifname
, 1)) {
1886 printf("Connected to interface '%s.\n", ctrl_ifname
);
1888 printf("Could not connect to interface '%s' - re-trying\n",
1895 static int wpa_cli_cmd_reconfigure(struct wpa_ctrl
*ctrl
, int argc
,
1898 return wpa_ctrl_command(ctrl
, "RECONFIGURE");
1902 static int wpa_cli_cmd_terminate(struct wpa_ctrl
*ctrl
, int argc
,
1905 return wpa_ctrl_command(ctrl
, "TERMINATE");
1909 static int wpa_cli_cmd_interface_add(struct wpa_ctrl
*ctrl
, int argc
,
1916 printf("Invalid INTERFACE_ADD command: needs at least one "
1917 "argument (interface name)\n"
1918 "All arguments: ifname confname driver ctrl_interface "
1919 "driver_param bridge_name\n");
1924 * INTERFACE_ADD <ifname>TAB<confname>TAB<driver>TAB<ctrl_interface>TAB
1925 * <driver_param>TAB<bridge_name>
1927 res
= os_snprintf(cmd
, sizeof(cmd
),
1928 "INTERFACE_ADD %s\t%s\t%s\t%s\t%s\t%s",
1930 argc
> 1 ? argv
[1] : "", argc
> 2 ? argv
[2] : "",
1931 argc
> 3 ? argv
[3] : "", argc
> 4 ? argv
[4] : "",
1932 argc
> 5 ? argv
[5] : "");
1933 if (res
< 0 || (size_t) res
>= sizeof(cmd
))
1935 cmd
[sizeof(cmd
) - 1] = '\0';
1936 return wpa_ctrl_command(ctrl
, cmd
);
1940 static int wpa_cli_cmd_interface_remove(struct wpa_ctrl
*ctrl
, int argc
,
1947 printf("Invalid INTERFACE_REMOVE command: needs one argument "
1948 "(interface name)\n");
1952 res
= os_snprintf(cmd
, sizeof(cmd
), "INTERFACE_REMOVE %s", argv
[0]);
1953 if (res
< 0 || (size_t) res
>= sizeof(cmd
))
1955 cmd
[sizeof(cmd
) - 1] = '\0';
1956 return wpa_ctrl_command(ctrl
, cmd
);
1960 static int wpa_cli_cmd_interface_list(struct wpa_ctrl
*ctrl
, int argc
,
1963 return wpa_ctrl_command(ctrl
, "INTERFACE_LIST");
1968 static int wpa_cli_cmd_sta(struct wpa_ctrl
*ctrl
, int argc
, char *argv
[])
1972 printf("Invalid 'sta' command - exactly one argument, STA "
1973 "address, is required.\n");
1976 os_snprintf(buf
, sizeof(buf
), "STA %s", argv
[0]);
1977 return wpa_ctrl_command(ctrl
, buf
);
1981 static int wpa_ctrl_command_sta(struct wpa_ctrl
*ctrl
, char *cmd
,
1982 char *addr
, size_t addr_len
)
1984 char buf
[4096], *pos
;
1988 if (ctrl_conn
== NULL
) {
1989 printf("Not connected to hostapd - command dropped.\n");
1992 len
= sizeof(buf
) - 1;
1993 ret
= wpa_ctrl_request(ctrl
, cmd
, os_strlen(cmd
), buf
, &len
,
1996 printf("'%s' command timed out.\n", cmd
);
1998 } else if (ret
< 0) {
1999 printf("'%s' command failed.\n", cmd
);
2004 if (os_memcmp(buf
, "FAIL", 4) == 0)
2009 while (*pos
!= '\0' && *pos
!= '\n')
2012 os_strlcpy(addr
, buf
, addr_len
);
2017 static int wpa_cli_cmd_all_sta(struct wpa_ctrl
*ctrl
, int argc
, char *argv
[])
2019 char addr
[32], cmd
[64];
2021 if (wpa_ctrl_command_sta(ctrl
, "STA-FIRST", addr
, sizeof(addr
)))
2024 os_snprintf(cmd
, sizeof(cmd
), "STA-NEXT %s", addr
);
2025 } while (wpa_ctrl_command_sta(ctrl
, cmd
, addr
, sizeof(addr
)) == 0);
2031 static int wpa_cli_cmd_deauthenticate(struct wpa_ctrl
*ctrl
, int argc
,
2036 printf("Invalid 'deauthenticate' command - exactly one "
2037 "argument, STA address, is required.\n");
2041 os_snprintf(buf
, sizeof(buf
), "DEAUTHENTICATE %s %s",
2044 os_snprintf(buf
, sizeof(buf
), "DEAUTHENTICATE %s", argv
[0]);
2045 return wpa_ctrl_command(ctrl
, buf
);
2049 static int wpa_cli_cmd_disassociate(struct wpa_ctrl
*ctrl
, int argc
,
2054 printf("Invalid 'disassociate' command - exactly one "
2055 "argument, STA address, is required.\n");
2059 os_snprintf(buf
, sizeof(buf
), "DISASSOCIATE %s %s",
2062 os_snprintf(buf
, sizeof(buf
), "DISASSOCIATE %s", argv
[0]);
2063 return wpa_ctrl_command(ctrl
, buf
);
2065 #endif /* CONFIG_AP */
2068 static int wpa_cli_cmd_suspend(struct wpa_ctrl
*ctrl
, int argc
, char *argv
[])
2070 return wpa_ctrl_command(ctrl
, "SUSPEND");
2074 static int wpa_cli_cmd_resume(struct wpa_ctrl
*ctrl
, int argc
, char *argv
[])
2076 return wpa_ctrl_command(ctrl
, "RESUME");
2080 static int wpa_cli_cmd_drop_sa(struct wpa_ctrl
*ctrl
, int argc
, char *argv
[])
2082 return wpa_ctrl_command(ctrl
, "DROP_SA");
2086 static int wpa_cli_cmd_roam(struct wpa_ctrl
*ctrl
, int argc
, char *argv
[])
2092 printf("Invalid ROAM command: needs one argument "
2093 "(target AP's BSSID)\n");
2097 res
= os_snprintf(cmd
, sizeof(cmd
), "ROAM %s", argv
[0]);
2098 if (res
< 0 || (size_t) res
>= sizeof(cmd
) - 1) {
2099 printf("Too long ROAM command.\n");
2102 return wpa_ctrl_command(ctrl
, cmd
);
2108 static int wpa_cli_cmd_p2p_find(struct wpa_ctrl
*ctrl
, int argc
, char *argv
[])
2114 return wpa_ctrl_command(ctrl
, "P2P_FIND");
2117 res
= os_snprintf(cmd
, sizeof(cmd
), "P2P_FIND %s %s %s",
2118 argv
[0], argv
[1], argv
[2]);
2120 res
= os_snprintf(cmd
, sizeof(cmd
), "P2P_FIND %s %s",
2123 res
= os_snprintf(cmd
, sizeof(cmd
), "P2P_FIND %s", argv
[0]);
2124 if (res
< 0 || (size_t) res
>= sizeof(cmd
))
2126 cmd
[sizeof(cmd
) - 1] = '\0';
2127 return wpa_ctrl_command(ctrl
, cmd
);
2131 static int wpa_cli_cmd_p2p_stop_find(struct wpa_ctrl
*ctrl
, int argc
,
2134 return wpa_ctrl_command(ctrl
, "P2P_STOP_FIND");
2138 static int wpa_cli_cmd_p2p_connect(struct wpa_ctrl
*ctrl
, int argc
,
2145 printf("Invalid P2P_CONNECT command: needs at least two "
2146 "arguments (address and pbc/PIN)\n");
2151 res
= os_snprintf(cmd
, sizeof(cmd
),
2152 "P2P_CONNECT %s %s %s %s %s",
2153 argv
[0], argv
[1], argv
[2], argv
[3],
2156 res
= os_snprintf(cmd
, sizeof(cmd
), "P2P_CONNECT %s %s %s %s",
2157 argv
[0], argv
[1], argv
[2], argv
[3]);
2159 res
= os_snprintf(cmd
, sizeof(cmd
), "P2P_CONNECT %s %s %s",
2160 argv
[0], argv
[1], argv
[2]);
2162 res
= os_snprintf(cmd
, sizeof(cmd
), "P2P_CONNECT %s %s",
2164 if (res
< 0 || (size_t) res
>= sizeof(cmd
))
2166 cmd
[sizeof(cmd
) - 1] = '\0';
2167 return wpa_ctrl_command(ctrl
, cmd
);
2171 static char ** wpa_cli_complete_p2p_connect(const char *str
, int pos
)
2173 int arg
= get_cmd_arg_num(str
, pos
);
2178 res
= cli_txt_list_array(&p2p_peers
);
2186 static int wpa_cli_cmd_p2p_listen(struct wpa_ctrl
*ctrl
, int argc
,
2193 return wpa_ctrl_command(ctrl
, "P2P_LISTEN");
2195 res
= os_snprintf(cmd
, sizeof(cmd
), "P2P_LISTEN %s", argv
[0]);
2196 if (res
< 0 || (size_t) res
>= sizeof(cmd
))
2198 cmd
[sizeof(cmd
) - 1] = '\0';
2199 return wpa_ctrl_command(ctrl
, cmd
);
2203 static int wpa_cli_cmd_p2p_group_remove(struct wpa_ctrl
*ctrl
, int argc
,
2210 printf("Invalid P2P_GROUP_REMOVE command: needs one argument "
2211 "(interface name)\n");
2215 res
= os_snprintf(cmd
, sizeof(cmd
), "P2P_GROUP_REMOVE %s", argv
[0]);
2216 if (res
< 0 || (size_t) res
>= sizeof(cmd
))
2218 cmd
[sizeof(cmd
) - 1] = '\0';
2219 return wpa_ctrl_command(ctrl
, cmd
);
2223 static char ** wpa_cli_complete_p2p_group_remove(const char *str
, int pos
)
2225 int arg
= get_cmd_arg_num(str
, pos
);
2230 res
= cli_txt_list_array(&p2p_groups
);
2238 static int wpa_cli_cmd_p2p_group_add(struct wpa_ctrl
*ctrl
, int argc
,
2245 return wpa_ctrl_command(ctrl
, "P2P_GROUP_ADD");
2248 res
= os_snprintf(cmd
, sizeof(cmd
), "P2P_GROUP_ADD %s %s",
2251 res
= os_snprintf(cmd
, sizeof(cmd
), "P2P_GROUP_ADD %s",
2253 if (res
< 0 || (size_t) res
>= sizeof(cmd
))
2255 cmd
[sizeof(cmd
) - 1] = '\0';
2256 return wpa_ctrl_command(ctrl
, cmd
);
2260 static int wpa_cli_cmd_p2p_prov_disc(struct wpa_ctrl
*ctrl
, int argc
,
2266 if (argc
!= 2 && argc
!= 3) {
2267 printf("Invalid P2P_PROV_DISC command: needs at least "
2268 "two arguments, address and config method\n"
2269 "(display, keypad, or pbc) and an optional join\n");
2274 res
= os_snprintf(cmd
, sizeof(cmd
), "P2P_PROV_DISC %s %s %s",
2275 argv
[0], argv
[1], argv
[2]);
2277 res
= os_snprintf(cmd
, sizeof(cmd
), "P2P_PROV_DISC %s %s",
2279 if (res
< 0 || (size_t) res
>= sizeof(cmd
))
2281 cmd
[sizeof(cmd
) - 1] = '\0';
2282 return wpa_ctrl_command(ctrl
, cmd
);
2286 static int wpa_cli_cmd_p2p_get_passphrase(struct wpa_ctrl
*ctrl
, int argc
,
2289 return wpa_ctrl_command(ctrl
, "P2P_GET_PASSPHRASE");
2293 static int wpa_cli_cmd_p2p_serv_disc_req(struct wpa_ctrl
*ctrl
, int argc
,
2299 if (argc
!= 2 && argc
!= 4) {
2300 printf("Invalid P2P_SERV_DISC_REQ command: needs two "
2301 "arguments (address and TLVs) or four arguments "
2302 "(address, \"upnp\", version, search target "
2308 res
= os_snprintf(cmd
, sizeof(cmd
),
2309 "P2P_SERV_DISC_REQ %s %s %s %s",
2310 argv
[0], argv
[1], argv
[2], argv
[3]);
2312 res
= os_snprintf(cmd
, sizeof(cmd
), "P2P_SERV_DISC_REQ %s %s",
2314 if (res
< 0 || (size_t) res
>= sizeof(cmd
))
2316 cmd
[sizeof(cmd
) - 1] = '\0';
2317 return wpa_ctrl_command(ctrl
, cmd
);
2321 static int wpa_cli_cmd_p2p_serv_disc_cancel_req(struct wpa_ctrl
*ctrl
,
2322 int argc
, char *argv
[])
2328 printf("Invalid P2P_SERV_DISC_CANCEL_REQ command: needs one "
2329 "argument (pending request identifier)\n");
2333 res
= os_snprintf(cmd
, sizeof(cmd
), "P2P_SERV_DISC_CANCEL_REQ %s",
2335 if (res
< 0 || (size_t) res
>= sizeof(cmd
))
2337 cmd
[sizeof(cmd
) - 1] = '\0';
2338 return wpa_ctrl_command(ctrl
, cmd
);
2342 static int wpa_cli_cmd_p2p_serv_disc_resp(struct wpa_ctrl
*ctrl
, int argc
,
2349 printf("Invalid P2P_SERV_DISC_RESP command: needs four "
2350 "arguments (freq, address, dialog token, and TLVs)\n");
2354 res
= os_snprintf(cmd
, sizeof(cmd
), "P2P_SERV_DISC_RESP %s %s %s %s",
2355 argv
[0], argv
[1], argv
[2], argv
[3]);
2356 if (res
< 0 || (size_t) res
>= sizeof(cmd
))
2358 cmd
[sizeof(cmd
) - 1] = '\0';
2359 return wpa_ctrl_command(ctrl
, cmd
);
2363 static int wpa_cli_cmd_p2p_service_update(struct wpa_ctrl
*ctrl
, int argc
,
2366 return wpa_ctrl_command(ctrl
, "P2P_SERVICE_UPDATE");
2370 static int wpa_cli_cmd_p2p_serv_disc_external(struct wpa_ctrl
*ctrl
,
2371 int argc
, char *argv
[])
2377 printf("Invalid P2P_SERV_DISC_EXTERNAL command: needs one "
2378 "argument (external processing: 0/1)\n");
2382 res
= os_snprintf(cmd
, sizeof(cmd
), "P2P_SERV_DISC_EXTERNAL %s",
2384 if (res
< 0 || (size_t) res
>= sizeof(cmd
))
2386 cmd
[sizeof(cmd
) - 1] = '\0';
2387 return wpa_ctrl_command(ctrl
, cmd
);
2391 static int wpa_cli_cmd_p2p_service_flush(struct wpa_ctrl
*ctrl
, int argc
,
2394 return wpa_ctrl_command(ctrl
, "P2P_SERVICE_FLUSH");
2398 static int wpa_cli_cmd_p2p_service_add(struct wpa_ctrl
*ctrl
, int argc
,
2404 if (argc
!= 3 && argc
!= 4) {
2405 printf("Invalid P2P_SERVICE_ADD command: needs three or four "
2411 res
= os_snprintf(cmd
, sizeof(cmd
),
2412 "P2P_SERVICE_ADD %s %s %s %s",
2413 argv
[0], argv
[1], argv
[2], argv
[3]);
2415 res
= os_snprintf(cmd
, sizeof(cmd
),
2416 "P2P_SERVICE_ADD %s %s %s",
2417 argv
[0], argv
[1], argv
[2]);
2418 if (res
< 0 || (size_t) res
>= sizeof(cmd
))
2420 cmd
[sizeof(cmd
) - 1] = '\0';
2421 return wpa_ctrl_command(ctrl
, cmd
);
2425 static int wpa_cli_cmd_p2p_service_del(struct wpa_ctrl
*ctrl
, int argc
,
2431 if (argc
!= 2 && argc
!= 3) {
2432 printf("Invalid P2P_SERVICE_DEL command: needs two or three "
2438 res
= os_snprintf(cmd
, sizeof(cmd
),
2439 "P2P_SERVICE_DEL %s %s %s",
2440 argv
[0], argv
[1], argv
[2]);
2442 res
= os_snprintf(cmd
, sizeof(cmd
),
2443 "P2P_SERVICE_DEL %s %s",
2445 if (res
< 0 || (size_t) res
>= sizeof(cmd
))
2447 cmd
[sizeof(cmd
) - 1] = '\0';
2448 return wpa_ctrl_command(ctrl
, cmd
);
2452 static int wpa_cli_cmd_p2p_reject(struct wpa_ctrl
*ctrl
,
2453 int argc
, char *argv
[])
2459 printf("Invalid P2P_REJECT command: needs one argument "
2460 "(peer address)\n");
2464 res
= os_snprintf(cmd
, sizeof(cmd
), "P2P_REJECT %s", argv
[0]);
2465 if (res
< 0 || (size_t) res
>= sizeof(cmd
))
2467 cmd
[sizeof(cmd
) - 1] = '\0';
2468 return wpa_ctrl_command(ctrl
, cmd
);
2472 static int wpa_cli_cmd_p2p_invite(struct wpa_ctrl
*ctrl
,
2473 int argc
, char *argv
[])
2479 printf("Invalid P2P_INVITE command: needs at least one "
2485 res
= os_snprintf(cmd
, sizeof(cmd
), "P2P_INVITE %s %s %s",
2486 argv
[0], argv
[1], argv
[2]);
2488 res
= os_snprintf(cmd
, sizeof(cmd
), "P2P_INVITE %s %s",
2491 res
= os_snprintf(cmd
, sizeof(cmd
), "P2P_INVITE %s", argv
[0]);
2492 if (res
< 0 || (size_t) res
>= sizeof(cmd
))
2494 cmd
[sizeof(cmd
) - 1] = '\0';
2495 return wpa_ctrl_command(ctrl
, cmd
);
2499 static int wpa_cli_cmd_p2p_peer(struct wpa_ctrl
*ctrl
, int argc
, char *argv
[])
2503 printf("Invalid 'p2p_peer' command - exactly one argument, "
2504 "P2P peer device address, is required.\n");
2507 os_snprintf(buf
, sizeof(buf
), "P2P_PEER %s", argv
[0]);
2508 return wpa_ctrl_command(ctrl
, buf
);
2512 static char ** wpa_cli_complete_p2p_peer(const char *str
, int pos
)
2514 int arg
= get_cmd_arg_num(str
, pos
);
2519 res
= cli_txt_list_array(&p2p_peers
);
2527 static int wpa_ctrl_command_p2p_peer(struct wpa_ctrl
*ctrl
, char *cmd
,
2528 char *addr
, size_t addr_len
,
2531 char buf
[4096], *pos
;
2535 if (ctrl_conn
== NULL
)
2537 len
= sizeof(buf
) - 1;
2538 ret
= wpa_ctrl_request(ctrl
, cmd
, os_strlen(cmd
), buf
, &len
,
2541 printf("'%s' command timed out.\n", cmd
);
2543 } else if (ret
< 0) {
2544 printf("'%s' command failed.\n", cmd
);
2549 if (os_memcmp(buf
, "FAIL", 4) == 0)
2553 while (*pos
!= '\0' && *pos
!= '\n')
2556 os_strlcpy(addr
, buf
, addr_len
);
2557 if (!discovered
|| os_strstr(pos
, "[PROBE_REQ_ONLY]") == NULL
)
2558 printf("%s\n", addr
);
2563 static int wpa_cli_cmd_p2p_peers(struct wpa_ctrl
*ctrl
, int argc
, char *argv
[])
2565 char addr
[32], cmd
[64];
2568 discovered
= argc
> 0 && os_strcmp(argv
[0], "discovered") == 0;
2570 if (wpa_ctrl_command_p2p_peer(ctrl
, "P2P_PEER FIRST",
2571 addr
, sizeof(addr
), discovered
))
2574 os_snprintf(cmd
, sizeof(cmd
), "P2P_PEER NEXT-%s", addr
);
2575 } while (wpa_ctrl_command_p2p_peer(ctrl
, cmd
, addr
, sizeof(addr
),
2582 static int wpa_cli_cmd_p2p_set(struct wpa_ctrl
*ctrl
, int argc
, char *argv
[])
2588 printf("Invalid P2P_SET command: needs two arguments (field, "
2593 res
= os_snprintf(cmd
, sizeof(cmd
), "P2P_SET %s %s", argv
[0], argv
[1]);
2594 if (res
< 0 || (size_t) res
>= sizeof(cmd
))
2596 cmd
[sizeof(cmd
) - 1] = '\0';
2597 return wpa_ctrl_command(ctrl
, cmd
);
2601 static int wpa_cli_cmd_p2p_flush(struct wpa_ctrl
*ctrl
, int argc
, char *argv
[])
2603 return wpa_ctrl_command(ctrl
, "P2P_FLUSH");
2607 static int wpa_cli_cmd_p2p_cancel(struct wpa_ctrl
*ctrl
, int argc
,
2610 return wpa_ctrl_command(ctrl
, "P2P_CANCEL");
2614 static int wpa_cli_cmd_p2p_unauthorize(struct wpa_ctrl
*ctrl
, int argc
,
2621 printf("Invalid P2P_UNAUTHORIZE command: needs one argument "
2622 "(peer address)\n");
2626 res
= os_snprintf(cmd
, sizeof(cmd
), "P2P_UNAUTHORIZE %s", argv
[0]);
2628 if (res
< 0 || (size_t) res
>= sizeof(cmd
))
2631 cmd
[sizeof(cmd
) - 1] = '\0';
2632 return wpa_ctrl_command(ctrl
, cmd
);
2636 static int wpa_cli_cmd_p2p_presence_req(struct wpa_ctrl
*ctrl
, int argc
,
2642 if (argc
!= 0 && argc
!= 2 && argc
!= 4) {
2643 printf("Invalid P2P_PRESENCE_REQ command: needs two arguments "
2644 "(preferred duration, interval; in microsecods).\n"
2645 "Optional second pair can be used to provide "
2646 "acceptable values.\n");
2651 res
= os_snprintf(cmd
, sizeof(cmd
),
2652 "P2P_PRESENCE_REQ %s %s %s %s",
2653 argv
[0], argv
[1], argv
[2], argv
[3]);
2655 res
= os_snprintf(cmd
, sizeof(cmd
), "P2P_PRESENCE_REQ %s %s",
2658 res
= os_snprintf(cmd
, sizeof(cmd
), "P2P_PRESENCE_REQ");
2659 if (res
< 0 || (size_t) res
>= sizeof(cmd
))
2661 cmd
[sizeof(cmd
) - 1] = '\0';
2662 return wpa_ctrl_command(ctrl
, cmd
);
2666 static int wpa_cli_cmd_p2p_ext_listen(struct wpa_ctrl
*ctrl
, int argc
,
2672 if (argc
!= 0 && argc
!= 2) {
2673 printf("Invalid P2P_EXT_LISTEN command: needs two arguments "
2674 "(availability period, availability interval; in "
2676 "Extended Listen Timing can be cancelled with this "
2677 "command when used without parameters.\n");
2682 res
= os_snprintf(cmd
, sizeof(cmd
), "P2P_EXT_LISTEN %s %s",
2685 res
= os_snprintf(cmd
, sizeof(cmd
), "P2P_EXT_LISTEN");
2686 if (res
< 0 || (size_t) res
>= sizeof(cmd
))
2688 cmd
[sizeof(cmd
) - 1] = '\0';
2689 return wpa_ctrl_command(ctrl
, cmd
);
2692 #endif /* CONFIG_P2P */
2695 #ifdef CONFIG_INTERWORKING
2696 static int wpa_cli_cmd_fetch_anqp(struct wpa_ctrl
*ctrl
, int argc
,
2699 return wpa_ctrl_command(ctrl
, "FETCH_ANQP");
2703 static int wpa_cli_cmd_stop_fetch_anqp(struct wpa_ctrl
*ctrl
, int argc
,
2706 return wpa_ctrl_command(ctrl
, "STOP_FETCH_ANQP");
2710 static int wpa_cli_cmd_interworking_select(struct wpa_ctrl
*ctrl
, int argc
,
2717 return wpa_ctrl_command(ctrl
, "INTERWORKING_SELECT");
2719 res
= os_snprintf(cmd
, sizeof(cmd
), "INTERWORKING_SELECT %s", argv
[0]);
2720 if (res
< 0 || (size_t) res
>= sizeof(cmd
))
2722 cmd
[sizeof(cmd
) - 1] = '\0';
2723 return wpa_ctrl_command(ctrl
, cmd
);
2727 static int wpa_cli_cmd_interworking_connect(struct wpa_ctrl
*ctrl
, int argc
,
2734 printf("Invalid INTERWORKING_CONNECT commands: needs one "
2735 "argument (BSSID)\n");
2739 res
= os_snprintf(cmd
, sizeof(cmd
), "INTERWORKING_CONNECT %s",
2741 if (res
< 0 || (size_t) res
>= sizeof(cmd
))
2743 cmd
[sizeof(cmd
) - 1] = '\0';
2744 return wpa_ctrl_command(ctrl
, cmd
);
2748 static int wpa_cli_cmd_anqp_get(struct wpa_ctrl
*ctrl
, int argc
, char *argv
[])
2754 printf("Invalid ANQP_GET command: needs two arguments "
2755 "(addr and info id list)\n");
2759 res
= os_snprintf(cmd
, sizeof(cmd
), "ANQP_GET %s %s",
2761 if (res
< 0 || (size_t) res
>= sizeof(cmd
))
2763 cmd
[sizeof(cmd
) - 1] = '\0';
2764 return wpa_ctrl_command(ctrl
, cmd
);
2766 #endif /* CONFIG_INTERWORKING */
2771 static int wpa_cli_cmd_hs20_anqp_get(struct wpa_ctrl
*ctrl
, int argc
,
2778 printf("Invalid HS20_ANQP_GET command: needs two arguments "
2779 "(addr and subtype list)\n");
2783 res
= os_snprintf(cmd
, sizeof(cmd
), "HS20_ANQP_GET %s %s",
2785 if (res
< 0 || (size_t) res
>= sizeof(cmd
))
2787 cmd
[sizeof(cmd
) - 1] = '\0';
2788 return wpa_ctrl_command(ctrl
, cmd
);
2792 static int wpa_cli_cmd_get_nai_home_realm_list(struct wpa_ctrl
*ctrl
, int argc
,
2799 printf("Command needs one or two arguments (dst mac addr and "
2800 "optional home realm)\n");
2805 res
= os_snprintf(cmd
, sizeof(cmd
),
2806 "HS20_GET_NAI_HOME_REALM_LIST %s",
2809 res
= os_snprintf(cmd
, sizeof(cmd
),
2810 "HS20_GET_NAI_HOME_REALM_LIST %s %s",
2812 if (res
< 0 || (size_t) res
>= sizeof(cmd
) - 1) {
2813 printf("Too long command.\n");
2817 return wpa_ctrl_command(ctrl
, cmd
);
2820 #endif /* CONFIG_HS20 */
2823 static int wpa_cli_cmd_sta_autoconnect(struct wpa_ctrl
*ctrl
, int argc
,
2830 printf("Invalid STA_AUTOCONNECT command: needs one argument "
2831 "(0/1 = disable/enable automatic reconnection)\n");
2834 res
= os_snprintf(cmd
, sizeof(cmd
), "STA_AUTOCONNECT %s", argv
[0]);
2835 if (res
< 0 || (size_t) res
>= sizeof(cmd
) - 1) {
2836 printf("Too long STA_AUTOCONNECT command.\n");
2839 return wpa_ctrl_command(ctrl
, cmd
);
2843 static int wpa_cli_cmd_tdls_discover(struct wpa_ctrl
*ctrl
, int argc
,
2850 printf("Invalid TDLS_DISCOVER command: needs one argument "
2851 "(Peer STA MAC address)\n");
2855 res
= os_snprintf(cmd
, sizeof(cmd
), "TDLS_DISCOVER %s", argv
[0]);
2856 if (res
< 0 || (size_t) res
>= sizeof(cmd
) - 1) {
2857 printf("Too long TDLS_DISCOVER command.\n");
2860 return wpa_ctrl_command(ctrl
, cmd
);
2864 static int wpa_cli_cmd_tdls_setup(struct wpa_ctrl
*ctrl
, int argc
,
2871 printf("Invalid TDLS_SETUP command: needs one argument "
2872 "(Peer STA MAC address)\n");
2876 res
= os_snprintf(cmd
, sizeof(cmd
), "TDLS_SETUP %s", argv
[0]);
2877 if (res
< 0 || (size_t) res
>= sizeof(cmd
) - 1) {
2878 printf("Too long TDLS_SETUP command.\n");
2881 return wpa_ctrl_command(ctrl
, cmd
);
2885 static int wpa_cli_cmd_tdls_teardown(struct wpa_ctrl
*ctrl
, int argc
,
2892 printf("Invalid TDLS_TEARDOWN command: needs one argument "
2893 "(Peer STA MAC address)\n");
2897 res
= os_snprintf(cmd
, sizeof(cmd
), "TDLS_TEARDOWN %s", argv
[0]);
2898 if (res
< 0 || (size_t) res
>= sizeof(cmd
) - 1) {
2899 printf("Too long TDLS_TEARDOWN command.\n");
2902 return wpa_ctrl_command(ctrl
, cmd
);
2906 static int wpa_cli_cmd_signal_poll(struct wpa_ctrl
*ctrl
, int argc
,
2909 return wpa_ctrl_command(ctrl
, "SIGNAL_POLL");
2913 static int wpa_cli_cmd_reauthenticate(struct wpa_ctrl
*ctrl
, int argc
,
2916 return wpa_ctrl_command(ctrl
, "REAUTHENTICATE");
2920 #ifdef CONFIG_AUTOSCAN
2922 static int wpa_cli_cmd_autoscan(struct wpa_ctrl
*ctrl
, int argc
, char *argv
[])
2928 return wpa_ctrl_command(ctrl
, "AUTOSCAN ");
2930 res
= os_snprintf(cmd
, sizeof(cmd
), "AUTOSCAN %s", argv
[0]);
2931 if (res
< 0 || (size_t) res
>= sizeof(cmd
) - 1) {
2932 printf("Too long AUTOSCAN command.\n");
2936 return wpa_ctrl_command(ctrl
, cmd
);
2939 #endif /* CONFIG_AUTOSCAN */
2942 enum wpa_cli_cmd_flags
{
2943 cli_cmd_flag_none
= 0x00,
2944 cli_cmd_flag_sensitive
= 0x01
2947 struct wpa_cli_cmd
{
2949 int (*handler
)(struct wpa_ctrl
*ctrl
, int argc
, char *argv
[]);
2950 enum wpa_cli_cmd_flags flags
;
2954 static struct wpa_cli_cmd wpa_cli_commands
[] = {
2955 { "status", wpa_cli_cmd_status
,
2957 "[verbose] = get current WPA/EAPOL/EAP status" },
2958 { "ifname", wpa_cli_cmd_ifname
,
2960 "= get current interface name" },
2961 { "ping", wpa_cli_cmd_ping
,
2963 "= pings wpa_supplicant" },
2964 { "relog", wpa_cli_cmd_relog
,
2966 "= re-open log-file (allow rolling logs)" },
2967 { "note", wpa_cli_cmd_note
,
2969 "<text> = add a note to wpa_supplicant debug log" },
2970 { "mib", wpa_cli_cmd_mib
,
2972 "= get MIB variables (dot1x, dot11)" },
2973 { "help", wpa_cli_cmd_help
,
2975 "= show this usage help" },
2976 { "interface", wpa_cli_cmd_interface
,
2978 "[ifname] = show interfaces/select interface" },
2979 { "level", wpa_cli_cmd_level
,
2981 "<debug level> = change debug level" },
2982 { "license", wpa_cli_cmd_license
,
2984 "= show full wpa_cli license" },
2985 { "quit", wpa_cli_cmd_quit
,
2988 { "set", wpa_cli_cmd_set
,
2990 "= set variables (shows list of variables when run without "
2992 { "get", wpa_cli_cmd_get
,
2994 "<name> = get information" },
2995 { "logon", wpa_cli_cmd_logon
,
2997 "= IEEE 802.1X EAPOL state machine logon" },
2998 { "logoff", wpa_cli_cmd_logoff
,
3000 "= IEEE 802.1X EAPOL state machine logoff" },
3001 { "pmksa", wpa_cli_cmd_pmksa
,
3003 "= show PMKSA cache" },
3004 { "reassociate", wpa_cli_cmd_reassociate
,
3006 "= force reassociation" },
3007 { "preauthenticate", wpa_cli_cmd_preauthenticate
,
3009 "<BSSID> = force preauthentication" },
3010 { "identity", wpa_cli_cmd_identity
,
3012 "<network id> <identity> = configure identity for an SSID" },
3013 { "password", wpa_cli_cmd_password
,
3014 cli_cmd_flag_sensitive
,
3015 "<network id> <password> = configure password for an SSID" },
3016 { "new_password", wpa_cli_cmd_new_password
,
3017 cli_cmd_flag_sensitive
,
3018 "<network id> <password> = change password for an SSID" },
3019 { "pin", wpa_cli_cmd_pin
,
3020 cli_cmd_flag_sensitive
,
3021 "<network id> <pin> = configure pin for an SSID" },
3022 { "otp", wpa_cli_cmd_otp
,
3023 cli_cmd_flag_sensitive
,
3024 "<network id> <password> = configure one-time-password for an SSID"
3026 { "passphrase", wpa_cli_cmd_passphrase
,
3027 cli_cmd_flag_sensitive
,
3028 "<network id> <passphrase> = configure private key passphrase\n"
3030 { "bssid", wpa_cli_cmd_bssid
,
3032 "<network id> <BSSID> = set preferred BSSID for an SSID" },
3033 { "blacklist", wpa_cli_cmd_blacklist
,
3035 "<BSSID> = add a BSSID to the blacklist\n"
3036 "blacklist clear = clear the blacklist\n"
3037 "blacklist = display the blacklist" },
3038 { "log_level", wpa_cli_cmd_log_level
,
3040 "<level> [<timestamp>] = update the log level/timestamp\n"
3041 "log_level = display the current log level and log options" },
3042 { "list_networks", wpa_cli_cmd_list_networks
,
3044 "= list configured networks" },
3045 { "select_network", wpa_cli_cmd_select_network
,
3047 "<network id> = select a network (disable others)" },
3048 { "enable_network", wpa_cli_cmd_enable_network
,
3050 "<network id> = enable a network" },
3051 { "disable_network", wpa_cli_cmd_disable_network
,
3053 "<network id> = disable a network" },
3054 { "add_network", wpa_cli_cmd_add_network
,
3056 "= add a network" },
3057 { "remove_network", wpa_cli_cmd_remove_network
,
3059 "<network id> = remove a network" },
3060 { "set_network", wpa_cli_cmd_set_network
,
3061 cli_cmd_flag_sensitive
,
3062 "<network id> <variable> <value> = set network variables (shows\n"
3063 " list of variables when run without arguments)" },
3064 { "get_network", wpa_cli_cmd_get_network
,
3066 "<network id> <variable> = get network variables" },
3067 { "list_creds", wpa_cli_cmd_list_creds
,
3069 "= list configured credentials" },
3070 { "add_cred", wpa_cli_cmd_add_cred
,
3072 "= add a credential" },
3073 { "remove_cred", wpa_cli_cmd_remove_cred
,
3075 "<cred id> = remove a credential" },
3076 { "set_cred", wpa_cli_cmd_set_cred
,
3077 cli_cmd_flag_sensitive
,
3078 "<cred id> <variable> <value> = set credential variables" },
3079 { "save_config", wpa_cli_cmd_save_config
,
3081 "= save the current configuration" },
3082 { "disconnect", wpa_cli_cmd_disconnect
,
3084 "= disconnect and wait for reassociate/reconnect command before\n"
3086 { "reconnect", wpa_cli_cmd_reconnect
,
3088 "= like reassociate, but only takes effect if already disconnected"
3090 { "scan", wpa_cli_cmd_scan
,
3092 "= request new BSS scan" },
3093 { "scan_results", wpa_cli_cmd_scan_results
,
3095 "= get latest scan results" },
3096 { "bss", wpa_cli_cmd_bss
,
3098 "<<idx> | <bssid>> = get detailed scan result info" },
3099 { "get_capability", wpa_cli_cmd_get_capability
,
3101 "<eap/pairwise/group/key_mgmt/proto/auth_alg/channels> "
3102 "= get capabilies" },
3103 { "reconfigure", wpa_cli_cmd_reconfigure
,
3105 "= force wpa_supplicant to re-read its configuration file" },
3106 { "terminate", wpa_cli_cmd_terminate
,
3108 "= terminate wpa_supplicant" },
3109 { "interface_add", wpa_cli_cmd_interface_add
,
3111 "<ifname> <confname> <driver> <ctrl_interface> <driver_param>\n"
3112 " <bridge_name> = adds new interface, all parameters but <ifname>\n"
3114 { "interface_remove", wpa_cli_cmd_interface_remove
,
3116 "<ifname> = removes the interface" },
3117 { "interface_list", wpa_cli_cmd_interface_list
,
3119 "= list available interfaces" },
3120 { "ap_scan", wpa_cli_cmd_ap_scan
,
3122 "<value> = set ap_scan parameter" },
3123 { "scan_interval", wpa_cli_cmd_scan_interval
,
3125 "<value> = set scan_interval parameter (in seconds)" },
3126 { "bss_expire_age", wpa_cli_cmd_bss_expire_age
,
3128 "<value> = set BSS expiration age parameter" },
3129 { "bss_expire_count", wpa_cli_cmd_bss_expire_count
,
3131 "<value> = set BSS expiration scan count parameter" },
3132 { "stkstart", wpa_cli_cmd_stkstart
,
3134 "<addr> = request STK negotiation with <addr>" },
3135 { "ft_ds", wpa_cli_cmd_ft_ds
,
3137 "<addr> = request over-the-DS FT with <addr>" },
3138 { "wps_pbc", wpa_cli_cmd_wps_pbc
,
3140 "[BSSID] = start Wi-Fi Protected Setup: Push Button Configuration" },
3141 { "wps_pin", wpa_cli_cmd_wps_pin
,
3142 cli_cmd_flag_sensitive
,
3143 "<BSSID> [PIN] = start WPS PIN method (returns PIN, if not "
3145 { "wps_check_pin", wpa_cli_cmd_wps_check_pin
,
3146 cli_cmd_flag_sensitive
,
3147 "<PIN> = verify PIN checksum" },
3148 { "wps_cancel", wpa_cli_cmd_wps_cancel
, cli_cmd_flag_none
,
3149 "Cancels the pending WPS operation" },
3150 #ifdef CONFIG_WPS_OOB
3151 { "wps_oob", wpa_cli_cmd_wps_oob
,
3152 cli_cmd_flag_sensitive
,
3153 "<DEV_TYPE> <PATH> <METHOD> [DEV_NAME] = start WPS OOB" },
3154 #endif /* CONFIG_WPS_OOB */
3155 #ifdef CONFIG_WPS_NFC
3156 { "wps_nfc", wpa_cli_cmd_wps_nfc
,
3158 "[BSSID] = start Wi-Fi Protected Setup: NFC" },
3159 { "wps_nfc_token", wpa_cli_cmd_wps_nfc_token
,
3161 "<WPS|NDEF> = create password token" },
3162 { "wps_nfc_tag_read", wpa_cli_cmd_wps_nfc_tag_read
,
3163 cli_cmd_flag_sensitive
,
3164 "<hexdump of payload> = report read NFC tag with WPS data" },
3165 #endif /* CONFIG_WPS_NFC */
3166 { "wps_reg", wpa_cli_cmd_wps_reg
,
3167 cli_cmd_flag_sensitive
,
3168 "<BSSID> <AP PIN> = start WPS Registrar to configure an AP" },
3169 { "wps_ap_pin", wpa_cli_cmd_wps_ap_pin
,
3170 cli_cmd_flag_sensitive
,
3171 "[params..] = enable/disable AP PIN" },
3172 { "wps_er_start", wpa_cli_cmd_wps_er_start
,
3174 "[IP address] = start Wi-Fi Protected Setup External Registrar" },
3175 { "wps_er_stop", wpa_cli_cmd_wps_er_stop
,
3177 "= stop Wi-Fi Protected Setup External Registrar" },
3178 { "wps_er_pin", wpa_cli_cmd_wps_er_pin
,
3179 cli_cmd_flag_sensitive
,
3180 "<UUID> <PIN> = add an Enrollee PIN to External Registrar" },
3181 { "wps_er_pbc", wpa_cli_cmd_wps_er_pbc
,
3183 "<UUID> = accept an Enrollee PBC using External Registrar" },
3184 { "wps_er_learn", wpa_cli_cmd_wps_er_learn
,
3185 cli_cmd_flag_sensitive
,
3186 "<UUID> <PIN> = learn AP configuration" },
3187 { "wps_er_set_config", wpa_cli_cmd_wps_er_set_config
,
3189 "<UUID> <network id> = set AP configuration for enrolling" },
3190 { "wps_er_config", wpa_cli_cmd_wps_er_config
,
3191 cli_cmd_flag_sensitive
,
3192 "<UUID> <PIN> <SSID> <auth> <encr> <key> = configure AP" },
3193 #ifdef CONFIG_WPS_NFC
3194 { "wps_er_nfc_config_token", wpa_cli_cmd_wps_er_nfc_config_token
,
3196 "<WPS/NDEF> <UUID> = build NFC configuration token" },
3197 #endif /* CONFIG_WPS_NFC */
3198 { "ibss_rsn", wpa_cli_cmd_ibss_rsn
,
3200 "<addr> = request RSN authentication with <addr> in IBSS" },
3202 { "sta", wpa_cli_cmd_sta
,
3204 "<addr> = get information about an associated station (AP)" },
3205 { "all_sta", wpa_cli_cmd_all_sta
,
3207 "= get information about all associated stations (AP)" },
3208 { "deauthenticate", wpa_cli_cmd_deauthenticate
,
3210 "<addr> = deauthenticate a station" },
3211 { "disassociate", wpa_cli_cmd_disassociate
,
3213 "<addr> = disassociate a station" },
3214 #endif /* CONFIG_AP */
3215 { "suspend", wpa_cli_cmd_suspend
, cli_cmd_flag_none
,
3216 "= notification of suspend/hibernate" },
3217 { "resume", wpa_cli_cmd_resume
, cli_cmd_flag_none
,
3218 "= notification of resume/thaw" },
3219 { "drop_sa", wpa_cli_cmd_drop_sa
, cli_cmd_flag_none
,
3220 "= drop SA without deauth/disassoc (test command)" },
3221 { "roam", wpa_cli_cmd_roam
,
3223 "<addr> = roam to the specified BSS" },
3225 { "p2p_find", wpa_cli_cmd_p2p_find
, cli_cmd_flag_none
,
3226 "[timeout] [type=*] = find P2P Devices for up-to timeout seconds" },
3227 { "p2p_stop_find", wpa_cli_cmd_p2p_stop_find
, cli_cmd_flag_none
,
3228 "= stop P2P Devices search" },
3229 { "p2p_connect", wpa_cli_cmd_p2p_connect
, cli_cmd_flag_none
,
3230 "<addr> <\"pbc\"|PIN> = connect to a P2P Devices" },
3231 { "p2p_listen", wpa_cli_cmd_p2p_listen
, cli_cmd_flag_none
,
3232 "[timeout] = listen for P2P Devices for up-to timeout seconds" },
3233 { "p2p_group_remove", wpa_cli_cmd_p2p_group_remove
, cli_cmd_flag_none
,
3234 "<ifname> = remove P2P group interface (terminate group if GO)" },
3235 { "p2p_group_add", wpa_cli_cmd_p2p_group_add
, cli_cmd_flag_none
,
3236 "= add a new P2P group (local end as GO)" },
3237 { "p2p_prov_disc", wpa_cli_cmd_p2p_prov_disc
, cli_cmd_flag_none
,
3238 "<addr> <method> = request provisioning discovery" },
3239 { "p2p_get_passphrase", wpa_cli_cmd_p2p_get_passphrase
,
3241 "= get the passphrase for a group (GO only)" },
3242 { "p2p_serv_disc_req", wpa_cli_cmd_p2p_serv_disc_req
,
3244 "<addr> <TLVs> = schedule service discovery request" },
3245 { "p2p_serv_disc_cancel_req", wpa_cli_cmd_p2p_serv_disc_cancel_req
,
3247 "<id> = cancel pending service discovery request" },
3248 { "p2p_serv_disc_resp", wpa_cli_cmd_p2p_serv_disc_resp
,
3250 "<freq> <addr> <dialog token> <TLVs> = service discovery response" },
3251 { "p2p_service_update", wpa_cli_cmd_p2p_service_update
,
3253 "= indicate change in local services" },
3254 { "p2p_serv_disc_external", wpa_cli_cmd_p2p_serv_disc_external
,
3256 "<external> = set external processing of service discovery" },
3257 { "p2p_service_flush", wpa_cli_cmd_p2p_service_flush
,
3259 "= remove all stored service entries" },
3260 { "p2p_service_add", wpa_cli_cmd_p2p_service_add
,
3262 "<bonjour|upnp> <query|version> <response|service> = add a local "
3264 { "p2p_service_del", wpa_cli_cmd_p2p_service_del
,
3266 "<bonjour|upnp> <query|version> [|service] = remove a local "
3268 { "p2p_reject", wpa_cli_cmd_p2p_reject
,
3270 "<addr> = reject connection attempts from a specific peer" },
3271 { "p2p_invite", wpa_cli_cmd_p2p_invite
,
3273 "<cmd> [peer=addr] = invite peer" },
3274 { "p2p_peers", wpa_cli_cmd_p2p_peers
, cli_cmd_flag_none
,
3275 "[discovered] = list known (optionally, only fully discovered) P2P "
3277 { "p2p_peer", wpa_cli_cmd_p2p_peer
, cli_cmd_flag_none
,
3278 "<address> = show information about known P2P peer" },
3279 { "p2p_set", wpa_cli_cmd_p2p_set
, cli_cmd_flag_none
,
3280 "<field> <value> = set a P2P parameter" },
3281 { "p2p_flush", wpa_cli_cmd_p2p_flush
, cli_cmd_flag_none
,
3282 "= flush P2P state" },
3283 { "p2p_cancel", wpa_cli_cmd_p2p_cancel
, cli_cmd_flag_none
,
3284 "= cancel P2P group formation" },
3285 { "p2p_unauthorize", wpa_cli_cmd_p2p_unauthorize
, cli_cmd_flag_none
,
3286 "<address> = unauthorize a peer" },
3287 { "p2p_presence_req", wpa_cli_cmd_p2p_presence_req
, cli_cmd_flag_none
,
3288 "[<duration> <interval>] [<duration> <interval>] = request GO "
3290 { "p2p_ext_listen", wpa_cli_cmd_p2p_ext_listen
, cli_cmd_flag_none
,
3291 "[<period> <interval>] = set extended listen timing" },
3292 #endif /* CONFIG_P2P */
3294 #ifdef CONFIG_INTERWORKING
3295 { "fetch_anqp", wpa_cli_cmd_fetch_anqp
, cli_cmd_flag_none
,
3296 "= fetch ANQP information for all APs" },
3297 { "stop_fetch_anqp", wpa_cli_cmd_stop_fetch_anqp
, cli_cmd_flag_none
,
3298 "= stop fetch_anqp operation" },
3299 { "interworking_select", wpa_cli_cmd_interworking_select
,
3301 "[auto] = perform Interworking network selection" },
3302 { "interworking_connect", wpa_cli_cmd_interworking_connect
,
3304 "<BSSID> = connect using Interworking credentials" },
3305 { "anqp_get", wpa_cli_cmd_anqp_get
, cli_cmd_flag_none
,
3306 "<addr> <info id>[,<info id>]... = request ANQP information" },
3307 #endif /* CONFIG_INTERWORKING */
3309 { "hs20_anqp_get", wpa_cli_cmd_hs20_anqp_get
, cli_cmd_flag_none
,
3310 "<addr> <subtype>[,<subtype>]... = request HS 2.0 ANQP information"
3312 { "nai_home_realm_list", wpa_cli_cmd_get_nai_home_realm_list
,
3314 "<addr> <home realm> = get HS20 nai home realm list" },
3315 #endif /* CONFIG_HS20 */
3316 { "sta_autoconnect", wpa_cli_cmd_sta_autoconnect
, cli_cmd_flag_none
,
3317 "<0/1> = disable/enable automatic reconnection" },
3318 { "tdls_discover", wpa_cli_cmd_tdls_discover
,
3320 "<addr> = request TDLS discovery with <addr>" },
3321 { "tdls_setup", wpa_cli_cmd_tdls_setup
,
3323 "<addr> = request TDLS setup with <addr>" },
3324 { "tdls_teardown", wpa_cli_cmd_tdls_teardown
,
3326 "<addr> = tear down TDLS with <addr>" },
3327 { "signal_poll", wpa_cli_cmd_signal_poll
,
3329 "= get signal parameters" },
3330 { "reauthenticate", wpa_cli_cmd_reauthenticate
, cli_cmd_flag_none
,
3331 "= trigger IEEE 802.1X/EAPOL reauthentication" },
3332 #ifdef CONFIG_AUTOSCAN
3333 { "autoscan", wpa_cli_cmd_autoscan
, cli_cmd_flag_none
,
3334 "[params] = Set or unset (if none) autoscan parameters" },
3335 #endif /* CONFIG_AUTOSCAN */
3336 { NULL
, NULL
, cli_cmd_flag_none
, NULL
}
3341 * Prints command usage, lines are padded with the specified string.
3343 static void print_cmd_help(struct wpa_cli_cmd
*cmd
, const char *pad
)
3348 printf("%s%s ", pad
, cmd
->cmd
);
3349 for (n
= 0; (c
= cmd
->usage
[n
]); n
++) {
3358 static void print_help(void)
3361 printf("commands:\n");
3362 for (n
= 0; wpa_cli_commands
[n
].cmd
; n
++)
3363 print_cmd_help(&wpa_cli_commands
[n
], " ");
3367 static int wpa_cli_edit_filter_history_cb(void *ctx
, const char *cmd
)
3369 const char *c
, *delim
;
3373 delim
= os_strchr(cmd
, ' ');
3377 len
= os_strlen(cmd
);
3379 for (n
= 0; (c
= wpa_cli_commands
[n
].cmd
); n
++) {
3380 if (os_strncasecmp(cmd
, c
, len
) == 0 && len
== os_strlen(c
))
3381 return (wpa_cli_commands
[n
].flags
&
3382 cli_cmd_flag_sensitive
);
3388 static char ** wpa_list_cmd_list(void)
3393 count
= sizeof(wpa_cli_commands
) / sizeof(wpa_cli_commands
[0]);
3394 res
= os_zalloc(count
* sizeof(char *));
3398 for (i
= 0; wpa_cli_commands
[i
].cmd
; i
++) {
3399 res
[i
] = os_strdup(wpa_cli_commands
[i
].cmd
);
3408 static char ** wpa_cli_cmd_completion(const char *cmd
, const char *str
,
3413 if (os_strcasecmp(cmd
, "bss") == 0)
3414 return wpa_cli_complete_bss(str
, pos
);
3416 if (os_strcasecmp(cmd
, "p2p_connect") == 0)
3417 return wpa_cli_complete_p2p_connect(str
, pos
);
3418 if (os_strcasecmp(cmd
, "p2p_peer") == 0)
3419 return wpa_cli_complete_p2p_peer(str
, pos
);
3420 if (os_strcasecmp(cmd
, "p2p_group_remove") == 0)
3421 return wpa_cli_complete_p2p_group_remove(str
, pos
);
3422 #endif /* CONFIG_P2P */
3424 for (i
= 0; wpa_cli_commands
[i
].cmd
; i
++) {
3425 if (os_strcasecmp(wpa_cli_commands
[i
].cmd
, cmd
) == 0) {
3427 printf("\r%s\n", wpa_cli_commands
[i
].usage
);
3437 static char ** wpa_cli_edit_completion_cb(void *ctx
, const char *str
, int pos
)
3443 end
= os_strchr(str
, ' ');
3444 if (end
== NULL
|| str
+ pos
< end
)
3445 return wpa_list_cmd_list();
3447 cmd
= os_malloc(pos
+ 1);
3450 os_memcpy(cmd
, str
, pos
);
3451 cmd
[end
- str
] = '\0';
3452 res
= wpa_cli_cmd_completion(cmd
, str
, pos
);
3458 static int wpa_request(struct wpa_ctrl
*ctrl
, int argc
, char *argv
[])
3460 struct wpa_cli_cmd
*cmd
, *match
= NULL
;
3465 cmd
= wpa_cli_commands
;
3467 if (os_strncasecmp(cmd
->cmd
, argv
[0], os_strlen(argv
[0])) == 0)
3470 if (os_strcasecmp(cmd
->cmd
, argv
[0]) == 0) {
3471 /* we have an exact match */
3481 printf("Ambiguous command '%s'; possible commands:", argv
[0]);
3482 cmd
= wpa_cli_commands
;
3484 if (os_strncasecmp(cmd
->cmd
, argv
[0],
3485 os_strlen(argv
[0])) == 0) {
3486 printf(" %s", cmd
->cmd
);
3492 } else if (count
== 0) {
3493 printf("Unknown command '%s'\n", argv
[0]);
3496 ret
= match
->handler(ctrl
, argc
- 1, &argv
[1]);
3503 static int str_match(const char *a
, const char *b
)
3505 return os_strncmp(a
, b
, os_strlen(b
)) == 0;
3509 static int wpa_cli_exec(const char *program
, const char *arg1
,
3517 len
= os_strlen(program
) + os_strlen(arg1
) + os_strlen(arg2
) + 3;
3518 cmd
= os_malloc(len
);
3521 res
= os_snprintf(cmd
, len
, "%s %s %s", program
, arg1
, arg2
);
3522 if (res
< 0 || (size_t) res
>= len
) {
3526 cmd
[len
- 1] = '\0';
3528 if (system(cmd
) < 0)
3530 #endif /* _WIN32_WCE */
3537 static void wpa_cli_action_process(const char *msg
)
3540 char *copy
= NULL
, *id
, *pos2
;
3545 pos
= os_strchr(pos
, '>');
3552 if (str_match(pos
, WPA_EVENT_CONNECTED
)) {
3554 os_unsetenv("WPA_ID");
3555 os_unsetenv("WPA_ID_STR");
3556 os_unsetenv("WPA_CTRL_DIR");
3558 pos
= os_strstr(pos
, "[id=");
3560 copy
= os_strdup(pos
+ 4);
3564 while (*pos2
&& *pos2
!= ' ')
3568 os_setenv("WPA_ID", id
, 1);
3569 while (*pos2
&& *pos2
!= '=')
3574 while (*pos2
&& *pos2
!= ']')
3577 os_setenv("WPA_ID_STR", id
, 1);
3581 os_setenv("WPA_CTRL_DIR", ctrl_iface_dir
, 1);
3583 if (!wpa_cli_connected
|| new_id
!= wpa_cli_last_id
) {
3584 wpa_cli_connected
= 1;
3585 wpa_cli_last_id
= new_id
;
3586 wpa_cli_exec(action_file
, ctrl_ifname
, "CONNECTED");
3588 } else if (str_match(pos
, WPA_EVENT_DISCONNECTED
)) {
3589 if (wpa_cli_connected
) {
3590 wpa_cli_connected
= 0;
3591 wpa_cli_exec(action_file
, ctrl_ifname
, "DISCONNECTED");
3593 } else if (str_match(pos
, P2P_EVENT_GROUP_STARTED
)) {
3594 wpa_cli_exec(action_file
, ctrl_ifname
, pos
);
3595 } else if (str_match(pos
, P2P_EVENT_GROUP_REMOVED
)) {
3596 wpa_cli_exec(action_file
, ctrl_ifname
, pos
);
3597 } else if (str_match(pos
, P2P_EVENT_CROSS_CONNECT_ENABLE
)) {
3598 wpa_cli_exec(action_file
, ctrl_ifname
, pos
);
3599 } else if (str_match(pos
, P2P_EVENT_CROSS_CONNECT_DISABLE
)) {
3600 wpa_cli_exec(action_file
, ctrl_ifname
, pos
);
3601 } else if (str_match(pos
, P2P_EVENT_GO_NEG_FAILURE
)) {
3602 wpa_cli_exec(action_file
, ctrl_ifname
, pos
);
3603 } else if (str_match(pos
, WPS_EVENT_SUCCESS
)) {
3604 wpa_cli_exec(action_file
, ctrl_ifname
, pos
);
3605 } else if (str_match(pos
, WPS_EVENT_FAIL
)) {
3606 wpa_cli_exec(action_file
, ctrl_ifname
, pos
);
3607 } else if (str_match(pos
, AP_STA_CONNECTED
)) {
3608 wpa_cli_exec(action_file
, ctrl_ifname
, pos
);
3609 } else if (str_match(pos
, AP_STA_DISCONNECTED
)) {
3610 wpa_cli_exec(action_file
, ctrl_ifname
, pos
);
3611 } else if (str_match(pos
, WPA_EVENT_TERMINATING
)) {
3612 printf("wpa_supplicant is terminating - stop monitoring\n");
3618 #ifndef CONFIG_ANSI_C_EXTRA
3619 static void wpa_cli_action_cb(char *msg
, size_t len
)
3621 wpa_cli_action_process(msg
);
3623 #endif /* CONFIG_ANSI_C_EXTRA */
3626 static void wpa_cli_reconnect(void)
3628 wpa_cli_close_connection();
3629 wpa_cli_open_connection(ctrl_ifname
, 1);
3633 static void cli_event(const char *str
)
3635 const char *start
, *s
;
3637 start
= os_strchr(str
, '>');
3643 if (str_starts(start
, WPA_EVENT_BSS_ADDED
)) {
3644 s
= os_strchr(start
, ' ');
3647 s
= os_strchr(s
+ 1, ' ');
3650 cli_txt_list_add(&bsses
, s
+ 1);
3654 if (str_starts(start
, WPA_EVENT_BSS_REMOVED
)) {
3655 s
= os_strchr(start
, ' ');
3658 s
= os_strchr(s
+ 1, ' ');
3661 cli_txt_list_del_addr(&bsses
, s
+ 1);
3666 if (str_starts(start
, P2P_EVENT_DEVICE_FOUND
)) {
3667 s
= os_strstr(start
, " p2p_dev_addr=");
3670 cli_txt_list_add_addr(&p2p_peers
, s
+ 14);
3674 if (str_starts(start
, P2P_EVENT_DEVICE_LOST
)) {
3675 s
= os_strstr(start
, " p2p_dev_addr=");
3678 cli_txt_list_del_addr(&p2p_peers
, s
+ 14);
3682 if (str_starts(start
, P2P_EVENT_GROUP_STARTED
)) {
3683 s
= os_strchr(start
, ' ');
3686 cli_txt_list_add_word(&p2p_groups
, s
+ 1);
3690 if (str_starts(start
, P2P_EVENT_GROUP_REMOVED
)) {
3691 s
= os_strchr(start
, ' ');
3694 cli_txt_list_del_word(&p2p_groups
, s
+ 1);
3697 #endif /* CONFIG_P2P */
3701 static void wpa_cli_recv_pending(struct wpa_ctrl
*ctrl
, int action_monitor
)
3703 if (ctrl_conn
== NULL
) {
3704 wpa_cli_reconnect();
3707 while (wpa_ctrl_pending(ctrl
) > 0) {
3709 size_t len
= sizeof(buf
) - 1;
3710 if (wpa_ctrl_recv(ctrl
, buf
, &len
) == 0) {
3713 wpa_cli_action_process(buf
);
3716 if (wpa_cli_show_event(buf
)) {
3718 printf("\r%s\n", buf
);
3723 printf("Could not read pending message.\n");
3728 if (wpa_ctrl_pending(ctrl
) < 0) {
3729 printf("Connection to wpa_supplicant lost - trying to "
3731 wpa_cli_reconnect();
3737 static int tokenize_cmd(char *cmd
, char *argv
[])
3750 if (argc
== max_args
)
3753 char *pos2
= os_strrchr(pos
, '"');
3757 while (*pos
!= '\0' && *pos
!= ' ')
3767 static void wpa_cli_ping(void *eloop_ctx
, void *timeout_ctx
)
3769 if (ctrl_conn
&& _wpa_ctrl_command(ctrl_conn
, "PING", 0)) {
3770 printf("Connection to wpa_supplicant lost - trying to "
3772 wpa_cli_close_connection();
3775 wpa_cli_reconnect();
3776 eloop_register_timeout(ping_interval
, 0, wpa_cli_ping
, NULL
, NULL
);
3780 static void wpa_cli_mon_receive(int sock
, void *eloop_ctx
, void *sock_ctx
)
3782 wpa_cli_recv_pending(mon_conn
, 0);
3786 static void wpa_cli_edit_cmd_cb(void *ctx
, char *cmd
)
3788 char *argv
[max_args
];
3790 argc
= tokenize_cmd(cmd
, argv
);
3792 wpa_request(ctrl_conn
, argc
, argv
);
3796 static void wpa_cli_edit_eof_cb(void *ctx
)
3802 static int warning_displayed
= 0;
3803 static char *hfile
= NULL
;
3804 static int edit_started
= 0;
3806 static void start_edit(void)
3810 home
= getenv("HOME");
3812 const char *fname
= ".wpa_cli_history";
3813 int hfile_len
= os_strlen(home
) + 1 + os_strlen(fname
) + 1;
3814 hfile
= os_malloc(hfile_len
);
3816 os_snprintf(hfile
, hfile_len
, "%s/%s", home
, fname
);
3819 if (edit_init(wpa_cli_edit_cmd_cb
, wpa_cli_edit_eof_cb
,
3820 wpa_cli_edit_completion_cb
, NULL
, hfile
,
3821 wpa_ctrl_get_remote_ifname(ctrl_conn
)) < 0) {
3827 eloop_register_timeout(ping_interval
, 0, wpa_cli_ping
, NULL
, NULL
);
3831 static void try_connection(void *eloop_ctx
, void *timeout_ctx
)
3833 if (!wpa_cli_open_connection(ctrl_ifname
, 1) == 0) {
3834 if (!warning_displayed
) {
3835 printf("Could not connect to wpa_supplicant: "
3836 "%s - re-trying\n", ctrl_ifname
);
3837 warning_displayed
= 1;
3839 eloop_register_timeout(1, 0, try_connection
, NULL
, NULL
);
3843 if (warning_displayed
)
3844 printf("Connection established.\n");
3850 static void wpa_cli_interactive(void)
3852 printf("\nInteractive mode\n\n");
3854 eloop_register_timeout(0, 0, try_connection
, NULL
, NULL
);
3856 eloop_cancel_timeout(try_connection
, NULL
, NULL
);
3858 cli_txt_list_flush(&p2p_peers
);
3859 cli_txt_list_flush(&p2p_groups
);
3860 cli_txt_list_flush(&bsses
);
3862 edit_deinit(hfile
, wpa_cli_edit_filter_history_cb
);
3864 eloop_cancel_timeout(wpa_cli_ping
, NULL
, NULL
);
3865 wpa_cli_close_connection();
3869 static void wpa_cli_action(struct wpa_ctrl
*ctrl
)
3871 #ifdef CONFIG_ANSI_C_EXTRA
3872 /* TODO: ANSI C version(?) */
3873 printf("Action processing not supported in ANSI C build.\n");
3874 #else /* CONFIG_ANSI_C_EXTRA */
3878 char buf
[256]; /* note: large enough to fit in unsolicited messages */
3881 fd
= wpa_ctrl_get_fd(ctrl
);
3883 while (!wpa_cli_quit
) {
3886 tv
.tv_sec
= ping_interval
;
3888 res
= select(fd
+ 1, &rfds
, NULL
, NULL
, &tv
);
3889 if (res
< 0 && errno
!= EINTR
) {
3894 if (FD_ISSET(fd
, &rfds
))
3895 wpa_cli_recv_pending(ctrl
, 1);
3897 /* verify that connection is still working */
3898 len
= sizeof(buf
) - 1;
3899 if (wpa_ctrl_request(ctrl
, "PING", 4, buf
, &len
,
3900 wpa_cli_action_cb
) < 0 ||
3901 len
< 4 || os_memcmp(buf
, "PONG", 4) != 0) {
3902 printf("wpa_supplicant did not reply to PING "
3903 "command - exiting\n");
3908 #endif /* CONFIG_ANSI_C_EXTRA */
3912 static void wpa_cli_cleanup(void)
3914 wpa_cli_close_connection();
3916 os_daemonize_terminate(pid_file
);
3918 os_program_deinit();
3922 static void wpa_cli_terminate(int sig
, void *ctx
)
3928 static char * wpa_cli_get_default_ifname(void)
3930 char *ifname
= NULL
;
3932 #ifdef CONFIG_CTRL_IFACE_UNIX
3933 struct dirent
*dent
;
3934 DIR *dir
= opendir(ctrl_iface_dir
);
3937 char ifprop
[PROPERTY_VALUE_MAX
];
3938 if (property_get("wifi.interface", ifprop
, NULL
) != 0) {
3939 ifname
= os_strdup(ifprop
);
3940 printf("Using interface '%s'\n", ifname
);
3943 #endif /* ANDROID */
3946 while ((dent
= readdir(dir
))) {
3947 #ifdef _DIRENT_HAVE_D_TYPE
3949 * Skip the file if it is not a socket. Also accept
3950 * DT_UNKNOWN (0) in case the C library or underlying
3951 * file system does not support d_type.
3953 if (dent
->d_type
!= DT_SOCK
&& dent
->d_type
!= DT_UNKNOWN
)
3955 #endif /* _DIRENT_HAVE_D_TYPE */
3956 if (os_strcmp(dent
->d_name
, ".") == 0 ||
3957 os_strcmp(dent
->d_name
, "..") == 0)
3959 printf("Selected interface '%s'\n", dent
->d_name
);
3960 ifname
= os_strdup(dent
->d_name
);
3964 #endif /* CONFIG_CTRL_IFACE_UNIX */
3966 #ifdef CONFIG_CTRL_IFACE_NAMED_PIPE
3967 char buf
[2048], *pos
;
3969 struct wpa_ctrl
*ctrl
;
3972 ctrl
= wpa_ctrl_open(NULL
);
3976 len
= sizeof(buf
) - 1;
3977 ret
= wpa_ctrl_request(ctrl
, "INTERFACES", 10, buf
, &len
, NULL
);
3980 pos
= os_strchr(buf
, '\n');
3983 ifname
= os_strdup(buf
);
3985 wpa_ctrl_close(ctrl
);
3986 #endif /* CONFIG_CTRL_IFACE_NAMED_PIPE */
3992 int main(int argc
, char *argv
[])
3997 const char *global
= NULL
;
3999 if (os_program_init())
4003 c
= getopt(argc
, argv
, "a:Bg:G:hi:p:P:v");
4008 action_file
= optarg
;
4017 ping_interval
= atoi(optarg
);
4023 printf("%s\n", wpa_cli_version
);
4026 os_free(ctrl_ifname
);
4027 ctrl_ifname
= os_strdup(optarg
);
4030 ctrl_iface_dir
= optarg
;
4041 interactive
= (argc
== optind
) && (action_file
== NULL
);
4044 printf("%s\n\n%s\n\n", wpa_cli_version
, wpa_cli_license
);
4050 #ifdef CONFIG_CTRL_IFACE_NAMED_PIPE
4051 ctrl_conn
= wpa_ctrl_open(NULL
);
4052 #else /* CONFIG_CTRL_IFACE_NAMED_PIPE */
4053 ctrl_conn
= wpa_ctrl_open(global
);
4054 #endif /* CONFIG_CTRL_IFACE_NAMED_PIPE */
4055 if (ctrl_conn
== NULL
) {
4056 fprintf(stderr
, "Failed to connect to wpa_supplicant "
4057 "global interface: %s error: %s\n",
4058 global
, strerror(errno
));
4063 eloop_register_signal_terminate(wpa_cli_terminate
, NULL
);
4065 if (ctrl_ifname
== NULL
)
4066 ctrl_ifname
= wpa_cli_get_default_ifname();
4069 wpa_cli_interactive();
4072 wpa_cli_open_connection(ctrl_ifname
, 0) < 0) {
4073 fprintf(stderr
, "Failed to connect to non-global "
4074 "ctrl_ifname: %s error: %s\n",
4075 ctrl_ifname
, strerror(errno
));
4080 if (wpa_ctrl_attach(ctrl_conn
) == 0) {
4081 wpa_cli_attached
= 1;
4083 printf("Warning: Failed to attach to "
4084 "wpa_supplicant.\n");
4089 if (daemonize
&& os_daemonize(pid_file
))
4093 wpa_cli_action(ctrl_conn
);
4095 ret
= wpa_request(ctrl_conn
, argc
- optind
,
4099 os_free(ctrl_ifname
);
4106 #else /* CONFIG_CTRL_IFACE */
4107 int main(int argc
, char *argv
[])
4109 printf("CONFIG_CTRL_IFACE not defined - wpa_cli disabled\n");
4112 #endif /* CONFIG_CTRL_IFACE */