* [PATCH 1/9] doc: Document station Affinities property
@ 2024-08-13 15:56 James Prestwood
2024-08-13 15:56 ` [PATCH 2/9] netdev: store signal threshold in netdev object, not globally James Prestwood
` (7 more replies)
0 siblings, 8 replies; 9+ messages in thread
From: James Prestwood @ 2024-08-13 15:56 UTC (permalink / raw)
To: iwd; +Cc: 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.
Setting the affinity on a BSS (regardless if the connected BSS) will
also cause a modified ranking factor to be applied to the BSS. This
could be used to push IWD to certain BSS's over others. Similar to
above, the affinity ranking factor for a BSS will only be applied if
that BSS's signal is above the crtical roaming threshold.
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 | 19 +++++++++++++++++++
src/iwd.config.rst | 20 ++++++++++++++++++++
2 files changed, 39 insertions(+)
diff --git a/doc/station-api.txt b/doc/station-api.txt
index 84f1b7bf..c22c57d4 100644
--- a/doc/station-api.txt
+++ b/doc/station-api.txt
@@ -170,6 +170,25 @@ Properties string State [readonly]
BSS the device is currently connected to or to which
a connection is in progress.
+ ao Affinities [optional]
+
+ Array of net.connman.iwd.BasicServiceSet object paths
+ that will be treated with higher affinity compared to
+ other BSS's. The affinity comes into play in two
+ scenarios:
+
+ 1. If the connected BSS is in the Affinities list the
+ roaming threshold will be lowered to loosly lock IWD
+ to its current BSS. This prevents IWD from roaming
+ unless the signal drops below the critical threshold
+ (i.e. main.conf: [General].CriticalRoamThreshold).
+
+ 2. A ranking factor will be applied to all BSS in the
+ Affinities list while choosing a roaming candidate.
+ The only exception here is if the BSS's signal
+ is below the critical roaming threshold.
+ (i.e. main.conf: [General].CriticalRoamTreshold)
+
SignalLevelAgent hierarchy
==========================
diff --git a/src/iwd.config.rst b/src/iwd.config.rst
index d9c94e01..7221c149 100644
--- a/src/iwd.config.rst
+++ b/src/iwd.config.rst
@@ -130,6 +130,26 @@ 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. This is used in two ways:
+
+ 1. 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.
+
+ 2. The affinity ranking factor will not be appled if the BSS's signal is
+ 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**)
--
2.34.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 2/9] netdev: store signal threshold in netdev object, not globally
2024-08-13 15:56 [PATCH 1/9] doc: Document station Affinities property James Prestwood
@ 2024-08-13 15:56 ` James Prestwood
2024-08-13 15:56 ` [PATCH 3/9] netdev: add critical signal threshold level James Prestwood
` (6 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: James Prestwood @ 2024-08-13 15:56 UTC (permalink / raw)
To: iwd; +Cc: 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(-)
diff --git a/src/netdev.c b/src/netdev.c
index 494e46a5..a9648fbc 100644
--- a/src/netdev.c
+++ b/src/netdev.c
@@ -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);
--
2.34.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 3/9] netdev: add critical signal threshold level
2024-08-13 15:56 [PATCH 1/9] doc: Document station Affinities property James Prestwood
2024-08-13 15:56 ` [PATCH 2/9] netdev: store signal threshold in netdev object, not globally James Prestwood
@ 2024-08-13 15:56 ` James Prestwood
2024-08-13 15:56 ` [PATCH 4/9] netdev: add netdev_get_critical_signal_threshold James Prestwood
` (5 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: James Prestwood @ 2024-08-13 15:56 UTC (permalink / raw)
To: iwd; +Cc: 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 | 2 ++
2 files changed, 53 insertions(+)
diff --git a/src/netdev.c b/src/netdev.c
index a9648fbc..94766552 100644
--- a/src/netdev.c
+++ b/src/netdev.c
@@ -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, "General", "CriticalRoamThreshold",
+ &CRITICAL_SIGNAL_THRESHOLD))
+ CRITICAL_SIGNAL_THRESHOLD = -80;
+
+ if (!l_settings_get_int(settings, "General", "CriticalRoamThreshold5G",
+ &CRITICAL_SIGNAL_THRESHOLD_5GHZ))
+ CRITICAL_SIGNAL_THRESHOLD_5GHZ = -82;
+
rand_addr_str = l_settings_get_value(settings, "General",
"AddressRandomization");
if (rand_addr_str && !strcmp(rand_addr_str, "network"))
diff --git a/src/netdev.h b/src/netdev.h
index db0440d0..3a772256 100644
--- a/src/netdev.h
+++ b/src/netdev.h
@@ -197,6 +197,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,
--
2.34.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 4/9] netdev: add netdev_get_critical_signal_threshold
2024-08-13 15:56 [PATCH 1/9] doc: Document station Affinities property James Prestwood
2024-08-13 15:56 ` [PATCH 2/9] netdev: store signal threshold in netdev object, not globally James Prestwood
2024-08-13 15:56 ` [PATCH 3/9] netdev: add critical signal threshold level James Prestwood
@ 2024-08-13 15:56 ` James Prestwood
2024-08-13 15:56 ` [PATCH 5/9] station: emit property changed for ConnectedAccessPoint James Prestwood
` (4 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: James Prestwood @ 2024-08-13 15:56 UTC (permalink / raw)
To: iwd; +Cc: James Prestwood
This is set via a main.conf option but to avoid duplicated settings
parsing in station add a getter API.
---
src/netdev.c | 6 ++++++
src/netdev.h | 1 +
2 files changed, 7 insertions(+)
diff --git a/src/netdev.c b/src/netdev.c
index 94766552..c7d0d880 100644
--- a/src/netdev.c
+++ b/src/netdev.c
@@ -3713,6 +3713,12 @@ int netdev_raise_signal_threshold(struct netdev *netdev)
LOW_SIGNAL_THRESHOLD_5GHZ);
}
+int netdev_get_critical_signal_threshold(struct netdev *netdev)
+{
+ return netdev->frequency > 4000 ? CRITICAL_SIGNAL_THRESHOLD_5GHZ :
+ CRITICAL_SIGNAL_THRESHOLD;
+}
+
static bool netdev_connection_work_ready(struct wiphy_radio_work_item *item)
{
struct netdev *netdev = l_container_of(item, struct netdev, work);
diff --git a/src/netdev.h b/src/netdev.h
index 3a772256..f89aa572 100644
--- a/src/netdev.h
+++ b/src/netdev.h
@@ -199,6 +199,7 @@ 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_critical_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,
--
2.34.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 5/9] station: emit property changed for ConnectedAccessPoint
2024-08-13 15:56 [PATCH 1/9] doc: Document station Affinities property James Prestwood
` (2 preceding siblings ...)
2024-08-13 15:56 ` [PATCH 4/9] netdev: add netdev_get_critical_signal_threshold James Prestwood
@ 2024-08-13 15:56 ` James Prestwood
2024-08-13 15:56 ` [PATCH 6/9] station: add Affinities DBus property James Prestwood
` (3 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: James Prestwood @ 2024-08-13 15:56 UTC (permalink / raw)
To: iwd; +Cc: James Prestwood
This was missed in a prior patch set. When station is connecting
or disconnecting ConnectedAccessPoint property change should be
emitted.
---
src/station.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/src/station.c b/src/station.c
index 06b19db3..3b61f264 100644
--- a/src/station.c
+++ b/src/station.c
@@ -1639,6 +1639,8 @@ static void station_enter_state(struct station *station,
l_dbus_property_changed(dbus, netdev_get_path(station->netdev),
IWD_STATION_INTERFACE, "ConnectedNetwork");
+ l_dbus_property_changed(dbus, netdev_get_path(station->netdev),
+ IWD_STATION_INTERFACE, "ConnectedAccessPoint");
l_dbus_property_changed(dbus,
network_get_path(station->connected_network),
IWD_NETWORK_INTERFACE, "Connected");
@@ -1810,6 +1812,8 @@ static void station_reset_connection_state(struct station *station)
l_dbus_property_changed(dbus, netdev_get_path(station->netdev),
IWD_STATION_INTERFACE, "ConnectedNetwork");
+ l_dbus_property_changed(dbus, netdev_get_path(station->netdev),
+ IWD_STATION_INTERFACE, "ConnectedAccessPoint");
l_dbus_property_changed(dbus, network_get_path(network),
IWD_NETWORK_INTERFACE, "Connected");
l_dbus_object_remove_interface(dbus, netdev_get_path(station->netdev),
--
2.34.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 6/9] station: add Affinities DBus property
2024-08-13 15:56 [PATCH 1/9] doc: Document station Affinities property James Prestwood
` (3 preceding siblings ...)
2024-08-13 15:56 ` [PATCH 5/9] station: emit property changed for ConnectedAccessPoint James Prestwood
@ 2024-08-13 15:56 ` James Prestwood
2024-08-13 15:56 ` [PATCH 7/9] station: Use Affinities property for roaming/ranking decisions James Prestwood
` (2 subsequent siblings)
7 siblings, 0 replies; 9+ messages in thread
From: James Prestwood @ 2024-08-13 15:56 UTC (permalink / raw)
To: iwd; +Cc: 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 example:
- If the device is stationary an external client could reduce
the likelihood of roaming by setting the affinity to the
current BSS.
- If an external client has knowledge of the devices planned
route though the environment it could plan a path to roam
between particular APs to reduce and optimize roaming.
---
src/station.c | 124 ++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 124 insertions(+)
diff --git a/src/station.c b/src/station.c
index 3b61f264..75dd13bb 100644
--- a/src/station.c
+++ b/src/station.c
@@ -128,6 +128,10 @@ struct station {
uint64_t last_roam_scan;
+ char **affinities;
+ unsigned int affinity_watch;
+ char *affinity_client;
+
bool preparing_roam : 1;
bool roam_scan_full : 1;
bool signal_low : 1;
@@ -1685,6 +1689,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:
@@ -4463,6 +4474,112 @@ 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;
+ char **path = station->affinities;
+
+ if (!station->connected_network)
+ return false;
+
+ l_dbus_message_builder_enter_array(builder, "o");
+
+ while (path && *path) {
+ l_dbus_message_builder_append_basic(builder, 'o', *path);
+ 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_strv_free(station->affinities);
+ station->affinities = NULL;
+}
+
+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;
+ char **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_strv_new();
+
+ while (l_dbus_message_iter_next_entry(&array, &path)) {
+ const char *p = network_get_path(station->connected_network);
+
+ /*
+ * It can't be assumed that the specific BSS has been seen, but
+ * at least validate the device/network portion matches the
+ * connected network.
+ */
+ if (strncmp(p, path, strlen(p))) {
+ l_warn("Can't set affinity to BSS (%s)", path);
+ l_strv_free(new_affinities);
+ return dbus_error_invalid_args(message);
+ }
+
+ new_affinities = l_strv_append(new_affinities, path);
+ }
+
+ l_strv_free(station->affinities);
+ 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;
@@ -4693,6 +4810,7 @@ static struct station *station_create(struct netdev *netdev)
station_set_autoconnect(station, autoconnect);
station->roam_bss_list = l_queue_new();
+ station->affinities = l_strv_new();
return station;
}
@@ -4785,6 +4903,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);
}
@@ -4821,6 +4942,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)
--
2.34.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 7/9] station: Use Affinities property for roaming/ranking decisions
2024-08-13 15:56 [PATCH 1/9] doc: Document station Affinities property James Prestwood
` (4 preceding siblings ...)
2024-08-13 15:56 ` [PATCH 6/9] station: add Affinities DBus property James Prestwood
@ 2024-08-13 15:56 ` James Prestwood
2024-08-13 15:56 ` [PATCH 8/9] auto-t: add affinities property for station, and extended_service_set James Prestwood
2024-08-13 15:56 ` [PATCH 9/9] auto-t: add tests for Affinities behavior James Prestwood
7 siblings, 0 replies; 9+ messages in thread
From: James Prestwood @ 2024-08-13 15:56 UTC (permalink / raw)
To: iwd; +Cc: James Prestwood
There are two pieces where the affinity to a BSS will come into play:
The first is while connected to a BSS with the affinity set. In this
scenario station will lower the roaming threshold in order to loosly
lock IWD to this BSS. By lowering the roaming threshold we can avoid
roaming/scanning in cases where the device is not moving i.e. if an
external client knows this information.
The second effect BSS affinity has is to modify ranking when choosing
a roam candidate. A new ranking modifier has been added that will be
applied to a BSS rank given:
- The BSS is in the Affinities array
- The BSS signal is above the critical threshold (set in main.conf
[General].CriticalRoamThreshold{_5GHZ}).
---
src/station.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 50 insertions(+)
diff --git a/src/station.c b/src/station.c
index 75dd13bb..ab04dcf2 100644
--- a/src/station.c
+++ b/src/station.c
@@ -1682,6 +1682,11 @@ static void station_enter_state(struct station *station,
if (station->connected_bss->hs20_dgaf_disable)
station_set_drop_unicast_l2_multicast(station, true);
+ if (l_strv_contains(station->affinities,
+ network_bss_get_path(station->connected_network,
+ station->connected_bss)))
+ netdev_lower_signal_threshold(station->netdev);
+
break;
case STATION_STATE_DISCONNECTED:
periodic_scan_stop(station);
@@ -2673,6 +2678,23 @@ static void station_update_roam_bss(struct station *station,
scan_bss_free(old);
}
+static bool station_apply_bss_affinity(struct station *station,
+ struct scan_bss *bss)
+{
+ struct network *network = station->connected_network;
+ const char *path = network_bss_get_path(network, bss);
+
+ /*
+ * Even if the BSS has the affinity set, don't apply the factor if its
+ * RSSI is below the critical threshold.
+ */
+ if (bss->signal_strength / 100 <
+ netdev_get_critical_signal_threshold(station->netdev))
+ return false;
+
+ return l_strv_contains(station->affinities, path);
+}
+
static bool station_roam_scan_notify(int err, struct l_queue *bss_list,
const struct scan_freq_set *freqs,
void *userdata)
@@ -2684,6 +2706,7 @@ static bool station_roam_scan_notify(int err, struct l_queue *bss_list,
struct scan_bss *bss;
double cur_bss_rank = 0.0;
static const double RANK_FT_FACTOR = 1.3;
+ static const double RANK_AFFINITY_FACTOR = 1.7;
uint16_t mdid;
enum security orig_security, security;
@@ -2715,6 +2738,9 @@ static bool station_roam_scan_notify(int err, struct l_queue *bss_list,
if (hs->mde && bss->mde_present && l_get_le16(bss->mde) == mdid)
cur_bss_rank *= RANK_FT_FACTOR;
+
+ if (station_apply_bss_affinity(station, bss))
+ cur_bss_rank *= RANK_AFFINITY_FACTOR;
}
/*
@@ -2765,6 +2791,9 @@ static bool station_roam_scan_notify(int err, struct l_queue *bss_list,
if (hs->mde && bss->mde_present && l_get_le16(bss->mde) == mdid)
rank *= RANK_FT_FACTOR;
+ if (station_apply_bss_affinity(station, bss))
+ rank *= RANK_AFFINITY_FACTOR;
+
if (rank <= cur_bss_rank)
goto next;
@@ -4506,6 +4535,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)
@@ -4531,6 +4563,8 @@ static struct l_dbus_message *station_property_set_affinities(
const char *sender = l_dbus_message_get_sender(message);
const char *path;
char **new_affinities;
+ const char *connected_path;
+ bool lower_threshold = false;
if (!station->connected_network)
return dbus_error_not_connected(message);
@@ -4550,6 +4584,8 @@ static struct l_dbus_message *station_property_set_affinities(
if (!l_dbus_message_iter_get_variant(new_value, "ao", &array))
return dbus_error_invalid_args(message);
+ connected_path = network_bss_get_path(station->connected_network,
+ station->connected_bss);
new_affinities = l_strv_new();
while (l_dbus_message_iter_next_entry(&array, &path)) {
@@ -4566,6 +4602,9 @@ static struct l_dbus_message *station_property_set_affinities(
return dbus_error_invalid_args(message);
}
+ if (!strcmp(path, connected_path))
+ lower_threshold = true;
+
new_affinities = l_strv_append(new_affinities, path);
}
@@ -4575,6 +4614,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;
--
2.34.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 8/9] auto-t: add affinities property for station, and extended_service_set
2024-08-13 15:56 [PATCH 1/9] doc: Document station Affinities property James Prestwood
` (5 preceding siblings ...)
2024-08-13 15:56 ` [PATCH 7/9] station: Use Affinities property for roaming/ranking decisions James Prestwood
@ 2024-08-13 15:56 ` James Prestwood
2024-08-13 15:56 ` [PATCH 9/9] auto-t: add tests for Affinities behavior James Prestwood
7 siblings, 0 replies; 9+ messages in thread
From: James Prestwood @ 2024-08-13 15:56 UTC (permalink / raw)
To: iwd; +Cc: James Prestwood
---
autotests/util/iwd.py | 22 ++++++++++++++++++++++
1 file changed, 22 insertions(+)
diff --git a/autotests/util/iwd.py b/autotests/util/iwd.py
index 1d4a5472..83f2d9ef 100755
--- a/autotests/util/iwd.py
+++ b/autotests/util/iwd.py
@@ -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.
@@ -975,6 +993,10 @@ class Network(IWDDBusAbstract):
'''
return bool(self._properties['Connected'])
+ @property
+ def extended_service_set(self):
+ return self._properties['ExtendedServiceSet']
+
def connect(self, wait=True):
'''
Connect to the network. Request the device implied by the object
--
2.34.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 9/9] auto-t: add tests for Affinities behavior
2024-08-13 15:56 [PATCH 1/9] doc: Document station Affinities property James Prestwood
` (6 preceding siblings ...)
2024-08-13 15:56 ` [PATCH 8/9] auto-t: add affinities property for station, and extended_service_set James Prestwood
@ 2024-08-13 15:56 ` James Prestwood
7 siblings, 0 replies; 9+ messages in thread
From: James Prestwood @ 2024-08-13 15:56 UTC (permalink / raw)
To: iwd; +Cc: 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 | 231 ++++++++++++++++++++
6 files changed, 328 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
diff --git a/autotests/testAffinity/TestFT.psk b/autotests/testAffinity/TestFT.psk
new file mode 100644
index 00000000..e82d1295
--- /dev/null
+++ b/autotests/testAffinity/TestFT.psk
@@ -0,0 +1,2 @@
+[Security]
+Passphrase=EasilyGuessedPassword
diff --git a/autotests/testAffinity/ft-psk-ccmp-1.conf b/autotests/testAffinity/ft-psk-ccmp-1.conf
new file mode 100644
index 00000000..839eb496
--- /dev/null
+++ b/autotests/testAffinity/ft-psk-ccmp-1.conf
@@ -0,0 +1,41 @@
+hw_mode=g
+channel=1
+ssid=TestFT
+utf8_ssid=1
+ctrl_interface=/var/run/hostapd
+
+r1_key_holder=120000000001
+nas_identifier=dummy1
+
+wpa=2
+# Can support WPA-PSK and FT-PSK (space separated list) and/or EAP at the same
+# time but we want to force FT
+wpa_key_mgmt=FT-PSK
+wpa_pairwise=CCMP
+wpa_passphrase=EasilyGuessedPassword
+ieee80211w=0
+rsn_preauth=1
+rsn_preauth_interfaces=lo
+disable_pmksa_caching=0
+# Allow PMK cache to be shared opportunistically among configured interfaces
+# and BSSes (i.e., all configurations within a single hostapd process).
+okc=1
+mobility_domain=1234
+reassociation_deadline=60000
+r0kh=12:00:00:00:00:01 dummy1 000102030405060708090a0b0c0d0e0f
+r0kh=12:00:00:00:00:02 dummy2 000102030405060708090a0b0c0d0e0f
+r1kh=12:00:00:00:00:01 00:00:00:00:00:01 000102030405060708090a0b0c0d0e0f
+r1kh=12:00:00:00:00:02 00:00:00:00:00:02 000102030405060708090a0b0c0d0e0f
+# Push mode only needed for 8021x, not PSK mode since msk already known
+pmk_r1_push=0
+# Allow locally generated FT response so we don't have to configure push/pull
+# between BSSes running as separate hostapd processes as in the test-runner
+# case. Only works with FT-PSK, otherwise brctl needs to be installed and
+# CONFIG_BRIDGE enabled in the kernel.
+ft_psk_generate_local=1
+rkh_pull_timeout=50
+ft_over_ds=0
+ap_table_expiration_time=36000
+ap_table_max_size=10
+rrm_neighbor_report=1
+ocv=1
diff --git a/autotests/testAffinity/ft-psk-ccmp-2.conf b/autotests/testAffinity/ft-psk-ccmp-2.conf
new file mode 100644
index 00000000..2ffd7262
--- /dev/null
+++ b/autotests/testAffinity/ft-psk-ccmp-2.conf
@@ -0,0 +1,41 @@
+hw_mode=g
+channel=2
+ssid=TestFT
+utf8_ssid=1
+ctrl_interface=/var/run/hostapd
+
+r1_key_holder=120000000002
+nas_identifier=dummy2
+
+wpa=2
+# Can support WPA-PSK and FT-PSK (space separated list) and/or EAP at the same
+# time but we want to force FT
+wpa_key_mgmt=FT-PSK
+wpa_pairwise=CCMP
+wpa_passphrase=EasilyGuessedPassword
+ieee80211w=0
+rsn_preauth=1
+rsn_preauth_interfaces=lo
+disable_pmksa_caching=0
+# Allow PMK cache to be shared opportunistically among configured interfaces
+# and BSSes (i.e., all configurations within a single hostapd process).
+okc=1
+mobility_domain=1234
+reassociation_deadline=60000
+r0kh=12:00:00:00:00:01 dummy1 000102030405060708090a0b0c0d0e0f
+r0kh=12:00:00:00:00:02 dummy2 000102030405060708090a0b0c0d0e0f
+r1kh=12:00:00:00:00:01 00:00:00:00:00:01 000102030405060708090a0b0c0d0e0f
+r1kh=12:00:00:00:00:02 00:00:00:00:00:02 000102030405060708090a0b0c0d0e0f
+# Push mode only needed for 8021x, not PSK mode since msk already known
+pmk_r1_push=0
+# Allow locally generated FT response so we don't have to configure push/pull
+# between BSSes running as separate hostapd processes as in the test-runner
+# case. Only works with FT-PSK, otherwise brctl needs to be installed and
+# CONFIG_BRIDGE enabled in the kernel.
+ft_psk_generate_local=1
+rkh_pull_timeout=50
+ft_over_ds=0
+ap_table_expiration_time=36000
+ap_table_max_size=10
+rrm_neighbor_report=1
+ocv=1
diff --git a/autotests/testAffinity/hw.conf b/autotests/testAffinity/hw.conf
new file mode 100644
index 00000000..c2b35d6e
--- /dev/null
+++ b/autotests/testAffinity/hw.conf
@@ -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
diff --git a/autotests/testAffinity/main.conf b/autotests/testAffinity/main.conf
new file mode 100644
index 00000000..3d93ff57
--- /dev/null
+++ b/autotests/testAffinity/main.conf
@@ -0,0 +1,5 @@
+[Scan]
+DisableMacAddressRandomization=true
+
+[General]
+RoamRetryInterval=1
diff --git a/autotests/testAffinity/test_set_affinity.py b/autotests/testAffinity/test_set_affinity.py
new file mode 100644
index 00000000..efd914a4
--- /dev/null
+++ b/autotests/testAffinity/test_set_affinity.py
@@ -0,0 +1,231 @@
+#! /usr/bin/python3
+
+import unittest
+import sys, os
+import dbus
+
+sys.path.append('../util')
+from config import ctx
+import iwd
+from iwd import IWD, IWDDBusAbstract
+from iwd import NetworkType
+from hwsim import Hwsim
+from hostapd import HostapdCLI
+
+#
+# Separate client used to test DBus disconnects so we don't bring down the
+# entire IWD python library
+#
+class AffinityClient(IWDDBusAbstract):
+ def __init__(self, device_path):
+ self._bus = dbus.bus.BusConnection(address_or_type=ctx.dbus_address)
+ self._station_prop_if = dbus.Interface(
+ self._bus.get_object(iwd.IWD_SERVICE, device_path),
+ iwd.DBUS_PROPERTIES)
+
+ def set(self, values):
+ self._station_prop_if.Set(iwd.IWD_STATION_INTERFACE, 'Affinities', dbus.Array([dbus.ObjectPath(v) for v in values], signature="o"))
+
+ def close(self):
+ self._bus.close()
+
+class Test(unittest.TestCase):
+ def connect(self, device, hapd):
+ ordered_network = device.get_ordered_network('TestFT', full_scan=True)
+
+ self.assertEqual(ordered_network.type, NetworkType.psk)
+
+ condition = 'not obj.connected'
+ self.wd.wait_for_object_condition(ordered_network.network_object, condition)
+
+ device.connect_bssid(hapd.bssid)
+
+ condition = 'obj.state == DeviceState.connected'
+ self.wd.wait_for_object_condition(device, condition)
+
+ def test_set_affinity(self):
+ device = self.wd.list_devices(1)[0]
+
+ self.connect(device, self.bss_hostapd[0])
+
+ print(device.connected_bss)
+
+ device.affinities = [device.connected_bss]
+
+ # IWD should not attempt to roam
+ with self.assertRaises(TimeoutError):
+ device.wait_for_event("roam-scan-triggered")
+
+ device.affinities = []
+ device.wait_for_event("roam-scan-triggered")
+
+ def test_roam_below_critical(self):
+ device = self.wd.list_devices(1)[0]
+
+ self.connect(device, self.bss_hostapd[0])
+
+ device.affinities = [device.connected_bss]
+
+ # IWD should not attempt to roam
+ with self.assertRaises(TimeoutError):
+ device.wait_for_event("roam-scan-triggered")
+
+ # Lower signal past critical level
+ self.bss0_rule.signal = -9000
+
+ device.wait_for_event("roam-scan-triggered")
+
+ def test_error_conditions(self):
+ device = self.wd.list_devices(1)[0]
+
+ # Calling set while disconnected should fail
+ with self.assertRaises(iwd.NotConnectedEx):
+ device.affinities = ["/some/path"]
+
+ self.connect(device, self.bss_hostapd[0])
+
+ device.affinities = [device.connected_bss]
+
+ # An invalid path should fail
+ with self.assertRaises(iwd.InvalidArgumentsEx):
+ device.affinities = [device.connected_bss, "/an/invalid/path"]
+
+ def test_affinity_client_disconnect(self):
+ device = self.wd.list_devices(1)[0]
+
+ client = AffinityClient(device.device_path)
+
+ self.connect(device, self.bss_hostapd[0])
+
+ client.set([device.connected_bss])
+
+ with self.assertRaises(TimeoutError):
+ device.wait_for_event("roam-scan-triggered")
+
+ client._bus.close()
+
+ device.wait_for_event("roam-scan-triggered")
+
+ def test_affinity_client_reconnect_during_roam(self):
+ device = self.wd.list_devices(1)[0]
+
+ client = AffinityClient(device.device_path)
+
+ self.connect(device, self.bss_hostapd[0])
+
+ client.set([device.connected_bss])
+
+ # Lower signal past critical level
+ self.bss0_rule.signal = -9000
+
+ device.wait_for_event("roam-scan-triggered")
+
+ client.close()
+ del client
+ client = AffinityClient(device.device_path)
+ # setting here should get cleared after connecting
+ client.set([device.connected_bss])
+
+ device.wait_for_event("ft-authenticating")
+ device.wait_for_event("associating")
+ device.wait_for_event("connected")
+
+ # Affinity should be reset, and IWD should be trying to roam
+ device.wait_for_event("roam-scan-triggered")
+
+ def test_cleanup_with_connected_client(self):
+ device = self.wd.list_devices(1)[0]
+
+ client = AffinityClient(device.device_path)
+
+ self.connect(device, self.bss_hostapd[0])
+
+ client.set([device.connected_bss])
+ self.wd.stop()
+
+ def test_affinity_directed_roaming(self):
+ device = self.wd.list_devices(1)[0]
+ network = device.get_ordered_network("TestFT").network_object
+
+ self.bss0_rule.signal = -7500
+ self.bss1_rule.signal = -7500
+
+ self.connect(device, self.bss_hostapd[0])
+
+ # Don't set the affinity on the current BSS, but on the other
+ affinities = [path for path in network.extended_service_set if path != device.connected_bss]
+
+ device.affinities = affinities
+
+ # We should roam to the other BSS.
+ device.wait_for_event("ft-authenticating")
+ device.wait_for_event("associating")
+ device.wait_for_event("connected")
+
+ # The affinity should still be set on this new BSS, causing the roam
+ # threshold to drop. We should not roam in this case.
+ with self.assertRaises(TimeoutError):
+ device.wait_for_event("roam-scan-triggered")
+
+ # Now set the affinity back to the prior BSS, which should adjust the
+ # ranking such that we roam back
+ device.affinities = [device.connected_bss]
+
+ device.wait_for_event("ft-authenticating")
+ device.wait_for_event("associating")
+ device.wait_for_event("connected")
+
+
+ def tearDown(self):
+ os.system('ip link set "' + self.bss_hostapd[0].ifname + '" down')
+ os.system('ip link set "' + self.bss_hostapd[1].ifname + '" down')
+ os.system('ip link set "' + self.bss_hostapd[0].ifname + '" up')
+ os.system('ip link set "' + self.bss_hostapd[1].ifname + '" up')
+
+ self.wd.stop()
+ self.wd = None
+
+ def setUp(self):
+ self.bss0_rule.signal = -8000
+ self.bss1_rule.signal = -8000
+
+ self.wd = IWD(True)
+
+ @classmethod
+ def setUpClass(cls):
+ hwsim = Hwsim()
+
+ IWD.copy_to_storage('TestFT.psk')
+
+ cls.bss_hostapd = [ HostapdCLI(config='ft-psk-ccmp-1.conf'),
+ HostapdCLI(config='ft-psk-ccmp-2.conf') ]
+
+ rad0 = hwsim.get_radio('rad0')
+ rad1 = hwsim.get_radio('rad1')
+
+ cls.bss0_rule = hwsim.rules.create()
+ cls.bss0_rule.source = rad0.addresses[0]
+ cls.bss0_rule.bidirectional = True
+ cls.bss0_rule.signal = -8000
+ cls.bss0_rule.enabled = True
+
+ cls.bss1_rule = hwsim.rules.create()
+ cls.bss1_rule.source = rad1.addresses[0]
+ cls.bss1_rule.bidirectional = True
+ cls.bss1_rule.signal = -8000
+ cls.bss1_rule.enabled = True
+
+ cls.bss_hostapd[0].set_address('12:00:00:00:00:01')
+ cls.bss_hostapd[1].set_address('12:00:00:00:00:02')
+
+ HostapdCLI.group_neighbors(*cls.bss_hostapd)
+
+ @classmethod
+ def tearDownClass(cls):
+ IWD.clear_storage()
+ cls.bss_hostapd = None
+ cls.bss0_rule.remove()
+ cls.bss1_rule.remove()
+
+if __name__ == '__main__':
+ unittest.main(exit=True)
--
2.34.1
^ permalink raw reply related [flat|nested] 9+ messages in thread
end of thread, other threads:[~2024-08-13 15:56 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-08-13 15:56 [PATCH 1/9] doc: Document station Affinities property James Prestwood
2024-08-13 15:56 ` [PATCH 2/9] netdev: store signal threshold in netdev object, not globally James Prestwood
2024-08-13 15:56 ` [PATCH 3/9] netdev: add critical signal threshold level James Prestwood
2024-08-13 15:56 ` [PATCH 4/9] netdev: add netdev_get_critical_signal_threshold James Prestwood
2024-08-13 15:56 ` [PATCH 5/9] station: emit property changed for ConnectedAccessPoint James Prestwood
2024-08-13 15:56 ` [PATCH 6/9] station: add Affinities DBus property James Prestwood
2024-08-13 15:56 ` [PATCH 7/9] station: Use Affinities property for roaming/ranking decisions James Prestwood
2024-08-13 15:56 ` [PATCH 8/9] auto-t: add affinities property for station, and extended_service_set James Prestwood
2024-08-13 15:56 ` [PATCH 9/9] auto-t: add tests for Affinities behavior James Prestwood
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox