Skip to contentSkip to conversation

dbus: Add net.connman.iwd.BasicServiceSet interface

PATCH Superseded James Prestwood 1 participant 13 messages Aug 8, 2024 Kbuild

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 1/13 dbus: Add net.connman.iwd.BasicServiceSet interface

---
 src/dbus.h | 1 +
 1 file changed, 1 insertion(+)
src/dbus.h +1 -0
index b43412d7..14814b5d 100644
@@ -48,6 +48,7 @@
 #define IWD_NETCONFIG_AGENT_INTERFACE \
 	"net.connman.iwd.NetworkConfigurationAgent"
 #define IWD_SHARED_CODE_AGENT_INTERFACE "net.connman.iwd.SharedCodeAgent"
+#define IWD_BSS_INTERFACE "net.connman.iwd.BasicServiceSet"
 
 #define IWD_BASE_PATH "/net/connman/iwd"
 #define IWD_AGENT_MANAGER_PATH IWD_BASE_PATH
Signature · 1 line
2.34.1
#1 lore raw

PATCH v2 2/13 network: Add BasicServiceSet object

This adds a new DBus object/interface for tracking BSS's for a given network. Since scanning replaces scan_bss objects some new APIs were added to avoid tearing down the associated DBus object for each BSS.

network_bss_start_update() should be called before any new BSS's are added to the network object. This will keep track of the old list and create a new network->bss_list where more entries can be added. This is effectively replacing network_bss_list_clear, except it keeps the old list around until...

network_bss_stop_update() is called when all BSS's have been added to the network object. This will then iterate the old list and lookup if any BSS DBus objects need to be destroyed. Once completed the old list is destroyed.

---
 src/network.c | 122 +++++++++++++++++++++++++++++++++++++++++++++++++-
 src/network.h |   4 ++
 2 files changed, 125 insertions(+), 1 deletion(-)

v2:
* Reworked to use network_bss_{start,stop}_update

src/network.c +121 -1
index 09099fac..9c197731 100644
@@ -75,6 +75,7 @@ struct network {
 	struct l_ecc_point *sae_pt_20; /* SAE PT for Group 20 */
 	unsigned int agent_request;
 	struct l_queue *bss_list;
+	struct l_queue *old_bss_list;
 	struct l_settings *settings;
 	struct l_queue *secrets;
 	struct l_queue *blacklist; /* temporary blacklist for BSS's */
@@ -1129,12 +1130,97 @@ bool network_update_known_frequencies(struct network *network)
 	return true;
 }
 
