]> git.ipfire.org Git - thirdparty/hostap.git/blobdiff - wpa_supplicant/wpa_cli.c
Disallow WEP configuration in WPA network
[thirdparty/hostap.git] / wpa_supplicant / wpa_cli.c
index 0727e921b2c7dd210ea0992996f754c6622cbfd8..5e6643fcd7e7f82e06dbcc3bc20cb3be1348c06c 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * WPA Supplicant - command line interface for wpa_supplicant daemon
- * Copyright (c) 2004-2012, Jouni Malinen <j@w1.fi>
+ * Copyright (c) 2004-2013, Jouni Malinen <j@w1.fi>
  *
  * This software may be distributed under the terms of the BSD license.
  * See README for more details.
@@ -81,6 +81,7 @@ 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;
 
 struct cli_txt_entry {
        struct dl_list list;
@@ -90,6 +91,7 @@ struct cli_txt_entry {
 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 void print_help(const char *cmd);
@@ -404,6 +406,12 @@ static int _wpa_ctrl_command(struct wpa_ctrl *ctrl, char *cmd, int print)
                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);
@@ -2825,9 +2833,12 @@ static char ** wpa_list_cmd_list(void)
 {
        char **res;
        int i, count;
+       struct cli_txt_entry *e;
 
        count = sizeof(wpa_cli_commands) / sizeof(wpa_cli_commands[0]);
-       res = os_calloc(count, sizeof(char *));
+       count += dl_list_len(&p2p_groups);
+       count += dl_list_len(&ifnames);
+       res = os_calloc(count + 1, sizeof(char *));
        if (res == NULL)
                return NULL;
 
@@ -2837,6 +2848,22 @@ static char ** wpa_list_cmd_list(void)
                        break;
        }
 
+       dl_list_for_each(e, &p2p_groups, struct cli_txt_entry, list) {
+               size_t len = 8 + os_strlen(e->txt);
+               res[i] = os_malloc(len);
+               if (res[i] == NULL)
+                       break;
+               os_snprintf(res[i], len, "ifname=%s", e->txt);
+               i++;
+       }
+
+       dl_list_for_each(e, &ifnames, struct cli_txt_entry, list) {
+               res[i] = os_strdup(e->txt);
+               if (res[i] == NULL)
+                       break;
+               i++;
+       }
+
        return res;
 }
 
@@ -2868,6 +2895,14 @@ static char ** wpa_cli_edit_completion_cb(void *ctx, const char *str, int pos)
        const char *end;
        char *cmd;
 
+       if (pos > 7 && os_strncasecmp(str, "IFNAME=", 7) == 0) {
+               end = os_strchr(str, ' ');
+               if (end && pos > end - str) {
+                       pos -= end - str + 1;
+                       str = end + 1;
+               }
+       }
+
        end = os_strchr(str, ' ');
        if (end == NULL || str + pos < end)
                return wpa_list_cmd_list();
@@ -2889,6 +2924,16 @@ static int wpa_request(struct wpa_ctrl *ctrl, int argc, char *argv[])
        int count;
        int ret = 0;
 
+       if (argc > 1 && os_strncasecmp(argv[0], "IFNAME=", 7) == 0) {
+               ifname_prefix = argv[0] + 7;
+               argv = &argv[1];
+               argc--;
+       } else
+               ifname_prefix = NULL;
+
+       if (argc == 0)
+               return -1;
+
        count = 0;
        cmd = wpa_cli_commands;
        while (cmd->cmd) {
@@ -3036,6 +3081,8 @@ static void wpa_cli_action_process(const char *msg)
                wpa_cli_exec(action_file, ctrl_ifname, pos);
        } else if (str_match(pos, AP_STA_DISCONNECTED)) {
                wpa_cli_exec(action_file, ctrl_ifname, pos);
+       } else if (str_match(pos, ESS_DISASSOC_IMMINENT)) {
+               wpa_cli_exec(action_file, ctrl_ifname, pos);
        } else if (str_match(pos, WPA_EVENT_TERMINATING)) {
                printf("wpa_supplicant is terminating - stop monitoring\n");
                wpa_cli_quit = 1;
@@ -3328,8 +3375,43 @@ static void update_bssid_list(struct wpa_ctrl *ctrl)
 }
 
 
+static void update_ifnames(struct wpa_ctrl *ctrl)
+{
+       char buf[4096];
+       size_t len = sizeof(buf);
+       int ret;
+       char *cmd = "INTERFACES";
+       char *pos, *end;
+       char txt[200];
+
+       cli_txt_list_flush(&ifnames);
+
+       if (ctrl == NULL)
+               return;
+       ret = wpa_ctrl_request(ctrl, cmd, os_strlen(cmd), buf, &len, NULL);
+       if (ret < 0)
+               return;
+       buf[len] = '\0';
+
+       pos = buf;
+       while (pos) {
+               end = os_strchr(pos, '\n');
+               if (end == NULL)
+                       break;
+               *end = '\0';
+               ret = os_snprintf(txt, sizeof(txt), "ifname=%s", pos);
+               if (ret > 0 && ret < (int) sizeof(txt))
+                       cli_txt_list_add(&ifnames, txt);
+               pos = end + 1;
+       }
+}
+
+
 static void try_connection(void *eloop_ctx, void *timeout_ctx)
 {
+       if (ctrl_conn)
+               goto done;
+
        if (ctrl_ifname == NULL)
                ctrl_ifname = wpa_cli_get_default_ifname();
 
@@ -3348,6 +3430,7 @@ static void try_connection(void *eloop_ctx, void *timeout_ctx)
        if (warning_displayed)
                printf("Connection established.\n");
 
+done:
        start_edit();
 }
 
@@ -3363,6 +3446,7 @@ static void wpa_cli_interactive(void)
        cli_txt_list_flush(&p2p_peers);
        cli_txt_list_flush(&p2p_groups);
        cli_txt_list_flush(&bsses);
+       cli_txt_list_flush(&ifnames);
        if (edit_started)
                edit_deinit(hfile, wpa_cli_edit_filter_history_cb);
        os_free(hfile);
@@ -3469,7 +3553,7 @@ static char * wpa_cli_get_default_ifname(void)
 #endif /* CONFIG_CTRL_IFACE_UNIX */
 
 #ifdef CONFIG_CTRL_IFACE_NAMED_PIPE
-       char buf[2048], *pos;
+       char buf[4096], *pos;
        size_t len;
        struct wpa_ctrl *ctrl;
        int ret;
@@ -3563,6 +3647,24 @@ int main(int argc, char *argv[])
                                global, strerror(errno));
                        return -1;
                }
+
+               if (interactive) {
+                       update_ifnames(ctrl_conn);
+                       mon_conn = wpa_ctrl_open(global);
+                       if (mon_conn) {
+                               if (wpa_ctrl_attach(mon_conn) == 0) {
+                                       wpa_cli_attached = 1;
+                                       eloop_register_read_sock(
+                                               wpa_ctrl_get_fd(mon_conn),
+                                               wpa_cli_mon_receive,
+                                               NULL, NULL);
+                               } else {
+                                       printf("Failed to open monitor "
+                                              "connection through global "
+                                              "control interface\n");
+                               }
+                       }
+               }
        }
 
        eloop_register_signal_terminate(wpa_cli_terminate, NULL);