* [PATCH v3 2/6] station: add debug method GetNetworks
2022-08-11 18:47 [PATCH v3 1/6] doc: add documentation for StationDebug James Prestwood
@ 2022-08-11 18:47 ` James Prestwood
2022-08-11 18:47 ` [PATCH v3 3/6] client: allow entity name to be passed to completion James Prestwood
` (4 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: James Prestwood @ 2022-08-11 18:47 UTC (permalink / raw)
To: iwd; +Cc: James Prestwood
This gets all networks but includes individual entries for each
BSS.
---
src/station.c | 87 +++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 87 insertions(+)
v3:
* Removed hidden networks from the list. GetHiddenAccessPoints could
be used instead.
diff --git a/src/station.c b/src/station.c
index 57dbd0d5..66b296b8 100644
--- a/src/station.c
+++ b/src/station.c
@@ -4600,6 +4600,90 @@ static struct l_dbus_message *station_property_set_autoconnect(
return l_dbus_message_new_method_return(message);
}
+static void station_append_byte_array(struct l_dbus_message_builder *builder,
+ const char *name,
+ const uint8_t *bytes, size_t len)
+{
+ size_t i;
+
+ l_dbus_message_builder_enter_dict(builder, "sv");
+ l_dbus_message_builder_append_basic(builder, 's', name);
+ l_dbus_message_builder_enter_variant(builder, "ay");
+ l_dbus_message_builder_enter_array(builder, "y");
+
+ for (i = 0; i < len; i++)
+ l_dbus_message_builder_append_basic(builder, 'y', &bytes[i]);
+
+ l_dbus_message_builder_leave_array(builder);
+ l_dbus_message_builder_leave_variant(builder);
+ l_dbus_message_builder_leave_dict(builder);
+}
+
+static void station_append_bss_list(struct l_dbus_message_builder *builder,
+ const struct l_queue_entry *entry)
+{
+ for (; entry; entry = entry->next) {
+ struct scan_bss *bss = entry->data;
+ int32_t rssi = bss->signal_strength / 100;
+
+ l_dbus_message_builder_enter_array(builder, "{sv}");
+
+ dbus_append_dict_basic(builder, "Frequency", 'u',
+ &bss->frequency);
+ dbus_append_dict_basic(builder, "RSSI", 'i',
+ &rssi);
+ dbus_append_dict_basic(builder, "Rank", 'q', &bss->rank);
+
+ dbus_append_dict_basic(builder, "Address", 's',
+ util_address_to_string(bss->addr));
+
+ station_append_byte_array(builder, "MDE", bss->mde, 3);
+
+ l_dbus_message_builder_leave_array(builder);
+ }
+}
+
+static struct l_dbus_message *station_debug_get_networks(struct l_dbus *dbus,
+ struct l_dbus_message *message,
+ void *user_data)
+{
+ struct station *station = user_data;
+ struct l_dbus_message *reply =
+ l_dbus_message_new_method_return(message);
+ struct l_dbus_message_builder *builder =
+ l_dbus_message_builder_new(reply);
+ const struct l_queue_entry *entry;
+
+ l_dbus_message_builder_enter_array(builder, "{oaa{sv}}");
+
+ if (l_queue_isempty(station->networks_sorted))
+ goto done;
+
+ for (entry = l_queue_get_entries(station->networks_sorted); entry;
+ entry = entry->next) {
+ const struct network *network = entry->data;
+
+ l_dbus_message_builder_enter_dict(builder, "oaa{sv}");
+ l_dbus_message_builder_append_basic(builder, 'o',
+ network_get_path(network));
+ l_dbus_message_builder_enter_array(builder, "a{sv}");
+
+ station_append_bss_list(builder,
+ network_bss_list_get_entries(network));
+
+ l_dbus_message_builder_leave_array(builder);
+ l_dbus_message_builder_leave_dict(builder);
+ }
+
+done:
+ l_dbus_message_builder_leave_array(builder);
+
+ l_dbus_message_builder_finalize(builder);
+ l_dbus_message_builder_destroy(builder);
+
+ return reply;
+}
+
static void station_setup_debug_interface(
struct l_dbus_interface *interface)
{
@@ -4612,6 +4696,9 @@ static void station_setup_debug_interface(
l_dbus_interface_method(interface, "Scan", 0,
station_debug_scan, "", "aq",
"frequencies");
+ l_dbus_interface_method(interface, "GetNetworks", 0,
+ station_debug_get_networks, "a{oaa{sv}}", "",
+ "networks");
l_dbus_interface_signal(interface, "Event", 0, "sav", "name", "data");
--
2.34.3
^ permalink raw reply related [flat|nested] 7+ messages in thread* [PATCH v3 3/6] client: allow entity name to be passed to completion
2022-08-11 18:47 [PATCH v3 1/6] doc: add documentation for StationDebug James Prestwood
2022-08-11 18:47 ` [PATCH v3 2/6] station: add debug method GetNetworks James Prestwood
@ 2022-08-11 18:47 ` James Prestwood
2022-08-11 18:47 ` [PATCH v3 4/6] client: add station-debug command interface James Prestwood
` (3 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: James Prestwood @ 2022-08-11 18:47 UTC (permalink / raw)
To: iwd; +Cc: James Prestwood
There is a limitation of libreadline where no context/userdata
can be passed to completion functions. This effects iwctl since
the entity value isn't known to completion functions.
Workarounds such as getting the default device are employed but
its not a great solution.
Instead hack around this limitation by parsing the prompt to
extract the entity (second arg). Then use a generic match function
given to readline which can call the actual match function and
include the entity.
---
client/adapter.c | 3 ++-
client/command.c | 39 ++++++++++++++++++++++++++++++++++++++-
client/command.h | 9 ++++++---
client/device.c | 3 ++-
client/known-networks.c | 3 ++-
client/station.c | 6 ++++--
6 files changed, 54 insertions(+), 9 deletions(-)
diff --git a/client/adapter.c b/client/adapter.c
index 394eae0d..1719b970 100644
--- a/client/adapter.c
+++ b/client/adapter.c
@@ -319,7 +319,8 @@ static enum cmd_status cmd_set_property(const char *adapter_name,
return CMD_STATUS_TRIGGERED;
}
-static char *set_property_cmd_arg_completion(const char *text, int state)
+static char *set_property_cmd_arg_completion(const char *text, int state,
+ const char *phy)
{
return proxy_property_completion(adapter_properties, text, state);
}
diff --git a/client/command.c b/client/command.c
index c0576e97..46752c72 100644
--- a/client/command.c
+++ b/client/command.c
@@ -213,20 +213,57 @@ bool command_line_find_token(const char *token, uint8_t num_to_inspect)
return false;
}
+/*
+ * Work around readline limitations of not being able to pass a context pointer
+ * to match functions. Set the command match function/entity to these globals
+ * and call a generic match function which can call the _real_ match function
+ * and include the entity.
+ */
+static command_completion_func_t cmd_current_completion_func = NULL;
+static const char *cmd_current_entity = NULL;
+
+static char *cmd_completion_generic(const char *text, int state)
+{
+ return cmd_current_completion_func(text, state, cmd_current_entity);
+}
+
static char **cmd_completion_match_entity_cmd(const char *cmd, const char *text,
const struct command *cmd_list)
{
char **matches = NULL;
size_t i;
+ char *family = NULL;
+ char *entity = NULL;
+ char *prompt = NULL;
for (i = 0; cmd_list[i].cmd; i++) {
+ char *tmp;
+
if (strcmp(cmd_list[i].cmd, cmd))
continue;
if (!cmd_list[i].completion)
break;
- matches = rl_completion_matches(text, cmd_list[i].completion);
+ if (cmd_list[i].entity) {
+ prompt = rl_copy_text(0, rl_end);
+
+ family = strtok_r(prompt, " ", &tmp);
+ if (!family)
+ goto done;
+
+ entity = strtok_r(NULL, " ", &tmp);
+ }
+
+done:
+ cmd_current_completion_func = cmd_list[i].completion;
+ cmd_current_entity = entity;
+
+ matches = rl_completion_matches(text, cmd_completion_generic);
+
+ l_free(prompt);
+ cmd_current_completion_func = NULL;
+ cmd_current_entity = NULL;
break;
}
diff --git a/client/command.h b/client/command.h
index 23f23dc9..1f841689 100644
--- a/client/command.h
+++ b/client/command.h
@@ -25,7 +25,10 @@
#define COMMAND_OPTION_PASSPHRASE "passphrase"
#define COMMAND_OPTION_DONTASK "dont-ask"
-typedef char *(*command_completion_func_t) (const char *text, int state);
+typedef char *(*command_completion_func_t)(const char *text, int state,
+ const char *entity);
+typedef char *(*command_rl_completion_func_t)(const char *text, int state);
+
enum cmd_status {
CMD_STATUS_TRIGGERED,
@@ -51,8 +54,8 @@ struct command_family {
const char *caption;
const char *name;
const struct command *command_list;
- command_completion_func_t family_arg_completion;
- command_completion_func_t entity_arg_completion;
+ command_rl_completion_func_t family_arg_completion;
+ command_rl_completion_func_t entity_arg_completion;
void (*set_default_entity)(const char *entity);
void (*reset_default_entity)(void);
};
diff --git a/client/device.c b/client/device.c
index 9f8d731c..8b27ddd2 100644
--- a/client/device.c
+++ b/client/device.c
@@ -398,7 +398,8 @@ static enum cmd_status cmd_set_property(const char *device_name,
return CMD_STATUS_TRIGGERED;
}
-static char *set_property_cmd_arg_completion(const char *text, int state)
+static char *set_property_cmd_arg_completion(const char *text, int state,
+ const char *device_name)
{
return proxy_property_completion(device_properties, text, state);
}
diff --git a/client/known-networks.c b/client/known-networks.c
index 56c34a2e..b2023e35 100644
--- a/client/known-networks.c
+++ b/client/known-networks.c
@@ -387,7 +387,8 @@ static enum cmd_status cmd_set_property(const char *network_name,
return CMD_STATUS_TRIGGERED;
}
-static char *set_property_cmd_arg_completion(const char *text, int state)
+static char *set_property_cmd_arg_completion(const char *text, int state,
+ const char *network_name)
{
return proxy_property_completion(known_network_properties, text, state);
}
diff --git a/client/station.c b/client/station.c
index 64becdbd..90291c88 100644
--- a/client/station.c
+++ b/client/station.c
@@ -277,7 +277,8 @@ 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)
+static char *connect_cmd_arg_completion(const char *text, int state,
+ const char *device_name)
{
const struct proxy_interface *device = device_get_default();
@@ -489,7 +490,8 @@ static void ordered_networks_callback(struct l_dbus_message *message,
l_queue_destroy(networks, ordered_networks_destroy);
}
-static char *get_networks_cmd_arg_completion(const char *text, int state)
+static char *get_networks_cmd_arg_completion(const char *text, int state,
+ const char *device_name)
{
static int index;
static int len;
--
2.34.3
^ permalink raw reply related [flat|nested] 7+ messages in thread* [PATCH v3 4/6] client: add station-debug command interface
2022-08-11 18:47 [PATCH v3 1/6] doc: add documentation for StationDebug James Prestwood
2022-08-11 18:47 ` [PATCH v3 2/6] station: add debug method GetNetworks James Prestwood
2022-08-11 18:47 ` [PATCH v3 3/6] client: allow entity name to be passed to completion James Prestwood
@ 2022-08-11 18:47 ` James Prestwood
2022-08-11 18:47 ` [PATCH v3 5/6] client: fix station autocomplete with multiple phys James Prestwood
` (2 subsequent siblings)
5 siblings, 0 replies; 7+ messages in thread
From: James Prestwood @ 2022-08-11 18:47 UTC (permalink / raw)
To: iwd; +Cc: James Prestwood
This lets iwctl call methods on .StationDebug. The command
name is called 'debug'. This can only be used when IWD is
in developer mode
---
Makefile.am | 4 +-
client/station-debug.c | 443 +++++++++++++++++++++++++++++++++++++++++
2 files changed, 446 insertions(+), 1 deletion(-)
create mode 100644 client/station-debug.c
diff --git a/Makefile.am b/Makefile.am
index cffb0738..ed93d000 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -301,7 +301,9 @@ client_iwctl_SOURCES = client/main.c \
client/wsc.c client/station.c \
client/diagnostic.c client/diagnostic.h \
client/daemon.c client/daemon.h \
- client/dpp.c
+ client/dpp.c client/station-debug.c \
+ src/util.c src/util.h \
+ src/band.c src/band.h
client_iwctl_LDADD = $(ell_ldadd) $(READLINE_LIBS)
diff --git a/client/station-debug.c b/client/station-debug.c
new file mode 100644
index 00000000..181fd906
--- /dev/null
+++ b/client/station-debug.c
@@ -0,0 +1,443 @@
+#include <ell/ell.h>
+#include "ell/useful.h"
+
+#include "client/command.h"
+#include "client/dbus-proxy.h"
+#include "client/device.h"
+#include "client/display.h"
+#include "client/properties.h"
+#include "client/network.h"
+#include "src/util.h"
+
+struct station_debug {
+ struct l_queue *network_list;
+ bool autoconnect;
+};
+
+struct network {
+ char *ssid;
+ struct l_queue *bss_list;
+};
+
+struct bss {
+ char addr[18];
+ uint32_t frequency;
+ int8_t rssi;
+ int32_t rank;
+ uint8_t mde[3];
+};
+
+static void network_free(void *data)
+{
+ struct network *network = data;
+
+ l_queue_destroy(network->bss_list, l_free);
+}
+
+static void *station_debug_create(void)
+{
+ struct station_debug *debug = l_new(struct station_debug, 1);
+
+ debug->network_list = l_queue_new();
+
+ return debug;
+}
+
+static void station_debug_destroy(void *data)
+{
+ struct station_debug *debug = data;
+
+ l_queue_destroy(debug->network_list, network_free);
+
+ l_free(debug);
+}
+
+static void check_errors_method_callback(struct l_dbus_message *message,
+ void *user_data)
+{
+ dbus_message_has_error(message);
+}
+
+static enum cmd_status cmd_debug_connect(const char *device_name,
+ char **argv, int argc)
+{
+
+ const struct proxy_interface *debug_i;
+ uint8_t addr[6];
+
+ if (argc < 1)
+ return CMD_STATUS_INVALID_ARGS;
+
+ debug_i = device_proxy_find(device_name, IWD_STATION_DEBUG_INTERFACE);
+ if (!debug_i) {
+ display_error("IWD not in developer mode");
+ return CMD_STATUS_INVALID_VALUE;
+ }
+
+ if (!util_string_to_address(argv[0], addr))
+ return CMD_STATUS_INVALID_ARGS;
+
+ proxy_interface_method_call(debug_i, "ConnectBssid", "ay",
+ check_errors_method_callback, 6,
+ addr[0], addr[1], addr[2],
+ addr[3], addr[4], addr[5]);
+ return CMD_STATUS_TRIGGERED;
+}
+
+static enum cmd_status cmd_debug_roam(const char *device_name,
+ char **argv, int argc)
+{
+ const struct proxy_interface *debug_i;
+ uint8_t addr[6];
+
+ if (argc < 1)
+ return CMD_STATUS_INVALID_ARGS;
+
+ debug_i = device_proxy_find(device_name, IWD_STATION_DEBUG_INTERFACE);
+ if (!debug_i) {
+ display_error("IWD not in developer mode");
+ return CMD_STATUS_INVALID_VALUE;
+ }
+
+ if (!util_string_to_address(argv[0], addr))
+ return CMD_STATUS_INVALID_ARGS;
+
+ proxy_interface_method_call(debug_i, "Roam", "ay",
+ check_errors_method_callback, 6,
+ addr[0], addr[1], addr[2],
+ addr[3], addr[4], addr[5]);
+ return CMD_STATUS_TRIGGERED;
+}
+
+static void get_byte_array(struct l_dbus_message_iter *variant, uint8_t *out,
+ unsigned int len)
+{
+ struct l_dbus_message_iter array;
+ uint32_t elems = 6;
+ uint8_t *a;
+
+ if (!l_dbus_message_iter_get_variant(variant, "ay", &array))
+ goto error;
+
+ if (!l_dbus_message_iter_get_fixed_array(&array, &a, &elems))
+ goto error;
+
+ if (elems != len)
+ goto error;
+
+ memcpy(out, a, len);
+
+ return;
+
+error:
+ display_error("Invalid Address element");
+}
+
+static void get_address(struct l_dbus_message_iter *variant,
+ char addr_out[static 18])
+{
+ char *s;
+
+ if (!l_dbus_message_iter_get_variant(variant, "s", &s))
+ goto error;
+
+ if (strlen(s) != 17)
+ goto error;
+
+ strcpy(addr_out, s);
+
+ return;
+
+error:
+ display_error("Invalid Address element");
+}
+
+static uint32_t get_u32(struct l_dbus_message_iter *variant)
+{
+ uint32_t u32 = 0;
+
+ if (!l_dbus_message_iter_get_variant(variant, "u", &u32))
+ display_error("Invalid Frequency element");
+
+ return u32;
+}
+
+static uint32_t get_u16(struct l_dbus_message_iter *variant)
+{
+ uint32_t u16 = 0;
+
+ if (!l_dbus_message_iter_get_variant(variant, "q", &u16))
+ display_error("Invalid Frequency element");
+
+ return u16;
+}
+
+static uint32_t get_i32(struct l_dbus_message_iter *variant)
+{
+ int32_t i32 = 0;
+
+ if (!l_dbus_message_iter_get_variant(variant, "i", &i32))
+ display_error("Invalid Frequency element");
+
+ return i32;
+}
+
+static void display_bss(struct bss *bss)
+{
+ char row[128];
+
+ sprintf(row, "%s%-*s %s %-*i %-*u %-*i %02x%02x%02x",
+ MARGIN MARGIN, 4, "", bss->addr, 4, bss->rssi,
+ 6, bss->frequency, 8, bss->rank,
+ bss->mde[0], bss->mde[1], bss->mde[2]);
+
+ display("%s\n", row);
+
+ return;
+}
+
+static void get_networks_method_callback(struct l_dbus_message *message,
+ void *user_data)
+{
+ struct proxy_interface *debug_i = user_data;
+ struct station_debug *debug = proxy_interface_get_data(debug_i);
+ struct l_dbus_message_iter iter;
+ struct l_dbus_message_iter variant;
+ struct l_dbus_message_iter array;
+ struct l_dbus_message_iter dict;
+ const char *key;
+
+ if (dbus_message_has_error(message))
+ return;
+
+ if (!l_dbus_message_get_arguments(message, "a{oaa{sv}}", &iter)) {
+ l_error("Failed to parse GetDiagnostics message");
+ return;
+ }
+
+ display_table_header("Available Networks (debug)",
+ "%s%-*s %-*s %-*s %-*s %-*s %-*s %-*s",
+ "", 2, "", 4, "SSID", 17, "BSSID", 4, "RSSI",
+ 6, "Freq", 8, "Rank", 10, "MDE");
+
+ while (l_dbus_message_iter_next_entry(&iter, &key, &array)) {
+ struct network *network = l_new(struct network, 1);
+ const struct proxy_interface *net_i = network_get_proxy(key);
+
+ network->ssid = l_strdup(network_get_name(net_i));
+ network->bss_list = l_queue_new();
+
+ display_table_row(MARGIN MARGIN, 3, 32, network->ssid,
+ 18, "", 6, "");
+
+ while (l_dbus_message_iter_next_entry(&array, &dict)) {
+ struct bss *bss = l_new(struct bss, 1);
+
+ while (l_dbus_message_iter_next_entry(&dict, &key,
+ &variant)) {
+ if (!strcmp(key, "Address"))
+ get_address(&variant, bss->addr);
+ else if (!strcmp(key, "Frequency"))
+ bss->frequency = get_u32(&variant);
+ else if (!strcmp(key, "RSSI"))
+ bss->rssi = get_i32(&variant);
+ else if (!strcmp(key, "Rank"))
+ bss->rank = get_u16(&variant);
+ else if (!strcmp(key, "MDE"))
+ get_byte_array(&variant, bss->mde, 3);
+ }
+
+ display_bss(bss);
+
+ l_queue_push_tail(network->bss_list, bss);
+ }
+
+ l_queue_push_tail(debug->network_list, network);
+ }
+
+ display_table_footer();
+}
+
+static enum cmd_status cmd_debug_get_networks(const char *device_name,
+ char **argv, int argc)
+{
+ const struct proxy_interface *debug_i;
+
+ debug_i = device_proxy_find(device_name, IWD_STATION_DEBUG_INTERFACE);
+ if (!debug_i) {
+ display_error("IWD not in developer mode");
+ return CMD_STATUS_INVALID_VALUE;
+ }
+
+ proxy_interface_method_call(debug_i, "GetNetworks", "",
+ get_networks_method_callback);
+
+ return CMD_STATUS_TRIGGERED;
+}
+
+static char *connect_debug_cmd_arg_completion(const char *text, int state,
+ const char *device_name)
+{
+ const struct proxy_interface *debug_i;
+ struct station_debug *debug;
+ static const struct l_queue_entry *n_entry;
+ static const struct l_queue_entry *b_entry;
+ size_t len = strlen(text);
+
+ debug_i = device_proxy_find(device_name, IWD_STATION_DEBUG_INTERFACE);
+ if (!debug_i)
+ return NULL;
+
+ debug = proxy_interface_get_data(debug_i);
+
+ if (!state)
+ n_entry = l_queue_get_entries(debug->network_list);
+
+ while (n_entry) {
+ struct network *network = n_entry->data;
+
+ n_entry = n_entry->next;
+
+ if (!b_entry)
+ b_entry = l_queue_get_entries(network->bss_list);
+
+ while (b_entry) {
+ struct bss *bss = b_entry->data;
+
+ b_entry = b_entry->next;
+
+ if (len > strlen(bss->addr))
+ return NULL;
+
+ if (strncmp(text, bss->addr, len))
+ continue;
+
+ return l_strdup_printf(MAC, MAC_STR(bss->addr));
+ }
+ }
+
+ return NULL;
+}
+
+static const char *get_autoconnect_tostr(const void *data)
+{
+ const struct station_debug *debug = data;
+
+ return debug->autoconnect ? "on" : "off";
+}
+
+static void update_autoconnect(void *data, struct l_dbus_message_iter *variant)
+{
+ struct station_debug *debug = data;
+ bool value;
+
+ if (!l_dbus_message_iter_get_variant(variant, "b", &value)) {
+ debug->autoconnect = false;
+
+ return;
+ }
+
+ debug->autoconnect = value;
+}
+
+static const struct proxy_interface_property debug_properties[] = {
+ { "AutoConnect", "b", update_autoconnect, get_autoconnect_tostr, true,
+ properties_builder_append_on_off_variant,
+ properties_on_off_opts },
+ { }
+};
+
+static enum cmd_status cmd_debug_set_autoconnect(const char *device_name,
+ char **argv, int argc)
+{
+ const struct proxy_interface *proxy = device_proxy_find(device_name,
+ IWD_STATION_DEBUG_INTERFACE);
+
+ if (!proxy) {
+ display_error("IWD not in developer mode");
+ return CMD_STATUS_INVALID_VALUE;
+ }
+
+ if (argc != 1)
+ return CMD_STATUS_INVALID_ARGS;
+
+ if (!proxy_property_set(proxy, "AutoConnect", argv[0],
+ check_errors_method_callback))
+ return CMD_STATUS_INVALID_VALUE;
+
+ return CMD_STATUS_TRIGGERED;
+}
+
+static const struct command station_debug_commands[] = {
+ { "<wlan>", "connect", "<bssid>", cmd_debug_connect,
+ "Connect to a specific BSS", false,
+ connect_debug_cmd_arg_completion },
+ { "<wlan>", "roam", "<bssid>", cmd_debug_roam,
+ "Roam to a BSS", false },
+ { "<wlan>", "get-networks", NULL, cmd_debug_get_networks,
+ "Get networks", true },
+ { "<wlan>", "autoconnect", "on|off", cmd_debug_set_autoconnect,
+ "Set AutoConnect property", false },
+ { }
+};
+
+static char *family_debug_arg_completion(const char *text, int state)
+{
+ return device_arg_completion(text, state, station_debug_commands,
+ IWD_STATION_DEBUG_INTERFACE);
+}
+
+static char *entity_debug_arg_completion(const char *text, int state)
+{
+ return command_entity_arg_completion(text, state,
+ station_debug_commands);
+}
+
+static struct command_family station_debug_command_family = {
+ .caption = "Station Debug",
+ .name = "debug",
+ .command_list = station_debug_commands,
+ .family_arg_completion = family_debug_arg_completion,
+ .entity_arg_completion = entity_debug_arg_completion,
+};
+
+static int station_debug_command_family_init(void)
+{
+ command_family_register(&station_debug_command_family);
+
+ return 0;
+}
+
+static void station_debug_command_family_exit(void)
+{
+ command_family_unregister(&station_debug_command_family);
+}
+
+COMMAND_FAMILY(station_debug_command_family, station_debug_command_family_init,
+ station_debug_command_family_exit)
+
+static const struct proxy_interface_type_ops station_debug_ops = {
+ .create = station_debug_create,
+ .destroy = station_debug_destroy,
+};
+
+static struct proxy_interface_type station_debug_interface_type = {
+ .interface = IWD_STATION_DEBUG_INTERFACE,
+ .ops = &station_debug_ops,
+ .properties = debug_properties,
+};
+
+static int station_debug_interface_init(void)
+{
+ proxy_interface_type_register(&station_debug_interface_type);
+
+ return 0;
+}
+
+static void station_debug_interface_exit(void)
+{
+ proxy_interface_type_unregister(&station_debug_interface_type);
+}
+
+INTERFACE_TYPE(station_debug_interface_type, station_debug_interface_init,
+ station_debug_interface_exit)
--
2.34.3
^ permalink raw reply related [flat|nested] 7+ messages in thread* [PATCH v3 6/6] device: command: remove default device concept
2022-08-11 18:47 [PATCH v3 1/6] doc: add documentation for StationDebug James Prestwood
` (3 preceding siblings ...)
2022-08-11 18:47 ` [PATCH v3 5/6] client: fix station autocomplete with multiple phys James Prestwood
@ 2022-08-11 18:47 ` James Prestwood
2022-08-11 20:48 ` [PATCH v3 1/6] doc: add documentation for StationDebug Denis Kenzior
5 siblings, 0 replies; 7+ messages in thread
From: James Prestwood @ 2022-08-11 18:47 UTC (permalink / raw)
To: iwd; +Cc: James Prestwood
There was quite a bit of framework behind setting/resetting a default
device, which is now no longer needed.
---
client/command.c | 18 ----------------
client/command.h | 3 ---
client/dbus-proxy.c | 2 --
client/device.c | 50 ---------------------------------------------
4 files changed, 73 deletions(-)
diff --git a/client/command.c b/client/command.c
index 46752c72..dbd97703 100644
--- a/client/command.c
+++ b/client/command.c
@@ -329,9 +329,6 @@ static char **cmd_completion_match_family_cmd(const char *cmd_family,
break;
}
- if (family->set_default_entity)
- family->set_default_entity(arg1);
-
matches = cmd_completion_match_entity_cmd(arg2, text,
family->command_list);
@@ -663,21 +660,6 @@ int command_get_exit_status(void)
return exit_status;
}
-void command_reset_default_entities(void)
-{
- const struct l_queue_entry *entry;
-
- for (entry = l_queue_get_entries(command_families); entry;
- entry = entry->next) {
- struct command_family *family = entry->data;
-
- if (!family->reset_default_entity)
- continue;
-
- family->reset_default_entity();
- }
-}
-
void command_family_register(const struct command_family *family)
{
l_queue_push_tail(command_families, (void *) family);
diff --git a/client/command.h b/client/command.h
index 1f841689..96eefdec 100644
--- a/client/command.h
+++ b/client/command.h
@@ -56,8 +56,6 @@ struct command_family {
const struct command *command_list;
command_rl_completion_func_t family_arg_completion;
command_rl_completion_func_t entity_arg_completion;
- void (*set_default_entity)(const char *entity);
- void (*reset_default_entity)(void);
};
bool command_option_get(const char *name, const char **value_out);
@@ -74,7 +72,6 @@ void command_noninteractive_trigger(void);
bool command_is_interactive_mode(void);
int command_get_exit_status(void);
void command_set_exit_status(int status);
-void command_reset_default_entities(void);
void command_family_register(const struct command_family *family);
void command_family_unregister(const struct command_family *family);
diff --git a/client/dbus-proxy.c b/client/dbus-proxy.c
index 1534488e..42b8427f 100644
--- a/client/dbus-proxy.c
+++ b/client/dbus-proxy.c
@@ -806,8 +806,6 @@ static void service_disappeared_callback(struct l_dbus *dbus,
l_queue_clear(proxy_interfaces, proxy_interface_destroy);
- command_reset_default_entities();
-
display_disable_cmd_prompt();
}
diff --git a/client/device.c b/client/device.c
index 8b27ddd2..ce2afc81 100644
--- a/client/device.c
+++ b/client/device.c
@@ -42,8 +42,6 @@ struct device {
const struct proxy_interface *adapter;
};
-static struct proxy_interface *default_device;
-
static void display_device(const struct proxy_interface *proxy)
{
const struct device *device = proxy_interface_get_data(proxy);
@@ -260,52 +258,6 @@ static bool match_by_partial_name(const void *a, const void *b)
return !strncmp(device->name, text, strlen(text));
}
-static bool match_all(const void *a, const void *b)
-{
- return true;
-}
-
-static void device_set_default(const char *device_name)
-{
- struct l_queue *match;
-
- if (!device_name)
- return;
-
- match = proxy_interface_find_all(device_interface_type.interface,
- match_by_name, device_name);
-
- if (!match)
- return;
-
- default_device = l_queue_pop_head(match);
- l_queue_destroy(match, NULL);
-}
-
-static void device_reset_default(void)
-{
- default_device = NULL;
-}
-
-const struct proxy_interface *device_get_default(void)
-{
- struct l_queue *match;
-
- if (default_device)
- return default_device;
-
- match = proxy_interface_find_all(device_interface_type.interface,
- match_all, NULL);
-
- if (!match)
- return NULL;
-
- default_device = l_queue_pop_head(match);
- l_queue_destroy(match, NULL);
-
- return default_device;
-}
-
const struct proxy_interface *device_proxy_find_by_name(const char *name)
{
struct l_queue *match;
@@ -464,8 +416,6 @@ static struct command_family device_command_family = {
.command_list = device_commands,
.family_arg_completion = family_arg_completion,
.entity_arg_completion = entity_arg_completion,
- .set_default_entity = device_set_default,
- .reset_default_entity = device_reset_default,
};
static int device_command_family_init(void)
--
2.34.3
^ permalink raw reply related [flat|nested] 7+ messages in thread