]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
wpa_cli: Allow IFNAME= prefix to be used
authorJouni Malinen <j@w1.fi>
Thu, 23 May 2013 17:04:17 +0000 (20:04 +0300)
committerJouni Malinen <j@w1.fi>
Thu, 23 May 2013 17:04:17 +0000 (20:04 +0300)
Strip out the IFNAME=<ifname> prefix from commands before parsing them
through the normal processing and then add the prefix back to the
beginning of the actual control interface command to make per-interface
commands work through the global control interface without having to use
the 'raw' command.

Signed-hostap: Jouni Malinen <j@w1.fi>

wpa_supplicant/wpa_cli.c

index 9a17b84fadd0ad5162ac02d0f855c081ac47668c..20b699cf42e4975578e5bbd846a3cef7d3b049f8 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;
@@ -404,6 +405,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);
@@ -2889,6 +2896,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) {