commit 8fd8852bf1b331d564d49ed4823fb575f896c775
parent 86e8b8c322a64784efea6eed49a399e240fb67fb
Author: Denis Kenzior <denkenz@gmail.com>
Date: Fri, 14 Sep 2018 21:33:40 -0500
client: Move device connect method to station
Diffstat:
3 files changed, 66 insertions(+), 59 deletions(-)
diff --git a/client/device.c b/client/device.c
@@ -440,7 +440,7 @@ static void device_set_default(const char *device_name)
l_queue_destroy(match, NULL);
}
-static const struct proxy_interface *device_get_default(void)
+const struct proxy_interface *device_get_default(void)
{
struct l_queue *match;
@@ -459,7 +459,7 @@ static const struct proxy_interface *device_get_default(void)
return default_device;
}
-static const struct proxy_interface *device_proxy_find_by_name(const char *name)
+const struct proxy_interface *device_proxy_find_by_name(const char *name)
{
struct l_queue *match;
struct proxy_interface *proxy = NULL;
@@ -574,48 +574,6 @@ static enum cmd_status cmd_set_property(const char *device_name,
return CMD_STATUS_TRIGGERED;
}
-static enum cmd_status cmd_connect(const char *device_name,
- char **argv, int argc)
-{
- struct network_args network_args;
- struct l_queue *match;
- const struct proxy_interface *network_proxy;
- const struct proxy_interface *device_proxy =
- device_proxy_find_by_name(device_name);
-
- if (!device_proxy)
- return CMD_STATUS_INVALID_VALUE;
-
- if (argc < 1)
- return CMD_STATUS_INVALID_ARGS;
-
- network_args.name = argv[0];
- network_args.type = argc >= 2 ? argv[1] : NULL;
-
- match = network_match_by_device_and_args(device_proxy, &network_args);
- if (!match) {
- display("Invalid network name '%s'\n", network_args.name);
- return CMD_STATUS_INVALID_VALUE;
- }
-
- if (l_queue_length(match) > 1) {
- if (!network_args.type) {
- display("Provided network name is ambiguous. "
- "Please specify security type.\n");
- }
-
- l_queue_destroy(match, NULL);
-
- return CMD_STATUS_INVALID_VALUE;
- }
-
- network_proxy = l_queue_pop_head(match);
- l_queue_destroy(match, NULL);
- network_connect(network_proxy);
-
- return CMD_STATUS_TRIGGERED;
-}
-
static char *get_networks_cmd_arg_completion(const char *text, int state)
{
static int index;
@@ -635,16 +593,6 @@ static char *get_networks_cmd_arg_completion(const char *text, int state)
return NULL;
}
-static char *connect_cmd_arg_completion(const char *text, int state)
-{
- const struct proxy_interface *device = device_get_default();
-
- if (!device)
- return NULL;
-
- return network_name_completion(device, text, state);
-}
-
static char *set_property_cmd_arg_completion(const char *text, int state)
{
return proxy_property_completion(device_properties, text, state);
@@ -663,11 +611,6 @@ static const struct command device_commands[] = {
cmd_set_property,
"Set property", false,
set_property_cmd_arg_completion },
- { "<wlan>", "connect",
- "<\"network name\"> [security]",
- cmd_connect,
- "Connect to network", false,
- connect_cmd_arg_completion },
{ }
};
diff --git a/client/device.h b/client/device.h
@@ -27,5 +27,7 @@ char *device_ap_family_arg_completion(const char *text, int state);
char *device_ad_hoc_family_arg_completion(const char *text, int state);
char *device_station_family_arg_completion(const char *text, int state);
+const struct proxy_interface *device_proxy_find_by_name(const char *name);
const struct proxy_interface *device_proxy_find(const char *device_name,
const char *interface);
+const struct proxy_interface *device_get_default(void);
diff --git a/client/station.c b/client/station.c
@@ -29,6 +29,7 @@
#include "command.h"
#include "dbus-proxy.h"
#include "device.h"
+#include "network.h"
#include "display.h"
struct station {
@@ -185,6 +186,62 @@ static enum cmd_status cmd_list(const char *device_name, char **argv, int argc)
return CMD_STATUS_DONE;
}
+static char *connect_cmd_arg_completion(const char *text, int state)
+{
+ const struct proxy_interface *device = device_get_default();
+
+ if (!device)
+ return NULL;
+
+ return network_name_completion(device, text, state);
+}
+
+static enum cmd_status cmd_connect(const char *device_name,
+ char **argv, int argc)
+{
+ const struct proxy_interface *station_i;
+ struct network_args network_args;
+ struct l_queue *match;
+ const struct proxy_interface *network_proxy;
+ const struct proxy_interface *device_proxy;
+
+ if (argc < 1)
+ return CMD_STATUS_INVALID_ARGS;
+
+ station_i = device_proxy_find(device_name, IWD_STATION_INTERFACE);
+ if (!station_i) {
+ display("No station on device: '%s'\n", device_name);
+ return CMD_STATUS_INVALID_VALUE;
+ }
+
+ device_proxy = device_proxy_find_by_name(device_name);
+ network_args.name = argv[0];
+ network_args.type = argc >= 2 ? argv[1] : NULL;
+
+ match = network_match_by_device_and_args(device_proxy, &network_args);
+ if (!match) {
+ display("Invalid network name '%s'\n", network_args.name);
+ return CMD_STATUS_INVALID_VALUE;
+ }
+
+ if (l_queue_length(match) > 1) {
+ if (!network_args.type) {
+ display("Provided network name is ambiguous. "
+ "Please specify security type.\n");
+ }
+
+ l_queue_destroy(match, NULL);
+
+ return CMD_STATUS_INVALID_VALUE;
+ }
+
+ network_proxy = l_queue_pop_head(match);
+ l_queue_destroy(match, NULL);
+ network_connect(network_proxy);
+
+ return CMD_STATUS_TRIGGERED;
+}
+
static enum cmd_status cmd_connect_hidden_network(const char *device_name,
char **argv,
int argc)
@@ -243,6 +300,11 @@ static enum cmd_status cmd_scan(const char *device_name,
static const struct command station_commands[] = {
{ NULL, "list", NULL, cmd_list, "List Ad-Hoc devices", true },
+ { "<wlan>", "connect",
+ "<\"network name\"> [security]",
+ cmd_connect,
+ "Connect to network", false,
+ connect_cmd_arg_completion },
{ "<wlan>", "connect-hidden",
"<\"network name\">",
cmd_connect_hidden_network,