Skip to contentSkip to conversation

audio: Remove AudioSink interface

PATCH In review Luiz Augusto von Dentz 2 participants 12 messages Nov 26, 2012 Bluetooth drivers

lore
Share & tools
lore

Luiz Augusto von Dentz

author maintainer
#0 lore raw

PATCH 1/11 audio: Remove AudioSink interface

From: Luiz Augusto von Dentz <[email protected]>

This interface is no longer needed as Device interface can now connect the profiles and the state can be tracked using MediaTransport interface.

---
 doc/audio-api.txt     |  53 -------------------
 profiles/audio/sink.c | 141 ++------------------------------------------------
 2 files changed, 3 insertions(+), 191 deletions(-)
doc/audio-api.txt +0 -53
index 9ace681..47ea4b6 100644
@@ -51,59 +51,6 @@ Properties	string State
 				Disconnected from the remote device
 
 
-AudioSink hierarchy
-===================
-
-Service		org.bluez
-Interface	org.bluez.AudioSink
-Object path	[variable prefix]/{hci0,hci1,...}/dev_XX_XX_XX_XX_XX_XX
-
-Methods		void Connect()
-
-			Connect and setup a stream to a A2DP sink on the
-			remote device.
-
-		void Disconnect()
-
-			Disconnect from the remote device.
-
-		dict GetProperties()
-
-			Returns all properties for the interface. See the
-			properties section for available properties.
-
-			Possible Errors: org.bluez.Error.InvalidArguments
-
-Signals		PropertyChanged(string name, variant value)
-
-			This signal indicates a changed value of the given
-			property.
-
-properties	string State [readonly]
-
-			Possible values: "disconnected", "connecting",
-			"connected", "playing"
-
-			"disconnected" -> "connecting"
-				Either an incoming or outgoing connection
-				attempt ongoing.
-
-			"connecting" -> "disconnected"
-				Connection attempt failed
-
-			"connecting" -> "connected"
-				Successfully connected
-
-			"connected" -> "playing"
-				Audio stream active
-
-			"playing" -> "connected"
-				Audio stream suspended
-
-			"connected" -> "disconnected"
-			"playing" -> "disconnected"
-				Disconnected from the remote device
-
 AudioSource hierarchy
 =====================
 
profiles/audio/sink.c +3 -138

181 lines not on this page · raw message

Signature · 1 line
1.7.11.7
author maintainer
#1 lore raw

PATCH 2/11 audio: Remove AudioSource interface

From: Luiz Augusto von Dentz <[email protected]>

This interface is no longer needed as Device interface can now connect the profiles and the state can be tracked using MediaTransport interface.

---
 doc/audio-api.txt       |  54 ------------------
 profiles/audio/source.c | 146 ++++--------------------------------------------
 2 files changed, 11 insertions(+), 189 deletions(-)
doc/audio-api.txt +0 -54
index 47ea4b6..6fd8dfc 100644
@@ -49,57 +49,3 @@ Properties	string State
 
 			"connected" -> "disconnected"
 				Disconnected from the remote device
-
-
-AudioSource hierarchy
-=====================
-
-Service		org.bluez
-Interface	org.bluez.AudioSource
-Object path	[variable prefix]/{hci0,hci1,...}/dev_XX_XX_XX_XX_XX_XX
-
-Methods		void Connect()
-
-			Connect and setup a stream to a A2DP source on the
-			remote device.
-
-		void Disconnect()
-
-			Disconnect from the remote device.
-
-		dict GetProperties()
-
-			Returns all properties for the interface. See the
-			properties section for available properties.
-
-			Possible Errors: org.bluez.Error.InvalidArguments
-
-Signals		PropertyChanged(string name, variant value)
-
-			This signal indicates a changed value of the given
-			property.
-
-properties	string State [readonly]
-
-			Possible values: "disconnected", "connecting",
-			"connected", "playing"
-
-			"disconnected" -> "connecting"
-				Either an incoming or outgoing connection
-				attempt ongoing.
-
-			"connecting" -> "disconnected"
-				Connection attempt failed
-
-			"connecting" -> "connected"
-				Successfully connected
-
-			"connected" -> "playing"
-				Audio stream active
-
-			"playing" -> "connected"
-				Audio stream suspended
-
-			"connected" -> "disconnected"
-			"playing" -> "disconnected"
-				Disconnected from the remote device
profiles/audio/source.c +11 -135

