Skip to contentSkip to conversation

network: add network_bss_list_prune

PATCH In review James Prestwood 2 participants 17 messages Aug 7, 2024 – Aug 8, 2024 Kbuild

lore
Share & tools
lore
#0 lore raw

PATCH 1/14 network: add network_bss_list_prune

This adds a new API meant to replace network_bss_list_clear. Instead of clearing the entirely network->bss_list on each scan we can instead just prune out entries that didn't show up in the scan. The network_bss_add API was also updated to prepare for network_bss_list_prune by removing existing entries, as now even "new" entries may exist in the list still and need to be removed.

---
 src/network.c | 43 ++++++++++++++++++++++++++++++++++++-------
 src/network.h |  2 ++
 2 files changed, 38 insertions(+), 7 deletions(-)
src/network.c +36 -7
index 09099fac..6d7e5ec4 100644
@@ -1129,8 +1129,17 @@ bool network_update_known_frequencies(struct network *network)
 	return true;
 }
 
+static bool match_addr(const void *a, const void *b)
+{
+	const struct scan_bss *bss = a;
+
+	return memcmp(bss->addr, b, 6) == 0;
+}
+
 bool network_bss_add(struct network *network, struct scan_bss *bss)
 {
+	l_queue_remove_if(network->bss_list, match_addr, bss->addr);
+
 	if (!l_queue_insert(network->bss_list, bss, scan_bss_rank_compare,
 									NULL))
 		return false;
@@ -1150,13 +1159,6 @@ bool network_bss_add(struct network *network, struct scan_bss *bss)
 	return true;
 }
 
