linux-bluetooth.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/2] serial: fix DBus message reply
@ 2011-09-13  3:46 Gustavo F. Padovan
  2011-09-13  7:19 ` Luiz Augusto von Dentz
  0 siblings, 1 reply; 5+ messages in thread
From: Gustavo F. Padovan @ 2011-09-13  3:46 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Gustavo F. Padovan

From: "Gustavo F. Padovan" <padovan@profusion.mobi>

If reply is NULL we have a crash.
---
 serial/port.c |    2 +-
 1 files changed, 1 insertions(+), 1 deletions(-)

diff --git a/serial/port.c b/serial/port.c
index d011084..2cdead4 100644
--- a/serial/port.c
+++ b/serial/port.c
@@ -369,7 +369,7 @@ static void get_record_cb(sdp_list_t *recs, int err, gpointer user_data)
 	GError *gerr = NULL;
 
 	if (!port->listener_id) {
-		reply = NULL;
+		reply = btd_error_failed(port->msg, "No listening application");
 		goto failed;
 	}
 
-- 
1.7.6.2


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/2] serial: fix DBus message reply
  2011-09-13  3:46 Gustavo F. Padovan
@ 2011-09-13  7:19 ` Luiz Augusto von Dentz
  0 siblings, 0 replies; 5+ messages in thread
From: Luiz Augusto von Dentz @ 2011-09-13  7:19 UTC (permalink / raw)
  To: Gustavo F. Padovan; +Cc: linux-bluetooth

Hi Gustavo,

On Tue, Sep 13, 2011 at 6:46 AM, Gustavo F. Padovan
<padovan@profusion.mobi> wrote:
> From: "Gustavo F. Padovan" <padovan@profusion.mobi>
>
> If reply is NULL we have a crash.
> ---
>  serial/port.c |    2 +-
>  1 files changed, 1 insertions(+), 1 deletions(-)
>
> diff --git a/serial/port.c b/serial/port.c
> index d011084..2cdead4 100644
> --- a/serial/port.c
> +++ b/serial/port.c
> @@ -369,7 +369,7 @@ static void get_record_cb(sdp_list_t *recs, int err, gpointer user_data)
>        GError *gerr = NULL;
>
>        if (!port->listener_id) {
> -               reply = NULL;
> +               reply = btd_error_failed(port->msg, "No listening application");
>                goto failed;
>        }

If we have no listener at this point we should probably not reply
because either the application has called Disconnect or it has exited
the bus, anyway the port->msg need to be unref.

-- 
Luiz Augusto von Dentz

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [PATCH 1/2] serial: fix DBus message reply
@ 2011-09-13 18:16 Gustavo F. Padovan
  2011-09-13 18:16 ` [PATCH 2/2] serial: add Serial.ConnectFD() Gustavo F. Padovan
  2011-09-27  8:32 ` [PATCH 1/2] serial: fix DBus message reply Johan Hedberg
  0 siblings, 2 replies; 5+ messages in thread
From: Gustavo F. Padovan @ 2011-09-13 18:16 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Gustavo F. Padovan

From: "Gustavo F. Padovan" <padovan@profusion.mobi>

If reply is NULL we have a crash.
---
 serial/port.c |    6 ++----
 1 files changed, 2 insertions(+), 4 deletions(-)

diff --git a/serial/port.c b/serial/port.c
index d011084..a931ebd 100644
--- a/serial/port.c
+++ b/serial/port.c
@@ -368,10 +368,8 @@ static void get_record_cb(sdp_list_t *recs, int err, gpointer user_data)
 	DBusMessage *reply;
 	GError *gerr = NULL;
 
