Merge hostapd driver init functions into one
[wpasupplicant] / wpa_supplicant / wpa_cli.c
index c36277a..73937d7 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * WPA Supplicant - command line interface for wpa_supplicant daemon
- * Copyright (c) 2004-2008, Jouni Malinen <j@w1.fi>
+ * Copyright (c) 2004-2009, 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
@@ -31,7 +31,7 @@
 
 static const char *wpa_cli_version =
 "wpa_cli v" VERSION_STR "\n"
-"Copyright (c) 2004-2008, Jouni Malinen <j@w1.fi> and contributors";
+"Copyright (c) 2004-2009, Jouni Malinen <j@w1.fi> and contributors";
 
 
 static const char *wpa_cli_license =
@@ -95,6 +95,7 @@ static const char *ctrl_iface_dir = "/var/run/wpa_supplicant";
 static char *ctrl_ifname = NULL;
 static const char *pid_file = NULL;
 static const char *action_file = NULL;
+static int ping_interval = 5;
 
 
 static void print_help();
@@ -104,7 +105,8 @@ 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>]  [command..]\n"
+              "        [-P<pid file>] [-g<global ctrl>] [-G<ping interval>]  "
+              "[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 "
@@ -444,6 +446,39 @@ 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];
@@ -465,6 +500,26 @@ static int wpa_cli_cmd_wps_reg(struct wpa_ctrl *ctrl, int argc, char *argv[])
 }
 
 
+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];
@@ -1236,9 +1291,17 @@ 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" },
+       { "ibss_rsn", wpa_cli_cmd_ibss_rsn,
+         cli_cmd_flag_none,
+         "<addr> = request RSN authentication with <addr> in IBSS" },
        { NULL, NULL, cli_cmd_flag_none, NULL }
 };
 
@@ -1563,7 +1626,7 @@ static void wpa_cli_interactive(void)
        do {
                wpa_cli_recv_pending(ctrl_conn, 0, 0);
 #ifndef CONFIG_NATIVE_WINDOWS
-               alarm(1);
+               alarm(ping_interval);
 #endif /* CONFIG_NATIVE_WINDOWS */
 #ifdef CONFIG_READLINE
                cmd = readline("> ");
@@ -1667,7 +1730,7 @@ static void wpa_cli_action(struct wpa_ctrl *ctrl)
        while (!wpa_cli_quit) {
                FD_ZERO(&rfds);
                FD_SET(fd, &rfds);
-               tv.tv_sec = 2;
+               tv.tv_sec = ping_interval;
                tv.tv_usec = 0;
                res = select(fd + 1, &rfds, NULL, NULL, &tv);
                if (res < 0 && errno != EINTR) {
@@ -1721,7 +1784,7 @@ static void wpa_cli_alarm(int sig)
                wpa_cli_reconnect();
        if (ctrl_conn)
                wpa_cli_recv_pending(ctrl_conn, 1, 0);
-       alarm(1);
+       alarm(ping_interval);
 }
 #endif /* CONFIG_NATIVE_WINDOWS */
 
@@ -1794,7 +1857,7 @@ int main(int argc, char *argv[])
                return -1;
 
        for (;;) {
-               c = getopt(argc, argv, "a:Bg:hi:p:P:v");
+               c = getopt(argc, argv, "a:Bg:G:hi:p:P:v");
                if (c < 0)
                        break;
                switch (c) {
@@ -1807,6 +1870,9 @@ int main(int argc, char *argv[])
                case 'g':
                        global = optarg;
                        break;
+               case 'G':
+                       ping_interval = atoi(optarg);
+                       break;
                case 'h':
                        usage();
                        return 0;