Skip to contentSkip to conversation

doc: add documentation for StationDebug

PATCH In review James Prestwood 2 participants 7 messages Aug 11, 2022 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/6 doc: add documentation for StationDebug

---
 doc/station-debug-api.txt | 68 +++++++++++++++++++++++++++++++++++++++
 1 file changed, 68 insertions(+)
 create mode 100644 doc/station-debug-api.txt

v3:
* Removed the special /hidden object

doc/station-debug-api.txt new file +68 -0
new file mode 100644
index 00000000..ad91fc3b
@@ -0,0 +1,68 @@
+Station Debug hierarchy [experimental]
+============================
+
+These are all development APIs not meant for production use.
+
+Service		net.connman.iwd
+Interface	net.connman.iwd.StationDebug
+Object path	/net/connman/iwd/{phy0,phy1,...}/{1,2,...}
+
+Methods		void ConnectBssid(array(y) address)
+
+			Connect to a specific BSS. The address parameter should
+			be a byte array of length 6, the BSSID of a BSS which
+			IWD already has in its scan list.
+
+			Possible errors: net.connman.iwd.InvalidArguments
+					 net.connman.iwd.NotFound
+
+		void Roam(array(y) address)
+
+			Roam to a specific BSS. The address parameter should be
+			a byte array of length 6, the BSSID of a BSS to roam to.
+			This BSS needs to be in IWD's scan results and fit the
+			requirements for a roam candidate (same network).
+			The type of roam is dependent on the network and is
+			chosen automatically by IWD.
+
+			Possible errors: net.connman.iwd.InvalidArguments
+					 net.connman.iwd.NotConnected
+
+		void Scan(array(q) frequencies)
+
+			Scan on specific frequencies. The frequencies parameter
+			should be a list of valid frequencies.
+
+			Possible errors: net.connman.iwd.Busy
+					 net.connman.iwd.InvalidArguments
+					 net.connamn.iwd.Failed
+
+		a{oaa{sv}} GetNetworks()
+
+			Get a list of networks including data for individual
+			BSS's. Returns a dictionary where keys are network
+			object paths and values are arrays of dictionaries
+			containing BSS information:
+
+			{
+				/network/path/1: [
+					{
+						Address: 11:22:33:44:55,
+						Frequency: 1234,
+						RSSI: -20,
+						Rank: 1000
+						MDE: 001122
+					},
+					{ ... }
+				]
+			}
+
+Signals:	Event(s name, av data)
+
+			Signal sent for various debug events. The 'name' is the
+			event name, and 'data' is event dependent.
+
+Properties:	boolean AutoConnect
+
+			True if IWD is in an autoconnect state. This property
+			can be written to put IWD into an autoconnect state.
Signature · 1 line
2.34.3
#1 lore raw

PATCH v3 2/6 station: add debug method GetNetworks

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.

src/station.c +87 -0
index 57dbd0d5..66b296b8 100644
@@ -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");
 
Signature · 1 line
2.34.3
#2 lore raw

PATCH v3 3/6 client: allow entity name to be passed to completion

In reply to 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(-)
client/adapter.c +2 -1
index 394eae0d..1719b970 100644
@@ -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);
 }
client/command.c +38 -1
index c0576e97..46752c72 100644
@@ -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;
 	}
client/command.h +6 -3
index 23f23dc9..1f841689 100644
@@ -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);
 };
client/device.c +2 -1
index 9f8d731c..8b27ddd2 100644
@@ -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);
 }
client/known-networks.c +2 -1
index 56c34a2e..b2023e35 100644
@@ -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);
 }
client/station.c +4 -2
index 64becdbd..90291c88 100644
@@ -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;
Signature · 1 line
2.34.3
#3 lore raw

PATCH v3 4/6 client: add station-debug command interface

In reply to 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
Makefile.am +3 -1
index cffb0738..ed93d000 100644
@@ -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)
 
client/station-debug.c new file +443 -0

443 lines not on this page · raw message

Signature · 1 line
2.34.3
#4 lore raw

PATCH v3 5/6 client: fix station autocomplete with multiple phys

In reply to James Prestwood

The limitations of readline required that the autocompletion choose a 'default' device. With multiple phys this doesn't work. Now the readline limitation has been worked around and station can look up the device for the command completion.

---
 client/station.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
client/station.c +2 -1
index 90291c88..b070807b 100644
@@ -280,7 +280,8 @@ static enum cmd_status cmd_list(const char *device_name, char **argv, int argc)
 static char *connect_cmd_arg_completion(const char *text, int state,
 					const char *device_name)
 {
-	const struct proxy_interface *device = device_get_default();
+	const struct proxy_interface *device = device_proxy_find(device_name,
+							IWD_STATION_INTERFACE);
 
 	if (!device)
 		return NULL;
Signature · 1 line
2.34.3
#5 lore raw

PATCH v3 6/6 device: command: remove default device concept

In reply to 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(-)
client/command.c +0 -18
index 46752c72..dbd97703 100644
@@ -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);
client/command.h +0 -3
index 1f841689..96eefdec 100644
@@ -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);
client/dbus-proxy.c +0 -2
index 1534488e..42b8427f 100644
@@ -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();
 }
 
client/device.c +0 -50

68 lines not on this page · raw message

Signature · 1 line
2.34.3
#6 lore raw
In reply to James Prestwood

Hi James,

Quoted 8 lines · James Prestwood
---
  doc/station-debug-api.txt | 68 +++++++++++++++++++++++++++++++++++++++
  1 file changed, 68 insertions(+)

create mode 100644 doc/station-debug-api.txt

v3:
* Removed the special /hidden object

All applied, thanks.

Regards,
-Denis