-static bool match_addr(const void *a, const void *b)
-{
-	const struct scan_bss *bss = a;
-
-	return memcmp(bss->addr, b, 6) == 0;
-}
-
 /*
  * Replaces an old scan_bss (if exists) in the bss list with a new bss object.
  * Note this BSS is *not* freed and must be by the caller. scan_bss objects are
@@ -1188,6 +1190,33 @@ void network_bss_list_clear(struct network *network)
 	network->bss_list = l_queue_new();
 }
 
+struct network_prune_data {
+	struct network *network;
+	struct l_queue *new_list;
+};
+
+static bool scan_bss_prune_missing(void *a, void *user_data)
+{
+	struct scan_bss *bss = a;
+	struct network_prune_data *data = user_data;
+
+	if (!l_queue_find(data->new_list, match_addr, bss->addr))
+		return true;
+
+	return false;
+}
+
+void network_bss_list_prune(struct network *network, struct l_queue *new_list)
+{
+	struct network_prune_data data;
+
+	data.network = network;
+	data.new_list = new_list;
+
+	l_queue_foreach_remove(network->bss_list,
+				scan_bss_prune_missing, &data);
+}
+
 struct scan_bss *network_bss_list_pop(struct network *network)
 {
 	return l_queue_pop_head(network->bss_list);
src/network.h +2 -0
index 17dfcca8..be81c150 100644
@@ -71,6 +71,8 @@ bool network_bss_add(struct network *network, struct scan_bss *bss);
 bool network_bss_update(struct network *network, struct scan_bss *bss);
 bool network_bss_list_isempty(struct network *network);
 void network_bss_list_clear(struct network *network);
+void network_bss_list_prune(struct network *network, struct l_queue *new_list);
+
 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
#1 lore raw

PATCH 2/14 station: use network_bss_list_prune

Use this to clear only entires that were not found in the newest scan results.

---
 src/station.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
src/station.c +1 -1
index e373b03b..2c4d686b 100644
@@ -943,7 +943,7 @@ void station_set_scan_results(struct station *station,
 	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_list_prune(network, new_bss_list);
 
 	l_queue_clear(station->hidden_bss_list_sorted, NULL);
 
Signature · 1 line
2.34.1
#2 lore raw

Re: [PATCH 02/14] station: use network_bss_list_prune

Hi James,

Quoted 11 lines · James Prestwood

Use this to clear only entires that were not found in the newest scan results.

---
  src/station.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
src/station.c +0 -0
index e373b03b..2c4d686b 100644

src/station.c void station_set_scan_results(struct station *station, · line 946

Quoted 5 lines
src/station.c +1 -1
@@ -943,7 +943,7 @@ void station_set_scan_results(struct station *station,
  	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_list_prune(network, new_bss_list);

You're sending the new list without vetting whether the SSID matches the network. That will likely come to haunt you later.

src/station.c void station_set_scan_results(struct station *station, · line 949

Quoted 3 lines
src/station.c +0 -0
  	l_queue_clear(station->hidden_bss_list_sorted, NULL);
 

Regards,
-Denis

#3 lore raw

Re: [PATCH 02/14] station: use network_bss_list_prune

Hi Denis,

Quoted 9 lines · Denis Kenzior

Hi James,

Quoted 6 lines · James Prestwood

Use this to clear only entires that were not found in the newest scan results.
---
  src/station.c | 2 +-

  1 file changed, 1 insertion(+), 1 deletion(-)
Quoted 12 lines

src/station.c void station_set_scan_results(struct station · line 946

Quoted 10 lines
src/station.c +1 -1
index e373b03b..2c4d686b 100644
@@ -943,7 +943,7 @@ void station_set_scan_results(struct station 
 *station,
       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_list_prune(network, new_bss_list);

You're sending the new list without vetting whether the SSID matches the network.  That will likely come to haunt you later.

Yes, one of several problems with this. Its also ~O(N^2) so with v2 I'll be using a different approach. Slightly more optimized, and fixes the issue you mentioned.

Quoted 4 lines

src/station.c void station_set_scan_results(struct station *station, · line 948

Quoted 2 lines
src/station.c +0 -0
 l_queue_clear(station->hidden_bss_list_sorted, NULL);

Regards,
-Denis

#4 lore raw

PATCH 3/14 network: remove network_bss_list_clear

In reply to James Prestwood
---
 src/network.c | 6 ------
 src/network.h | 1 -
 2 files changed, 7 deletions(-)
src/network.c +0 -6
index 6d7e5ec4..c63d53b8 100644
@@ -1184,12 +1184,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 network_prune_data {
 	struct network *network;
 	struct l_queue *new_list;
src/network.h +0 -1
index be81c150..29bc57ee 100644
@@ -70,7 +70,6 @@ void network_connect_failed(struct network *network, bool in_handshake);
 bool network_bss_add(struct network *network, struct scan_bss *bss);
 bool network_bss_update(struct network *network, struct scan_bss *bss);
 bool network_bss_list_isempty(struct network *network);
-void network_bss_list_clear(struct network *network);
 void network_bss_list_prune(struct network *network, struct l_queue *new_list);
 
 struct scan_bss *network_bss_list_pop(struct network *network);
Signature · 1 line
2.34.1
#5 lore raw

PATCH 4/14 dbus: Add net.connman.iwd.BasicServiceSet interface

In reply to James Prestwood
---
 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
#6 lore raw

PATCH 5/14 network: implement net.connman.iwd.BasicServiceSet

In reply to James Prestwood

This ties the addition/removal of scan_bss objects from a network object to BasicServiceSet objects. If a "new" object is added when one with the same address already existed, no DBus object changes are made (only the user data is updated with the new scan_bss).

Currently the only property on a BasicServiceSet object is the "Bssid".

---
 src/network.c | 94 ++++++++++++++++++++++++++++++++++++++++++++++++---
 src/network.h |  2 ++
 2 files changed, 91 insertions(+), 5 deletions(-)
src/network.c +89 -5
index c63d53b8..e3f5bee8 100644
@@ -1136,13 +1136,64 @@ static bool match_addr(const void *a, const void *b)
 	return memcmp(bss->addr, b, 6) == 0;
 }
 
+const char *network_bss_get_path(struct network *network,
+						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,
+					bool update)
+{
+	const char *path = network_bss_get_path(network, bss);
+
+	if (update)
+		return l_dbus_object_set_data(dbus_get_bus(),
+					network_bss_get_path(network, bss),
+					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;
+}
+
 bool network_bss_add(struct network *network, struct scan_bss *bss)
 {
-	l_queue_remove_if(network->bss_list, match_addr, bss->addr);
+	bool removed = l_queue_remove_if(network->bss_list,
+					match_addr, bss->addr) != NULL;
+
+	if (!l_queue_insert(network->bss_list, bss,
+				scan_bss_rank_compare, NULL)) {
+		/* This is essentially impossible... */
+		if (L_WARN_ON(removed))
+			network_unregister_bss(bss, network);
 
-	if (!l_queue_insert(network->bss_list, bss, scan_bss_rank_compare,
-									NULL))
 		return false;
+	}
+
+	L_WARN_ON(!network_register_bss(network, bss, removed));
 
 	/* Done if BSS is not HS20 or we already have network_info set */
 	if (!bss->hs20_capable)
@@ -1194,8 +1245,10 @@ static bool scan_bss_prune_missing(void *a, void *user_data)
 	struct scan_bss *bss = a;
 	struct network_prune_data *data = user_data;
 
-	if (!l_queue_find(data->new_list, match_addr, bss->addr))
+	if (!l_queue_find(data->new_list, match_addr, bss->addr)) {
+		network_unregister_bss(bss, data->network);
 		return true;
+	}
 
 	return false;
 }
@@ -1213,7 +1266,12 @@ void network_bss_list_prune(struct network *network, struct l_queue *new_list)
 
 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,
@@ -1931,6 +1989,8 @@ void network_remove(struct network *network, int reason)
 	if (network->info)
 		network->info->seen_count -= 1;
 
+	l_queue_foreach_remove(network->bss_list,
+				network_unregister_bss, network);
 	l_queue_destroy(network->bss_list, NULL);
 	l_queue_destroy(network->blacklist, NULL);
 
@@ -2178,6 +2238,24 @@ static void setup_network_interface(struct l_dbus_interface *interface)
 				network_property_get_known_network, NULL);
 }
 
