Skip to contentSkip to conversation

network: make network const in network_bss_list_get_entries

PATCH Applied James Prestwood 2 participants 13 messages Aug 10, 2022 – Aug 11, 2022 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH 1/8 network: make network const in network_bss_list_get_entries

No reason for this to not be const.

---
 src/network.c | 2 +-
 src/network.h | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
src/network.c +1 -1
index c0befa42..3099d102 100644
@@ -1168,7 +1168,7 @@ struct erp_cache_entry *network_get_erp_cache(struct network *network)
 }
 
 const struct l_queue_entry *network_bss_list_get_entries(
-						struct network *network)
+						const struct network *network)
 {
 	return l_queue_get_entries(network->bss_list);
 }
src/network.h +1 -1
index c6b99f6c..f29649f7 100644
@@ -91,7 +91,7 @@ void network_blacklist_add(struct network *network, struct scan_bss *bss);
 struct erp_cache_entry *network_get_erp_cache(struct network *network);
 
 const struct l_queue_entry *network_bss_list_get_entries(
-						struct network *network);
+						const struct network *network);
 
 struct l_dbus_message *__network_connect(struct network *network,
 						struct scan_bss *bss,
Signature · 1 line
2.34.3
#1 lore raw

PATCH 2/8 station: check for matching SSID in Roam()

This is a debug method, but still should verify the SSID in the target matches the current BSS.

---
 src/station.c | 7 +++++++
 1 file changed, 7 insertions(+)
src/station.c +7 -0
index 8c230b52..57dbd0d5 100644
@@ -4373,6 +4373,13 @@ static struct l_dbus_message *station_force_roam(struct l_dbus *dbus,
 	if (!target || target == station->connected_bss)
 		return dbus_error_invalid_args(message);
 
+	if (station->connected_bss->ssid_len != target->ssid_len)
+		goto invalid_args;
+
+	if (memcmp(station->connected_bss->ssid, target->ssid,
+				target->ssid_len))
+		goto invalid_args;
+
 	l_debug("Attempting forced roam to BSS "MAC, MAC_STR(mac));
 
 	/* The various roam routines expect this to be set from scanning */
Signature · 1 line
2.34.3
#2 lore raw

PATCH 3/8 station: add debug method GetNetworks

In reply to James Prestwood

This gets all networks but includes individual entries for each BSS.

---
 src/station.c | 94 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 94 insertions(+)
src/station.c +94 -0
index 57dbd0d5..4f0f2afc 100644
@@ -4600,6 +4600,97 @@ 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", 'i', &bss->rank);
+
+		station_append_byte_array(builder, "Address", bss->addr, 6);
+		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, "{sv}");
+
+	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, "sv");
+		l_dbus_message_builder_append_basic(builder, 's',
+						network_get_ssid(network));
+		l_dbus_message_builder_enter_variant(builder, "aa{sv}");
+		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_variant(builder);
+		l_dbus_message_builder_leave_dict(builder);
+	}
+
+	/* Hidden Networks. Use an empty string for the SSID */
+	l_dbus_message_builder_enter_dict(builder, "sv");
+	l_dbus_message_builder_append_basic(builder, 's', "");
+	l_dbus_message_builder_enter_variant(builder, "aa{sv}");
+	l_dbus_message_builder_enter_array(builder, "a{sv}");
+	station_append_bss_list(builder,
+			l_queue_get_entries(station->hidden_bss_list_sorted));
+	l_dbus_message_builder_leave_array(builder);
+	l_dbus_message_builder_leave_variant(builder);
+	l_dbus_message_builder_leave_dict(builder);
+
+	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 +4703,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{sv}", "",
+				"networks");
 
 	l_dbus_interface_signal(interface, "Event", 0, "sav", "name", "data");
 
Signature · 1 line
2.34.3
#3 lore raw

Re: [PATCH 3/8] station: add debug method GetNetworks

Hi James,

Quoted 6 lines · James Prestwood

This gets all networks but includes individual entries for each BSS.

---
  src/station.c | 94 +++++++++++++++++++++++++++++++++++++++++++++++++++
  1 file changed, 94 insertions(+)

You really should start with a commit in doc/ describing this API.

