summary refs log tree commit diff
path: root/src/devices/bluetooth
diff options
context:
space:
mode:
authorMichael Biebl <biebl@debian.org>2020-04-11 21:28:04 +0200
committerMichael Biebl <biebl@debian.org>2020-04-11 21:28:04 +0200
commit1e5977b62f896e844b548c3007ace9e1dfa7f9ed (patch)
tree7a7416ed410e72b6200f3d860fd315ec11cc106b /src/devices/bluetooth
parentb012fa6e1d808e0736c009799c62d835cbfcc1dd (diff)
New upstream version 1.23.90 upstream/1.23.90
Diffstat (limited to 'src/devices/bluetooth')
-rw-r--r--src/devices/bluetooth/meson.build2
-rw-r--r--src/devices/bluetooth/nm-bluez-manager.c59
-rw-r--r--src/devices/bluetooth/nm-bluez5-dun.c118
-rw-r--r--src/devices/bluetooth/nm-device-bt.c16
4 files changed, 119 insertions, 76 deletions
diff --git a/src/devices/bluetooth/meson.build b/src/devices/bluetooth/meson.build
index f0507c23..638a01a2 100644
--- a/src/devices/bluetooth/meson.build
+++ b/src/devices/bluetooth/meson.build
@@ -1,3 +1,5 @@
+# SPDX-License-Identifier: LGPL-2.1+
+
 sources = files(
   'nm-bluez-manager.c',
   'nm-bt-error.c',
diff --git a/src/devices/bluetooth/nm-bluez-manager.c b/src/devices/bluetooth/nm-bluez-manager.c
index ef087d83..6ff96c32 100644
--- a/src/devices/bluetooth/nm-bluez-manager.c
+++ b/src/devices/bluetooth/nm-bluez-manager.c
@@ -221,7 +221,7 @@ convert_uuids_to_capabilities (const char *const*strv)
 				continue;
 
 			s_part1 = g_strndup (str, s - str);
-			switch (g_ascii_strtoull (s_part1, NULL, 16)) {
+			switch (_nm_utils_ascii_str_to_int64 (s_part1, 16, 0, G_MAXINT, -1)) {
 			case 0x1103:
 				capabilities |= NM_BT_CAPABILITY_DUN;
 				break;
@@ -1089,7 +1089,7 @@ _network_server_register_cb (GObject *source_object,
 
 	ret = g_dbus_connection_call_finish (G_DBUS_CONNECTION (source_object), res, &error);
 	if (   !ret
-	    && nm_utils_error_is_cancelled (error, FALSE))
+	    && nm_utils_error_is_cancelled (error))
 		return;
 
 	bzobj = user_data;
@@ -2071,9 +2071,12 @@ _dbus_handle_interface_removed (NMBluezManager *self,
 }
 
 static void
-_dbus_managed_objects_changed_cb (const char *object_path,
-                                  GVariant *added_interfaces_and_properties,
-                                  const char *const*removed_interfaces,
+_dbus_managed_objects_changed_cb (GDBusConnection *connection,
+                                  const char *sender_name,
+                                  const char *arg_object_path,
+                                  const char *interface_name,
+                                  const char *signal_name,
+                                  GVariant *parameters,
                                   gpointer user_data)
 {
 	NMBluezManager *self = user_data;
@@ -2081,17 +2084,46 @@ _dbus_managed_objects_changed_cb (const char *object_path,
 	BzDBusObj *bzobj = NULL;
 	gboolean changed;
 
+	nm_assert (nm_streq0 (interface_name, DBUS_INTERFACE_OBJECT_MANAGER));
+
 	if (priv->get_managed_objects_cancellable) {
 		/* we still wait for the initial GetManagedObjects(). Ignore the event. */
 		return;
 	}
 
-	if (!added_interfaces_and_properties) {
-		changed = _dbus_handle_interface_removed (self, object_path, &bzobj, removed_interfaces);
+	if (nm_streq (signal_name, "InterfacesAdded")) {
+		gs_unref_variant GVariant *interfaces_and_properties = NULL;
+		const char *object_path;
+
+		if (!g_variant_is_of_type (parameters, G_VARIANT_TYPE ("(oa{sa{sv}})")))
+			return;
+
+		g_variant_get (parameters,
+		               "(&o@a{sa{sv}})",
+		               &object_path,
+		               &interfaces_and_properties);
+
+		_dbus_handle_interface_added (self, object_path, interfaces_and_properties, FALSE);
+		return;
+	}
+
+	if (nm_streq (signal_name, "InterfacesRemoved")) {
+		gs_free const char **interfaces = NULL;
+		const char *object_path;
+
+		if (!g_variant_is_of_type (parameters, G_VARIANT_TYPE ("(oas)")))
+			return;
+
+		g_variant_get (parameters,
+		               "(&o^a&s)",
+		               &object_path,
+		               &interfaces);
+
+		changed = _dbus_handle_interface_removed (self, object_path, &bzobj, interfaces);
 		if (changed)
 			_dbus_process_changes (self, bzobj, "dbus-iface-removed");
-	} else
-		_dbus_handle_interface_added (self, object_path, added_interfaces_and_properties, FALSE);
+		return;
+	}
 }
 
 static void
@@ -2140,7 +2172,7 @@ _dbus_get_managed_objects_cb (GVariant *result,
 	GVariant *ifaces;
 
 	if (   !result
-	    && nm_utils_error_is_cancelled (error, FALSE))
+	    && nm_utils_error_is_cancelled (error))
 		return;
 
 	self = user_data;
@@ -2234,6 +2266,7 @@ name_owner_changed (NMBluezManager *self,
 	priv->managed_objects_changed_id = nm_dbus_connection_signal_subscribe_object_manager (priv->dbus_connection,
 	                                                                                       priv->name_owner,
 	                                                                                       NM_BLUEZ_MANAGER_PATH,
+	                                                                                       NULL,
 	                                                                                       _dbus_managed_objects_changed_cb,
 	                                                                                       self,
 	                                                                                       NULL);
@@ -2442,7 +2475,7 @@ _connect_dun_step2_cb (NMBluez5DunContext *context,
 {
 	BzDBusObj *bzobj;
 
-	if (nm_utils_error_is_cancelled (error, FALSE))
+	if (nm_utils_error_is_cancelled (error))
 		return;
 
 	bzobj = user_data;
@@ -2484,7 +2517,7 @@ _connect_dun_step1_cb (GObject *source_object,
 	ret = g_dbus_connection_call_finish (G_DBUS_CONNECTION (source_object), res, &error);
 
 	if (   !ret
-	    && nm_utils_error_is_cancelled (error, FALSE))
+	    && nm_utils_error_is_cancelled (error))
 		return;
 
 	bzobj = user_data;
@@ -2531,7 +2564,7 @@ _connect_nap_cb (GObject *source_object,
 	ret = g_dbus_connection_call_finish (G_DBUS_CONNECTION (source_object), res, &error);
 
 	if (   !ret
-	    && nm_utils_error_is_cancelled (error, FALSE))
+	    && nm_utils_error_is_cancelled (error))
 		return;
 
 	if (ret)
diff --git a/src/devices/bluetooth/nm-bluez5-dun.c b/src/devices/bluetooth/nm-bluez5-dun.c
index af463d1a..c253d4e2 100644
--- a/src/devices/bluetooth/nm-bluez5-dun.c
+++ b/src/devices/bluetooth/nm-bluez5-dun.c
@@ -31,12 +31,12 @@ typedef struct {
 
 	GError *rfcomm_sdp_search_error;
 
+	GSource *source;
+
 	gint64 connect_open_tty_started_at;
 
 	gulong cancelled_id;
 
-	guint source_id;
-
 	guint8 sdp_session_try_count;
 } ConnectData;
 
@@ -50,13 +50,13 @@ struct _NMBluez5DunContext {
 
 	char *rfcomm_tty_path;
 
+	GSource *rfcomm_tty_poll_source;
+
 	int rfcomm_sock_fd;
 	int rfcomm_tty_fd;
 	int rfcomm_tty_no;
 	int rfcomm_channel;
 
-	guint rfcomm_tty_poll_id;
-
 	bdaddr_t src;
 	bdaddr_t dst;
 
@@ -118,7 +118,7 @@ nm_bluez5_dun_context_get_rfcomm_dev (const NMBluez5DunContext *context)
 /*****************************************************************************/
 
 static gboolean
-_rfcomm_tty_poll_cb (GIOChannel *stream,
+_rfcomm_tty_poll_cb (int fd,
                      GIOCondition condition,
                      gpointer user_data)
 {
@@ -129,7 +129,7 @@ _rfcomm_tty_poll_cb (GIOChannel *stream,
 	       NM_FLAGS_ALL (condition, G_IO_HUP | G_IO_ERR) ? ","   : "",
 	       NM_FLAGS_HAS (condition, G_IO_HUP)            ? "HUP" : "");
 
-	context->rfcomm_tty_poll_id = 0;
+	nm_clear_g_source_inst (&context->rfcomm_tty_poll_source);
 	context->notify_tty_hangup_cb (context,
 	                               context->notify_tty_hangup_user_data);
 	return G_SOURCE_REMOVE;
@@ -145,10 +145,10 @@ _connect_open_tty_retry_cb (gpointer user_data)
 	if (r >= 0)
 		return G_SOURCE_REMOVE;
 
-	if (nm_utils_get_monotonic_timestamp_ns () > context->cdat->connect_open_tty_started_at + (30 * 100 * NM_UTILS_NS_PER_MSEC)) {
+	if (nm_utils_get_monotonic_timestamp_nsec () > context->cdat->connect_open_tty_started_at + (30 * 100 * NM_UTILS_NSEC_PER_MSEC)) {
 		gs_free_error GError *error = NULL;
 
-		context->cdat->source_id = 0;
+		nm_clear_g_source_inst (&context->cdat->source);
 		g_set_error (&error,
 		             NM_BT_ERROR,
 		             NM_BT_ERROR_DUN_CONNECT_FAILED,
@@ -166,7 +166,6 @@ _connect_open_tty_retry_cb (gpointer user_data)
 static int
 _connect_open_tty (NMBluez5DunContext *context)
 {
-	nm_auto_unref_io_channel GIOChannel *io_channel = NULL;
 	int fd;
 	int errsv;
 
@@ -174,26 +173,31 @@ _connect_open_tty (NMBluez5DunContext *context)
 	if (fd < 0) {
 		errsv = NM_ERRNO_NATIVE (errno);
 
-		if (context->cdat->source_id == 0) {
+		if (!context->cdat->source) {
 			_LOGD (context, "failed opening tty "RFCOMM_FMT": %s (%d). Start polling...",
 			       context->rfcomm_tty_no,
 			       nm_strerror_native (errsv),
 			       errsv);
-			context->cdat->connect_open_tty_started_at = nm_utils_get_monotonic_timestamp_ns ();
-			context->cdat->source_id = g_timeout_add (100,
-			                                          _connect_open_tty_retry_cb,
-			                                          context);
+			context->cdat->connect_open_tty_started_at = nm_utils_get_monotonic_timestamp_nsec ();
+			context->cdat->source = nm_g_timeout_source_new (100,
+			                                                 G_PRIORITY_DEFAULT,
+			                                                 _connect_open_tty_retry_cb,
+			                                                 context,
+			                                                 NULL);
+			g_source_attach (context->cdat->source, NULL);
 		}
 		return -errsv;
 	}
 
 	context->rfcomm_tty_fd = fd;
 
-	io_channel = g_io_channel_unix_new (context->rfcomm_tty_fd);
-	context->rfcomm_tty_poll_id = g_io_add_watch (io_channel,
-	                                              G_IO_ERR | G_IO_HUP,
-	                                              _rfcomm_tty_poll_cb,
-	                                              context);
+	context->rfcomm_tty_poll_source = nm_g_unix_fd_source_new (context->rfcomm_tty_fd,
+	                                                           G_IO_ERR | G_IO_HUP,
+	                                                           G_PRIORITY_DEFAULT,
+	                                                           _rfcomm_tty_poll_cb,
+	                                                           context,
+	                                                           NULL);
+	g_source_attach (context->rfcomm_tty_poll_source, NULL);
 
 	_context_invoke_callback_success (context);
 	return 0;
@@ -263,7 +267,7 @@ _connect_create_rfcomm (NMBluez5DunContext *context)
 }
 
 static gboolean
-_connect_socket_connect_cb (GIOChannel *stream,
+_connect_socket_connect_cb (int fd,
                             GIOCondition condition,
                             gpointer user_data)
 {
@@ -273,7 +277,7 @@ _connect_socket_connect_cb (GIOChannel *stream,
 	socklen_t slen = sizeof(errsv);
 	int r;
 
-	context->cdat->source_id = 0;
+	nm_clear_g_source_inst (&context->cdat->source);
 
 	r = getsockopt (context->rfcomm_sock_fd, SOL_SOCKET, SO_ERROR, &errsv, &slen);
 
@@ -346,7 +350,6 @@ _connect_socket_connect (NMBluez5DunContext *context)
 	if (connect (context->rfcomm_sock_fd,
 	             (struct sockaddr *) &sa,
 	             sizeof (sa)) != 0) {
-		nm_auto_unref_io_channel GIOChannel *io_channel = NULL;
 
 		errsv = errno;
 		if (errsv != EINPROGRESS) {
@@ -363,11 +366,13 @@ _connect_socket_connect (NMBluez5DunContext *context)
 		       context->dst_str,
 		       context->rfcomm_channel);
 
-		io_channel = g_io_channel_unix_new (context->rfcomm_sock_fd);
-		context->cdat->source_id = g_io_add_watch (io_channel,
-		                                           G_IO_OUT,
-		                                           _connect_socket_connect_cb,
-		                                           context);
+		context->cdat->source = nm_g_unix_fd_source_new (context->rfcomm_sock_fd,
+		                                                 G_IO_OUT,
+		                                                 G_PRIORITY_DEFAULT,
+		                                                 _connect_socket_connect_cb,
+		                                                 context,
+		                                                 NULL);
+		g_source_attach (context->cdat->source, NULL);
 		return;
 	}
 
@@ -466,7 +471,7 @@ _connect_sdp_search_cb (uint8_t type,
 }
 
 static gboolean
-_connect_sdp_search_io_cb (GIOChannel *io_channel,
+_connect_sdp_search_io_cb (int fd,
                            GIOCondition condition,
                            gpointer user_data)
 {
@@ -480,7 +485,7 @@ _connect_sdp_search_io_cb (GIOChannel *io_channel,
 		error = g_error_new (NM_BT_ERROR,
 		                     NM_BT_ERROR_DUN_CONNECT_FAILED,
 		                     "Service Discovery interrupted");
-		context->cdat->source_id = 0;
+		nm_clear_g_source_inst (&context->cdat->source);
 		_context_invoke_callback_fail_and_free (context, error);
 		return G_SOURCE_REMOVE;
 	}
@@ -490,7 +495,7 @@ _connect_sdp_search_io_cb (GIOChannel *io_channel,
 		return G_SOURCE_CONTINUE;
 	}
 
-	context->cdat->source_id = 0;
+	nm_clear_g_source_inst (&context->cdat->source);
 
 	if (   context->rfcomm_channel < 0
 	    && !context->cdat->rfcomm_sdp_search_error) {
@@ -524,7 +529,7 @@ _connect_sdp_session_start_on_idle_cb (gpointer user_data)
 	NMBluez5DunContext *context = user_data;
 	gs_free_error GError *error = NULL;
 
-	context->cdat->source_id = 0;
+	nm_clear_g_source_inst (&context->cdat->source);
 
 	_LOGD (context, "retry starting sdp-session...");
 
@@ -535,7 +540,7 @@ _connect_sdp_session_start_on_idle_cb (gpointer user_data)
 }
 
 static gboolean
-_connect_sdp_io_cb (GIOChannel *io_channel,
+_connect_sdp_io_cb (int fd,
                     GIOCondition condition,
                     gpointer user_data)
 {
@@ -544,16 +549,13 @@ _connect_sdp_io_cb (GIOChannel *io_channel,
 	sdp_list_t *attrs;
 	uuid_t svclass;
 	uint16_t attr;
-	int fd;
 	int errsv;
 	int fd_err = 0;
 	int r;
 	socklen_t len = sizeof (fd_err);
 	gs_free_error GError *error = NULL;
 
-	context->cdat->source_id = 0;
-
-	fd = g_io_channel_unix_get_fd (io_channel);
+	nm_clear_g_source_inst (&context->cdat->source);
 
 	_LOGD (context, "sdp-session ready to connect with fd=%d", fd);
 
@@ -572,10 +574,13 @@ _connect_sdp_io_cb (GIOChannel *io_channel,
 		    && --context->cdat->sdp_session_try_count > 0) {
 			/* *sigh* */
 			_LOGD (context, "sdp-session failed with %s (%d). Retry in a bit", nm_strerror_native (errsv), errsv);
-			nm_clear_g_source (&context->cdat->source_id);
-			context->cdat->source_id = g_timeout_add (1000,
-			                                          _connect_sdp_session_start_on_idle_cb,
-			                                          context);
+			nm_clear_g_source_inst (&context->cdat->source);
+			context->cdat->source = nm_g_timeout_source_new (1000,
+			                                                 G_PRIORITY_DEFAULT,
+			                                                 _connect_sdp_session_start_on_idle_cb,
+			                                                 context,
+			                                                 NULL);
+			g_source_attach (context->cdat->source, NULL);
 			return G_SOURCE_REMOVE;
 		}
 
@@ -615,10 +620,13 @@ _connect_sdp_io_cb (GIOChannel *io_channel,
 	}
 
 	/* Set callback responsible for update the internal SDP transaction */
-	context->cdat->source_id = g_io_add_watch (io_channel,
-	                                           G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
-	                                           _connect_sdp_search_io_cb,
-	                                           context);
+	context->cdat->source = nm_g_unix_fd_source_new (fd,
+	                                                 G_IO_IN | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
+	                                                 G_PRIORITY_DEFAULT,
+	                                                 _connect_sdp_search_io_cb,
+	                                                 context,
+	                                                 NULL);
+	g_source_attach (context->cdat->source, NULL);
 
 done:
 	if (error)
@@ -644,11 +652,9 @@ static gboolean
 _connect_sdp_session_start (NMBluez5DunContext *context,
                             GError **error)
 {
-	nm_auto_unref_io_channel GIOChannel *io_channel = NULL;
-
 	nm_assert (context->cdat);
 
-	nm_clear_g_source (&context->cdat->source_id);
+	nm_clear_g_source_inst (&context->cdat->source);
 	nm_clear_pointer (&context->cdat->sdp_session, sdp_close);
 
 	context->cdat->sdp_session = sdp_connect (&context->src, &context->dst, SDP_NON_BLOCKING);
@@ -661,11 +667,13 @@ _connect_sdp_session_start (NMBluez5DunContext *context,
 		return FALSE;
 	}
 
-	io_channel = g_io_channel_unix_new (sdp_get_socket (context->cdat->sdp_session));
-	context->cdat->source_id = g_io_add_watch (io_channel,
-	                                           G_IO_OUT | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
-	                                           _connect_sdp_io_cb,
-	                                           context);
+	context->cdat->source = nm_g_unix_fd_source_new (sdp_get_socket (context->cdat->sdp_session),
+	                                                 G_IO_OUT | G_IO_HUP | G_IO_ERR | G_IO_NVAL,
+	                                                 G_PRIORITY_DEFAULT,
+	                                                 _connect_sdp_io_cb,
+	                                                 context,
+	                                                 NULL);
+	g_source_attach (context->cdat->source, NULL);
 	return TRUE;
 }
 
@@ -772,7 +780,7 @@ _context_cleanup_connect_data (NMBluez5DunContext *context)
 
 	nm_clear_g_signal_handler (cdat->cancellable, &cdat->cancelled_id);
 
-	nm_clear_g_source (&cdat->source_id);
+	nm_clear_g_source_inst (&cdat->source);
 
 	nm_clear_pointer (&cdat->sdp_session, sdp_close);
 
@@ -797,7 +805,7 @@ _context_invoke_callback (NMBluez5DunContext *context,
 
 	if (!error)
 		_LOGD (context, "connected via \"%s\"", context->rfcomm_tty_path);
-	else if (nm_utils_error_is_cancelled (error, FALSE))
+	else if (nm_utils_error_is_cancelled (error))
 		_LOGD (context, "cancelled");
 	else
 		_LOGD (context, "failed to connect: %s", error->message);
@@ -836,7 +844,7 @@ _context_free (NMBluez5DunContext *context)
 
 	_context_cleanup_connect_data (context);
 
-	nm_clear_g_source (&context->rfcomm_tty_poll_id);
+	nm_clear_g_source_inst (&context->rfcomm_tty_poll_source);
 
 	if (context->rfcomm_sock_fd >= 0) {
 		if (context->rfcomm_tty_no >= 0) {
diff --git a/src/devices/bluetooth/nm-device-bt.c b/src/devices/bluetooth/nm-device-bt.c
index 497810c3..ab18897f 100644
--- a/src/devices/bluetooth/nm-device-bt.c
+++ b/src/devices/bluetooth/nm-device-bt.c
@@ -484,7 +484,7 @@ modem_auth_result (NMModem *modem, GError *error, gpointer user_data)
 	}
 
 	priv->stage1_modem_prepare_state = NM_DEVICE_STAGE_STATE_INIT;
-	nm_device_activate_schedule_stage1_device_prepare (device);
+	nm_device_activate_schedule_stage1_device_prepare (device, FALSE);
 }
 
 static void
@@ -519,7 +519,7 @@ modem_prepare_result (NMModem *modem,
 	}
 
 	priv->stage1_modem_prepare_state = NM_DEVICE_STAGE_STATE_COMPLETED;
-	nm_device_activate_schedule_stage1_device_prepare (NM_DEVICE (self));
+	nm_device_activate_schedule_stage1_device_prepare (NM_DEVICE (self), FALSE);
 }
 
 static void
@@ -719,7 +719,7 @@ mm_modem_added_cb (NMModemManager *manager,
 	priv = NM_DEVICE_BT_GET_PRIVATE (self);
 
 	if (priv->stage1_bt_state == NM_DEVICE_STAGE_STATE_COMPLETED)
-		nm_device_activate_schedule_stage1_device_prepare (NM_DEVICE (self));
+		nm_device_activate_schedule_stage1_device_prepare (NM_DEVICE (self), FALSE);
 }
 
 /*****************************************************************************/
@@ -830,7 +830,7 @@ connect_bz_cb (NMBluezManager *bz_mgr,
 	NMDeviceBtPrivate *priv;
 	char sbuf[100];
 
-	if (nm_utils_error_is_cancelled (error, FALSE))
+	if (nm_utils_error_is_cancelled (error))
 		return;
 
 	self = user_data;
@@ -903,7 +903,7 @@ connect_bz_cb (NMBluezManager *bz_mgr,
 	}
 
 	priv->stage1_bt_state = NM_DEVICE_STAGE_STATE_COMPLETED;
-	nm_device_activate_schedule_stage1_device_prepare (NM_DEVICE (self));
+	nm_device_activate_schedule_stage1_device_prepare (NM_DEVICE (self), FALSE);
 }
 
 static NMActStageReturn
@@ -1153,7 +1153,7 @@ static void
 get_property (GObject *object, guint prop_id,
               GValue *value, GParamSpec *pspec)
 {
-	NMDeviceBtPrivate *priv = NM_DEVICE_BT_GET_PRIVATE ((NMDeviceBt *) object);
+	NMDeviceBtPrivate *priv = NM_DEVICE_BT_GET_PRIVATE (object);
 
 	switch (prop_id) {
 	case PROP_BT_NAME:
@@ -1172,7 +1172,7 @@ static void
 set_property (GObject *object, guint prop_id,
               const GValue *value, GParamSpec *pspec)
 {
-	NMDeviceBtPrivate *priv = NM_DEVICE_BT_GET_PRIVATE ((NMDeviceBt *) object);
+	NMDeviceBtPrivate *priv = NM_DEVICE_BT_GET_PRIVATE (object);
 
 	switch (prop_id) {
 	case PROP_BT_BZ_MGR:
@@ -1296,7 +1296,7 @@ dispose (GObject *object)
 static void
 finalize (GObject *object)
 {
-	NMDeviceBtPrivate *priv = NM_DEVICE_BT_GET_PRIVATE ((NMDeviceBt *) object);
+	NMDeviceBtPrivate *priv = NM_DEVICE_BT_GET_PRIVATE (object);
 
 	g_free (priv->connect_rfcomm_iface);
 	g_free (priv->dbus_path);