+static bool network_bss_property_get_bssid(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, "Bssid", 0, "s",
+					network_bss_property_get_bssid, NULL);
+}
+
 static int network_init(void)
 {
 	if (!l_dbus_register_interface(dbus_get_bus(), IWD_NETWORK_INTERFACE,
@@ -2185,6 +2263,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);
 
@@ -2202,6 +2285,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 +2 -0
index 29bc57ee..62ed834b 100644
@@ -69,6 +69,8 @@ int network_autoconnect(struct network *network, struct scan_bss *bss);
 void network_connect_failed(struct network *network, bool in_handshake);
 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(struct network *network,
+						struct scan_bss *bss);
 bool network_bss_list_isempty(struct network *network);
 void network_bss_list_prune(struct network *network, struct l_queue *new_list);
 
Signature · 1 line
2.34.1
#7 lore raw

PATCH 6/14 network: add BasicServiceSets property on the network object

In reply to James Prestwood

This will hold an array of object paths pointing to each BasicServiceSet object.

---
 src/network.c | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)
src/network.c +28 -0
index e3f5bee8..de56eaaf 100644
@@ -1176,6 +1176,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, "BasicServiceSets");
+
 	return true;
 }
 
@@ -1938,6 +1941,28 @@ static bool network_property_get_known_network(struct l_dbus *dbus,
 	return true;
 }
 
+static bool network_property_get_basic_service_sets(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,
@@ -2236,6 +2261,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, "BasicServiceSets", 0, "ao",
+				network_property_get_basic_service_sets, NULL);
 }
 
 static bool network_bss_property_get_bssid(struct l_dbus *dbus,
Signature · 1 line
2.34.1
#8 lore raw

PATCH 7/14 station: add ConnectedBss 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(+)
src/station.c +20 -0
index 2c4d686b..5a6360de 100644
@@ -4363,6 +4363,23 @@ static bool station_property_get_connected_network(struct l_dbus *dbus,
 	return true;
 }
 
+static bool station_property_get_connected_bss(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,
@@ -4770,6 +4787,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, "ConnectedBss", 0, "o",
+					station_property_get_connected_bss,
+					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
#9 lore raw

PATCH 8/14 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
doc/basic-service-set.txt new file +10 -0
new file mode 100644
index 00000000..2ebb63be
@@ -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 Bssid [readonly]
+
+			MAC address of BSS
doc/network-api.txt +5 -0
index e4a34411..3aa68382 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.
+
+		a(o) BasicServiceSets [readonly]
+
+			Contains a list of paths of each individual
+			BasicServiceSet object.
doc/station-api.txt +6 -0
index 05dd137e..7b067620 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 ConnectedBss [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
#10 lore raw

Re: [PATCH 08/14] doc: document BasicServiceSet API

Hi James,

Quoted 13 lines · 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

doc/basic-service-set.txt new file +0 -0
new file mode 100644
index 00000000..2ebb63be

doc/basic-service-set.txt line 8

Quoted 8 lines
doc/basic-service-set.txt new file +8 -0
@@ -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 Bssid [readonly]

Lets call this Address to be consistent with .Device, .Station.GetHiddenAccessPoints, etc

doc/network-api.txt Properties string Name [readonly] · line 54

Quoted 12 lines
doc/basic-service-set.txt new file +2 -0
+
+			MAC address of BSS
doc/network-api.txt +2 -0
index e4a34411..3aa68382 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.
+
+		a(o) BasicServiceSets [readonly]

Should just be ao, there's no encompassing structure. Lets just call this ServiceSet maybe? Or ExtendedServiceSet if you want to use the spec terminology.

doc/station-api.txt Properties string State [readonly] · line 167

Quoted 12 lines
doc/network-api.txt +3 -0
+
+			Contains a list of paths of each individual
+			BasicServiceSet object.
doc/station-api.txt +1 -0
index 05dd137e..7b067620 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 ConnectedBss [readonly, optional]

ConnectedBasicServiceSet? We also use AccessPoint terminology in GetHiddenAccessPoints, so maybe ConnectedAccessPoint? This is Station after all.

doc/station-api.txt Properties string State [readonly] · line 175

Quoted 8 lines
doc/station-api.txt +5 -0
+
+			net.connman.iwd.BasicServiceSet object represeting the
+			BSS the device is currently connected to or to which
+			a connection is in progress.
+
  SignalLevelAgent hierarchy
  ==========================
 

Regards,
-Denis

#11 lore raw

PATCH 9/14 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
#12 lore raw

PATCH 10/14 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
#13 lore raw

PATCH 11/14 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..2bb986ce 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_bss(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_bss(const void *data)
+{
+	const struct network *network = data;
+	static char count[4];
+
+	snprintf(count, 4, "%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},
+	{ "BasicServiceSets",  "ao", update_bss, get_bss },
 	{ }
 };
 
@@ -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
#14 lore raw

PATCH 12/14 client: add BasicServiceSet interface

In reply to James Prestwood
---
 Makefile.am  |   1 +
 client/bss.c | 110 +++++++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 111 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 +110 -0

110 lines not on this page · raw message

Signature · 1 line
2.34.1
#15 lore raw

PATCH 13/14 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
#16 lore raw

PATCH 14/14 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