Allow wpa_cli/hostapd_cli client socket directory to be specified
This adds a new helper function wpa_ctrl_open2() that can be used instead of wpa_ctrl_open() to override the default client socket directory. Add optional -s<directory path> argument to hostapd_cli and wpa_cli to allow the client socket directory to be specified. Signed-off-by: Jouni Malinen <jouni@qca.qualcomm.com>
This commit is contained in:
parent
89a72e1c7f
commit
4ae7120919
4 changed files with 65 additions and 10 deletions
|
@ -97,6 +97,7 @@ static int hostapd_cli_attached = 0;
|
||||||
#define CONFIG_CTRL_IFACE_DIR "/var/run/hostapd"
|
#define CONFIG_CTRL_IFACE_DIR "/var/run/hostapd"
|
||||||
#endif /* CONFIG_CTRL_IFACE_DIR */
|
#endif /* CONFIG_CTRL_IFACE_DIR */
|
||||||
static const char *ctrl_iface_dir = 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 char *ctrl_ifname = NULL;
|
||||||
static const char *pid_file = NULL;
|
static const char *pid_file = NULL;
|
||||||
|
@ -119,6 +120,8 @@ static void usage(void)
|
||||||
" -v shown version information\n"
|
" -v shown version information\n"
|
||||||
" -p<path> path to find control sockets (default: "
|
" -p<path> path to find control sockets (default: "
|
||||||
"/var/run/hostapd)\n"
|
"/var/run/hostapd)\n"
|
||||||
|
" -s<dir_path> dir path to open client sockets (default: "
|
||||||
|
CONFIG_CTRL_IFACE_DIR ")\n"
|
||||||
" -a<file> run in daemon mode executing the action file "
|
" -a<file> run in daemon mode executing the action file "
|
||||||
"based on events\n"
|
"based on events\n"
|
||||||
" from hostapd\n"
|
" from hostapd\n"
|
||||||
|
@ -145,7 +148,14 @@ static struct wpa_ctrl * hostapd_cli_open_connection(const char *ifname)
|
||||||
return NULL;
|
return NULL;
|
||||||
snprintf(cfile, flen, "%s/%s", ctrl_iface_dir, ifname);
|
snprintf(cfile, flen, "%s/%s", ctrl_iface_dir, ifname);
|
||||||
|
|
||||||
ctrl_conn = wpa_ctrl_open(cfile);
|
if (client_socket_dir && client_socket_dir[0] &&
|
||||||
|
access(client_socket_dir, F_OK) < 0) {
|
||||||
|
perror(client_socket_dir);
|
||||||
|
free(cfile);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
ctrl_conn = wpa_ctrl_open2(cfile, client_socket_dir);
|
||||||
free(cfile);
|
free(cfile);
|
||||||
return ctrl_conn;
|
return ctrl_conn;
|
||||||
}
|
}
|
||||||
|
@ -1337,7 +1347,7 @@ int main(int argc, char *argv[])
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
for (;;) {
|
for (;;) {
|
||||||
c = getopt(argc, argv, "a:BhG:i:p:P:v");
|
c = getopt(argc, argv, "a:BhG:i:p:P:s:v");
|
||||||
if (c < 0)
|
if (c < 0)
|
||||||
break;
|
break;
|
||||||
switch (c) {
|
switch (c) {
|
||||||
|
@ -1366,6 +1376,9 @@ int main(int argc, char *argv[])
|
||||||
case 'P':
|
case 'P':
|
||||||
pid_file = optarg;
|
pid_file = optarg;
|
||||||
break;
|
break;
|
||||||
|
case 's':
|
||||||
|
client_socket_dir = optarg;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
usage();
|
usage();
|
||||||
return -1;
|
return -1;
|
||||||
|
|
|
@ -84,6 +84,13 @@ struct wpa_ctrl {
|
||||||
|
|
||||||
|
|
||||||
struct wpa_ctrl * wpa_ctrl_open(const char *ctrl_path)
|
struct wpa_ctrl * wpa_ctrl_open(const char *ctrl_path)
|
||||||
|
{
|
||||||
|
return wpa_ctrl_open2(ctrl_path, NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
struct wpa_ctrl * wpa_ctrl_open2(const char *ctrl_path,
|
||||||
|
const char *cli_path)
|
||||||
{
|
{
|
||||||
struct wpa_ctrl *ctrl;
|
struct wpa_ctrl *ctrl;
|
||||||
static int counter = 0;
|
static int counter = 0;
|
||||||
|
@ -108,10 +115,18 @@ struct wpa_ctrl * wpa_ctrl_open(const char *ctrl_path)
|
||||||
ctrl->local.sun_family = AF_UNIX;
|
ctrl->local.sun_family = AF_UNIX;
|
||||||
counter++;
|
counter++;
|
||||||
try_again:
|
try_again:
|
||||||
ret = os_snprintf(ctrl->local.sun_path, sizeof(ctrl->local.sun_path),
|
if (cli_path && cli_path[0] == '/') {
|
||||||
CONFIG_CTRL_IFACE_CLIENT_DIR "/"
|
ret = os_snprintf(ctrl->local.sun_path,
|
||||||
CONFIG_CTRL_IFACE_CLIENT_PREFIX "%d-%d",
|
sizeof(ctrl->local.sun_path),
|
||||||
(int) getpid(), counter);
|
"%s/" CONFIG_CTRL_IFACE_CLIENT_PREFIX "%d-%d",
|
||||||
|
cli_path, (int) getpid(), counter);
|
||||||
|
} else {
|
||||||
|
ret = os_snprintf(ctrl->local.sun_path,
|
||||||
|
sizeof(ctrl->local.sun_path),
|
||||||
|
CONFIG_CTRL_IFACE_CLIENT_DIR "/"
|
||||||
|
CONFIG_CTRL_IFACE_CLIENT_PREFIX "%d-%d",
|
||||||
|
(int) getpid(), counter);
|
||||||
|
}
|
||||||
if (os_snprintf_error(sizeof(ctrl->local.sun_path), ret)) {
|
if (os_snprintf_error(sizeof(ctrl->local.sun_path), ret)) {
|
||||||
close(ctrl->s);
|
close(ctrl->s);
|
||||||
os_free(ctrl);
|
os_free(ctrl);
|
||||||
|
|
|
@ -316,6 +316,20 @@ enum wpa_vendor_elem_frame {
|
||||||
*/
|
*/
|
||||||
struct wpa_ctrl * wpa_ctrl_open(const char *ctrl_path);
|
struct wpa_ctrl * wpa_ctrl_open(const char *ctrl_path);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* wpa_ctrl_open2 - Open a control interface to wpa_supplicant/hostapd
|
||||||
|
* @ctrl_path: Path for UNIX domain sockets; ignored if UDP sockets are used.
|
||||||
|
* @cli_path: Path for client UNIX domain sockets; ignored if UDP socket
|
||||||
|
* is used.
|
||||||
|
* Returns: Pointer to abstract control interface data or %NULL on failure
|
||||||
|
*
|
||||||
|
* This function is used to open a control interface to wpa_supplicant/hostapd
|
||||||
|
* when the socket path for client need to be specified explicitly. Default
|
||||||
|
* ctrl_path is usually /var/run/wpa_supplicant or /var/run/hostapd and client
|
||||||
|
* socket path is /tmp.
|
||||||
|
*/
|
||||||
|
struct wpa_ctrl * wpa_ctrl_open2(const char *ctrl_path, const char *cli_path);
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* wpa_ctrl_close - Close a control interface to wpa_supplicant/hostapd
|
* wpa_ctrl_close - Close a control interface to wpa_supplicant/hostapd
|
||||||
|
|
|
@ -76,6 +76,7 @@ static int wpa_cli_last_id = 0;
|
||||||
#define CONFIG_CTRL_IFACE_DIR "/var/run/wpa_supplicant"
|
#define CONFIG_CTRL_IFACE_DIR "/var/run/wpa_supplicant"
|
||||||
#endif /* CONFIG_CTRL_IFACE_DIR */
|
#endif /* CONFIG_CTRL_IFACE_DIR */
|
||||||
static const char *ctrl_iface_dir = 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 char *ctrl_ifname = NULL;
|
||||||
static const char *pid_file = NULL;
|
static const char *pid_file = NULL;
|
||||||
static const char *action_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] "
|
printf("wpa_cli [-p<path to ctrl sockets>] [-i<ifname>] [-hvB] "
|
||||||
"[-a<action file>] \\\n"
|
"[-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"
|
"[command..]\n"
|
||||||
" -h = help (show this usage text)\n"
|
" -h = help (show this usage text)\n"
|
||||||
" -v = shown version information\n"
|
" -v = shown version information\n"
|
||||||
|
@ -330,6 +333,13 @@ static int wpa_cli_open_connection(const char *ifname, int attach)
|
||||||
}
|
}
|
||||||
#endif /* ANDROID */
|
#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) {
|
if (cfile == NULL) {
|
||||||
flen = os_strlen(ctrl_iface_dir) + os_strlen(ifname) + 2;
|
flen = os_strlen(ctrl_iface_dir) + os_strlen(ifname) + 2;
|
||||||
cfile = os_malloc(flen);
|
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) {
|
if (ctrl_conn == NULL) {
|
||||||
os_free(cfile);
|
os_free(cfile);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (attach && interactive)
|
if (attach && interactive)
|
||||||
mon_conn = wpa_ctrl_open(cfile);
|
mon_conn = wpa_ctrl_open2(cfile, client_socket_dir);
|
||||||
else
|
else
|
||||||
mon_conn = NULL;
|
mon_conn = NULL;
|
||||||
os_free(cfile);
|
os_free(cfile);
|
||||||
|
@ -4255,7 +4265,7 @@ int main(int argc, char *argv[])
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
for (;;) {
|
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)
|
if (c < 0)
|
||||||
break;
|
break;
|
||||||
switch (c) {
|
switch (c) {
|
||||||
|
@ -4287,6 +4297,9 @@ int main(int argc, char *argv[])
|
||||||
case 'P':
|
case 'P':
|
||||||
pid_file = optarg;
|
pid_file = optarg;
|
||||||
break;
|
break;
|
||||||
|
case 's':
|
||||||
|
client_socket_dir = optarg;
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
usage();
|
usage();
|
||||||
return -1;
|
return -1;
|
||||||
|
|
Loading…
Reference in a new issue