Allow wpa_cli/hostapd_cli client socket directory to be specified
[mech_eap.git] / wpa_supplicant / wpa_cli.c
index 2d1adc9..7ddae3d 100644 (file)
@@ -76,6 +76,7 @@ static int wpa_cli_last_id = 0;
 #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 *pid_file = NULL;
 static const char *action_file = NULL;
@@ -107,7 +108,9 @@ 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>]  "
+              "        [-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"
@@ -330,6 +333,13 @@ static int wpa_cli_open_connection(const char *ifname, int attach)
        }
 #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);
@@ -343,14 +353,14 @@ static int wpa_cli_open_connection(const char *ifname, int attach)
                }
        }
 
-       ctrl_conn = wpa_ctrl_open(cfile);
+       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_open(cfile);
+               mon_conn = wpa_ctrl_open2(cfile, client_socket_dir);
        else
                mon_conn = NULL;
        os_free(cfile);
@@ -502,6 +512,10 @@ static int wpa_cli_cmd_status(struct wpa_ctrl *ctrl, int argc, char *argv[])
                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");
 }
 
@@ -618,6 +632,7 @@ static char ** wpa_cli_complete_set(const char *str, int pos)
                "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",
@@ -2801,6 +2816,13 @@ static int wpa_cli_cmd_mac_rand_scan(struct wpa_ctrl *ctrl, int argc,
 }
 
 
+static int wpa_cli_cmd_get_pref_freq_list(struct wpa_ctrl *ctrl, int argc,
+                                         char *argv[])
+{
+       return wpa_cli_cmd(ctrl, "GET_PREF_FREQ_LIST", 1, argc, argv);
+}
+
+
 enum wpa_cli_cmd_flags {
        cli_cmd_flag_none               = 0x00,
        cli_cmd_flag_sensitive          = 0x01
@@ -3355,6 +3377,9 @@ static const struct wpa_cli_cmd wpa_cli_commands[] = {
          "<scan|sched|pno|all> enable=<0/1> [addr=mac-address "
          "mask=mac-address-mask] = scan MAC randomization"
        },
+       { "get_pref_freq_list", wpa_cli_cmd_get_pref_freq_list, NULL,
+         cli_cmd_flag_none,
+         "<interface type> = retrieve preferred freq list for the specified interface type" },
        { NULL, NULL, NULL, cli_cmd_flag_none, NULL }
 };
 
@@ -4169,18 +4194,17 @@ static char * wpa_cli_get_default_ifname(void)
 {
        char *ifname = NULL;
 
+#ifdef ANDROID
+       char ifprop[PROPERTY_VALUE_MAX];
+       if (property_get("wifi.interface", ifprop, NULL) != 0) {
+               ifname = os_strdup(ifprop);
+               printf("Using interface '%s'\n", ifname ? ifname : "N/A");
+       }
+#else /* ANDROID */
 #ifdef CONFIG_CTRL_IFACE_UNIX
        struct dirent *dent;
        DIR *dir = opendir(ctrl_iface_dir);
        if (!dir) {
-#ifdef ANDROID
-               char ifprop[PROPERTY_VALUE_MAX];
-               if (property_get("wifi.interface", ifprop, NULL) != 0) {
-                       ifname = os_strdup(ifprop);
-                       printf("Using interface '%s'\n", ifname);
-                       return ifname;
-               }
-#endif /* ANDROID */
                return NULL;
        }
        while ((dent = readdir(dir))) {
@@ -4224,6 +4248,7 @@ static char * wpa_cli_get_default_ifname(void)
        }
        wpa_ctrl_close(ctrl);
 #endif /* CONFIG_CTRL_IFACE_NAMED_PIPE */
+#endif /* ANDROID */
 
        return ifname;
 }
@@ -4240,7 +4265,7 @@ int main(int argc, char *argv[])
                return -1;
 
        for (;;) {
-               c = getopt(argc, argv, "a:Bg:G:hi:p:P:v");
+               c = getopt(argc, argv, "a:Bg:G:hi:p:P:s:v");
                if (c < 0)
                        break;
                switch (c) {
@@ -4272,6 +4297,9 @@ int main(int argc, char *argv[])
                case 'P':
                        pid_file = optarg;
                        break;
+               case 's':
+                       client_socket_dir = optarg;
+                       break;
                default:
                        usage();
                        return -1;