diff mbox series

[v3,5/9] station: provide new state in __station_connect_network

Message ID 20231031184750.722404-6-prestwoj@gmail.com (mailing list archive)
State Accepted, archived
Headers show
Series DPP PKEX Changes | expand

Checks

Context Check Description
tedd_an/pre-ci_am success Success
prestwoj/iwd-ci-gitlint success GitLint

Commit Message

James Prestwood Oct. 31, 2023, 6:47 p.m. UTC
This is being done to allow the DPP module to work correctl. DPP
currently uses __station_connect_network incorrectly since it
does not (and cannot) change the state after calling. The only
way to connect with a state change is via station_connect_network
which requires a DBus method that triggered the connection; DPP
does not have this due to its potentially long run time.

To support DPP there are a few options:
 1. Pass a state into __station_connect_network (this patch)
 2. Support a NULL DBus message in station_connect_network. This
    would require several NULL checks and adding all that to only
    support DPP just didn't feel right.
 3. A 3rd connect API in station which wraps
    __station_connect_network and changes the state. And again, an
    entirely new API for only DPP felt wrong (I guess we did this
    for network_autoconnect though...)

Its about 50/50 between call sites that changed state after calling
and those that do not. Changing the state inside
__station_connect_network felt useful enough to cover the cases that
could benefit and the remaining cases could handle it easily enough:
 - network_autoconnect(), and the state is changed by station after
   calling so it more or less follows the same pattern just routes
   through network. This will now pass the CONNECTING_AUTO state
   from within network vs station.
 - The disconnect/reconnect path. Here the state is changed to
   ROAMING prior in order to avoid multiple state changes. Knowing
   this the same ROAMING state can be passed which won't trigger a
   state change.
 - Retrying after a failed BSS. The state changes on the first call
   then remains the same for each connection attempt. To support this
   the current station->state is passed to avoid a state change.
---
 src/dpp.c     |  3 ++-
 src/network.c |  3 ++-
 src/station.c | 23 +++++++++++------------
 src/station.h |  2 +-
 4 files changed, 16 insertions(+), 15 deletions(-)
diff mbox series

Patch

diff --git a/src/dpp.c b/src/dpp.c
index e5e1b3fa..b0a79361 100644
--- a/src/dpp.c
+++ b/src/dpp.c
@@ -833,7 +833,8 @@  static void dpp_handle_config_response_frame(const struct mmpdu_header *frame,
 	offchannel_cancel(dpp->wdev_id, dpp->offchannel_id);
 
 	if (network && bss)
-		__station_connect_network(station, network, bss);
+		__station_connect_network(station, network, bss,
+						STATION_STATE_CONNECTING);
 	else if (station) {
 		dpp->connect_scan_id = scan_active(dpp->wdev_id, NULL, 0,
 						dpp_scan_triggered,
diff --git a/src/network.c b/src/network.c
index 3099d102..f203834c 100644
--- a/src/network.c
+++ b/src/network.c
@@ -991,7 +991,8 @@  int network_autoconnect(struct network *network, struct scan_bss *bss)
 		return -ENOTSUP;
 	}
 
-	return __station_connect_network(station, network, bss);
+	return __station_connect_network(station, network, bss,
+						STATION_STATE_CONNECTING_AUTO);
 
 close_settings:
 	network_settings_close(network);
diff --git a/src/station.c b/src/station.c
index d4eb0cd8..3da02b06 100644
--- a/src/station.c
+++ b/src/station.c
@@ -280,9 +280,6 @@  static int station_autoconnect_next(struct station *station)
 
 		r = network_autoconnect(network, bss);
 		if (!r) {
-			station_enter_state(station,
-						STATION_STATE_CONNECTING_AUTO);
-
 			if (station->quick_scan_id) {
 				scan_cancel(netdev_get_wdev_id(station->netdev),
 						station->quick_scan_id);
@@ -3084,7 +3081,7 @@  static bool station_try_next_bss(struct station *station)
 		return false;
 
 	ret = __station_connect_network(station, station->connected_network,
-						next);
+						next, station->state);
 	if (ret < 0)
 		return false;
 
@@ -3421,7 +3418,7 @@  static void station_netdev_event(struct netdev *netdev, enum netdev_event event,
 }
 
 int __station_connect_network(struct station *station, struct network *network,
-				struct scan_bss *bss)
+				struct scan_bss *bss, enum station_state state)
 {
 	struct handshake_state *hs;
 	int r;
@@ -3448,6 +3445,9 @@  int __station_connect_network(struct station *station, struct network *network,
 	station->connected_bss = bss;
 	station->connected_network = network;
 
+	if (station->state != state)
+		station_enter_state(station, state);
+
 	return 0;
 }
 
@@ -3461,7 +3461,8 @@  static void station_disconnect_onconnect_cb(struct netdev *netdev, bool success,
 
 	err = __station_connect_network(station,
 					station->connect_pending_network,
-					station->connect_pending_bss);
+					station->connect_pending_bss,
+					STATION_STATE_CONNECTING);
 
 	station->connect_pending_network = NULL;
 	station->connect_pending_bss = NULL;
@@ -3472,8 +3473,6 @@  static void station_disconnect_onconnect_cb(struct netdev *netdev, bool success,
 						station->connect_pending));
 		return;
 	}
-
-	station_enter_state(station, STATION_STATE_CONNECTING);
 }
 
 static void station_disconnect_onconnect(struct station *station,
@@ -3531,12 +3530,11 @@  void station_connect_network(struct station *station, struct network *network,
 		return;
 	}
 
-	err = __station_connect_network(station, network, bss);
+	err = __station_connect_network(station, network, bss,
+					STATION_STATE_CONNECTING);
 	if (err < 0)
 		goto error;
 
-	station_enter_state(station, STATION_STATE_CONNECTING);
-
 	station->connect_pending = l_dbus_message_ref(message);
 
 	station_set_autoconnect(station, true);
@@ -3746,7 +3744,8 @@  static void station_disconnect_reconnect_cb(struct netdev *netdev, bool success,
 	struct station *station = user_data;
 
 	if (__station_connect_network(station, station->connected_network,
-					station->connected_bss) < 0)
+					station->connected_bss,
+					STATION_STATE_ROAMING) < 0)
 		station_disassociated(station);
 }
 
diff --git a/src/station.h b/src/station.h
index 24fab321..0d502a08 100644
--- a/src/station.h
+++ b/src/station.h
@@ -89,7 +89,7 @@  void station_remove_event_watch(uint32_t id);
 bool station_set_autoconnect(struct station *station, bool autoconnect);
 
 int __station_connect_network(struct station *station, struct network *network,
-				struct scan_bss *bss);
+				struct scan_bss *bss, enum station_state state);
 void station_connect_network(struct station *station, struct network *network,
 				struct scan_bss *bss,
 				struct l_dbus_message *message);