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);
98 static char * wpa_cli_get_default_ifname(void);
101 static void usage(void)
103 printf("wpa_cli [-p<path to ctrl sockets>] [-i<ifname>] [-hvB] "
104 "[-a<action file>] \\\n"
105 " [-P<pid file>] [-g<global ctrl>] [-G<ping interval>] "
107 " -h = help (show this usage text)\n"
108 " -v = shown version information\n"
109 " -a = run in daemon mode executing the action file based on "
112 " -B = run a daemon in the background\n"
113 " default path: " CONFIG_CTRL_IFACE_DIR
"\n"
114 " default interface: first interface found in socket path\n");
119 static void cli_txt_list_free(struct cli_txt_entry
*e
)
121 dl_list_del(&e
->list
);
127 static void cli_txt_list_flush(struct dl_list
*list
)
129 struct cli_txt_entry
*e
;
130 while ((e
= dl_list_first(list
, struct cli_txt_entry
, list
)))
131 cli_txt_list_free(e
);
135 static struct cli_txt_entry
* cli_txt_list_get(struct dl_list
*txt_list
,
138 struct cli_txt_entry
*e
;
139 dl_list_for_each(e
, txt_list
, struct cli_txt_entry
, list
) {
140 if (os_strcmp(e
->txt
, txt
) == 0)
147 static void cli_txt_list_del(struct dl_list
*txt_list
, const char *txt
)
149 struct cli_txt_entry
*e
;
150 e
= cli_txt_list_get(txt_list
, txt
);
152 cli_txt_list_free(e
);
156 static void cli_txt_list_del_addr(struct dl_list
*txt_list
, const char *txt
)
160 if (hwaddr_aton(txt
, addr
) < 0)
162 os_snprintf(buf
, sizeof(buf
), MACSTR
, MAC2STR(addr
));
163 cli_txt_list_del(txt_list
, buf
);
168 static void cli_txt_list_del_word(struct dl_list
*txt_list
, const char *txt
)
172 end
= os_strchr(txt
, ' ');
174 end
= txt
+ os_strlen(txt
);
175 buf
= os_malloc(end
- txt
+ 1);
178 os_memcpy(buf
, txt
, end
- txt
);
179 buf
[end
- txt
] = '\0';
180 cli_txt_list_del(txt_list
, buf
);
183 #endif /* CONFIG_P2P */
186 static int cli_txt_list_add(struct dl_list
*txt_list
, const char *txt
)
188 struct cli_txt_entry
*e
;
189 e
= cli_txt_list_get(txt_list
, txt
);
192 e
= os_zalloc(sizeof(*e
));
195 e
->txt
= os_strdup(txt
);
196 if (e
->txt
== NULL
) {
200 dl_list_add(txt_list
, &e
->list
);
206 static int cli_txt_list_add_addr(struct dl_list
*txt_list
, const char *txt
)
210 if (hwaddr_aton(txt
, addr
) < 0)
212 os_snprintf(buf
, sizeof(buf
), MACSTR
, MAC2STR(addr
));
213 return cli_txt_list_add(txt_list
, buf
);
217 static int cli_txt_list_add_word(struct dl_list
*txt_list
, const char *txt
)
222 end
= os_strchr(txt
, ' ');
224 end
= txt
+ os_strlen(txt
);
225 buf
= os_malloc(end
- txt
+ 1);
228 os_memcpy(buf
, txt
, end
- txt
);
229 buf
[end
- txt
] = '\0';
230 ret
= cli_txt_list_add(txt_list
, buf
);
234 #endif /* CONFIG_P2P */
237 static char ** cli_txt_list_array(struct dl_list
*txt_list
)
239 unsigned int i
, count
= dl_list_len(txt_list
);
241 struct cli_txt_entry
*e
;
243 res
= os_calloc(count
+ 1, sizeof(char *));
248 dl_list_for_each(e
, txt_list
, struct cli_txt_entry
, list
) {
249 res
[i
] = os_strdup(e
->txt
);
259 static int get_cmd_arg_num(const char *str
, int pos
)
263 for (i
= 0; i
<= pos
; i
++) {
266 while (i
<= pos
&& str
[i
] != ' ')
277 static int str_starts(const char *src
, const char *match
)
279 return os_strncmp(src
, match
, os_strlen(match
)) == 0;
283 static int wpa_cli_show_event(const char *event
)
287 start
= os_strchr(event
, '>');
293 * Skip BSS added/removed events since they can be relatively frequent
294 * and are likely of not much use for an interactive user.
296 if (str_starts(start
, WPA_EVENT_BSS_ADDED
) ||
297 str_starts(start
, WPA_EVENT_BSS_REMOVED
))
304 static int wpa_cli_open_connection(const char *ifname
, int attach
)
306 #if defined(CONFIG_CTRL_IFACE_UDP) || defined(CONFIG_CTRL_IFACE_NAMED_PIPE)
307 ctrl_conn
= wpa_ctrl_open(ifname
);
308 if (ctrl_conn
== NULL
)
311 if (attach
&& interactive
)
312 mon_conn
= wpa_ctrl_open(ifname
);
315 #else /* CONFIG_CTRL_IFACE_UDP || CONFIG_CTRL_IFACE_NAMED_PIPE */
323 if (access(ctrl_iface_dir
, F_OK
) < 0) {
324 cfile
= os_strdup(ifname
);
331 flen
= os_strlen(ctrl_iface_dir
) + os_strlen(ifname
) + 2;
332 cfile
= os_malloc(flen
);
335 res
= os_snprintf(cfile
, flen
, "%s/%s", ctrl_iface_dir
,
337 if (res
< 0 || res
>= flen
) {
343 ctrl_conn
= wpa_ctrl_open(cfile
);
344 if (ctrl_conn
== NULL
) {
349 if (attach
&& interactive
)
350 mon_conn
= wpa_ctrl_open(cfile
);
354 #endif /* CONFIG_CTRL_IFACE_UDP || CONFIG_CTRL_IFACE_NAMED_PIPE */
357 if (wpa_ctrl_attach(mon_conn
) == 0) {
358 wpa_cli_attached
= 1;
360 eloop_register_read_sock(
361 wpa_ctrl_get_fd(mon_conn
),
362 wpa_cli_mon_receive
, NULL
, NULL
);
364 printf("Warning: Failed to attach to "
365 "wpa_supplicant.\n");
366 wpa_cli_close_connection();
375 static void wpa_cli_close_connection(void)
377 if (ctrl_conn
== NULL
)
380 if (wpa_cli_attached
) {
381 wpa_ctrl_detach(interactive
? mon_conn
: ctrl_conn
);
382 wpa_cli_attached
= 0;
384 wpa_ctrl_close(ctrl_conn
);
387 eloop_unregister_read_sock(wpa_ctrl_get_fd(mon_conn
));
388 wpa_ctrl_close(mon_conn
);
394 static void wpa_cli_msg_cb(char *msg
, size_t len
)
400 static int _wpa_ctrl_command(struct wpa_ctrl
*ctrl
, char *cmd
, int print
)
406 if (ctrl_conn
== NULL
) {
407 printf("Not connected to wpa_supplicant - command dropped.\n");
410 len
= sizeof(buf
) - 1;
411 ret
= wpa_ctrl_request(ctrl
, cmd
, os_strlen(cmd
), buf
, &len
,
414 printf("'%s' command timed out.\n", cmd
);
416 } else if (ret
< 0) {
417 printf("'%s' command failed.\n", cmd
);
423 if (interactive
&& len
> 0 && buf
[len
- 1] != '\n')
430 static int wpa_ctrl_command(struct wpa_ctrl
*ctrl
, char *cmd
)
432 return _wpa_ctrl_command(ctrl
, cmd
, 1);
436 static int wpa_cli_cmd_ifname(struct wpa_ctrl
*ctrl
, int argc
, char *argv
[])
438 return wpa_ctrl_command(ctrl
, "IFNAME");
442 static int wpa_cli_cmd_status(struct wpa_ctrl
*ctrl
, int argc
, char *argv
[])
444 if (argc
> 0 && os_strcmp(argv
[0], "verbose") == 0)
445 return wpa_ctrl_command(ctrl
, "STATUS-VERBOSE");
446 if (argc
> 0 && os_strcmp(argv
[0], "wps") == 0)
447 return wpa_ctrl_command(ctrl
, "STATUS-WPS");
448 return wpa_ctrl_command(ctrl
, "STATUS");
452 static int wpa_cli_cmd_ping(struct wpa_ctrl
*ctrl
, int argc
, char *argv
[])
454 return wpa_ctrl_command(ctrl
, "PING");
458 static int wpa_cli_cmd_relog(struct wpa_ctrl
*ctrl
, int argc
, char *argv
[])
460 return wpa_ctrl_command(ctrl
, "RELOG");
464 static int wpa_cli_cmd_note(struct wpa_ctrl
*ctrl
, int argc
, char *argv
[])
470 ret
= os_snprintf(cmd
, sizeof(cmd
), "NOTE %s", argv
[0]);
471 if (ret
< 0 || (size_t) ret
>= sizeof(cmd
))
473 return wpa_ctrl_command(ctrl
, cmd
);
477 static int wpa_cli_cmd_mib(struct wpa_ctrl
*ctrl
, int argc
, char *argv
[])
479 return wpa_ctrl_command(ctrl
, "MIB");
483 static int wpa_cli_cmd_pmksa(struct wpa_ctrl
*ctrl
, int argc
, char *argv
[])
485 return wpa_ctrl_command(ctrl
, "PMKSA");
489 static int wpa_cli_cmd_help(struct wpa_ctrl
*ctrl
, int argc
, char *argv
[])
496 static int wpa_cli_cmd_license(struct wpa_ctrl
*ctrl
, int argc
, char *argv
[])
498 printf("%s\n\n%s\n", wpa_cli_version
, wpa_cli_full_license
);
503 static int wpa_cli_cmd_quit(struct wpa_ctrl
*ctrl
, int argc
, char *argv
[])
512 static void wpa_cli_show_variables(void)
514 printf("set variables:\n"
515 " EAPOL::heldPeriod (EAPOL state machine held period, "
517 " EAPOL::authPeriod (EAPOL state machine authentication "
518 "period, in seconds)\n"
519 " EAPOL::startPeriod (EAPOL state machine start period, in "
521 " EAPOL::maxStart (EAPOL state machine maximum start "
523 printf(" dot11RSNAConfigPMKLifetime (WPA/WPA2 PMK lifetime in "
525 " dot11RSNAConfigPMKReauthThreshold (WPA/WPA2 reauthentication"
526 " threshold\n\tpercentage)\n"
527 " dot11RSNAConfigSATimeout (WPA/WPA2 timeout for completing "
528 "security\n\tassociation in seconds)\n");
532 static int wpa_cli_cmd_set(struct wpa_ctrl
*ctrl
, int argc
, char *argv
[])
538 wpa_cli_show_variables();
542 if (argc
!= 1 && argc
!= 2) {
543 printf("Invalid SET command: needs two arguments (variable "
544 "name and value)\n");
549 res
= os_snprintf(cmd
, sizeof(cmd
), "SET %s ", argv
[0]);
551 res
= os_snprintf(cmd
, sizeof(cmd
), "SET %s %s",
553 if (res
< 0 || (size_t) res
>= sizeof(cmd
) - 1) {
554 printf("Too long SET command.\n");
557 return wpa_ctrl_command(ctrl
, cmd
);
561 static int wpa_cli_cmd_get(struct wpa_ctrl
*ctrl
, int argc
, char *argv
[])
567 printf("Invalid GET command: need one argument (variable "
572 res
= os_snprintf(cmd
, sizeof(cmd
), "GET %s", argv
[0]);
573 if (res
< 0 || (size_t) res
>= sizeof(cmd
) - 1) {
574 printf("Too long GET command.\n");
577 return wpa_ctrl_command(ctrl
, cmd
);
581 static int wpa_cli_cmd_logoff(struct wpa_ctrl
*ctrl
, int argc
, char *argv
[])
583 return wpa_ctrl_command(ctrl
, "LOGOFF");
587 static int wpa_cli_cmd_logon(struct wpa_ctrl
*ctrl
, int argc
, char *argv
[])
589 return wpa_ctrl_command(ctrl
, "LOGON");
593 static int wpa_cli_cmd_reassociate(struct wpa_ctrl
*ctrl
, int argc
,
596 return wpa_ctrl_command(ctrl
, "REASSOCIATE");
600 static int wpa_cli_cmd_preauthenticate(struct wpa_ctrl
*ctrl
, int argc
,
607 printf("Invalid PREAUTH command: needs one argument "
612 res
= os_snprintf(cmd
, sizeof(cmd
), "PREAUTH %s", argv
[0]);
613 if (res
< 0 || (size_t) res
>= sizeof(cmd
) - 1) {
614 printf("Too long PREAUTH command.\n");
617 return wpa_ctrl_command(ctrl
, cmd
);
621 static int wpa_cli_cmd_ap_scan(struct wpa_ctrl
*ctrl
, int argc
, char *argv
[])
627 printf("Invalid AP_SCAN command: needs one argument (ap_scan "
631 res
= os_snprintf(cmd
, sizeof(cmd
), "AP_SCAN %s", argv
[0]);
632 if (res
< 0 || (size_t) res
>= sizeof(cmd
) - 1) {
633 printf("Too long AP_SCAN command.\n");
636 return wpa_ctrl_command(ctrl
, cmd
);
640 static int wpa_cli_cmd_scan_interval(struct wpa_ctrl
*ctrl
, int argc
,
647 printf("Invalid SCAN_INTERVAL command: needs one argument "
648 "scan_interval value)\n");
651 res
= os_snprintf(cmd
, sizeof(cmd
), "SCAN_INTERVAL %s", argv
[0]);
652 if (res
< 0 || (size_t) res
>= sizeof(cmd
) - 1) {
653 printf("Too long SCAN_INTERVAL command.\n");
656 return wpa_ctrl_command(ctrl
, cmd
);
660 static int wpa_cli_cmd_bss_expire_age(struct wpa_ctrl
*ctrl
, int argc
,
667 printf("Invalid BSS_EXPIRE_AGE command: needs one argument "
668 "(bss_expire_age value)\n");
671 res
= os_snprintf(cmd
, sizeof(cmd
), "BSS_EXPIRE_AGE %s", argv
[0]);
672 if (res
< 0 || (size_t) res
>= sizeof(cmd
) - 1) {
673 printf("Too long BSS_EXPIRE_AGE command.\n");
676 return wpa_ctrl_command(ctrl
, cmd
);
680 static int wpa_cli_cmd_bss_expire_count(struct wpa_ctrl
*ctrl
, int argc
,
687 printf("Invalid BSS_EXPIRE_COUNT command: needs one argument "
688 "(bss_expire_count value)\n");
691 res
= os_snprintf(cmd
, sizeof(cmd
), "BSS_EXPIRE_COUNT %s", argv
[0]);
692 if (res
< 0 || (size_t) res
>= sizeof(cmd
) - 1) {
693 printf("Too long BSS_EXPIRE_COUNT command.\n");
696 return wpa_ctrl_command(ctrl
, cmd
);
700 static int wpa_cli_cmd_stkstart(struct wpa_ctrl
*ctrl
, int argc
,
707 printf("Invalid STKSTART command: needs one argument "
708 "(Peer STA MAC address)\n");
712 res
= os_snprintf(cmd
, sizeof(cmd
), "STKSTART %s", argv
[0]);
713 if (res
< 0 || (size_t) res
>= sizeof(cmd
) - 1) {
714 printf("Too long STKSTART command.\n");
717 return wpa_ctrl_command(ctrl
, cmd
);
721 static int wpa_cli_cmd_ft_ds(struct wpa_ctrl
*ctrl
, int argc
, char *argv
[])
727 printf("Invalid FT_DS command: needs one argument "
728 "(Target AP MAC address)\n");
732 res
= os_snprintf(cmd
, sizeof(cmd
), "FT_DS %s", argv
[0]);
733 if (res
< 0 || (size_t) res
>= sizeof(cmd
) - 1) {
734 printf("Too long FT_DS command.\n");
737 return wpa_ctrl_command(ctrl
, cmd
);
741 static int wpa_cli_cmd_wps_pbc(struct wpa_ctrl
*ctrl
, int argc
, char *argv
[])
748 return wpa_ctrl_command(ctrl
, "WPS_PBC");
752 res
= os_snprintf(cmd
, sizeof(cmd
), "WPS_PBC %s", argv
[0]);
753 if (res
< 0 || (size_t) res
>= sizeof(cmd
) - 1) {
754 printf("Too long WPS_PBC command.\n");
757 return wpa_ctrl_command(ctrl
, cmd
);
761 static int wpa_cli_cmd_wps_pin(struct wpa_ctrl
*ctrl
, int argc
, char *argv
[])
767 printf("Invalid WPS_PIN command: need one or two arguments:\n"
768 "- BSSID: use 'any' to select any\n"
769 "- PIN: optional, used only with devices that have no "
775 /* Use dynamically generated PIN (returned as reply) */
776 res
= os_snprintf(cmd
, sizeof(cmd
), "WPS_PIN %s", argv
[0]);
777 if (res
< 0 || (size_t) res
>= sizeof(cmd
) - 1) {
778 printf("Too long WPS_PIN command.\n");
781 return wpa_ctrl_command(ctrl
, cmd
);
784 /* Use hardcoded PIN from a label */
785 res
= os_snprintf(cmd
, sizeof(cmd
), "WPS_PIN %s %s", argv
[0], argv
[1]);
786 if (res
< 0 || (size_t) res
>= sizeof(cmd
) - 1) {
787 printf("Too long WPS_PIN command.\n");
790 return wpa_ctrl_command(ctrl
, cmd
);
794 static int wpa_cli_cmd_wps_check_pin(struct wpa_ctrl
*ctrl
, int argc
,
800 if (argc
!= 1 && argc
!= 2) {
801 printf("Invalid WPS_CHECK_PIN command: needs one argument:\n"
802 "- PIN to be verified\n");
807 res
= os_snprintf(cmd
, sizeof(cmd
), "WPS_CHECK_PIN %s %s",
810 res
= os_snprintf(cmd
, sizeof(cmd
), "WPS_CHECK_PIN %s",
812 if (res
< 0 || (size_t) res
>= sizeof(cmd
) - 1) {
813 printf("Too long WPS_CHECK_PIN command.\n");
816 return wpa_ctrl_command(ctrl
, cmd
);
820 static int wpa_cli_cmd_wps_cancel(struct wpa_ctrl
*ctrl
, int argc
,
823 return wpa_ctrl_command(ctrl
, "WPS_CANCEL");
827 #ifdef CONFIG_WPS_OOB
828 static int wpa_cli_cmd_wps_oob(struct wpa_ctrl
*ctrl
, int argc
, char *argv
[])
833 if (argc
!= 3 && argc
!= 4) {
834 printf("Invalid WPS_OOB command: need three or four "
836 "- DEV_TYPE: use 'ufd' or 'nfc'\n"
837 "- PATH: path of OOB device like '/mnt'\n"
838 "- METHOD: OOB method 'pin-e' or 'pin-r', "
840 "- DEV_NAME: (only for NFC) device name like "
846 res
= os_snprintf(cmd
, sizeof(cmd
), "WPS_OOB %s %s %s",
847 argv
[0], argv
[1], argv
[2]);
849 res
= os_snprintf(cmd
, sizeof(cmd
), "WPS_OOB %s %s %s %s",
850 argv
[0], argv
[1], argv
[2], argv
[3]);
851 if (res
< 0 || (size_t) res
>= sizeof(cmd
) - 1) {
852 printf("Too long WPS_OOB command.\n");
855 return wpa_ctrl_command(ctrl
, cmd
);
857 #endif /* CONFIG_WPS_OOB */
860 #ifdef CONFIG_WPS_NFC
862 static int wpa_cli_cmd_wps_nfc(struct wpa_ctrl
*ctrl
, int argc
, char *argv
[])
868 res
= os_snprintf(cmd
, sizeof(cmd
), "WPS_NFC %s",
871 res
= os_snprintf(cmd
, sizeof(cmd
), "WPS_NFC");
872 if (res
< 0 || (size_t) res
>= sizeof(cmd
) - 1) {
873 printf("Too long WPS_NFC command.\n");
876 return wpa_ctrl_command(ctrl
, cmd
);
880 static int wpa_cli_cmd_wps_nfc_token(struct wpa_ctrl
*ctrl
, int argc
,
887 printf("Invalid WPS_NFC_TOKEN command: need one argument:\n"
888 "format: WPS or NDEF\n");
892 res
= os_snprintf(cmd
, sizeof(cmd
), "WPS_NFC_TOKEN %s",
895 res
= os_snprintf(cmd
, sizeof(cmd
), "WPS_NFC_TOKEN");
896 if (res
< 0 || (size_t) res
>= sizeof(cmd
) - 1) {
897 printf("Too long WPS_NFC_TOKEN command.\n");
900 return wpa_ctrl_command(ctrl
, cmd
);
904 static int wpa_cli_cmd_wps_nfc_tag_read(struct wpa_ctrl
*ctrl
, int argc
,
912 printf("Invalid 'wps_nfc_tag_read' command - one argument "
917 buflen
= 18 + os_strlen(argv
[0]);
918 buf
= os_malloc(buflen
);
921 os_snprintf(buf
, buflen
, "WPS_NFC_TAG_READ %s", argv
[0]);
923 ret
= wpa_ctrl_command(ctrl
, buf
);
929 #endif /* CONFIG_WPS_NFC */
932 static int wpa_cli_cmd_wps_reg(struct wpa_ctrl
*ctrl
, int argc
, char *argv
[])
938 res
= os_snprintf(cmd
, sizeof(cmd
), "WPS_REG %s %s",
940 else if (argc
== 5 || argc
== 6) {
941 char ssid_hex
[2 * 32 + 1];
942 char key_hex
[2 * 64 + 1];
946 for (i
= 0; i
< 32; i
++) {
947 if (argv
[2][i
] == '\0')
949 os_snprintf(&ssid_hex
[i
* 2], 3, "%02x", argv
[2][i
]);
954 for (i
= 0; i
< 64; i
++) {
955 if (argv
[5][i
] == '\0')
957 os_snprintf(&key_hex
[i
* 2], 3, "%02x",
962 res
= os_snprintf(cmd
, sizeof(cmd
),
963 "WPS_REG %s %s %s %s %s %s",
964 argv
[0], argv
[1], ssid_hex
, argv
[3], argv
[4],
967 printf("Invalid WPS_REG command: need two arguments:\n"
968 "- BSSID of the target AP\n"
970 printf("Alternatively, six arguments can be used to "
971 "reconfigure the AP:\n"
972 "- BSSID of the target AP\n"
975 "- new auth (OPEN, WPAPSK, WPA2PSK)\n"
976 "- new encr (NONE, WEP, TKIP, CCMP)\n"
981 if (res
< 0 || (size_t) res
>= sizeof(cmd
) - 1) {
982 printf("Too long WPS_REG command.\n");
985 return wpa_ctrl_command(ctrl
, cmd
);
989 static int wpa_cli_cmd_wps_ap_pin(struct wpa_ctrl
*ctrl
, int argc
,
996 printf("Invalid WPS_AP_PIN command: needs at least one "
1002 res
= os_snprintf(cmd
, sizeof(cmd
), "WPS_AP_PIN %s %s %s",
1003 argv
[0], argv
[1], argv
[2]);
1005 res
= os_snprintf(cmd
, sizeof(cmd
), "WPS_AP_PIN %s %s",
1008 res
= os_snprintf(cmd
, sizeof(cmd
), "WPS_AP_PIN %s",
1010 if (res
< 0 || (size_t) res
>= sizeof(cmd
) - 1) {
1011 printf("Too long WPS_AP_PIN command.\n");
1014 return wpa_ctrl_command(ctrl
, cmd
);
1018 static int wpa_cli_cmd_wps_er_start(struct wpa_ctrl
*ctrl
, int argc
,
1023 os_snprintf(cmd
, sizeof(cmd
), "WPS_ER_START %s", argv
[0]);
1024 return wpa_ctrl_command(ctrl
, cmd
);
1026 return wpa_ctrl_command(ctrl
, "WPS_ER_START");
1030 static int wpa_cli_cmd_wps_er_stop(struct wpa_ctrl
*ctrl
, int argc
,
1033 return wpa_ctrl_command(ctrl
, "WPS_ER_STOP");
1038 static int wpa_cli_cmd_wps_er_pin(struct wpa_ctrl
*ctrl
, int argc
,
1045 printf("Invalid WPS_ER_PIN command: need at least two "
1047 "- UUID: use 'any' to select any\n"
1048 "- PIN: Enrollee PIN\n"
1049 "optional: - Enrollee MAC address\n");
1054 res
= os_snprintf(cmd
, sizeof(cmd
), "WPS_ER_PIN %s %s %s",
1055 argv
[0], argv
[1], argv
[2]);
1057 res
= os_snprintf(cmd
, sizeof(cmd
), "WPS_ER_PIN %s %s",
1059 if (res
< 0 || (size_t) res
>= sizeof(cmd
) - 1) {
1060 printf("Too long WPS_ER_PIN command.\n");
1063 return wpa_ctrl_command(ctrl
, cmd
);
1067 static int wpa_cli_cmd_wps_er_pbc(struct wpa_ctrl
*ctrl
, int argc
,
1074 printf("Invalid WPS_ER_PBC command: need one argument:\n"
1075 "- UUID: Specify the Enrollee\n");
1079 res
= os_snprintf(cmd
, sizeof(cmd
), "WPS_ER_PBC %s",
1081 if (res
< 0 || (size_t) res
>= sizeof(cmd
) - 1) {
1082 printf("Too long WPS_ER_PBC command.\n");
1085 return wpa_ctrl_command(ctrl
, cmd
);
1089 static int wpa_cli_cmd_wps_er_learn(struct wpa_ctrl
*ctrl
, int argc
,
1096 printf("Invalid WPS_ER_LEARN command: need two arguments:\n"
1097 "- UUID: specify which AP to use\n"
1102 res
= os_snprintf(cmd
, sizeof(cmd
), "WPS_ER_LEARN %s %s",
1104 if (res
< 0 || (size_t) res
>= sizeof(cmd
) - 1) {
1105 printf("Too long WPS_ER_LEARN command.\n");
1108 return wpa_ctrl_command(ctrl
, cmd
);
1112 static int wpa_cli_cmd_wps_er_set_config(struct wpa_ctrl
*ctrl
, int argc
,
1119 printf("Invalid WPS_ER_SET_CONFIG command: need two "
1121 "- UUID: specify which AP to use\n"
1122 "- Network configuration id\n");
1126 res
= os_snprintf(cmd
, sizeof(cmd
), "WPS_ER_SET_CONFIG %s %s",
1128 if (res
< 0 || (size_t) res
>= sizeof(cmd
) - 1) {
1129 printf("Too long WPS_ER_SET_CONFIG command.\n");
1132 return wpa_ctrl_command(ctrl
, cmd
);
1136 static int wpa_cli_cmd_wps_er_config(struct wpa_ctrl
*ctrl
, int argc
,
1142 if (argc
== 5 || argc
== 6) {
1143 char ssid_hex
[2 * 32 + 1];
1144 char key_hex
[2 * 64 + 1];
1148 for (i
= 0; i
< 32; i
++) {
1149 if (argv
[2][i
] == '\0')
1151 os_snprintf(&ssid_hex
[i
* 2], 3, "%02x", argv
[2][i
]);
1156 for (i
= 0; i
< 64; i
++) {
1157 if (argv
[5][i
] == '\0')
1159 os_snprintf(&key_hex
[i
* 2], 3, "%02x",
1164 res
= os_snprintf(cmd
, sizeof(cmd
),
1165 "WPS_ER_CONFIG %s %s %s %s %s %s",
1166 argv
[0], argv
[1], ssid_hex
, argv
[3], argv
[4],
1169 printf("Invalid WPS_ER_CONFIG command: need six arguments:\n"
1173 "- new auth (OPEN, WPAPSK, WPA2PSK)\n"
1174 "- new encr (NONE, WEP, TKIP, CCMP)\n"
1179 if (res
< 0 || (size_t) res
>= sizeof(cmd
) - 1) {
1180 printf("Too long WPS_ER_CONFIG command.\n");
1183 return wpa_ctrl_command(ctrl
, cmd
);
1187 #ifdef CONFIG_WPS_NFC
1188 static int wpa_cli_cmd_wps_er_nfc_config_token(struct wpa_ctrl
*ctrl
, int argc
,
1195 printf("Invalid WPS_ER_NFC_CONFIG_TOKEN command: need two "
1197 "- WPS/NDEF: token format\n"
1198 "- UUID: specify which AP to use\n");
1202 res
= os_snprintf(cmd
, sizeof(cmd
), "WPS_ER_NFC_CONFIG_TOKEN %s %s",
1204 if (res
< 0 || (size_t) res
>= sizeof(cmd
) - 1) {
1205 printf("Too long WPS_ER_NFC_CONFIG_TOKEN command.\n");
1208 return wpa_ctrl_command(ctrl
, cmd
);
1210 #endif /* CONFIG_WPS_NFC */
1213 static int wpa_cli_cmd_ibss_rsn(struct wpa_ctrl
*ctrl
, int argc
, char *argv
[])
1219 printf("Invalid IBSS_RSN command: needs one argument "
1220 "(Peer STA MAC address)\n");
1224 res
= os_snprintf(cmd
, sizeof(cmd
), "IBSS_RSN %s", argv
[0]);
1225 if (res
< 0 || (size_t) res
>= sizeof(cmd
) - 1) {
1226 printf("Too long IBSS_RSN command.\n");
1229 return wpa_ctrl_command(ctrl
, cmd
);
1233 static int wpa_cli_cmd_level(struct wpa_ctrl
*ctrl
, int argc
, char *argv
[])
1239 printf("Invalid LEVEL command: needs one argument (debug "
1243 res
= os_snprintf(cmd
, sizeof(cmd
), "LEVEL %s", argv
[0]);
1244 if (res
< 0 || (size_t) res
>= sizeof(cmd
) - 1) {
1245 printf("Too long LEVEL command.\n");
1248 return wpa_ctrl_command(ctrl
, cmd
);
1252 static int wpa_cli_cmd_identity(struct wpa_ctrl
*ctrl
, int argc
, char *argv
[])
1254 char cmd
[256], *pos
, *end
;
1258 printf("Invalid IDENTITY command: needs two arguments "
1259 "(network id and identity)\n");
1263 end
= cmd
+ sizeof(cmd
);
1265 ret
= os_snprintf(pos
, end
- pos
, WPA_CTRL_RSP
"IDENTITY-%s:%s",
1267 if (ret
< 0 || ret
>= end
- pos
) {
1268 printf("Too long IDENTITY command.\n");
1272 for (i
= 2; i
< argc
; i
++) {
1273 ret
= os_snprintf(pos
, end
- pos
, " %s", argv
[i
]);
1274 if (ret
< 0 || ret
>= end
- pos
) {
1275 printf("Too long IDENTITY command.\n");
1281 return wpa_ctrl_command(ctrl
, cmd
);
1285 static int wpa_cli_cmd_password(struct wpa_ctrl
*ctrl
, int argc
, char *argv
[])
1287 char cmd
[256], *pos
, *end
;
1291 printf("Invalid PASSWORD command: needs two arguments "
1292 "(network id and password)\n");
1296 end
= cmd
+ sizeof(cmd
);
1298 ret
= os_snprintf(pos
, end
- pos
, WPA_CTRL_RSP
"PASSWORD-%s:%s",
1300 if (ret
< 0 || ret
>= end
- pos
) {
1301 printf("Too long PASSWORD command.\n");
1305 for (i
= 2; i
< argc
; i
++) {
1306 ret
= os_snprintf(pos
, end
- pos
, " %s", argv
[i
]);
1307 if (ret
< 0 || ret
>= end
- pos
) {
1308 printf("Too long PASSWORD command.\n");
1314 return wpa_ctrl_command(ctrl
, cmd
);
1318 static int wpa_cli_cmd_new_password(struct wpa_ctrl
*ctrl
, int argc
,
1321 char cmd
[256], *pos
, *end
;
1325 printf("Invalid NEW_PASSWORD command: needs two arguments "
1326 "(network id and password)\n");
1330 end
= cmd
+ sizeof(cmd
);
1332 ret
= os_snprintf(pos
, end
- pos
, WPA_CTRL_RSP
"NEW_PASSWORD-%s:%s",
1334 if (ret
< 0 || ret
>= end
- pos
) {
1335 printf("Too long NEW_PASSWORD command.\n");
1339 for (i
= 2; i
< argc
; i
++) {
1340 ret
= os_snprintf(pos
, end
- pos
, " %s", argv
[i
]);
1341 if (ret
< 0 || ret
>= end
- pos
) {
1342 printf("Too long NEW_PASSWORD command.\n");
1348 return wpa_ctrl_command(ctrl
, cmd
);
1352 static int wpa_cli_cmd_pin(struct wpa_ctrl
*ctrl
, int argc
, char *argv
[])
1354 char cmd
[256], *pos
, *end
;
1358 printf("Invalid PIN command: needs two arguments "
1359 "(network id and pin)\n");
1363 end
= cmd
+ sizeof(cmd
);
1365 ret
= os_snprintf(pos
, end
- pos
, WPA_CTRL_RSP
"PIN-%s:%s",
1367 if (ret
< 0 || ret
>= end
- pos
) {
1368 printf("Too long PIN command.\n");
1372 for (i
= 2; i
< argc
; i
++) {
1373 ret
= os_snprintf(pos
, end
- pos
, " %s", argv
[i
]);
1374 if (ret
< 0 || ret
>= end
- pos
) {
1375 printf("Too long PIN command.\n");
1380 return wpa_ctrl_command(ctrl
, cmd
);
1384 static int wpa_cli_cmd_otp(struct wpa_ctrl
*ctrl
, int argc
, char *argv
[])
1386 char cmd
[256], *pos
, *end
;
1390 printf("Invalid OTP command: needs two arguments (network "
1391 "id and password)\n");
1395 end
= cmd
+ sizeof(cmd
);
1397 ret
= os_snprintf(pos
, end
- pos
, WPA_CTRL_RSP
"OTP-%s:%s",
1399 if (ret
< 0 || ret
>= end
- pos
) {
1400 printf("Too long OTP command.\n");
1404 for (i
= 2; i
< argc
; i
++) {
1405 ret
= os_snprintf(pos
, end
- pos
, " %s", argv
[i
]);
1406 if (ret
< 0 || ret
>= end
- pos
) {
1407 printf("Too long OTP command.\n");
1413 return wpa_ctrl_command(ctrl
, cmd
);
1417 static int wpa_cli_cmd_passphrase(struct wpa_ctrl
*ctrl
, int argc
,
1420 char cmd
[256], *pos
, *end
;
1424 printf("Invalid PASSPHRASE command: needs two arguments "
1425 "(network id and passphrase)\n");
1429 end
= cmd
+ sizeof(cmd
);
1431 ret
= os_snprintf(pos
, end
- pos
, WPA_CTRL_RSP
"PASSPHRASE-%s:%s",
1433 if (ret
< 0 || ret
>= end
- pos
) {
1434 printf("Too long PASSPHRASE command.\n");
1438 for (i
= 2; i
< argc
; i
++) {
1439 ret
= os_snprintf(pos
, end
- pos
, " %s", argv
[i
]);
1440 if (ret
< 0 || ret
>= end
- pos
) {
1441 printf("Too long PASSPHRASE command.\n");
1447 return wpa_ctrl_command(ctrl
, cmd
);
1451 static int wpa_cli_cmd_bssid(struct wpa_ctrl
*ctrl
, int argc
, char *argv
[])
1453 char cmd
[256], *pos
, *end
;
1457 printf("Invalid BSSID command: needs two arguments (network "
1462 end
= cmd
+ sizeof(cmd
);
1464 ret
= os_snprintf(pos
, end
- pos
, "BSSID");
1465 if (ret
< 0 || ret
>= end
- pos
) {
1466 printf("Too long BSSID command.\n");
1470 for (i
= 0; i
< argc
; i
++) {
1471 ret
= os_snprintf(pos
, end
- pos
, " %s", argv
[i
]);
1472 if (ret
< 0 || ret
>= end
- pos
) {
1473 printf("Too long BSSID command.\n");
1479 return wpa_ctrl_command(ctrl
, cmd
);
1483 static int wpa_cli_cmd_blacklist(struct wpa_ctrl
*ctrl
, int argc
, char *argv
[])
1485 char cmd
[256], *pos
, *end
;
1488 end
= cmd
+ sizeof(cmd
);
1490 ret
= os_snprintf(pos
, end
- pos
, "BLACKLIST");
1491 if (ret
< 0 || ret
>= end
- pos
) {
1492 printf("Too long BLACKLIST command.\n");
1496 for (i
= 0; i
< argc
; i
++) {
1497 ret
= os_snprintf(pos
, end
- pos
, " %s", argv
[i
]);
1498 if (ret
< 0 || ret
>= end
- pos
) {
1499 printf("Too long BLACKLIST command.\n");
1505 return wpa_ctrl_command(ctrl
, cmd
);
1509 static int wpa_cli_cmd_log_level(struct wpa_ctrl
*ctrl
, int argc
, char *argv
[])
1511 char cmd
[256], *pos
, *end
;
1514 end
= cmd
+ sizeof(cmd
);
1516 ret
= os_snprintf(pos
, end
- pos
, "LOG_LEVEL");
1517 if (ret
< 0 || ret
>= end
- pos
) {
1518 printf("Too long LOG_LEVEL command.\n");
1522 for (i
= 0; i
< argc
; i
++) {
1523 ret
= os_snprintf(pos
, end
- pos
, " %s", argv
[i
]);
1524 if (ret
< 0 || ret
>= end
- pos
) {
1525 printf("Too long LOG_LEVEL command.\n");
1531 return wpa_ctrl_command(ctrl
, cmd
);
1535 static int wpa_cli_cmd_list_networks(struct wpa_ctrl
*ctrl
, int argc
,
1538 return wpa_ctrl_command(ctrl
, "LIST_NETWORKS");
1542 static int wpa_cli_cmd_select_network(struct wpa_ctrl
*ctrl
, int argc
,
1549 printf("Invalid SELECT_NETWORK command: needs one argument "
1554 res
= os_snprintf(cmd
, sizeof(cmd
), "SELECT_NETWORK %s", argv
[0]);
1555 if (res
< 0 || (size_t) res
>= sizeof(cmd
))
1557 cmd
[sizeof(cmd
) - 1] = '\0';
1559 return wpa_ctrl_command(ctrl
, cmd
);
1563 static int wpa_cli_cmd_enable_network(struct wpa_ctrl
*ctrl
, int argc
,
1570 printf("Invalid ENABLE_NETWORK command: needs one argument "
1576 res
= os_snprintf(cmd
, sizeof(cmd
), "ENABLE_NETWORK %s %s",
1579 res
= os_snprintf(cmd
, sizeof(cmd
), "ENABLE_NETWORK %s",
1581 if (res
< 0 || (size_t) res
>= sizeof(cmd
))
1583 cmd
[sizeof(cmd
) - 1] = '\0';
1585 return wpa_ctrl_command(ctrl
, cmd
);
1589 static int wpa_cli_cmd_disable_network(struct wpa_ctrl
*ctrl
, int argc
,
1596 printf("Invalid DISABLE_NETWORK command: needs one argument "
1601 res
= os_snprintf(cmd
, sizeof(cmd
), "DISABLE_NETWORK %s", argv
[0]);
1602 if (res
< 0 || (size_t) res
>= sizeof(cmd
))
1604 cmd
[sizeof(cmd
) - 1] = '\0';
1606 return wpa_ctrl_command(ctrl
, cmd
);
1610 static int wpa_cli_cmd_add_network(struct wpa_ctrl
*ctrl
, int argc
,
1613 return wpa_ctrl_command(ctrl
, "ADD_NETWORK");
1617 static int wpa_cli_cmd_remove_network(struct wpa_ctrl
*ctrl
, int argc
,
1624 printf("Invalid REMOVE_NETWORK command: needs one argument "
1629 res
= os_snprintf(cmd
, sizeof(cmd
), "REMOVE_NETWORK %s", argv
[0]);
1630 if (res
< 0 || (size_t) res
>= sizeof(cmd
))
1632 cmd
[sizeof(cmd
) - 1] = '\0';
1634 return wpa_ctrl_command(ctrl
, cmd
);
1638 static void wpa_cli_show_network_variables(void)
1640 printf("set_network variables:\n"
1641 " ssid (network name, SSID)\n"
1642 " psk (WPA passphrase or pre-shared key)\n"
1643 " key_mgmt (key management protocol)\n"
1644 " identity (EAP identity)\n"
1645 " password (EAP password)\n"
1648 "Note: Values are entered in the same format as the "
1649 "configuration file is using,\n"
1650 "i.e., strings values need to be inside double quotation "
1652 "For example: set_network 1 ssid \"network name\"\n"
1654 "Please see wpa_supplicant.conf documentation for full list "
1655 "of\navailable variables.\n");
1659 static int wpa_cli_cmd_set_network(struct wpa_ctrl
*ctrl
, int argc
,
1666 wpa_cli_show_network_variables();
1671 printf("Invalid SET_NETWORK command: needs three arguments\n"
1672 "(network id, variable name, and value)\n");
1676 res
= os_snprintf(cmd
, sizeof(cmd
), "SET_NETWORK %s %s %s",
1677 argv
[0], argv
[1], argv
[2]);
1678 if (res
< 0 || (size_t) res
>= sizeof(cmd
) - 1) {
1679 printf("Too long SET_NETWORK command.\n");
1682 return wpa_ctrl_command(ctrl
, cmd
);
1686 static int wpa_cli_cmd_get_network(struct wpa_ctrl
*ctrl
, int argc
,
1693 wpa_cli_show_network_variables();
1698 printf("Invalid GET_NETWORK command: needs two arguments\n"
1699 "(network id and variable name)\n");
1703 res
= os_snprintf(cmd
, sizeof(cmd
), "GET_NETWORK %s %s",
1705 if (res
< 0 || (size_t) res
>= sizeof(cmd
) - 1) {
1706 printf("Too long GET_NETWORK command.\n");
1709 return wpa_ctrl_command(ctrl
, cmd
);
1713 static int wpa_cli_cmd_list_creds(struct wpa_ctrl
*ctrl
, int argc
,
1716 return wpa_ctrl_command(ctrl
, "LIST_CREDS");
1720 static int wpa_cli_cmd_add_cred(struct wpa_ctrl
*ctrl
, int argc
, char *argv
[])
1722 return wpa_ctrl_command(ctrl
, "ADD_CRED");
1726 static int wpa_cli_cmd_remove_cred(struct wpa_ctrl
*ctrl
, int argc
,
1733 printf("Invalid REMOVE_CRED command: needs one argument "
1738 res
= os_snprintf(cmd
, sizeof(cmd
), "REMOVE_CRED %s", argv
[0]);
1739 if (res
< 0 || (size_t) res
>= sizeof(cmd
))
1741 cmd
[sizeof(cmd
) - 1] = '\0';
1743 return wpa_ctrl_command(ctrl
, cmd
);
1747 static int wpa_cli_cmd_set_cred(struct wpa_ctrl
*ctrl
, int argc
, char *argv
[])
1753 printf("Invalid SET_CRED command: needs three arguments\n"
1754 "(cred id, variable name, and value)\n");
1758 res
= os_snprintf(cmd
, sizeof(cmd
), "SET_CRED %s %s %s",
1759 argv
[0], argv
[1], argv
[2]);
1760 if (res
< 0 || (size_t) res
>= sizeof(cmd
) - 1) {
1761 printf("Too long SET_CRED command.\n");
1764 return wpa_ctrl_command(ctrl
, cmd
);
1768 static int wpa_cli_cmd_disconnect(struct wpa_ctrl
*ctrl
, int argc
,
1771 return wpa_ctrl_command(ctrl
, "DISCONNECT");
1775 static int wpa_cli_cmd_reconnect(struct wpa_ctrl
*ctrl
, int argc
,
1778 return wpa_ctrl_command(ctrl
, "RECONNECT");
1782 static int wpa_cli_cmd_save_config(struct wpa_ctrl
*ctrl
, int argc
,
1785 return wpa_ctrl_command(ctrl
, "SAVE_CONFIG");
1789 static int wpa_cli_cmd_scan(struct wpa_ctrl
*ctrl
, int argc
, char *argv
[])
1791 return wpa_ctrl_command(ctrl
, "SCAN");
1795 static int wpa_cli_cmd_scan_results(struct wpa_ctrl
*ctrl
, int argc
,
1798 return wpa_ctrl_command(ctrl
, "SCAN_RESULTS");
1802 static int wpa_cli_cmd_bss(struct wpa_ctrl
*ctrl
, int argc
, char *argv
[])
1808 printf("Invalid BSS command: need at least one argument"
1809 "(index or BSSID)\n");
1813 res
= os_snprintf(cmd
, sizeof(cmd
), "BSS %s%s%s%s%s", argv
[0],
1814 argc
> 1 ? " " : "", argc
> 1 ? argv
[1] : "",
1815 argc
> 2 ? " " : "", argc
> 2 ? argv
[2] : "");
1817 if (res
< 0 || (size_t) res
>= sizeof(cmd
))
1819 cmd
[sizeof(cmd
) - 1] = '\0';
1821 return wpa_ctrl_command(ctrl
, cmd
);
1825 static char ** wpa_cli_complete_bss(const char *str
, int pos
)
1827 int arg
= get_cmd_arg_num(str
, pos
);
1832 res
= cli_txt_list_array(&bsses
);
1840 static int wpa_cli_cmd_get_capability(struct wpa_ctrl
*ctrl
, int argc
,
1846 if (argc
< 1 || argc
> 2) {
1847 printf("Invalid GET_CAPABILITY command: need either one or "
1852 if ((argc
== 2) && os_strcmp(argv
[1], "strict") != 0) {
1853 printf("Invalid GET_CAPABILITY command: second argument, "
1854 "if any, must be 'strict'\n");
1858 res
= os_snprintf(cmd
, sizeof(cmd
), "GET_CAPABILITY %s%s", argv
[0],
1859 (argc
== 2) ? " strict" : "");
1860 if (res
< 0 || (size_t) res
>= sizeof(cmd
))
1862 cmd
[sizeof(cmd
) - 1] = '\0';
1864 return wpa_ctrl_command(ctrl
, cmd
);
1868 static int wpa_cli_list_interfaces(struct wpa_ctrl
*ctrl
)
1870 printf("Available interfaces:\n");
1871 return wpa_ctrl_command(ctrl
, "INTERFACES");
1875 static int wpa_cli_cmd_interface(struct wpa_ctrl
*ctrl
, int argc
, char *argv
[])
1878 wpa_cli_list_interfaces(ctrl
);
1882 wpa_cli_close_connection();
1883 os_free(ctrl_ifname
);
1884 ctrl_ifname
= os_strdup(argv
[0]);
1886 if (wpa_cli_open_connection(ctrl_ifname
, 1)) {
1887 printf("Connected to interface '%s.\n", ctrl_ifname
);
1889 printf("Could not connect to interface '%s' - re-trying\n",
1896 static int wpa_cli_cmd_reconfigure(struct wpa_ctrl
*ctrl
, int argc
,
1899 return wpa_ctrl_command(ctrl
, "RECONFIGURE");
1903 static int wpa_cli_cmd_terminate(struct wpa_ctrl
*ctrl
, int argc
,
1906 return wpa_ctrl_command(ctrl
, "TERMINATE");
1910 static int wpa_cli_cmd_interface_add(struct wpa_ctrl
*ctrl
, int argc
,
1917 printf("Invalid INTERFACE_ADD command: needs at least one "
1918 "argument (interface name)\n"
1919 "All arguments: ifname confname driver ctrl_interface "
1920 "driver_param bridge_name\n");
1925 * INTERFACE_ADD <ifname>TAB<confname>TAB<driver>TAB<ctrl_interface>TAB
1926 * <driver_param>TAB<bridge_name>
1928 res
= os_snprintf(cmd
, sizeof(cmd
),
1929 "INTERFACE_ADD %s\t%s\t%s\t%s\t%s\t%s",
1931 argc
> 1 ? argv
[1] : "", argc
> 2 ? argv
[2] : "",
1932 argc
> 3 ? argv
[3] : "", argc
> 4 ? argv
[4] : "",
1933 argc
> 5 ? argv
[5] : "");
1934 if (res
< 0 || (size_t) res
>= sizeof(cmd
))
1936 cmd
[sizeof(cmd
) - 1] = '\0';
1937 return wpa_ctrl_command(ctrl
, cmd
);
1941 static int wpa_cli_cmd_interface_remove(struct wpa_ctrl
*ctrl
, int argc
,
1948 printf("Invalid INTERFACE_REMOVE command: needs one argument "
1949 "(interface name)\n");
1953 res
= os_snprintf(cmd
, sizeof(cmd
), "INTERFACE_REMOVE %s", argv
[0]);
1954 if (res
< 0 || (size_t) res
>= sizeof(cmd
))
1956 cmd
[sizeof(cmd
) - 1] = '\0';
1957 return wpa_ctrl_command(ctrl
, cmd
);
1961 static int wpa_cli_cmd_interface_list(struct wpa_ctrl
*ctrl
, int argc
,
1964 return wpa_ctrl_command(ctrl
, "INTERFACE_LIST");
1969 static int wpa_cli_cmd_sta(struct wpa_ctrl
*ctrl
, int argc
, char *argv
[])
1973 printf("Invalid 'sta' command - exactly one argument, STA "
1974 "address, is required.\n");
1977 os_snprintf(buf
, sizeof(buf
), "STA %s", argv
[0]);
1978 return wpa_ctrl_command(ctrl
, buf
);
1982 static int wpa_ctrl_command_sta(struct wpa_ctrl
*ctrl
, char *cmd
,
1983 char *addr
, size_t addr_len
)
1985 char buf
[4096], *pos
;
1989 if (ctrl_conn
== NULL
) {
1990 printf("Not connected to hostapd - command dropped.\n");
1993 len
= sizeof(buf
) - 1;
1994 ret
= wpa_ctrl_request(ctrl
, cmd
, os_strlen(cmd
), buf
, &len
,
1997 printf("'%s' command timed out.\n", cmd
);
1999 } else if (ret
< 0) {
2000 printf("'%s' command failed.\n", cmd
);
2005 if (os_memcmp(buf
, "FAIL", 4) == 0)
2010 while (*pos
!= '\0' && *pos
!= '\n')
2013 os_strlcpy(addr
, buf
, addr_len
);
2018 static int wpa_cli_cmd_all_sta(struct wpa_ctrl
*ctrl
, int argc
, char *argv
[])
2020 char addr
[32], cmd
[64];
2022 if (wpa_ctrl_command_sta(ctrl
, "STA-FIRST", addr
, sizeof(addr
)))
2025 os_snprintf(cmd
, sizeof(cmd
), "STA-NEXT %s", addr
);
2026 } while (wpa_ctrl_command_sta(ctrl
, cmd
, addr
, sizeof(addr
)) == 0);
2032 static int wpa_cli_cmd_deauthenticate(struct wpa_ctrl
*ctrl
, int argc
,
2037 printf("Invalid 'deauthenticate' command - exactly one "
2038 "argument, STA address, is required.\n");
2042 os_snprintf(buf
, sizeof(buf
), "DEAUTHENTICATE %s %s",
2045 os_snprintf(buf
, sizeof(buf
), "DEAUTHENTICATE %s", argv
[0]);
2046 return wpa_ctrl_command(ctrl
, buf
);
2050 static int wpa_cli_cmd_disassociate(struct wpa_ctrl
*ctrl
, int argc
,
2055 printf("Invalid 'disassociate' command - exactly one "
2056 "argument, STA address, is required.\n");
2060 os_snprintf(buf
, sizeof(buf
), "DISASSOCIATE %s %s",
2063 os_snprintf(buf
, sizeof(buf
), "DISASSOCIATE %s", argv
[0]);
2064 return wpa_ctrl_command(ctrl
, buf
);
2066 #endif /* CONFIG_AP */
2069 static int wpa_cli_cmd_suspend(struct wpa_ctrl
*ctrl
, int argc
, char *argv
[])
2071 return wpa_ctrl_command(ctrl
, "SUSPEND");
2075 static int wpa_cli_cmd_resume(struct wpa_ctrl
*ctrl
, int argc
, char *argv
[])
2077 return wpa_ctrl_command(ctrl
, "RESUME");
2081 static int wpa_cli_cmd_drop_sa(struct wpa_ctrl
*ctrl
, int argc
, char *argv
[])
2083 return wpa_ctrl_command(ctrl
, "DROP_SA");
2087 static int wpa_cli_cmd_roam(struct wpa_ctrl
*ctrl
, int argc
, char *argv
[])
2093 printf("Invalid ROAM command: needs one argument "
2094 "(target AP's BSSID)\n");
2098 res
= os_snprintf(cmd
, sizeof(cmd
), "ROAM %s", argv
[0]);
2099 if (res
< 0 || (size_t) res
>= sizeof(cmd
) - 1) {
2100 printf("Too long ROAM command.\n");
2103 return wpa_ctrl_command(ctrl
, cmd
);
2109 static int wpa_cli_cmd_p2p_find(struct wpa_ctrl
*ctrl
, int argc
, char *argv
[])
2115 return wpa_ctrl_command(ctrl
, "P2P_FIND");
2118 res
= os_snprintf(cmd
, sizeof(cmd
), "P2P_FIND %s %s %s",
2119 argv
[0], argv
[1], argv
[2]);
2121 res
= os_snprintf(cmd
, sizeof(cmd
), "P2P_FIND %s %s",
2124 res
= os_snprintf(cmd
, sizeof(cmd
), "P2P_FIND %s", argv
[0]);
2125 if (res
< 0 || (size_t) res
>= sizeof(cmd
))
2127 cmd
[sizeof(cmd
) - 1] = '\0';
2128 return wpa_ctrl_command(ctrl
, cmd
);
2132 static int wpa_cli_cmd_p2p_stop_find(struct wpa_ctrl
*ctrl
, int argc
,
2135 return wpa_ctrl_command(ctrl
, "P2P_STOP_FIND");
2139 static int wpa_cli_cmd_p2p_connect(struct wpa_ctrl
*ctrl
, int argc
,
2146 printf("Invalid P2P_CONNECT command: needs at least two "
2147 "arguments (address and pbc/PIN)\n");
2152 res
= os_snprintf(cmd
, sizeof(cmd
),
2153 "P2P_CONNECT %s %s %s %s %s",
2154 argv
[0], argv
[1], argv
[2], argv
[3],
2157 res
= os_snprintf(cmd
, sizeof(cmd
), "P2P_CONNECT %s %s %s %s",
2158 argv
[0], argv
[1], argv
[2], argv
[3]);
2160 res
= os_snprintf(cmd
, sizeof(cmd
), "P2P_CONNECT %s %s %s",
2161 argv
[0], argv
[1], argv
[2]);
2163 res
= os_snprintf(cmd
, sizeof(cmd
), "P2P_CONNECT %s %s",
2165 if (res
< 0 || (size_t) res
>= sizeof(cmd
))
2167 cmd
[sizeof(cmd
) - 1] = '\0';
2168 return wpa_ctrl_command(ctrl
, cmd
);
2172 static char ** wpa_cli_complete_p2p_connect(const char *str
, int pos
)
2174 int arg
= get_cmd_arg_num(str
, pos
);
2179 res
= cli_txt_list_array(&p2p_peers
);
2187 static int wpa_cli_cmd_p2p_listen(struct wpa_ctrl
*ctrl
, int argc
,
2194 return wpa_ctrl_command(ctrl
, "P2P_LISTEN");
2196 res
= os_snprintf(cmd
, sizeof(cmd
), "P2P_LISTEN %s", argv
[0]);
2197 if (res
< 0 || (size_t) res
>= sizeof(cmd
))
2199 cmd
[sizeof(cmd
) - 1] = '\0';
2200 return wpa_ctrl_command(ctrl
, cmd
);
2204 static int wpa_cli_cmd_p2p_group_remove(struct wpa_ctrl
*ctrl
, int argc
,
2211 printf("Invalid P2P_GROUP_REMOVE command: needs one argument "
2212 "(interface name)\n");
2216 res
= os_snprintf(cmd
, sizeof(cmd
), "P2P_GROUP_REMOVE %s", argv
[0]);
2217 if (res
< 0 || (size_t) res
>= sizeof(cmd
))
2219 cmd
[sizeof(cmd
) - 1] = '\0';
2220 return wpa_ctrl_command(ctrl
, cmd
);
2224 static char ** wpa_cli_complete_p2p_group_remove(const char *str
, int pos
)
2226 int arg
= get_cmd_arg_num(str
, pos
);
2231 res
= cli_txt_list_array(&p2p_groups
);
2239 static int wpa_cli_cmd_p2p_group_add(struct wpa_ctrl
*ctrl
, int argc
,
2246 return wpa_ctrl_command(ctrl
, "P2P_GROUP_ADD");
2249 res
= os_snprintf(cmd
, sizeof(cmd
), "P2P_GROUP_ADD %s %s",
2252 res
= os_snprintf(cmd
, sizeof(cmd
), "P2P_GROUP_ADD %s",
2254 if (res
< 0 || (size_t) res
>= sizeof(cmd
))
2256 cmd
[sizeof(cmd
) - 1] = '\0';
2257 return wpa_ctrl_command(ctrl
, cmd
);
2261 static int wpa_cli_cmd_p2p_prov_disc(struct wpa_ctrl
*ctrl
, int argc
,
2267 if (argc
!= 2 && argc
!= 3) {
2268 printf("Invalid P2P_PROV_DISC command: needs at least "
2269 "two arguments, address and config method\n"
2270 "(display, keypad, or pbc) and an optional join\n");
2275 res
= os_snprintf(cmd
, sizeof(cmd
), "P2P_PROV_DISC %s %s %s",
2276 argv
[0], argv
[1], argv
[2]);
2278 res
= os_snprintf(cmd
, sizeof(cmd
), "P2P_PROV_DISC %s %s",
2280 if (res
< 0 || (size_t) res
>= sizeof(cmd
))
2282 cmd
[sizeof(cmd
) - 1] = '\0';
2283 return wpa_ctrl_command(ctrl
, cmd
);
2287 static int wpa_cli_cmd_p2p_get_passphrase(struct wpa_ctrl
*ctrl
, int argc
,
2290 return wpa_ctrl_command(ctrl
, "P2P_GET_PASSPHRASE");
2294 static int wpa_cli_cmd_p2p_serv_disc_req(struct wpa_ctrl
*ctrl
, int argc
,
2300 if (argc
!= 2 && argc
!= 4) {
2301 printf("Invalid P2P_SERV_DISC_REQ command: needs two "
2302 "arguments (address and TLVs) or four arguments "
2303 "(address, \"upnp\", version, search target "
2309 res
= os_snprintf(cmd
, sizeof(cmd
),
2310 "P2P_SERV_DISC_REQ %s %s %s %s",
2311 argv
[0], argv
[1], argv
[2], argv
[3]);
2313 res
= os_snprintf(cmd
, sizeof(cmd
), "P2P_SERV_DISC_REQ %s %s",
2315 if (res
< 0 || (size_t) res
>= sizeof(cmd
))
2317 cmd
[sizeof(cmd
) - 1] = '\0';
2318 return wpa_ctrl_command(ctrl
, cmd
);
2322 static int wpa_cli_cmd_p2p_serv_disc_cancel_req(struct wpa_ctrl
*ctrl
,
2323 int argc
, char *argv
[])
2329 printf("Invalid P2P_SERV_DISC_CANCEL_REQ command: needs one "
2330 "argument (pending request identifier)\n");
2334 res
= os_snprintf(cmd
, sizeof(cmd
), "P2P_SERV_DISC_CANCEL_REQ %s",
2336 if (res
< 0 || (size_t) res
>= sizeof(cmd
))
2338 cmd
[sizeof(cmd
) - 1] = '\0';
2339 return wpa_ctrl_command(ctrl
, cmd
);
2343 static int wpa_cli_cmd_p2p_serv_disc_resp(struct wpa_ctrl
*ctrl
, int argc
,
2350 printf("Invalid P2P_SERV_DISC_RESP command: needs four "
2351 "arguments (freq, address, dialog token, and TLVs)\n");
2355 res
= os_snprintf(cmd
, sizeof(cmd
), "P2P_SERV_DISC_RESP %s %s %s %s",
2356 argv
[0], argv
[1], argv
[2], argv
[3]);
2357 if (res
< 0 || (size_t) res
>= sizeof(cmd
))
2359 cmd
[sizeof(cmd
) - 1] = '\0';
2360 return wpa_ctrl_command(ctrl
, cmd
);
2364 static int wpa_cli_cmd_p2p_service_update(struct wpa_ctrl
*ctrl
, int argc
,
2367 return wpa_ctrl_command(ctrl
, "P2P_SERVICE_UPDATE");
2371 static int wpa_cli_cmd_p2p_serv_disc_external(struct wpa_ctrl
*ctrl
,
2372 int argc
, char *argv
[])
2378 printf("Invalid P2P_SERV_DISC_EXTERNAL command: needs one "
2379 "argument (external processing: 0/1)\n");
2383 res
= os_snprintf(cmd
, sizeof(cmd
), "P2P_SERV_DISC_EXTERNAL %s",
2385 if (res
< 0 || (size_t) res
>= sizeof(cmd
))
2387 cmd
[sizeof(cmd
) - 1] = '\0';
2388 return wpa_ctrl_command(ctrl
, cmd
);
2392 static int wpa_cli_cmd_p2p_service_flush(struct wpa_ctrl
*ctrl
, int argc
,
2395 return wpa_ctrl_command(ctrl
, "P2P_SERVICE_FLUSH");
2399 static int wpa_cli_cmd_p2p_service_add(struct wpa_ctrl
*ctrl
, int argc
,
2405 if (argc
!= 3 && argc
!= 4) {
2406 printf("Invalid P2P_SERVICE_ADD command: needs three or four "
2412 res
= os_snprintf(cmd
, sizeof(cmd
),
2413 "P2P_SERVICE_ADD %s %s %s %s",
2414 argv
[0], argv
[1], argv
[2], argv
[3]);
2416 res
= os_snprintf(cmd
, sizeof(cmd
),
2417 "P2P_SERVICE_ADD %s %s %s",
2418 argv
[0], argv
[1], argv
[2]);
2419 if (res
< 0 || (size_t) res
>= sizeof(cmd
))
2421 cmd
[sizeof(cmd
) - 1] = '\0';
2422 return wpa_ctrl_command(ctrl
, cmd
);
2426 static int wpa_cli_cmd_p2p_service_del(struct wpa_ctrl
*ctrl
, int argc
,
2432 if (argc
!= 2 && argc
!= 3) {
2433 printf("Invalid P2P_SERVICE_DEL command: needs two or three "
2439 res
= os_snprintf(cmd
, sizeof(cmd
),
2440 "P2P_SERVICE_DEL %s %s %s",
2441 argv
[0], argv
[1], argv
[2]);
2443 res
= os_snprintf(cmd
, sizeof(cmd
),
2444 "P2P_SERVICE_DEL %s %s",
2446 if (res
< 0 || (size_t) res
>= sizeof(cmd
))
2448 cmd
[sizeof(cmd
) - 1] = '\0';
2449 return wpa_ctrl_command(ctrl
, cmd
);
2453 static int wpa_cli_cmd_p2p_reject(struct wpa_ctrl
*ctrl
,
2454 int argc
, char *argv
[])
2460 printf("Invalid P2P_REJECT command: needs one argument "
2461 "(peer address)\n");
2465 res
= os_snprintf(cmd
, sizeof(cmd
), "P2P_REJECT %s", argv
[0]);
2466 if (res
< 0 || (size_t) res
>= sizeof(cmd
))
2468 cmd
[sizeof(cmd
) - 1] = '\0';
2469 return wpa_ctrl_command(ctrl
, cmd
);
2473 static int wpa_cli_cmd_p2p_invite(struct wpa_ctrl
*ctrl
,
2474 int argc
, char *argv
[])
2480 printf("Invalid P2P_INVITE command: needs at least one "
2486 res
= os_snprintf(cmd
, sizeof(cmd
), "P2P_INVITE %s %s %s",
2487 argv
[0], argv
[1], argv
[2]);
2489 res
= os_snprintf(cmd
, sizeof(cmd
), "P2P_INVITE %s %s",
2492 res
= os_snprintf(cmd
, sizeof(cmd
), "P2P_INVITE %s", argv
[0]);
2493 if (res
< 0 || (size_t) res
>= sizeof(cmd
))
2495 cmd
[sizeof(cmd
) - 1] = '\0';
2496 return wpa_ctrl_command(ctrl
, cmd
);
2500 static int wpa_cli_cmd_p2p_peer(struct wpa_ctrl
*ctrl
, int argc
, char *argv
[])
2504 printf("Invalid 'p2p_peer' command - exactly one argument, "
2505 "P2P peer device address, is required.\n");
2508 os_snprintf(buf
, sizeof(buf
), "P2P_PEER %s", argv
[0]);
2509 return wpa_ctrl_command(ctrl
, buf
);
2513 static char ** wpa_cli_complete_p2p_peer(const char *str
, int pos
)
2515 int arg
= get_cmd_arg_num(str
, pos
);
2520 res
= cli_txt_list_array(&p2p_peers
);
2528 static int wpa_ctrl_command_p2p_peer(struct wpa_ctrl
*ctrl
, char *cmd
,
2529 char *addr
, size_t addr_len
,
2532 char buf
[4096], *pos
;
2536 if (ctrl_conn
== NULL
)
2538 len
= sizeof(buf
) - 1;
2539 ret
= wpa_ctrl_request(ctrl
, cmd
, os_strlen(cmd
), buf
, &len
,
2542 printf("'%s' command timed out.\n", cmd
);
2544 } else if (ret
< 0) {
2545 printf("'%s' command failed.\n", cmd
);
2550 if (os_memcmp(buf
, "FAIL", 4) == 0)
2554 while (*pos
!= '\0' && *pos
!= '\n')
2557 os_strlcpy(addr
, buf
, addr_len
);
2558 if (!discovered
|| os_strstr(pos
, "[PROBE_REQ_ONLY]") == NULL
)
2559 printf("%s\n", addr
);
2564 static int wpa_cli_cmd_p2p_peers(struct wpa_ctrl
*ctrl
, int argc
, char *argv
[])
2566 char addr
[32], cmd
[64];
2569 discovered
= argc
> 0 && os_strcmp(argv
[0], "discovered") == 0;
2571 if (wpa_ctrl_command_p2p_peer(ctrl
, "P2P_PEER FIRST",
2572 addr
, sizeof(addr
), discovered
))
2575 os_snprintf(cmd
, sizeof(cmd
), "P2P_PEER NEXT-%s", addr
);
2576 } while (wpa_ctrl_command_p2p_peer(ctrl
, cmd
, addr
, sizeof(addr
),
2583 static int wpa_cli_cmd_p2p_set(struct wpa_ctrl
*ctrl
, int argc
, char *argv
[])
2589 printf("Invalid P2P_SET command: needs two arguments (field, "
2594 res
= os_snprintf(cmd
, sizeof(cmd
), "P2P_SET %s %s", argv
[0], argv
[1]);
2595 if (res
< 0 || (size_t) res
>= sizeof(cmd
))
2597 cmd
[sizeof(cmd
) - 1] = '\0';
2598 return wpa_ctrl_command(ctrl
, cmd
);
2602 static int wpa_cli_cmd_p2p_flush(struct wpa_ctrl
*ctrl
, int argc
, char *argv
[])
2604 return wpa_ctrl_command(ctrl
, "P2P_FLUSH");
2608 static int wpa_cli_cmd_p2p_cancel(struct wpa_ctrl
*ctrl
, int argc
,
2611 return wpa_ctrl_command(ctrl
, "P2P_CANCEL");
2615 static int wpa_cli_cmd_p2p_unauthorize(struct wpa_ctrl
*ctrl
, int argc
,
2622 printf("Invalid P2P_UNAUTHORIZE command: needs one argument "
2623 "(peer address)\n");
2627 res
= os_snprintf(cmd
, sizeof(cmd
), "P2P_UNAUTHORIZE %s", argv
[0]);
2629 if (res
< 0 || (size_t) res
>= sizeof(cmd
))
2632 cmd
[sizeof(cmd
) - 1] = '\0';
2633 return wpa_ctrl_command(ctrl
, cmd
);
2637 static int wpa_cli_cmd_p2p_presence_req(struct wpa_ctrl
*ctrl
, int argc
,
2643 if (argc
!= 0 && argc
!= 2 && argc
!= 4) {
2644 printf("Invalid P2P_PRESENCE_REQ command: needs two arguments "
2645 "(preferred duration, interval; in microsecods).\n"
2646 "Optional second pair can be used to provide "
2647 "acceptable values.\n");
2652 res
= os_snprintf(cmd
, sizeof(cmd
),
2653 "P2P_PRESENCE_REQ %s %s %s %s",
2654 argv
[0], argv
[1], argv
[2], argv
[3]);
2656 res
= os_snprintf(cmd
, sizeof(cmd
), "P2P_PRESENCE_REQ %s %s",
2659 res
= os_snprintf(cmd
, sizeof(cmd
), "P2P_PRESENCE_REQ");
2660 if (res
< 0 || (size_t) res
>= sizeof(cmd
))
2662 cmd
[sizeof(cmd
) - 1] = '\0';
2663 return wpa_ctrl_command(ctrl
, cmd
);
2667 static int wpa_cli_cmd_p2p_ext_listen(struct wpa_ctrl
*ctrl
, int argc
,
2673 if (argc
!= 0 && argc
!= 2) {
2674 printf("Invalid P2P_EXT_LISTEN command: needs two arguments "
2675 "(availability period, availability interval; in "
2677 "Extended Listen Timing can be cancelled with this "
2678 "command when used without parameters.\n");
2683 res
= os_snprintf(cmd
, sizeof(cmd
), "P2P_EXT_LISTEN %s %s",
2686 res
= os_snprintf(cmd
, sizeof(cmd
), "P2P_EXT_LISTEN");
2687 if (res
< 0 || (size_t) res
>= sizeof(cmd
))
2689 cmd
[sizeof(cmd
) - 1] = '\0';
2690 return wpa_ctrl_command(ctrl
, cmd
);
2693 #endif /* CONFIG_P2P */
2696 #ifdef CONFIG_INTERWORKING
2697 static int wpa_cli_cmd_fetch_anqp(struct wpa_ctrl
*ctrl
, int argc
,
2700 return wpa_ctrl_command(ctrl
, "FETCH_ANQP");
2704 static int wpa_cli_cmd_stop_fetch_anqp(struct wpa_ctrl
*ctrl
, int argc
,
2707 return wpa_ctrl_command(ctrl
, "STOP_FETCH_ANQP");
2711 static int wpa_cli_cmd_interworking_select(struct wpa_ctrl
*ctrl
, int argc
,
2718 return wpa_ctrl_command(ctrl
, "INTERWORKING_SELECT");
2720 res
= os_snprintf(cmd
, sizeof(cmd
), "INTERWORKING_SELECT %s", argv
[0]);
2721 if (res
< 0 || (size_t) res
>= sizeof(cmd
))
2723 cmd
[sizeof(cmd
) - 1] = '\0';
2724 return wpa_ctrl_command(ctrl
, cmd
);
2728 static int wpa_cli_cmd_interworking_connect(struct wpa_ctrl
*ctrl
, int argc
,
2735 printf("Invalid INTERWORKING_CONNECT commands: needs one "
2736 "argument (BSSID)\n");
2740 res
= os_snprintf(cmd
, sizeof(cmd
), "INTERWORKING_CONNECT %s",
2742 if (res
< 0 || (size_t) res
>= sizeof(cmd
))
2744 cmd
[sizeof(cmd
) - 1] = '\0';
2745 return wpa_ctrl_command(ctrl
, cmd
);
2749 static int wpa_cli_cmd_anqp_get(struct wpa_ctrl
*ctrl
, int argc
, char *argv
[])
2755 printf("Invalid ANQP_GET command: needs two arguments "
2756 "(addr and info id list)\n");
2760 res
= os_snprintf(cmd
, sizeof(cmd
), "ANQP_GET %s %s",
2762 if (res
< 0 || (size_t) res
>= sizeof(cmd
))
2764 cmd
[sizeof(cmd
) - 1] = '\0';
2765 return wpa_ctrl_command(ctrl
, cmd
);
2767 #endif /* CONFIG_INTERWORKING */
2772 static int wpa_cli_cmd_hs20_anqp_get(struct wpa_ctrl
*ctrl
, int argc
,
2779 printf("Invalid HS20_ANQP_GET command: needs two arguments "
2780 "(addr and subtype list)\n");
2784 res
= os_snprintf(cmd
, sizeof(cmd
), "HS20_ANQP_GET %s %s",
2786 if (res
< 0 || (size_t) res
>= sizeof(cmd
))
2788 cmd
[sizeof(cmd
) - 1] = '\0';
2789 return wpa_ctrl_command(ctrl
, cmd
);
2793 static int wpa_cli_cmd_get_nai_home_realm_list(struct wpa_ctrl
*ctrl
, int argc
,
2800 printf("Command needs one or two arguments (dst mac addr and "
2801 "optional home realm)\n");
2806 res
= os_snprintf(cmd
, sizeof(cmd
),
2807 "HS20_GET_NAI_HOME_REALM_LIST %s",
2810 res
= os_snprintf(cmd
, sizeof(cmd
),
2811 "HS20_GET_NAI_HOME_REALM_LIST %s %s",
2813 if (res
< 0 || (size_t) res
>= sizeof(cmd
) - 1) {
2814 printf("Too long command.\n");
2818 return wpa_ctrl_command(ctrl
, cmd
);
2821 #endif /* CONFIG_HS20 */
2824 static int wpa_cli_cmd_sta_autoconnect(struct wpa_ctrl
*ctrl
, int argc
,
2831 printf("Invalid STA_AUTOCONNECT command: needs one argument "
2832 "(0/1 = disable/enable automatic reconnection)\n");
2835 res
= os_snprintf(cmd
, sizeof(cmd
), "STA_AUTOCONNECT %s", argv
[0]);
2836 if (res
< 0 || (size_t) res
>= sizeof(cmd
) - 1) {
2837 printf("Too long STA_AUTOCONNECT command.\n");
2840 return wpa_ctrl_command(ctrl
, cmd
);
2844 static int wpa_cli_cmd_tdls_discover(struct wpa_ctrl
*ctrl
, int argc
,
2851 printf("Invalid TDLS_DISCOVER command: needs one argument "
2852 "(Peer STA MAC address)\n");
2856 res
= os_snprintf(cmd
, sizeof(cmd
), "TDLS_DISCOVER %s", argv
[0]);
2857 if (res
< 0 || (size_t) res
>= sizeof(cmd
) - 1) {
2858 printf("Too long TDLS_DISCOVER command.\n");
2861 return wpa_ctrl_command(ctrl
, cmd
);
2865 static int wpa_cli_cmd_tdls_setup(struct wpa_ctrl
*ctrl
, int argc
,
2872 printf("Invalid TDLS_SETUP command: needs one argument "
2873 "(Peer STA MAC address)\n");
2877 res
= os_snprintf(cmd
, sizeof(cmd
), "TDLS_SETUP %s", argv
[0]);
2878 if (res
< 0 || (size_t) res
>= sizeof(cmd
) - 1) {
2879 printf("Too long TDLS_SETUP command.\n");
2882 return wpa_ctrl_command(ctrl
, cmd
);
2886 static int wpa_cli_cmd_tdls_teardown(struct wpa_ctrl
*ctrl
, int argc
,
2893 printf("Invalid TDLS_TEARDOWN command: needs one argument "
2894 "(Peer STA MAC address)\n");
2898 res
= os_snprintf(cmd
, sizeof(cmd
), "TDLS_TEARDOWN %s", argv
[0]);
2899 if (res
< 0 || (size_t) res
>= sizeof(cmd
) - 1) {
2900 printf("Too long TDLS_TEARDOWN command.\n");
2903 return wpa_ctrl_command(ctrl
, cmd
);
2907 static int wpa_cli_cmd_signal_poll(struct wpa_ctrl
*ctrl
, int argc
,
2910 return wpa_ctrl_command(ctrl
, "SIGNAL_POLL");
2914 static int wpa_cli_cmd_reauthenticate(struct wpa_ctrl
*ctrl
, int argc
,
2917 return wpa_ctrl_command(ctrl
, "REAUTHENTICATE");
2921 #ifdef CONFIG_AUTOSCAN
2923 static int wpa_cli_cmd_autoscan(struct wpa_ctrl
*ctrl
, int argc
, char *argv
[])
2929 return wpa_ctrl_command(ctrl
, "AUTOSCAN ");
2931 res
= os_snprintf(cmd
, sizeof(cmd
), "AUTOSCAN %s", argv
[0]);
2932 if (res
< 0 || (size_t) res
>= sizeof(cmd
) - 1) {
2933 printf("Too long AUTOSCAN command.\n");
2937 return wpa_ctrl_command(ctrl
, cmd
);
2940 #endif /* CONFIG_AUTOSCAN */
2943 enum wpa_cli_cmd_flags
{
2944 cli_cmd_flag_none
= 0x00,
2945 cli_cmd_flag_sensitive
= 0x01
2948 struct wpa_cli_cmd
{
2950 int (*handler
)(struct wpa_ctrl
*ctrl
, int argc
, char *argv
[]);
2951 enum wpa_cli_cmd_flags flags
;
2955 static struct wpa_cli_cmd wpa_cli_commands
[] = {
2956 { "status", wpa_cli_cmd_status
,
2958 "[verbose] = get current WPA/EAPOL/EAP status" },
2959 { "ifname", wpa_cli_cmd_ifname
,
2961 "= get current interface name" },
2962 { "ping", wpa_cli_cmd_ping
,
2964 "= pings wpa_supplicant" },
2965 { "relog", wpa_cli_cmd_relog
,
2967 "= re-open log-file (allow rolling logs)" },
2968 { "note", wpa_cli_cmd_note
,
2970 "<text> = add a note to wpa_supplicant debug log" },
2971 { "mib", wpa_cli_cmd_mib
,
2973 "= get MIB variables (dot1x, dot11)" },
2974 { "help", wpa_cli_cmd_help
,
2976 "= show this usage help" },
2977 { "interface", wpa_cli_cmd_interface
,
2979 "[ifname] = show interfaces/select interface" },
2980 { "level", wpa_cli_cmd_level
,
2982 "<debug level> = change debug level" },
2983 { "license", wpa_cli_cmd_license
,
2985 "= show full wpa_cli license" },
2986 { "quit", wpa_cli_cmd_quit
,
2989 { "set", wpa_cli_cmd_set
,
2991 "= set variables (shows list of variables when run without "
2993 { "get", wpa_cli_cmd_get
,
2995 "<name> = get information" },
2996 { "logon", wpa_cli_cmd_logon
,
2998 "= IEEE 802.1X EAPOL state machine logon" },
2999 { "logoff", wpa_cli_cmd_logoff
,
3001 "= IEEE 802.1X EAPOL state machine logoff" },
3002 { "pmksa", wpa_cli_cmd_pmksa
,
3004 "= show PMKSA cache" },
3005 { "reassociate", wpa_cli_cmd_reassociate
,
3007 "= force reassociation" },
3008 { "preauthenticate", wpa_cli_cmd_preauthenticate
,
3010 "<BSSID> = force preauthentication" },
3011 { "identity", wpa_cli_cmd_identity
,
3013 "<network id> <identity> = configure identity for an SSID" },
3014 { "password", wpa_cli_cmd_password
,
3015 cli_cmd_flag_sensitive
,
3016 "<network id> <password> = configure password for an SSID" },
3017 { "new_password", wpa_cli_cmd_new_password
,
3018 cli_cmd_flag_sensitive
,
3019 "<network id> <password> = change password for an SSID" },
3020 { "pin", wpa_cli_cmd_pin
,
3021 cli_cmd_flag_sensitive
,
3022 "<network id> <pin> = configure pin for an SSID" },
3023 { "otp", wpa_cli_cmd_otp
,
3024 cli_cmd_flag_sensitive
,
3025 "<network id> <password> = configure one-time-password for an SSID"
3027 { "passphrase", wpa_cli_cmd_passphrase
,
3028 cli_cmd_flag_sensitive
,
3029 "<network id> <passphrase> = configure private key passphrase\n"
3031 { "bssid", wpa_cli_cmd_bssid
,
3033 "<network id> <BSSID> = set preferred BSSID for an SSID" },
3034 { "blacklist", wpa_cli_cmd_blacklist
,
3036 "<BSSID> = add a BSSID to the blacklist\n"
3037 "blacklist clear = clear the blacklist\n"
3038 "blacklist = display the blacklist" },
3039 { "log_level", wpa_cli_cmd_log_level
,
3041 "<level> [<timestamp>] = update the log level/timestamp\n"
3042 "log_level = display the current log level and log options" },
3043 { "list_networks", wpa_cli_cmd_list_networks
,
3045 "= list configured networks" },
3046 { "select_network", wpa_cli_cmd_select_network
,
3048 "<network id> = select a network (disable others)" },
3049 { "enable_network", wpa_cli_cmd_enable_network
,
3051 "<network id> = enable a network" },
3052 { "disable_network", wpa_cli_cmd_disable_network
,
3054 "<network id> = disable a network" },
3055 { "add_network", wpa_cli_cmd_add_network
,
3057 "= add a network" },
3058 { "remove_network", wpa_cli_cmd_remove_network
,
3060 "<network id> = remove a network" },
3061 { "set_network", wpa_cli_cmd_set_network
,
3062 cli_cmd_flag_sensitive
,
3063 "<network id> <variable> <value> = set network variables (shows\n"
3064 " list of variables when run without arguments)" },
3065 { "get_network", wpa_cli_cmd_get_network
,
3067 "<network id> <variable> = get network variables" },
3068 { "list_creds", wpa_cli_cmd_list_creds
,
3070 "= list configured credentials" },
3071 { "add_cred", wpa_cli_cmd_add_cred
,
3073 "= add a credential" },
3074 { "remove_cred", wpa_cli_cmd_remove_cred
,
3076 "<cred id> = remove a credential" },
3077 { "set_cred", wpa_cli_cmd_set_cred
,
3078 cli_cmd_flag_sensitive
,
3079 "<cred id> <variable> <value> = set credential variables" },
3080 { "save_config", wpa_cli_cmd_save_config
,
3082 "= save the current configuration" },
3083 { "disconnect", wpa_cli_cmd_disconnect
,
3085 "= disconnect and wait for reassociate/reconnect command before\n"
3087 { "reconnect", wpa_cli_cmd_reconnect
,
3089 "= like reassociate, but only takes effect if already disconnected"
3091 { "scan", wpa_cli_cmd_scan
,
3093 "= request new BSS scan" },
3094 { "scan_results", wpa_cli_cmd_scan_results
,
3096 "= get latest scan results" },
3097 { "bss", wpa_cli_cmd_bss
,
3099 "<<idx> | <bssid>> = get detailed scan result info" },
3100 { "get_capability", wpa_cli_cmd_get_capability
,
3102 "<eap/pairwise/group/key_mgmt/proto/auth_alg/channels> "
3103 "= get capabilies" },
3104 { "reconfigure", wpa_cli_cmd_reconfigure
,
3106 "= force wpa_supplicant to re-read its configuration file" },
3107 { "terminate", wpa_cli_cmd_terminate
,
3109 "= terminate wpa_supplicant" },
3110 { "interface_add", wpa_cli_cmd_interface_add
,
3112 "<ifname> <confname> <driver> <ctrl_interface> <driver_param>\n"
3113 " <bridge_name> = adds new interface, all parameters but <ifname>\n"
3115 { "interface_remove", wpa_cli_cmd_interface_remove
,
3117 "<ifname> = removes the interface" },
3118 { "interface_list", wpa_cli_cmd_interface_list
,
3120 "= list available interfaces" },
3121 { "ap_scan", wpa_cli_cmd_ap_scan
,
3123 "<value> = set ap_scan parameter" },
3124 { "scan_interval", wpa_cli_cmd_scan_interval
,
3126 "<value> = set scan_interval parameter (in seconds)" },
3127 { "bss_expire_age", wpa_cli_cmd_bss_expire_age
,
3129 "<value> = set BSS expiration age parameter" },
3130 { "bss_expire_count", wpa_cli_cmd_bss_expire_count
,
3132 "<value> = set BSS expiration scan count parameter" },
3133 { "stkstart", wpa_cli_cmd_stkstart
,
3135 "<addr> = request STK negotiation with <addr>" },
3136 { "ft_ds", wpa_cli_cmd_ft_ds
,
3138 "<addr> = request over-the-DS FT with <addr>" },
3139 { "wps_pbc", wpa_cli_cmd_wps_pbc
,
3141 "[BSSID] = start Wi-Fi Protected Setup: Push Button Configuration" },
3142 { "wps_pin", wpa_cli_cmd_wps_pin
,
3143 cli_cmd_flag_sensitive
,
3144 "<BSSID> [PIN] = start WPS PIN method (returns PIN, if not "
3146 { "wps_check_pin", wpa_cli_cmd_wps_check_pin
,
3147 cli_cmd_flag_sensitive
,
3148 "<PIN> = verify PIN checksum" },
3149 { "wps_cancel", wpa_cli_cmd_wps_cancel
, cli_cmd_flag_none
,
3150 "Cancels the pending WPS operation" },
3151 #ifdef CONFIG_WPS_OOB
3152 { "wps_oob", wpa_cli_cmd_wps_oob
,
3153 cli_cmd_flag_sensitive
,
3154 "<DEV_TYPE> <PATH> <METHOD> [DEV_NAME] = start WPS OOB" },
3155 #endif /* CONFIG_WPS_OOB */
3156 #ifdef CONFIG_WPS_NFC
3157 { "wps_nfc", wpa_cli_cmd_wps_nfc
,
3159 "[BSSID] = start Wi-Fi Protected Setup: NFC" },
3160 { "wps_nfc_token", wpa_cli_cmd_wps_nfc_token
,
3162 "<WPS|NDEF> = create password token" },
3163 { "wps_nfc_tag_read", wpa_cli_cmd_wps_nfc_tag_read
,
3164 cli_cmd_flag_sensitive
,
3165 "<hexdump of payload> = report read NFC tag with WPS data" },
3166 #endif /* CONFIG_WPS_NFC */
3167 { "wps_reg", wpa_cli_cmd_wps_reg
,
3168 cli_cmd_flag_sensitive
,
3169 "<BSSID> <AP PIN> = start WPS Registrar to configure an AP" },
3170 { "wps_ap_pin", wpa_cli_cmd_wps_ap_pin
,
3171 cli_cmd_flag_sensitive
,
3172 "[params..] = enable/disable AP PIN" },
3173 { "wps_er_start", wpa_cli_cmd_wps_er_start
,
3175 "[IP address] = start Wi-Fi Protected Setup External Registrar" },
3176 { "wps_er_stop", wpa_cli_cmd_wps_er_stop
,
3178 "= stop Wi-Fi Protected Setup External Registrar" },
3179 { "wps_er_pin", wpa_cli_cmd_wps_er_pin
,
3180 cli_cmd_flag_sensitive
,
3181 "<UUID> <PIN> = add an Enrollee PIN to External Registrar" },
3182 { "wps_er_pbc", wpa_cli_cmd_wps_er_pbc
,
3184 "<UUID> = accept an Enrollee PBC using External Registrar" },
3185 { "wps_er_learn", wpa_cli_cmd_wps_er_learn
,
3186 cli_cmd_flag_sensitive
,
3187 "<UUID> <PIN> = learn AP configuration" },
3188 { "wps_er_set_config", wpa_cli_cmd_wps_er_set_config
,
3190 "<UUID> <network id> = set AP configuration for enrolling" },
3191 { "wps_er_config", wpa_cli_cmd_wps_er_config
,
3192 cli_cmd_flag_sensitive
,
3193 "<UUID> <PIN> <SSID> <auth> <encr> <key> = configure AP" },
3194 #ifdef CONFIG_WPS_NFC
3195 { "wps_er_nfc_config_token", wpa_cli_cmd_wps_er_nfc_config_token
,
3197 "<WPS/NDEF> <UUID> = build NFC configuration token" },
3198 #endif /* CONFIG_WPS_NFC */
3199 { "ibss_rsn", wpa_cli_cmd_ibss_rsn
,
3201 "<addr> = request RSN authentication with <addr> in IBSS" },
3203 { "sta", wpa_cli_cmd_sta
,
3205 "<addr> = get information about an associated station (AP)" },
3206 { "all_sta", wpa_cli_cmd_all_sta
,
3208 "= get information about all associated stations (AP)" },
3209 { "deauthenticate", wpa_cli_cmd_deauthenticate
,
3211 "<addr> = deauthenticate a station" },
3212 { "disassociate", wpa_cli_cmd_disassociate
,
3214 "<addr> = disassociate a station" },
3215 #endif /* CONFIG_AP */
3216 { "suspend", wpa_cli_cmd_suspend
, cli_cmd_flag_none
,
3217 "= notification of suspend/hibernate" },
3218 { "resume", wpa_cli_cmd_resume
, cli_cmd_flag_none
,
3219 "= notification of resume/thaw" },
3220 { "drop_sa", wpa_cli_cmd_drop_sa
, cli_cmd_flag_none
,
3221 "= drop SA without deauth/disassoc (test command)" },
3222 { "roam", wpa_cli_cmd_roam
,
3224 "<addr> = roam to the specified BSS" },
3226 { "p2p_find", wpa_cli_cmd_p2p_find
, cli_cmd_flag_none
,
3227 "[timeout] [type=*] = find P2P Devices for up-to timeout seconds" },
3228 { "p2p_stop_find", wpa_cli_cmd_p2p_stop_find
, cli_cmd_flag_none
,
3229 "= stop P2P Devices search" },
3230 { "p2p_connect", wpa_cli_cmd_p2p_connect
, cli_cmd_flag_none
,
3231 "<addr> <\"pbc\"|PIN> = connect to a P2P Devices" },
3232 { "p2p_listen", wpa_cli_cmd_p2p_listen
, cli_cmd_flag_none
,
3233 "[timeout] = listen for P2P Devices for up-to timeout seconds" },
3234 { "p2p_group_remove", wpa_cli_cmd_p2p_group_remove
, cli_cmd_flag_none
,
3235 "<ifname> = remove P2P group interface (terminate group if GO)" },
3236 { "p2p_group_add", wpa_cli_cmd_p2p_group_add
, cli_cmd_flag_none
,
3237 "= add a new P2P group (local end as GO)" },
3238 { "p2p_prov_disc", wpa_cli_cmd_p2p_prov_disc
, cli_cmd_flag_none
,
3239 "<addr> <method> = request provisioning discovery" },
3240 { "p2p_get_passphrase", wpa_cli_cmd_p2p_get_passphrase
,
3242 "= get the passphrase for a group (GO only)" },
3243 { "p2p_serv_disc_req", wpa_cli_cmd_p2p_serv_disc_req
,
3245 "<addr> <TLVs> = schedule service discovery request" },
3246 { "p2p_serv_disc_cancel_req", wpa_cli_cmd_p2p_serv_disc_cancel_req
,
3248 "<id> = cancel pending service discovery request" },
3249 { "p2p_serv_disc_resp", wpa_cli_cmd_p2p_serv_disc_resp
,
3251 "<freq> <addr> <dialog token> <TLVs> = service discovery response" },
3252 { "p2p_service_update", wpa_cli_cmd_p2p_service_update
,
3254 "= indicate change in local services" },
3255 { "p2p_serv_disc_external", wpa_cli_cmd_p2p_serv_disc_external
,
3257 "<external> = set external processing of service discovery" },
3258 { "p2p_service_flush", wpa_cli_cmd_p2p_service_flush
,
3260 "= remove all stored service entries" },
3261 { "p2p_service_add", wpa_cli_cmd_p2p_service_add
,
3263 "<bonjour|upnp> <query|version> <response|service> = add a local "
3265 { "p2p_service_del", wpa_cli_cmd_p2p_service_del
,
3267 "<bonjour|upnp> <query|version> [|service] = remove a local "
3269 { "p2p_reject", wpa_cli_cmd_p2p_reject
,
3271 "<addr> = reject connection attempts from a specific peer" },
3272 { "p2p_invite", wpa_cli_cmd_p2p_invite
,
3274 "<cmd> [peer=addr] = invite peer" },
3275 { "p2p_peers", wpa_cli_cmd_p2p_peers
, cli_cmd_flag_none
,
3276 "[discovered] = list known (optionally, only fully discovered) P2P "
3278 { "p2p_peer", wpa_cli_cmd_p2p_peer
, cli_cmd_flag_none
,
3279 "<address> = show information about known P2P peer" },
3280 { "p2p_set", wpa_cli_cmd_p2p_set
, cli_cmd_flag_none
,
3281 "<field> <value> = set a P2P parameter" },
3282 { "p2p_flush", wpa_cli_cmd_p2p_flush
, cli_cmd_flag_none
,
3283 "= flush P2P state" },
3284 { "p2p_cancel", wpa_cli_cmd_p2p_cancel
, cli_cmd_flag_none
,
3285 "= cancel P2P group formation" },
3286 { "p2p_unauthorize", wpa_cli_cmd_p2p_unauthorize
, cli_cmd_flag_none
,
3287 "<address> = unauthorize a peer" },
3288 { "p2p_presence_req", wpa_cli_cmd_p2p_presence_req
, cli_cmd_flag_none
,
3289 "[<duration> <interval>] [<duration> <interval>] = request GO "
3291 { "p2p_ext_listen", wpa_cli_cmd_p2p_ext_listen
, cli_cmd_flag_none
,
3292 "[<period> <interval>] = set extended listen timing" },
3293 #endif /* CONFIG_P2P */
3295 #ifdef CONFIG_INTERWORKING
3296 { "fetch_anqp", wpa_cli_cmd_fetch_anqp
, cli_cmd_flag_none
,
3297 "= fetch ANQP information for all APs" },
3298 { "stop_fetch_anqp", wpa_cli_cmd_stop_fetch_anqp
, cli_cmd_flag_none
,
3299 "= stop fetch_anqp operation" },
3300 { "interworking_select", wpa_cli_cmd_interworking_select
,
3302 "[auto] = perform Interworking network selection" },
3303 { "interworking_connect", wpa_cli_cmd_interworking_connect
,
3305 "<BSSID> = connect using Interworking credentials" },
3306 { "anqp_get", wpa_cli_cmd_anqp_get
, cli_cmd_flag_none
,
3307 "<addr> <info id>[,<info id>]... = request ANQP information" },
3308 #endif /* CONFIG_INTERWORKING */
3310 { "hs20_anqp_get", wpa_cli_cmd_hs20_anqp_get
, cli_cmd_flag_none
,
3311 "<addr> <subtype>[,<subtype>]... = request HS 2.0 ANQP information"
3313 { "nai_home_realm_list", wpa_cli_cmd_get_nai_home_realm_list
,
3315 "<addr> <home realm> = get HS20 nai home realm list" },
3316 #endif /* CONFIG_HS20 */
3317 { "sta_autoconnect", wpa_cli_cmd_sta_autoconnect
, cli_cmd_flag_none
,
3318 "<0/1> = disable/enable automatic reconnection" },
3319 { "tdls_discover", wpa_cli_cmd_tdls_discover
,
3321 "<addr> = request TDLS discovery with <addr>" },
3322 { "tdls_setup", wpa_cli_cmd_tdls_setup
,
3324 "<addr> = request TDLS setup with <addr>" },
3325 { "tdls_teardown", wpa_cli_cmd_tdls_teardown
,
3327 "<addr> = tear down TDLS with <addr>" },
3328 { "signal_poll", wpa_cli_cmd_signal_poll
,
3330 "= get signal parameters" },
3331 { "reauthenticate", wpa_cli_cmd_reauthenticate
, cli_cmd_flag_none
,
3332 "= trigger IEEE 802.1X/EAPOL reauthentication" },
3333 #ifdef CONFIG_AUTOSCAN
3334 { "autoscan", wpa_cli_cmd_autoscan
, cli_cmd_flag_none
,
3335 "[params] = Set or unset (if none) autoscan parameters" },
3336 #endif /* CONFIG_AUTOSCAN */
3337 { NULL
, NULL
, cli_cmd_flag_none
, NULL
}
3342 * Prints command usage, lines are padded with the specified string.
3344 static void print_cmd_help(struct wpa_cli_cmd
*cmd
, const char *pad
)
3349 printf("%s%s ", pad
, cmd
->cmd
);
3350 for (n
= 0; (c
= cmd
->usage
[n
]); n
++) {
3359 static void print_help(void)
3362 printf("commands:\n");
3363 for (n
= 0; wpa_cli_commands
[n
].cmd
; n
++)
3364 print_cmd_help(&wpa_cli_commands
[n
], " ");
3368 static int wpa_cli_edit_filter_history_cb(void *ctx
, const char *cmd
)
3370 const char *c
, *delim
;
3374 delim
= os_strchr(cmd
, ' ');
3378 len
= os_strlen(cmd
);
3380 for (n
= 0; (c
= wpa_cli_commands
[n
].cmd
); n
++) {
3381 if (os_strncasecmp(cmd
, c
, len
) == 0 && len
== os_strlen(c
))
3382 return (wpa_cli_commands
[n
].flags
&
3383 cli_cmd_flag_sensitive
);
3389 static char ** wpa_list_cmd_list(void)
3394 count
= sizeof(wpa_cli_commands
) / sizeof(wpa_cli_commands
[0]);
3395 res
= os_calloc(count
, sizeof(char *));
3399 for (i
= 0; wpa_cli_commands
[i
].cmd
; i
++) {
3400 res
[i
] = os_strdup(wpa_cli_commands
[i
].cmd
);
3409 static char ** wpa_cli_cmd_completion(const char *cmd
, const char *str
,
3414 if (os_strcasecmp(cmd
, "bss") == 0)
3415 return wpa_cli_complete_bss(str
, pos
);
3417 if (os_strcasecmp(cmd
, "p2p_connect") == 0)
3418 return wpa_cli_complete_p2p_connect(str
, pos
);
3419 if (os_strcasecmp(cmd
, "p2p_peer") == 0)
3420 return wpa_cli_complete_p2p_peer(str
, pos
);
3421 if (os_strcasecmp(cmd
, "p2p_group_remove") == 0)
3422 return wpa_cli_complete_p2p_group_remove(str
, pos
);
3423 #endif /* CONFIG_P2P */
3425 for (i
= 0; wpa_cli_commands
[i
].cmd
; i
++) {
3426 if (os_strcasecmp(wpa_cli_commands
[i
].cmd
, cmd
) == 0) {
3428 printf("\r%s\n", wpa_cli_commands
[i
].usage
);
3438 static char ** wpa_cli_edit_completion_cb(void *ctx
, const char *str
, int pos
)
3444 end
= os_strchr(str
, ' ');
3445 if (end
== NULL
|| str
+ pos
< end
)
3446 return wpa_list_cmd_list();
3448 cmd
= os_malloc(pos
+ 1);
3451 os_memcpy(cmd
, str
, pos
);
3452 cmd
[end
- str
] = '\0';
3453 res
= wpa_cli_cmd_completion(cmd
, str
, pos
);
3459 static int wpa_request(struct wpa_ctrl
*ctrl
, int argc
, char *argv
[])
3461 struct wpa_cli_cmd
*cmd
, *match
= NULL
;
3466 cmd
= wpa_cli_commands
;
3468 if (os_strncasecmp(cmd
->cmd
, argv
[0], os_strlen(argv
[0])) == 0)
3471 if (os_strcasecmp(cmd
->cmd
, argv
[0]) == 0) {
3472 /* we have an exact match */
3482 printf("Ambiguous command '%s'; possible commands:", argv
[0]);
3483 cmd
= wpa_cli_commands
;
3485 if (os_strncasecmp(cmd
->cmd
, argv
[0],
3486 os_strlen(argv
[0])) == 0) {
3487 printf(" %s", cmd
->cmd
);
3493 } else if (count
== 0) {
3494 printf("Unknown command '%s'\n", argv
[0]);
3497 ret
= match
->handler(ctrl
, argc
- 1, &argv
[1]);
3504 static int str_match(const char *a
, const char *b
)
3506 return os_strncmp(a
, b
, os_strlen(b
)) == 0;
3510 static int wpa_cli_exec(const char *program
, const char *arg1
,
3518 len
= os_strlen(program
) + os_strlen(arg1
) + os_strlen(arg2
) + 3;
3519 cmd
= os_malloc(len
);
3522 res
= os_snprintf(cmd
, len
, "%s %s %s", program
, arg1
, arg2
);
3523 if (res
< 0 || (size_t) res
>= len
) {
3527 cmd
[len
- 1] = '\0';
3529 if (system(cmd
) < 0)
3531 #endif /* _WIN32_WCE */
3538 static void wpa_cli_action_process(const char *msg
)
3541 char *copy
= NULL
, *id
, *pos2
;
3546 pos
= os_strchr(pos
, '>');
3553 if (str_match(pos
, WPA_EVENT_CONNECTED
)) {
3555 os_unsetenv("WPA_ID");
3556 os_unsetenv("WPA_ID_STR");
3557 os_unsetenv("WPA_CTRL_DIR");
3559 pos
= os_strstr(pos
, "[id=");
3561 copy
= os_strdup(pos
+ 4);
3565 while (*pos2
&& *pos2
!= ' ')
3569 os_setenv("WPA_ID", id
, 1);
3570 while (*pos2
&& *pos2
!= '=')
3575 while (*pos2
&& *pos2
!= ']')
3578 os_setenv("WPA_ID_STR", id
, 1);
3582 os_setenv("WPA_CTRL_DIR", ctrl_iface_dir
, 1);
3584 if (!wpa_cli_connected
|| new_id
!= wpa_cli_last_id
) {
3585 wpa_cli_connected
= 1;
3586 wpa_cli_last_id
= new_id
;
3587 wpa_cli_exec(action_file
, ctrl_ifname
, "CONNECTED");
3589 } else if (str_match(pos
, WPA_EVENT_DISCONNECTED
)) {
3590 if (wpa_cli_connected
) {
3591 wpa_cli_connected
= 0;
3592 wpa_cli_exec(action_file
, ctrl_ifname
, "DISCONNECTED");
3594 } else if (str_match(pos
, P2P_EVENT_GROUP_STARTED
)) {
3595 wpa_cli_exec(action_file
, ctrl_ifname
, pos
);
3596 } else if (str_match(pos
, P2P_EVENT_GROUP_REMOVED
)) {
3597 wpa_cli_exec(action_file
, ctrl_ifname
, pos
);
3598 } else if (str_match(pos
, P2P_EVENT_CROSS_CONNECT_ENABLE
)) {
3599 wpa_cli_exec(action_file
, ctrl_ifname
, pos
);
3600 } else if (str_match(pos
, P2P_EVENT_CROSS_CONNECT_DISABLE
)) {
3601 wpa_cli_exec(action_file
, ctrl_ifname
, pos
);
3602 } else if (str_match(pos
, P2P_EVENT_GO_NEG_FAILURE
)) {
3603 wpa_cli_exec(action_file
, ctrl_ifname
, pos
);
3604 } else if (str_match(pos
, WPS_EVENT_SUCCESS
)) {
3605 wpa_cli_exec(action_file
, ctrl_ifname
, pos
);
3606 } else if (str_match(pos
, WPS_EVENT_FAIL
)) {
3607 wpa_cli_exec(action_file
, ctrl_ifname
, pos
);
3608 } else if (str_match(pos
, AP_STA_CONNECTED
)) {
3609 wpa_cli_exec(action_file
, ctrl_ifname
, pos
);
3610 } else if (str_match(pos
, AP_STA_DISCONNECTED
)) {
3611 wpa_cli_exec(action_file
, ctrl_ifname
, pos
);
3612 } else if (str_match(pos
, WPA_EVENT_TERMINATING
)) {
3613 printf("wpa_supplicant is terminating - stop monitoring\n");
3619 #ifndef CONFIG_ANSI_C_EXTRA
3620 static void wpa_cli_action_cb(char *msg
, size_t len
)
3622 wpa_cli_action_process(msg
);
3624 #endif /* CONFIG_ANSI_C_EXTRA */
3627 static void wpa_cli_reconnect(void)
3629 wpa_cli_close_connection();
3630 if (wpa_cli_open_connection(ctrl_ifname
, 1) < 0)
3635 printf("\rConnection to wpa_supplicant re-established\n");
3641 static void cli_event(const char *str
)
3643 const char *start
, *s
;
3645 start
= os_strchr(str
, '>');
3651 if (str_starts(start
, WPA_EVENT_BSS_ADDED
)) {
3652 s
= os_strchr(start
, ' ');
3655 s
= os_strchr(s
+ 1, ' ');
3658 cli_txt_list_add(&bsses
, s
+ 1);
3662 if (str_starts(start
, WPA_EVENT_BSS_REMOVED
)) {
3663 s
= os_strchr(start
, ' ');
3666 s
= os_strchr(s
+ 1, ' ');
3669 cli_txt_list_del_addr(&bsses
, s
+ 1);
3674 if (str_starts(start
, P2P_EVENT_DEVICE_FOUND
)) {
3675 s
= os_strstr(start
, " p2p_dev_addr=");
3678 cli_txt_list_add_addr(&p2p_peers
, s
+ 14);
3682 if (str_starts(start
, P2P_EVENT_DEVICE_LOST
)) {
3683 s
= os_strstr(start
, " p2p_dev_addr=");
3686 cli_txt_list_del_addr(&p2p_peers
, s
+ 14);
3690 if (str_starts(start
, P2P_EVENT_GROUP_STARTED
)) {
3691 s
= os_strchr(start
, ' ');
3694 cli_txt_list_add_word(&p2p_groups
, s
+ 1);
3698 if (str_starts(start
, P2P_EVENT_GROUP_REMOVED
)) {
3699 s
= os_strchr(start
, ' ');
3702 cli_txt_list_del_word(&p2p_groups
, s
+ 1);
3705 #endif /* CONFIG_P2P */
3709 static int check_terminating(const char *msg
)
3711 const char *pos
= msg
;
3715 pos
= os_strchr(pos
, '>');
3722 if (str_match(pos
, WPA_EVENT_TERMINATING
) && ctrl_conn
) {
3724 printf("\rConnection to wpa_supplicant lost - trying to "
3727 wpa_cli_attached
= 0;
3728 wpa_cli_close_connection();
3736 static void wpa_cli_recv_pending(struct wpa_ctrl
*ctrl
, int action_monitor
)
3738 if (ctrl_conn
== NULL
) {
3739 wpa_cli_reconnect();
3742 while (wpa_ctrl_pending(ctrl
) > 0) {
3744 size_t len
= sizeof(buf
) - 1;
3745 if (wpa_ctrl_recv(ctrl
, buf
, &len
) == 0) {
3748 wpa_cli_action_process(buf
);
3751 if (wpa_cli_show_event(buf
)) {
3753 printf("\r%s\n", buf
);
3757 if (interactive
&& check_terminating(buf
) > 0)
3761 printf("Could not read pending message.\n");
3766 if (wpa_ctrl_pending(ctrl
) < 0) {
3767 printf("Connection to wpa_supplicant lost - trying to "
3769 wpa_cli_reconnect();
3775 static int tokenize_cmd(char *cmd
, char *argv
[])
3788 if (argc
== max_args
)
3791 char *pos2
= os_strrchr(pos
, '"');
3795 while (*pos
!= '\0' && *pos
!= ' ')
3805 static void wpa_cli_ping(void *eloop_ctx
, void *timeout_ctx
)
3807 if (ctrl_conn
&& _wpa_ctrl_command(ctrl_conn
, "PING", 0)) {
3808 printf("Connection to wpa_supplicant lost - trying to "
3810 wpa_cli_close_connection();
3813 wpa_cli_reconnect();
3814 eloop_register_timeout(ping_interval
, 0, wpa_cli_ping
, NULL
, NULL
);
3818 static void wpa_cli_mon_receive(int sock
, void *eloop_ctx
, void *sock_ctx
)
3820 wpa_cli_recv_pending(mon_conn
, 0);
3824 static void wpa_cli_edit_cmd_cb(void *ctx
, char *cmd
)
3826 char *argv
[max_args
];
3828 argc
= tokenize_cmd(cmd
, argv
);
3830 wpa_request(ctrl_conn
, argc
, argv
);
3834 static void wpa_cli_edit_eof_cb(void *ctx
)
3840 static int warning_displayed
= 0;
3841 static char *hfile
= NULL
;
3842 static int edit_started
= 0;
3844 static void start_edit(void)
3849 #ifdef CONFIG_CTRL_IFACE_UDP_REMOTE
3850 ps
= wpa_ctrl_get_remote_ifname(ctrl_conn
);
3851 #endif /* CONFIG_CTRL_IFACE_UDP_REMOTE */
3853 home
= getenv("HOME");
3855 const char *fname
= ".wpa_cli_history";
3856 int hfile_len
= os_strlen(home
) + 1 + os_strlen(fname
) + 1;
3857 hfile
= os_malloc(hfile_len
);
3859 os_snprintf(hfile
, hfile_len
, "%s/%s", home
, fname
);
3862 if (edit_init(wpa_cli_edit_cmd_cb
, wpa_cli_edit_eof_cb
,
3863 wpa_cli_edit_completion_cb
, NULL
, hfile
, ps
) < 0) {
3869 eloop_register_timeout(ping_interval
, 0, wpa_cli_ping
, NULL
, NULL
);
3873 static void try_connection(void *eloop_ctx
, void *timeout_ctx
)
3875 if (ctrl_ifname
== NULL
)
3876 ctrl_ifname
= wpa_cli_get_default_ifname();
3878 if (!wpa_cli_open_connection(ctrl_ifname
, 1) == 0) {
3879 if (!warning_displayed
) {
3880 printf("Could not connect to wpa_supplicant: "
3881 "%s - re-trying\n", ctrl_ifname
);
3882 warning_displayed
= 1;
3884 eloop_register_timeout(1, 0, try_connection
, NULL
, NULL
);
3888 if (warning_displayed
)
3889 printf("Connection established.\n");
3895 static void wpa_cli_interactive(void)
3897 printf("\nInteractive mode\n\n");
3899 eloop_register_timeout(0, 0, try_connection
, NULL
, NULL
);
3901 eloop_cancel_timeout(try_connection
, NULL
, NULL
);
3903 cli_txt_list_flush(&p2p_peers
);
3904 cli_txt_list_flush(&p2p_groups
);
3905 cli_txt_list_flush(&bsses
);
3907 edit_deinit(hfile
, wpa_cli_edit_filter_history_cb
);
3909 eloop_cancel_timeout(wpa_cli_ping
, NULL
, NULL
);
3910 wpa_cli_close_connection();
3914 static void wpa_cli_action(struct wpa_ctrl
*ctrl
)
3916 #ifdef CONFIG_ANSI_C_EXTRA
3917 /* TODO: ANSI C version(?) */
3918 printf("Action processing not supported in ANSI C build.\n");
3919 #else /* CONFIG_ANSI_C_EXTRA */
3923 char buf
[256]; /* note: large enough to fit in unsolicited messages */
3926 fd
= wpa_ctrl_get_fd(ctrl
);
3928 while (!wpa_cli_quit
) {
3931 tv
.tv_sec
= ping_interval
;
3933 res
= select(fd
+ 1, &rfds
, NULL
, NULL
, &tv
);
3934 if (res
< 0 && errno
!= EINTR
) {
3939 if (FD_ISSET(fd
, &rfds
))
3940 wpa_cli_recv_pending(ctrl
, 1);
3942 /* verify that connection is still working */
3943 len
= sizeof(buf
) - 1;
3944 if (wpa_ctrl_request(ctrl
, "PING", 4, buf
, &len
,
3945 wpa_cli_action_cb
) < 0 ||
3946 len
< 4 || os_memcmp(buf
, "PONG", 4) != 0) {
3947 printf("wpa_supplicant did not reply to PING "
3948 "command - exiting\n");
3953 #endif /* CONFIG_ANSI_C_EXTRA */
3957 static void wpa_cli_cleanup(void)
3959 wpa_cli_close_connection();
3961 os_daemonize_terminate(pid_file
);
3963 os_program_deinit();
3967 static void wpa_cli_terminate(int sig
, void *ctx
)
3973 static char * wpa_cli_get_default_ifname(void)
3975 char *ifname
= NULL
;
3977 #ifdef CONFIG_CTRL_IFACE_UNIX
3978 struct dirent
*dent
;
3979 DIR *dir
= opendir(ctrl_iface_dir
);
3982 char ifprop
[PROPERTY_VALUE_MAX
];
3983 if (property_get("wifi.interface", ifprop
, NULL
) != 0) {
3984 ifname
= os_strdup(ifprop
);
3985 printf("Using interface '%s'\n", ifname
);
3988 #endif /* ANDROID */
3991 while ((dent
= readdir(dir
))) {
3992 #ifdef _DIRENT_HAVE_D_TYPE
3994 * Skip the file if it is not a socket. Also accept
3995 * DT_UNKNOWN (0) in case the C library or underlying
3996 * file system does not support d_type.
3998 if (dent
->d_type
!= DT_SOCK
&& dent
->d_type
!= DT_UNKNOWN
)
4000 #endif /* _DIRENT_HAVE_D_TYPE */
4001 if (os_strcmp(dent
->d_name
, ".") == 0 ||
4002 os_strcmp(dent
->d_name
, "..") == 0)
4004 printf("Selected interface '%s'\n", dent
->d_name
);
4005 ifname
= os_strdup(dent
->d_name
);
4009 #endif /* CONFIG_CTRL_IFACE_UNIX */
4011 #ifdef CONFIG_CTRL_IFACE_NAMED_PIPE
4012 char buf
[2048], *pos
;
4014 struct wpa_ctrl
*ctrl
;
4017 ctrl
= wpa_ctrl_open(NULL
);
4021 len
= sizeof(buf
) - 1;
4022 ret
= wpa_ctrl_request(ctrl
, "INTERFACES", 10, buf
, &len
, NULL
);
4025 pos
= os_strchr(buf
, '\n');
4028 ifname
= os_strdup(buf
);
4030 wpa_ctrl_close(ctrl
);
4031 #endif /* CONFIG_CTRL_IFACE_NAMED_PIPE */
4037 int main(int argc
, char *argv
[])
4042 const char *global
= NULL
;
4044 if (os_program_init())
4048 c
= getopt(argc
, argv
, "a:Bg:G:hi:p:P:v");
4053 action_file
= optarg
;
4062 ping_interval
= atoi(optarg
);
4068 printf("%s\n", wpa_cli_version
);
4071 os_free(ctrl_ifname
);
4072 ctrl_ifname
= os_strdup(optarg
);
4075 ctrl_iface_dir
= optarg
;
4086 interactive
= (argc
== optind
) && (action_file
== NULL
);
4089 printf("%s\n\n%s\n\n", wpa_cli_version
, wpa_cli_license
);
4095 #ifdef CONFIG_CTRL_IFACE_NAMED_PIPE
4096 ctrl_conn
= wpa_ctrl_open(NULL
);
4097 #else /* CONFIG_CTRL_IFACE_NAMED_PIPE */
4098 ctrl_conn
= wpa_ctrl_open(global
);
4099 #endif /* CONFIG_CTRL_IFACE_NAMED_PIPE */
4100 if (ctrl_conn
== NULL
) {
4101 fprintf(stderr
, "Failed to connect to wpa_supplicant "
4102 "global interface: %s error: %s\n",
4103 global
, strerror(errno
));
4108 eloop_register_signal_terminate(wpa_cli_terminate
, NULL
);
4110 if (ctrl_ifname
== NULL
)
4111 ctrl_ifname
= wpa_cli_get_default_ifname();
4114 wpa_cli_interactive();
4117 wpa_cli_open_connection(ctrl_ifname
, 0) < 0) {
4118 fprintf(stderr
, "Failed to connect to non-global "
4119 "ctrl_ifname: %s error: %s\n",
4120 ctrl_ifname
, strerror(errno
));
4125 if (wpa_ctrl_attach(ctrl_conn
) == 0) {
4126 wpa_cli_attached
= 1;
4128 printf("Warning: Failed to attach to "
4129 "wpa_supplicant.\n");
4134 if (daemonize
&& os_daemonize(pid_file
))
4138 wpa_cli_action(ctrl_conn
);
4140 ret
= wpa_request(ctrl_conn
, argc
- optind
,
4144 os_free(ctrl_ifname
);
4151 #else /* CONFIG_CTRL_IFACE */
4152 int main(int argc
, char *argv
[])
4154 printf("CONFIG_CTRL_IFACE not defined - wpa_cli disabled\n");
4157 #endif /* CONFIG_CTRL_IFACE */