Skip to contentSkip to conversation

doc: Document station Affinities property

PATCH Superseded James Prestwood 2 participants 11 messages Aug 23, 2024 – Aug 28, 2024

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH v4 1/8 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 d9c94e01..2d1f6dcd 100644
@@ -130,6 +130,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 v4 2/8 netdev: define netdev settings in netdev.h

Following knownnetworks, this moves the settings into a header file which is easier to maintain/read.

---
 src/netdev.c | 8 ++++----
 src/netdev.h | 5 +++++
 2 files changed, 9 insertions(+), 4 deletions(-)

v4:
* Fix typos

src/netdev.c +4 -4
index 494e46a5..e0121095 100644
@@ -6264,16 +6264,16 @@ static int netdev_init(void)
 		goto fail_netlink;
 	}
 
-	if (!l_settings_get_int(settings, "General", "RoamThreshold",
+	if (!l_settings_get_int(settings, NETDEV_ROAM_THRESHOLD,
 					&LOW_SIGNAL_THRESHOLD))
 		LOW_SIGNAL_THRESHOLD = -70;
 
-	if (!l_settings_get_int(settings, "General", "RoamThreshold5G",
+	if (!l_settings_get_int(settings, NETDEV_ROAM_THRESHOLD_5G,
 					&LOW_SIGNAL_THRESHOLD_5GHZ))
 		LOW_SIGNAL_THRESHOLD_5GHZ = -76;
 
-	rand_addr_str = l_settings_get_value(settings, "General",
-						"AddressRandomization");
+	rand_addr_str = l_settings_get_value(settings,
+						NETDEV_ADDRESS_RANDOMIZATION);
 	if (rand_addr_str && !strcmp(rand_addr_str, "network"))
 		mac_per_ssid = true;
 
src/netdev.h +5 -0
index db0440d0..c48b2c38 100644
@@ -29,6 +29,11 @@ struct eapol_sm;
 struct mmpdu_header;
 struct diagnostic_station_info;
 
+#define GENERAL "General"
+#define NETDEV_ADDRESS_RANDOMIZATION GENERAL, "AddressRandomization"
+#define NETDEV_ROAM_THRESHOLD GENERAL, "RoamThreshold"
+#define NETDEV_ROAM_THRESHOLD_5G GENERAL, "RoamThreshold5G"
+
 enum netdev_result {
 	NETDEV_RESULT_OK,
 	NETDEV_RESULT_AUTHENTICATION_FAILED,
Signature · 1 line
2.34.1
#2 lore raw

Re: [PATCH v4 2/8] netdev: define netdev settings in netdev.h

Hi James,

Quoted 10 lines · James Prestwood

Following knownnetworks, this moves the settings into a header file which is easier to maintain/read.

---
  src/netdev.c | 8 ++++----
  src/netdev.h | 5 +++++
  2 files changed, 9 insertions(+), 4 deletions(-)

v4:
* Fix typos

Patches 2-4 applied, thanks.

Regards,
-Denis

#3 lore raw

PATCH v4 3/8 netdev: store signal threshold in netdev object, not globally

In reply to James Prestwood

This prepares for the ability to toggle between two signal thresholds in netdev. Since each netdev may not need/want the same threshold store it in the netdev object rather than globally.

---
 src/netdev.c | 22 ++++++++++++++--------
 1 file changed, 14 insertions(+), 8 deletions(-)
src/netdev.c +14 -8
index e0121095..1f1b9400 100644
@@ -172,6 +172,9 @@ struct netdev {
 
 	struct netdev_ext_key_info *ext_key_info;
 
+	int low_signal_threshold;
+	int low_signal_threshold_5ghz;
+
 	bool connected : 1;
 	bool associated : 1;
 	bool operational : 1;
@@ -206,6 +209,9 @@ static struct l_genl_family *nl80211;
 static struct l_queue *netdev_list;
 static struct watchlist netdev_watches;
 static bool mac_per_ssid;
+/* Threshold RSSI for roaming to trigger, configurable in main.conf */
+static int LOW_SIGNAL_THRESHOLD;
+static int LOW_SIGNAL_THRESHOLD_5GHZ;
 
 static unsigned int iov_ie_append(struct iovec *iov,
 					unsigned int n_iov, unsigned int c,
@@ -1058,10 +1064,6 @@ struct netdev *netdev_find(int ifindex)
 	return l_queue_find(netdev_list, netdev_match, L_UINT_TO_PTR(ifindex));
 }
 
-/* Threshold RSSI for roaming to trigger, configurable in main.conf */
-static int LOW_SIGNAL_THRESHOLD;
-static int LOW_SIGNAL_THRESHOLD_5GHZ;
-
 static void netdev_cqm_event_rssi_threshold(struct netdev *netdev,
 						uint32_t rssi_event)
 {
@@ -1089,8 +1091,9 @@ static void netdev_cqm_event_rssi_value(struct netdev *netdev, int rssi_val)
 {
 	bool new_rssi_low;
 	uint8_t prev_rssi_level_idx = netdev->cur_rssi_level_idx;
-	int threshold = netdev->frequency > 4000 ? LOW_SIGNAL_THRESHOLD_5GHZ :
-						LOW_SIGNAL_THRESHOLD;
+	int threshold = netdev->frequency > 4000 ?
+					netdev->low_signal_threshold_5ghz :
+					netdev->low_signal_threshold;
 
 	if (!netdev->connected)
 		return;
@@ -3585,8 +3588,9 @@ static struct l_genl_msg *netdev_build_cmd_cqm_rssi_update(
 	uint32_t hyst = 5;
 	int thold_count;
 	int32_t thold_list[levels_num + 2];
-	int threshold = netdev->frequency > 4000 ? LOW_SIGNAL_THRESHOLD_5GHZ :
-						LOW_SIGNAL_THRESHOLD;
+	int threshold = netdev->frequency > 4000 ?
+					netdev->low_signal_threshold_5ghz :
+					netdev->low_signal_threshold;
 
 	if (levels_num == 0) {
 		thold_list[0] = threshold;
@@ -6163,6 +6167,8 @@ struct netdev *netdev_create_from_genl(struct l_genl_msg *msg,
 	l_strlcpy(netdev->name, ifname, IFNAMSIZ);
 	netdev->wiphy = wiphy;
 	netdev->pae_over_nl80211 = pae_io == NULL;
+	netdev->low_signal_threshold = LOW_SIGNAL_THRESHOLD;
+	netdev->low_signal_threshold_5ghz = LOW_SIGNAL_THRESHOLD_5GHZ;
 
 	if (set_mac)
 		memcpy(netdev->set_mac_once, set_mac, 6);
Signature · 1 line
2.34.1
#4 lore raw

PATCH v4 4/8 netdev: add critical signal threshold level

In reply to James Prestwood

This adds a secondary set of signal thresholds. The purpose of these are to provide more flexibility in how IWD roams. The critical threshold is intended to be temporary and is automatically reset upon any connection changes: disconnects, roams, or new connections.

---
 src/netdev.c | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++
 src/netdev.h |  4 ++++
 2 files changed, 55 insertions(+)
src/netdev.c +51 -0
index 1f1b9400..73fbf0c1 100644
@@ -212,6 +212,8 @@ static bool mac_per_ssid;
 /* Threshold RSSI for roaming to trigger, configurable in main.conf */
 static int LOW_SIGNAL_THRESHOLD;
 static int LOW_SIGNAL_THRESHOLD_5GHZ;
+static int CRITICAL_SIGNAL_THRESHOLD;
+static int CRITICAL_SIGNAL_THRESHOLD_5GHZ;
 
 static unsigned int iov_ie_append(struct iovec *iov,
 					unsigned int n_iov, unsigned int c,
@@ -841,6 +843,10 @@ static void netdev_connect_free(struct netdev *netdev)
 		l_genl_family_cancel(nl80211, netdev->get_oci_cmd_id);
 		netdev->get_oci_cmd_id = 0;
 	}
+
+	/* Reset thresholds back to default */
+	netdev->low_signal_threshold = LOW_SIGNAL_THRESHOLD;
+	netdev->low_signal_threshold_5ghz = LOW_SIGNAL_THRESHOLD_5GHZ;
 }
 
 static void netdev_connect_failed(struct netdev *netdev,
@@ -3674,6 +3680,39 @@ static int netdev_cqm_rssi_update(struct netdev *netdev)
 	return 0;
 }
 
+static int netdev_set_signal_thresholds(struct netdev *netdev, int threshold,
+					int threshold_5ghz)
+{
+	int current = netdev->frequency > 4000 ?
+					netdev->low_signal_threshold_5ghz :
+					netdev->low_signal_threshold;
+	int new = netdev->frequency > 4000 ? threshold_5ghz : threshold;
+
+	if (current == new)
+		return -EALREADY;
+
+	l_debug("changing low signal threshold to %d", new);
+
+	netdev->low_signal_threshold = threshold;
+	netdev->low_signal_threshold_5ghz = threshold_5ghz;
+
+	netdev_cqm_rssi_update(netdev);
+
+	return 0;
+}
+
+int netdev_lower_signal_threshold(struct netdev *netdev)
+{
+	return netdev_set_signal_thresholds(netdev, CRITICAL_SIGNAL_THRESHOLD,
+						CRITICAL_SIGNAL_THRESHOLD_5GHZ);
+}
+
+int netdev_raise_signal_threshold(struct netdev *netdev)
+{
+	return netdev_set_signal_thresholds(netdev, LOW_SIGNAL_THRESHOLD,
+						LOW_SIGNAL_THRESHOLD_5GHZ);
+}
+
 static bool netdev_connection_work_ready(struct wiphy_radio_work_item *item)
 {
 	struct netdev *netdev = l_container_of(item, struct netdev, work);
@@ -3887,6 +3926,8 @@ done:
 	netdev->handshake = hs;
 	netdev->sm = sm;
 	netdev->cur_rssi = bss->signal_strength / 100;
+	netdev->low_signal_threshold = LOW_SIGNAL_THRESHOLD;
+	netdev->low_signal_threshold_5ghz = LOW_SIGNAL_THRESHOLD_5GHZ;
 
 	if (netdev->rssi_levels_num)
 		netdev_set_rssi_level_idx(netdev);
@@ -4260,6 +4301,8 @@ int netdev_ft_reassociate(struct netdev *netdev,
 	netdev->event_filter = event_filter;
 	netdev->connect_cb = cb;
 	netdev->user_data = user_data;
+	netdev->low_signal_threshold = LOW_SIGNAL_THRESHOLD;
+	netdev->low_signal_threshold_5ghz = LOW_SIGNAL_THRESHOLD_5GHZ;
 
 	/*
 	 * Cancel commands that could be running because of EAPoL activity
@@ -6278,6 +6321,14 @@ static int netdev_init(void)
 					&LOW_SIGNAL_THRESHOLD_5GHZ))
 		LOW_SIGNAL_THRESHOLD_5GHZ = -76;
 
+	if (!l_settings_get_int(settings, NETDEV_CRITICAL_ROAM_THRESHOLD,
+					&CRITICAL_SIGNAL_THRESHOLD))
+		CRITICAL_SIGNAL_THRESHOLD = -80;
+
+	if (!l_settings_get_int(settings, NETDEV_CRITICAL_ROAM_THRESHOLD_5G,
+					&CRITICAL_SIGNAL_THRESHOLD_5GHZ))
+		CRITICAL_SIGNAL_THRESHOLD_5GHZ = -82;
+
 	rand_addr_str = l_settings_get_value(settings,
 						NETDEV_ADDRESS_RANDOMIZATION);
 	if (rand_addr_str && !strcmp(rand_addr_str, "network"))
src/netdev.h +4 -0
index c48b2c38..6299934e 100644
@@ -33,6 +33,8 @@ struct diagnostic_station_info;
 #define NETDEV_ADDRESS_RANDOMIZATION GENERAL, "AddressRandomization"
 #define NETDEV_ROAM_THRESHOLD GENERAL, "RoamThreshold"
 #define NETDEV_ROAM_THRESHOLD_5G GENERAL, "RoamThreshold5G"
+#define NETDEV_CRITICAL_ROAM_THRESHOLD GENERAL, "CriticalRoamThreshold"
+#define NETDEV_CRITICAL_ROAM_THRESHOLD_5G GENERAL, "CriticalRoamThreshold5G"
 
 enum netdev_result {
 	NETDEV_RESULT_OK,
@@ -202,6 +204,8 @@ int netdev_neighbor_report_req(struct netdev *netdev,
 
 int netdev_set_rssi_report_levels(struct netdev *netdev, const int8_t *levels,
 					size_t levels_num);
+int netdev_lower_signal_threshold(struct netdev *netdev);
+int netdev_raise_signal_threshold(struct netdev *netdev);
 
 int netdev_get_station(struct netdev *netdev, const uint8_t *mac,
 			netdev_get_station_cb_t cb, void *user_data,
Signature · 1 line
2.34.1
#5 lore raw

PATCH v4 5/8 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 loosly 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 | 145 ++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 145 insertions(+)
src/station.c +145 -0
index 30a1232a..c72d42ae 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,118 @@ 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;
+
+	l_free(station->affinity_client);
+	station->affinity_client = NULL;
+
+	l_queue_destroy(station->affinities, l_free);
+	station->affinities = NULL;
+
+	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);
+	const char *path;
+	struct l_queue *new_affinities;
+
+	if (!station->connected_network)
+		return dbus_error_not_connected(message);
+
+	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);
+	} else if (strcmp(station->affinity_client, sender)) {
+		l_warn("Only one client may manage Affinities property");
+		return dbus_error_not_available(message);
+	}
+
+	if (!l_dbus_message_iter_get_variant(new_value, "ao", &array))
+		return dbus_error_invalid_args(message);
+
+	new_affinities = l_queue_new();
+
+	while (l_dbus_message_iter_next_entry(&array, &path)) {
+		struct scan_bss *bss = l_dbus_object_get_data(dbus_get_bus(),
+						path,
+						IWD_BSS_INTERFACE);
+
+		/*
+		 * TODO: For now only allow the affinities array to contain the
+		 *       connected BSS path. Any other values will be rejected.
+		 *       This could change in the future.
+		 */
+		if (bss != station->connected_bss) {
+			l_queue_destroy(new_affinities, l_free);
+			return dbus_error_invalid_args(message);
+		}
+
+		l_queue_push_head(new_affinities, l_strdup(path));
+	}
+
+	l_queue_destroy(station->affinities, l_free);
+	station->affinities = new_affinities;
+
+	l_dbus_property_changed(dbus, netdev_get_path(station->netdev),
+				IWD_STATION_INTERFACE, "Affinities");
+
+	complete(dbus, message, NULL);
+
+	return NULL;
+}
+
 void station_foreach(station_foreach_func_t func, void *user_data)
 {
 	const struct l_queue_entry *entry;
@@ -4842,6 +4981,9 @@ 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_free(station);
 }
 
@@ -4878,6 +5020,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
#6 lore raw

Re: [PATCH v4 5/8] station: add Affinities DBus property

Hi James,

Quoted 4 lines · 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 loosly lock IWD to certain

typo: 'loosely'

Quoted 54 lines

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 | 145 ++++++++++++++++++++++++++++++++++++++++++++++++++
  1 file changed, 145 insertions(+)
src/station.c +14 -0
index 30a1232a..c72d42ae 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);
  }
 

src/station.c static void station_enter_state(struct station *station, · line 1763

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

Hmm, but not resetting affinities?

src/station.c static void station_enter_state(struct station *station, · line 1774

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

Okay. This reminds me that for hardware supporting FW roaming we may want to return NotCapable when setting Affinities.

Quoted 5 lines
src/station.c +2 -0
+		}
+
  		station_set_evict_nocarrier(station, false);
  		break;
  	}

<snip>

src/station.c static bool station_property_get_state(struct l_dbus *dbus, · line 4597

Quoted 13 lines
src/station.c +13 -0
+static void station_affinity_watch_destroy(void *user_data)
+{
+	struct station *station = user_data;
+
+	l_free(station->affinity_client);
+	station->affinity_client = NULL;
+
+	l_queue_destroy(station->affinities, l_free);
+	station->affinities = NULL;
+
+	l_dbus_property_changed(dbus_get_bus(),
+				netdev_get_path(station->netdev),
+				IWD_STATION_INTERFACE, "Affinities");

What if the list was empty?

Quoted 18 lines
src/station.c +18 -0
+}
+
+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);
+	const char *path;
+	struct l_queue *new_affinities;
+
+	if (!station->connected_network)
+		return dbus_error_not_connected(message);
+

src/station.c static bool station_property_get_state(struct l_dbus *dbus, · line 4625

Quoted 10 lines
src/station.c +10 -0
+	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);
+	} else if (strcmp(station->affinity_client, sender)) {
+		l_warn("Only one client may manage Affinities property");
+		return dbus_error_not_available(message);

Hmm, we probably need a new error for 'permission denied or something'

src/station.c static bool station_property_get_state(struct l_dbus *dbus, · line 4629

Quoted 4 lines
src/station.c +4 -0
+	}
+
+	if (!l_dbus_message_iter_get_variant(new_value, "ao", &array))
+		return dbus_error_invalid_args(message);

So what happens to affinity_client / affinity_watch above?

Quoted 6 lines
src/station.c +6 -0
+
+	new_affinities = l_queue_new();
+
+	while (l_dbus_message_iter_next_entry(&array, &path)) {
+		struct scan_bss *bss = l_dbus_object_get_data(dbus_get_bus(),
+						path,

src/station.c static bool station_property_get_state(struct l_dbus *dbus, · line 4645

Quoted 10 lines
src/station.c +10 -0
+						IWD_BSS_INTERFACE);
+
+		/*
+		 * TODO: For now only allow the affinities array to contain the
+		 *       connected BSS path. Any other values will be rejected.
+		 *       This could change in the future.
+		 */
+		if (bss != station->connected_bss) {
+			l_queue_destroy(new_affinities, l_free);
+			return dbus_error_invalid_args(message);

same as above?

You may want to make your life easier by just looking for an empty list or list of size 1 with the connected bss.

src/station.c static bool station_property_get_state(struct l_dbus *dbus, · line 4652

Quoted 7 lines
src/station.c +7 -0
+		}
+
+		l_queue_push_head(new_affinities, l_strdup(path));
+	}
+
+	l_queue_destroy(station->affinities, l_free);
+	station->affinities = new_affinities;

If the list is empty, should you unregister the watch?

src/station.c static bool station_property_get_state(struct l_dbus *dbus, · line 4657

Quoted 5 lines
src/station.c +5 -0
+
+	l_dbus_property_changed(dbus, netdev_get_path(station->netdev),
+				IWD_STATION_INTERFACE, "Affinities");
+
+	complete(dbus, message, NULL);

It is the other way around, we send the 'message_return' first, then the signal.
Do you want to spuriously emit if the two lists are the same?

src/station.c static bool station_property_get_state(struct l_dbus *dbus, · line 4664

Quoted 7 lines
src/station.c +4 -0
+
+	return NULL;
+}
+
  void station_foreach(station_foreach_func_t func, void *user_data)
  {
  	const struct l_queue_entry *entry;

Regards,
-Denis

#7 lore raw

PATCH v4 6/8 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 c72d42ae..ca0b5329 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)
@@ -4609,6 +4612,7 @@ static struct l_dbus_message *station_property_set_affinities(
 	const char *sender = l_dbus_message_get_sender(message);
 	const char *path;
 	struct l_queue *new_affinities;
+	bool lower_threshold = false;
 
 	if (!station->connected_network)
 		return dbus_error_not_connected(message);
@@ -4645,6 +4649,8 @@ static struct l_dbus_message *station_property_set_affinities(
 			return dbus_error_invalid_args(message);
 		}
 
+		lower_threshold = true;
+
 		l_queue_push_head(new_affinities, l_strdup(path));
 	}
 
@@ -4654,6 +4660,17 @@ static struct l_dbus_message *station_property_set_affinities(
 	l_dbus_property_changed(dbus, netdev_get_path(station->netdev),
 				IWD_STATION_INTERFACE, "Affinities");
 
+	/*
+	 * 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);
 
 	return NULL;
Signature · 1 line
2.34.1
#8 lore raw

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

PATCH v4 8/8 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
#10 lore raw
In reply to James Prestwood

Hi James,

src/iwd.config.rst The group ``[General]`` contains general settings. · line 134

Quoted 10 lines
src/iwd.config.rst +2 -0
index d9c94e01..2d1f6dcd 100644
@@ -130,6 +130,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**

-100 to -1?

src/iwd.config.rst The group ``[General]`` contains general settings. · line 145

Quoted 11 lines
src/iwd.config.rst +11 -0
+
+       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**
+

as above?

src/iwd.config.rst The group ``[General]`` contains general settings. · line 151

Quoted 6 lines
src/iwd.config.rst +3 -0
+       This has the same effect as ``CriticalRoamThreshold``, but for the 5GHz
+       band.
+
     * - RoamRetryInterval
       - Value: unsigned int value in seconds (default: **60**)
 

Regards,
-Denis