Quoted 4 lines
src/station.c +4 -0
+static void station_append_bss_list(struct l_dbus_message_builder *builder,
+					const struct l_queue_entry *entry)
+{
+	for (; entry; entry = entry->next) {

src/station.c static struct l_dbus_message *station_property_set_autoconnect( · line 4635

Quoted 10 lines
src/station.c +10 -0
+		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", 'i', &bss->rank);

Rank is a uint16.

Review

Quoted 2 lines
(quoted diff) +2 -0
+
+		station_append_byte_array(builder, "Address", bss->addr, 6);

Are you sure you don't want Address in string form?

Quoted 16 lines
src/station.c +16 -0
+		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;

src/station.c static struct l_dbus_message *station_property_set_autoconnect( · line 4663

Quoted 10 lines
src/station.c +10 -0
+
+	l_dbus_message_builder_enter_array(builder, "{sv}");
+
+	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, "sv");
+		l_dbus_message_builder_append_basic(builder, 's',
+						network_get_ssid(network));

Using the SSID as the key is not a good idea. You can have multiple network types with the same SSID. This should probably just be an array of some sort. Or maybe a dict where the key is the .Network object path. Something like a(oa{sv}) or a{oa{sv}}.

Quoted 23 lines
src/station.c +23 -0
+		l_dbus_message_builder_enter_variant(builder, "aa{sv}");
+		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_variant(builder);
+		l_dbus_message_builder_leave_dict(builder);
+	}
+
+	/* Hidden Networks. Use an empty string for the SSID */
+	l_dbus_message_builder_enter_dict(builder, "sv");
+	l_dbus_message_builder_append_basic(builder, 's', "");
+	l_dbus_message_builder_enter_variant(builder, "aa{sv}");
+	l_dbus_message_builder_enter_array(builder, "a{sv}");
+	station_append_bss_list(builder,
+			l_queue_get_entries(station->hidden_bss_list_sorted));
+	l_dbus_message_builder_leave_array(builder);
+	l_dbus_message_builder_leave_variant(builder);
+	l_dbus_message_builder_leave_dict(builder);
+
+	l_dbus_message_builder_leave_array(builder);

src/station.c static struct l_dbus_message *station_property_set_autoconnect( · line 4696

Quoted 10 lines
src/station.c +7 -0
+
+	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)
  {

Regards,
-Denis

#4 lore raw

PATCH 4/8 client: add developer mode option (-E)

In reply to James Prestwood

This puts iwctl into developer mode which allows IWD debug interfaces to be used.

---
 client/command.c | 26 ++++++++++++++++++--------
 client/command.h |  1 +
 2 files changed, 19 insertions(+), 8 deletions(-)
client/command.c +18 -8
index c0576e97..80599620 100644
@@ -38,6 +38,7 @@ static struct l_queue *command_families;
 static struct l_queue *command_options;
 static int exit_status;
 static bool interactive_mode;
+static bool developer_mode;
 static struct command_noninteractive {
 	char **argv;
 	int argc;
@@ -616,6 +617,11 @@ bool command_is_interactive_mode(void)
 	return interactive_mode;
 }
 
+bool command_is_developer_mode(void)
+{
+	return developer_mode;
+}
+
 void command_set_exit_status(int status)
 {
 	exit_status = status;
@@ -657,6 +663,7 @@ static const struct option command_opts[] = {
 	{ COMMAND_OPTION_PASSPHRASE,	required_argument, NULL, 'P' },
 	{ COMMAND_OPTION_DONTASK,	no_argument,	   NULL, 'd' },
 	{ "help",			no_argument,	   NULL, 'h' },
+	{ "developer",			no_argument,	   NULL, 'E' },
 	{ }
 };
 
@@ -671,17 +678,10 @@ bool command_init(char **argv, int argc)
 	command_families = l_queue_new();
 	command_options = l_queue_new();
 
-	for (desc = __start___command; desc < __stop___command; desc++) {
-		if (!desc->init)
-			continue;
-
-		desc->init();
-	}
-
 	for (;;) {
 		struct command_option *option;
 
-		opt = getopt_long(argc, argv, "u:p:P:dh", command_opts, NULL);
+		opt = getopt_long(argc, argv, "u:p:P:dhE", command_opts, NULL);
 
 		switch (opt) {
 		case 'u':
@@ -714,6 +714,9 @@ bool command_init(char **argv, int argc)
 
 			l_queue_push_tail(command_options, option);
 
+			break;
+		case 'E':
+			developer_mode = true;
 			break;
 		case 'h':
 			command_display_help();
@@ -731,6 +734,13 @@ bool command_init(char **argv, int argc)
 	}
 
 options_parsed:
+	for (desc = __start___command; desc < __stop___command; desc++) {
+		if (!desc->init)
+			continue;
+
+		desc->init();
+	}
+
 	argv += optind;
 	argc -= optind;
 
client/command.h +1 -0
index 23f23dc9..bdfc7e99 100644
@@ -69,6 +69,7 @@ void command_process_prompt(char **argv, int argc);
 
 void command_noninteractive_trigger(void);
 bool command_is_interactive_mode(void);
+bool command_is_developer_mode(void);
 int command_get_exit_status(void);
 void command_set_exit_status(int status);
 void command_reset_default_entities(void);
Signature · 1 line
2.34.3
#5 lore raw

Re: [PATCH 4/8] client: add developer mode option (-E)

Hi James,

Quoted 2 lines · James Prestwood

This puts iwctl into developer mode which allows IWD debug interfaces to be used.

Why is this needed? Can't you just detect that iwd made Debug interfaces available and enable these automagically?

Quoted 5 lines
---
  client/command.c | 26 ++++++++++++++++++--------
  client/command.h |  1 +
  2 files changed, 19 insertions(+), 8 deletions(-)

Regards,
-Denis

#6 lore raw

PATCH 5/8 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 80599620..835c00c5 100644
@@ -214,20 +214,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 bdfc7e99..70a54e7e 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
#7 lore raw

PATCH 6/8 client: add STATION_DEBUG_INTERFACE definition

In reply to James Prestwood
---
 client/dbus-proxy.h | 1 +
 1 file changed, 1 insertion(+)
client/dbus-proxy.h +1 -0
index 34917e82..0b4fec43 100644
@@ -34,6 +34,7 @@ struct proxy_interface;
 #define IWD_WSC_INTERFACE                "net.connman.iwd.SimpleConfiguration"
 #define IWD_STATION_INTERFACE            "net.connman.iwd.Station"
 #define IWD_STATION_DIAGNOSTIC_INTERFACE "net.connman.iwd.StationDiagnostic"
+#define IWD_STATION_DEBUG_INTERFACE      "net.connman.iwd.StationDebug"
 #define IWD_AP_DIAGNOSTIC_INTERFACE      "net.connman.iwd.AccessPointDiagnostic"
 #define IWD_DAEMON_INTERFACE             "net.connman.iwd.Daemon"
 #define IWD_DPP_INTERFACE                "net.connman.iwd.DeviceProvisioning"
Signature · 1 line
2.34.3
#8 lore raw

Re: [PATCH 6/8] client: add STATION_DEBUG_INTERFACE definition

Hi James,

Quoted 4 lines · James Prestwood
---
  client/dbus-proxy.h | 1 +
  1 file changed, 1 insertion(+)

Applied, thanks.

Regards,
-Denis

#9 lore raw

PATCH 7/8 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 both iwctl and IWD are in developer mode (-E)

---
 Makefile.am            |   4 +-
 client/station-debug.c | 417 +++++++++++++++++++++++++++++++++++++++++
 2 files changed, 420 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 +417 -0

417 lines not on this page · raw message

Signature · 1 line
2.34.3
#10 lore raw

PATCH 8/8 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
#11 lore raw

Re: [PATCH 8/8] client: fix station autocomplete with multiple phys

Hi James,

Quoted 4 lines · 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.

So should you get rid of device_get_default() now as well?

Quoted 4 lines
---
  client/station.c | 3 ++-
  1 file changed, 2 insertions(+), 1 deletion(-)

Regards,
-Denis

#12 lore raw
In reply to James Prestwood

Hi James,

Quoted 6 lines · James Prestwood

No reason for this to not be const.

---
  src/network.c | 2 +-
  src/network.h | 2 +-
  2 files changed, 2 insertions(+), 2 deletions(-)

Patch 1 & 2 applied, thanks.

Regards,
-Denis