Skip to contentSkip to conversation

doc: Document station Affinities property

PATCH In review James Prestwood 2 participants 7 messages Aug 28, 2024 – Sep 3, 2024

lore
Share & tools
lore
#0 lore raw

PATCH v5 1/6 doc: Document station Affinities property

This documents new DBus property that expose a bit more control to how IWD roams.

Setting the affinity on the connected BSS effectively "locks" IWD to that BSS (except at critical RSSI levels, explained below). This can be useful for clients that have access to more information about the environment than IWD. For example, if a client is stationary there is likely no point in trying to roam until it has moved elsewhere.

A new main.conf option would also be added:

[General].CriticalRoamThreshold

This would be the new roam threshold set if the currently connected BSS is in the Affinities list. If the RSSI continues to drop below this level IWD will still attempt to roam.

---
 doc/station-api.txt | 17 +++++++++++++++++
 src/iwd.config.rst  | 16 ++++++++++++++++
 2 files changed, 33 insertions(+)
doc/station-api.txt +17 -0
index 84f1b7bf..707c6834 100644
@@ -170,6 +170,23 @@ Properties	string State [readonly]
 			BSS the device is currently connected to or to which
 			a connection is in progress.
 
+		ao Affinities [optional] [experimental]
+
+			Array of net.connman.iwd.BasicServiceSet object paths
+			that will be treated with higher affinity compared to
+			other BSS's. Currently the only allowed value to be
+			set in this array is the path to the currently connected
+			BasicServiceSet object, i.e.
+			Station.ConnectedAccessPoint.
+
+			Setting the affinity will lower the roaming threshold,
+			effectively locking IWD to the current BSS unless the
+			RSSI drops below the critical threshold set by
+			[General].CriticalRoamThreshold{5G} at which point
+			IWD will proceed with normal roaming behavior.
+
+			This property is cleared on roams/disconnections.
+
 SignalLevelAgent hierarchy
 ==========================
 
src/iwd.config.rst +16 -0
index 0b2878b8..9dc0fe0c 100644
@@ -133,6 +133,22 @@ The group ``[General]`` contains general settings.
        This value can be used to control how aggressively **iwd** roams when
        connected to a 5GHz access point.
 
+   * - CriticalRoamThreshold
+     - Value: rssi dBm value, from -100 to -1, default: **-80**
+
+       The threshold (for 2.4GHz) at which IWD will roam regardless of the
+       affinity set to the current BSS. If the connected BSS has affinity
+       (set in Station's Affinities list) the roam threshold will be lowed to
+       this value and IWD will not attempt to roam (or roam scan) until either
+       the affinity is cleared, or the signal drops below this threshold.
+
+
+   * - CriticalRoamThreshold5G
+     - Value: rssi dBm value, from -100 to -1, default: **-82**
+
+       This has the same effect as ``CriticalRoamThreshold``, but for the 5GHz
+       band.
+
    * - RoamRetryInterval
      - Value: unsigned int value in seconds (default: **60**)
 
Signature · 1 line
2.34.1
#1 lore raw

PATCH v5 2/6 dbus: add PermissionDenied DBus error

---
 src/dbus.c | 6 ++++++
 src/dbus.h | 1 +
 2 files changed, 7 insertions(+)
src/dbus.c +6 -0
index 32de1e1a..b3799b55 100644
@@ -134,6 +134,12 @@ struct l_dbus_message *dbus_error_not_hidden(struct l_dbus_message *msg)
 					"Not hidden");
 }
 