+const char *network_bss_get_path(const struct network *network,
+						const struct scan_bss *bss)
+{
+	static char path[256];
+
+	snprintf(path, sizeof(path), "%s/%02x%02x%02x%02x%02x%02x",
+			network->object_path, MAC_STR(bss->addr));
+
+	return path;
+}
+
+static bool network_unregister_bss(void *a, void *user_data)
+{
+	struct scan_bss *bss = a;
+	struct network *network = user_data;
+
+	l_dbus_unregister_object(dbus_get_bus(),
+					network_bss_get_path(network, bss));
+
+	return true;
+}
+
+static bool network_register_bss(struct network *network, struct scan_bss *bss)
+{
+	const char *path = network_bss_get_path(network, bss);
+	struct scan_bss *old;
+
+	/*
+	 * Due to station issuing multiple scan requests we may already have
+	 * this BSS data registered. Remove it from the old_bss_list
+	 */
+	old = l_dbus_object_get_data(dbus_get_bus(), path, IWD_BSS_INTERFACE);
+	if (old == bss)
+		return l_queue_remove(network->old_bss_list, bss);
+	else if (old)
+		return l_dbus_object_set_data(dbus_get_bus(), path,
+						IWD_BSS_INTERFACE, bss);
+
+	if (!l_dbus_object_add_interface(dbus_get_bus(), path,
+						IWD_BSS_INTERFACE, bss))
+		return false;
+
+	if (!l_dbus_object_add_interface(dbus_get_bus(), path,
+					L_DBUS_INTERFACE_PROPERTIES, bss))
+		return false;
+
+	return true;
+}
+
+void network_bss_start_update(struct network *network)
+{
+	network->old_bss_list = network->bss_list;
+	network->bss_list = l_queue_new();
+}
+
+void network_bss_stop_update(struct network *network)
+{
+	const struct l_queue_entry *e;
+
+	/*
+	 * Update has finished, clean up any BSS's from the old list that have
+	 * been registered on DBus.
+	 */
+	for (e = l_queue_get_entries(network->old_bss_list); e; e = e->next) {
+		const struct scan_bss *old = e->data;
+		const struct scan_bss *bss;
+		const char *path = network_bss_get_path(network, old);
+
+		bss = l_dbus_object_get_data(dbus_get_bus(), path,
+						IWD_BSS_INTERFACE);
+		/*
+		 * The lookup matched the user data of an old BSS. This should
+		 * be unregistered from DBus
+		 */
+		if (bss && bss == old)
+			l_dbus_object_remove_interface(dbus_get_bus(), path,
+							IWD_BSS_INTERFACE);
+	}
+
+	l_queue_destroy(network->old_bss_list, NULL);
+	network->old_bss_list = NULL;
+}
+
 bool network_bss_add(struct network *network, struct scan_bss *bss)
 {
 	if (!l_queue_insert(network->bss_list, bss, scan_bss_rank_compare,
 									NULL))
 		return false;
 
+	network_register_bss(network, bss);
+
 	/* Done if BSS is not HS20 or we already have network_info set */
 	if (!bss->hs20_capable)
 		return true;
@@ -1168,6 +1254,8 @@ bool network_bss_update(struct network *network, struct scan_bss *bss)
 
 	l_queue_insert(network->bss_list, bss, scan_bss_rank_compare, NULL);
 
+	network_register_bss(network, bss);
+
 	/* Sync frequency for already known networks */
 	if (network->info) {
 		known_network_add_frequency(network->info, bss->frequency);
@@ -1190,7 +1278,12 @@ void network_bss_list_clear(struct network *network)
 
 struct scan_bss *network_bss_list_pop(struct network *network)
 {
-	return l_queue_pop_head(network->bss_list);
+	struct scan_bss *bss = l_queue_pop_head(network->bss_list);
+
+	if (bss)
+		network_unregister_bss(bss, network);
+
+	return bss;
 }
 
 struct scan_bss *network_bss_find_by_addr(struct network *network,
@@ -1899,6 +1992,9 @@ static void network_unregister(struct network *network, int reason)
 
 void network_remove(struct network *network, int reason)
 {
+	l_queue_foreach_remove(network->bss_list,
+				network_unregister_bss, network);
+
 	if (network->object_path)
 		network_unregister(network, reason);
 
@@ -2155,6 +2251,24 @@ static void setup_network_interface(struct l_dbus_interface *interface)
 				network_property_get_known_network, NULL);
 }
 
+static bool network_bss_property_get_address(struct l_dbus *dbus,
+					struct l_dbus_message *message,
+					struct l_dbus_message_builder *builder,
+					void *user_data)
+{
+	struct scan_bss *bss = user_data;
+
+	l_dbus_message_builder_append_basic(builder, 's',
+					util_address_to_string(bss->addr));
+	return true;
+}
+
+static void setup_bss_interface(struct l_dbus_interface *interface)
+{
+	l_dbus_interface_property(interface, "Address", 0, "s",
+					network_bss_property_get_address, NULL);
+}
+
 static int network_init(void)
 {
 	if (!l_dbus_register_interface(dbus_get_bus(), IWD_NETWORK_INTERFACE,
@@ -2162,6 +2276,11 @@ static int network_init(void)
 		l_error("Unable to register %s interface",
 						IWD_NETWORK_INTERFACE);
 
+	if (!l_dbus_register_interface(dbus_get_bus(), IWD_BSS_INTERFACE,
+					setup_bss_interface, NULL, false))
+		l_error("Unable to register %s interface",
+						IWD_BSS_INTERFACE);
+
 	known_networks_watch =
 		known_networks_watch_add(known_networks_changed, NULL, NULL);
 
@@ -2179,6 +2298,7 @@ static void network_exit(void)
 	event_watch = 0;
 
 	l_dbus_unregister_interface(dbus_get_bus(), IWD_NETWORK_INTERFACE);
+	l_dbus_unregister_interface(dbus_get_bus(), IWD_BSS_INTERFACE);
 }
 
 IWD_MODULE(network, network_init, network_exit)
src/network.h +4 -0
index 17dfcca8..f27329a9 100644
@@ -67,8 +67,12 @@ int network_can_connect_bss(struct network *network,
 						const struct scan_bss *bss);
 int network_autoconnect(struct network *network, struct scan_bss *bss);
 void network_connect_failed(struct network *network, bool in_handshake);
+void network_bss_start_update(struct network *network);
+void network_bss_stop_update(struct network *network);
 bool network_bss_add(struct network *network, struct scan_bss *bss);
 bool network_bss_update(struct network *network, struct scan_bss *bss);
+const char *network_bss_get_path(const struct network *network,
+						const struct scan_bss *bss);
 bool network_bss_list_isempty(struct network *network);
 void network_bss_list_clear(struct network *network);
 struct scan_bss *network_bss_list_pop(struct network *network);
Signature · 1 line
2.34.1
#2 lore raw

PATCH v2 3/13 station: use network_bss_{start,stop}_update

In reply to James Prestwood

This will tell network the BSS list is being updated and it can act accordingly as far as the BSS DBus registrations/unregistration.

In addition any scan_bss object needing to be freed has to wait until after network_bss_stop_update() because network has to be able to iterate its old list and unregister any BSS's that were not seen in the scan results. This is done by pushing each BSS needing to be freed into a queue, then destroying them after the BSS's are all added.

---
 src/station.c | 23 ++++++++++++++++++-----
 1 file changed, 18 insertions(+), 5 deletions(-)

v2:
* Updated to use network_bss_{start,stop} update
* Added the free list to fix invalid reads due to freeing the scan_bss early

src/station.c +18 -5
index e373b03b..8a76339c 100644
@@ -344,6 +344,8 @@ static bool process_network(const void *key, void *data, void *user_data)
 	struct network *network = data;
 	struct station *station = user_data;
 
+	network_bss_stop_update(network);
+
 	if (!network_bss_list_isempty(network)) {
 		bool connected = network == station->connected_network;
 
@@ -532,6 +534,7 @@ struct bss_expiration_data {
 	struct scan_bss *connected_bss;
 	uint64_t now;
 	const struct scan_freq_set *freqs;
+	struct l_queue *free_list;
 };
 
 #define SCAN_RESULT_BSS_RETENTION_TIME (30 * 1000000)
@@ -553,18 +556,20 @@ static bool bss_free_if_expired(void *data, void *user_data)
 			bss->time_stamp + SCAN_RESULT_BSS_RETENTION_TIME))
 		return false;
 
-	bss_free(bss);
+	l_queue_push_head(expiration_data->free_list, bss);
 
 	return true;
 }
 
 static void station_bss_list_remove_expired_bsses(struct station *station,
-					const struct scan_freq_set *freqs)
+					const struct scan_freq_set *freqs,
+					struct l_queue *free_list)
 {
 	struct bss_expiration_data data = {
 		.now = l_time_now(),
 		.connected_bss = station->connected_bss,
 		.freqs = freqs,
+		.free_list = free_list,
 	};
 
 	l_queue_foreach_remove(station->bss_list, bss_free_if_expired, &data);
@@ -939,18 +944,19 @@ void station_set_scan_results(struct station *station,
 {
 	const struct l_queue_entry *bss_entry;
 	struct network *network;
+	struct l_queue *free_list = l_queue_new();
 
 	l_queue_foreach_remove(new_bss_list, bss_free_if_ssid_not_utf8, NULL);
 
 	while ((network = l_queue_pop_head(station->networks_sorted)))
-		network_bss_list_clear(network);
+		network_bss_start_update(network);
 
 	l_queue_clear(station->hidden_bss_list_sorted, NULL);
 
 	l_queue_destroy(station->autoconnect_list, NULL);
 	station->autoconnect_list = NULL;
 
-	station_bss_list_remove_expired_bsses(station, freqs);
+	station_bss_list_remove_expired_bsses(station, freqs, free_list);
 
 	for (bss_entry = l_queue_get_entries(station->bss_list); bss_entry;
 						bss_entry = bss_entry->next) {
@@ -962,7 +968,12 @@ void station_set_scan_results(struct station *station,
 			if (old_bss == station->connected_bss)
 				station->connected_bss = new_bss;
 
-			bss_free(old_bss);
+			/*
+			 * The network object is still holding a reference to
+			 * the BSS. Until we tell network to replace the BSS
+			 * with a new object, don't free it.
+			 */
+			l_queue_push_head(free_list, old_bss);
 
 			continue;
 		}
@@ -996,6 +1007,8 @@ void station_set_scan_results(struct station *station,
 
 	l_hashmap_foreach_remove(station->networks, process_network, station);
 
+	l_queue_destroy(free_list, bss_free);
+
 	station->autoconnect_can_start = trigger_autoconnect;
 	station_autoconnect_start(station);
 }
Signature · 1 line
2.34.1
#3 lore raw

PATCH v2 4/13 network: add ExtendedServiceSet DBus property

In reply to James Prestwood

This contains a list of all BasicServiceSet objects (paths) that exist for a network.

---
 src/network.c | 31 +++++++++++++++++++++++++++++++
 1 file changed, 31 insertions(+)

v2:
* Renamed BasicServiceSets to ExtendedServiceSet

src/network.c +31 -0
index 9c197731..35e7ba4a 100644
@@ -1149,6 +1149,9 @@ static bool network_unregister_bss(void *a, void *user_data)
 	l_dbus_unregister_object(dbus_get_bus(),
 					network_bss_get_path(network, bss));
 
+	l_dbus_property_changed(dbus_get_bus(), network->object_path,
+				IWD_NETWORK_INTERFACE, "ExtendedServiceSet");
+
 	return true;
 }
 
@@ -1176,6 +1179,9 @@ static bool network_register_bss(struct network *network, struct scan_bss *bss)
 					L_DBUS_INTERFACE_PROPERTIES, bss))
 		return false;
 
+	l_dbus_property_changed(dbus_get_bus(), network->object_path,
+				IWD_NETWORK_INTERFACE, "ExtendedServiceSet");
+
 	return true;
 }
 
@@ -1950,6 +1956,28 @@ static bool network_property_get_known_network(struct l_dbus *dbus,
 	return true;
 }
 
+static bool network_property_get_extended_service_set(struct l_dbus *dbus,
+					struct l_dbus_message *message,
+					struct l_dbus_message_builder *builder,
+					void *user_data)
+{
+	struct network *network = user_data;
+	const struct l_queue_entry *e;
+
+	l_dbus_message_builder_enter_array(builder, "o");
+
+	for (e = l_queue_get_entries(network->bss_list); e; e = e->next) {
+		struct scan_bss *bss = e->data;
+		const char *path = network_bss_get_path(network, bss);
+
+		l_dbus_message_builder_append_basic(builder, 'o', path);
+	}
+
+	l_dbus_message_builder_leave_array(builder);
+
+	return true;
+}
+
 bool network_register(struct network *network, const char *path)
 {
 	if (!l_dbus_object_add_interface(dbus_get_bus(), path,
@@ -2249,6 +2277,9 @@ static void setup_network_interface(struct l_dbus_interface *interface)
 
 	l_dbus_interface_property(interface, "KnownNetwork", 0, "o",
 				network_property_get_known_network, NULL);
+
+	l_dbus_interface_property(interface, "ExtendedServiceSet", 0, "ao",
+				network_property_get_extended_service_set, NULL);
 }
 
 static bool network_bss_property_get_address(struct l_dbus *dbus,
Signature · 1 line
2.34.1
#4 lore raw

PATCH v2 5/13 network: remove network_bss_list_clear

In reply to James Prestwood
---
 src/network.c | 6 ------
 src/network.h | 2 +-
 2 files changed, 1 insertion(+), 7 deletions(-)
src/network.c +0 -6
index 35e7ba4a..eff4117a 100644
@@ -1276,12 +1276,6 @@ bool network_bss_list_isempty(struct network *network)
 	return l_queue_isempty(network->bss_list);
 }
 
-void network_bss_list_clear(struct network *network)
-{
-	l_queue_destroy(network->bss_list, NULL);
-	network->bss_list = l_queue_new();
-}
-
 struct scan_bss *network_bss_list_pop(struct network *network)
 {
 	struct scan_bss *bss = l_queue_pop_head(network->bss_list);
src/network.h +1 -1
index f27329a9..121404ef 100644
@@ -74,7 +74,7 @@ bool network_bss_update(struct network *network, struct scan_bss *bss);
 const char *network_bss_get_path(const struct network *network,
 						const struct scan_bss *bss);
 bool network_bss_list_isempty(struct network *network);
-void network_bss_list_clear(struct network *network);
+
 struct scan_bss *network_bss_list_pop(struct network *network);
 struct scan_bss *network_bss_find_by_addr(struct network *network,
 							const uint8_t *addr);
Signature · 1 line
2.34.1
#5 lore raw

PATCH v2 6/13 station: add ConnectedAccessPoint property

In reply to James Prestwood

This property is a path that corresponds to a BasicServiceSet object, the one the station is currently connected to.

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

v2:
* Renamed ConnectedBss to ConnectedAccessPoint

src/station.c +20 -0
index 8a76339c..5524943b 100644
@@ -4376,6 +4376,23 @@ static bool station_property_get_connected_network(struct l_dbus *dbus,
 	return true;
 }
 
+static bool station_property_get_connected_ap(struct l_dbus *dbus,
+					struct l_dbus_message *message,
+					struct l_dbus_message_builder *builder,
+					void *user_data)
+{
+	struct station *station = user_data;
+
+	if (!station->connected_network)
+		return false;
+
+	l_dbus_message_builder_append_basic(builder, 'o',
+			network_bss_get_path(station->connected_network,
+						station->connected_bss));
+
+	return true;
+}
+
 static bool station_property_get_scanning(struct l_dbus *dbus,
 					struct l_dbus_message *message,
 					struct l_dbus_message_builder *builder,
@@ -4783,6 +4800,9 @@ static void station_setup_interface(struct l_dbus_interface *interface)
 	l_dbus_interface_property(interface, "ConnectedNetwork", 0, "o",
 					station_property_get_connected_network,
 					NULL);
+	l_dbus_interface_property(interface, "ConnectedAccessPoint", 0, "o",
+					station_property_get_connected_ap,
+					NULL);
 	l_dbus_interface_property(interface, "Scanning", 0, "b",
 					station_property_get_scanning, NULL);
 	l_dbus_interface_property(interface, "State", 0, "s",
Signature · 1 line
2.34.1
#6 lore raw

PATCH v2 7/13 doc: document BasicServiceSet API

In reply to James Prestwood
---
 doc/basic-service-set.txt | 10 ++++++++++
 doc/network-api.txt       |  5 +++++
 doc/station-api.txt       |  6 ++++++
 3 files changed, 21 insertions(+)
 create mode 100644 doc/basic-service-set.txt

v2:
* Renamed properties after review

doc/basic-service-set.txt new file +10 -0
new file mode 100644
index 00000000..f827ca02
@@ -0,0 +1,10 @@
+Basic service set hierarchy
+=================
+
+Service		net.connman.iwd
+Interface	net.connman.iwd.BasicServiceSet
+Object path	/net/connman/iwd/{phy0,phy1,...}/{1,2,...}/Xxx
+
+Properties	string Address [readonly]
+
+			MAC address of BSS
doc/network-api.txt +5 -0
index e4a34411..8bc6eea6 100644
@@ -50,3 +50,8 @@ Properties	string Name [readonly]
 			corresponding to this Network.  If the network
 			is not provisioned or has not been connected to
 			before, the property is omitted.
+
+		array(object) ExtendedServiceSet [readonly]
+
+			Contains a list of paths of each individual
+			BasicServiceSet object.
doc/station-api.txt +6 -0
index 05dd137e..84f1b7bf 100644
@@ -164,6 +164,12 @@ Properties	string State [readonly]
 			for networks.  net.connman.iwd.Network objects are
 			updated when this property goes from true to false.
 
+		object ConnectedAccessPoint [readonly, optional]
+
+			net.connman.iwd.BasicServiceSet object represeting the
+			BSS the device is currently connected to or to which
+			a connection is in progress.
+
 SignalLevelAgent hierarchy
 ==========================
 
Signature · 1 line
2.34.1
#7 lore raw

PATCH v2 8/13 client: separate property header and values into two functions

In reply to James Prestwood

There are certain cases where we may not want to display the entire header for a given set of properties. For example displaying a list of proxy interfaces. Add finer control by separating out the header and the prop/value display into two functions.

---
 client/dbus-proxy.c | 38 +++++++++++++++++++++++++++++---------
 client/dbus-proxy.h |  7 +++++++
 2 files changed, 36 insertions(+), 9 deletions(-)
client/dbus-proxy.c +29 -9
index 42b8427f..1e50d902 100644
@@ -47,10 +47,10 @@ static struct l_dbus *dbus;
 static struct l_queue *proxy_interfaces;
 static struct l_queue *proxy_interface_types;
 
-void proxy_properties_display(const struct proxy_interface *proxy,
-				const char *caption, const char *margin,
-				unsigned int name_column_width,
-				unsigned int value_column_width)
+void proxy_properties_display_inline(const struct proxy_interface *proxy,
+					const char *margin,
+					unsigned int name_column_width,
+					unsigned int value_column_width)
 {
 	const void *data;
 	const struct proxy_interface_property *properties;
@@ -59,11 +59,6 @@ void proxy_properties_display(const struct proxy_interface *proxy,
 	if (!proxy->type->properties)
 		return;
 
-	display_table_header(caption, "%s%-*s  %-*s  %-*s", margin,
-				8, "Settable",
-				name_column_width, "Property",
-				value_column_width, "Value");
-
 	data = proxy_interface_get_data(proxy);
 	properties = proxy->type->properties;
 
@@ -82,6 +77,31 @@ void proxy_properties_display(const struct proxy_interface *proxy,
 	}
 }
 
+void proxy_properties_display_header(const char *caption, const char *margin,
+					unsigned int name_column_width,
+					unsigned int value_column_width)
+{
+	display_table_header(caption, "%s%-*s  %-*s  %-*s", margin,
+				8, "Settable",
+				name_column_width, "Property",
+				value_column_width, "Value");
+}
+
+void proxy_properties_display(const struct proxy_interface *proxy,
+				const char *caption, const char *margin,
+				unsigned int name_column_width,
+				unsigned int value_column_width)
+{
+	if (!proxy->type->properties)
+		return;
+
+	proxy_properties_display_header(caption, margin, name_column_width,
+					value_column_width);
+
+	proxy_properties_display_inline(proxy, margin, name_column_width,
+					value_column_width);
+}
+
 static const void *proxy_interface_property_tostr(
 					const struct proxy_interface *proxy,
 					const char *name)
client/dbus-proxy.h +7 -0
index 98b0a2a4..f0a5d38a 100644
@@ -95,6 +95,13 @@ void proxy_properties_display(const struct proxy_interface *proxy,
 				const char *caption, const char *margin,
 				unsigned int name_column_width,
 				unsigned int value_column_width);
+void proxy_properties_display_inline(const struct proxy_interface *proxy,
+					const char *margin,
+					unsigned int name_column_width,
+					unsigned int value_column_width);
+void proxy_properties_display_header(const char *caption, const char *margin,
+					unsigned int name_column_width,
+					unsigned int value_column_width);
 
 char *proxy_property_str_completion(const struct proxy_interface_type *type,
 					proxy_property_match_func_t function,
Signature · 1 line
2.34.1
#8 lore raw

PATCH v2 9/13 client: add net.connman.iwd.BasicServiceSet definition

In reply to James Prestwood
---
 client/dbus-proxy.h | 1 +
 1 file changed, 1 insertion(+)
client/dbus-proxy.h +1 -0
index f0a5d38a..32300f41 100644
@@ -41,6 +41,7 @@ struct proxy_interface;
 #define IWD_DPP_INTERFACE                "net.connman.iwd.DeviceProvisioning"
 #define IWD_DPP_PKEX_INTERFACE \
 				"net.connman.iwd.SharedCodeDeviceProvisioning"
+#define IWD_BSS_INTERFACE                "net.connman.iwd.BasicServiceSet"
 
 typedef bool (*proxy_property_match_func_t) (const void *a, const void *b);
 
Signature · 1 line
2.34.1
#9 lore raw

PATCH v2 10/13 client: Add BasicServiceSets property to network

In reply to James Prestwood

The property itself is an array of paths, but this is difficult to fit nicely within a terminal. Instead just display the count of BSS's. Displaying a detailed list of BSS's will be done via a separate command.

---
 client/network.c | 49 ++++++++++++++++++++++++++++++++++++++++++++++++
 client/network.h |  2 ++
 2 files changed, 51 insertions(+)
client/network.c +49 -0
index 6b79bcd1..7431183b 100644
@@ -35,6 +35,7 @@ struct network {
 	char *identity;
 	char *name;
 	char *type;
+	struct l_queue *bss_list;
 	const struct proxy_interface *device;
 };
 
@@ -146,11 +147,58 @@ static void update_type(void *data, struct l_dbus_message_iter *variant)
 	network->type = l_strdup(value);
 }
 
+static bool match_path(const void *a, const void *user_data)
+{
+	const char *path1 = a;
+	const char *path2 = user_data;
+
+	return !strcmp(path1, path2);
+}
+
+static void update_ess(void *data, struct l_dbus_message_iter *variant)
+{
+	struct network *network = data;
+	struct l_dbus_message_iter array;
+	const char *path;
+
+	if (!network->bss_list)
+		network->bss_list = l_queue_new();
+
+	if (!l_dbus_message_iter_get_variant(variant, "ao", &array))
+		return;
+
+	while (l_dbus_message_iter_next_entry(&array, &path)) {
+		l_free(l_queue_remove_if(network->bss_list, match_path, path));
+		l_queue_push_head(network->bss_list, l_strdup(path));
+	}
+}
+
+static const char *get_ess(const void *data)
+{
+	const struct network *network = data;
+	static char count[10];
+
+	snprintf(count, 10, "Count %u", l_queue_length(network->bss_list));
+
+	return count;
+}
+
+struct l_queue *network_get_bss_list(
+				const struct proxy_interface *network_proxy)
+{
+	const struct network *network = proxy_interface_get_data(network_proxy);
+	if (!network)
+		return NULL;
+
+	return network->bss_list;
+}
+
 static const struct proxy_interface_property network_properties[] = {
 	{ "Name",       "s", update_name, get_name },
 	{ "Connected",  "b", update_connected},
 	{ "Device",     "o", update_device},
 	{ "Type",       "s", update_type},
+	{ "ExtendedServiceSet",  "ao", update_ess, get_ess },
 	{ }
 };
 
@@ -186,6 +234,7 @@ static void network_destroy(void *data)
 	l_free(network->name);
 	l_free(network->type);
 	l_free(network->identity);
+	l_queue_destroy(network->bss_list, l_free);
 
 	network->device = NULL;
 
client/network.h +2 -0
index 41624749..56d74e3f 100644
@@ -37,3 +37,5 @@ char *network_name_completion(const struct proxy_interface *device,
 struct l_queue *network_match_by_device_and_args(
 					const struct proxy_interface *device,
 					const struct network_args *args);
+struct l_queue *network_get_bss_list(
+				const struct proxy_interface *network_proxy);
Signature · 1 line
2.34.1
#10 lore raw

PATCH v2 11/13 client: add BasicServiceSet interface

In reply to James Prestwood
---
 Makefile.am  |   1 +
 client/bss.c | 109 +++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 110 insertions(+)
 create mode 100644 client/bss.c
Makefile.am +1 -0
index 0c152216..d438a5ba 100644
@@ -319,6 +319,7 @@ client_iwctl_SOURCES = client/main.c \
 			client/daemon.c client/daemon.h \
 			client/dpp.c client/dpp-pkex.c \
 			client/station-debug.c \
+			client/bss.c \
 			src/util.c src/util.h \
 			src/band.c src/band.h
 
client/bss.c new file +109 -0

109 lines not on this page · raw message

Signature · 1 line
2.34.1
#11 lore raw

PATCH v2 12/13 client: refactor cmd_connect() and add find_network()

In reply to James Prestwood

This will do all the lookup/searching needed to find a network proxy object.

---
 client/station.c | 35 +++++++++++++++++++++++++----------
 1 file changed, 25 insertions(+), 10 deletions(-)
client/station.c +25 -10
index affb7f15..58aac29e 100644
@@ -283,28 +283,26 @@ static char *connect_cmd_arg_completion(const char *text, int state,
 	return network_name_completion(device, text, state);
 }
 
-static enum cmd_status cmd_connect(const char *device_name,
-						char **argv, int argc)
+static const struct proxy_interface *find_network(const char *device_name,
+						const char *name,
+						const char *type)
 {
 	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;
-
 	device_proxy = device_proxy_find_by_name(device_name);
 	if (!device_proxy)
-		return CMD_STATUS_INVALID_VALUE;
+		return NULL;
 
-	network_args.name = argv[0];
-	network_args.type = argc >= 2 ? argv[1] : NULL;
+	network_args.name = name;
+	network_args.type = type;
 
 	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;
+		return NULL;
 	}
 
 	if (l_queue_length(match) > 1) {
@@ -315,11 +313,28 @@ static enum cmd_status cmd_connect(const char *device_name,
 
 		l_queue_destroy(match, NULL);
 
-		return CMD_STATUS_INVALID_VALUE;
+		return NULL;
 	}
 
 	network_proxy = l_queue_pop_head(match);
 	l_queue_destroy(match, NULL);
+
+	return network_proxy;
+}
+
+static enum cmd_status cmd_connect(const char *device_name,
+						char **argv, int argc)
+{
+	const struct proxy_interface *network_proxy;
+
+	if (argc < 1)
+		return CMD_STATUS_INVALID_ARGS;
+
+	network_proxy = find_network(device_name, argv[0],
+					argc >= 2 ? argv[1] : NULL);
+	if (!network_proxy)
+		return CMD_STATUS_INVALID_VALUE;
+
 	network_connect(network_proxy);
 
 	return CMD_STATUS_TRIGGERED;
Signature · 1 line
2.34.1
#12 lore raw

PATCH v2 13/13 client: add station command "get-bsses"

In reply to James Prestwood

This command will get the BasicServiceSet list for a given network. If no network is supplied, its assumed to be the current network.

---
 client/station.c | 51 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 51 insertions(+)
client/station.c +51 -0
index 58aac29e..5066a9f1 100644
@@ -723,6 +723,55 @@ static enum cmd_status cmd_show(const char *device_name,
 	return CMD_STATUS_TRIGGERED;
 }
 
+
+static enum cmd_status cmd_get_bsses(const char *device_name,
+						char **argv, int argc)
+{
+	const struct proxy_interface *station_i =
+			device_proxy_find(device_name, IWD_STATION_INTERFACE);
+	const struct station *station = proxy_interface_get_data(station_i);
+	struct l_queue *bss_list;
+	const struct l_queue_entry *e;
+	const struct proxy_interface *network_proxy;
+	char header[256];
+
+	if (argc > 0)
+		network_proxy = find_network(device_name, argv[0],
+						argc >= 2 ? argv[1] : NULL);
+	else
+		network_proxy = station->connected_network;
+
+	if (!network_proxy) {
+		display_error("Can't find network");
+		return CMD_STATUS_INVALID_ARGS;
+	}
+
+	bss_list = network_get_bss_list(network_proxy);
+	if (!bss_list) {
+		display_error("No BSS list for network");
+		return CMD_STATUS_FAILED;
+	}
+
+	sprintf(header, "%s BasicServiceSets", network_get_name(network_proxy));
+
+	proxy_properties_display_header(header, MARGIN, 10, 18);
+
+	for (e = l_queue_get_entries(bss_list); e; e = e->next) {
+		const char *path = e->data;
+		const struct proxy_interface *bss_i = proxy_interface_find(
+						IWD_BSS_INTERFACE, path);
+
+		if (!bss_i)
+			continue;
+
+		display_table_row(MARGIN, 1, strlen(path), path);
+		proxy_properties_display_inline(bss_i, MARGIN, 10, 18);
+		display_table_row(MARGIN, 1, 1, "");
+	}
+
+	return CMD_STATUS_DONE;
+}
+
 static const struct command station_commands[] = {
 	{ NULL, "list", NULL, cmd_list, "List devices in Station mode", true },
 	{ "<wlan>", "connect",
@@ -747,6 +796,8 @@ static const struct command station_commands[] = {
 						"Get hidden APs", true },
 	{ "<wlan>", "scan",     NULL,   cmd_scan, "Scan for networks" },
 	{ "<wlan>", "show",     NULL,   cmd_show, "Show station info", true },
+	{ "<wlan>", "get-bsses", "[network] [security]", cmd_get_bsses,
+				"Get BSS's for a network", true },
 	{ }
 };
 
Signature · 1 line
2.34.1