blob: 695fcbe04995644ca349082b87bb6f564142f3a8 [file] [log] [blame]
/*
* WPA Supplicant - command line interface for wpa_supplicant daemon
* Copyright (c) 2004-2019, Jouni Malinen <j@w1.fi>
*
* This software may be distributed under the terms of the BSD license.
* See README for more details.
*/
#include "includes.h"
#ifdef CONFIG_CTRL_IFACE
#ifdef CONFIG_CTRL_IFACE_UNIX
#include <dirent.h>
#endif /* CONFIG_CTRL_IFACE_UNIX */
#include "common/cli.h"
#include "common/wpa_ctrl.h"
#include "utils/common.h"
#include "utils/eloop.h"
#include "utils/edit.h"
#include "utils/list.h"
#include "common/version.h"
#include "common/ieee802_11_defs.h"
#ifdef ANDROID
#include <cutils/properties.h>
#endif /* ANDROID */
static const char *const wpa_cli_version =
"wpa_cli v" VERSION_STR "\n"
"Copyright (c) 2004-2019, Jouni Malinen <j@w1.fi> and contributors";
#define VENDOR_ELEM_FRAME_ID \
" 0: Probe Req (P2P), 1: Probe Resp (P2P) , 2: Probe Resp (GO), " \
"3: Beacon (GO), 4: PD Req, 5: PD Resp, 6: GO Neg Req, " \
"7: GO Neg Resp, 8: GO Neg Conf, 9: Inv Req, 10: Inv Resp, " \
"11: Assoc Req (P2P), 12: Assoc Resp (P2P)"
static struct wpa_ctrl *ctrl_conn;
static struct wpa_ctrl *mon_conn;
static int wpa_cli_quit = 0;
static int wpa_cli_attached = 0;
static int wpa_cli_connected = -1;
static int wpa_cli_last_id = 0;
#ifndef CONFIG_CTRL_IFACE_DIR
#define CONFIG_CTRL_IFACE_DIR "/var/run/wpa_supplicant"
#endif /* CONFIG_CTRL_IFACE_DIR */
static const char *ctrl_iface_dir = CONFIG_CTRL_IFACE_DIR;
static const char *client_socket_dir = NULL;
static char *ctrl_ifname = NULL;
static const char *global = NULL;
static const char *pid_file = NULL;
static const char *action_file = NULL;
static int ping_interval = 5;
static int interactive = 0;
static char *ifname_prefix = NULL;
static DEFINE_DL_LIST(bsses); /* struct cli_txt_entry */
static DEFINE_DL_LIST(p2p_peers); /* struct cli_txt_entry */
static DEFINE_DL_LIST(p2p_groups); /* struct cli_txt_entry */
static DEFINE_DL_LIST(ifnames); /* struct cli_txt_entry */
static DEFINE_DL_LIST(networks); /* struct cli_txt_entry */
static DEFINE_DL_LIST(creds); /* struct cli_txt_entry */
#ifdef CONFIG_AP
static DEFINE_DL_LIST(stations); /* struct cli_txt_entry */
#endif /* CONFIG_AP */
static void print_help(const char *cmd);
static void wpa_cli_mon_receive(int sock, void *eloop_ctx, void *sock_ctx);
static void wpa_cli_close_connection(void);
static char * wpa_cli_get_default_ifname(void);
static char ** wpa_list_cmd_list(void);
static void update_creds(struct wpa_ctrl *ctrl);
static void update_networks(struct wpa_ctrl *ctrl);
static void update_stations(struct wpa_ctrl *ctrl);
static void update_ifnames(struct wpa_ctrl *ctrl);
static void usage(void)
{
printf("wpa_cli [-p<path to ctrl sockets>] [-i<ifname>] [-hvB] "
"[-a<action file>] \\\n"
" [-P<pid file>] [-g<global ctrl>] [-G<ping interval>] "
"\\\n"
" [-s<wpa_client_socket_file_path>] "
"[command..]\n"
" -h = help (show this usage text)\n"
" -v = shown version information\n"
" -a = run in daemon mode executing the action file based on "
"events from\n"
" wpa_supplicant\n"
" -B = run a daemon in the background\n"
" default path: " CONFIG_CTRL_IFACE_DIR "\n"
" default interface: first interface found in socket path\n");
print_help(NULL);
}
static int wpa_cli_show_event(const char *event)
{
const char *start;
start = os_strchr(event, '>');
if (start == NULL)
return 1;
start++;
/*
* Skip BSS added/removed events since they can be relatively frequent
* and are likely of not much use for an interactive user.
*/
if (str_starts(start, WPA_EVENT_BSS_ADDED) ||
str_starts(start, WPA_EVENT_BSS_REMOVED))
return 0;
return 1;
}
static int wpa_cli_open_connection(const char *ifname, int attach)
{
#if defined(CONFIG_CTRL_IFACE_UDP) || defined(CONFIG_CTRL_IFACE_NAMED_PIPE)
ctrl_conn = wpa_ctrl_open(ifname);
if (ctrl_conn == NULL)
return -1;
if (attach && interactive)
mon_conn = wpa_ctrl_open(ifname);
else
mon_conn = NULL;
#else /* CONFIG_CTRL_IFACE_UDP || CONFIG_CTRL_IFACE_NAMED_PIPE */
char *cfile = NULL;
int flen, res;
if (ifname == NULL)
return -1;
#ifdef ANDROID
if (access(ctrl_iface_dir, F_OK) < 0) {
cfile = os_strdup(ifname);
if (cfile == NULL)
return -1;
}
#endif /* ANDROID */
if (client_socket_dir && client_socket_dir[0] &&
access(client_socket_dir, F_OK) < 0) {
perror(client_socket_dir);
os_free(cfile);
return -1;
}
if (cfile == NULL) {
flen = os_strlen(ctrl_iface_dir) + os_strlen(ifname) + 2;
cfile = os_malloc(flen);
if (cfile == NULL)
return -1;
res = os_snprintf(cfile, flen, "%s/%s", ctrl_iface_dir,
ifname);
if (os_snprintf_error(flen, res)) {
os_free(cfile);
return -1;
}
}
ctrl_conn = wpa_ctrl_open2(cfile, client_socket_dir);
if (ctrl_conn == NULL) {
os_free(cfile);
return -1;
}
if (attach && interactive)
mon_conn = wpa_ctrl_open2(cfile, client_socket_dir);
else
mon_conn = NULL;
os_free(cfile);
#endif /* CONFIG_CTRL_IFACE_UDP || CONFIG_CTRL_IFACE_NAMED_PIPE */
if (mon_conn) {
if (wpa_ctrl_attach(mon_conn) == 0) {
wpa_cli_attached = 1;
if (interactive)
eloop_register_read_sock(
wpa_ctrl_get_fd(mon_conn),
wpa_cli_mon_receive, NULL, NULL);
} else {
printf("Warning: Failed to attach to "
"wpa_supplicant.\n");
wpa_cli_close_connection();
return -1;
}
}
return 0;
}
static void wpa_cli_close_connection(void)
{
if (ctrl_conn == NULL)
return;
if (wpa_cli_attached) {
wpa_ctrl_detach(interactive ? mon_conn : ctrl_conn);
wpa_cli_attached = 0;
}
wpa_ctrl_close(ctrl_conn);
ctrl_conn = NULL;
if (mon_conn) {
eloop_unregister_read_sock(wpa_ctrl_get_fd(mon_conn));
wpa_ctrl_close(mon_conn);
mon_conn = NULL;
}
}
static void wpa_cli_msg_cb(char *msg, size_t len)
{
printf("%s\n", msg);
}
static int _wpa_ctrl_command(struct wpa_ctrl *ctrl, const char *cmd, int print)
{
char buf[4096];
size_t len;
int ret;
if (ctrl_conn == NULL) {
printf("Not connected to wpa_supplicant - command dropped.\n");
return -1;
}
if (ifname_prefix) {
os_snprintf(buf, sizeof(buf), "IFNAME=%s %s",
ifname_prefix, cmd);
buf[sizeof(buf) - 1] = '\0';
cmd = buf;
}
len = sizeof(buf) - 1;
ret = wpa_ctrl_request(ctrl, cmd, os_strlen(cmd), buf, &len,
wpa_cli_msg_cb);
if (ret == -2) {
printf("'%s' command timed out.\n", cmd);
return -2;
} else if (ret < 0) {
printf("'%s' command failed.\n", cmd);
return -1;
}
if (print) {
buf[len] = '\0';
printf("%s", buf);
if (interactive && len > 0 && buf[len - 1] != '\n')
printf("\n");
}
return 0;
}
static int wpa_ctrl_command(struct wpa_ctrl *ctrl, const char *cmd)
{
return _wpa_ctrl_command(ctrl, cmd, 1);
}
static int wpa_cli_cmd(struct wpa_ctrl *ctrl, const char *cmd, int min_args,
int argc, char *argv[])
{
char buf[4096];
if (argc < min_args) {
printf("Invalid %s command - at least %d argument%s "
"required.\n", cmd, min_args,
min_args > 1 ? "s are" : " is");
return -1;
}
if (write_cmd(buf, sizeof(buf), cmd, argc, argv) < 0)
return -1;
return wpa_ctrl_command(ctrl, buf);
}
static int wpa_cli_cmd_ifname(struct wpa_ctrl *ctrl, int argc, char *argv[])
{
return wpa_ctrl_command(ctrl, "IFNAME");
}
static int wpa_cli_cmd_status(struct wpa_ctrl *ctrl, int argc, char *argv[])
{
if (argc > 0 && os_strcmp(argv[0], "verbose") == 0)
return wpa_ctrl_command(ctrl, "STATUS-VERBOSE");
if (argc > 0 && os_strcmp(argv[0], "wps") == 0)
return wpa_ctrl_command(ctrl, "STATUS-WPS");
if (argc > 0 && os_strcmp(argv[0], "driver") == 0)
return wpa_ctrl_command(ctrl, "STATUS-DRIVER");
#ifdef ANDROID
if (argc > 0 && os_strcmp(argv[0], "no_events") == 0)
return wpa_ctrl_command(ctrl, "STATUS-NO_EVENTS");
#endif /* ANDROID */
return wpa_ctrl_command(ctrl, "STATUS");
}
static int wpa_cli_cmd_ping(struct wpa_ctrl *ctrl, int argc, char *argv[])
{
return wpa_ctrl_command(ctrl, "PING");
}
static int wpa_cli_cmd_relog(struct wpa_ctrl *ctrl, int argc, char *argv[])
{
return wpa_ctrl_command(ctrl, "RELOG");
}
static int wpa_cli_cmd_note(struct wpa_ctrl *ctrl, int argc, char *argv[])
{
return wpa_cli_cmd(ctrl, "NOTE", 1, argc, argv);
}
static int wpa_cli_cmd_mib(struct wpa_ctrl *ctrl, int argc, char *argv[])
{
return wpa_ctrl_command(ctrl, "MIB");
}
static int wpa_cli_cmd_pmksa(struct wpa_ctrl *ctrl, int argc, char *argv[])
{
return wpa_ctrl_command(ctrl, "PMKSA");
}
static int wpa_cli_cmd_pmksa_flush(struct wpa_ctrl *ctrl, int argc,
char *argv[])
{
return wpa_ctrl_command(ctrl, "PMKSA_FLUSH");
}
#ifdef CONFIG_PMKSA_CACHE_EXTERNAL
static int wpa_cli_cmd_pmksa_get(struct wpa_ctrl *ctrl, int argc, char *argv[])
{
return wpa_cli_cmd(ctrl, "PMKSA_GET", 1, argc, argv);
}
static int wpa_cli_cmd_pmksa_add(struct wpa_ctrl *ctrl, int argc, char *argv[])
{
return wpa_cli_cmd(ctrl, "PMKSA_ADD", 8, argc, argv);
}
#ifdef CONFIG_MESH
static int wpa_cli_mesh_cmd_pmksa_get(struct wpa_ctrl *ctrl, int argc,
char *argv[])
{
return wpa_cli_cmd(ctrl, "MESH_PMKSA_GET", 1, argc, argv);
}
static int wpa_cli_mesh_cmd_pmksa_add(struct wpa_ctrl *ctrl, int argc,
char *argv[])
{
return wpa_cli_cmd(ctrl, "MESH_PMKSA_ADD", 4, argc, argv);
}
#endif /* CONFIG_MESH */
#endif /* CONFIG_PMKSA_CACHE_EXTERNAL */
static int wpa_cli_cmd_help(struct wpa_ctrl *ctrl, int argc, char *argv[])
{
print_help(argc > 0 ? argv[0] : NULL);
return 0;
}
static char ** wpa_cli_complete_help(const char *str, int pos)
{
int arg = get_cmd_arg_num(str, pos);
char **res = NULL;
switch (arg) {
case 1:
res = wpa_list_cmd_list();
break;
}
return res;
}
static int wpa_cli_cmd_license(struct wpa_ctrl *ctrl, int argc, char *argv[])
{
printf("%s\n\n%s\n", wpa_cli_version, cli_full_license);
return 0;
}
static int wpa_cli_cmd_quit(struct wpa_ctrl *ctrl, int argc, char *argv[])
{
wpa_cli_quit = 1;
if (interactive)
eloop_terminate();
return 0;
}
static int wpa_cli_cmd_set(struct wpa_ctrl *ctrl, int argc, char *argv[])
{
char cmd[256];
int res;
if (argc == 1) {
res = os_snprintf(cmd, sizeof(cmd), "SET %s ", argv[0]);
if (os_snprintf_error(sizeof(cmd), res)) {
printf("Too long SET command.\n");
return -1;
}
return wpa_ctrl_command(ctrl, cmd);
}
return wpa_cli_cmd(ctrl, "SET", 2, argc, argv);
}
static char ** wpa_cli_complete_set(const char *str, int pos)
{
int arg = get_cmd_arg_num(str, pos);
const char *fields[] = {
/* runtime values */
"EAPOL::heldPeriod", "EAPOL::authPeriod", "EAPOL::startPeriod",
"EAPOL::maxStart", "dot11RSNAConfigPMKLifetime",
"dot11RSNAConfigPMKReauthThreshold", "dot11RSNAConfigSATimeout",
"wps_fragment_size", "wps_version_number", "ampdu",
"tdls_testing", "tdls_disabled", "pno", "radio_disabled",
"uapsd", "ps", "wifi_display", "bssid_filter", "disallow_aps",
"no_keep_alive",
/* global configuration parameters */
#ifdef CONFIG_CTRL_IFACE
"ctrl_interface", "no_ctrl_interface", "ctrl_interface_group",
#endif /* CONFIG_CTRL_IFACE */
"eapol_version", "ap_scan", "bgscan",
#ifdef CONFIG_MESH
"user_mpm", "max_peer_links", "mesh_max_inactivity",
"dot11RSNASAERetransPeriod",
#endif /* CONFIG_MESH */
"disable_scan_offload", "fast_reauth", "opensc_engine_path",
"pkcs11_engine_path", "pkcs11_module_path", "openssl_ciphers",
"pcsc_reader", "pcsc_pin", "external_sim", "driver_param",
"dot11RSNAConfigPMKLifetime",
"dot11RSNAConfigPMKReauthThreshold",
"dot11RSNAConfigSATimeout",
#ifndef CONFIG_NO_CONFIG_WRITE
"update_config",
#endif /* CONFIG_NO_CONFIG_WRITE */
"load_dynamic_eap",
#ifdef CONFIG_WPS
"uuid", "device_name", "manufacturer", "model_name",
"model_number", "serial_number", "device_type", "os_version",
"config_methods", "wps_cred_processing", "wps_vendor_ext_m1",
#endif /* CONFIG_WPS */
#ifdef CONFIG_P2P
"sec_device_type",
"p2p_listen_reg_class", "p2p_listen_channel",
"p2p_oper_reg_class", "p2p_oper_channel", "p2p_go_intent",
"p2p_ssid_postfix", "persistent_reconnect", "p2p_intra_bss",
"p2p_group_idle", "p2p_passphrase_len", "p2p_pref_chan",
"p2p_no_go_freq", "p2p_add_cli_chan",
"p2p_optimize_listen_chan", "p2p_go_ht40", "p2p_go_vht",
"p2p_disabled", "p2p_go_ctwindow", "p2p_no_group_iface",
"p2p_ignore_shared_freq", "ip_addr_go", "ip_addr_mask",
"ip_addr_start", "ip_addr_end",
#endif /* CONFIG_P2P */
"country", "bss_max_count", "bss_expiration_age",
"bss_expiration_scan_count", "filter_ssids", "filter_rssi",
"max_num_sta", "disassoc_low_ack", "ap_isolate",
#ifdef CONFIG_HS20
"hs20",
#endif /* CONFIG_HS20 */
"interworking", "hessid", "access_network_type", "pbc_in_m1",
"go_interworking", "go_access_network_type", "go_internet",
"go_venue_group", "go_venue_type",
"autoscan", "wps_nfc_dev_pw_id", "wps_nfc_dh_pubkey",
"wps_nfc_dh_privkey", "wps_nfc_dev_pw", "ext_password_backend",
"p2p_go_max_inactivity", "auto_interworking", "okc", "pmf",
"sae_groups", "dtim_period", "beacon_int",
"ap_vendor_elements", "ignore_old_scan_res", "freq_list",
"scan_cur_freq", "sched_scan_interval",
"tdls_external_control", "osu_dir", "wowlan_triggers",
"p2p_search_delay", "mac_addr", "rand_addr_lifetime",
"preassoc_mac_addr", "key_mgmt_offload", "passive_scan",
"reassoc_same_bss_optim", "wps_priority",
#ifdef CONFIG_TESTING_OPTIONS
"ignore_auth_resp",
#endif /* CONFIG_TESTING_OPTIONS */
"relative_rssi", "relative_band_adjust",
};
int i, num_fields = ARRAY_SIZE(fields);
if (arg == 1) {
char **res = os_calloc(num_fields + 1, sizeof(char *));
if (res == NULL)
return NULL;
for (i = 0; i < num_fields; i++) {
res[i] = os_strdup(fields[i]);
if (res[i] == NULL)
return res;
}
return res;
}
if (arg > 1 && os_strncasecmp(str, "set bssid_filter ", 17) == 0)
return cli_txt_list_array(&bsses);
return NULL;
}
static int wpa_cli_cmd_dump(struct wpa_ctrl *ctrl, int argc, char *argv[])
{
return wpa_ctrl_command(ctrl, "DUMP");
}
static int wpa_cli_cmd_driver_flags(struct wpa_ctrl *ctrl, int argc,
char *argv[])
{
return wpa_ctrl_command(ctrl, "DRIVER_FLAGS");
}
static int wpa_cli_cmd_get(struct wpa_ctrl *ctrl, int argc, char *argv[])
{
return wpa_cli_cmd(ctrl, "GET", 1, argc, argv);
}
static char ** wpa_cli_complete_get(const char *str, int pos)
{
int arg = get_cmd_arg_num(str, pos);
const char *fields[] = {
#ifdef CONFIG_CTRL_IFACE
"ctrl_interface", "ctrl_interface_group",
#endif /* CONFIG_CTRL_IFACE */
"eapol_version", "ap_scan",
#ifdef CONFIG_MESH
"user_mpm", "max_peer_links", "mesh_max_inactivity",
#endif /* CONFIG_MESH */
"disable_scan_offload", "fast_reauth", "opensc_engine_path",
"pkcs11_engine_path", "pkcs11_module_path", "openssl_ciphers",
"pcsc_reader", "pcsc_pin", "external_sim", "driver_param",
"dot11RSNAConfigPMKLifetime",
"dot11RSNAConfigPMKReauthThreshold",
"dot11RSNAConfigSATimeout",
#ifndef CONFIG_NO_CONFIG_WRITE
"update_config",
#endif /* CONFIG_NO_CONFIG_WRITE */
#ifdef CONFIG_WPS
"device_name", "manufacturer", "model_name", "model_number",
"serial_number", "config_methods", "wps_cred_processing",
#endif /* CONFIG_WPS */
#ifdef CONFIG_P2P
"p2p_listen_reg_class", "p2p_listen_channel",
"p2p_oper_reg_class", "p2p_oper_channel", "p2p_go_intent",
"p2p_ssid_postfix", "persistent_reconnect", "p2p_intra_bss",
"p2p_group_idle", "p2p_passphrase_len", "p2p_add_cli_chan",
"p2p_optimize_listen_chan", "p2p_go_ht40", "p2p_go_vht",
"p2p_disabled", "p2p_go_ctwindow", "p2p_no_group_iface",
"p2p_ignore_shared_freq", "ip_addr_go", "ip_addr_mask",
"ip_addr_start", "ip_addr_end",
#endif /* CONFIG_P2P */
"bss_max_count", "bss_expiration_age",
"bss_expiration_scan_count", "filter_ssids", "filter_rssi",
"max_num_sta", "disassoc_low_ack", "ap_isolate",
#ifdef CONFIG_HS20
"hs20",
#endif /* CONFIG_HS20 */
"interworking", "access_network_type", "pbc_in_m1", "autoscan",
"go_interworking", "go_access_network_type", "go_internet",
"go_venue_group", "go_venue_type",
"wps_nfc_dev_pw_id", "ext_password_backend",
"p2p_go_max_inactivity", "auto_interworking", "okc", "pmf",
"dtim_period", "beacon_int", "ignore_old_scan_res",
"scan_cur_freq", "sched_scan_interval",
"sched_scan_start_delay",
"tdls_external_control", "osu_dir", "wowlan_triggers",
"p2p_search_delay", "mac_addr", "rand_addr_lifetime",
"preassoc_mac_addr", "key_mgmt_offload", "passive_scan",
"reassoc_same_bss_optim"
};
int i, num_fields = ARRAY_SIZE(fields);
if (arg == 1) {
char **res = os_calloc(num_fields + 1, sizeof(char *));
if (res == NULL)
return NULL;
for (i = 0; i < num_fields; i++) {
res[i] = os_strdup(fields[i]);
if (res[i] == NULL)
return res;
}
return res;
}
return NULL;
}
static int wpa_cli_cmd_logoff(struct wpa_ctrl *ctrl, int argc, char *argv[])
{
return wpa_ctrl_command(ctrl, "LOGOFF");
}
static int wpa_cli_cmd_logon(struct wpa_ctrl *ctrl, int argc, char *argv[])
{
return wpa_ctrl_command(ctrl, "LOGON");
}
static int wpa_cli_cmd_reassociate(struct wpa_ctrl *ctrl, int argc,
char *argv[])
{
return wpa_ctrl_command(ctrl, "REASSOCIATE");
}
static int wpa_cli_cmd_reattach(struct wpa_ctrl *ctrl, int argc, char *argv[])
{
return wpa_ctrl_command(ctrl, "REATTACH");
}
static int wpa_cli_cmd_preauthenticate(struct wpa_ctrl *ctrl, int argc,
char *argv[])
{
return wpa_cli_cmd(ctrl, "PREAUTH", 1, argc, argv);
}
static int wpa_cli_cmd_ap_scan(struct wpa_ctrl *ctrl, int argc, char *argv[])
{
return wpa_cli_cmd(ctrl, "AP_SCAN", 1, argc, argv);
}
static int wpa_cli_cmd_scan_interval(struct wpa_ctrl *ctrl, int argc,
char *argv[])
{
return wpa_cli_cmd(ctrl, "SCAN_INTERVAL", 1, argc, argv);
}
static int wpa_cli_cmd_bss_expire_age(struct wpa_ctrl *ctrl, int argc,
char *argv[])
{
return wpa_cli_cmd(ctrl, "BSS_EXPIRE_AGE", 1, argc, argv);
}
static int wpa_cli_cmd_bss_expire_count(struct wpa_ctrl *ctrl, int argc,
char *argv[])
{
return wpa_cli_cmd(ctrl, "BSS_EXPIRE_COUNT", 1, argc, argv);
}
static int wpa_cli_cmd_bss_flush(struct wpa_ctrl *ctrl, int argc, char *argv[])
{
char cmd[256];
int res;
if (argc < 1)
res = os_snprintf(cmd, sizeof(cmd), "BSS_FLUSH 0");
else
res = os_snprintf(cmd, sizeof(cmd), "BSS_FLUSH %s", argv[0]);
if (os_snprintf_error(sizeof(cmd), res)) {
printf("Too long BSS_FLUSH command.\n");
return -1;
}
return wpa_ctrl_command(ctrl, cmd);
}
static int wpa_cli_cmd_ft_ds(struct wpa_ctrl *ctrl, int argc, char *argv[])
{
return wpa_cli_cmd(ctrl, "FT_DS", 1, argc, argv);
}
static int wpa_cli_cmd_wps_pbc(struct wpa_ctrl *ctrl, int argc, char *argv[])
{
return wpa_cli_cmd(ctrl, "WPS_PBC", 0, argc, argv);
}
static int wpa_cli_cmd_wps_pin(struct wpa_ctrl *ctrl, int argc, char *argv[])
{
if (argc == 0) {
printf("Invalid WPS_PIN command: need one or two arguments:\n"
"- BSSID: use 'any' to select any\n"
"- PIN: optional, used only with devices that have no "
"display\n");
return -1;
}
return wpa_cli_cmd(ctrl, "WPS_PIN", 1, argc, argv);
}
static int wpa_cli_cmd_wps_check_pin(struct wpa_ctrl *ctrl, int argc,
char *argv[])
{
return wpa_cli_cmd(ctrl, "WPS_CHECK_PIN", 1, argc, argv);
}
static int wpa_cli_cmd_wps_cancel(struct wpa_ctrl *ctrl, int argc,
char *argv[])
{
return wpa_ctrl_command(ctrl, "WPS_CANCEL");
}
#ifdef CONFIG_WPS_NFC
static int wpa_cli_cmd_wps_nfc(struct wpa_ctrl *ctrl, int argc, char *argv[])
{
return wpa_cli_cmd(ctrl, "WPS_NFC", 0, argc, argv);
}
static int wpa_cli_cmd_wps_nfc_config_token(struct wpa_ctrl *ctrl, int argc,
char *argv[])
{
return wpa_cli_cmd(ctrl, "WPS_NFC_CONFIG_TOKEN", 1, argc, argv);
}
static int wpa_cli_cmd_wps_nfc_token(struct wpa_ctrl *ctrl, int argc,
char *argv[])
{
return wpa_cli_cmd(ctrl, "WPS_NFC_TOKEN", 1, argc, argv);
}
static int wpa_cli_cmd_wps_nfc_tag_read(struct wpa_ctrl *ctrl, int argc,
char *argv[])
{
int ret;
char *buf;
size_t buflen;
if (argc != 1) {
printf("Invalid 'wps_nfc_tag_read' command - one argument "
"is required.\n");
return -1;
}
buflen = 18 + os_strlen(argv[0]);
buf = os_malloc(buflen);
if (buf == NULL)
return -1;
os_snprintf(buf, buflen, "WPS_NFC_TAG_READ %s", argv[0]);
ret = wpa_ctrl_command(ctrl, buf);
os_free(buf);
return ret;
}
static int wpa_cli_cmd_nfc_get_handover_req(struct wpa_ctrl *ctrl, int argc,
char *argv[])
{
return wpa_cli_cmd(ctrl, "NFC_GET_HANDOVER_REQ", 2, argc, argv);
}
static int wpa_cli_cmd_nfc_get_handover_sel(struct wpa_ctrl *ctrl, int argc,
char *argv[])
{
return wpa_cli_cmd(ctrl, "NFC_GET_HANDOVER_SEL", 2, argc, argv);
}
static int wpa_cli_cmd_nfc_report_handover(struct wpa_ctrl *ctrl, int argc,
char *argv[])
{
return wpa_cli_cmd(ctrl, "NFC_REPORT_HANDOVER", 4, argc, argv);
}
#endif /* CONFIG_WPS_NFC */
static int wpa_cli_cmd_wps_reg(struct wpa_ctrl *ctrl, int argc, char *argv[])
{
char cmd[256];
int res;
if (argc == 2)
res = os_snprintf(cmd, sizeof(cmd), "WPS_REG %s %s",
argv[0], argv[1]);
else if (argc == 5 || argc == 6) {
char ssid_hex[2 * SSID_MAX_LEN + 1];
char key_hex[2 * 64 + 1];
int i;
ssid_hex[0] = '\0';
for (i = 0; i < SSID_MAX_LEN; i++) {
if (argv[2][i] == '\0')
break;
os_snprintf(&ssid_hex[i * 2], 3, "%02x", argv[2][i]);
}
key_hex[0] = '\0';
if (argc == 6) {
for (i = 0; i < 64; i++) {
if (argv[5][i] == '\0')
break;
os_snprintf(&key_hex[i * 2], 3, "%02x",
argv[5][i]);
}
}
res = os_snprintf(cmd, sizeof(cmd),
"WPS_REG %s %s %s %s %s %s",
argv[0], argv[1], ssid_hex, argv[3], argv[4],
key_hex);
} else {
printf("Invalid WPS_REG command: need two arguments:\n"
"- BSSID of the target AP\n"
"- AP PIN\n");
printf("Alternatively, six arguments can be used to "
"reconfigure the AP:\n"
"- BSSID of the target AP\n"
"- AP PIN\n"
"- new SSID\n"
"- new auth (OPEN, WPAPSK, WPA2PSK)\n"
"- new encr (NONE, WEP, TKIP, CCMP)\n"
"- new key\n");
return -1;
}
if (os_snprintf_error(sizeof(cmd), res)) {
printf("Too long WPS_REG command.\n");
return -1;
}
return wpa_ctrl_command(ctrl, cmd);
}
static int wpa_cli_cmd_wps_ap_pin(struct wpa_ctrl *ctrl, int argc,
char *argv[])
{
return wpa_cli_cmd(ctrl, "WPS_AP_PIN", 1, argc, argv);
}
static int wpa_cli_cmd_wps_er_start(struct wpa_ctrl *ctrl, int argc,
char *argv[])
{
return wpa_cli_cmd(ctrl, "WPS_ER_START", 0, argc, argv);
}
static int wpa_cli_cmd_wps_er_stop(struct wpa_ctrl *ctrl, int argc,
char *argv[])
{
return wpa_ctrl_command(ctrl, "WPS_ER_STOP");
}
static int wpa_cli_cmd_wps_er_pin(struct wpa_ctrl *ctrl, int argc,
char *argv[])
{
if (argc < 2) {
printf("Invalid WPS_ER_PIN command: need at least two "
"arguments:\n"
"- UUID: use 'any' to select any\n"
"- PIN: Enrollee PIN\n"
"optional: - Enrollee MAC address\n");
return -1;
}
return wpa_cli_cmd(ctrl, "WPS_ER_PIN", 2, argc, argv);
}
static int wpa_cli_cmd_wps_er_pbc(struct wpa_ctrl *ctrl, int argc,
char *argv[])
{
return wpa_cli_cmd(ctrl, "WPS_ER_PBC", 1, argc, argv);
}
static int wpa_cli_cmd_wps_er_learn(struct wpa_ctrl *ctrl, int argc,
char *argv[])
{
if (argc != 2) {
printf("Invalid WPS_ER_LEARN command: need two arguments:\n"
"- UUID: specify which AP to use\n"
"- PIN: AP PIN\n");
return -1;
}
return wpa_cli_cmd(ctrl, "WPS_ER_LEARN", 2, argc, argv);
}
static int wpa_cli_cmd_wps_er_set_config(struct wpa_ctrl *ctrl, int argc,
char *argv[])
{
if (argc != 2) {
printf("Invalid WPS_ER_SET_CONFIG command: need two "
"arguments:\n"
"- UUID: specify which AP to use\n"
"- Network configuration id\n");
return -1;
}
return wpa_cli_cmd(ctrl, "WPS_ER_SET_CONFIG", 2, argc, argv);
}
static int wpa_cli_cmd_wps_er_config(struct wpa_ctrl *ctrl, int argc,
char *argv[])
{
char cmd[256];
int res;
if (argc == 5 || argc == 6) {
char ssid_hex[2 * SSID_MAX_LEN + 1];
char key_hex[2 * 64 + 1];
int i;
ssid_hex[0] = '\0';
for (i = 0; i < SSID_MAX_LEN; i++) {
if (argv[2][i] == '\0')
break;
os_snprintf(&ssid_hex[i * 2], 3, "%02x", argv[2][i]);
}
key_hex[0] = '\0';
if (argc == 6) {
for (i = 0; i < 64; i++) {
if (argv[5][i] == '\0')
break;
os_snprintf(&key_hex[i * 2], 3, "%02x",
argv[5][i]);
}
}
res = os_snprintf(cmd, sizeof(cmd),
"WPS_ER_CONFIG %s %s %s %s %s %s",
argv[0], argv[1], ssid_hex, argv[3], argv[4],
key_hex);
} else {
printf("Invalid WPS_ER_CONFIG command: need six arguments:\n"
"- AP UUID\n"
"- AP PIN\n"
"- new SSID\n"
"- new auth (OPEN, WPAPSK, WPA2PSK)\n"
"- new encr (NONE, WEP, TKIP, CCMP)\n"
"- new key\n");
return -1;
}
if (os_snprintf_error(sizeof(cmd), res)) {
printf("Too long WPS_ER_CONFIG command.\n");
return -1;
}
return wpa_ctrl_command(ctrl, cmd);
}
#ifdef CONFIG_WPS_NFC
static int wpa_cli_cmd_wps_er_nfc_config_token(struct wpa_ctrl *ctrl, int argc,
char *argv[])
{
if (argc != 2) {
printf("Invalid WPS_ER_NFC_CONFIG_TOKEN command: need two "
"arguments:\n"
"- WPS/NDEF: token format\n"
"- UUID: specify which AP to use\n");
return -1;
}
return wpa_cli_cmd(ctrl, "WPS_ER_NFC_CONFIG_TOKEN", 2, argc, argv);
}
#endif /* CONFIG_WPS_NFC */
static int wpa_cli_cmd_ibss_rsn(struct wpa_ctrl *ctrl, int argc, char *argv[])
{
return wpa_cli_cmd(ctrl, "IBSS_RSN", 1, argc, argv);
}
static int wpa_cli_cmd_level(struct wpa_ctrl *ctrl, int argc, char *argv[])
{
return wpa_cli_cmd(ctrl, "LEVEL", 1, argc, argv);
}
static int wpa_cli_cmd_identity(struct wpa_ctrl *ctrl, int argc, char *argv[])
{
char cmd[256], *pos, *end;
int i, ret;
if (argc < 2) {
printf("Invalid IDENTITY command: needs two arguments "
"(network id and identity)\n");
return -1;
}
end = cmd + sizeof(cmd);
pos = cmd;
ret = os_snprintf(pos, end - pos, WPA_CTRL_RSP "IDENTITY-%s:%s",
argv[0], argv[1]);
if (os_snprintf_error(end - pos, ret)) {
printf("Too long IDENTITY command.\n");
return -1;
}
pos += ret;
for (i = 2; i < argc; i++) {
ret = os_snprintf(pos, end - pos, " %s", argv[i]);
if (os_snprintf_error(end - pos, ret)) {
printf("Too long IDENTITY command.\n");
return -1;
}
pos += ret;
}
return wpa_ctrl_command(ctrl, cmd);
}
static int wpa_cli_cmd_password(struct wpa_ctrl *ctrl, int argc, char *argv[])
{
char cmd[256], *pos, *end;
int i, ret;
if (argc < 2) {
printf("Invalid PASSWORD command: needs two arguments "
"(network id and password)\n");
return -1;
}
end = cmd + sizeof(cmd);
pos = cmd;
ret = os_snprintf(pos, end - pos, WPA_CTRL_RSP "PASSWORD-%s:%s",
argv[0], argv[1]);
if (os_snprintf_error(end - pos, ret)) {
printf("Too long PASSWORD command.\n");
return -1;
}
pos += ret;
for (i = 2; i < argc; i++) {
ret = os_snprintf(pos, end - pos, " %s", argv[i]);
if (os_snprintf_error(end - pos, ret)) {
printf("Too long PASSWORD command.\n");
return -1;
}
pos += ret;
}
return wpa_ctrl_command(ctrl, cmd);
}
static int wpa_cli_cmd_new_password(struct wpa_ctrl *ctrl, int argc,
char *argv[])
{
char cmd[256], *pos, *end;
int i, ret;
if (argc < 2) {
printf("Invalid NEW_PASSWORD command: needs two arguments "
"(network id and password)\n");
return -1;
}
end = cmd + sizeof(cmd);
pos = cmd;
ret = os_snprintf(pos, end - pos, WPA_CTRL_RSP "NEW_PASSWORD-%s:%s",
argv[0], argv[1]);
if (os_snprintf_error(end - pos, ret)) {
printf("Too long NEW_PASSWORD command.\n");
return -1;
}
pos += ret;
for (i = 2; i < argc; i++) {
ret = os_snprintf(pos, end - pos, " %s", argv[i]);
if (os_snprintf_error(end - pos, ret)) {
printf("Too long NEW_PASSWORD command.\n");
return -1;
}
pos += ret;
}
return wpa_ctrl_command(ctrl, cmd);
}
static int wpa_cli_cmd_pin(struct wpa_ctrl *ctrl, int argc, char *argv[])
{
char cmd[256], *pos, *end;
int i, ret;
if (argc < 2) {
printf("Invalid PIN command: needs two arguments "
"(network id and pin)\n");
return -1;
}
end = cmd + sizeof(cmd);
pos = cmd;
ret = os_snprintf(pos, end - pos, WPA_CTRL_RSP "PIN-%s:%s",
argv[0], argv[1]);
if (os_snprintf_error(end - pos, ret)) {
printf("Too long PIN command.\n");
return -1;
}
pos += ret;
for (i = 2; i < argc; i++) {
ret = os_snprintf(pos, end - pos, " %s", argv[i]);
if (os_snprintf_error(end - pos, ret)) {
printf("Too long PIN command.\n");
return -1;
}
pos += ret;
}
return wpa_ctrl_command(ctrl, cmd);
}
static int wpa_cli_cmd_otp(struct wpa_ctrl *ctrl, int argc, char *argv[])
{
char cmd[256], *pos, *end;
int i, ret;
if (argc < 2) {
printf("Invalid OTP command: needs two arguments (network "
"id and password)\n");
return -1;
}
end = cmd + sizeof(cmd);
pos = cmd;
ret = os_snprintf(pos, end - pos, WPA_CTRL_RSP "OTP-%s:%s",
argv[0], argv[1]);
if (os_snprintf_error(end - pos, ret)) {
printf("Too long OTP command.\n");
return -1;
}
pos += ret;
for (i = 2; i < argc; i++) {
ret = os_snprintf(pos, end - pos, " %s", argv[i]);
if (os_snprintf_error(end - pos, ret)) {
printf("Too long OTP command.\n");
return -1;
}
pos += ret;
}
return wpa_ctrl_command(ctrl, cmd);
}
static int wpa_cli_cmd_sim(struct wpa_ctrl *ctrl, int argc, char *argv[])
{
char cmd[256], *pos, *end;
int i, ret;
if (argc < 2) {
printf("Invalid SIM command: needs two arguments "
"(network id and SIM operation response)\n");
return -1;
}
end = cmd + sizeof(cmd);
pos = cmd;
ret = os_snprintf(pos, end - pos, WPA_CTRL_RSP "SIM-%s:%s",
argv[0], argv[1]);
if (os_snprintf_error(end - pos, ret)) {
printf("Too long SIM command.\n");
return -1;
}
pos += ret;
for (i = 2; i < argc; i++) {
ret = os_snprintf(pos, end - pos, " %s", argv[i]);
if (os_snprintf_error(end - pos, ret)) {
printf("Too long SIM command.\n");
return -1;
}
pos += ret;
}
return wpa_ctrl_command(ctrl, cmd);
}
static int wpa_cli_cmd_psk_passphrase(struct wpa_ctrl *ctrl, int argc,
char *argv[])
{
char cmd[256], *pos, *end;
int i, ret;
if (argc < 2) {
printf("Invalid PSK_PASSPHRASE command: needs two arguments (network id and PSK/passphrase)\n");
return -1;
}
end = cmd + sizeof(cmd);
pos = cmd;
ret = os_snprintf(pos, end - pos, WPA_CTRL_RSP "PSK_PASSPHRASE-%s:%s",
argv[0], argv[1]);
if (os_snprintf_error(end - pos, ret)) {
printf("Too long PSK_PASSPHRASE command.\n");
return -1;
}
pos += ret;
for (i = 2; i < argc; i++) {
ret = os_snprintf(pos, end - pos, " %s", argv[i]);
if (os_snprintf_error(end - pos, ret)) {
printf("Too long PSK_PASSPHRASE command.\n");
return -1;
}
pos += ret;
}
return wpa_ctrl_command(ctrl, cmd);
}
static int wpa_cli_cmd_passphrase(struct wpa_ctrl *ctrl, int argc,
char *argv[])
{
char cmd[256], *pos, *end;
int i, ret;
if (argc < 2) {
printf("Invalid PASSPHRASE command: needs two arguments "
"(network id and passphrase)\n");
return -1;
}
end = cmd + sizeof(cmd);
pos = cmd;
ret = os_snprintf(pos, end - pos, WPA_CTRL_RSP "PASSPHRASE-%s:%s",
argv[0], argv[1]);
if (os_snprintf_error(end - pos, ret)) {
printf("Too long PASSPHRASE command.\n");
return -1;
}
pos += ret;
for (i = 2; i < argc; i++) {
ret = os_snprintf(pos, end - pos, " %s", argv[i]);
if (os_snprintf_error(end - pos, ret)) {
printf("Too long PASSPHRASE command.\n");
return -1;
}
pos += ret;
}
return wpa_ctrl_command(ctrl, cmd);
}
static int wpa_cli_cmd_bssid(struct wpa_ctrl *ctrl, int argc, char *argv[])
{
if (argc < 2) {
printf("Invalid BSSID command: needs two arguments (network "
"id and BSSID)\n");
return -1;
}
return wpa_cli_cmd(ctrl, "BSSID", 2, argc, argv);
}
static int wpa_cli_cmd_blacklist(struct wpa_ctrl *ctrl, int argc, char *argv[])
{
return wpa_cli_cmd(ctrl, "BLACKLIST", 0, argc, argv);
}
static int wpa_cli_cmd_log_level(struct wpa_ctrl *ctrl, int argc, char *argv[])
{
return wpa_cli_cmd(ctrl, "LOG_LEVEL", 0, argc, argv);
}
static int wpa_cli_cmd_list_networks(struct wpa_ctrl *ctrl, int argc,
char *argv[])
{
return wpa_ctrl_command(ctrl, "LIST_NETWORKS");
}
static int wpa_cli_cmd_select_network(struct wpa_ctrl *ctrl, int argc,
char *argv[])
{
return wpa_cli_cmd(ctrl, "SELECT_NETWORK", 1, argc, argv);
}
static int wpa_cli_cmd_enable_network(struct wpa_ctrl *ctrl, int argc,
char *argv[])
{
return wpa_cli_cmd(ctrl, "ENABLE_NETWORK", 1, argc, argv);
}
static int wpa_cli_cmd_disable_network(struct wpa_ctrl *ctrl, int argc,
char *argv[])
{
return wpa_cli_cmd(ctrl, "DISABLE_NETWORK", 1, argc, argv);
}
static int wpa_cli_cmd_add_network(struct wpa_ctrl *ctrl, int argc,
char *argv[])
{
int res = wpa_ctrl_command(ctrl, "ADD_NETWORK");
if (interactive)
update_networks(ctrl);
return res;
}
static int wpa_cli_cmd_remove_network(struct wpa_ctrl *ctrl, int argc,
char *argv[])
{
int res = wpa_cli_cmd(ctrl, "REMOVE_NETWORK", 1, argc, argv);
if (interactive)
update_networks(ctrl);
return res;
}
static void wpa_cli_show_network_variables(void)
{
printf("set_network variables:\n"
" ssid (network name, SSID)\n"
" psk (WPA passphrase or pre-shared key)\n"
" key_mgmt (key management protocol)\n"
" identity (EAP identity)\n"
" password (EAP password)\n"
" ...\n"
"\n"
"Note: Values are entered in the same format as the "
"configuration file is using,\n"
"i.e., strings values need to be inside double quotation "
"marks.\n"
"For example: set_network 1 ssid \"network name\"\n"
"\n"
"Please see wpa_supplicant.conf documentation for full list "
"of\navailable variables.\n");
}
static int wpa_cli_cmd_set_network(struct wpa_ctrl *ctrl, int argc,
char *argv[])
{
if (argc == 0) {
wpa_cli_show_network_variables();
return 0;
}
if (argc < 3) {
printf("Invalid SET_NETWORK command: needs three arguments\n"
"(network id, variable name, and value)\n");
return -1;
}
return wpa_cli_cmd(ctrl, "SET_NETWORK", 3, argc, argv);
}
static int wpa_cli_cmd_get_network(struct wpa_ctrl *ctrl, int argc,
char *argv[])
{
if (argc == 0) {
wpa_cli_show_network_variables();
return 0;
}
if (argc != 2) {
printf("Invalid GET_NETWORK command: needs two arguments\n"
"(network id and variable name)\n");
return -1;
}
return wpa_cli_cmd(ctrl, "GET_NETWORK", 2, argc, argv);
}
static const char *network_fields[] = {
"ssid", "scan_ssid", "bssid", "bssid_blacklist",
"bssid_whitelist", "psk", "proto", "key_mgmt",
"bg_scan_period", "pairwise", "group", "auth_alg", "scan_freq",
"freq_list", "max_oper_chwidth", "ht40", "vht", "vht_center_freq1",
"vht_center_freq2", "ht",
#ifdef IEEE8021X_EAPOL
"eap", "identity", "anonymous_identity", "password", "ca_cert",
"ca_path", "client_cert", "private_key", "private_key_passwd",
"dh_file", "subject_match", "altsubject_match",
"check_cert_subject",
"domain_suffix_match", "domain_match", "ca_cert2", "ca_path2",
"client_cert2", "private_key2", "private_key2_passwd",
"dh_file2", "subject_match2", "altsubject_match2",
"check_cert_subject2",
"domain_suffix_match2", "domain_match2", "phase1", "phase2",
"pcsc", "pin", "engine_id", "key_id", "cert_id", "ca_cert_id",
"pin2", "engine2_id", "key2_id", "cert2_id", "ca_cert2_id",
"engine", "engine2", "eapol_flags", "sim_num",
"openssl_ciphers", "erp",
#endif /* IEEE8021X_EAPOL */
"wep_key0", "wep_key1", "wep_key2", "wep_key3",
"wep_tx_keyidx", "priority",
#ifdef IEEE8021X_EAPOL
"eap_workaround", "pac_file", "fragment_size", "ocsp",
#endif /* IEEE8021X_EAPOL */
#ifdef CONFIG_MESH
"mode", "no_auto_peer", "mesh_rssi_threshold",
#else /* CONFIG_MESH */
"mode",
#endif /* CONFIG_MESH */
"proactive_key_caching", "disabled", "id_str",
#ifdef CONFIG_IEEE80211W
"ieee80211w",
#endif /* CONFIG_IEEE80211W */
"mixed_cell", "frequency", "fixed_freq",
#ifdef CONFIG_MESH
"mesh_basic_rates", "dot11MeshMaxRetries",
"dot11MeshRetryTimeout", "dot11MeshConfirmTimeout",
"dot11MeshHoldingTimeout",
#endif /* CONFIG_MESH */
"wpa_ptk_rekey", "bgscan", "ignore_broadcast_ssid",
#ifdef CONFIG_P2P
"go_p2p_dev_addr", "p2p_client_list", "psk_list",
#endif /* CONFIG_P2P */
#ifdef CONFIG_HT_OVERRIDES
"disable_ht", "disable_ht40", "disable_sgi", "disable_ldpc",
"ht40_intolerant", "disable_max_amsdu", "ampdu_factor",
"ampdu_density", "ht_mcs", "rx_stbc", "tx_stbc",
#endif /* CONFIG_HT_OVERRIDES */
#ifdef CONFIG_VHT_OVERRIDES
"disable_vht", "vht_capa", "vht_capa_mask", "vht_rx_mcs_nss_1",
"vht_rx_mcs_nss_2", "vht_rx_mcs_nss_3", "vht_rx_mcs_nss_4",
"vht_rx_mcs_nss_5", "vht_rx_mcs_nss_6", "vht_rx_mcs_nss_7",
"vht_rx_mcs_nss_8", "vht_tx_mcs_nss_1", "vht_tx_mcs_nss_2",
"vht_tx_mcs_nss_3", "vht_tx_mcs_nss_4", "vht_tx_mcs_nss_5",
"vht_tx_mcs_nss_6", "vht_tx_mcs_nss_7", "vht_tx_mcs_nss_8",
#endif /* CONFIG_VHT_OVERRIDES */
"ap_max_inactivity", "dtim_period", "beacon_int",
#ifdef CONFIG_MACSEC
"macsec_policy",
"macsec_integ_only",
"macsec_replay_protect",
"macsec_replay_window",
"macsec_port",
"mka_priority",
#endif /* CONFIG_MACSEC */
#ifdef CONFIG_HS20
"update_identifier",
#endif /* CONFIG_HS20 */
"mac_addr", "pbss", "wps_disabled"
};
static char ** wpa_cli_complete_network(const char *str, int pos)
{
int arg = get_cmd_arg_num(str, pos);
int i, num_fields = ARRAY_SIZE(network_fields);
char **res = NULL;
switch (arg) {
case 1:
res = cli_txt_list_array(&networks);
break;
case 2:
res = os_calloc(num_fields + 1, sizeof(char *));
if (res == NULL)
return NULL;
for (i = 0; i < num_fields; i++) {
res[i] = os_strdup(network_fields[i]);
if (res[i] == NULL)
break;
}
}
return res;
}
static char ** wpa_cli_complete_network_id(const char *str, int pos)
{
int arg = get_cmd_arg_num(str, pos);
if (arg == 1)
return cli_txt_list_array(&networks);
return NULL;
}
static int wpa_cli_cmd_dup_network(struct wpa_ctrl *ctrl, int argc,
char *argv[])
{
if (argc == 0) {
wpa_cli_show_network_variables();
return 0;
}
if (argc < 3) {
printf("Invalid DUP_NETWORK command: needs three arguments\n"
"(src netid, dest netid, and variable name)\n");
return -1;
}
return wpa_cli_cmd(ctrl, "DUP_NETWORK", 3, argc, argv);
}
static char ** wpa_cli_complete_dup_network(const char *str, int pos)
{
int arg = get_cmd_arg_num(str, pos);
int i, num_fields = ARRAY_SIZE(network_fields);
char **res = NULL;
switch (arg) {
case 1:
case 2:
res = cli_txt_list_array(&networks);
break;
case 3:
res = os_calloc(num_fields + 1, sizeof(char *));
if (res == NULL)
return NULL;
for (i = 0; i < num_fields; i++) {
res[i] = os_strdup(network_fields[i]);
if (res[i] == NULL)
break;
}
}
return res;
}
static int wpa_cli_cmd_list_creds(struct wpa_ctrl *ctrl, int argc,
char *argv[])
{
return wpa_ctrl_command(ctrl, "LIST_CREDS");
}
static int wpa_cli_cmd_add_cred(struct wpa_ctrl *ctrl, int argc, char *argv[])
{
int res = wpa_ctrl_command(ctrl, "ADD_CRED");
if (interactive)
update_creds(ctrl);
return res;
}
static int wpa_cli_cmd_remove_cred(struct wpa_ctrl *ctrl, int argc,
char *argv[])
{
int res = wpa_cli_cmd(ctrl, "REMOVE_CRED", 1, argc, argv);
if (interactive)
update_creds(ctrl);
return res;
}
static const char * const cred_fields[] = {
"temporary", "priority", "sp_priority", "pcsc", "eap",
"update_identifier", "min_dl_bandwidth_home", "min_ul_bandwidth_home",
"min_dl_bandwidth_roaming", "min_ul_bandwidth_roaming", "max_bss_load",
"req_conn_capab", "ocsp", "sim_num", "realm", "username", "password",
"ca_cert", "client_cert", "private_key", "private_key_passwd", "imsi",
"milenage", "domain_suffix_match", "domain", "phase1", "phase2",
"roaming_consortium", "required_roaming_consortium", "excluded_ssid",
"roaming_partner", "provisioning_sp"
};
static char ** wpa_cli_complete_cred(const char *str, int pos)
{
int arg = get_cmd_arg_num(str, pos);
int i, num_fields = ARRAY_SIZE(cred_fields);
char **res = NULL;
switch (arg) {
case 1:
res = cli_txt_list_array(&creds);
break;
case 2:
res = os_calloc(num_fields + 1, sizeof(char *));
if (res == NULL)
return NULL;
for (i = 0; i < num_fields; i++) {
res[i] = os_strdup(cred_fields[i]);
if (res[i] == NULL)
break;
}
}
return res;
}
static int wpa_cli_cmd_set_cred(struct wpa_ctrl *ctrl, int argc, char *argv[])
{
if (argc != 3) {
printf("Invalid SET_CRED command: needs three arguments\n"
"(cred id, variable name, and value)\n");
return -1;
}
return wpa_cli_cmd(ctrl, "SET_CRED", 3, argc, argv);
}
static int wpa_cli_cmd_get_cred(struct wpa_ctrl *ctrl, int argc, char *argv[])
{
if (argc != 2) {
printf("Invalid GET_CRED command: needs two arguments\n"
"(cred id, variable name)\n");
return -1;
}
return wpa_cli_cmd(ctrl, "GET_CRED", 2, argc, argv);
}
static int wpa_cli_cmd_disconnect(struct wpa_ctrl *ctrl, int argc,
char *argv[])
{
return wpa_ctrl_command(ctrl, "DISCONNECT");
}
static int wpa_cli_cmd_reconnect(struct wpa_ctrl *ctrl, int argc,
char *argv[])
{
return wpa_ctrl_command(ctrl, "RECONNECT");
}
static int wpa_cli_cmd_save_config(struct wpa_ctrl *ctrl, int argc,
char *argv[])
{
return wpa_ctrl_command(ctrl, "SAVE_CONFIG");
}
static int wpa_cli_cmd_scan(struct wpa_ctrl *ctrl, int argc, char *argv[])
{
return wpa_cli_cmd(ctrl, "SCAN", 0, argc, argv);
}
static int wpa_cli_cmd_scan_results(struct wpa_ctrl *ctrl, int argc,
char *argv[])
{
return wpa_ctrl_command(ctrl, "SCAN_RESULTS");
}
static int wpa_cli_cmd_abort_scan(struct wpa_ctrl *ctrl, int argc,
char *argv[])
{
return wpa_ctrl_command(ctrl, "ABORT_SCAN");
}
static int wpa_cli_cmd_bss(struct wpa_ctrl *ctrl, int argc, char *argv[])
{
return wpa_cli_cmd(ctrl, "BSS", 1, argc, argv);
}
static char ** wpa_cli_complete_bss(const char *str, int pos)
{
int arg = get_cmd_arg_num(str, pos);
char **res = NULL;
switch (arg) {
case 1:
res = cli_txt_list_array(&bsses);
break;
}
return res;
}
static int wpa_cli_cmd_get_capability(struct wpa_ctrl *ctrl, int argc,
char *argv[])
{
if (argc < 1 || argc > 2) {
printf("Invalid GET_CAPABILITY command: need either one or "
"two arguments\n");
return -1;
}
if ((argc == 2) && os_strcmp(argv[1], "strict") != 0) {
printf("Invalid GET_CAPABILITY command: second argument, "
"if any, must be 'strict'\n");
return -1;
}
return wpa_cli_cmd(ctrl, "GET_CAPABILITY", 1, argc, argv);
}
static char ** wpa_cli_complete_get_capability(const char *str, int pos)
{
int arg = get_cmd_arg_num(str, pos);
const char *fields[] = {
"eap", "pairwise", "group", "group_mgmt", "key_mgmt",
"proto", "auth_alg", "modes", "channels", "freq",
#ifdef CONFIG_TDLS
"tdls",
#endif /* CONFIG_TDLS */
#ifdef CONFIG_ERP
"erp",
#endif /* CONFIG_ERP */
#ifdef CONFIG_FIPS
"fips",
#endif /* CONFIG_FIPS */
#ifdef CONFIG_ACS
"acs",
#endif /* CONFIG_ACS */
};
int i, num_fields = ARRAY_SIZE(fields);
char **res = NULL;
if (arg == 1) {
res = os_calloc(num_fields + 1, sizeof(char *));
if (res == NULL)
return NULL;
for (i = 0; i < num_fields; i++) {
res[i] = os_strdup(fields[i]);
if (res[i] == NULL)
return res;
}
}
if (arg == 2) {
res = os_calloc(1 + 1, sizeof(char *));
if (res == NULL)
return NULL;
res[0] = os_strdup("strict");
}
return res;
}
static int wpa_cli_list_interfaces(struct wpa_ctrl *ctrl)
{
printf("Available interfaces:\n");
return wpa_ctrl_command(ctrl, "INTERFACES");
}
static int wpa_cli_cmd_interface(struct wpa_ctrl *ctrl, int argc, char *argv[])
{
if (argc < 1) {
wpa_cli_list_interfaces(ctrl);
return 0;
}
wpa_cli_close_connection();
os_free(ctrl_ifname);
ctrl_ifname = os_strdup(argv[0]);
if (!ctrl_ifname) {
printf("Failed to allocate memory\n");
return 0;
}
if (wpa_cli_open_connection(ctrl_ifname, 1) == 0) {
printf("Connected to interface '%s.\n", ctrl_ifname);
} else {
printf("Could not connect to interface '%s' - re-trying\n",
ctrl_ifname);
}
return 0;
}
static int wpa_cli_cmd_reconfigure(struct wpa_ctrl *ctrl, int argc,
char *argv[])
{
return wpa_ctrl_command(ctrl, "RECONFIGURE");
}
static int wpa_cli_cmd_terminate(struct wpa_ctrl *ctrl, int argc,
char *argv[])
{
return wpa_ctrl_command(ctrl, "TERMINATE");
}
static int wpa_cli_cmd_interface_add(struct wpa_ctrl *ctrl, int argc,
char *argv[])
{
char cmd[256];
int res;
if (argc < 1) {
printf("Invalid INTERFACE_ADD command: needs at least one "
"argument (interface name)\n"
"All arguments: ifname confname driver ctrl_interface "
"driver_param bridge_name [create]\n");
return -1;
}
/*
* INTERFACE_ADD <ifname>TAB<confname>TAB<driver>TAB<ctrl_interface>TAB
* <driver_param>TAB<bridge_name>[TAB<create>[TAB<type>]]
*/
res = os_snprintf(cmd, sizeof(cmd),
"INTERFACE_ADD %s\t%s\t%s\t%s\t%s\t%s\t%s\t%s",
argv[0],
argc > 1 ? argv[1] : "", argc > 2 ? argv[2] : "",
argc > 3 ? argv[3] : "", argc > 4 ? argv[4] : "",
argc > 5 ? argv[5] : "", argc > 6 ? argv[6] : "",
argc > 7 ? argv[7] : "");
if (os_snprintf_error(sizeof(cmd), res))
return -1;
cmd[sizeof(cmd) - 1] = '\0';
return wpa_ctrl_command(ctrl, cmd);
}
static int wpa_cli_cmd_interface_remove(struct wpa_ctrl *ctrl, int argc,
char *argv[])
{
return wpa_cli_cmd(ctrl, "INTERFACE_REMOVE", 1, argc, argv);
}
static int wpa_cli_cmd_interface_list(struct wpa_ctrl *ctrl, int argc,
char *argv[])
{
return wpa_ctrl_command(ctrl, "INTERFACE_LIST");
}
#ifdef CONFIG_AP
static int wpa_cli_cmd_sta(struct wpa_ctrl *ctrl, int argc, char *argv[])
{
return wpa_cli_cmd(ctrl, "STA", 1, argc, argv);
}
static char ** wpa_cli_complete_sta(const char *str, int pos)
{
int arg = get_cmd_arg_num(str, pos);
char **res = NULL;
switch (arg) {
case 1:
res = cli_txt_list_array(&stations);
break;
}
return res;
}
static int wpa_ctrl_command_sta(struct wpa_ctrl *ctrl, const char *cmd,
char *addr, size_t addr_len, int print)
{
char buf[4096], *pos;
size_t len;
int ret;
if (ctrl_conn == NULL) {
printf("Not connected to hostapd - command dropped.\n");
return -1;
}
if (ifname_prefix) {
os_snprintf(buf, sizeof(buf), "IFNAME=%s %s",
ifname_prefix, cmd);
buf[sizeof(buf) - 1] = '\0';
cmd = buf;
}
len = sizeof(buf) - 1;
ret = wpa_ctrl_request(ctrl, cmd, os_strlen(cmd), buf, &len,
wpa_cli_msg_cb);
if (ret == -2) {
printf("'%s' command timed out.\n", cmd);
return -2;
} else if (ret < 0) {
printf("'%s' command failed.\n", cmd);
return -1;
}
buf[len] = '\0';
if (os_memcmp(buf, "FAIL", 4) == 0 ||
os_memcmp(buf, "UNKNOWN COMMAND", 15) == 0)
return -1;
if (print)
printf("%s", buf);
pos = buf;
while (*pos != '\0' && *pos != '\n')
pos++;
*pos = '\0';
os_strlcpy(addr, buf, addr_len);
return 0;
}
static int wpa_cli_cmd_all_sta(struct wpa_ctrl *ctrl, int argc, char *argv[])
{
char addr[32], cmd[64];
if (wpa_ctrl_command_sta(ctrl, "STA-FIRST", addr, sizeof(addr), 1))
return 0;
do {
os_snprintf(cmd, sizeof(cmd), "STA-NEXT %s", addr);
} while (wpa_ctrl_command_sta(ctrl, cmd, addr, sizeof(addr), 1) == 0);
return -1;
}
static int wpa_cli_cmd_list_sta(struct wpa_ctrl *ctrl, int argc,
char *argv[])
{
char addr[32], cmd[64];
if (wpa_ctrl_command_sta(ctrl, "STA-FIRST", addr, sizeof(addr), 0))
return 0;
do {
if (os_strcmp(addr, "") != 0)
printf("%s\n", addr);
os_snprintf(cmd, sizeof(cmd), "STA-NEXT %s", addr);
} while (wpa_ctrl_command_sta(ctrl, cmd, addr, sizeof(addr), 0) == 0);
return 0;
}
static int wpa_cli_cmd_deauthenticate(struct wpa_ctrl *ctrl, int argc,
char *argv[])
{
return wpa_cli_cmd(ctrl, "DEAUTHENTICATE", 1, argc, argv);
}
static char ** wpa_cli_complete_deauthenticate(const char *str, int pos)
{
int arg = get_cmd_arg_num(str, pos);
char **res = NULL;
switch (arg) {
case 1:
res = cli_txt_list_array(&stations);
break;
}
return res;
}
static int wpa_cli_cmd_disassociate(struct wpa_ctrl *ctrl, int argc,
char *argv[])
{
return wpa_cli_cmd(ctrl, "DISASSOCIATE", 1, argc, argv);
}
static char ** wpa_cli_complete_disassociate(const char *str, int pos)
{
int arg = get_cmd_arg_num(str, pos);
char **res = NULL;
switch (arg) {
case 1:
res = cli_txt_list_array(&stations);
break;
}
return res;
}
static int wpa_cli_cmd_chanswitch(struct wpa_ctrl *ctrl, int argc,
char *argv[])
{
return wpa_cli_cmd(ctrl, "CHAN_SWITCH", 2, argc, argv);
}
#endif /* CONFIG_AP */
static int wpa_cli_cmd_suspend(struct wpa_ctrl *ctrl, int argc, char *argv[])
{
return wpa_ctrl_command(ctrl, "SUSPEND");
}
static int wpa_cli_cmd_resume(struct wpa_ctrl *ctrl, int argc, char *argv[])
{
return wpa_ctrl_command(ctrl, "RESUME");
}
#ifdef CONFIG_TESTING_OPTIONS
static int wpa_cli_cmd_drop_sa(struct wpa_ctrl *ctrl, int argc, char *argv[])
{
return wpa_ctrl_command(ctrl, "DROP_SA");
}
#endif /* CONFIG_TESTING_OPTIONS */
static int wpa_cli_cmd_roam(struct wpa_ctrl *ctrl, int argc, char *argv[])
{
return wpa_cli_cmd(ctrl, "ROAM", 1, argc, argv);
}
#ifdef CONFIG_MESH
static int wpa_cli_cmd_mesh_interface_add(struct wpa_ctrl *ctrl, int argc,
char *argv[])
{
return wpa_cli_cmd(ctrl, "MESH_INTERFACE_ADD", 0, argc, argv);
}
static int wpa_cli_cmd_mesh_group_add(struct wpa_ctrl *ctrl, int argc,
char *argv[])
{
return wpa_cli_cmd(ctrl, "MESH_GROUP_ADD", 1, argc, argv);
}
static int wpa_cli_cmd_mesh_group_remove(struct wpa_ctrl *ctrl, int argc,
char *argv[])
{
return wpa_cli_cmd(ctrl, "MESH_GROUP_REMOVE", 1, argc, argv);
}
static int wpa_cli_cmd_mesh_peer_remove(struct wpa_ctrl *ctrl, int argc,
char *argv[])
{
return wpa_cli_cmd(ctrl, "MESH_PEER_REMOVE", 1, argc, argv);
}
static int wpa_cli_cmd_mesh_peer_add(struct wpa_ctrl *ctrl, int argc,
char *argv[])
{
return wpa_cli_cmd(ctrl, "MESH_PEER_ADD", 1, argc, argv);
}
#endif /* CONFIG_MESH */
#ifdef CONFIG_P2P
static int wpa_cli_cmd_p2p_find(struct wpa_ctrl *ctrl, int argc, char *argv[])
{
return wpa_cli_cmd(ctrl, "P2P_FIND", 0, argc, argv);
}
static char ** wpa_cli_complete_p2p_find(const char *str, int pos)
{
char **res = NULL;
int arg = get_cmd_arg_num(str, pos);
res = os_calloc(6, sizeof(char *));
if (res == NULL)
return NULL;
res[0] = os_strdup("type=social");
if (res[0] == NULL) {
os_free(res);
return NULL;
}
res[1] = os_strdup("type=progressive");
if (res[1] == NULL)
return res;
res[2] = os_strdup("delay=");
if (res[2] == NULL)
return res;
res[3] = os_strdup("dev_id=");
if (res[3] == NULL)
return res;
if (arg == 1)
res[4] = os_strdup("[timeout]");
return res;
}
static int wpa_cli_cmd_p2p_stop_find(struct wpa_ctrl *ctrl, int argc,
char *argv[])
{
return wpa_ctrl_command(ctrl, "P2P_STOP_FIND");
}
static int wpa_cli_cmd_p2p_asp_provision(struct wpa_ctrl *ctrl, int argc,
char *argv[])
{
return wpa_cli_cmd(ctrl, "P2P_ASP_PROVISION", 3, argc, argv);
}
static int wpa_cli_cmd_p2p_asp_provision_resp(struct wpa_ctrl *ctrl, int argc,
char *argv[])
{
return wpa_cli_cmd(ctrl, "P2P_ASP_PROVISION_RESP", 2, argc, argv);
}
static int wpa_cli_cmd_p2p_connect(struct wpa_ctrl *ctrl, int argc,
char *argv[])
{
return wpa_cli_cmd(ctrl, "P2P_CONNECT", 2, argc, argv);
}
static char ** wpa_cli_complete_p2p_connect(const char *str, int pos)
{
int arg = get_cmd_arg_num(str, pos);
char **res = NULL;
switch (arg) {
case 1:
res = cli_txt_list_array(&p2p_peers);
break;
}
return res;
}
static int wpa_cli_cmd_p2p_listen(struct wpa_ctrl *ctrl, int argc,
char *argv[])
{
return wpa_cli_cmd(ctrl, "P2P_LISTEN", 0, argc, argv);
}
static int wpa_cli_cmd_p2p_group_remove(struct wpa_ctrl *ctrl, int argc,
char *argv[])
{
return wpa_cli_cmd(ctrl, "P2P_GROUP_REMOVE", 1, argc, argv);
}
static char ** wpa_cli_complete_p2p_group_remove(const char *str, int pos)
{
int arg = get_cmd_arg_num(str, pos);
char **res = NULL;
switch (arg) {
case 1:
res = cli_txt_list_array(&p2p_groups);
break;
}
return res;
}
static int wpa_cli_cmd_p2p_group_add(struct wpa_ctrl *ctrl, int argc,
char *argv[])
{
return wpa_cli_cmd(ctrl, "P2P_GROUP_ADD", 0, argc, argv);
}
static int wpa_cli_cmd_p2p_group_member(struct wpa_ctrl *ctrl, int argc,
char *argv[])
{
return wpa_cli_cmd(ctrl, "P2P_GROUP_MEMBER", 1, argc, argv);
}
static int wpa_cli_cmd_p2p_prov_disc(struct wpa_ctrl *ctrl, int argc,
char *argv[])
{
if (argc != 2 && argc != 3) {
printf("Invalid P2P_PROV_DISC command: needs at least "
"two arguments, address and config method\n"
"(display, keypad, or pbc) and an optional join\n");
return -1;
}
return wpa_cli_cmd(ctrl, "P2P_PROV_DISC", 2, argc, argv);
}
static int wpa_cli_cmd_p2p_get_passphrase(struct wpa_ctrl *ctrl, int argc,
char *argv[])
{
return wpa_ctrl_command(ctrl, "P2P_GET_PASSPHRASE");
}
static int wpa_cli_cmd_p2p_serv_disc_req(struct wpa_ctrl *ctrl, int argc,
char *argv[])
{
char cmd[4096];
if (argc < 2) {
printf("Invalid P2P_SERV_DISC_REQ command: needs two "
"or more arguments (address and TLVs)\n");
return -1;
}
if (write_cmd(cmd, sizeof(cmd), "P2P_SERV_DISC_REQ", argc, argv) < 0)
return -1;
return wpa_ctrl_command(ctrl, cmd);
}
static int wpa_cli_cmd_p2p_serv_disc_cancel_req(struct wpa_ctrl *ctrl,
int argc, char *argv[])
{
return wpa_cli_cmd(ctrl, "P2P_SERV_DISC_CANCEL_REQ", 1, argc, argv);
}
static int wpa_cli_cmd_p2p_serv_disc_resp(struct wpa_ctrl *ctrl, int argc,
char *argv[])
{
char cmd[4096];
int res;
if (argc != 4) {
printf("Invalid P2P_SERV_DISC_RESP command: needs four "
"arguments (freq, address, dialog token, and TLVs)\n");
return -1;
}
res = os_snprintf(cmd, sizeof(cmd), "P2P_SERV_DISC_RESP %s %s %s %s",
argv[0], argv[1], argv[2], argv[3]);
if (os_snprintf_error(sizeof(cmd), res))
return -1;
cmd[sizeof(cmd) - 1] = '\0';
return wpa_ctrl_command(ctrl, cmd);
}
static int wpa_cli_cmd_p2p_service_update(struct wpa_ctrl *ctrl, int argc,
char *argv[])
{
return wpa_ctrl_command(ctrl, "P2P_SERVICE_UPDATE");
}
static int wpa_cli_cmd_p2p_serv_disc_external(struct wpa_ctrl *ctrl,
int argc, char *argv[])
{
return wpa_cli_cmd(ctrl, "P2P_SERV_DISC_EXTERNAL", 1, argc, argv);
}
static int wpa_cli_cmd_p2p_service_flush(struct wpa_ctrl *ctrl, int argc,
char *argv[])
{
return wpa_ctrl_command(ctrl, "P2P_SERVICE_FLUSH");
}
static int wpa_cli_cmd_p2p_service_add(struct wpa_ctrl *ctrl, int argc,
char *argv[])
{
if (argc < 3) {
printf("Invalid P2P_SERVICE_ADD command: needs 3-6 arguments\n");
return -1;
}
return wpa_cli_cmd(ctrl, "P2P_SERVICE_ADD", 3, argc, argv);
}
static int wpa_cli_cmd_p2p_service_rep(struct wpa_ctrl *ctrl, int argc,
char *argv[])
{
if (argc < 5 || argc > 6) {
printf("Invalid P2P_SERVICE_REP command: needs 5-6 "
"arguments\n");
return -1;
}
return wpa_cli_cmd(ctrl, "P2P_SERVICE_REP", 5, argc, argv);
}
static int wpa_cli_cmd_p2p_service_del(struct wpa_ctrl *ctrl, int argc,
char *argv[])
{
char cmd[4096];
int res;
if (argc != 2 && argc != 3) {
printf("Invalid P2P_SERVICE_DEL command: needs two or three "
"arguments\n");
return -1;
}
if (argc == 3)
res = os_snprintf(cmd, sizeof(cmd),
"P2P_SERVICE_DEL %s %s %s",
argv[0], argv[1], argv[2]);
else
res = os_snprintf(cmd, sizeof(cmd),
"P2P_SERVICE_DEL %s %s",
argv[0], argv[1]);
if (os_snprintf_error(sizeof(cmd), res))
return -1;
cmd[sizeof(cmd) - 1] = '\0';
return wpa_ctrl_command(ctrl, cmd);
}
static int wpa_cli_cmd_p2p_reject(struct wpa_ctrl *ctrl,
int argc, char *argv[])
{
return wpa_cli_cmd(ctrl, "P2P_REJECT", 1, argc, argv);
}
static int wpa_cli_cmd_p2p_invite(struct wpa_ctrl *ctrl,
int argc, char *argv[])
{
return wpa_cli_cmd(ctrl, "P2P_INVITE", 1, argc, argv);
}
static int wpa_cli_cmd_p2p_peer(struct wpa_ctrl *ctrl, int argc, char *argv[])
{
return wpa_cli_cmd(ctrl, "P2P_PEER", 1, argc, argv);
}
static char ** wpa_cli_complete_p2p_peer(const char *str, int pos)
{
int arg = get_cmd_arg_num(str, pos);
char **res = NULL;
switch (arg) {
case 1:
res = cli_txt_list_array(&p2p_peers);
break;
}
return res;
}
static int wpa_ctrl_command_p2p_peer(struct wpa_ctrl *ctrl, const char *cmd,
char *addr, size_t addr_len,
int discovered)
{
char buf[4096], *pos;
size_t len;
int ret;
if (ctrl_conn == NULL)
return -1;
len = sizeof(buf) - 1;
ret = wpa_ctrl_request(ctrl, cmd, os_strlen(cmd), buf, &len,
wpa_cli_msg_cb);
if (ret == -2) {
printf("'%s' command timed out.\n", cmd);
return -2;
} else if (ret < 0) {
printf("'%s' command failed.\n", cmd);
return -1;
}
buf[len] = '\0';
if (os_memcmp(buf, "FAIL", 4) == 0)
return -1;
pos = buf;
while (*pos != '\0' && *pos != '\n')
pos++;
*pos++ = '\0';
os_strlcpy(addr, buf, addr_len);
if (!discovered || os_strstr(pos, "[PROBE_REQ_ONLY]") == NULL)
printf("%s\n", addr);
return 0;
}
static int wpa_cli_cmd_p2p_peers(struct wpa_ctrl *ctrl, int argc, char *argv[])
{
char addr[32], cmd[64];
int discovered;
discovered = argc > 0 && os_strcmp(argv[0], "discovered") == 0;
if (wpa_ctrl_command_p2p_peer(ctrl, "P2P_PEER FIRST",
addr, sizeof(addr), discovered))
return -1;
do {
os_snprintf(cmd, sizeof(cmd), "P2P_PEER NEXT-%s", addr);
} while (wpa_ctrl_command_p2p_peer(ctrl, cmd, addr, sizeof(addr),
discovered) == 0);
return 0;
}
static int wpa_cli_cmd_p2p_set(struct wpa_ctrl *ctrl, int argc, char *argv[])
{
return wpa_cli_cmd(ctrl, "P2P_SET", 2, argc, argv);
}
static char ** wpa_cli_complete_p2p_set(const char *str, int pos)
{
int arg = get_cmd_arg_num(str, pos);
const char *fields[] = {
"discoverability",
"managed",
"listen_channel",
"ssid_postfix",
"noa",
"ps",
"oppps",
"ctwindow",
"disabled",
"conc_pref",
"force_long_sd",
"peer_filter",
"cross_connect",
"go_apsd",
"client_apsd",
"disallow_freq",
"disc_int",
"per_sta_psk",
};
int i, num_fields = ARRAY_SIZE(fields);
if (arg == 1) {
char **res = os_calloc(num_fields + 1, sizeof(char *));
if (res == NULL)
return NULL;
for (i = 0; i < num_fields; i++) {
res[i] = os_strdup(fields[i]);
if (res[i] == NULL)
return res;
}
return res;
}
if (arg == 2 && os_strncasecmp(str, "p2p_set peer_filter ", 20) == 0)
return cli_txt_list_array(&p2p_peers);
return NULL;
}
static int wpa_cli_cmd_p2p_flush(struct wpa_ctrl *ctrl, int argc, char *argv[])
{
return wpa_ctrl_command(ctrl, "P2P_FLUSH");
}
static int wpa_cli_cmd_p2p_cancel(struct wpa_ctrl *ctrl, int argc,
char *argv[])
{
return wpa_ctrl_command(ctrl, "P2P_CANCEL");
}
static int wpa_cli_cmd_p2p_unauthorize(struct wpa_ctrl *ctrl, int argc,
char *argv[])
{
return wpa_cli_cmd(ctrl, "P2P_UNAUTHORIZE", 1, argc, argv);
}
static int wpa_cli_cmd_p2p_presence_req(struct wpa_ctrl *ctrl, int argc,
char *argv[])
{
if (argc != 0 && argc != 2 && argc != 4) {
printf("Invalid P2P_PRESENCE_REQ command: needs two arguments "
"(preferred duration, interval; in microsecods).\n"
"Optional second pair can be used to provide "
"acceptable values.\n");
return -1;
}
return wpa_cli_cmd(ctrl, "P2P_PRESENCE_REQ", 0, argc, argv);
}
static int wpa_cli_cmd_p2p_ext_listen(struct wpa_ctrl *ctrl, int argc,
char *argv[])
{
if (argc != 0 && argc != 2) {
printf("Invalid P2P_EXT_LISTEN command: needs two arguments "
"(availability period, availability interval; in "
"millisecods).\n"
"Extended Listen Timing can be cancelled with this "
"command when used without parameters.\n");
return -1;
}
return wpa_cli_cmd(ctrl, "P2P_EXT_LISTEN", 0, argc, argv);
}
static int wpa_cli_cmd_p2p_remove_client(struct wpa_ctrl *ctrl, int argc,
char *argv[])
{
return wpa_cli_cmd(ctrl, "P2P_REMOVE_CLIENT", 1, argc, argv);
}
#endif /* CONFIG_P2P */
static int wpa_cli_cmd_vendor_elem_add(struct wpa_ctrl *ctrl, int argc,
char *argv[])
{
return wpa_cli_cmd(ctrl, "VENDOR_ELEM_ADD", 2, argc, argv);
}
static int wpa_cli_cmd_vendor_elem_get(struct wpa_ctrl *ctrl, int argc,
char *argv[])
{
return wpa_cli_cmd(ctrl, "VENDOR_ELEM_GET", 1, argc, argv);
}
static int wpa_cli_cmd_vendor_elem_remove(struct wpa_ctrl *ctrl, int argc,
char *argv[])
{
return wpa_cli_cmd(ctrl, "VENDOR_ELEM_REMOVE", 2, argc, argv);
}
#ifdef CONFIG_WIFI_DISPLAY
static int wpa_cli_cmd_wfd_subelem_set(struct wpa_ctrl *ctrl, int argc,
char *argv[])
{
char cmd[100];
int res;
if (argc != 1 && argc != 2) {
printf("Invalid WFD_SUBELEM_SET command: needs one or two "
"arguments (subelem, hexdump)\n");
return -1;
}
res = os_snprintf(cmd, sizeof(cmd), "WFD_SUBELEM_SET %s %s",
argv[0], argc > 1 ? argv[1] : "");
if (os_snprintf_error(sizeof(cmd), res))
return -1;
cmd[sizeof(cmd) - 1] = '\0';
return wpa_ctrl_command(ctrl, cmd);
}
static int wpa_cli_cmd_wfd_subelem_get(struct wpa_ctrl *ctrl, int argc,
char *argv[])
{
char cmd[100];
int res;
if (argc != 1) {
printf("Invalid WFD_SUBELEM_GET command: needs one "
"argument (subelem)\n");
return -1;
}
res = os_snprintf(cmd, sizeof(cmd), "WFD_SUBELEM_GET %s",
argv[0]);
if (os_snprintf_error(sizeof(cmd), res))
return -1;
cmd[sizeof(cmd) - 1] = '\0';
return wpa_ctrl_command(ctrl, cmd);
}
#endif /* CONFIG_WIFI_DISPLAY */
#ifdef CONFIG_INTERWORKING
static int wpa_cli_cmd_fetch_anqp(struct wpa_ctrl *ctrl, int argc,
char *argv[])
{
return wpa_ctrl_command(ctrl, "FETCH_ANQP");
}
static int wpa_cli_cmd_stop_fetch_anqp(struct wpa_ctrl *ctrl, int argc,
char *argv[])
{
return wpa_ctrl_command(ctrl, "STOP_FETCH_ANQP");
}
static int wpa_cli_cmd_interworking_select(struct wpa_ctrl *ctrl, int argc,
char *argv[])
{
return wpa_cli_cmd(ctrl, "INTERWORKING_SELECT", 0, argc, argv);
}
static int wpa_cli_cmd_interworking_connect(struct wpa_ctrl *ctrl, int argc,
char *argv[])
{
return wpa_cli_cmd(ctrl, "INTERWORKING_CONNECT", 1, argc, argv);
}
static int wpa_cli_cmd_interworking_add_network(struct wpa_ctrl *ctrl, int argc,
char *argv[])
{
return wpa_cli_cmd(ctrl, "INTERWORKING_ADD_NETWORK", 1, argc, argv);
}
static int wpa_cli_cmd_anqp_get(struct wpa_ctrl *ctrl, int argc, char *argv[])
{
return wpa_cli_cmd(ctrl, "ANQP_GET", 2, argc, argv);
}
static int wpa_cli_cmd_gas_request(struct wpa_ctrl *ctrl, int argc,
char *argv[])
{
return wpa_cli_cmd(ctrl, "GAS_REQUEST", 2, argc, argv);
}
static int wpa_cli_cmd_gas_response_get(struct wpa_ctrl *ctrl, int argc,
char *argv[])
{
return wpa_cli_cmd(ctrl, "GAS_RESPONSE_GET", 2, argc, argv);
}
#endif /* CONFIG_INTERWORKING */
#ifdef CONFIG_HS20
static int wpa_cli_cmd_hs20_anqp_get(struct wpa_ctrl *ctrl, int argc,
char *argv[])