[PATCH v2 3/6] station: include netconfig as part of the BSS retry logic

James Prestwood
2025-05-28T20:10:33Z

A netconfig failure results in a failed connection which restarts
autoconnect and prevents IWD from retrying the connection on any
other BSS's within the network as a whole. When autoconnect restarts
IWD will scan and choose the "best" BSS which is likely the same as
the prior attempt. If that BSS is somehow misconfigured as far as
DHCP goes, it will likely fail indefinitely and in turn cause IWD to
retry indefinitely.

To improve this netconfig has been adopted into the IWD's BSS retry
logic. If netconfig fails this will not result in IWD transitioning
to a disconnected state, and instead the BSS will be network
blacklisted and the next will be tried. Only once all BSS's have been
tried will IWD go into a disconnected state and start autoconnect
over.
---
src/station.c | 85 +++++++++++++++++++++++++--------------------------
1 file changed, 41 insertions(+), 44 deletions(-)

v2:
* Removed network_disconnected() call on failure
* Utilize network_clear_blacklist() and retain the existing call site
for network_connected()

diff --git a/src/station.c b/src/station.c
index 4180b7a4..a4c3e7d1 100644
--- a/src/station.c
+++ b/src/station.c
@@ -1795,6 +1795,8 @@ static void station_enter_state(struct station *station,
periodic_scan_stop(station);
break;
case STATION_STATE_CONNECTED:
+ network_clear_blacklist(station->connected_network);
+
if (station->connect_pending) {
struct l_dbus_message *reply =
l_dbus_message_new_method_return(
@@ -2221,6 +2223,26 @@ static void station_early_neighbor_report_cb(struct netdev *netdev, int err,
&station->roam_freqs);
}

+static bool station_try_next_bss(struct station *station)
+{
+ struct scan_bss *next;
+ int ret;
+
+ next = network_bss_select(station->connected_network, false);
+
+ if (!next)
+ return false;
+
+ ret = __station_connect_network(station, station->connected_network,
+ next, station->state);
+ if (ret < 0)
+ return false;
+
+ l_debug("Attempting to connect to next BSS "MAC, MAC_STR(next->addr));
+
+ return true;
+}
+
static bool station_can_fast_transition(struct station *station,
struct handshake_state *hs,
struct scan_bss *bss)
@@ -2263,28 +2285,26 @@ static bool station_can_fast_transition(struct station *station,
return true;
}

-static void station_disconnect_on_error_cb(struct netdev *netdev, bool success,
- void *user_data)
+static void station_disconnect_on_netconfig_failed(struct netdev *netdev,
+ bool success,
+ void *user_data)
{
struct station *station = user_data;
- bool continue_autoconnect;

- station_enter_state(station, STATION_STATE_DISCONNECTED);
-
- continue_autoconnect = station->state == STATION_STATE_CONNECTING_AUTO;
+ if (station_try_next_bss(station))
+ return;

- if (continue_autoconnect) {
- if (station_autoconnect_next(station) < 0) {
- l_debug("Nothing left on autoconnect list");
- station_enter_state(station,
- STATION_STATE_AUTOCONNECT_FULL);
- }
+ if (station->connect_pending) {
+ struct l_dbus_message *reply = dbus_error_failed(
+ station->connect_pending);

- return;
+ dbus_pending_reply(&station->connect_pending, reply);
}

- if (station->autoconnect)
- station_enter_state(station, STATION_STATE_AUTOCONNECT_QUICK);
+ station_reset_connection_state(station);
+
+ station_enter_state(station, STATION_STATE_DISCONNECTED);
+ station_enter_state(station, STATION_STATE_AUTOCONNECT_FULL);
}

static void station_netconfig_event_handler(enum netconfig_event event,
@@ -2297,23 +2317,20 @@ static void station_netconfig_event_handler(enum netconfig_event event,
station_enter_state(station, STATION_STATE_CONNECTED);
break;
case NETCONFIG_EVENT_FAILED:
- if (station->connect_pending) {
- struct l_dbus_message *reply = dbus_error_failed(
- station->connect_pending);
+ station_debug_event(station, "netconfig-failed");

- dbus_pending_reply(&station->connect_pending, reply);
- }
+ netconfig_reset(station->netconfig);

if (station->state == STATION_STATE_NETCONFIG)
network_connect_failed(station->connected_network,
false);

+ network_blacklist_add(station->connected_network,
+ station->connected_bss);
+
netdev_disconnect(station->netdev,
- station_disconnect_on_error_cb,
+ station_disconnect_on_netconfig_failed,
station);
- station_reset_connection_state(station);
-
- station_enter_state(station, STATION_STATE_DISCONNECTING);
break;
default:
l_error("station: Unsupported netconfig event: %d.", event);
@@ -3416,26 +3433,6 @@ static void station_event_channel_switched(struct station *station,
network_bss_update(network, station->connected_bss);
}

-static bool station_try_next_bss(struct station *station)
-{
- struct scan_bss *next;
- int ret;
-
- next = network_bss_select(station->connected_network, false);
-
- if (!next)
- return false;
-
- ret = __station_connect_network(station, station->connected_network,
- next, station->state);
- if (ret < 0)
- return false;
-
- l_debug("Attempting to connect to next BSS "MAC, MAC_STR(next->addr));
-
- return true;
-}
-
static bool station_retry_owe_default_group(struct station *station)
{
/*
--
2.34.1