summary refs log tree commit diff
path: root/src/devices/wifi/nm-device-wifi-p2p.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/devices/wifi/nm-device-wifi-p2p.c')
-rw-r--r--src/devices/wifi/nm-device-wifi-p2p.c96
1 files changed, 36 insertions, 60 deletions
diff --git a/src/devices/wifi/nm-device-wifi-p2p.c b/src/devices/wifi/nm-device-wifi-p2p.c
index 649f36d0..34ff70fa 100644
--- a/src/devices/wifi/nm-device-wifi-p2p.c
+++ b/src/devices/wifi/nm-device-wifi-p2p.c
@@ -1,21 +1,6 @@
-/* NetworkManager -- Wi-Fi P2P Device
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02110-1301 USA.
- *
- * (C) Copyright 2018 Red Hat, Inc.
+// SPDX-License-Identifier: LGPL-2.1+
+/*
+ * Copyright (C) 2018 Red Hat, Inc.
  */
 
 #include "nm-default.h"
@@ -63,6 +48,7 @@ typedef struct {
 
 	CList peers_lst_head;
 
+	guint find_peer_timeout_id;
 	guint sup_timeout_id;
 	guint peer_dump_id;
 	guint peer_missing_id;
@@ -349,7 +335,7 @@ supplicant_find_timeout_cb (gpointer user_data)
 	NMDeviceWifiP2P *self = NM_DEVICE_WIFI_P2P (user_data);
 	NMDeviceWifiP2PPrivate *priv = NM_DEVICE_WIFI_P2P_GET_PRIVATE (self);
 
-	priv->sup_timeout_id = 0;
+	priv->find_peer_timeout_id = 0;
 
 	nm_supplicant_interface_p2p_cancel_connect (priv->mgmt_iface);
 
@@ -368,27 +354,16 @@ act_stage1_prepare (NMDevice *device, NMDeviceStateReason *out_failure_reason)
 {
 	NMDeviceWifiP2P *self = NM_DEVICE_WIFI_P2P (device);
 	NMDeviceWifiP2PPrivate *priv = NM_DEVICE_WIFI_P2P_GET_PRIVATE (self);
-	NMActStageReturn ret;
-	NMActRequest *req;
 	NMConnection *connection;
 	NMSettingWifiP2P *s_wifi_p2p;
 	NMWifiP2PPeer *peer;
 
-	nm_clear_g_source (&priv->sup_timeout_id);
-
-	ret = NM_DEVICE_CLASS (nm_device_wifi_p2p_parent_class)->act_stage1_prepare (device, out_failure_reason);
-	if (ret != NM_ACT_STAGE_RETURN_SUCCESS)
-		return ret;
-
 	if (!priv->mgmt_iface) {
 		NM_SET_OUT (out_failure_reason, NM_DEVICE_STATE_REASON_SUPPLICANT_FAILED);
 		return NM_ACT_STAGE_RETURN_FAILURE;
 	}
 
-	req = nm_device_get_act_request (NM_DEVICE (self));
-	g_return_val_if_fail (req, NM_ACT_STAGE_RETURN_FAILURE);
-
-	connection = nm_act_request_get_applied_connection (req);
+	connection = nm_device_get_applied_connection (NM_DEVICE (self));
 	g_return_val_if_fail (connection, NM_ACT_STAGE_RETURN_FAILURE);
 
 	s_wifi_p2p = NM_SETTING_WIFI_P2P (nm_connection_get_setting (connection, NM_TYPE_SETTING_WIFI_P2P));
@@ -397,33 +372,19 @@ act_stage1_prepare (NMDevice *device, NMDeviceStateReason *out_failure_reason)
 	peer = nm_wifi_p2p_peers_find_first_compatible (&priv->peers_lst_head, connection);
 	if (!peer) {
 		/* Set up a timeout on the find attempt and run a find for the same period of time */
-		priv->sup_timeout_id = g_timeout_add_seconds (10,
-		                                              supplicant_find_timeout_cb,
-		                                              self);
-
-		nm_supplicant_interface_p2p_start_find (priv->mgmt_iface, 10);
+		if (priv->find_peer_timeout_id == 0) {
+			priv->find_peer_timeout_id = g_timeout_add_seconds (10,
+			                                                    supplicant_find_timeout_cb,
+			                                                    self);
 
+			nm_supplicant_interface_p2p_start_find (priv->mgmt_iface, 10);
+		}
 		return NM_ACT_STAGE_RETURN_POSTPONE;
 	}
 
 	return NM_ACT_STAGE_RETURN_SUCCESS;
 }
 
-static void
-cleanup_p2p_connect_attempt (NMDeviceWifiP2P *self, gboolean disconnect)
-{
-	NMDeviceWifiP2PPrivate *priv = NM_DEVICE_WIFI_P2P_GET_PRIVATE (self);
-
-	nm_clear_g_source (&priv->sup_timeout_id);
-	nm_clear_g_source (&priv->peer_missing_id);
-
-	if (priv->mgmt_iface)
-		nm_supplicant_interface_p2p_cancel_connect (priv->mgmt_iface);
-
-	if (disconnect && priv->group_iface)
-		nm_supplicant_interface_p2p_disconnect (priv->group_iface);
-}
-
 /*
  * supplicant_connection_timeout_cb
  *
@@ -461,7 +422,8 @@ act_stage2_config (NMDevice *device, NMDeviceStateReason *out_failure_reason)
 	NMWifiP2PPeer *peer;
 	GBytes *wfd_ies;
 
-	nm_clear_g_source (&priv->sup_timeout_id);
+	if (nm_clear_g_source (&priv->find_peer_timeout_id))
+		nm_assert_not_reached ();
 
 	if (!priv->mgmt_iface) {
 		NM_SET_OUT (out_failure_reason, NM_DEVICE_STATE_REASON_SUPPLICANT_FAILED);
@@ -493,9 +455,11 @@ act_stage2_config (NMDevice *device, NMDeviceStateReason *out_failure_reason)
 	                                     "pbc", NULL);
 
 	/* Set up a timeout on the connect attempt */
-	priv->sup_timeout_id = g_timeout_add_seconds (45,
-	                                              supplicant_connection_timeout_cb,
-	                                              self);
+	if (priv->sup_timeout_id == 0) {
+		priv->sup_timeout_id = g_timeout_add_seconds (45,
+		                                              supplicant_connection_timeout_cb,
+		                                              self);
+	}
 
 	/* We'll get stage3 started when the P2P group has been started */
 	return NM_ACT_STAGE_RETURN_POSTPONE;
@@ -550,17 +514,19 @@ peer_add_remove (NMDeviceWifiP2P *self,
 	if (is_adding) {
 		/* If we are in prepare state, then we are currently runnign a find
 		 * to search for the requested peer. */
-		if (nm_device_get_state (device) == NM_DEVICE_STATE_PREPARE) {
+		if (priv->find_peer_timeout_id != 0) {
 			NMConnection *connection;
 
+			nm_assert (nm_device_get_state (device) == NM_DEVICE_STATE_PREPARE);
+
 			connection = nm_device_get_applied_connection (device);
-			g_assert (connection);
+			nm_assert (NM_IS_CONNECTION (connection));
 
 			peer = nm_wifi_p2p_peers_find_first_compatible (&priv->peers_lst_head, connection);
 			if (peer) {
 				/* A peer for the connection was found, cancel the timeout and go to configure state. */
-				nm_clear_g_source (&priv->sup_timeout_id);
-				nm_device_activate_schedule_stage2_device_config (device);
+				nm_clear_g_source (&priv->find_peer_timeout_id);
+				nm_device_activate_schedule_stage1_device_prepare (device);
 			}
 		}
 
@@ -620,8 +586,17 @@ deactivate (NMDevice *device)
 {
 	NMDeviceWifiP2P *self = NM_DEVICE_WIFI_P2P (device);
 	int ifindex = nm_device_get_ip_ifindex (device);
+	NMDeviceWifiP2PPrivate *priv = NM_DEVICE_WIFI_P2P_GET_PRIVATE (self);
+
+	nm_clear_g_source (&priv->find_peer_timeout_id);
+	nm_clear_g_source (&priv->sup_timeout_id);
+	nm_clear_g_source (&priv->peer_missing_id);
 
-	cleanup_p2p_connect_attempt (self, TRUE);
+	if (priv->mgmt_iface)
+		nm_supplicant_interface_p2p_cancel_connect (priv->mgmt_iface);
+
+	if (priv->group_iface)
+		nm_supplicant_interface_p2p_disconnect (priv->group_iface);
 
 	/* Clear any critical protocol notification in the Wi-Fi stack */
 	if (ifindex > 0)
@@ -922,6 +897,7 @@ supplicant_interfaces_release (NMDeviceWifiP2P *self, gboolean set_is_waiting)
 		nm_supplicant_manager_set_wfd_ies (priv->sup_mgr, NULL);
 		g_signal_handlers_disconnect_by_data (priv->mgmt_iface, self);
 		g_clear_object (&priv->mgmt_iface);
+		nm_clear_g_source (&priv->find_peer_timeout_id);
 		nm_clear_g_source (&priv->sup_timeout_id);
 	}