+struct l_dbus_message *dbus_error_permission_denied(struct l_dbus_message *msg)
+{
+	return l_dbus_message_new_error(msg, IWD_SERVICE ".PermissionDenied",
+					"Permission Denied");
+}
+
 struct l_dbus_message *dbus_error_from_errno(int err,
 						struct l_dbus_message *msg)
 {
src/dbus.h +1 -0
index 14814b5d..6d7074bf 100644
@@ -82,6 +82,7 @@ struct l_dbus_message *dbus_error_service_set_overlap(
 struct l_dbus_message *dbus_error_already_provisioned(
 						struct l_dbus_message *msg);
 struct l_dbus_message *dbus_error_not_hidden(struct l_dbus_message *msg);
+struct l_dbus_message *dbus_error_permission_denied(struct l_dbus_message *msg);
 
 struct l_dbus_message *dbus_error_from_errno(int err,
 						struct l_dbus_message *msg);
Signature · 1 line
2.34.1
#2 lore raw

PATCH v5 3/6 station: add Affinities DBus property

In reply to James Prestwood

This property will hold an array of object paths for BasicServiceSet (BSS) objects. For the purpose of this patch only the setter/getter and client watch is implemented. The purpose of this array is to guide or loosely lock IWD to certain BSS's provided that some external client has more information about the environment than what IWD takes into account for its roaming decisions.

For the time being, the array is limited to only the connected BSS path, and any roams or disconnects will clear the array.

The intended use case for this is if the device is stationary an external client could reduce the likelihood of roaming by setting the affinity to the current BSS.

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

v5:
* reworked a lot of the logic removing the loop and instead just trying to get the first path, and fail if a second exists. Also fixed some cleanup on error paths
* Check for FW roaming, and don't allow the affinities to be set if that is enabled.
* Return PermissionDenied error if a client is already managing the affinities.

src/station.c +174 -0
index 30a1232a..1eeefe75 100644
@@ -128,6 +128,10 @@ struct station {
 
 	uint64_t last_roam_scan;
 
+	struct l_queue *affinities;
+	unsigned int affinity_watch;
+	char *affinity_client;
+
 	bool preparing_roam : 1;
 	bool roam_scan_full : 1;
 	bool signal_low : 1;
@@ -449,6 +453,14 @@ static const char *station_get_bss_path(struct station *station,
 	return __network_path_append_bss(network_path, bss);
 }
 
+static bool match_bss_path(const void *data, const void *user_data)
+{
+	const char *path1 = data;
+	const char *path2 = user_data;
+
+	return !strcmp(path1, path2);
+}
+
 static bool station_unregister_bss(struct station *station,
 					struct scan_bss *bss)
 {
@@ -457,6 +469,8 @@ static bool station_unregister_bss(struct station *station,
 	if (L_WARN_ON(!path))
 		return false;
 
+	l_queue_remove_if(station->affinities, match_bss_path, path);
+
 	return l_dbus_unregister_object(dbus_get_bus(), path);
 }
 
@@ -1740,6 +1754,13 @@ static void station_enter_state(struct station *station,
 		station_set_evict_nocarrier(station, true);
 		station_set_drop_neighbor_discovery(station, false);
 		station_set_drop_unicast_l2_multicast(station, false);
+
+		if (station->affinity_watch) {
+			l_dbus_remove_watch(dbus_get_bus(),
+						station->affinity_watch);
+			station->affinity_watch = 0;
+		}
+
 		break;
 	case STATION_STATE_DISCONNECTING:
 	case STATION_STATE_NETCONFIG:
@@ -1747,6 +1768,12 @@ static void station_enter_state(struct station *station,
 	case STATION_STATE_ROAMING:
 	case STATION_STATE_FT_ROAMING:
 	case STATION_STATE_FW_ROAMING:
+		if (station->affinity_watch) {
+			l_dbus_remove_watch(dbus_get_bus(),
+						station->affinity_watch);
+			station->affinity_watch = 0;
+		}
+
 		station_set_evict_nocarrier(station, false);
 		break;
 	}
@@ -4520,6 +4547,144 @@ static bool station_property_get_state(struct l_dbus *dbus,
 	return true;
 }
 
+static bool station_property_get_affinities(struct l_dbus *dbus,
+					struct l_dbus_message *message,
+					struct l_dbus_message_builder *builder,
+					void *user_data)
+{
+	struct station *station = user_data;
+	const struct l_queue_entry *e;
+
+	if (!station->connected_network)
+		return false;
+
+	l_dbus_message_builder_enter_array(builder, "o");
+
+	for (e = l_queue_get_entries(station->affinities); e; e = e->next) {
+		const char *path = e->data;
+
+		l_dbus_message_builder_append_basic(builder, 'o', path);
+	}
+
+	l_dbus_message_builder_leave_array(builder);
+
+	return true;
+}
+
+static void station_affinity_disconnected_cb(struct l_dbus *dbus,
+						void *user_data)
+{
+	struct station *station = user_data;
+
+	l_dbus_remove_watch(dbus_get_bus(), station->affinity_watch);
+	station->affinity_watch = 0;
+
+	l_debug("client that set affinity has disconnected");
+}
+
+static void station_affinity_watch_destroy(void *user_data)
+{
+	struct station *station = user_data;
+	bool empty = l_queue_length(station->affinities) == 0;
+
+	l_free(station->affinity_client);
+	station->affinity_client = NULL;
+
+	l_queue_clear(station->affinities, l_free);
+
+	if (!empty)
+		l_dbus_property_changed(dbus_get_bus(),
+					netdev_get_path(station->netdev),
+					IWD_STATION_INTERFACE, "Affinities");
+}
+
+static struct l_dbus_message *station_property_set_affinities(
+					struct l_dbus *dbus,
+					struct l_dbus_message *message,
+					struct l_dbus_message_iter *new_value,
+					l_dbus_property_complete_cb_t complete,
+					void *user_data)
+{
+	struct station *station = user_data;
+	struct l_dbus_message_iter array;
+	const char *sender = l_dbus_message_get_sender(message);
+	char *old_path = l_queue_peek_head(station->affinities);
+	const char *new_path = NULL;
+	struct scan_bss *new_bss = NULL;
+	struct scan_bss *old_bss = NULL;
+
+	if (!station->connected_network)
+		return dbus_error_not_connected(message);
+
+	if (wiphy_supports_firmware_roam(station->wiphy))
+		return dbus_error_not_supported(message);
+
+	if (station->affinity_watch &&
+				strcmp(station->affinity_client, sender)) {
+		l_warn("Only one client may manage Affinities property");
+		return dbus_error_permission_denied(message);
+	}
+
+	if (!l_dbus_message_iter_get_variant(new_value, "ao", &array))
+		return dbus_error_invalid_args(message);
+
+	/* Get first entry, there should be only one */
+	l_dbus_message_iter_next_entry(&array, &new_path);
+
+	if (l_dbus_message_iter_next_entry(&array, &new_path))
+		return dbus_error_invalid_args(message);
+
+	old_path = l_queue_peek_head(station->affinities);
+	if (old_path)
+		old_bss = l_dbus_object_get_data(dbus_get_bus(),
+						old_path, IWD_BSS_INTERFACE);
+	if (new_path)
+		new_bss = l_dbus_object_get_data(dbus,
+						new_path, IWD_BSS_INTERFACE);
+
+	/* Either the same path, or both arrays are empty */
+	if (old_bss == new_bss) {
+		complete(dbus, message, NULL);
+		return NULL;
+	}
+
+	/*
+	 * TODO: For now only allow the affinities array to contain a single
+	 *       value, the connected BSS path. Any other values will be
+	 *       rejected. This could change in the future.
+	 */
+	if (new_bss && new_bss != station->connected_bss)
+		return dbus_error_invalid_args(message);
+
+	l_queue_clear(station->affinities, l_free);
+
+	/*
+	 * Adding a new BSS, create a watch for this DBus client so if it
+	 * disconnects we can clear the affinities list
+	 */
+	if (new_path) {
+		l_queue_push_head(station->affinities, l_strdup(new_path));
+
+		if (!station->affinity_watch) {
+			station->affinity_client = l_strdup(sender);
+			station->affinity_watch = l_dbus_add_disconnect_watch(
+					dbus, sender,
+					station_affinity_disconnected_cb,
+					station,
+					station_affinity_watch_destroy);
+		}
+	/* The list was cleared, remove the watch */
+	} else if (station->affinity_watch)
+		l_dbus_remove_watch(dbus, station->affinity_watch);
+
+	complete(dbus, message, NULL);
+
+	l_dbus_property_changed(dbus, netdev_get_path(station->netdev),
+				IWD_STATION_INTERFACE, "Affinities");
+
+	return NULL;
+}
+
 void station_foreach(station_foreach_func_t func, void *user_data)
 {
 	const struct l_queue_entry *entry;
@@ -4750,6 +4915,7 @@ static struct station *station_create(struct netdev *netdev)
 	station_set_autoconnect(station, autoconnect);
 
 	station->roam_bss_list = l_queue_new();
+	station->affinities = l_queue_new();
 
 	return station;
 }
@@ -4842,6 +5008,11 @@ static void station_free(struct station *station)
 
 	l_queue_destroy(station->roam_bss_list, l_free);
 
+	if (station->affinity_watch)
+		l_dbus_remove_watch(dbus_get_bus(), station->affinity_watch);
+
+	l_queue_destroy(station->affinities, l_free);
+
 	l_free(station);
 }
 
@@ -4878,6 +5049,9 @@ static void station_setup_interface(struct l_dbus_interface *interface)
 					station_property_get_scanning, NULL);
 	l_dbus_interface_property(interface, "State", 0, "s",
 					station_property_get_state, NULL);
+	l_dbus_interface_property(interface, "Affinities", 0, "ao",
+					station_property_get_affinities,
+					station_property_set_affinities);
 }
 
 static void station_destroy_interface(void *user_data)
Signature · 1 line
2.34.1
#3 lore raw

PATCH v5 4/6 station: Use Affinities property to change roaming threshold

In reply to James Prestwood

When the affinity is set to the current BSS lower the roaming threshold to loosly lock IWD to the current BSS. The lower threshold is automatically removed upon roaming/disconnection since the affinity array is also cleared out.

---
 src/station.c | 17 +++++++++++++++++
 1 file changed, 17 insertions(+)
src/station.c +17 -0
index 1eeefe75..c45d13df 100644
@@ -4580,6 +4580,9 @@ static void station_affinity_disconnected_cb(struct l_dbus *dbus,
 	station->affinity_watch = 0;
 
 	l_debug("client that set affinity has disconnected");
+
+	/* The client who set the affinity disconnected, raise the threshold */
+	netdev_raise_signal_threshold(station->netdev);
 }
 
 static void station_affinity_watch_destroy(void *user_data)
@@ -4612,6 +4615,7 @@ static struct l_dbus_message *station_property_set_affinities(
 	const char *new_path = NULL;
 	struct scan_bss *new_bss = NULL;
 	struct scan_bss *old_bss = NULL;
+	bool lower_threshold = false;
 
 	if (!station->connected_network)
 		return dbus_error_not_connected(message);
@@ -4665,6 +4669,8 @@ static struct l_dbus_message *station_property_set_affinities(
 	if (new_path) {
 		l_queue_push_head(station->affinities, l_strdup(new_path));
 
+		lower_threshold = true;
+
 		if (!station->affinity_watch) {
 			station->affinity_client = l_strdup(sender);
 			station->affinity_watch = l_dbus_add_disconnect_watch(
@@ -4677,6 +4683,17 @@ static struct l_dbus_message *station_property_set_affinities(
 	} else if (station->affinity_watch)
 		l_dbus_remove_watch(dbus, station->affinity_watch);
 
+	/*
+	 * If affinity was set to the current BSS, lower the roam threshold. If
+	 * the connected BSS was not in the list raise the signal threshold.
+	 * The threshold may already be raised, in which case netdev will detect
+	 * this and do nothing.
+	 */
+	if (lower_threshold)
+		netdev_lower_signal_threshold(station->netdev);
+	else
+		netdev_raise_signal_threshold(station->netdev);
+
 	complete(dbus, message, NULL);
 
 	l_dbus_property_changed(dbus, netdev_get_path(station->netdev),
Signature · 1 line
2.34.1
#4 lore raw

PATCH v5 5/6 auto-t: add affinities property for station, and extended_service_set

In reply to James Prestwood
---
 autotests/util/iwd.py | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)
autotests/util/iwd.py +18 -0
index 74bb25c0..83f2d9ef 100755
@@ -596,6 +596,11 @@ class Device(IWDDBusAbstract):
         props = self._station_properties()
         return props.get('ConnectedNetwork')
 
+    @property
+    def connected_bss(self):
+        props = self._station_properties()
+        return props.get('ConnectedAccessPoint')
+
     @property
     def powered(self):
         '''
@@ -630,6 +635,19 @@ class Device(IWDDBusAbstract):
         self._station_debug._prop_proxy.Set(IWD_STATION_DEBUG_INTERFACE,
                                             'AutoConnect', value)
 
+    @property
+    def affinities(self):
+        return self._station_properties()['Affinities']
+
+    @affinities.setter
+    def affinities(self, values):
+        self._station_properties()
+        self._station_prop_if.Set(
+            IWD_STATION_INTERFACE, 'Affinities',
+            dbus.Array([dbus.ObjectPath(v) for v in values], signature="o"),
+            reply_handler=self._success, error_handler=self._failure)
+        self._wait_for_async_op()
+
     def scan(self, wait=True):
         '''Schedule a network scan.
 
Signature · 1 line
2.34.1
#5 lore raw

PATCH v5 6/6 auto-t: add tests for Affinities behavior

In reply to James Prestwood
---
 autotests/testAffinity/TestFT.psk           |   2 +
 autotests/testAffinity/ft-psk-ccmp-1.conf   |  41 ++++
 autotests/testAffinity/ft-psk-ccmp-2.conf   |  41 ++++
 autotests/testAffinity/hw.conf              |   8 +
 autotests/testAffinity/main.conf            |   5 +
 autotests/testAffinity/test_set_affinity.py | 216 ++++++++++++++++++++
 6 files changed, 313 insertions(+)
 create mode 100644 autotests/testAffinity/TestFT.psk
 create mode 100644 autotests/testAffinity/ft-psk-ccmp-1.conf
 create mode 100644 autotests/testAffinity/ft-psk-ccmp-2.conf
 create mode 100644 autotests/testAffinity/hw.conf
 create mode 100644 autotests/testAffinity/main.conf
 create mode 100644 autotests/testAffinity/test_set_affinity.py
autotests/testAffinity/TestFT.psk new file +2 -0
new file mode 100644
index 00000000..e82d1295
@@ -0,0 +1,2 @@
+[Security]
+Passphrase=EasilyGuessedPassword
autotests/testAffinity/ft-psk-ccmp-1.conf new file +41 -0

41 lines not on this page · raw message

autotests/testAffinity/ft-psk-ccmp-2.conf new file +41 -0

41 lines not on this page · raw message

autotests/testAffinity/hw.conf new file +8 -0
new file mode 100644
index 00000000..c2b35d6e
@@ -0,0 +1,8 @@
+[SETUP]
+num_radios=3
+start_iwd=0
+hwsim_medium=yes
+
+[HOSTAPD]
+rad0=ft-psk-ccmp-1.conf
+rad1=ft-psk-ccmp-2.conf
autotests/testAffinity/main.conf new file +5 -0
new file mode 100644
index 00000000..3d93ff57
@@ -0,0 +1,5 @@
+[Scan]
+DisableMacAddressRandomization=true
+
+[General]
+RoamRetryInterval=1
autotests/testAffinity/test_set_affinity.py new file +216 -0

216 lines not on this page · raw message

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

Hi James,

Quoted 13 lines · James Prestwood

This documents new DBus property that expose a bit more control to how IWD roams.

Setting the affinity on the connected BSS effectively "locks" IWD to that BSS (except at critical RSSI levels, explained below). This can be useful for clients that have access to more information about the environment than IWD. For example, if a client is stationary there is likely no point in trying to roam until it has moved elsewhere.

A new main.conf option would also be added:

[General].CriticalRoamThreshold

Quoted 8 lines

This would be the new roam threshold set if the currently connected BSS is in the Affinities list. If the RSSI continues to drop below this level IWD will still attempt to roam.

---
  doc/station-api.txt | 17 +++++++++++++++++
  src/iwd.config.rst  | 16 ++++++++++++++++
  2 files changed, 33 insertions(+)

All applied, thanks.

Regards,
-Denis