188 lines not on this page · raw message

Signature · 1 line
1.7.11.7
author maintainer
#2 lore raw

PATCH 3/11 audio: Remove Audio interface

In reply to Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

This interface is no longer needed as Device interface can now connect the profiles and the state can be tracked using MediaTransport interface.

---
 doc/audio-api.txt       |  51 ---------------
 profiles/audio/device.c | 160 +-----------------------------------------------
 2 files changed, 2 insertions(+), 209 deletions(-)
 delete mode 100644 doc/audio-api.txt
doc/audio-api.txt deleted +0 -51
deleted file mode 100644
index 6fd8dfc..0000000
@@ -1,51 +0,0 @@
-BlueZ D-Bus Audio API description
-*********************************
-
-Copyright (C) 2004-2010  Marcel Holtmann <[email protected]>
-Copyright (C) 2005-2007  Johan Hedberg <[email protected]>
-Copyright (C) 2005-2006  Brad Midgley <[email protected]>
-
-Audio hierarchy
-===============
-
-Service		org.bluez
-Interface	org.bluez.Audio
-Object path	[variable prefix]/{hci0,hci1,...}/dev_XX_XX_XX_XX_XX_XX
-
-This is a generic audio interface that abstracts the different audio profiles.
-
-Methods		void Connect()
-
-			Connect all supported audio profiles on the device.
-
-		void Disconnect()
-
-			Disconnect all audio profiles on the device
-
-		dict GetProperties()
-
-			Returns all properties for the interface. See the
-			properties section for available properties.
-
-Signals		void PropertyChanged(string name, variant value)
-
-			This signal indicates a changed value of the given
-			property.
-
-Properties	string State
-
-			Possible values: "disconnected", "connecting",
-			"connected"
-
-			"disconnected" -> "connecting"
-				Either an incoming or outgoing connection
-				attempt ongoing.
-
-			"connecting" -> "disconnected"
-				Connection attempt failed
-
-			"connecting" -> "connected"
-				Successfully connected
-
-			"connected" -> "disconnected"
-				Disconnected from the remote device
profiles/audio/device.c +2 -158

204 lines not on this page · raw message

Signature · 1 line
1.7.11.7
author maintainer
#3 lore raw

PATCH 4/11 audio: Remove Control.Connect and Control.Disconnect

In reply to Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

These method are no longer necessary as Device interface has similar functionality.

---
 doc/control-api.txt      | 10 +---------
 profiles/audio/control.c | 47 -----------------------------------------------
 profiles/audio/device.c  |  6 ++++--
 3 files changed, 5 insertions(+), 58 deletions(-)
doc/control-api.txt +1 -9
index 0d25512..a16ee7d 100644
@@ -12,15 +12,7 @@ Service		org.bluez
 Interface	org.bluez.Control
 Object path	[variable prefix]/{hci0,hci1,...}/dev_XX_XX_XX_XX_XX_XX
 
-Methods		void Connect()
-
-			Connect to remote device.
-
-		void Disconnect()
-
-			Disconnect from remote device.
-
-		void Play()
+Methods		void Play()
 
 			Resume playback.
 
profiles/audio/control.c +0 -47

65 lines not on this page · raw message

