summaryrefslogtreecommitdiffstats
path: root/wpa_supplicant/wpa_cli.c
diff options
context:
space:
mode:
authorrpaulo <rpaulo@FreeBSD.org>2010-10-29 08:01:21 +0000
committerrpaulo <rpaulo@FreeBSD.org>2010-10-29 08:01:21 +0000
commit4dc7b761106b26c00b15dfbfd5e4da7a15d85166 (patch)
tree0b2308ac0b6239b9bd8d56cb4a658ca35f20a06b /wpa_supplicant/wpa_cli.c
parent60c44471bf25f9e84d8701afe1bbcbcc88e18c89 (diff)
downloadFreeBSD-src-4dc7b761106b26c00b15dfbfd5e4da7a15d85166.zip
FreeBSD-src-4dc7b761106b26c00b15dfbfd5e4da7a15d85166.tar.gz
Import wpa_supplicant / hostapd 0.7.3.
Changes: 2010-09-07 - v0.7.3 * fixed fallback from failed PMKSA caching into full EAP authentication [Bug 355] * fixed issue with early D-Bus signals during initialization * fixed X.509 name handling in internal TLS * fixed WPS ER to use corrent Enrollee MAC Address in Credential * fixed scanning routines ot improve AP selection for WPS * added WPS workaround for open networks * fixed WPS Diffie-Hellman derivation to use correct public key length * fixed wpa_supplicant AP mode operations to ignore Supplicant and scan result events * improved SME operations with nl80211 * fixed WPS ER event_id handling in some cases * fixed some issues with bgscan simple to avoid unnecessary scans * fixed issue with l2_packet_ndis overlapped writes corrupting stack [Bug 328] * updated WinPcap to the latest stable version 4.1.2 in Windows installer 2010-04-18 - v0.7.2 * nl80211: fixed number of issues with roaming * avoid unnecessary roaming if multiple APs with similar signal strength are present in scan results * add TLS client events and server probing to ease design of automatic detection of EAP parameters * add option for server certificate matching (SHA256 hash of the certificate) instead of trusted CA certificate configuration * bsd: Cleaned up driver wrapper and added various low-level configuration options * wpa_gui-qt4: do not show too frequent WPS AP available events as tray messages * TNC: fixed issues with fragmentation * EAP-TNC: add Flags field into fragment acknowledgement (needed to interoperate with other implementations; may potentially breaks compatibility with older wpa_supplicant/hostapd versions) * wpa_cli: added option for using a separate process to receive event messages to reduce latency in showing these (CFLAGS += -DCONFIG_WPA_CLI_FORK=y in .config to enable this) * maximum BSS table size can now be configured (bss_max_count) * BSSes to be included in the BSS table can be filtered based on configured SSIDs to save memory (filter_ssids) * fix number of issues with IEEE 802.11r/FT; this version is not backwards compatible with old versions * nl80211: add support for IEEE 802.11r/FT protocol (both over-the-air and over-the-DS) * add freq_list network configuration parameter to allow the AP selection to filter out entries based on the operating channel * add signal strength change events for bgscan; this allows more dynamic changes to background scanning interval based on changes in the signal strength with the current AP; this improves roaming within ESS quite a bit, e.g., with bgscan="simple:30:-45:300" in the network configuration block to request background scans less frequently when signal strength remains good and to automatically trigger background scans whenever signal strength drops noticeably (this is currently only available with nl80211) * add BSSID and reason code (if available) to disconnect event messages * wpa_gui-qt4: more complete support for translating the GUI with linguist and add German translation * fix DH padding with internal crypto code (mainly, for WPS) * do not trigger initial scan automatically anymore if there are no enabled networks 2010-01-16 - v0.7.1 * cleaned up driver wrapper API (struct wpa_driver_ops); the new API is not fully backwards compatible, so out-of-tree driver wrappers will need modifications * cleaned up various module interfaces * merge hostapd and wpa_supplicant developers' documentation into a single document * nl80211: use explicit deauthentication to clear cfg80211 state to avoid issues when roaming between APs * dbus: major design changes in the new D-Bus API (fi.w1.wpa_supplicant1) * nl80211: added support for IBSS networks * added internal debugging mechanism with backtrace support and memory allocation/freeing validation, etc. tests (CONFIG_WPA_TRACE=y) * added WPS ER unsubscription command to more cleanly unregister from receiving UPnP events when ER is terminated * cleaned up AP mode operations to avoid need for virtual driver_ops wrapper * added BSS table to maintain more complete scan result information over multiple scans (that may include only partial results) * wpa_gui-qt4: update Peers dialog information more dynamically while the dialog is kept open * fixed PKCS#12 use with OpenSSL 1.0.0 * driver_wext: Added cfg80211-specific optimization to avoid some unnecessary scans and to speed up association 2009-11-21 - v0.7.0 * increased wpa_cli ping interval to 5 seconds and made this configurable with a new command line options (-G<seconds>) * fixed scan buffer processing with WEXT to handle up to 65535 byte result buffer (previously, limited to 32768 bytes) * allow multiple driver wrappers to be specified on command line (e.g., -Dnl80211,wext); the first one that is able to initialize the interface will be used * added support for multiple SSIDs per scan request to optimize scan_ssid=1 operations in ap_scan=1 mode (i.e., search for hidden SSIDs); this requires driver support and can currently be used only with nl80211 * added support for WPS USBA out-of-band mechanism with USB Flash Drives (UFD) (CONFIG_WPS_UFD=y) * driver_ndis: add PAE group address to the multicast address list to fix wired IEEE 802.1X authentication * fixed IEEE 802.11r key derivation function to match with the standard (note: this breaks interoperability with previous version) [Bug 303] * added better support for drivers that allow separate authentication and association commands (e.g., mac80211-based Linux drivers with nl80211; SME in wpa_supplicant); this allows over-the-air FT protocol to be used (IEEE 802.11r) * fixed SHA-256 based key derivation function to match with the standard when using CCMP (for IEEE 802.11r and IEEE 802.11w) (note: this breaks interoperability with previous version) [Bug 307] * use shared driver wrapper files with hostapd * added AP mode functionality (CONFIG_AP=y) with mode=2 in the network block; this can be used for open and WPA2-Personal networks (optionally, with WPS); this links in parts of hostapd functionality into wpa_supplicant * wpa_gui-qt4: added new Peers dialog to show information about peers (other devices, including APs and stations, etc. in the neighborhood) * added support for WPS External Registrar functionality (configure APs and enroll new devices); can be used with wpa_gui-qt4 Peers dialog and wpa_cli commands wps_er_start, wps_er_stop, wps_er_pin, wps_er_pbc, wps_er_learn (this can also be used with a new 'none' driver wrapper if no wireless device or IEEE 802.1X on wired is needed) * driver_nl80211: multiple updates to provide support for new Linux nl80211/mac80211 functionality * updated management frame protection to use IEEE Std 802.11w-2009 * fixed number of small WPS issues and added workarounds to interoperate with common deployed broken implementations * added support for NFC out-of-band mechanism with WPS * driver_ndis: fixed wired IEEE 802.1X authentication with PAE group address frames * added preliminary support for IEEE 802.11r RIC processing * added support for specifying subset of enabled frequencies to scan (scan_freq option in the network configuration block); this can speed up scanning process considerably if it is known that only a small subset of channels is actually used in the network (this is currently supported only with -Dnl80211) * added a workaround for race condition between receiving the association event and the following EAPOL-Key * added background scan and roaming infrastructure to allow network-specific optimizations to be used to improve roaming within an ESS (same SSID) * added new DBus interface (fi.w1.wpa_supplicant1)
Diffstat (limited to 'wpa_supplicant/wpa_cli.c')
-rw-r--r--wpa_supplicant/wpa_cli.c630
1 files changed, 558 insertions, 72 deletions
diff --git a/wpa_supplicant/wpa_cli.c b/wpa_supplicant/wpa_cli.c
index 7de6534..162a0b8 100644
--- a/wpa_supplicant/wpa_cli.c
+++ b/wpa_supplicant/wpa_cli.c
@@ -1,6 +1,6 @@
/*
* WPA Supplicant - command line interface for wpa_supplicant daemon
- * Copyright (c) 2004-2009, Jouni Malinen <j@w1.fi>
+ * Copyright (c) 2004-2010, Jouni Malinen <j@w1.fi>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
@@ -23,15 +23,18 @@
#include <readline/readline.h>
#include <readline/history.h>
#endif /* CONFIG_READLINE */
+#ifdef CONFIG_WPA_CLI_FORK
+#include <sys/wait.h>
+#endif /* CONFIG_WPA_CLI_FORK */
-#include "wpa_ctrl.h"
+#include "common/wpa_ctrl.h"
#include "common.h"
-#include "version.h"
+#include "common/version.h"
static const char *wpa_cli_version =
"wpa_cli v" VERSION_STR "\n"
-"Copyright (c) 2004-2009, Jouni Malinen <j@w1.fi> and contributors";
+"Copyright (c) 2004-2010, Jouni Malinen <j@w1.fi> and contributors";
static const char *wpa_cli_license =
@@ -87,6 +90,10 @@ static const char *wpa_cli_full_license =
"\n";
static struct wpa_ctrl *ctrl_conn;
+static struct wpa_ctrl *mon_conn;
+#ifdef CONFIG_WPA_CLI_FORK
+static pid_t mon_pid = 0;
+#endif /* CONFIG_WPA_CLI_FORK */
static int wpa_cli_quit = 0;
static int wpa_cli_attached = 0;
static int wpa_cli_connected = 0;
@@ -96,6 +103,7 @@ static char *ctrl_ifname = NULL;
static const char *pid_file = NULL;
static const char *action_file = NULL;
static int ping_interval = 5;
+static int interactive = 0;
static void print_help();
@@ -119,32 +127,126 @@ static void usage(void)
}
-static struct wpa_ctrl * wpa_cli_open_connection(const char *ifname)
+#ifdef CONFIG_WPA_CLI_FORK
+static int in_query = 0;
+
+static void wpa_cli_monitor_sig(int sig)
+{
+ if (sig == SIGUSR1)
+ in_query = 1;
+ else if (sig == SIGUSR2)
+ in_query = 0;
+}
+
+static void wpa_cli_monitor(void)
+{
+ char buf[256];
+ size_t len = sizeof(buf) - 1;
+ struct timeval tv;
+ fd_set rfds;
+
+ signal(SIGUSR1, wpa_cli_monitor_sig);
+ signal(SIGUSR2, wpa_cli_monitor_sig);
+
+ while (mon_conn) {
+ int s = wpa_ctrl_get_fd(mon_conn);
+ tv.tv_sec = 5;
+ tv.tv_usec = 0;
+ FD_ZERO(&rfds);
+ FD_SET(s, &rfds);
+ if (select(s + 1, &rfds, NULL, NULL, &tv) < 0) {
+ if (errno == EINTR)
+ continue;
+ perror("select");
+ break;
+ }
+ if (mon_conn == NULL)
+ break;
+ if (FD_ISSET(s, &rfds)) {
+ len = sizeof(buf) - 1;
+ int res = wpa_ctrl_recv(mon_conn, buf, &len);
+ if (res < 0) {
+ perror("wpa_ctrl_recv");
+ break;
+ }
+ buf[len] = '\0';
+ if (in_query)
+ printf("\r");
+ printf("%s\n", buf);
+ kill(getppid(), SIGUSR1);
+ }
+ }
+}
+#endif /* CONFIG_WPA_CLI_FORK */
+
+
+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);
- return ctrl_conn;
+ 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;
int flen, res;
if (ifname == NULL)
- return NULL;
+ return -1;
flen = os_strlen(ctrl_iface_dir) + os_strlen(ifname) + 2;
cfile = os_malloc(flen);
if (cfile == NULL)
- return NULL;
+ return -1L;
res = os_snprintf(cfile, flen, "%s/%s", ctrl_iface_dir, ifname);
if (res < 0 || res >= flen) {
os_free(cfile);
- return NULL;
+ return -1;
}
ctrl_conn = wpa_ctrl_open(cfile);
+ if (ctrl_conn == NULL) {
+ os_free(cfile);
+ return -1;
+ }
+
+ if (attach && interactive)
+ mon_conn = wpa_ctrl_open(cfile);
+ else
+ mon_conn = NULL;
os_free(cfile);
- return ctrl_conn;
#endif /* CONFIG_CTRL_IFACE_UDP || CONFIG_CTRL_IFACE_NAMED_PIPE */
+
+ if (mon_conn) {
+ if (wpa_ctrl_attach(mon_conn) == 0) {
+ wpa_cli_attached = 1;
+ } else {
+ printf("Warning: Failed to attach to "
+ "wpa_supplicant.\n");
+ return -1;
+ }
+
+#ifdef CONFIG_WPA_CLI_FORK
+ {
+ pid_t p = fork();
+ if (p < 0) {
+ perror("fork");
+ return -1;
+ }
+ if (p == 0) {
+ wpa_cli_monitor();
+ exit(0);
+ } else
+ mon_pid = p;
+ }
+#endif /* CONFIG_WPA_CLI_FORK */
+ }
+
+ return 0;
}
@@ -153,12 +255,25 @@ static void wpa_cli_close_connection(void)
if (ctrl_conn == NULL)
return;
+#ifdef CONFIG_WPA_CLI_FORK
+ if (mon_pid) {
+ int status;
+ kill(mon_pid, SIGPIPE);
+ wait(&status);
+ mon_pid = 0;
+ }
+#endif /* CONFIG_WPA_CLI_FORK */
+
if (wpa_cli_attached) {
- wpa_ctrl_detach(ctrl_conn);
+ wpa_ctrl_detach(interactive ? mon_conn : ctrl_conn);
wpa_cli_attached = 0;
}
wpa_ctrl_close(ctrl_conn);
ctrl_conn = NULL;
+ if (mon_conn) {
+ wpa_ctrl_close(mon_conn);
+ mon_conn = NULL;
+ }
}
@@ -446,19 +561,85 @@ static int wpa_cli_cmd_wps_pin(struct wpa_ctrl *ctrl, int argc, char *argv[])
}
+#ifdef CONFIG_WPS_OOB
+static int wpa_cli_cmd_wps_oob(struct wpa_ctrl *ctrl, int argc, char *argv[])
+{
+ char cmd[256];
+ int res;
+
+ if (argc != 3 && argc != 4) {
+ printf("Invalid WPS_OOB command: need three or four "
+ "arguments:\n"
+ "- DEV_TYPE: use 'ufd' or 'nfc'\n"
+ "- PATH: path of OOB device like '/mnt'\n"
+ "- METHOD: OOB method 'pin-e' or 'pin-r', "
+ "'cred'\n"
+ "- DEV_NAME: (only for NFC) device name like "
+ "'pn531'\n");
+ return -1;
+ }
+
+ if (argc == 3)
+ res = os_snprintf(cmd, sizeof(cmd), "WPS_OOB %s %s %s",
+ argv[0], argv[1], argv[2]);
+ else
+ res = os_snprintf(cmd, sizeof(cmd), "WPS_OOB %s %s %s %s",
+ argv[0], argv[1], argv[2], argv[3]);
+ if (res < 0 || (size_t) res >= sizeof(cmd) - 1) {
+ printf("Too long WPS_OOB command.\n");
+ return -1;
+ }
+ return wpa_ctrl_command(ctrl, cmd);
+}
+#endif /* CONFIG_WPS_OOB */
+
+
static int wpa_cli_cmd_wps_reg(struct wpa_ctrl *ctrl, int argc, char *argv[])
{
char cmd[256];
int res;
- if (argc != 2) {
+ if (argc == 2)
+ res = os_snprintf(cmd, sizeof(cmd), "WPS_REG %s %s",
+ argv[0], argv[1]);
+ else if (argc == 6) {
+ char ssid_hex[2 * 32 + 1];
+ char key_hex[2 * 64 + 1];
+ int i;
+
+ ssid_hex[0] = '\0';
+ for (i = 0; i < 32; i++) {
+ if (argv[2][i] == '\0')
+ break;
+ os_snprintf(&ssid_hex[i * 2], 3, "%02x", argv[2][i]);
+ }
+
+ key_hex[0] = '\0';
+ 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: use 'any' to select any\n"
"- AP PIN\n");
+ printf("Alternatively, six arguments can be used to "
+ "reconfigure the AP:\n"
+ "- BSSID: use 'any' to select any\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;
}
- res = os_snprintf(cmd, sizeof(cmd), "WPS_REG %s %s", argv[0], argv[1]);
if (res < 0 || (size_t) res >= sizeof(cmd) - 1) {
printf("Too long WPS_REG command.\n");
return -1;
@@ -467,6 +648,110 @@ static int wpa_cli_cmd_wps_reg(struct wpa_ctrl *ctrl, int argc, char *argv[])
}
+static int wpa_cli_cmd_wps_er_start(struct wpa_ctrl *ctrl, int argc,
+ char *argv[])
+{
+ return wpa_ctrl_command(ctrl, "WPS_ER_START");
+
+}
+
+
+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[])
+{
+ char cmd[256];
+ int res;
+
+ if (argc != 2) {
+ printf("Invalid WPS_ER_PIN command: need two arguments:\n"
+ "- UUID: use 'any' to select any\n"
+ "- PIN: Enrollee PIN\n");
+ return -1;
+ }
+
+ res = os_snprintf(cmd, sizeof(cmd), "WPS_ER_PIN %s %s",
+ argv[0], argv[1]);
+ if (res < 0 || (size_t) res >= sizeof(cmd) - 1) {
+ printf("Too long WPS_ER_PIN command.\n");
+ return -1;
+ }
+ return wpa_ctrl_command(ctrl, cmd);
+}
+
+
+static int wpa_cli_cmd_wps_er_pbc(struct wpa_ctrl *ctrl, int argc,
+ char *argv[])
+{
+ char cmd[256];
+ int res;
+
+ if (argc != 1) {
+ printf("Invalid WPS_ER_PBC command: need one argument:\n"
+ "- UUID: Specify the Enrollee\n");
+ return -1;
+ }
+
+ res = os_snprintf(cmd, sizeof(cmd), "WPS_ER_PBC %s",
+ argv[0]);
+ if (res < 0 || (size_t) res >= sizeof(cmd) - 1) {
+ printf("Too long WPS_ER_PBC command.\n");
+ return -1;
+ }
+ return wpa_ctrl_command(ctrl, cmd);
+}
+
+
+static int wpa_cli_cmd_wps_er_learn(struct wpa_ctrl *ctrl, int argc,
+ char *argv[])
+{
+ char cmd[256];
+ int res;
+
+ 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;
+ }
+
+ res = os_snprintf(cmd, sizeof(cmd), "WPS_ER_LEARN %s %s",
+ argv[0], argv[1]);
+ if (res < 0 || (size_t) res >= sizeof(cmd) - 1) {
+ printf("Too long WPS_ER_LEARN command.\n");
+ return -1;
+ }
+ return wpa_ctrl_command(ctrl, cmd);
+}
+
+
+static int wpa_cli_cmd_ibss_rsn(struct wpa_ctrl *ctrl, int argc, char *argv[])
+{
+ char cmd[256];
+ int res;
+
+ if (argc != 1) {
+ printf("Invalid IBSS_RSN command: needs one argument "
+ "(Peer STA MAC address)\n");
+ return -1;
+ }
+
+ res = os_snprintf(cmd, sizeof(cmd), "IBSS_RSN %s", argv[0]);
+ if (res < 0 || (size_t) res >= sizeof(cmd) - 1) {
+ printf("Too long IBSS_RSN command.\n");
+ return -1;
+ }
+ return wpa_ctrl_command(ctrl, cmd);
+}
+
+
static int wpa_cli_cmd_level(struct wpa_ctrl *ctrl, int argc, char *argv[])
{
char cmd[256];
@@ -990,14 +1275,8 @@ static int wpa_cli_cmd_interface(struct wpa_ctrl *ctrl, int argc, char *argv[])
os_free(ctrl_ifname);
ctrl_ifname = os_strdup(argv[0]);
- if (wpa_cli_open_connection(ctrl_ifname)) {
+ if (wpa_cli_open_connection(ctrl_ifname, 1)) {
printf("Connected to interface '%s.\n", ctrl_ifname);
- if (wpa_ctrl_attach(ctrl_conn) == 0) {
- wpa_cli_attached = 1;
- } else {
- printf("Warning: Failed to attach to "
- "wpa_supplicant.\n");
- }
} else {
printf("Could not connect to interface '%s' - re-trying\n",
ctrl_ifname);
@@ -1078,6 +1357,109 @@ static int wpa_cli_cmd_interface_list(struct wpa_ctrl *ctrl, int argc,
}
+#ifdef CONFIG_AP
+static int wpa_cli_cmd_sta(struct wpa_ctrl *ctrl, int argc, char *argv[])
+{
+ char buf[64];
+ if (argc != 1) {
+ printf("Invalid 'sta' command - exactly one argument, STA "
+ "address, is required.\n");
+ return -1;
+ }
+ os_snprintf(buf, sizeof(buf), "STA %s", argv[0]);
+ return wpa_ctrl_command(ctrl, buf);
+}
+
+
+static int wpa_ctrl_command_sta(struct wpa_ctrl *ctrl, char *cmd,
+ char *addr, size_t addr_len)
+{
+ char buf[4096], *pos;
+ size_t len;
+ int ret;
+
+ if (ctrl_conn == NULL) {
+ printf("Not connected to hostapd - command dropped.\n");
+ return -1;
+ }
+ len = sizeof(buf) - 1;
+ ret = wpa_ctrl_request(ctrl, cmd, 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 (memcmp(buf, "FAIL", 4) == 0)
+ return -1;
+ 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)))
+ return 0;
+ do {
+ os_snprintf(cmd, sizeof(cmd), "STA-NEXT %s", addr);
+ } while (wpa_ctrl_command_sta(ctrl, cmd, addr, sizeof(addr)) == 0);
+
+ return -1;
+}
+#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");
+}
+
+
+static int wpa_cli_cmd_drop_sa(struct wpa_ctrl *ctrl, int argc, char *argv[])
+{
+ return wpa_ctrl_command(ctrl, "DROP_SA");
+}
+
+
+static int wpa_cli_cmd_roam(struct wpa_ctrl *ctrl, int argc, char *argv[])
+{
+ char cmd[128];
+ int res;
+
+ if (argc != 1) {
+ printf("Invalid ROAM command: needs one argument "
+ "(target AP's BSSID)\n");
+ return -1;
+ }
+
+ res = os_snprintf(cmd, sizeof(cmd), "ROAM %s", argv[0]);
+ if (res < 0 || (size_t) res >= sizeof(cmd) - 1) {
+ printf("Too long ROAM command.\n");
+ return -1;
+ }
+ return wpa_ctrl_command(ctrl, cmd);
+}
+
+
enum wpa_cli_cmd_flags {
cli_cmd_flag_none = 0x00,
cli_cmd_flag_sensitive = 0x01
@@ -1238,9 +1620,49 @@ static struct wpa_cli_cmd wpa_cli_commands[] = {
cli_cmd_flag_sensitive,
"<BSSID> [PIN] = start WPS PIN method (returns PIN, if not "
"hardcoded)" },
+#ifdef CONFIG_WPS_OOB
+ { "wps_oob", wpa_cli_cmd_wps_oob,
+ cli_cmd_flag_sensitive,
+ "<DEV_TYPE> <PATH> <METHOD> [DEV_NAME] = start WPS OOB" },
+#endif /* CONFIG_WPS_OOB */
{ "wps_reg", wpa_cli_cmd_wps_reg,
cli_cmd_flag_sensitive,
"<BSSID> <AP PIN> = start WPS Registrar to configure an AP" },
+ { "wps_er_start", wpa_cli_cmd_wps_er_start,
+ cli_cmd_flag_none,
+ "= start Wi-Fi Protected Setup External Registrar" },
+ { "wps_er_stop", wpa_cli_cmd_wps_er_stop,
+ cli_cmd_flag_none,
+ "= stop Wi-Fi Protected Setup External Registrar" },
+ { "wps_er_pin", wpa_cli_cmd_wps_er_pin,
+ cli_cmd_flag_sensitive,
+ "<UUID> <PIN> = add an Enrollee PIN to External Registrar" },
+ { "wps_er_pbc", wpa_cli_cmd_wps_er_pbc,
+ cli_cmd_flag_none,
+ "<UUID> = accept an Enrollee PBC using External Registrar" },
+ { "wps_er_learn", wpa_cli_cmd_wps_er_learn,
+ cli_cmd_flag_sensitive,
+ "<UUID> <PIN> = learn AP configuration" },
+ { "ibss_rsn", wpa_cli_cmd_ibss_rsn,
+ cli_cmd_flag_none,
+ "<addr> = request RSN authentication with <addr> in IBSS" },
+#ifdef CONFIG_AP
+ { "sta", wpa_cli_cmd_sta,
+ cli_cmd_flag_none,
+ "<addr> = get information about an associated station (AP)" },
+ { "all_sta", wpa_cli_cmd_all_sta,
+ cli_cmd_flag_none,
+ "= get information about all associated stations (AP)" },
+#endif /* CONFIG_AP */
+ { "suspend", wpa_cli_cmd_suspend, cli_cmd_flag_none,
+ "= notification of suspend/hibernate" },
+ { "resume", wpa_cli_cmd_resume, cli_cmd_flag_none,
+ "= notification of resume/thaw" },
+ { "drop_sa", wpa_cli_cmd_drop_sa, cli_cmd_flag_none,
+ "= drop SA without deauth/disassoc (test command)" },
+ { "roam", wpa_cli_cmd_roam,
+ cli_cmd_flag_none,
+ "<addr> = roam to the specified BSS" },
{ NULL, NULL, cli_cmd_flag_none, NULL }
};
@@ -1448,16 +1870,7 @@ static void wpa_cli_action_cb(char *msg, size_t len)
static void wpa_cli_reconnect(void)
{
wpa_cli_close_connection();
- ctrl_conn = wpa_cli_open_connection(ctrl_ifname);
- if (ctrl_conn) {
- printf("Connection to wpa_supplicant re-established\n");
- if (wpa_ctrl_attach(ctrl_conn) == 0) {
- wpa_cli_attached = 1;
- } else {
- printf("Warning: Failed to attach to "
- "wpa_supplicant.\n");
- }
- }
+ wpa_cli_open_connection(ctrl_ifname, 1);
}
@@ -1478,9 +1891,13 @@ static void wpa_cli_recv_pending(struct wpa_ctrl *ctrl, int in_read,
wpa_cli_action_process(buf);
else {
if (in_read && first)
- printf("\n");
+ printf("\r");
first = 0;
printf("%s\n", buf);
+#ifdef CONFIG_READLINE
+ rl_on_new_line();
+ rl_redisplay();
+#endif /* CONFIG_READLINE */
}
} else {
printf("Could not read pending message.\n");
@@ -1510,7 +1927,7 @@ static char * wpa_cli_cmd_gen(const char *text, int state)
while ((cmd = wpa_cli_commands[i].cmd)) {
i++;
if (os_strncasecmp(cmd, text, len) == 0)
- return os_strdup(cmd);
+ return strdup(cmd);
}
return NULL;
@@ -1519,14 +1936,60 @@ static char * wpa_cli_cmd_gen(const char *text, int state)
static char * wpa_cli_dummy_gen(const char *text, int state)
{
+ int i;
+
+ for (i = 0; wpa_cli_commands[i].cmd; i++) {
+ const char *cmd = wpa_cli_commands[i].cmd;
+ size_t len = os_strlen(cmd);
+ if (os_strncasecmp(rl_line_buffer, cmd, len) == 0 &&
+ rl_line_buffer[len] == ' ') {
+ printf("\n%s\n", wpa_cli_commands[i].usage);
+ rl_on_new_line();
+ rl_redisplay();
+ break;
+ }
+ }
+
+ rl_attempted_completion_over = 1;
+ return NULL;
+}
+
+
+static char * wpa_cli_status_gen(const char *text, int state)
+{
+ static int i, len;
+ char *options[] = {
+ "verbose", NULL
+ };
+ char *t;
+
+ if (state == 0) {
+ i = 0;
+ len = os_strlen(text);
+ }
+
+ while ((t = options[i])) {
+ i++;
+ if (os_strncasecmp(t, text, len) == 0)
+ return strdup(t);
+ }
+
+ rl_attempted_completion_over = 1;
return NULL;
}
static char ** wpa_cli_completion(const char *text, int start, int end)
{
- return rl_completion_matches(text, start == 0 ?
- wpa_cli_cmd_gen : wpa_cli_dummy_gen);
+ char * (*func)(const char *text, int state);
+
+ if (start == 0)
+ func = wpa_cli_cmd_gen;
+ else if (os_strncasecmp(rl_line_buffer, "status ", 7) == 0)
+ func = wpa_cli_status_gen;
+ else
+ func = wpa_cli_dummy_gen;
+ return rl_completion_matches(text, func);
}
#endif /* CONFIG_READLINE */
@@ -1563,10 +2026,14 @@ static void wpa_cli_interactive(void)
#endif /* CONFIG_READLINE */
do {
- wpa_cli_recv_pending(ctrl_conn, 0, 0);
+ wpa_cli_recv_pending(mon_conn, 0, 0);
#ifndef CONFIG_NATIVE_WINDOWS
alarm(ping_interval);
#endif /* CONFIG_NATIVE_WINDOWS */
+#ifdef CONFIG_WPA_CLI_FORK
+ if (mon_pid)
+ kill(mon_pid, SIGUSR1);
+#endif /* CONFIG_WPA_CLI_FORK */
#ifdef CONFIG_READLINE
cmd = readline("> ");
if (cmd && *cmd) {
@@ -1587,7 +2054,7 @@ static void wpa_cli_interactive(void)
#endif /* CONFIG_NATIVE_WINDOWS */
if (cmd == NULL)
break;
- wpa_cli_recv_pending(ctrl_conn, 0, 0);
+ wpa_cli_recv_pending(mon_conn, 0, 0);
pos = cmd;
while (*pos != '\0') {
if (*pos == '\n') {
@@ -1621,7 +2088,11 @@ static void wpa_cli_interactive(void)
wpa_request(ctrl_conn, argc, argv);
if (cmd != cmdbuf)
- os_free(cmd);
+ free(cmd);
+#ifdef CONFIG_WPA_CLI_FORK
+ if (mon_pid)
+ kill(mon_pid, SIGUSR2);
+#endif /* CONFIG_WPA_CLI_FORK */
} while (!wpa_cli_quit);
#ifdef CONFIG_READLINE
@@ -1711,6 +2182,17 @@ static void wpa_cli_terminate(int sig)
}
+#ifdef CONFIG_WPA_CLI_FORK
+static void wpa_cli_usr1(int sig)
+{
+#ifdef CONFIG_READLINE
+ rl_on_new_line();
+ rl_redisplay();
+#endif /* CONFIG_READLINE */
+}
+#endif /* CONFIG_WPA_CLI_FORK */
+
+
#ifndef CONFIG_NATIVE_WINDOWS
static void wpa_cli_alarm(int sig)
{
@@ -1721,8 +2203,8 @@ static void wpa_cli_alarm(int sig)
}
if (!ctrl_conn)
wpa_cli_reconnect();
- if (ctrl_conn)
- wpa_cli_recv_pending(ctrl_conn, 1, 0);
+ if (mon_conn)
+ wpa_cli_recv_pending(mon_conn, 1, 0);
alarm(ping_interval);
}
#endif /* CONFIG_NATIVE_WINDOWS */
@@ -1785,7 +2267,6 @@ static char * wpa_cli_get_default_ifname(void)
int main(int argc, char *argv[])
{
- int interactive;
int warning_displayed = 0;
int c;
int daemonize = 0;
@@ -1852,31 +2333,6 @@ int main(int argc, char *argv[])
}
}
- for (; !global;) {
- if (ctrl_ifname == NULL)
- ctrl_ifname = wpa_cli_get_default_ifname();
- ctrl_conn = wpa_cli_open_connection(ctrl_ifname);
- if (ctrl_conn) {
- if (warning_displayed)
- printf("Connection established.\n");
- break;
- }
-
- if (!interactive) {
- perror("Failed to connect to wpa_supplicant - "
- "wpa_ctrl_open");
- return -1;
- }
-
- if (!warning_displayed) {
- printf("Could not connect to wpa_supplicant - "
- "re-trying\n");
- warning_displayed = 1;
- }
- os_sleep(1, 0);
- continue;
- }
-
#ifndef _WIN32_WCE
signal(SIGINT, wpa_cli_terminate);
signal(SIGTERM, wpa_cli_terminate);
@@ -1884,15 +2340,45 @@ int main(int argc, char *argv[])
#ifndef CONFIG_NATIVE_WINDOWS
signal(SIGALRM, wpa_cli_alarm);
#endif /* CONFIG_NATIVE_WINDOWS */
+#ifdef CONFIG_WPA_CLI_FORK
+ signal(SIGUSR1, wpa_cli_usr1);
+#endif /* CONFIG_WPA_CLI_FORK */
+
+ if (ctrl_ifname == NULL)
+ ctrl_ifname = wpa_cli_get_default_ifname();
+
+ if (interactive) {
+ for (; !global;) {
+ if (wpa_cli_open_connection(ctrl_ifname, 1) == 0) {
+ if (warning_displayed)
+ printf("Connection established.\n");
+ break;
+ }
- if (interactive || action_file) {
- if (wpa_ctrl_attach(ctrl_conn) == 0) {
- wpa_cli_attached = 1;
- } else {
- printf("Warning: Failed to attach to "
- "wpa_supplicant.\n");
- if (!interactive)
+ if (!warning_displayed) {
+ printf("Could not connect to wpa_supplicant - "
+ "re-trying\n");
+ warning_displayed = 1;
+ }
+ os_sleep(1, 0);
+ continue;
+ }
+ } else {
+ if (!global &&
+ wpa_cli_open_connection(ctrl_ifname, 0) < 0) {
+ perror("Failed to connect to wpa_supplicant - "
+ "wpa_ctrl_open");
+ return -1;
+ }
+
+ if (action_file) {
+ if (wpa_ctrl_attach(ctrl_conn) == 0) {
+ wpa_cli_attached = 1;
+ } else {
+ printf("Warning: Failed to attach to "
+ "wpa_supplicant.\n");
return -1;
+ }
}
}
OpenPOWER on IntegriCloud