-	if (!port->listener_id) {
-		reply = NULL;
-		goto failed;
-	}
+	if (!port->listener_id)
+		return;
 
 	if (err < 0) {
 		error("Unable to get service record: %s (%d)", strerror(-err),
-- 
1.7.6.2


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [PATCH 2/2] serial: add Serial.ConnectFD()
  2011-09-13 18:16 [PATCH 1/2] serial: fix DBus message reply Gustavo F. Padovan
@ 2011-09-13 18:16 ` Gustavo F. Padovan
  2011-09-27  8:32 ` [PATCH 1/2] serial: fix DBus message reply Johan Hedberg
  1 sibling, 0 replies; 5+ messages in thread
From: Gustavo F. Padovan @ 2011-09-13 18:16 UTC (permalink / raw)
  To: linux-bluetooth; +Cc: Gustavo F. Padovan

From: "Gustavo F. Padovan" <padovan@profusion.mobi>

It's similar to Serial.Connect() but returns the actual RFCOMM file
descriptor instead of creating a device in /dev
---
 doc/serial-api.txt |   16 ++++++++++++++++
 serial/port.c      |   25 ++++++++++++++++++++++++-
 2 files changed, 40 insertions(+), 1 deletions(-)

diff --git a/doc/serial-api.txt b/doc/serial-api.txt
index 5f9bd5f..98b0ad4 100644
--- a/doc/serial-api.txt
+++ b/doc/serial-api.txt
@@ -26,6 +26,22 @@ Methods		string Connect(string pattern)
 					 org.bluez.Error.ConnectionAttemptFailed
 					 org.bluez.Error.NotSupported
 
+Methods		fd ConnectFD(string pattern) [experimental]
+
+			Connects to a specific RFCOMM based service on a
+			remote device and returns a file descriptor to talk
+			 with this device.
+
+			Possible patterns: UUID 128 bit as string
+					   Profile short names, e.g: spp, dun
+					   RFCOMM channel as string, 1-30
+
+			Possible errors: org.bluez.Error.InvalidArguments
+					 org.bluez.Error.InProgress
+					 org.bluez.Error.ConnectionAttemptFailed
+					 org.bluez.Error.NotSupported
+
+
 		void Disconnect(string device)
 
 			Disconnect a RFCOMM TTY device that has been
diff --git a/serial/port.c b/serial/port.c
index a931ebd..7f5fce1 100644
--- a/serial/port.c
+++ b/serial/port.c
@@ -63,6 +63,10 @@
 #define MAX_OPEN_TRIES		5
 #define OPEN_WAIT		300	/* ms. udev node creation retry wait */
 
+#ifndef DBUS_TYPE_UNIX_FD
+#define DBUS_TYPE_UNIX_FD -1
+#endif
+
 struct serial_device {
 	DBusConnection	*conn;		/* for name listener handling */
 	bdaddr_t	src;		/* Source (local) address */
@@ -318,6 +322,21 @@ static void rfcomm_connect_cb(GIOChannel *chan, GError *conn_err,
 		goto fail;
 	}
 
+	sk = g_io_channel_unix_get_fd(chan);
+
+	if (dbus_message_has_member(port->msg, "ConnectFD")) {
+		reply = g_dbus_create_reply(port->msg, DBUS_TYPE_UNIX_FD, &sk,
+							DBUS_TYPE_INVALID);
+		g_dbus_send_message(device->conn, reply);
+
+		close(sk);
+
+		g_dbus_remove_watch(device->conn, port->listener_id);
+		port->listener_id = 0;
+
+		return;
+	}
+
 	memset(&req, 0, sizeof(req));
 	req.dev_id = -1;
 	req.flags = (1 << RFCOMM_REUSE_DLC);
@@ -328,7 +347,6 @@ static void rfcomm_connect_cb(GIOChannel *chan, GError *conn_err,
 	g_io_channel_unref(port->io);
 	port->io = NULL;
 
-	sk = g_io_channel_unix_get_fd(chan);
 	port->id = ioctl(sk, RFCOMMCREATEDEV, &req);
 	if (port->id < 0) {
 		int err = -errno;
@@ -474,6 +492,9 @@ static DBusMessage *port_connect(DBusConnection *conn,
 	const char *pattern;
 	int err;
 
+	if (dbus_message_has_member(msg, "ConnectFD") && DBUS_TYPE_UNIX_FD < 0)
+		return btd_error_not_supported(msg);
+
 	if (dbus_message_get_args(msg, NULL, DBUS_TYPE_STRING, &pattern,
 						DBUS_TYPE_INVALID) == FALSE)
 		return NULL;
@@ -497,6 +518,7 @@ static DBusMessage *port_connect(DBusConnection *conn,
 						dbus_message_get_sender(msg),
 						port_owner_exited, port,
 						NULL);
+
 	port->msg = dbus_message_ref(msg);
 
 	err = connect_port(port);
@@ -544,6 +566,7 @@ static DBusMessage *port_disconnect(DBusConnection *conn,
 
 static GDBusMethodTable port_methods[] = {
 	{ "Connect",    "s", "s", port_connect, G_DBUS_METHOD_FLAG_ASYNC },
+	{ "ConnectFD",    "s", "h", port_connect, G_DBUS_METHOD_FLAG_ASYNC },
 	{ "Disconnect", "s", "",  port_disconnect },
 	{ }
 };
-- 
1.7.6.2


^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [PATCH 1/2] serial: fix DBus message reply
  2011-09-13 18:16 [PATCH 1/2] serial: fix DBus message reply Gustavo F. Padovan
  2011-09-13 18:16 ` [PATCH 2/2] serial: add Serial.ConnectFD() Gustavo F. Padovan
@ 2011-09-27  8:32 ` Johan Hedberg
  1 sibling, 0 replies; 5+ messages in thread
From: Johan Hedberg @ 2011-09-27  8:32 UTC (permalink / raw)
  To: Gustavo F. Padovan; +Cc: linux-bluetooth

Hi Gustavo,

On Tue, Sep 13, 2011, Gustavo F. Padovan wrote:
> From: "Gustavo F. Padovan" <padovan@profusion.mobi>
> 
> If reply is NULL we have a crash.
> ---
>  serial/port.c |    6 ++----
>  1 files changed, 2 insertions(+), 4 deletions(-)

Both patches applied. Thanks.

Johan

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2011-09-27  8:32 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-09-13 18:16 [PATCH 1/2] serial: fix DBus message reply Gustavo F. Padovan
2011-09-13 18:16 ` [PATCH 2/2] serial: add Serial.ConnectFD() Gustavo F. Padovan
2011-09-27  8:32 ` [PATCH 1/2] serial: fix DBus message reply Johan Hedberg
  -- strict thread matches above, loose matches on Subject: below --
2011-09-13  3:46 Gustavo F. Padovan
2011-09-13  7:19 ` Luiz Augusto von Dentz

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).