profiles/audio/device.c +4 -2
index b14f75b..fef2bea 100644
@@ -298,6 +298,8 @@ struct audio_device *audio_device_register(struct btd_device *device,
 {
 	struct audio_device *dev;
 
+	DBG("%s", device_get_path(device));
+
 	dev = g_new0(struct audio_device, 1);
 
 	dev->btd_dev = btd_device_ref(device);
@@ -306,8 +308,6 @@ struct audio_device *audio_device_register(struct btd_device *device,
 	dev->priv = g_new0(struct dev_priv, 1);
 	dev->priv->state = AUDIO_STATE_DISCONNECTED;
 
-	DBG("%s", device_get_path(dev->btd_dev));
-
 	if (sink_callback_id == 0)
 		sink_callback_id = sink_add_state_cb(device_sink_cb, NULL);
 
@@ -341,6 +341,8 @@ gboolean audio_device_is_active(struct audio_device *dev,
 
 void audio_device_unregister(struct audio_device *device)
 {
+	DBG("%s", device_get_path(device->btd_dev));
+
 	if (device->hs_preauth_id) {
 		g_source_remove(device->hs_preauth_id);
 		device->hs_preauth_id = 0;
Signature · 1 line
1.7.11.7
author maintainer
#4 lore raw

PATCH 5/11 input: Remove Input interface

In reply to Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

This interface is no longer needed as Device interface can now connect the profiles.

---
 doc/input-api.txt       | 44 -----------------------
 profiles/input/device.c | 93 ++++---------------------------------------------
 2 files changed, 6 insertions(+), 131 deletions(-)
 delete mode 100644 doc/input-api.txt
doc/input-api.txt deleted +0 -44
deleted file mode 100644
index 7c3a4b2..0000000
@@ -1,44 +0,0 @@
-BlueZ D-Bus Input API description
-*********************************
-
-Copyright (C) 2004-2010  Marcel Holtmann <[email protected]>
-
-
-Input hierarchy
-===============
-
-Service		org.bluez
-Interface	org.bluez.Input
-Object path	[variable prefix]/{hci0,hci1,...}/dev_XX_XX_XX_XX_XX_XX
-
-Methods		void Connect()
-
-			Connect to the input device.
-
-			Possible errors: org.bluez.Error.AlreadyConnected
-					 org.bluez.Error.ConnectionAttemptFailed
-
-		void Disconnect()
-
-			Disconnect from the input device.
-
-			To abort a connection attempt in case of errors or
-			timeouts in the client it is fine to call this method.
-
-			Possible errors: org.bluez.Error.Failed
-
-		dict GetProperties()
-
-			Returns all properties for the interface. See the
-			properties section for available properties.
-
-			Possible Errors: org.bluez.Error.InvalidArguments
-
-Signals		PropertyChanged(string name, variant value)
-
-			This signal indicates a changed value of the given
-			property.
-
-Properties	boolean Connected [readonly]
-
-			Indicates if the device is connected.
profiles/input/device.c +6 -87

129 lines not on this page · raw message

Signature · 1 line
1.7.11.7
author maintainer
#5 lore raw

PATCH 6/11 network: Make use of D-Bus Properties interface

In reply to Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

---
 profiles/network/connection.c | 133 +++++++++++++++++++++---------------------
 1 file changed, 68 insertions(+), 65 deletions(-)
profiles/network/connection.c +68 -65
index 57451b9..d9961f8 100644
@@ -113,19 +113,15 @@ static gboolean bnep_watchdog_cb(GIOChannel *chan, GIOCondition cond,
 				gpointer data)
 {
 	struct network_conn *nc = data;
-	gboolean connected = FALSE;
-	const char *property = "";
+	DBusConnection *conn = btd_get_dbus_connection();
 	const char *path = device_get_path(nc->peer->device);
 
-	emit_property_changed(path,
-				NETWORK_PEER_INTERFACE, "Connected",
-				DBUS_TYPE_BOOLEAN, &connected);
-	emit_property_changed(path,
-				NETWORK_PEER_INTERFACE, "Interface",
-				DBUS_TYPE_STRING, &property);
-	emit_property_changed(path,
-				NETWORK_PEER_INTERFACE, "UUID",
-				DBUS_TYPE_STRING, &property);
+	g_dbus_emit_property_changed(conn, path,
+					NETWORK_PEER_INTERFACE, "Connected");
+	g_dbus_emit_property_changed(conn, path,
+					NETWORK_PEER_INTERFACE, "Interface");
+	g_dbus_emit_property_changed(conn, path,
+					NETWORK_PEER_INTERFACE, "UUID");
 	device_remove_disconnect_watch(nc->peer->device, nc->dc_id);
 	nc->dc_id = 0;
 	if (nc->watch) {
@@ -200,9 +196,8 @@ static gboolean bnep_setup_cb(GIOChannel *chan, GIOCondition cond,
 	char pkt[BNEP_MTU];
 	ssize_t r;
 	int sk;
-	const char *pdev, *uuid;
-	gboolean connected;
 	const char *path;
+	DBusConnection *conn;
 
 	if (cond & G_IO_NVAL)
 		return FALSE;
@@ -265,24 +260,19 @@ static gboolean bnep_setup_cb(GIOChannel *chan, GIOCondition cond,
 	}
 
 	bnep_if_up(nc->dev);
-	pdev = nc->dev;
-	uuid = bnep_uuid(nc->id);
 
 	if (nc->cb)
-		nc->cb(nc->peer->device, 0, pdev, nc->cb_data);
+		nc->cb(nc->peer->device, 0, nc->dev, nc->cb_data);
 
+	conn = btd_get_dbus_connection();
 	path = device_get_path(nc->peer->device);
 
-	connected = TRUE;
-	emit_property_changed(path,
-				NETWORK_PEER_INTERFACE, "Connected",
-				DBUS_TYPE_BOOLEAN, &connected);
-	emit_property_changed(path,
-				NETWORK_PEER_INTERFACE, "Interface",
-				DBUS_TYPE_STRING, &pdev);
-	emit_property_changed(path,
-				NETWORK_PEER_INTERFACE, "UUID",
-				DBUS_TYPE_STRING, &uuid);
+	g_dbus_emit_property_changed(conn, path,
+					NETWORK_PEER_INTERFACE, "Connected");
+	g_dbus_emit_property_changed(conn, path,
+					NETWORK_PEER_INTERFACE, "Interface");
+	g_dbus_emit_property_changed(conn, path,
+					NETWORK_PEER_INTERFACE, "UUID");
 
 	nc->state = CONNECTED;
 	nc->dc_id = device_add_disconnect_watch(nc->peer->device, disconnect_cb,
@@ -530,54 +520,69 @@ static DBusMessage *local_disconnect(DBusConnection *conn,
 	return btd_error_not_connected(msg);
 }
 
-static DBusMessage *local_get_properties(DBusConnection *conn,
-					DBusMessage *msg, void *data)
+static gboolean
+network_property_get_connected(const GDBusPropertyTable *property,
+					DBusMessageIter *iter, void *data)
 {
 	struct network_peer *peer = data;
-	struct network_conn *nc = NULL;
-	DBusMessage *reply;
-	DBusMessageIter iter;
-	DBusMessageIter dict;
-	dbus_bool_t connected;
-	const char *property;
+	dbus_bool_t value = FALSE;
 	GSList *l;
 
-	reply = dbus_message_new_method_return(msg);
-	if (!reply)
-		return NULL;
+	for (l = peer->connections; l; l = l->next) {
+		struct network_conn *tmp = l->data;
+
+		if (tmp->state == CONNECTED) {
+			value = TRUE;
+			break;
+		}
+	}
+
+	dbus_message_iter_append_basic(iter, DBUS_TYPE_BOOLEAN, &value);
 
-	dbus_message_iter_init_append(reply, &iter);
+	return TRUE;
+}
 
-	dbus_message_iter_open_container(&iter, DBUS_TYPE_ARRAY,
-			DBUS_DICT_ENTRY_BEGIN_CHAR_AS_STRING
-			DBUS_TYPE_STRING_AS_STRING DBUS_TYPE_VARIANT_AS_STRING
-			DBUS_DICT_ENTRY_END_CHAR_AS_STRING, &dict);
+static gboolean
+network_property_get_interface(const GDBusPropertyTable *property,
+					DBusMessageIter *iter, void *data)
+{
+	struct network_peer *peer = data;
+	const char *value = "";
+	GSList *l;
 
-	/* Connected */
 	for (l = peer->connections; l; l = l->next) {
 		struct network_conn *tmp = l->data;
 
-		if (tmp->state != CONNECTED)
-			continue;
-
-		nc = tmp;
-		break;
+		if (tmp->state == CONNECTED) {
+			value = tmp->dev;
+			break;
+		}
 	}
 
-	connected = nc ? TRUE : FALSE;
-	dict_append_entry(&dict, "Connected", DBUS_TYPE_BOOLEAN, &connected);
+	dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &value);
 
-	/* Interface */
-	property = nc ? nc->dev : "";
-	dict_append_entry(&dict, "Interface", DBUS_TYPE_STRING, &property);
+	return TRUE;
+}
 
-	/* UUID */
-	property = nc ? bnep_uuid(nc->id) : "";
-	dict_append_entry(&dict, "UUID", DBUS_TYPE_STRING, &property);
+static gboolean network_property_get_uuid(const GDBusPropertyTable *property,
+					DBusMessageIter *iter, void *data)
+{
+	struct network_peer *peer = data;
+	const char *value = "";
+	GSList *l;
+
+	for (l = peer->connections; l; l = l->next) {
+		struct network_conn *tmp = l->data;
+
+		if (tmp->state == CONNECTED) {
+			value = bnep_uuid(tmp->id);
+			break;
+		}
+	}
 
-	dbus_message_iter_close_container(&iter, &dict);
+	dbus_message_iter_append_basic(iter, DBUS_TYPE_STRING, &value);
 
-	return reply;
+	return TRUE;
 }
 
 static void connection_free(void *data)
@@ -618,15 +623,13 @@ static const GDBusMethodTable connection_methods[] = {
 				local_connect) },
 	{ GDBUS_METHOD("Disconnect",
 			NULL, NULL, local_disconnect) },
-	{ GDBUS_METHOD("GetProperties",
-			NULL, GDBUS_ARGS({ "properties", "a{sv}" }),
-			local_get_properties) },
 	{ }
 };
 
-static const GDBusSignalTable connection_signals[] = {
-	{ GDBUS_SIGNAL("PropertyChanged",
-			GDBUS_ARGS({ "name", "s" }, { "value", "v" })) },
+static const GDBusPropertyTable connection_properties[] = {
+	{ "Connected", "b", network_property_get_connected },
+	{ "Interface", "s", network_property_get_interface },
+	{ "UUID", "s", network_property_get_uuid },
 	{ }
 };
 
@@ -659,7 +662,7 @@ static struct network_peer *create_peer(struct btd_device *device)
 	if (g_dbus_register_interface(btd_get_dbus_connection(), path,
 					NETWORK_PEER_INTERFACE,
 					connection_methods,
-					connection_signals, NULL,
+					NULL, connection_properties,
 					peer, path_unregister) == FALSE) {
 		error("D-Bus failed to register %s interface",
 			NETWORK_PEER_INTERFACE);
Signature · 1 line
1.7.11.7
author maintainer
#6 lore raw

PATCH 7/11 network: Remove Network.Connect and Network.Disconnect

In reply to Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

These method are no longer necessary as Device interface has similar functionality.

---
 doc/network-api.txt           | 36 -------------------
 profiles/network/connection.c | 81 +------------------------------------------
 2 files changed, 1 insertion(+), 116 deletions(-)
doc/network-api.txt +0 -36
index 4dd3e58..b640b9a 100644
@@ -11,42 +11,6 @@ Service		org.bluez
 Interface	org.bluez.Network
 Object path	[variable prefix]/{hci0,hci1,...}/dev_XX_XX_XX_XX_XX_XX
 
-Methods		string Connect(string uuid)
-
-			Connect to the network device and return the network
-			interface name. Examples of the interface name are
-			bnep0, bnep1 etc.
-
-			uuid can be either one of "gn", "panu" or "nap" (case
-			insensitive) or a traditional string representation of
-			UUID or a hexadecimal number.
-
-			The connection will be closed and network device
-			released either upon calling Disconnect() or when
-			the client disappears from the message bus.
-
-			Possible errors: org.bluez.Error.AlreadyConnected
-					 org.bluez.Error.ConnectionAttemptFailed
-
-		void Disconnect()
-
-			Disconnect from the network device.
-
-			To abort a connection attempt in case of errors or
-			timeouts in the client it is fine to call this method.
-
-			Possible errors: org.bluez.Error.Failed
-
-		dict GetProperties()
-
-			Returns all properties for the interface. See the
-			properties section for available properties.
-
-Signals		PropertyChanged(string name, variant value)
-
-			This signal indicates a changed value of the given
-			property.
-
 Properties	boolean Connected [readonly]
 
 			Indicates if the device is connected.
profiles/network/connection.c +1 -80

105 lines not on this page · raw message

Signature · 1 line
1.7.11.7
author maintainer
#7 lore raw

PATCH 8/11 network: Fix not responding to Device.ConnectProfile

In reply to Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

The callback passed to connection_connect has to be used to respond when the connection completes.

---
 profiles/network/connection.c | 2 ++
 1 file changed, 2 insertions(+)
profiles/network/connection.c +2 -0
index 231164b..912e5b4 100644
@@ -417,6 +417,8 @@ int connection_connect(struct btd_device *device, uint16_t id,
 
 	nc->state = CONNECTING;
 	nc->owner = g_strdup(owner);
+	nc->cb = cb;
+	nc->cb_data = data;
 
 	if (owner)
 		nc->watch = g_dbus_add_disconnect_watch(
Signature · 1 line
1.7.11.7
author maintainer
#8 lore raw

PATCH 9/11 network: Fix trying to register NetworkServer interface multiple times

In reply to Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

This also removes the limitation of only accepting nap as UUID, now all PAN UUID are supported including their friendly names.

---
 profiles/network/server.c | 64 ++++++++++++++++++++++++++++++++---------------
 1 file changed, 44 insertions(+), 20 deletions(-)
profiles/network/server.c +44 -20
index 1a485ca..2c3c72e 100644
@@ -72,7 +72,6 @@ struct network_adapter {
 /* Main server structure */
 struct network_server {
 	bdaddr_t	src;		/* Bluetooth Local Address */
-	char		*iface;		/* DBus interface */
 	char		*name;		/* Server service name */
 	char		*bridge;	/* Bridge name */
 	uint32_t	record_id;	/* Service record id */
@@ -110,6 +109,22 @@ static struct network_server *find_server(GSList *list, uint16_t id)
 	return NULL;
 }
 
+static struct network_server *find_server_by_uuid(GSList *list,
+							const char *uuid)
+{
+	for (; list; list = list->next) {
+		struct network_server *ns = list->data;
+
+		if (strcasecmp(uuid, bnep_uuid(ns->id)) == 0)
+			return ns;
+
+		if (strcasecmp(uuid, bnep_name(ns->id)) == 0)
+			return ns;
+	}
+
+	return NULL;
+}
+
 static sdp_record_t *server_record_new(const char *name, uint16_t id)
 {
 	sdp_list_t *svclass, *pfseq, *apseq, *root, *aproto;
@@ -624,7 +639,8 @@ static void server_disconnect(DBusConnection *conn, void *user_data)
 static DBusMessage *register_server(DBusConnection *conn,
 				DBusMessage *msg, void *data)
 {
-	struct network_server *ns = data;
+	struct network_adapter *na = data;
+	struct network_server *ns;
 	DBusMessage *reply;
 	const char *uuid, *bridge;
 
@@ -632,7 +648,8 @@ static DBusMessage *register_server(DBusConnection *conn,
 				DBUS_TYPE_STRING, &bridge, DBUS_TYPE_INVALID))
 		return btd_error_invalid_args(msg);
 
-	if (g_strcmp0(uuid, "nap"))
+	ns = find_server_by_uuid(na->servers, uuid);
+	if (ns == NULL)
 		return btd_error_failed(msg, "Invalid UUID");
 
 	if (ns->record_id)
@@ -693,8 +710,10 @@ static void adapter_free(struct network_adapter *na)
 	g_free(na);
 }
 
-static void server_free(struct network_server *ns)
+static void server_free(void *data)
 {
+	struct network_server *ns = data;
+
 	if (!ns)
 		return;
 
@@ -703,7 +722,6 @@ static void server_free(struct network_server *ns)
 	if (ns->record_id)
 		remove_record_from_server(ns->record_id);
 
-	g_free(ns->iface);
 	g_free(ns->name);
 	g_free(ns->bridge);
 
@@ -712,17 +730,12 @@ static void server_free(struct network_server *ns)
 
 static void path_unregister(void *data)
 {
-	struct network_server *ns = data;
-	struct network_adapter *na = ns->na;
+	struct network_adapter *na = data;
 
 	DBG("Unregistered interface %s on path %s",
-		ns->iface, adapter_get_path(na->adapter));
-
-	na->servers = g_slist_remove(na->servers, ns);
-	server_free(ns);
+		NETWORK_SERVER_INTERFACE, adapter_get_path(na->adapter));
 
-	if (na->servers)
-		return;
+	g_slist_free_full(na->servers, server_free);
 
 	adapters = g_slist_remove(adapters, na);
 	adapter_free(na);
@@ -786,29 +799,33 @@ int server_register(struct btd_adapter *adapter, uint16_t id)
 
 	ns = g_new0(struct network_server, 1);
 
-	ns->iface = g_strdup(NETWORK_SERVER_INTERFACE);
 	ns->name = g_strdup("Network service");
 
 	path = adapter_get_path(adapter);
 
+	if (g_slist_length(na->servers) > 0)
+		goto done;
+
 	if (!g_dbus_register_interface(btd_get_dbus_connection(),
-					path, ns->iface,
+					path, NETWORK_SERVER_INTERFACE,
 					server_methods, NULL, NULL,
-					ns, path_unregister)) {
+					na, path_unregister)) {
 		error("D-Bus failed to register %s interface",
-				ns->iface);
+						NETWORK_SERVER_INTERFACE);
 		server_free(ns);
 		return -1;
 	}
 
+	DBG("Registered interface %s on path %s", NETWORK_SERVER_INTERFACE,
+									path);
+
+done:
 	bacpy(&ns->src, adapter_get_address(adapter));
 	ns->id = id;
 	ns->na = na;
 	ns->record_id = 0;
 	na->servers = g_slist_append(na->servers, ns);
 
-	DBG("Registered interface %s on path %s", ns->iface, path);
-
 	return 0;
 }
 
@@ -825,8 +842,15 @@ int server_unregister(struct btd_adapter *adapter, uint16_t id)
 	if (!ns)
 		return -EINVAL;
 
+	na->servers = g_slist_remove(na->servers, ns);
+	server_free(ns);
+
+	if (g_slist_length(na->servers) > 0)
+		return 0;
+
 	g_dbus_unregister_interface(btd_get_dbus_connection(),
-					adapter_get_path(adapter), ns->iface);
+						adapter_get_path(adapter),
+						NETWORK_SERVER_INTERFACE);
 
 	return 0;
 }
Signature · 1 line
1.7.11.7
author maintainer
#9 lore raw

PATCH 10/11 network: Fix always attempting to connect to PANU service

In reply to Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

connection_connect takes the remote role as parameter not the local one.

---
 profiles/network/manager.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
profiles/network/manager.c +1 -2
index 06abe1b..06ef9fc 100644
@@ -100,8 +100,7 @@ static int connect_profile(struct btd_device *dev, struct btd_profile *profile,
 	req->profile = profile;
 	req->cb = cb;
 
-	err = connection_connect(dev, BNEP_SVC_PANU, NULL, connect_profile_cb,
-									req);
+	err = connection_connect(dev, id, NULL, connect_profile_cb, req);
 	if (err < 0) {
 		g_free(req);
 		return err;
Signature · 1 line
1.7.11.7
author maintainer
#10 lore raw

PATCH 11/11 network: Fix invalid read on exit

In reply to Luiz Augusto von Dentz

From: Luiz Augusto von Dentz <[email protected]>

Invalid read of size 1
at 0x4A09D91: strcmp (mc_replace_strmem.c:729)
by 0x4C6C768: g_str_equal (in /usr/lib64/libglib-2.0.so.0.3200.4) by 0x1446B7: connection_disconnect (connection.c:451)
by 0x141DEA: disconnect_profile (manager.c:120)
by 0x4C96C5C: g_slist_foreach (in /usr/lib64/libglib-2.0.so.0.3200.4) by 0x182B2D: device_remove (device.c:2034)
by 0x178809: adapter_remove (adapter.c:2902)
by 0x173902: manager_cleanup (manager.c:256)
by 0x1217B9: main (main.c:550)
Address 0x0 is not stack'd, malloc'd or (recently) free'd

In addition remove owner since it is no longer possible to track the owner as this is done in the core.

---
 profiles/network/connection.c | 26 --------------------------
 1 file changed, 26 deletions(-)
profiles/network/connection.c +0 -26
index 912e5b4..a7e45e6 100644
@@ -70,8 +70,6 @@ struct network_conn {
 	uint16_t	id;		/* Role: Service Class Identifier */
 	conn_state	state;
 	GIOChannel	*io;
-	char		*owner;		/* Connection initiator D-Bus client */
-	guint		watch;		/* Disconnect watch */
 	guint		dc_id;
 	struct network_peer *peer;
 	guint		attempt_cnt;
@@ -124,10 +122,6 @@ static gboolean bnep_watchdog_cb(GIOChannel *chan, GIOCondition cond,
 					NETWORK_PEER_INTERFACE, "UUID");
 	device_remove_disconnect_watch(nc->peer->device, nc->dc_id);
 	nc->dc_id = 0;
-	if (nc->watch) {
-		g_dbus_remove_watch(nc->watch);
-		nc->watch = 0;
-	}
 
 	info("%s disconnected", nc->dev);
 
@@ -146,11 +140,6 @@ static void cancel_connection(struct network_conn *nc, int err)
 		nc->timeout_source = 0;
 	}
 
-	if (nc->watch) {
-		g_dbus_remove_watch(nc->watch);
-		nc->watch = 0;
-	}
-
 	if (nc->cb)
 		nc->cb(nc->peer->device, err, NULL, nc->cb_data);
 
@@ -170,11 +159,6 @@ static void connection_destroy(DBusConnection *conn, void *user_data)
 		bnep_kill_connection(device_get_address(nc->peer->device));
 	} else if (nc->io)
 		cancel_connection(nc, -EIO);
-
-	if (nc->owner) {
-		g_free(nc->owner);
-		nc->owner = NULL;
-	}
 }
 
 static void disconnect_cb(struct btd_device *device, gboolean removal,
@@ -416,16 +400,9 @@ int connection_connect(struct btd_device *device, uint16_t id,
 		return -EIO;
 
 	nc->state = CONNECTING;
-	nc->owner = g_strdup(owner);
 	nc->cb = cb;
 	nc->cb_data = data;
 
-	if (owner)
-		nc->watch = g_dbus_add_disconnect_watch(
-						btd_get_dbus_connection(),
-						owner, connection_destroy,
-						nc, NULL);
-
 	return 0;
 }
 
@@ -446,9 +423,6 @@ int connection_disconnect(struct btd_device *device, uint16_t id,
 	if (nc->state == DISCONNECTED)
 		return 0;
 
-	if (!g_str_equal(nc->owner, caller))
-		return -EPERM;
-
 	connection_destroy(NULL, nc);
 
 	return 0;
Signature · 1 line
1.7.11.7
#11 lore raw
In reply to Luiz Augusto von Dentz

Hi Luiz,

Quoted 6 lines · Luiz Augusto von Dentz

This interface is no longer needed as Device interface can now connect the profiles and the state can be tracked using MediaTransport interface.

---
 doc/audio-api.txt     |  53 -------------------
 profiles/audio/sink.c | 141 ++------------------------------------------------
 2 files changed, 3 insertions(+), 191 deletions(-)

All patches in this set have been applied. Thanks.

Johan